home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / gemlib27 / acskel_c next >
Encoding:
Text File  |  1993-07-30  |  7.6 KB  |  301 lines

  1. /*********************************************************************/
  2. /* SAMPLE ACCESSORY SKELETON                          */
  3. /*    started 5/28/85 R.Z.   Copyright ATARI Corp. 1985         */
  4. /*********************************************************************/
  5.  
  6. /*********************************************************************/
  7. /* INCLUDE FILES                             */
  8. /*********************************************************************/
  9.  
  10. #include <gemfast.h>
  11. #include <aesbind.h>
  12. #include <vdibind.h>
  13. #include <osbind.h>
  14.  
  15. /* Gcc convention for accessories */
  16.  
  17. char _stack_heap[1024];
  18. void *_heapbase = (void *)_stack_heap;
  19. long _stksize = sizeof(_stack_heap);
  20.  
  21. /*********************************************************************/
  22. /* DEFINES                                    */
  23. /*********************************************************************/
  24.  
  25. #define TRUE  1
  26. #define FALSE 0
  27.  
  28. #define WI_KIND        (SIZER|MOVER|FULLER|CLOSER|NAME)
  29. #define NO_WINDOW (-1)
  30.  
  31. #define MIN_WIDTH  (2*gl_wbox)
  32. #define MIN_HEIGHT (3*gl_hbox)
  33.  
  34. /*********************************************************************/
  35. /* EXTERNALS                                    */
  36. /*********************************************************************/
  37.  
  38. extern int    gl_apid;
  39.  
  40. /*********************************************************************/
  41. /* GLOBAL VARIABLES                                */
  42. /*********************************************************************/
  43.  
  44. int    gl_hchar;
  45. int    gl_wchar;
  46. int    gl_wbox;
  47. int    gl_hbox;    /* system sizes */
  48.  
  49. int    menu_id ;    /* our menu id */
  50.  
  51. int     phys_handle;    /* physical workstation handle */
  52. int     handle;        /* virtual workstation handle */
  53. int    wi_handle;    /* window handle */
  54. int    top_window;    /* handle of topped window */
  55.  
  56. int    xdesk,ydesk,hdesk,wdesk;
  57. int    xold,yold,hold,wold;
  58. int    xwork,ywork,hwork,wwork;    /* desktop and work areas */
  59.  
  60. int    msgbuff[8];    /* event message buffer */
  61. int    keycode;    /* keycode returned by event-keyboard */
  62. int    mx,my;        /* mouse x and y pos. */
  63. int    butdown;    /* button state tested for, UP/DOWN */
  64. int    ret;        /* dummy return variable */
  65.  
  66. int    hidden;        /* current state of cursor */
  67.  
  68. int    fulled;        /* current state of window */
  69.  
  70. int work_in[11];    /* Input to GSX parameter array */
  71. int work_out[57];    /* Output from GSX parameter array */
  72. int pxyarray[10];    /* input point array */
  73.  
  74. /****************************************************************/
  75. /*  GSX UTILITY ROUTINES.                    */
  76. /****************************************************************/
  77.  
  78. hide_mouse()
  79. {
  80.     if(! hidden){
  81.         graf_mouse(M_OFF,0x0L);
  82.         hidden=TRUE;
  83.     }
  84. }
  85.  
  86. show_mouse()
  87. {
  88.     if(hidden){
  89.         graf_mouse(M_ON,0x0L);
  90.         hidden=FALSE;
  91.     }
  92. }
  93.  
  94. /****************************************************************/
  95. /* open virtual workstation                    */
  96. /****************************************************************/
  97. open_vwork()
  98. {
  99. int i;
  100.     for(i=1;i<10;work_in[i++]=1);
  101.     work_in[0]=Getrez()+2;
  102.     work_in[10]=2;
  103.     handle=phys_handle;
  104.     v_opnvwk(work_in,&handle,work_out);
  105. }
  106.  
  107. /****************************************************************/
  108. /* set clipping rectangle                    */
  109. /****************************************************************/
  110. set_clip(x,y,w,h)
  111. int x,y,w,h;
  112. {
  113. int clip[4];
  114.     clip[0]=x;
  115.     clip[1]=y;
  116.     clip[2]=x+w;
  117.     clip[3]=y+h;
  118.     vs_clip(handle,1,clip);
  119. }
  120.  
  121. /****************************************************************/
  122. /* open window                            */
  123. /****************************************************************/
  124. open_window()
  125. {
  126.     wi_handle=wind_create(WI_KIND,xdesk,ydesk,wdesk,hdesk);
  127.     wind_set(wi_handle, WF_NAME," IMA SAMPLE ",0,0);
  128.     graf_growbox(xdesk+wdesk/2,ydesk+hdesk/2,gl_wbox,gl_hbox,xdesk,ydesk,wdesk,hdesk);
  129.     wind_open(wi_handle,xdesk,ydesk,wdesk,hdesk);
  130.     wind_get(wi_handle,WF_WORKXYWH,&xwork,&ywork,&wwork,&hwork);
  131. }
  132.  
  133. /****************************************************************/
  134. /* find and redraw all clipping rectangles            */
  135. /****************************************************************/
  136. do_redraw(xc,yc,wc,hc)
  137. int xc,yc,wc,hc;
  138. {
  139. GRECT t1,t2;
  140.  
  141.     hide_mouse();
  142.     wind_update(TRUE);
  143.     t2.g_x=xc;
  144.     t2.g_y=yc;
  145.     t2.g_w=wc;
  146.     t2.g_h=hc;
  147.     wind_get(wi_handle,WF_FIRSTXYWH,&t1.g_x,&t1.g_y,&t1.g_w,&t1.g_h);
  148.     while (t1.g_w && t1.g_h) {
  149.       if (rc_intersect(&t2,&t1)) {
  150.         set_clip(t1.g_x,t1.g_y,t1.g_w,t1.g_h);
  151.         draw_sample();
  152.       }
  153.       wind_get(wi_handle,WF_NEXTXYWH,&t1.g_x,&t1.g_y,&t1.g_w,&t1.g_h);
  154.     }
  155.     wind_update(FALSE);
  156.     show_mouse();
  157. }
  158.  
  159. /****************************************************************/
  160. /*        Accessory Init. Until First Event_Multi        */
  161. /****************************************************************/
  162. main()
  163. {
  164.     appl_init();
  165.     phys_handle=graf_handle(&gl_wchar,&gl_hchar,&gl_wbox,&gl_hbox);
  166. #ifdef __MSHORT__
  167.     menu_id=menu_register(gl_apid,"      Sample Acc16");
  168. #else
  169.     menu_id=menu_register(gl_apid,"      Sample Acc32");
  170. #endif
  171.     wind_get(0, WF_WORKXYWH, &xdesk, &ydesk, &wdesk, &hdesk);
  172.  
  173.     wi_handle=NO_WINDOW;
  174.     hidden=FALSE;
  175.     fulled=FALSE;
  176.     butdown=TRUE;
  177.  
  178.     multi();
  179. }
  180.  
  181.  
  182. /****************************************************************/
  183. /* dispatches all accessory tasks                */
  184. /****************************************************************/
  185. multi()
  186. {
  187. int event;
  188.  
  189.       while (TRUE) {
  190.     event = evnt_multi(MU_MESAG | MU_BUTTON | MU_KEYBD,
  191.             1,1,butdown,
  192.             0,0,0,0,0,
  193.             0,0,0,0,0,
  194.             msgbuff,0L,&mx,&my,&ret,&ret,&keycode,&ret);
  195.  
  196.     wind_update(TRUE);
  197.     wind_get(wi_handle,WF_TOP,&top_window,&ret,&ret,&ret);
  198.  
  199.     if (event & MU_MESAG)
  200.       switch (msgbuff[0]) {
  201.  
  202.       case WM_REDRAW:
  203.         if (msgbuff[3] == wi_handle)
  204.           do_redraw(msgbuff[4],msgbuff[5],msgbuff[6],msgbuff[7]);
  205.         break;
  206.  
  207.       case WM_NEWTOP:
  208.       case WM_TOPPED:
  209.         if (msgbuff[3] == wi_handle){
  210.           wind_set(wi_handle,WF_TOP,0,0,0,0);}
  211.         break;
  212.  
  213.       case AC_CLOSE:
  214.         if((msgbuff[3] == menu_id)&&(wi_handle != NO_WINDOW)){
  215.           v_clsvwk(handle);
  216.           wi_handle = NO_WINDOW;
  217.         }
  218.         break;
  219.  
  220.       case WM_CLOSED:
  221.         if(msgbuff[3] == wi_handle){
  222.           wind_close(wi_handle);
  223.           graf_shrinkbox(xwork+wwork/2,ywork+hwork/2,gl_wbox,gl_hbox,xwork,ywork,wwork,hwork);
  224.           wind_delete(wi_handle);
  225.           v_clsvwk(handle);
  226.           wi_handle = NO_WINDOW;
  227.         }
  228.         break;
  229.  
  230.       case WM_SIZED:
  231.       case WM_MOVED:
  232.         if(msgbuff[3] == wi_handle){
  233.         if(msgbuff[6]<MIN_WIDTH)msgbuff[6]=MIN_WIDTH;
  234.         if(msgbuff[7]<MIN_HEIGHT)msgbuff[7]=MIN_HEIGHT;
  235.         wind_set(wi_handle,WF_CURRXYWH,msgbuff[4],msgbuff[5],msgbuff[6],msgbuff[7]);
  236.         wind_get(wi_handle,WF_WORKXYWH,&xwork,&ywork,&wwork,&hwork);
  237.         }
  238.         break;
  239.  
  240.       case AC_OPEN:
  241.         if (msgbuff[4] == menu_id){
  242.           if(wi_handle == NO_WINDOW){
  243.         open_vwork();
  244.             open_window();
  245.           }
  246.           else    /* if already opened, for user convenience */
  247.             wind_set(wi_handle,WF_TOP,0,0,0,0);
  248.         }
  249.         break;
  250.  
  251.       case WM_FULLED:
  252.         if(fulled){
  253.         wind_calc(WC_WORK,WI_KIND,xold,yold,wold,hold,
  254.                 &xwork,&ywork,&wwork,&hwork);
  255.         wind_set(wi_handle,WF_CURRXYWH,xold,yold,wold,hold);}
  256.         else{
  257.         wind_calc(WC_BORDER,WI_KIND,xwork,ywork,wwork,hwork,
  258.                 &xold,&yold,&wold,&hold);
  259.         wind_calc(WC_WORK,WI_KIND,xdesk,ydesk,wdesk,hdesk,
  260.                 &xwork,&ywork,&wwork,&hwork);
  261.         wind_set(wi_handle,WF_CURRXYWH,xdesk,ydesk,wdesk,hdesk);
  262.         }
  263.         fulled ^= TRUE;
  264.         break;
  265.  
  266.       } /* switch (msgbuff[0]) */
  267.  
  268.     if ((event & MU_BUTTON)&&(wi_handle == top_window))
  269.       if(butdown) butdown = FALSE;
  270.       else butdown = TRUE;
  271.  
  272.       if(event & MU_KEYBD){
  273.          do_redraw(xwork,ywork,wwork,hwork);
  274.       }
  275.     
  276.     wind_update(FALSE);
  277.  
  278.       } /* while (TRUE) */
  279.  
  280. }
  281.  
  282. /****************************************************************/
  283. /* Draw Filled Ellipse.                        */
  284. /****************************************************************/
  285. draw_sample()
  286. {
  287. int temp[4];
  288.     vsf_interior(handle,2);
  289.     vsf_style(handle,8);
  290.     vsf_color(handle,0);
  291.     temp[0]=xwork;
  292.     temp[1]=ywork;
  293.     temp[2]=xwork+wwork-1;
  294.     temp[3]=ywork+hwork-1;
  295.     v_bar(handle,temp);        /* blank the interior */
  296.     vsf_interior(handle,4);
  297.     vsf_color(handle,1);
  298.     v_ellipse(handle,xwork+wwork/2,ywork+hwork/2,wwork/2,hwork/2);
  299. }
  300.  
  301.