home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / c / xaes_new / popup.c < prev    next >
C/C++ Source or Header  |  1994-09-27  |  12KB  |  396 lines

  1. /********************************************************************
  2.  *                                                                0.20*
  3.  *    Popup menu bars for inside dialog boxes and dropside menus        *
  4.  *    by Ken Hollis                                                    *
  5.  *                                                                    *
  6.  *    Copyright (c) 1994, Bitgate Software.  All Rights Reserved.        *
  7.  *                                                                    *
  8.  *    These are the preliminaries for the actual popup routines.        *
  9.  *    They don't quite work the way I want them to, but after all.    *
  10.  *    They *ARE* the first versions, after all...                        *
  11.  *                                                                    *
  12.  ********************************************************************/
  13.  
  14. #include <tos.h>        /* Standard TOS bindings */
  15. #include <stdio.h>        /* Standard IO bindings */
  16.  
  17. #include "xaes.h"
  18.  
  19. void *dpbuffer;
  20.  
  21. GLOBAL void PPopup_DialXY(OBJECT *srctree, int srcindex, OBJECT *desttree)
  22. {
  23.     int    tx, ty;
  24.     int ox, oy;
  25.  
  26.     desttree->ob_x = srctree->ob_x;
  27.     desttree->ob_y = srctree->ob_y;
  28.  
  29.     objc_offset(srctree, srcindex, &ox, &oy);
  30.  
  31.     desttree->ob_x += ox;
  32.     desttree->ob_y += oy;
  33.  
  34.     desttree->ob_x--;
  35.     desttree->ob_y--;
  36.  
  37.     if ((tx = (desttree->ob_x + desttree->ob_width) - (desk.g_x + desk.g_w)) < 0)
  38.         tx = 0;
  39.     else
  40.         tx += 8;
  41.  
  42.     if (((desttree->ob_y + desttree->ob_height) - (desk.g_y + desk.g_h)) < 0)
  43.         ty = 0;
  44.     else
  45.         ty -= desttree->ob_y + desttree->ob_height;
  46.  
  47.     desttree->ob_x -= tx;
  48.     desttree->ob_y += ty;
  49. }
  50.  
  51. GLOBAL void PDropdown_DialXY(OBJECT *srctree, int srcindex, OBJECT *desttree)
  52. {
  53.     int    tx, ty;
  54.     int ox, oy;
  55.  
  56.     desttree->ob_x = srctree->ob_x;
  57.     desttree->ob_y = srctree->ob_y + srctree->ob_height;
  58.  
  59.     objc_offset(srctree, srcindex, &ox, &oy);
  60.  
  61.     desttree->ob_x += ox;
  62.     desttree->ob_y += oy;
  63.  
  64.     desttree->ob_x--;
  65.     desttree->ob_y -= 2;
  66.  
  67.     if ((tx = (desttree->ob_x + desttree->ob_width) - (desk.g_x + desk.g_w)) < 0)
  68.         tx = 0;
  69.     else
  70.         tx += 8;
  71.  
  72.     if (((desttree->ob_y + desttree->ob_height) - (desk.g_y + desk.g_h)) < 0)
  73.         ty = 0;
  74.     else
  75.         ty -= desttree->ob_y + desttree->ob_height;
  76.  
  77.     desttree->ob_x -= tx;
  78.     desttree->ob_y += ty;
  79. }
  80.  
  81. GLOBAL void PPopup_WinXY(WINDOW *win, int srcindex, OBJECT *desttree)
  82. {
  83.     int    tx, ty;
  84.     GRECT work;
  85.  
  86.     WWindGet(win, WF_WORKXYWH, &work.g_x, &work.g_y, &work.g_w, &work.g_h);
  87.  
  88.     desttree->ob_x = win->tree[srcindex].ob_x + work.g_x;
  89.     desttree->ob_y = win->tree[srcindex].ob_y + work.g_y;
  90.  
  91.     desttree->ob_x--;
  92.     desttree->ob_y--;
  93.  
  94.     if ((tx = (desttree->ob_x + desttree->ob_width) - (desk.g_x + desk.g_w)) < 0)
  95.         tx = 0;
  96.  
  97.     if ((ty = (desttree->ob_y + desttree->ob_height) - (desk.g_y + desk.g_h)) < 0)
  98.         ty = 0;
  99.  
  100.     desttree->ob_x -= tx;
  101.     desttree->ob_y -= ty;
  102. }
  103.  
  104. GLOBAL void PDropdown_WinXY(WINDOW *win, int srcindex, OBJECT *desttree)
  105. {
  106.     int    tx, ty;
  107.     GRECT work;
  108.  
  109.     WWindGet(win, WF_WORKXYWH, &work.g_x, &work.g_y, &work.g_w, &work.g_h);
  110.  
  111.     desttree->ob_x = win->tree[srcindex].ob_x + work.g_x;
  112.     desttree->ob_y = (win->tree[srcindex].ob_y + win->tree[srcindex].ob_height) + work.g_y;
  113.  
  114.     desttree->ob_x--;
  115.     desttree->ob_y -= 2;
  116.  
  117.     if ((tx = (desttree->ob_x + desttree->ob_width) - (desk.g_x + desk.g_w)) < 0)
  118.         tx = 0;
  119.  
  120.     if ((ty = (desttree->ob_y + desttree->ob_height) - (desk.g_y + desk.g_h)) < 0)
  121.         ty = 0;
  122.  
  123.     desttree->ob_x -= tx;
  124.     desttree->ob_y -= ty;
  125. }
  126.  
  127. GLOBAL void PMovePopupCoord(OBJECT *desttree, int x, int y)
  128. {
  129.     int    tx, ty;
  130.  
  131.     desttree->ob_x = x;
  132.     desttree->ob_y = y;
  133.  
  134.     desttree->ob_x--;
  135.     desttree->ob_y--;
  136.  
  137.     if ((tx = (desttree->ob_x + desttree->ob_width) - (desk.g_x + desk.g_w)) < 0)
  138.         tx = 0;
  139.  
  140.     if ((ty = (desttree->ob_y + desttree->ob_height) - (desk.g_y + desk.g_h)) < 0)
  141.         ty = 0;
  142.  
  143.     desttree->ob_x -= tx;
  144.     desttree->ob_y -= ty;
  145.  
  146.     if (desttree->ob_x < desk.g_x)
  147.         desttree->ob_x = desk.g_x;
  148.  
  149.     if (desttree->ob_y < desk.g_y)
  150.         desttree->ob_y = desk.g_y;
  151. }
  152.  
  153. GLOBAL int PDoPopup(WINDOW *win, int index, OBJECT *menu_addr, int show, int x, int y, int w, int h)
  154. {
  155.     int LastOb,CurrOb,work_out[57];
  156.     int button,mx,my,firstbut;
  157.     void *ourbuffer;
  158.     OBJECT *ptr;
  159.     GRECT work;
  160.  
  161.     UNUSED(menu_addr);
  162.     UNUSED(show);
  163.  
  164.     WWindGet(win, WF_WORKXYWH, &work.g_x, &work.g_y, &work.g_w, &work.g_h);
  165.  
  166.     vq_extnd(VDIhandle, 1, work_out);
  167.  
  168.     rsrc_gaddr(R_TREE, index, &ptr);
  169.  
  170.     ourbuffer = scrsave(VDIhandle, ptr->ob_x, ptr->ob_y, ptr->ob_width, ptr->ob_height);
  171.  
  172.     if (x!=0 && y!=0 && w!=0 && h!=0)
  173.         graf_growbox(x + work.g_x, y + work.g_y, w, h, ptr->ob_x, ptr->ob_y, ptr->ob_width, ptr->ob_height);
  174.  
  175.     objc_draw(ptr, 0, 6, ptr->ob_x, ptr->ob_y, ptr->ob_width, ptr->ob_height);
  176.     LastOb = -1;
  177.  
  178.     vq_mouse(VDIhandle,&firstbut,&mx,&my);
  179.  
  180. /*    if (firstbut == 2) {
  181.         while (firstbut==2)
  182.             vq_mouse(VDIhandle, &firstbut, &mx, &my);
  183.  
  184.         firstbut = 0;
  185.     } */
  186.  
  187.     do {
  188.         vq_mouse(VDIhandle,&button,&mx,&my);
  189.         CurrOb = objc_find(ptr, 0, MAX_DEPTH, mx, my);
  190.         if ((CurrOb==-1) && (ptr[LastOb].ob_flags & SELECTABLE) && !(ptr[LastOb].ob_state & DISABLED)) {
  191.             objc_change(ptr,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
  192.             objc_draw(ptr,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h);
  193.             LastOb = -1;
  194.         }
  195.         if ((CurrOb>0) && (LastOb!=CurrOb) && (ptr[LastOb].ob_flags & SELECTABLE) && !(ptr[LastOb].ob_state & DISABLED)) {
  196.             if ((LastOb>0) && !(ptr[LastOb].ob_state & DISABLED)) {
  197.                 objc_change(ptr,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
  198.                 objc_draw(ptr,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h);
  199.             }
  200.             LastOb = -1;
  201.         }
  202.         if ((CurrOb!=LastOb) && (ptr[CurrOb].ob_flags & SELECTABLE) && !(ptr[CurrOb].ob_state & DISABLED)) {
  203.             if ((LastOb>0) && !(ptr[LastOb].ob_state & DISABLED)) {
  204.                 objc_change(ptr,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
  205.                 objc_draw(ptr,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h);
  206.             }
  207.             if ((CurrOb>0) && !(ptr[CurrOb].ob_state & DISABLED)) {
  208.                 objc_change(ptr,CurrOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,SELECTED,1);
  209.                 objc_draw(ptr,CurrOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h);
  210.             }
  211.             LastOb = CurrOb;
  212.         }
  213.     } while(button == firstbut);
  214.  
  215.     if ((LastOb>0) && !(ptr[LastOb].ob_state & DISABLED) && (ptr[LastOb].ob_flags & SELECTABLE)) {
  216.         objc_change(ptr,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
  217.         objc_draw(ptr,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h);
  218.     }
  219.     if ((CurrOb>0) && !(ptr[CurrOb].ob_state & DISABLED) && (ptr[CurrOb].ob_flags & SELECTABLE)) {
  220.         objc_change(ptr,CurrOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
  221.         objc_draw(ptr,CurrOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h);
  222.     }
  223.  
  224.     do {
  225.         vq_mouse(VDIhandle,&button,&mx,&my);
  226.     } while(button);
  227.  
  228.     scrrestore(ourbuffer);
  229.  
  230.     if (x!=0 && y!=0 && w!=0 && h!=0) {
  231.         graf_shrinkbox(x + work.g_x, y + work.g_y, w, h, ptr->ob_x, ptr->ob_y, ptr->ob_width, ptr->ob_height);
  232.         vswr_mode(VDIhandle, MD_XOR);
  233.     }
  234.  
  235.     return(LastOb);
  236. }
  237.  
  238. GLOBAL int PDoPopupAddr(OBJECT *index)
  239. {
  240.     int LastOb,CurrOb,work_out[57];
  241.     int button,mx,my,firstbut,but;
  242.     void *ourbuffer;
  243.  
  244.     vq_extnd(VDIhandle, 1, work_out);
  245.  
  246.     ourbuffer = scrsave(VDIhandle, index->ob_x, index->ob_y, index->ob_width, index->ob_height);
  247.     objc_draw(index, 0, 6, index->ob_x, index->ob_y, index->ob_width, index->ob_height);
  248.     LastOb = -1;
  249.  
  250. /*    if (firstbut == 2) {
  251.         while (firstbut==2)
  252.             vq_mouse(VDIhandle, &firstbut, &mx, &my);
  253.  
  254.         firstbut = 0;
  255.     } */
  256.  
  257.     vq_mouse(VDIhandle,&firstbut,&mx,&my);
  258.  
  259.     but = (firstbut == 1) ? 0 : 1;
  260.  
  261.     do {
  262.         vq_mouse(VDIhandle,&button,&mx,&my);
  263.         CurrOb = objc_find(index, 0, MAX_DEPTH, mx, my);
  264.         if ((CurrOb==-1) && (LastOb!=-1) && (index[LastOb].ob_flags & SELECTABLE) && !(index[LastOb].ob_state & DISABLED)) {
  265.             objc_change(index,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
  266.             LastOb = -1;
  267.         }
  268.         if ((CurrOb>0) && (LastOb!=CurrOb) && (index[LastOb].ob_flags & SELECTABLE) && !(index[LastOb].ob_state & DISABLED)) {
  269.             if ((LastOb>0) && !(index[LastOb].ob_state & DISABLED)) {
  270.                 objc_change(index,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
  271.             }
  272.             LastOb = -1;
  273.         }
  274.         if ((CurrOb!=LastOb) && (index[CurrOb].ob_flags & SELECTABLE) && !(index[CurrOb].ob_state & DISABLED)) {
  275.             if ((LastOb>0) && !(index[LastOb].ob_state & DISABLED)) {
  276.                 objc_change(index,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
  277.             }
  278.             if ((CurrOb>0) && !(index[CurrOb].ob_state & DISABLED)) {
  279.                 objc_change(index,CurrOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,SELECTED,1);
  280.             }
  281.             LastOb = CurrOb;
  282.         }
  283.     } while(button != but);
  284.  
  285.     if ((LastOb>0) && !(index[LastOb].ob_state & DISABLED) && (index[LastOb].ob_flags & SELECTABLE)) {
  286.         objc_change(index,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
  287.         objc_draw(index,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h);
  288.     }
  289.     if ((CurrOb>0) && !(index[CurrOb].ob_state & DISABLED) && (index[CurrOb].ob_flags & SELECTABLE)) {
  290.         objc_change(index,CurrOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
  291.         objc_draw(index,CurrOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h);
  292.     }
  293.  
  294.     do {
  295.         vq_mouse(VDIhandle,&button,&mx,&my);
  296.     } while(button);
  297.  
  298.     scrrestore(ourbuffer);
  299.  
  300.     return(LastOb);
  301. }
  302.  
  303. GLOBAL int PShowPopupDesk(OBJECT *index)
  304. {
  305.     dpbuffer = scrsave(VDIhandle, index->ob_x, index->ob_y, index->ob_width, index->ob_height);
  306.     if (dpbuffer) {
  307.         objc_draw(index, 0, 6, index->ob_x, index->ob_y, index->ob_width, index->ob_height);
  308.         return TRUE;
  309.     } else
  310.         return FALSE;
  311. }
  312.  
  313. GLOBAL int PEndPopupDesk(OBJECT *index)
  314. {
  315.     if (dpbuffer) {
  316.         scrrestore(dpbuffer);
  317.         return TRUE;
  318.     } else {
  319.         form_dial(3, index->ob_x, index->ob_y, index->ob_width, index->ob_height,
  320.                      index->ob_x, index->ob_y, index->ob_width, index->ob_height);
  321.         return FALSE;
  322.     }
  323. }
  324.  
  325. GLOBAL int PDoPopupDeskMenu(OBJECT *index, int *retbtn)
  326. {
  327.     int LastOb,CurrOb;
  328.     int button,mx,my,firstbut;
  329.  
  330.     *retbtn = 0;
  331.     LastOb = -1;
  332.  
  333.     vq_mouse(VDIhandle,&firstbut,&mx,&my);
  334.  
  335. /*    if (firstbut == 2) {
  336.         while (firstbut==2)
  337.             vq_mouse(VDIhandle, &firstbut, &mx, &my);
  338.  
  339.         firstbut = 0;
  340.     } */
  341.  
  342.     do {
  343.         vq_mouse(VDIhandle,&button,&mx,&my);
  344.         CurrOb = objc_find(index, 0, MAX_DEPTH, mx, my);
  345.  
  346.         if (CurrOb==-1) {
  347.             if ((LastOb>0) && !(index[LastOb].ob_state & DISABLED) && (index[LastOb].ob_flags & SELECTABLE)) {
  348.                 objc_change(index,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
  349.                 objc_draw(index,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h);
  350.             }
  351.             if ((CurrOb>0) && !(index[CurrOb].ob_state & DISABLED) && (index[CurrOb].ob_flags & SELECTABLE)) {
  352.                 objc_change(index,CurrOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
  353.                 objc_draw(index,CurrOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h);
  354.             }
  355.  
  356.             *retbtn = FALSE;
  357.             return 0;
  358.         }
  359.         
  360.         if ((CurrOb==-1) && (index[LastOb].ob_flags & SELECTABLE) && !(index[LastOb].ob_state & DISABLED)) {
  361.             objc_change(index,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
  362.             LastOb = -1;
  363.         }
  364.         if ((CurrOb>0) && (LastOb!=CurrOb) && (index[LastOb].ob_flags & SELECTABLE) && !(index[LastOb].ob_state & DISABLED)) {
  365.             if ((LastOb>0) && !(index[LastOb].ob_state & DISABLED)) {
  366.                 objc_change(index,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
  367.             }
  368.             LastOb = -1;
  369.         }
  370.         if ((CurrOb!=LastOb) && (index[CurrOb].ob_flags & SELECTABLE) && !(index[CurrOb].ob_state & DISABLED)) {
  371.             if ((LastOb>0) && !(index[LastOb].ob_state & DISABLED)) {
  372.                 objc_change(index,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
  373.             }
  374.             if ((CurrOb>0) && !(index[CurrOb].ob_state & DISABLED)) {
  375.                 objc_change(index,CurrOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,SELECTED,1);
  376.             }
  377.             LastOb = CurrOb;
  378.         }
  379.     } while(button == firstbut);
  380.  
  381.     if ((LastOb>0) && !(index[LastOb].ob_state & DISABLED) && (index[LastOb].ob_flags & SELECTABLE)) {
  382.         objc_change(index,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
  383.         objc_draw(index,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h);
  384.     }
  385.     if ((CurrOb>0) && !(index[CurrOb].ob_state & DISABLED) && (index[CurrOb].ob_flags & SELECTABLE)) {
  386.         objc_change(index,CurrOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
  387.         objc_draw(index,CurrOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h);
  388.     }
  389.  
  390.     do {
  391.         vq_mouse(VDIhandle,&button,&mx,&my);
  392.     } while(button);
  393.  
  394.     *retbtn = TRUE;
  395.     return(LastOb);
  396. }