home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / progtool / c / egem / source / tool.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-22  |  7.2 KB  |  425 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 vsf_aespattern(int handle, int obx, int oby, int patternindex)
  111. {
  112.     static long aespatterns[] = {
  113.         0x00000000L, 0x00440011L, 0x00550055L, 0x88552288L,
  114.         0x55AA55AAL, 0xAADDAA77L, 0x55FF55FFL, 0xFFFFFFFFL };
  115.  
  116.     unsigned long pat;
  117.     reg int i,j,pattern[16];
  118.     reg char *patptr, *p;
  119.  
  120.     pat = aespatterns[patternindex];
  121.  
  122.     obx &= 3;
  123.     pat >>= obx;
  124.     pat &= 0x0F0F0F0FL;
  125.     pat |= (pat<<4);
  126.  
  127.     oby &= 3;
  128.     pat = (pat<<((4-oby)<<3))|(pat>>(oby<<3));
  129.  
  130.     patptr = (char *) pattern;
  131.     for (i=4;--i>=0;)
  132.     {
  133.         p = (char *) &pat;
  134.         for (j=4;--j>=0;)
  135.         {
  136.             *patptr++ = *p;
  137.             *patptr++ = *p++;
  138.         }
  139.     }
  140.  
  141.     vsf_interior(handle, 4);
  142.     vsf_udpat(handle, pattern, 1);
  143. }
  144.  
  145. void v_aespattern(int ob_x, int ob_y, int pattern)
  146. {
  147.     vsf_aespattern(x_handle, ob_x, ob_y, pattern);
  148.     _finter = 4;
  149. }
  150.  
  151. void _bitblt(OBJECT *tree,MFDB *form,boolean flag)
  152. {
  153.     reg int pxy[8],*ptr=pxy;
  154.     reg int x = tree->ob_x - 3,y = tree->ob_y - 3;
  155.     reg int w = tree->ob_width + 5,h = tree->ob_height + 5;
  156.     
  157.     graf_mouse(M_OFF,NULL);
  158.  
  159.     if (flag)
  160.     {
  161.         *ptr++ = x;
  162.         *ptr++ = y;
  163.         *ptr++ = x + w;
  164.         *ptr++ = y + h;
  165.         *ptr++ = 0;
  166.         *ptr++ = 0;
  167.         *ptr++ = w;
  168.         *ptr   = h;
  169.         vro_cpyfm(x_handle,3,pxy,screen,form);
  170.     }
  171.     else
  172.     {
  173.         *ptr++ = 0;
  174.         *ptr++ = 0;
  175.         *ptr++ = w;
  176.         *ptr++ = h;
  177.         *ptr++ = x;
  178.         *ptr++ = y;
  179.         *ptr++ = x + w;
  180.         *ptr   = y + h;
  181.         vro_cpyfm(x_handle,3,pxy,form,screen);
  182.     }
  183.  
  184.     graf_mouse(M_ON,NULL);
  185. }
  186.  
  187. void _line(int x1,int y1,int x2,int y2)
  188. {
  189.     reg int pxy[4];
  190.     
  191.     pxy[0] = x1;
  192.     pxy[1] = y1;
  193.     pxy[2] = x2;
  194.     pxy[3] = y2;
  195.     v_pline(x_handle,2,pxy);
  196. }
  197.  
  198. void _bar(int x,int y,int w,int h,int interior,int color)
  199. {
  200.     reg int pxy[4];
  201.  
  202.     v_set_fill(color,interior,-1);
  203.  
  204.     pxy[0] = x;
  205.     pxy[1] = y;
  206.     pxy[2] = x + w;
  207.     pxy[3] = y + h;
  208.     v_bar(x_handle,pxy);
  209. }
  210.  
  211. void _rectangle(int sx,int sy,int dx,int dy)
  212. {
  213.     reg int pxy[10];
  214.  
  215.     pxy[0] = pxy[6] = pxy[8] = sx;
  216.     pxy[1] = pxy[3] = pxy[9] = sy;
  217.     pxy[2] = pxy[4] = dx;
  218.     pxy[5] = pxy[7] = dy;
  219.     v_pline(x_handle,5,pxy);
  220. }
  221.  
  222. void _beg_ctrl()
  223. {
  224.     wind_update(BEG_UPDATE);
  225.     wind_update(BEG_MCTRL);
  226. }
  227.  
  228. void _end_ctrl()
  229. {
  230.     wind_update(END_MCTRL);
  231.     wind_update(END_UPDATE);
  232. }
  233.  
  234. int _mouse_but(void)
  235. {
  236.     int but,dummy;
  237.  
  238.     if (!_back_win)
  239.         graf_mkstate(&dummy,&dummy,&but,&dummy);
  240.     else
  241.         vq_mouse(x_handle,&but,&dummy,&dummy);
  242.  
  243.     return(but);
  244. }
  245.  
  246. void _mouse_pos(reg int *x,reg int *y)
  247. {
  248.     int dummy;
  249.     graf_mkstate(x,y,&dummy,&dummy);
  250. }
  251.  
  252. void _no_click()
  253. {
  254.     int dummy;
  255.     if (_mouse_but() & 1)
  256.         evnt_button(1,1,0,&dummy,&dummy,&dummy,&dummy);
  257. }
  258.  
  259. /*************************/
  260.  
  261. int min(int v_1,int v_2)
  262. {
  263.     if (v_1<v_2)
  264.         return(v_1);
  265.     else
  266.         return(v_2);
  267. }
  268.  
  269. int max(int v_1,int v_2)
  270. {
  271.     if (v_1>v_2)
  272.         return(v_1);
  273.     else
  274.         return(v_2);
  275. }
  276.  
  277. void Min(int *var,int val)
  278. {
  279.     if (*var>val)
  280.         *var = val;
  281. }
  282.  
  283. void Max(int *var,int val)
  284. {
  285.     if (*var<val)
  286.         *var = val;
  287. }
  288.  
  289. int scan_2_ascii(int scan,int state)
  290. {
  291.     reg long old_stack;
  292.     reg KEYTAB *keytab = Keytbl((void *) -1l,(void *) -1l,(void *) -1l);
  293.  
  294.     if (state)
  295.     {
  296.         scan = (int) (((unsigned) scan)>>8);
  297.         if ((scan>=120) && (scan<=131))
  298.             scan -= 118;
  299.  
  300.         old_stack = (long) Super(NULL);
  301.         if (state & 3)
  302.             scan = (int) *(keytab->shift+scan);
  303.         else
  304.             scan = (int) *(keytab->unshift+scan);
  305.         Super((void *) old_stack);
  306.     }
  307.  
  308.     scan &= 0xff;
  309.     if (scan>='a')
  310.     {
  311.         if (scan<='z')
  312.             scan -= 32;
  313.         else if (scan=='ä')
  314.             scan='Ä';
  315.         else if (scan=='ö')
  316.             scan='Ö';
  317.         else if (scan=='ü')
  318.             scan='Ü';
  319.     }
  320.     return(scan);
  321. }
  322.  
  323. void mfdb(MFDB *fm,int *adr,int w,int h,int st,int pl)
  324. {
  325.     fm->fd_addr        = adr;
  326.     fm->fd_w        = (w+15) & 0xfff0;
  327.     fm->fd_h        = h;
  328.     fm->fd_wdwidth    = fm->fd_w>>4;
  329.     fm->fd_stand    = st;
  330.     fm->fd_nplanes    = pl;
  331. }
  332.  
  333. long mfdb_size(MFDB *fm)
  334. {
  335.     return ((long) (fm->fd_wdwidth<<1) * (long) fm->fd_h * (long) fm->fd_nplanes);
  336. }
  337.  
  338. int Event_Multi(EVENT *event,long last)
  339. {
  340.     reg int events;
  341.     clock_t timer;
  342.  
  343.     if (event->ev_mflags & MU_TIMER)
  344.     {
  345.         clock_t interval;
  346.  
  347.         interval = event->ev_mthicount;
  348.         interval <<= 16;
  349.         interval |= event->ev_mtlocount;
  350.         interval /= 5;
  351.  
  352.         if (last>0)
  353.             timer = last + interval;
  354.         else
  355.             timer = clock() + interval;
  356.     }
  357.  
  358.     do
  359.     {
  360.          events = EvntMulti(event);
  361.  
  362.         if ((events & MU_BUTTON) && _back_win && !event->ev_mbstate && !_bevent)
  363.         {
  364.             if (_mouse_but() & event->ev_bmask)
  365.                 events &= ~MU_BUTTON;
  366.         }
  367.  
  368.         if ((event->ev_mflags & MU_TIMER) && !(events & MU_TIMER) && clock()>=timer)
  369.             events |= MU_TIMER;
  370.     } while(!events);
  371.  
  372.     return (events);
  373. }
  374.  
  375. void rc_sc_clear(GRECT *dest)
  376. {
  377.     rc_sc_copy(dest,dest->g_x,dest->g_y,0);
  378. }
  379.  
  380. void rc_sc_invert(GRECT *dest)
  381. {
  382.     rc_sc_copy(dest,dest->g_x,dest->g_y,D_INVERT);
  383. }
  384.  
  385. void rc_sc_copy(GRECT *source,int dx,int dy,int mode)
  386. {
  387.     reg GRECT work = *source;
  388.  
  389.     if (rc_intersect(&desk,&work))
  390.     {
  391.         reg GRECT dest;
  392.  
  393.         dest.g_x = dx;
  394.         dest.g_y = dy;
  395.         dest.g_w = work.g_w;
  396.         dest.g_h = work.g_h;
  397.         
  398.         if (rc_intersect(&desk,&dest))
  399.         {
  400.             reg int pxy[8];
  401.  
  402.             rc_grect_to_array(&work,pxy);
  403.             rc_grect_to_array(&dest,pxy+4);
  404.             vro_cpyfm(x_handle,mode,pxy,screen,screen);
  405.         }
  406.     }
  407. }
  408.  
  409. void save_clipping(int *area)
  410. {
  411.     reg long *clip=(long *) clipping_area;
  412.  
  413.     *((long *) area)++ = *clip++;
  414.     *((long *) area)++ = *clip++;
  415. }
  416.  
  417. void restore_clipping(int *area)
  418. {
  419.     reg long *clip=(long *) clipping_area;
  420.  
  421.     vs_clip(x_handle,1,area);
  422.     *clip++ = *((long *) area)++;
  423.     *clip++ = *((long *) area)++;
  424. }
  425.