home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 179.lha / ClipLines / doslbnc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-28  |  3.9 KB  |  246 lines

  1.  
  2. /* doslbnc.ld  - Copyright 1988 Commodore-Amiga, Inc. */
  3.  
  4. #include <exec/types.h>
  5. #include <exec/memory.h>
  6. #include <graphics/gfx.h>
  7. #include <graphics/gfxbase.h>
  8. #include <graphics/clip.h>
  9. #include <graphics/rastport.h>
  10. #include <graphics/layers.h>
  11. #include <intuition/intuition.h>
  12.  
  13. #define DEPTH    2
  14.  
  15. /*#define DEBUG*/
  16.  
  17. /* #define KPRINTF */
  18.  
  19. #ifdef KPRINTF
  20. #define printf kprintf
  21. #endif
  22.  
  23. extern int GfxBase;
  24.  
  25. int HEIGHT = 512;
  26. int WIDTH = 1024-16;
  27.  
  28. #define RBG_ID 0x0001
  29. #define BBG_ID 0x0002
  30.  
  31. int usable_width(w)
  32. struct Window *w;
  33. {
  34.    return (w->Width - w->BorderLeft - w->BorderRight);
  35. }
  36.  
  37. int usable_height(w)
  38. struct Window *w;
  39. {
  40.    return(w->Height - w->BorderTop - w->BorderBottom);
  41. }
  42.  
  43. do_gadget_down(msg)
  44. struct IntuiMessage *msg;
  45. {
  46. LONG error = FALSE;
  47.  
  48. #ifdef DEBUG
  49.     printf("do_gadget_down: entering...\n");
  50. #endif
  51.  
  52.     /* stub */
  53.  
  54. #ifdef DEBUG
  55.     printf("do_gadget_down: exiting...\n");
  56. #endif
  57.  
  58.     return(error);
  59. }
  60.  
  61. do_gadget_up(msg)
  62. struct IntuiMessage *msg;
  63. {
  64. LONG error = FALSE;
  65. struct Window *w;
  66. struct RastPort *rp;
  67. struct Layer *l;
  68. struct LayerInfo *li;
  69. struct Gadget *g;
  70. UWORD gid;
  71. struct PropInfo *pi;
  72.  
  73. #ifdef DEBUG
  74.     printf("do_gadget_up: entering...\n");
  75. #endif
  76.  
  77.     if(msg)
  78.     {
  79.         if(g = (struct Gadget *)msg->IAddress)
  80.         {
  81.  
  82.             gid = g->GadgetID;
  83.             switch(gid)
  84.             {
  85.                 case(RBG_ID): 
  86.                 {
  87.                     /* scroll vertically */
  88. #ifdef DEBUG
  89.                     printf("do_gadget_up: scroll vertically...\n");
  90. #endif
  91.  
  92.                     if(w = msg->IDCMPWindow)
  93.                     {
  94.                         if(rp = w->RPort)
  95.                         {
  96.                             if(l = rp->Layer)
  97.                             {
  98.                                 if(li = l->LayerInfo)
  99.                                 {
  100.                                     WORD abs_scroll;
  101.                                     WORD delta_scroll;
  102.                                     WORD max_scroll;
  103.                                     WORD sb_height;
  104.  
  105.                                     pi = g->SpecialInfo;
  106.                             
  107.                                     sb_height = l->SuperBitMap->Rows;
  108.  
  109.                                     abs_scroll = (((pi->VertPot + 1) * (sb_height - usable_height(w))) >> 16);
  110.  
  111.                                     delta_scroll = abs_scroll - l->Scroll_Y;
  112.  
  113.                                     ScrollLayer(li,l,0,delta_scroll);
  114.                                 }
  115.                             }
  116.                         }
  117.                     }
  118.                     break;
  119.                 }
  120.  
  121.                 case(BBG_ID): 
  122.                 {
  123.                     /* scroll horizontally */
  124. #ifdef DEBUG
  125.                     printf("do_gadget_up: scroll horizontally...\n");
  126. #endif
  127.                     if(w = msg->IDCMPWindow)
  128.                     {
  129.                         if(rp = w->RPort)
  130.                         {
  131.                             if(l = rp->Layer)
  132.                             {
  133.                                 if(li = l->LayerInfo)
  134.                                 {
  135.                                     WORD abs_scroll;
  136.                                     WORD delta_scroll;
  137.                                     WORD max_scroll;
  138.                                     WORD sb_width;
  139.  
  140.                                     pi = g->SpecialInfo;
  141.                         
  142.                                     sb_width = l->SuperBitMap->BytesPerRow << 3;
  143.  
  144.                                     abs_scroll = (((pi->HorizPot + 1) * (sb_width - usable_width(w))) >> 16);
  145.  
  146.                                     delta_scroll = abs_scroll - l->Scroll_X;
  147.  
  148.                                     ScrollLayer(li,l,delta_scroll,0);
  149.                                 }
  150.                             }
  151.                         }
  152.                     }
  153.                     break;
  154.                 }
  155.  
  156.                 default:
  157.                 {
  158.                     /* unknown gid */
  159. #ifdef DEBUG
  160.                     printf("do_gadget_up: unknown gadget_id...ERROR = TRUE!\n");
  161. #endif
  162.                     error = TRUE;
  163.                     break;
  164.                 }
  165.             }
  166.         }
  167.         else
  168.         {
  169.             error = TRUE;
  170.         } 
  171.     } 
  172.     else
  173.     {
  174.     error = TRUE;
  175.     } 
  176.  
  177. #ifdef DEBUG
  178.     printf("do_gadget_up: exiting...\n");
  179. #endif
  180.  
  181.     return(error);
  182. }
  183.  
  184. dots(vp,rp)
  185. struct ViewPort *vp;
  186. struct RastPort *rp;
  187. {
  188. #ifdef DEBUG
  189.     printf("rp=%lx\n",rp);
  190. #endif
  191.     lbnc(rp);
  192. }
  193.  
  194. struct BitMap bm;    /* assume initialized to 0 */
  195.  
  196. main()
  197. {
  198.     int i;
  199.  
  200.     GfxBase = OpenLibrary("graphics.library",32);
  201.  
  202.     if (AvailMem(MEMF_CHIP) < 100000)    /* for eentsy machines */
  203.     {
  204.         HEIGHT = 256;
  205.         WIDTH = 640;
  206.     }
  207.  
  208.     InitBitMap(&bm,DEPTH,WIDTH,HEIGHT);
  209.  
  210.     for(i = 0; i< DEPTH ; i++)
  211.     {
  212.         if ( (bm.Planes[i] = (PLANEPTR)AllocRaster(WIDTH,HEIGHT)) == 0)
  213.         {
  214.  
  215. #ifdef DEBUG
  216.             printf("no mem for bitmap\n");
  217. #endif
  218.             for (i = 0; i< DEPTH; i++)
  219.             {
  220.                 if (bm.Planes[i])    
  221.                 {
  222.                     FreeRaster(bm.Planes[i],WIDTH,HEIGHT);
  223.                 }
  224.             }
  225.             CloseLibrary(GfxBase);
  226.             exit();
  227.         }
  228.         else    
  229.         {
  230.             BltClear(bm.Planes[i],RASSIZE(WIDTH,HEIGHT));
  231.         }
  232.     }
  233.  
  234.     startgfx(200,100,50,100,DEPTH,0,dots,"Lines Window",
  235.         GIMMEZEROZERO|SMART_REFRESH|SUPER_BITMAP,&bm);
  236.  
  237.     for(i = 0; i< DEPTH ; i++)
  238.     {
  239.         FreeRaster(bm.Planes[i],WIDTH,HEIGHT);
  240.     }
  241.  
  242.     CloseLibrary(GfxBase);
  243.  
  244. }
  245.  
  246.