home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / clib / progs / haswinlib / c / caret next >
Encoding:
Text File  |  1991-02-04  |  7.5 KB  |  209 lines

  1. /* > $.CLIB.C.caret
  2.  *
  3.  *      HASWIN graphics Library
  4.  *     =========================
  5.  *
  6.  *      Copyright (C) H.A.Shaw 1990.
  7.  *              Howard A. Shaw.
  8.  *              The Unit for Space Sciences,
  9.  *              Room 165,
  10.  *              Physics Building,
  11.  *              University of Kent at Canterbury.
  12.  *              Canterbury.
  13.  *              Kent.  CT2 7NJ
  14.  *      You may use and distribute this code freely, however please leave
  15.  *      it alone.  If you find bugs (and there will be many) please contact
  16.  *      me and the master source can be modified.  If you keep me informed
  17.  *      of who you give copies of this to then I can get release upgrades
  18.  *      to them.
  19.  *
  20.  *      routines to deal with carets.
  21.  */
  22. #include "includes.h"
  23.  
  24. /*
  25.  *      Take a caret pointer and fill it in from the current caret.  If
  26.  *      no pointer is given create one.
  27.  */
  28. caret *haswin_getcaretinfo(caret *car) {
  29.  
  30.         buffer                  buff;
  31.         _kernel_swi_regs        regs;
  32.  
  33.         if (!car)
  34.                 car = haswin_malloc(sizeof(caret), "haswin_getcaretinfo", "new caret");
  35.         regs.r[1] = (int)&buff;
  36.         if (!haswin_swi(HASWIN_Get_caret, ®s))
  37.                 return(0);
  38.         if (buff.i[0] == -1)
  39.                 car->win = 0;  /* -1 means no window not ICON BAR !! */
  40.         else {
  41.                 if ((car->win=haswin_findwindowhandle(buff.i[0])) == 0) {
  42.                         /* not in one of our HASWIN windows */
  43.                         car->win = (window *)buff.i[0];
  44.                         car->ic  = (icon *)buff.i[1];
  45.                         car->flags = buff.i[4];
  46.                 } else {
  47.                         /* is in one of our HASWIN windows */
  48.                         car->ic = haswin_findiconhandle(car->win, buff.i[1]);
  49.                         car->flags = buff.i[4] | CARET_HASWIN;
  50.                 }
  51.         }
  52.         car->x = buff.i[2];
  53.         car->y = buff.i[3];
  54.         car->index = buff.i[5];
  55.         car->colour = (car->flags >> 16) & 0xFF;
  56.         car->height = car->flags & CARET_HEIGHT;
  57.         return(car);
  58. }
  59.  
  60. /*
  61.  *      set the caret from the given caret structure
  62.  */
  63. int haswin_setcaret(caret *car) {
  64.  
  65.         _kernel_swi_regs        regs;
  66.         int                     buff[20], bg, col;
  67.  
  68.         if (!car) {
  69.                 /* disown the caret */
  70.                 regs.r[0] = -1;
  71.                 regs.r[1] = -1;
  72.                 regs.r[2] = 0;
  73.                 regs.r[3] = 0;
  74.                 regs.r[4] = -1;
  75.                 regs.r[5] = -1;
  76.                 return(haswin_swi(HASWIN_Set_caret, ®s));
  77.         }
  78.         if (!(car->flags & CARET_HASWIN)) {
  79.                 /* can't do much more than restore the window cos
  80.                    it isn't one of our program's HASWIN ones anyway
  81.                  */
  82.                 regs.r[0] = (int)car->win;
  83.                 regs.r[1] = (int)car->ic;
  84.                 regs.r[2] = car->x;
  85.                 regs.r[3] = car->y;
  86.                 if (car->flags & CARET_WIMPCOL)
  87.                         /* set, real colour 0-255 */
  88.                         regs.r[4] = (car->height & CARET_HEIGHT) |
  89.                                     ((car->colour & 0xFF) << 16) |
  90.                                     (car->flags & CARET_WIMPUSE);
  91.                 else
  92.                         /* clear, WIMP colour 0-15 */
  93.                         regs.r[4] = (car->height & CARET_HEIGHT) |
  94.                                     ((car->colour & 0x0F) << 16) |
  95.                                     (car->flags & CARET_WIMPUSE);
  96.                 regs.r[5] = car->index;
  97.                 return(haswin_swi(HASWIN_Set_caret, ®s));
  98.         }
  99.         regs.r[1] = (int)&buff;
  100.         if ((haswin_swi(HASWIN_Read_palette, ®s)) && 
  101.             (car->flags & CARET_REALCOL)) {
  102.                 /* we got the palette and the colours are a real colour,
  103.                    not EORed colour so do the following:
  104.                    1) use the real logical colour of caret from read palette
  105.                    2) EOR with background from window
  106.                    3) use this as colour for caret and set bits 26,27
  107.                  */
  108.                 if ((int)car->win > 0) {
  109.                         bg = ((char *)car->win->win)[35];
  110.                         if (bg == 0xFF)
  111.                                 bg = 0; /* transparent ?? */
  112.                         else
  113.                                 bg &= 0x0F;
  114.                 } else
  115.                         bg = 0; /* no window ?? */
  116.                 if (car->flags & CARET_USECOLOUR) {
  117.                         /* use given colour for colour */
  118.                         if (car->flags & CARET_WIMPCOL)
  119.                                 col = (buff[bg]^car->colour) & 0xFF;
  120.                         else
  121.                                 col = (buff[bg]^buff[car->colour&0x0F])&0xFF;
  122.                 } else
  123.                         /* use WIMP colour 11 for colour */
  124.                         col = (buff[bg]^buff[11]) & 0xFF;
  125.                 regs.r[4] = (car->height & CARET_HEIGHT) | (col << 16) |
  126.                             ((car->flags|CARET_WIMPCOL|CARET_USECOLOUR) & CARET_WIMPUSE);
  127.         } else {
  128.                 if (car->flags & CARET_WIMPCOL)
  129.                         /* set, real colour 0-255 */
  130.                         regs.r[4] = (car->height & CARET_HEIGHT) |
  131.                                     ((car->colour & 0xFF) << 16) |
  132.                                     (car->flags & CARET_WIMPUSE);
  133.                 else
  134.                         /* clear, WIMP colour 0-15 */
  135.                         regs.r[4] = (car->height & CARET_HEIGHT) |
  136.                                     ((car->colour & 0x0F) << 16) |
  137.                                     (car->flags & CARET_WIMPUSE);
  138.         }
  139.         if ((int)car->win > 0)
  140.                 regs.r[0] = car->win->handle;
  141.         else
  142.                 regs.r[0] = (int)car->win;
  143.         if ((int)car->ic > 0)
  144.                 regs.r[1] = car->ic->ihandle;
  145.         else
  146.                 regs.r[1] = (int)car->ic;
  147.         regs.r[2] = car->x;
  148.         regs.r[3] = car->y;
  149.         regs.r[5] = car->index;
  150.         return(haswin_swi(HASWIN_Set_caret, ®s));
  151. }
  152.  
  153. /*
  154.  *      we can stack carets up to HASWIN_MAXCARETS levels
  155.  */
  156. #define HASWIN_MAXCARETS 16
  157. static caret   haswin_caretstack[HASWIN_MAXCARETS];
  158. static int     haswin_caretstackptr = 0;
  159.  
  160. /*
  161.  *      push the current caret onto the caret stack and set a new one
  162.  *      if we can.
  163.  */
  164. int haswin_pushcaret(caret *car) {
  165.  
  166.         if ((!car) || (haswin_caretstackptr == HASWIN_MAXCARETS))
  167.                 return(HASWIN_FALSE);
  168.         haswin_getcaretinfo(&haswin_caretstack[haswin_caretstackptr++]);
  169.         haswin_setcaret(car);
  170.         return(HASWIN_TRUE);
  171. }
  172.  
  173. /*
  174.  *      pull a caret from the caret stack if we can
  175.  */
  176. int haswin_popcaret() {
  177.  
  178.         if (haswin_caretstackptr <= 0) {
  179.                 haswin_setcaret(0);    /* disown the caret */
  180.                 return(HASWIN_FALSE);
  181.         }
  182.         haswin_setcaret(&haswin_caretstack[--haswin_caretstackptr]);
  183.         return(HASWIN_TRUE);
  184. }
  185.  
  186. /*
  187.  *      create a new caret structure
  188.  */
  189. caret *haswin_makecaret(window *win, icon *ic, int x, int y, int height, int colour, int flags, int index) {
  190.         caret   *car;
  191.  
  192.         car = (caret *)haswin_malloc(sizeof(caret), "haswin_makecaret", "caret block");
  193.         car->win = win;
  194.         if (ic)
  195.                 car->ic = ic;
  196.         else
  197.                 car->ic = (icon *)(-1);
  198.         car->x = x;
  199.         car->y = y;
  200.         car->height = height & CARET_HEIGHT;
  201.         car->colour = colour & 0xFF;
  202.         car->flags = flags & CARET_WIMPUSE|CARET_REALCOL;
  203.         if ((int)win > 0)
  204.                 car->flags |= CARET_HASWIN;
  205.         car->index = index;
  206.         return(car);
  207. }
  208.  
  209.