home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Programming / ace_gpl_release / src_ansi / ace / c / gadget.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-05  |  7.1 KB  |  372 lines

  1. /* << ACE >>
  2.  
  3.    -- Amiga BASIC Compiler --
  4.  
  5.    ** Parser: gadget functions **
  6.    ** Copyright (C) 1998 David Benn
  7.    ** 
  8.    ** This program is free software; you can redistribute it and/or
  9.    ** modify it under the terms of the GNU General Public License
  10.    ** as published by the Free Software Foundation; either version 2
  11.    ** of the License, or (at your option) any later version.
  12.    **
  13.    ** This program is distributed in the hope that it will be useful,
  14.    ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.    ** GNU General Public License for more details.
  17.    **
  18.    ** You should have received a copy of the GNU General Public License
  19.    ** along with this program; if not, write to the Free Software
  20.    ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  21.  
  22.    Author: David J Benn
  23.    Date: 1st,2nd,6th November 1993,
  24.    23rd-25th June 1994,
  25.    10th,12th July 1994,
  26.    12th March 1995,
  27.    6th November 1995
  28.  */
  29.  
  30. #include "acedef.h"
  31.  
  32. /* externals */
  33. extern int sym;
  34. extern int lastsym;
  35.  
  36. /* functions */
  37. void gadget_rectangle (void)
  38. {
  39. /* (x1,y1)-(x2,y2) */
  40.  
  41.   if (sym != lparen)
  42.     _error (14);
  43.   else
  44.     {
  45.       insymbol ();
  46.       make_sure_long (expr ());    /* x1 */
  47.  
  48.       if (sym != comma)
  49.     _error (16);
  50.       else
  51.     {
  52.       insymbol ();
  53.       make_sure_long (expr ());    /* y1 */
  54.  
  55.       if (sym != rparen)
  56.         _error (9);
  57.       else
  58.         {
  59.           insymbol ();
  60.           if (sym != minus)
  61.         _error (21);
  62.           else
  63.         {
  64.           insymbol ();
  65.           if (sym != lparen)
  66.             _error (14);
  67.           else
  68.             {
  69.               insymbol ();
  70.               make_sure_long (expr ());        /* x2 */
  71.  
  72.               if (sym != comma)
  73.             _error (16);
  74.               else
  75.             {
  76.               insymbol ();
  77.               make_sure_long (expr ());    /* y2 */
  78.  
  79.               if (sym != rparen)
  80.                 _error (9);
  81.               insymbol ();
  82.             }
  83.             }
  84.         }
  85.         }
  86.     }
  87.     }
  88. }
  89.  
  90. void close_gadget (void)
  91. {
  92. /* GADGET CLOSE gadget-id */
  93.  
  94.   insymbol ();
  95.   make_sure_long (expr ());    /* gadget-id */
  96.  
  97.   gen ("jsr", "_CloseGadget", "  ");
  98.   gen ("addq", "#4", "sp");
  99.   enter_XREF ("_CloseGadget");
  100. }
  101.  
  102. void gadget_output (void)
  103. {
  104. /*
  105.    ** GADGET OUTPUT id
  106.    **
  107.    ** Make the specified gadget the one from which 
  108.    ** information may be obtained via the GADGET(n)
  109.    ** function. This allows the value of a string,
  110.    ** longint or slider gadget to be obtained at 
  111.    ** any time rather than just when a gadget event
  112.    ** occurs.
  113.  */
  114.   insymbol ();
  115.   make_sure_long (expr ());    /* gadget-id */
  116.  
  117.   gen ("jsr", "_SetCurrentGadget", "  ");
  118.   gen ("addq", "#4", "sp");
  119.   enter_XREF ("_SetCurrentGadget");
  120. }
  121.  
  122. void wait_gadget (void)
  123. {
  124. /* GADGET WAIT gadget-id */
  125.  
  126.   insymbol ();
  127.   make_sure_long (expr ());    /* gadget-id */
  128.  
  129.   gen ("jsr", "_WaitGadget", "  ");
  130.   gen ("addq", "#4", "sp");
  131.   enter_XREF ("_WaitGadget");
  132. }
  133.  
  134. void modify_gadget (void)
  135. {
  136. /* 
  137.    ** GADGET MOD gadget-id,knob-position[,max-position] 
  138.    **
  139.    ** For the modification of (proportional) gadgets.
  140.  */
  141.  
  142.   insymbol ();
  143.   make_sure_long (expr ());    /* gadget-id */
  144.  
  145.   if (sym != comma)
  146.     _error (16);
  147.   else
  148.     {
  149.       insymbol ();
  150.       make_sure_long (expr ());    /* knob-position */
  151.  
  152.       /* specify new maximum notches for slider? */
  153.       if (sym != comma)
  154.     gen ("move.l", "#-1", "-(sp)");
  155.       else
  156.     {
  157.       insymbol ();
  158.       make_sure_long (expr ());    /* max-position */
  159.     }
  160.  
  161.       /* call function */
  162.       gen ("jsr", "_modify_gad", "  ");
  163.       gen ("add.l", "#12", "sp");
  164.  
  165.       enter_XREF ("_modify_gad");
  166.       enter_XREF ("_GfxBase");
  167.     }
  168. }
  169.  
  170. void gadget (void)
  171. {
  172. /* GADGET gadget-id,status[,gadget-value,(x1,y1)-(x2,y2),type[,style][,font,size,txtstyle]]
  173.    GADGET MOD gadget-id,knob-pos[,max-notches]
  174.    GADGET WAIT gadget-id
  175.    GADGET CLOSE gadget-id
  176.    GADGET ON | OFF | STOP
  177.  */
  178.   int gtype;
  179.  
  180.   insymbol ();
  181.  
  182.   if (sym == onsym || sym == offsym || sym == stopsym)
  183.     change_event_trapping_status (lastsym);
  184.   else if (sym == closesym)
  185.     close_gadget ();
  186.   else if (sym == outputsym)
  187.     gadget_output ();
  188.   else if (sym == waitsym)
  189.     wait_gadget ();
  190.   else if (sym == modsym)
  191.     modify_gadget ();
  192.   else
  193.     {
  194.       make_sure_long (expr ());    /* gadget-id */
  195.  
  196.       if (sym != comma)
  197.     _error (16);
  198.       else
  199.     {
  200.       insymbol ();
  201.       if (sym == onsym)
  202.         {
  203.           gen ("move.l", "#1", "-(sp)");
  204.           insymbol ();
  205.         }
  206.       else if (sym == offsym)
  207.         {
  208.           gen ("move.l", "#0", "-(sp)");
  209.           insymbol ();
  210.         }
  211.       else
  212.         {
  213.           /* status */
  214.           make_sure_long (expr ());
  215.         }
  216.  
  217.       if (sym != comma)
  218.         {
  219.           gen ("jsr", "_ChangeGadgetStatus", "  ");
  220.           gen ("addq", "#8", "sp");
  221.  
  222.           enter_XREF ("_ChangeGadgetStatus");
  223.           enter_XREF ("_GfxBase");
  224.           return;
  225.         }
  226.     }
  227.  
  228.       if (sym != comma)
  229.     _error (16);
  230.       else
  231.     {
  232.       insymbol ();
  233.       gtype = expr ();
  234.  
  235.       /* string or integer expression for 3rd parameter */
  236.       if (gtype != stringtype)
  237.         {
  238.           make_sure_long (gtype);
  239.         }
  240.     }
  241.  
  242.       if (sym != comma)
  243.     _error (16);
  244.       else
  245.     {
  246.       insymbol ();
  247.       gadget_rectangle ();    /* (x1,y1)-(x2,y2) */
  248.  
  249.       if (sym != comma)
  250.         _error (16);
  251.       else
  252.         {
  253.           /* 
  254.              ** Gadget Type.
  255.            */
  256.           insymbol ();
  257.  
  258.           if (sym == buttonsym)
  259.         {
  260.           gen ("move.l", "#1", "-(sp)");
  261.           insymbol ();
  262.         }
  263.           else if (sym == stringsym)
  264.         {
  265.           gen ("move.l", "#2", "-(sp)");
  266.           insymbol ();
  267.         }
  268.           else if (sym == longintsym)
  269.         {
  270.           gen ("move.l", "#3", "-(sp)");
  271.           insymbol ();
  272.         }
  273.           else if (sym == potxsym)
  274.         {
  275.           gen ("move.l", "#4", "-(sp)");
  276.           insymbol ();
  277.         }
  278.           else if (sym == potysym)
  279.         {
  280.           gen ("move.l", "#5", "-(sp)");
  281.           insymbol ();
  282.         }
  283.           else
  284.         {
  285.           /* type */
  286.           make_sure_long (expr ());
  287.         }
  288.         }
  289.  
  290.       /*
  291.          ** Optional gadget style parameter.
  292.        */
  293.       if (sym != comma)
  294.         gen ("move.l", "#0", "-(sp)");    /* style = 0 */
  295.       else
  296.         {
  297.           insymbol ();
  298.  
  299.           if (sym != comma)
  300.         make_sure_long (expr ());    /* style */
  301.           else
  302.         gen ("move.l", "#0", "-(sp)");    /* style = 0 */
  303.         }
  304.  
  305.       /*
  306.          ** Optional font and font-size parameters (for button).
  307.        */
  308.       if (sym != comma)
  309.         {
  310.           gen ("move.l", "#0", "-(sp)");    /* font name = NULL */
  311.           gen ("move.l", "#0", "-(sp)");    /* font size = 0 */
  312.           gen ("move.l", "#0", "-(sp)");    /* font style = 0 */
  313.         }
  314.       else
  315.         {
  316.           insymbol ();
  317.           if (expr () != stringtype)    /* font name */
  318.         _error (4);
  319.           else
  320.         {
  321.           if (sym != comma)
  322.             _error (16);
  323.           else
  324.             {
  325.               insymbol ();
  326.               make_sure_long (expr ());        /* font size */
  327.             }
  328.  
  329.           if (sym != comma)
  330.             _error (16);
  331.           else
  332.             {
  333.               insymbol ();
  334.               make_sure_long (expr ());        /* font style */
  335.             }
  336.         }
  337.         }
  338.     }
  339.  
  340.       /* call function */
  341.       gen ("jsr", "_CreateGadget", "  ");
  342.       gen ("add.l", "#48", "sp");
  343.  
  344.       enter_XREF ("_CreateGadget");
  345.       enter_XREF ("_GfxBase");
  346.     }
  347. }
  348.  
  349. void bevel_box (void)
  350. {
  351. /* 
  352.    ** BEVELBOX (x1,y1)-(x2,y2),type
  353.  */
  354.   insymbol ();
  355.  
  356.   gadget_rectangle ();
  357.   if (sym != comma)
  358.     _error (16);
  359.   else
  360.     {
  361.       insymbol ();
  362.       make_sure_long (expr ());    /* type */
  363.  
  364.       /* call function */
  365.       gen ("jsr", "_BevelBox", "  ");
  366.       gen ("add.l", "#20", "sp");
  367.  
  368.       enter_XREF ("_BevelBox");
  369.       enter_XREF ("_GfxBase");
  370.     }
  371. }
  372.