home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / c / e_gem140 / source / tool.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-05  |  6.3 KB  |  381 lines

  1.  
  2. #include <time.h>
  3. #include "proto.h"
  4.  
  5. static int clipping_area[4];
  6.  
  7. char _upper(char ch)
  8. {
  9.     if (ch>='a')
  10.     {
  11.         if(ch>'z')
  12.         {
  13.             if (ch=='ä')
  14.                 return('Ä');
  15.             else if (ch=='ö')
  16.                 return('Ö');
  17.             else if (ch=='ü')
  18.                 return('Ü');
  19.         }
  20.         else
  21.             return(ch-32);
  22.     }
  23.  
  24.     return(ch);
  25. }
  26.  
  27. char _lower(char ch)
  28. {
  29.     if (ch>='A')
  30.     {
  31.         if(ch>'Z')
  32.         {
  33.             if (ch=='Ä')
  34.                 return('ä');
  35.             else if (ch=='Ö')
  36.                 return('ö');
  37.             else if (ch=='Ü')
  38.                 return('ü');
  39.         }
  40.         else
  41.             return(ch+32);
  42.     }
  43.  
  44.     return(ch);
  45. }
  46.  
  47. static int _mode,_lwidth,_lcolor,_fcolor,_finter,_fstyle,_tfont,_theight,_tcolor;
  48.  
  49. void vs_attr(void)
  50. {
  51.     _mode = _lwidth = _lcolor = _fcolor = _finter = _fstyle = _tfont = _theight = _tcolor = -1;
  52. }
  53.  
  54. void _vdi_attr(int mode,int wid,int col)
  55. {
  56.     v_set_mode(mode);
  57.     v_set_line(col,wid);
  58. }
  59.  
  60. void v_set_text(int font,int height,int color,int *out)
  61. {
  62.     if (font!=_tfont)
  63.         vst_font(x_handle,_tfont=font);
  64.  
  65.     if (out!=NULL || height!=_theight)
  66.     {
  67.         int dummy[4];
  68.  
  69.         if (out==NULL)
  70.             out = dummy;
  71.  
  72.         if (height>0)
  73.             vst_height(x_handle,height,&out[0],&out[1],&out[2],&out[3]);
  74.         else
  75.             vst_point(x_handle,-height,&out[0],&out[1],&out[2],&out[3]);
  76.         _theight = height;
  77.     }
  78.  
  79.     if (color!=_tcolor)
  80.         vst_color(x_handle,_tcolor = color);
  81. }
  82.  
  83. void v_set_mode(int mode)
  84. {
  85.     if (mode>=0 && mode!=_mode)
  86.         vswr_mode(x_handle,_mode=mode);
  87. }
  88.  
  89. void v_set_line(int color,int width)
  90. {
  91.     if (width>=0 && width!=_lwidth)
  92.         vsl_width(x_handle,_lwidth=width);
  93.  
  94.     if (color>=0 && color!=_lcolor)
  95.         vsl_color(x_handle,_lcolor=color);
  96. }
  97.  
  98. void v_set_fill(int color,int inter,int style)
  99. {
  100.     if (color>=0 && color!=_fcolor)
  101.         vsf_color(x_handle,_fcolor=color);
  102.  
  103.     if (inter>=0 && inter!=_finter)
  104.         vsf_interior(x_handle,_finter=inter);
  105.  
  106.     if (style>=0 && style!=_fstyle)
  107.         vsf_style(x_handle,_fstyle=style);
  108. }
  109.  
  110. void _bitblt(OBJECT *tree,MFDB *form,boolean flag)
  111. {
  112.     reg int pxy[8],*ptr=pxy;
  113.     reg int x = tree->ob_x - 3,y = tree->ob_y - 3;
  114.     reg int w = tree->ob_width + 5,h = tree->ob_height + 5;
  115.     
  116.     graf_mouse(M_OFF,NULL);
  117.  
  118.     if (flag)
  119.     {
  120.         *ptr++ = x;
  121.         *ptr++ = y;
  122.         *ptr++ = x + w;
  123.         *ptr++ = y + h;
  124.         *ptr++ = 0;
  125.         *ptr++ = 0;
  126.         *ptr++ = w;
  127.         *ptr   = h;
  128.         vro_cpyfm(x_handle,3,pxy,screen,form);
  129.     }
  130.     else
  131.     {
  132.         *ptr++ = 0;
  133.         *ptr++ = 0;
  134.         *ptr++ = w;
  135.         *ptr++ = h;
  136.         *ptr++ = x;
  137.         *ptr++ = y;
  138.         *ptr++ = x + w;
  139.         *ptr   = y + h;
  140.         vro_cpyfm(x_handle,3,pxy,form,screen);
  141.     }
  142.  
  143.     graf_mouse(M_ON,NULL);
  144. }
  145.  
  146. void _line(int x1,int y1,int x2,int y2)
  147. {
  148.     reg int pxy[4];
  149.     
  150.     pxy[0] = x1;
  151.     pxy[1] = y1;
  152.     pxy[2] = x2;
  153.     pxy[3] = y2;
  154.     v_pline(x_handle,2,pxy);
  155. }
  156.  
  157. void _bar(int x,int y,int w,int h,int interior,int color)
  158. {
  159.     reg int pxy[4];
  160.  
  161.     v_set_fill(color,interior,-1);
  162.  
  163.     pxy[0] = x;
  164.     pxy[1] = y;
  165.     pxy[2] = x + w;
  166.     pxy[3] = y + h;
  167.     v_bar(x_handle,pxy);
  168. }
  169.  
  170. void _rectangle(int sx,int sy,int dx,int dy)
  171. {
  172.     reg int pxy[10];
  173.  
  174.     pxy[0] = pxy[6] = pxy[8] = sx;
  175.     pxy[1] = pxy[3] = pxy[9] = sy;
  176.     pxy[2] = pxy[4] = dx;
  177.     pxy[5] = pxy[7] = dy;
  178.     v_pline(x_handle,5,pxy);
  179. }
  180.  
  181. void _beg_ctrl()
  182. {
  183.     wind_update(BEG_UPDATE);
  184.     wind_update(BEG_MCTRL);
  185. }
  186.  
  187. void _end_ctrl()
  188. {
  189.     wind_update(END_MCTRL);
  190.     wind_update(END_UPDATE);
  191. }
  192.  
  193. int _mouse_but(void)
  194. {
  195.     int but,dummy;
  196.  
  197.     if (!_back_win)
  198.         graf_mkstate(&dummy,&dummy,&but,&dummy);
  199.     else
  200.         vq_mouse(x_handle,&but,&dummy,&dummy);
  201.  
  202.     return(but);
  203. }
  204.  
  205. void _mouse_pos(reg int *x,reg int *y)
  206. {
  207.     int dummy;
  208.     graf_mkstate(x,y,&dummy,&dummy);
  209. }
  210.  
  211. void _no_click()
  212. {
  213.     int dummy;
  214.     if (_mouse_but() & 1)
  215.         evnt_button(1,1,0,&dummy,&dummy,&dummy,&dummy);
  216. }
  217.  
  218. /*************************/
  219.  
  220. int min(int v_1,int v_2)
  221. {
  222.     if (v_1<v_2)
  223.         return(v_1);
  224.     else
  225.         return(v_2);
  226. }
  227.  
  228. int max(int v_1,int v_2)
  229. {
  230.     if (v_1>v_2)
  231.         return(v_1);
  232.     else
  233.         return(v_2);
  234. }
  235.  
  236. void Min(int *var,int val)
  237. {
  238.     if (*var>val)
  239.         *var = val;
  240. }
  241.  
  242. void Max(int *var,int val)
  243. {
  244.     if (*var<val)
  245.         *var = val;
  246. }
  247.  
  248. int scan_2_ascii(int scan,int state)
  249. {
  250.     reg KEYTAB *keytab = Keytbl((void *) -1l,(void *) -1l,(void *) -1l);
  251.  
  252.     if (state)
  253.     {
  254.         scan = (int) (((unsigned) scan)>>8);
  255.         if ((scan>=120) && (scan<=131))
  256.             scan -= 118;
  257.  
  258.         if (state & 3)
  259.             scan = (int) *(keytab->shift+scan);
  260.         else
  261.             scan = (int) *(keytab->unshift+scan);
  262.     }
  263.  
  264.     scan &= 0xff;
  265.     if (scan>='a')
  266.     {
  267.         if (scan<='z')
  268.             scan -= 32;
  269.         else if (scan=='ä')
  270.             scan='Ä';
  271.         else if (scan=='ö')
  272.             scan='Ö';
  273.         else if (scan=='ü')
  274.             scan='Ü';
  275.     }
  276.     return(scan);
  277. }
  278.  
  279. void mfdb(MFDB *fm,int *adr,int w,int h,int st,int pl)
  280. {
  281.     fm->fd_addr        = adr;
  282.     fm->fd_w        = (w+15) & 0xfff0;
  283.     fm->fd_h        = h;
  284.     fm->fd_wdwidth    = fm->fd_w>>4;
  285.     fm->fd_stand    = st;
  286.     fm->fd_nplanes    = pl;
  287. }
  288.  
  289. long mfdb_size(MFDB *fm)
  290. {
  291.     return ((long) (fm->fd_wdwidth<<1) * (long) fm->fd_h * (long) fm->fd_nplanes);
  292. }
  293.  
  294. int Event_Multi(EVENT *event,long last)
  295. {
  296.     reg int events;
  297.     clock_t timer;
  298.  
  299.     if (event->ev_mflags & MU_TIMER)
  300.     {
  301.         clock_t interval;
  302.  
  303.         interval = event->ev_mthicount;
  304.         interval <<= 16;
  305.         interval |= event->ev_mtlocount;
  306.         interval /= 5;
  307.  
  308.         if (last>0)
  309.             timer = last + interval;
  310.         else
  311.             timer = clock() + interval;
  312.     }
  313.  
  314.     do
  315.     {
  316.          events = EvntMulti(event);
  317.  
  318.         if ((events & MU_BUTTON) && _back_win && !event->ev_mbstate && !_bevent)
  319.         {
  320.             if (_mouse_but() & event->ev_bmask)
  321.                 events &= ~MU_BUTTON;
  322.         }
  323.  
  324.         if ((event->ev_mflags & MU_TIMER) && !(events & MU_TIMER) && clock()>=timer)
  325.             events |= MU_TIMER;
  326.     } while(!events);
  327.  
  328.     return (events);
  329. }
  330.  
  331. void rc_sc_clear(GRECT *dest)
  332. {
  333.     rc_sc_copy(dest,dest->g_x,dest->g_y,0);
  334. }
  335.  
  336. void rc_sc_invert(GRECT *dest)
  337. {
  338.     rc_sc_copy(dest,dest->g_x,dest->g_y,D_INVERT);
  339. }
  340.  
  341. void rc_sc_copy(GRECT *source,int dx,int dy,int mode)
  342. {
  343.     reg GRECT work = *source;
  344.  
  345.     if (rc_intersect(&desk,&work))
  346.     {
  347.         reg GRECT dest;
  348.  
  349.         dest.g_x = dx;
  350.         dest.g_y = dy;
  351.         dest.g_w = work.g_w;
  352.         dest.g_h = work.g_h;
  353.         
  354.         if (rc_intersect(&desk,&dest))
  355.         {
  356.             reg int pxy[8];
  357.  
  358.             rc_grect_to_array(&work,pxy);
  359.             rc_grect_to_array(&dest,pxy+4);
  360.             vro_cpyfm(x_handle,mode,pxy,screen,screen);
  361.         }
  362.     }
  363. }
  364.  
  365. void save_clipping(int *area)
  366. {
  367.     reg long *clip=(long *) clipping_area;
  368.  
  369.     *((long *) area)++ = *clip++;
  370.     *((long *) area)++ = *clip++;
  371. }
  372.  
  373. void restore_clipping(int *area)
  374. {
  375.     reg long *clip=(long *) clipping_area;
  376.  
  377.     vs_clip(x_handle,1,area);
  378.     *clip++ = *((long *) area)++;
  379.     *clip++ = *((long *) area)++;
  380. }
  381.