home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / sm_390.lzh / SM / sm.c < prev    next >
C/C++ Source or Header  |  1990-10-23  |  4KB  |  161 lines

  1. /* ScreenShift 1.0
  2.  * Anson Mah
  3.  * June 4, 1987
  4.  * Completely in the Public Domain
  5.  * Written for Lattice C
  6.  
  7.  * Reworked by Ølli
  8.  * 3.2.90
  9.  * for Lettuce-C V5.04
  10.  * Removed that nasty "SS" ->
  11.  *  sorry, but I couldn't bear the name
  12.  *  esspecially regarding current events
  13.  *  in germany...
  14.  
  15.  */
  16.  
  17.  
  18. #include <proto/intuition.h>
  19. #include <proto/exec.h>
  20.  
  21. #define PROPGADWIDTH    200    /* gadget proportions */
  22. #define PROPGADHEIGHT    50
  23. #define XJUMP    512        /* add to Vert/HorizPot when */
  24. #define YJUMP    1024        /*   moving with cursor keys */
  25. #define UP    0x4c        /* cursor key RAWKEYS */
  26. #define DOWN    0x4d        /* also defined in intuition.h, */
  27. #define LEFT    0x4f        /*   but included for clarity */
  28. #define RIGHT    0x4e
  29. #define CR    0x44        /* RETURN key */
  30.  
  31. extern UWORD xoffset(BYTE), yoffset(BYTE);      /* the math.s routines */
  32. extern BYTE xpot(UWORD), ypot(UWORD);
  33.  
  34. UWORD piData[60] = {
  35.    0x0000,0x0000,0x0000,
  36.    0x7FFF,0xFFFF,0xFE00,
  37.    0x7FFF,0xB7DF,0xFE00,
  38.    0x7FFB,0xDBDF,0xFE00,
  39.    0x7FFD,0xFDDF,0xFE00,
  40.    0x7FFF,0xDADF,0xFE00,
  41.    0x7FFB,0xDBDF,0xFE00,
  42.    0x7FFF,0xBBDF,0xFE00,
  43.    0x7FFF,0xFFFF,0xFE00,
  44.    0x0000,0x0000,0x0000,
  45.    0xFFFF,0xFFFF,0xFF00,
  46.    0xFFFF,0xFFFF,0xFF00,
  47.    0xFFF0,0x6FBF,0xFF00,
  48.    0xFFE7,0x273F,0xFF00,
  49.    0xFFE3,0xE23F,0xFF00,
  50.    0xFFFE,0x253F,0xFF00,
  51.    0xFFE7,0x273F,0xFF00,
  52.    0xFFF0,0x673F,0xFF00,
  53.    0xFFFF,0xFFFF,0xFF00,
  54.    0xFFFF,0xFFFF,0xFF00
  55. };
  56.  
  57. struct Image piImage = {
  58.     0, 0,        /* LeftEdge, TopEdge */
  59.     40, 10, 2,    /* Width, Height, Depth */
  60.     &piData[0],    /* ImageData */
  61.     0x03, 0x00,    /* PlanePick, PlaneOnOff */
  62.     NULL        /* NextImage */
  63. };
  64.  
  65.  
  66.  
  67. struct PropInfo pinfo = { FREEVERT | FREEHORIZ, 0,0, MAXBODY/5,MAXBODY/5, 0,0,0,0,0 };
  68. struct Gadget pgadget = {
  69.     NULL, 0, 10, PROPGADWIDTH, PROPGADHEIGHT, GADGIMAGE, FOLLOWMOUSE,
  70.     PROPGADGET, (APTR)&piImage, NULL, NULL, 0, (APTR)&pinfo,
  71.     0, NULL
  72. };
  73.  
  74. struct NewWindow pwindef = {
  75.     220, 70,
  76.     PROPGADWIDTH, PROPGADHEIGHT + 10,
  77.     0, 3,
  78.     CLOSEWINDOW | MOUSEMOVE | RAWKEY,
  79.     WINDOWDEPTH | WINDOWCLOSE | WINDOWDRAG | ACTIVATE | SMART_REFRESH | RMBTRAP,
  80.     &pgadget,
  81.     NULL,
  82.     "ScreenMove",
  83.     NULL, NULL,
  84.     0,0, 0,0,
  85.     WBENCHSCREEN
  86. };
  87.  
  88. void _main(void);
  89. void XCEXIT(int);
  90.  
  91. void _main()
  92. {
  93.     struct IntuiMessage *msg;
  94.     ULONG class, code;
  95.     BYTE c_xoffset, c_yoffset;
  96.     struct IntuitionBase *IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 33);
  97.     struct Preferences pref;
  98.     struct Window *pwin;
  99.  
  100.     /* get current preference setting */
  101.     (void)GetPrefs(&pref, sizeof(struct Preferences));
  102.     /* set up prop gadget with current View settings */
  103.     pinfo.HorizPot = xoffset(pref.ViewXOffset);
  104.     pinfo.VertPot = yoffset(pref.ViewYOffset);
  105.     if (!(pwin = (struct Window *)OpenWindow(&pwindef)))
  106.         goto exit;
  107.  
  108.     for (;;) {
  109.         WaitPort(pwin->UserPort);
  110.         msg = (struct IntuiMessage *)GetMsg(pwin->UserPort);
  111.         class = msg->Class;
  112.         code = msg->Code;
  113.         ReplyMsg((struct Message*)msg);
  114.  
  115.         switch (class) {
  116.             case CLOSEWINDOW:
  117.                 goto exit;
  118.             case RAWKEY:
  119.               switch (code) {
  120.                 case UP:
  121.                     if (pinfo.VertPot >= YJUMP)
  122.                         pinfo.VertPot -= YJUMP;
  123.                     else    pinfo.VertPot = 0;
  124.                     break;
  125.                 case DOWN:
  126.                     if (pinfo.VertPot < MAXBODY - YJUMP)
  127.                         pinfo.VertPot += YJUMP;
  128.                     else    pinfo.VertPot = MAXBODY;
  129.                     break;
  130.                 case LEFT:
  131.                     if (pinfo.HorizPot >= XJUMP)
  132.                         pinfo.HorizPot -= XJUMP;
  133.                     else    pinfo.HorizPot = 0;
  134.                     break;
  135.                 case RIGHT:
  136.                     if (pinfo.HorizPot < MAXBODY - XJUMP)
  137.                         pinfo.HorizPot += XJUMP;
  138.                     else    pinfo.HorizPot = MAXBODY;
  139.                     break;
  140.                 case CR:    /* carriage return */
  141.                     goto exit;
  142.               }
  143.               RefreshGadgets(&pgadget, pwin, NULL);
  144.               /* fall through */
  145.             case MOUSEMOVE:
  146.                 c_xoffset = xpot(pinfo.HorizPot);
  147.                 c_yoffset = ypot(pinfo.VertPot);
  148.                 if (pref.ViewXOffset != c_xoffset || pref.ViewYOffset != c_yoffset) {
  149.                     pref.ViewXOffset = c_xoffset;
  150.                     pref.ViewYOffset = c_yoffset;
  151.                     (void)SetPrefs(&pref, sizeof(struct Preferences), FALSE);
  152.                 }
  153.                 break;
  154.         }
  155.     }
  156. exit:
  157.     if(pwin) CloseWindow(pwin);
  158.     XCEXIT(0);
  159. }
  160.  
  161.