home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / cdity / scrollscreen.lha / ScrollScreen / ScrollScreen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-25  |  5.1 KB  |  238 lines

  1. /*
  2.    ScrollScreen V1.0
  3.    written by Patrick Ohly
  4.    all rights reserved, but copying allowed, i.e. it's freeware
  5.    (or giftware, respectively, if you want...)
  6. */
  7.  
  8. #include <clib/exec_protos.h>
  9. #include <clib/intuition_protos.h>
  10. #include <clib/icon_protos.h>
  11. #include <clib/dos_protos.h>
  12. #include <clib/commodities_protos.h>
  13. #include <clib/alib_protos.h>
  14.  
  15. #include <intuition/screens.h>
  16. #include <intuition/intuitionbase.h>
  17. #include <libraries/commodities.h>
  18. #include <devices/inputevent.h>
  19. #include <workbench/startup.h>
  20. #include <workbench/workbench.h>
  21. #include <stdio.h>
  22.  
  23. int CXBRK(void) { return(0); }
  24. int chkabort(void) { return(0); }
  25.  
  26. struct Library *CxBase, *IconBase;
  27. struct IntuitionBase *IntuitionBase;
  28. struct MsgPort *BrokerMp;
  29. CxObj *Broker, *CustomFilter;
  30.  
  31. struct NewBroker NewBroker =
  32. {
  33.     NB_VERSION,
  34.     "ScrollScreen",
  35.     "SrollScreen by Patrick Ohly",
  36.     "scroll screens with cursor keys",
  37.     NBU_UNIQUE | NBU_NOTIFY,
  38.     0,0,0,0
  39. };
  40.  
  41. /* activate this Task */
  42. struct Task *SigTask;
  43. ULONG CXSigflag;
  44.  
  45. /* have a look for this qualifier */
  46. IX Qualifier;
  47.  
  48. /* scrolling[art: no qual, shift, ctrl][richtung] */
  49. enum qual     {none, shift, ctrl};
  50. enum richtung {up, down, right, left};
  51. ULONG Scrolling[3][4];
  52. ULONG TotalScrolling;
  53. #define JUMP_SIZE 8;
  54.  
  55. __interrupt __saveds VOID CustomFunction(CxMsg *cxm, CxObj *co)
  56. {
  57.     struct InputEvent *ie;
  58.     BOOL signal_task = FALSE;
  59.  
  60.     ie = CxMsgData(cxm);
  61.  
  62.     if(ie->ie_Class == IECLASS_RAWKEY &&
  63.        (ie->ie_Qualifier & Qualifier.ix_QualMask & Qualifier.ix_Qualifier) ==
  64.        Qualifier.ix_Qualifier)
  65.     {
  66.         do
  67.         {
  68.             UWORD key = ie->ie_Code - 0x4C;
  69.             UWORD qual;
  70.  
  71.             if(key <= 3)
  72.             {
  73.                 if(ie->ie_Qualifier & IEQUALIFIER_CONTROL)
  74.                     qual = ctrl;
  75.                 else
  76.                     if(ie->ie_Qualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT))
  77.                         qual = shift;
  78.                     else
  79.                         qual = none;
  80.                 Scrolling[qual][key]++;
  81.                 TotalScrolling++;
  82.                 signal_task = TRUE;
  83.             }
  84.             ie = ie->ie_NextEvent;
  85.         }while(ie);
  86.  
  87.         /* start scrolling */
  88.         if(signal_task)
  89.         {
  90.             Signal(SigTask, CXSigflag);
  91.             DisposeCxMsg(cxm);
  92.         }
  93.     }
  94. }
  95.  
  96. VOID ProcessMsg(VOID)
  97. {
  98.     CxMsg *msg;
  99.     ULONG sigrcvd, msgid, msgtype;
  100.     BOOL keepon = TRUE;
  101.  
  102.     while(keepon)
  103.     {
  104.         sigrcvd = Wait(SIGBREAKF_CTRL_C | CXSigflag);
  105.  
  106.         while(msg = (CxMsg *)GetMsg(BrokerMp))
  107.         {
  108.             msgid = CxMsgID(msg);
  109.             msgtype = CxMsgType(msg);
  110.             ReplyMsg((struct Message *)msg);
  111.  
  112.             if(msgtype == CXM_COMMAND)
  113.             {
  114.                 switch(msgid)
  115.                 {
  116.                     case CXCMD_DISABLE:
  117.                         ActivateCxObj(Broker, 0L);
  118.                         break;
  119.                     case CXCMD_ENABLE:
  120.                         ActivateCxObj(Broker, 1L);
  121.                         break;
  122.                     case CXCMD_KILL:
  123.                     case CXCMD_UNIQUE:
  124.                         keepon = FALSE;
  125.                         break;
  126.                 }
  127.             }
  128.         }
  129.         if(TotalScrolling)
  130.         {
  131.             ULONG screen_modeID;
  132.             struct Rectangle rect;
  133.             struct Screen *screen  = IntuitionBase->ActiveScreen;
  134.             UWORD i;
  135.  
  136.             /* please don't close the screen now -
  137.                not really safe or even system-friendly, but better than nothing */
  138.             Forbid();
  139.             screen_modeID = GetVPModeID(&(screen->ViewPort));
  140.             if(screen_modeID != INVALID_ID &&
  141.                QueryOverscan(screen_modeID, &rect, OSCAN_TEXT))
  142.             {
  143.                 WORD x, y;
  144.  
  145.                 if(Scrolling[ctrl][right])
  146.                     x = -screen->Width;
  147.                 else
  148.                     if(Scrolling[ctrl][left])
  149.                         x = screen->Width;
  150.                 else
  151.                 {
  152.                     x = (Scrolling[shift][left] - Scrolling[shift][right]) *
  153.                         (rect.MaxX - rect.MinX);
  154.                     x += (Scrolling[none][left] - Scrolling[none][right]) *
  155.                          JUMP_SIZE;
  156.                 }
  157.  
  158.                 if(Scrolling[ctrl][down])
  159.                     y = -screen->Height;
  160.                 else
  161.                     if(Scrolling[ctrl][up])
  162.                         y = screen->Height;
  163.                     else
  164.                     {
  165.                         y = (Scrolling[shift][up] - Scrolling[shift][down]) *
  166.                             (rect.MaxY - rect.MinY);
  167.                         y += (Scrolling[none][up] - Scrolling[none][down]) *
  168.                              JUMP_SIZE;
  169.                     }
  170.  
  171.                 if(x || y)
  172.                 {
  173.                     /* don't scroll it to much down */
  174.                     if(y + screen->TopEdge > 0 && y > 0)
  175.                         if(screen->TopEdge < 0)
  176.                             y = -screen->TopEdge;
  177.                         else
  178.                             y = 0;
  179.                     MoveScreen(screen, x, y);
  180.                 }
  181.             }
  182.             /* do what you want again */
  183.  
  184.             for(i = 0; i < 3 * 4; i++)
  185.                 ((ULONG *)Scrolling)[i] = 0;
  186.             TotalScrolling = 0;
  187.         }
  188.  
  189.         if(sigrcvd & SIGBREAKF_CTRL_C)
  190.             keepon = FALSE;
  191.     }    
  192. }
  193.  
  194. ULONG main(int argc, char **argv)
  195. {    
  196.     if(CxBase = OpenLibrary("commodities.library", 37L))
  197.     {    
  198.         if(IconBase = OpenLibrary("icon.library", 36L))
  199.         {
  200.             if(IntuitionBase = (struct IntuitionBase *)
  201.                                OpenLibrary("intuition.library", 33))
  202.             {    
  203.                 if(BrokerMp = CreateMsgPort())
  204.                 {    
  205.                     UBYTE **ttypes;
  206.  
  207.                     NewBroker.nb_Port = BrokerMp;
  208.                     CXSigflag = 1L << BrokerMp->mp_SigBit;
  209.                     SigTask = FindTask(NULL);
  210.  
  211.                     ttypes = ArgArrayInit(argc, argv);
  212.                     NewBroker.nb_Pri = (ULONG)ArgInt(ttypes, "CX_PRIORITY", 10);
  213.                     if(! ParseIX(ArgString(ttypes, "QUALIFIER", "lcommand"), &Qualifier))
  214.                     {
  215.                         if(Broker = CxBroker(&NewBroker, NULL))
  216.                         {
  217.                             if(CustomFilter = CxCustom(CustomFunction, 0L))
  218.                             {    
  219.                                 AttachCxObj(Broker, CustomFilter);
  220.                                 ActivateCxObj(Broker, 1L);
  221.                                 ProcessMsg();
  222.                             }
  223.                             DeleteCxObjAll(Broker);
  224.                         }
  225.                         ArgArrayDone();
  226.                         DeletePort(BrokerMp);
  227.                     }
  228.                 }
  229.                 CloseLibrary((struct Library *)IntuitionBase);
  230.             }
  231.             CloseLibrary(IconBase);
  232.         }
  233.         CloseLibrary(CxBase);
  234.     }
  235.  
  236.     return(0);
  237. }
  238.