home *** CD-ROM | disk | FTP | other *** search
- /* > $.CLIB.C.caret
- *
- * HASWIN graphics Library
- * =========================
- *
- * Copyright (C) H.A.Shaw 1990.
- * Howard A. Shaw.
- * The Unit for Space Sciences,
- * Room 165,
- * Physics Building,
- * University of Kent at Canterbury.
- * Canterbury.
- * Kent. CT2 7NJ
- * You may use and distribute this code freely, however please leave
- * it alone. If you find bugs (and there will be many) please contact
- * me and the master source can be modified. If you keep me informed
- * of who you give copies of this to then I can get release upgrades
- * to them.
- *
- * routines to deal with carets.
- */
- #include "includes.h"
-
- /*
- * Take a caret pointer and fill it in from the current caret. If
- * no pointer is given create one.
- */
- caret *haswin_getcaretinfo(caret *car) {
-
- buffer buff;
- _kernel_swi_regs regs;
-
- if (!car)
- car = haswin_malloc(sizeof(caret), "haswin_getcaretinfo", "new caret");
- regs.r[1] = (int)&buff;
- if (!haswin_swi(HASWIN_Get_caret, ®s))
- return(0);
- if (buff.i[0] == -1)
- car->win = 0; /* -1 means no window not ICON BAR !! */
- else {
- if ((car->win=haswin_findwindowhandle(buff.i[0])) == 0) {
- /* not in one of our HASWIN windows */
- car->win = (window *)buff.i[0];
- car->ic = (icon *)buff.i[1];
- car->flags = buff.i[4];
- } else {
- /* is in one of our HASWIN windows */
- car->ic = haswin_findiconhandle(car->win, buff.i[1]);
- car->flags = buff.i[4] | CARET_HASWIN;
- }
- }
- car->x = buff.i[2];
- car->y = buff.i[3];
- car->index = buff.i[5];
- car->colour = (car->flags >> 16) & 0xFF;
- car->height = car->flags & CARET_HEIGHT;
- return(car);
- }
-
- /*
- * set the caret from the given caret structure
- */
- int haswin_setcaret(caret *car) {
-
- _kernel_swi_regs regs;
- int buff[20], bg, col;
-
- if (!car) {
- /* disown the caret */
- regs.r[0] = -1;
- regs.r[1] = -1;
- regs.r[2] = 0;
- regs.r[3] = 0;
- regs.r[4] = -1;
- regs.r[5] = -1;
- return(haswin_swi(HASWIN_Set_caret, ®s));
- }
- if (!(car->flags & CARET_HASWIN)) {
- /* can't do much more than restore the window cos
- it isn't one of our program's HASWIN ones anyway
- */
- regs.r[0] = (int)car->win;
- regs.r[1] = (int)car->ic;
- regs.r[2] = car->x;
- regs.r[3] = car->y;
- if (car->flags & CARET_WIMPCOL)
- /* set, real colour 0-255 */
- regs.r[4] = (car->height & CARET_HEIGHT) |
- ((car->colour & 0xFF) << 16) |
- (car->flags & CARET_WIMPUSE);
- else
- /* clear, WIMP colour 0-15 */
- regs.r[4] = (car->height & CARET_HEIGHT) |
- ((car->colour & 0x0F) << 16) |
- (car->flags & CARET_WIMPUSE);
- regs.r[5] = car->index;
- return(haswin_swi(HASWIN_Set_caret, ®s));
- }
- regs.r[1] = (int)&buff;
- if ((haswin_swi(HASWIN_Read_palette, ®s)) &&
- (car->flags & CARET_REALCOL)) {
- /* we got the palette and the colours are a real colour,
- not EORed colour so do the following:
- 1) use the real logical colour of caret from read palette
- 2) EOR with background from window
- 3) use this as colour for caret and set bits 26,27
- */
- if ((int)car->win > 0) {
- bg = ((char *)car->win->win)[35];
- if (bg == 0xFF)
- bg = 0; /* transparent ?? */
- else
- bg &= 0x0F;
- } else
- bg = 0; /* no window ?? */
- if (car->flags & CARET_USECOLOUR) {
- /* use given colour for colour */
- if (car->flags & CARET_WIMPCOL)
- col = (buff[bg]^car->colour) & 0xFF;
- else
- col = (buff[bg]^buff[car->colour&0x0F])&0xFF;
- } else
- /* use WIMP colour 11 for colour */
- col = (buff[bg]^buff[11]) & 0xFF;
- regs.r[4] = (car->height & CARET_HEIGHT) | (col << 16) |
- ((car->flags|CARET_WIMPCOL|CARET_USECOLOUR) & CARET_WIMPUSE);
- } else {
- if (car->flags & CARET_WIMPCOL)
- /* set, real colour 0-255 */
- regs.r[4] = (car->height & CARET_HEIGHT) |
- ((car->colour & 0xFF) << 16) |
- (car->flags & CARET_WIMPUSE);
- else
- /* clear, WIMP colour 0-15 */
- regs.r[4] = (car->height & CARET_HEIGHT) |
- ((car->colour & 0x0F) << 16) |
- (car->flags & CARET_WIMPUSE);
- }
- if ((int)car->win > 0)
- regs.r[0] = car->win->handle;
- else
- regs.r[0] = (int)car->win;
- if ((int)car->ic > 0)
- regs.r[1] = car->ic->ihandle;
- else
- regs.r[1] = (int)car->ic;
- regs.r[2] = car->x;
- regs.r[3] = car->y;
- regs.r[5] = car->index;
- return(haswin_swi(HASWIN_Set_caret, ®s));
- }
-
- /*
- * we can stack carets up to HASWIN_MAXCARETS levels
- */
- #define HASWIN_MAXCARETS 16
- static caret haswin_caretstack[HASWIN_MAXCARETS];
- static int haswin_caretstackptr = 0;
-
- /*
- * push the current caret onto the caret stack and set a new one
- * if we can.
- */
- int haswin_pushcaret(caret *car) {
-
- if ((!car) || (haswin_caretstackptr == HASWIN_MAXCARETS))
- return(HASWIN_FALSE);
- haswin_getcaretinfo(&haswin_caretstack[haswin_caretstackptr++]);
- haswin_setcaret(car);
- return(HASWIN_TRUE);
- }
-
- /*
- * pull a caret from the caret stack if we can
- */
- int haswin_popcaret() {
-
- if (haswin_caretstackptr <= 0) {
- haswin_setcaret(0); /* disown the caret */
- return(HASWIN_FALSE);
- }
- haswin_setcaret(&haswin_caretstack[--haswin_caretstackptr]);
- return(HASWIN_TRUE);
- }
-
- /*
- * create a new caret structure
- */
- caret *haswin_makecaret(window *win, icon *ic, int x, int y, int height, int colour, int flags, int index) {
- caret *car;
-
- car = (caret *)haswin_malloc(sizeof(caret), "haswin_makecaret", "caret block");
- car->win = win;
- if (ic)
- car->ic = ic;
- else
- car->ic = (icon *)(-1);
- car->x = x;
- car->y = y;
- car->height = height & CARET_HEIGHT;
- car->colour = colour & 0xFF;
- car->flags = flags & CARET_WIMPUSE|CARET_REALCOL;
- if ((int)win > 0)
- car->flags |= CARET_HASWIN;
- car->index = index;
- return(car);
- }
-
-