home *** CD-ROM | disk | FTP | other *** search
- /*
- ScrollScreen V1.0
- written by Patrick Ohly
- all rights reserved, but copying allowed, i.e. it's freeware
- (or giftware, respectively, if you want...)
- */
-
- #include <clib/exec_protos.h>
- #include <clib/intuition_protos.h>
- #include <clib/icon_protos.h>
- #include <clib/dos_protos.h>
- #include <clib/commodities_protos.h>
- #include <clib/alib_protos.h>
-
- #include <intuition/screens.h>
- #include <intuition/intuitionbase.h>
- #include <libraries/commodities.h>
- #include <devices/inputevent.h>
- #include <workbench/startup.h>
- #include <workbench/workbench.h>
- #include <stdio.h>
-
- int CXBRK(void) { return(0); }
- int chkabort(void) { return(0); }
-
- struct Library *CxBase, *IconBase;
- struct IntuitionBase *IntuitionBase;
- struct MsgPort *BrokerMp;
- CxObj *Broker, *CustomFilter;
-
- struct NewBroker NewBroker =
- {
- NB_VERSION,
- "ScrollScreen",
- "SrollScreen by Patrick Ohly",
- "scroll screens with cursor keys",
- NBU_UNIQUE | NBU_NOTIFY,
- 0,0,0,0
- };
-
- /* activate this Task */
- struct Task *SigTask;
- ULONG CXSigflag;
-
- /* have a look for this qualifier */
- IX Qualifier;
-
- /* scrolling[art: no qual, shift, ctrl][richtung] */
- enum qual {none, shift, ctrl};
- enum richtung {up, down, right, left};
- ULONG Scrolling[3][4];
- ULONG TotalScrolling;
- #define JUMP_SIZE 8;
-
- __interrupt __saveds VOID CustomFunction(CxMsg *cxm, CxObj *co)
- {
- struct InputEvent *ie;
- BOOL signal_task = FALSE;
-
- ie = CxMsgData(cxm);
-
- if(ie->ie_Class == IECLASS_RAWKEY &&
- (ie->ie_Qualifier & Qualifier.ix_QualMask & Qualifier.ix_Qualifier) ==
- Qualifier.ix_Qualifier)
- {
- do
- {
- UWORD key = ie->ie_Code - 0x4C;
- UWORD qual;
-
- if(key <= 3)
- {
- if(ie->ie_Qualifier & IEQUALIFIER_CONTROL)
- qual = ctrl;
- else
- if(ie->ie_Qualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT))
- qual = shift;
- else
- qual = none;
- Scrolling[qual][key]++;
- TotalScrolling++;
- signal_task = TRUE;
- }
- ie = ie->ie_NextEvent;
- }while(ie);
-
- /* start scrolling */
- if(signal_task)
- {
- Signal(SigTask, CXSigflag);
- DisposeCxMsg(cxm);
- }
- }
- }
-
- VOID ProcessMsg(VOID)
- {
- CxMsg *msg;
- ULONG sigrcvd, msgid, msgtype;
- BOOL keepon = TRUE;
-
- while(keepon)
- {
- sigrcvd = Wait(SIGBREAKF_CTRL_C | CXSigflag);
-
- while(msg = (CxMsg *)GetMsg(BrokerMp))
- {
- msgid = CxMsgID(msg);
- msgtype = CxMsgType(msg);
- ReplyMsg((struct Message *)msg);
-
- if(msgtype == CXM_COMMAND)
- {
- switch(msgid)
- {
- case CXCMD_DISABLE:
- ActivateCxObj(Broker, 0L);
- break;
- case CXCMD_ENABLE:
- ActivateCxObj(Broker, 1L);
- break;
- case CXCMD_KILL:
- case CXCMD_UNIQUE:
- keepon = FALSE;
- break;
- }
- }
- }
- if(TotalScrolling)
- {
- ULONG screen_modeID;
- struct Rectangle rect;
- struct Screen *screen = IntuitionBase->ActiveScreen;
- UWORD i;
-
- /* please don't close the screen now -
- not really safe or even system-friendly, but better than nothing */
- Forbid();
- screen_modeID = GetVPModeID(&(screen->ViewPort));
- if(screen_modeID != INVALID_ID &&
- QueryOverscan(screen_modeID, &rect, OSCAN_TEXT))
- {
- WORD x, y;
-
- if(Scrolling[ctrl][right])
- x = -screen->Width;
- else
- if(Scrolling[ctrl][left])
- x = screen->Width;
- else
- {
- x = (Scrolling[shift][left] - Scrolling[shift][right]) *
- (rect.MaxX - rect.MinX);
- x += (Scrolling[none][left] - Scrolling[none][right]) *
- JUMP_SIZE;
- }
-
- if(Scrolling[ctrl][down])
- y = -screen->Height;
- else
- if(Scrolling[ctrl][up])
- y = screen->Height;
- else
- {
- y = (Scrolling[shift][up] - Scrolling[shift][down]) *
- (rect.MaxY - rect.MinY);
- y += (Scrolling[none][up] - Scrolling[none][down]) *
- JUMP_SIZE;
- }
-
- if(x || y)
- {
- /* don't scroll it to much down */
- if(y + screen->TopEdge > 0 && y > 0)
- if(screen->TopEdge < 0)
- y = -screen->TopEdge;
- else
- y = 0;
- MoveScreen(screen, x, y);
- }
- }
- /* do what you want again */
-
- for(i = 0; i < 3 * 4; i++)
- ((ULONG *)Scrolling)[i] = 0;
- TotalScrolling = 0;
- }
-
- if(sigrcvd & SIGBREAKF_CTRL_C)
- keepon = FALSE;
- }
- }
-
- ULONG main(int argc, char **argv)
- {
- if(CxBase = OpenLibrary("commodities.library", 37L))
- {
- if(IconBase = OpenLibrary("icon.library", 36L))
- {
- if(IntuitionBase = (struct IntuitionBase *)
- OpenLibrary("intuition.library", 33))
- {
- if(BrokerMp = CreateMsgPort())
- {
- UBYTE **ttypes;
-
- NewBroker.nb_Port = BrokerMp;
- CXSigflag = 1L << BrokerMp->mp_SigBit;
- SigTask = FindTask(NULL);
-
- ttypes = ArgArrayInit(argc, argv);
- NewBroker.nb_Pri = (ULONG)ArgInt(ttypes, "CX_PRIORITY", 10);
- if(! ParseIX(ArgString(ttypes, "QUALIFIER", "lcommand"), &Qualifier))
- {
- if(Broker = CxBroker(&NewBroker, NULL))
- {
- if(CustomFilter = CxCustom(CustomFunction, 0L))
- {
- AttachCxObj(Broker, CustomFilter);
- ActivateCxObj(Broker, 1L);
- ProcessMsg();
- }
- DeleteCxObjAll(Broker);
- }
- ArgArrayDone();
- DeletePort(BrokerMp);
- }
- }
- CloseLibrary((struct Library *)IntuitionBase);
- }
- CloseLibrary(IconBase);
- }
- CloseLibrary(CxBase);
- }
-
- return(0);
- }
-