/*
|
/*
|
* Copyright (c) 1999, 2000 Greg Haerr <greg@censoft.com>
|
* Copyright (c) 1999, 2000 Greg Haerr <greg@censoft.com>
|
* Copyright (C) 1999 Bradley D. LaRonde (brad@ltc.com)
|
* Copyright (C) 1999 Bradley D. LaRonde (brad@ltc.com)
|
* Copyright (c) 1991 David I. Bell
|
* Copyright (c) 1991 David I. Bell
|
* Permission is granted to use, distribute, or modify this source,
|
* Permission is granted to use, distribute, or modify this source,
|
* provided that this copyright notice remains intact.
|
* provided that this copyright notice remains intact.
|
*
|
*
|
* Device-independent top level mouse and cursor routines
|
* Device-independent top level mouse and cursor routines
|
*
|
*
|
* Reads data from mouse driver and tracks real position on the screen.
|
* Reads data from mouse driver and tracks real position on the screen.
|
* Intersection detection for cursor with auto removal
|
* Intersection detection for cursor with auto removal
|
*
|
*
|
* Bradley D. LaRonde added absolute coordinates and z (pen pressure) Oct-1999
|
* Bradley D. LaRonde added absolute coordinates and z (pen pressure) Oct-1999
|
*/
|
*/
|
#include <string.h>
|
#include <string.h>
|
#include "device.h"
|
#include "device.h"
|
|
|
/*
|
/*
|
* The following define specifies whether returned mouse
|
* The following define specifies whether returned mouse
|
* driver coordinates are adjusted when running in portrait
|
* driver coordinates are adjusted when running in portrait
|
* mode. If the mouse driver doesn't adjust returned values
|
* mode. If the mouse driver doesn't adjust returned values
|
* when in portrait mode (as is the case for the iPAQ), then
|
* when in portrait mode (as is the case for the iPAQ), then
|
* this define should be set on.
|
* this define should be set on.
|
*/
|
*/
|
#define FLIP_MOUSE_IN_PORTRAIT_MODE 1
|
#define FLIP_MOUSE_IN_PORTRAIT_MODE 1
|
|
|
static MWCOORD xpos; /* current x position of mouse */
|
static MWCOORD xpos; /* current x position of mouse */
|
static MWCOORD ypos; /* current y position of mouse */
|
static MWCOORD ypos; /* current y position of mouse */
|
static MWCOORD minx; /* minimum allowed x position */
|
static MWCOORD minx; /* minimum allowed x position */
|
static MWCOORD maxx; /* maximum allowed x position */
|
static MWCOORD maxx; /* maximum allowed x position */
|
static MWCOORD miny; /* minimum allowed y position */
|
static MWCOORD miny; /* minimum allowed y position */
|
static MWCOORD maxy; /* maximum allowed y position */
|
static MWCOORD maxy; /* maximum allowed y position */
|
static int scale; /* acceleration scale factor */
|
static int scale; /* acceleration scale factor */
|
static int thresh; /* acceleration threshhold */
|
static int thresh; /* acceleration threshhold */
|
static int buttons; /* current state of buttons */
|
static int buttons; /* current state of buttons */
|
static MWBOOL changed; /* mouse state has changed */
|
static MWBOOL changed; /* mouse state has changed */
|
|
|
static MWCOORD curminx; /* minimum x value of cursor */
|
static MWCOORD curminx; /* minimum x value of cursor */
|
static MWCOORD curminy; /* minimum y value of cursor */
|
static MWCOORD curminy; /* minimum y value of cursor */
|
static MWCOORD curmaxx; /* maximum x value of cursor */
|
static MWCOORD curmaxx; /* maximum x value of cursor */
|
static MWCOORD curmaxy; /* maximum y value of cursor */
|
static MWCOORD curmaxy; /* maximum y value of cursor */
|
static int curvisible; /* >0 if cursor is visible*/
|
static int curvisible; /* >0 if cursor is visible*/
|
static MWBOOL curneedsrestore;/* cursor needs restoration after drawing*/
|
static MWBOOL curneedsrestore;/* cursor needs restoration after drawing*/
|
static MWCOORD cursavx; /* saved cursor location*/
|
static MWCOORD cursavx; /* saved cursor location*/
|
static MWCOORD cursavy;
|
static MWCOORD cursavy;
|
static MWCOORD cursavx2;
|
static MWCOORD cursavx2;
|
static MWCOORD cursavy2;
|
static MWCOORD cursavy2;
|
static MWPIXELVAL curfg; /* foreground color of cursor */
|
static MWPIXELVAL curfg; /* foreground color of cursor */
|
static MWPIXELVAL curbg; /* background color of cursor */
|
static MWPIXELVAL curbg; /* background color of cursor */
|
static MWPIXELVAL cursavbits[MWMAX_CURSOR_SIZE * MWMAX_CURSOR_SIZE];
|
static MWPIXELVAL cursavbits[MWMAX_CURSOR_SIZE * MWMAX_CURSOR_SIZE];
|
static MWIMAGEBITS cursormask[MWMAX_CURSOR_SIZE];
|
static MWIMAGEBITS cursormask[MWMAX_CURSOR_SIZE];
|
static MWIMAGEBITS cursorcolor[MWMAX_CURSOR_SIZE];
|
static MWIMAGEBITS cursorcolor[MWMAX_CURSOR_SIZE];
|
|
|
extern int gr_mode;
|
extern int gr_mode;
|
|
|
/*
|
/*
|
* Initialize the mouse.
|
* Initialize the mouse.
|
* This sets its position to (0, 0) with no boundaries and no buttons pressed.
|
* This sets its position to (0, 0) with no boundaries and no buttons pressed.
|
* Returns < 0 on error, or mouse fd on success
|
* Returns < 0 on error, or mouse fd on success
|
*/
|
*/
|
int
|
int
|
GdOpenMouse(void)
|
GdOpenMouse(void)
|
{
|
{
|
int fd;
|
int fd;
|
|
|
/* init mouse position info*/
|
/* init mouse position info*/
|
buttons = 0;
|
buttons = 0;
|
xpos = 0;
|
xpos = 0;
|
ypos = 0;
|
ypos = 0;
|
minx = MIN_MWCOORD;
|
minx = MIN_MWCOORD;
|
miny = MIN_MWCOORD;
|
miny = MIN_MWCOORD;
|
maxx = MAX_MWCOORD;
|
maxx = MAX_MWCOORD;
|
maxy = MAX_MWCOORD;
|
maxy = MAX_MWCOORD;
|
changed = TRUE;
|
changed = TRUE;
|
|
|
/* init cursor position and size info*/
|
/* init cursor position and size info*/
|
curvisible = 0;
|
curvisible = 0;
|
curneedsrestore = FALSE;
|
curneedsrestore = FALSE;
|
curminx = minx;
|
curminx = minx;
|
curminy = miny;
|
curminy = miny;
|
curmaxx = curminx + MWMAX_CURSOR_SIZE - 1;
|
curmaxx = curminx + MWMAX_CURSOR_SIZE - 1;
|
curmaxy = curminy + MWMAX_CURSOR_SIZE - 1;
|
curmaxy = curminy + MWMAX_CURSOR_SIZE - 1;
|
|
|
if ((fd = mousedev.Open(&mousedev)) == -1)
|
if ((fd = mousedev.Open(&mousedev)) == -1)
|
return -1;
|
return -1;
|
|
|
/* get default acceleration settings*/
|
/* get default acceleration settings*/
|
mousedev.GetDefaultAccel(&scale, &thresh);
|
mousedev.GetDefaultAccel(&scale, &thresh);
|
|
|
/* handle null mouse driver by hiding cursor*/
|
/* handle null mouse driver by hiding cursor*/
|
if(fd == -2)
|
if(fd == -2)
|
GdHideCursor(&scrdev);
|
GdHideCursor(&scrdev);
|
return fd;
|
return fd;
|
}
|
}
|
|
|
/*
|
/*
|
* Terminate the use of the mouse.
|
* Terminate the use of the mouse.
|
*/
|
*/
|
void
|
void
|
GdCloseMouse(void)
|
GdCloseMouse(void)
|
{
|
{
|
mousedev.Close();
|
mousedev.Close();
|
}
|
}
|
|
|
void
|
void
|
GdGetButtonInfo(int *buttons)
|
GdGetButtonInfo(int *buttons)
|
{
|
{
|
*buttons = mousedev.GetButtonInfo();
|
*buttons = mousedev.GetButtonInfo();
|
}
|
}
|
|
|
/*
|
/*
|
* Restrict the coordinates of the mouse to the specified coordinates.
|
* Restrict the coordinates of the mouse to the specified coordinates.
|
*/
|
*/
|
void
|
void
|
GdRestrictMouse(MWCOORD newminx, MWCOORD newminy, MWCOORD newmaxx,
|
GdRestrictMouse(MWCOORD newminx, MWCOORD newminy, MWCOORD newmaxx,
|
MWCOORD newmaxy)
|
MWCOORD newmaxy)
|
{
|
{
|
minx = newminx;
|
minx = newminx;
|
miny = newminy;
|
miny = newminy;
|
maxx = newmaxx;
|
maxx = newmaxx;
|
maxy = newmaxy;
|
maxy = newmaxy;
|
GdMoveMouse(xpos, ypos);
|
GdMoveMouse(xpos, ypos);
|
}
|
}
|
|
|
/*
|
/*
|
* Set the acceleration threshhold and scale factors.
|
* Set the acceleration threshhold and scale factors.
|
* Acceleration makes the cursor move further for faster movements.
|
* Acceleration makes the cursor move further for faster movements.
|
* Basically, at mouse speeds above the threshold, the excess distance
|
* Basically, at mouse speeds above the threshold, the excess distance
|
* moved is multiplied by the scale factor. For example, with a threshhold
|
* moved is multiplied by the scale factor. For example, with a threshhold
|
* of 5 and a scale of 3, the following gives examples of the original and
|
* of 5 and a scale of 3, the following gives examples of the original and
|
* modified mouse movements:
|
* modified mouse movements:
|
* input: 0 4 5 6 9 20
|
* input: 0 4 5 6 9 20
|
* output: 0 4 5 8 17 50
|
* output: 0 4 5 8 17 50
|
*/
|
*/
|
void
|
void
|
GdSetAccelMouse(int newthresh, int newscale)
|
GdSetAccelMouse(int newthresh, int newscale)
|
{
|
{
|
if (newthresh < 0)
|
if (newthresh < 0)
|
newthresh = 0;
|
newthresh = 0;
|
if (newscale < 0)
|
if (newscale < 0)
|
newscale = 0;
|
newscale = 0;
|
thresh = newthresh;
|
thresh = newthresh;
|
scale = newscale;
|
scale = newscale;
|
}
|
}
|
|
|
/*
|
/*
|
* Move the mouse to the specified coordinates.
|
* Move the mouse to the specified coordinates.
|
* The location is limited by the current mouse coordinate restrictions.
|
* The location is limited by the current mouse coordinate restrictions.
|
*/
|
*/
|
void
|
void
|
GdMoveMouse(MWCOORD newx, MWCOORD newy)
|
GdMoveMouse(MWCOORD newx, MWCOORD newy)
|
{
|
{
|
if (newx < minx)
|
if (newx < minx)
|
newx = minx;
|
newx = minx;
|
if (newx > maxx)
|
if (newx > maxx)
|
newx = maxx;
|
newx = maxx;
|
if (newy < miny)
|
if (newy < miny)
|
newy = miny;
|
newy = miny;
|
if (newy > maxy)
|
if (newy > maxy)
|
newy = maxy;
|
newy = maxy;
|
if (newx == xpos && newy == ypos)
|
if (newx == xpos && newy == ypos)
|
return;
|
return;
|
|
|
changed = TRUE;
|
changed = TRUE;
|
xpos = newx;
|
xpos = newx;
|
ypos = newy;
|
ypos = newy;
|
}
|
}
|
|
|
/*
|
/*
|
* Read the current location and button states of the mouse.
|
* Read the current location and button states of the mouse.
|
* Returns -1 on read error.
|
* Returns -1 on read error.
|
* Returns 0 if no new data is available from the mouse driver,
|
* Returns 0 if no new data is available from the mouse driver,
|
* or if the new data shows no change in button state or position.
|
* or if the new data shows no change in button state or position.
|
* Returns 1 if the mouse driver tells us a changed button state
|
* Returns 1 if the mouse driver tells us a changed button state
|
* or position. Button state and position are always both returned,
|
* or position. Button state and position are always both returned,
|
* even if only one or the other changes.
|
* even if only one or the other changes.
|
* Do not block.
|
* Do not block.
|
*/
|
*/
|
int
|
int
|
GdReadMouse(MWCOORD *px, MWCOORD *py, int *pb)
|
GdReadMouse(MWCOORD *px, MWCOORD *py, int *pb)
|
{
|
{
|
MWCOORD x, y, z;
|
MWCOORD x, y, z;
|
int newbuttons; /* new button state */
|
int newbuttons; /* new button state */
|
int sign; /* sign of change */
|
int sign; /* sign of change */
|
int status; /* status of reading mouse */
|
int status; /* status of reading mouse */
|
|
|
*px = xpos;
|
*px = xpos;
|
*py = ypos;
|
*py = ypos;
|
*pb = buttons;
|
*pb = buttons;
|
|
|
if (changed) {
|
if (changed) {
|
changed = FALSE;
|
changed = FALSE;
|
return 1;
|
return 1;
|
}
|
}
|
|
|
/* read the mouse position */
|
/* read the mouse position */
|
status = mousedev.Read(&x, &y, &z, &newbuttons);
|
status = mousedev.Read(&x, &y, &z, &newbuttons);
|
if (status < 0)
|
if (status < 0)
|
return -1;
|
return -1;
|
|
|
/* no new info from the mouse driver? */
|
/* no new info from the mouse driver? */
|
if (status == 0)
|
if (status == 0)
|
return 0;
|
return 0;
|
|
|
/* has the button state changed? */
|
/* has the button state changed? */
|
if (buttons != newbuttons) {
|
if (buttons != newbuttons) {
|
changed = TRUE;
|
changed = TRUE;
|
buttons = newbuttons;
|
buttons = newbuttons;
|
}
|
}
|
|
|
/* depending on the kind of data that we have */
|
/* depending on the kind of data that we have */
|
switch(status) {
|
switch(status) {
|
case 1: /* relative position change reported, figure new position */
|
case 1: /* relative position change reported, figure new position */
|
sign = 1;
|
sign = 1;
|
if (x < 0) {
|
if (x < 0) {
|
sign = -1;
|
sign = -1;
|
x = -x;
|
x = -x;
|
}
|
}
|
if (x > thresh)
|
if (x > thresh)
|
x = thresh + (x - thresh) * scale;
|
x = thresh + (x - thresh) * scale;
|
x *= sign;
|
x *= sign;
|
|
|
sign = 1;
|
sign = 1;
|
if (y < 0) {
|
if (y < 0) {
|
sign = -1;
|
sign = -1;
|
y = -y;
|
y = -y;
|
}
|
}
|
if (y > thresh)
|
if (y > thresh)
|
y = thresh + (y - thresh) * scale;
|
y = thresh + (y - thresh) * scale;
|
y *= sign;
|
y *= sign;
|
|
|
#if FLIP_MOUSE_IN_PORTRAIT_MODE
|
#if FLIP_MOUSE_IN_PORTRAIT_MODE
|
if (scrdev.portrait == MWPORTRAIT_RIGHT)
|
if (scrdev.portrait == MWPORTRAIT_RIGHT)
|
GdMoveMouse(xpos + y, ypos - x); /* right*/
|
GdMoveMouse(xpos + y, ypos - x); /* right*/
|
else if (scrdev.portrait == MWPORTRAIT_LEFT)
|
else if (scrdev.portrait == MWPORTRAIT_LEFT)
|
GdMoveMouse(xpos - y, ypos + x); /* left*/
|
GdMoveMouse(xpos - y, ypos + x); /* left*/
|
else if (scrdev.portrait == MWPORTRAIT_DOWN)
|
else if (scrdev.portrait == MWPORTRAIT_DOWN)
|
GdMoveMouse(xpos + x, ypos - y); /* down*/
|
GdMoveMouse(xpos + x, ypos - y); /* down*/
|
else
|
else
|
#endif
|
#endif
|
GdMoveMouse(xpos + x, ypos + y);
|
GdMoveMouse(xpos + x, ypos + y);
|
break;
|
break;
|
|
|
case 2: /* absolute position reported */
|
case 2: /* absolute position reported */
|
#if FLIP_MOUSE_IN_PORTRAIT_MODE
|
#if FLIP_MOUSE_IN_PORTRAIT_MODE
|
if (scrdev.portrait == MWPORTRAIT_RIGHT)
|
if (scrdev.portrait == MWPORTRAIT_RIGHT)
|
GdMoveMouse(y, scrdev.xres - x - 1); /* right*/
|
GdMoveMouse(y, scrdev.xres - x - 1); /* right*/
|
else if (scrdev.portrait == MWPORTRAIT_LEFT)
|
else if (scrdev.portrait == MWPORTRAIT_LEFT)
|
GdMoveMouse(scrdev.yres - y - 1, x); /* left*/
|
GdMoveMouse(scrdev.yres - y - 1, x); /* left*/
|
else if (scrdev.portrait == MWPORTRAIT_DOWN)
|
else if (scrdev.portrait == MWPORTRAIT_DOWN)
|
GdMoveMouse(x, scrdev.yres - y - 1); /* down?*/
|
GdMoveMouse(x, scrdev.yres - y - 1); /* down?*/
|
else
|
else
|
#endif
|
#endif
|
GdMoveMouse(x, y);
|
GdMoveMouse(x, y);
|
break;
|
break;
|
|
|
case 3: /* only button data is available */
|
case 3: /* only button data is available */
|
break;
|
break;
|
}
|
}
|
|
|
/* didn't anything change? */
|
/* didn't anything change? */
|
if (!changed)
|
if (!changed)
|
return 0;
|
return 0;
|
|
|
/* report new mouse data */
|
/* report new mouse data */
|
changed = FALSE;
|
changed = FALSE;
|
*px = xpos;
|
*px = xpos;
|
*py = ypos;
|
*py = ypos;
|
*pb = buttons;
|
*pb = buttons;
|
return 1;
|
return 1;
|
}
|
}
|
|
|
/*
|
/*
|
* Set the cursor position.
|
* Set the cursor position.
|
*/
|
*/
|
void
|
void
|
GdMoveCursor(MWCOORD newx, MWCOORD newy)
|
GdMoveCursor(MWCOORD newx, MWCOORD newy)
|
{
|
{
|
MWCOORD shiftx;
|
MWCOORD shiftx;
|
MWCOORD shifty;
|
MWCOORD shifty;
|
|
|
shiftx = newx - curminx;
|
shiftx = newx - curminx;
|
shifty = newy - curminy;
|
shifty = newy - curminy;
|
if(shiftx == 0 && shifty == 0)
|
if(shiftx == 0 && shifty == 0)
|
return;
|
return;
|
curminx += shiftx;
|
curminx += shiftx;
|
curmaxx += shiftx;
|
curmaxx += shiftx;
|
curminy += shifty;
|
curminy += shifty;
|
curmaxy += shifty;
|
curmaxy += shifty;
|
|
|
/* Restore the screen under the mouse pointer*/
|
/* Restore the screen under the mouse pointer*/
|
GdHideCursor(&scrdev);
|
GdHideCursor(&scrdev);
|
|
|
/* Draw the new pointer*/
|
/* Draw the new pointer*/
|
GdShowCursor(&scrdev);
|
GdShowCursor(&scrdev);
|
}
|
}
|
|
|
/* return current mouse position in x, y*/
|
/* return current mouse position in x, y*/
|
MWBOOL
|
MWBOOL
|
GdGetCursorPos(MWCOORD *px, MWCOORD *py)
|
GdGetCursorPos(MWCOORD *px, MWCOORD *py)
|
{
|
{
|
*px = xpos;
|
*px = xpos;
|
*py = ypos;
|
*py = ypos;
|
return curvisible > 0; /* return TRUE if visible*/
|
return curvisible > 0; /* return TRUE if visible*/
|
}
|
}
|
|
|
/*
|
/*
|
* Set the cursor size and bitmaps.
|
* Set the cursor size and bitmaps.
|
*/
|
*/
|
void
|
void
|
GdSetCursor(PMWCURSOR pcursor)
|
GdSetCursor(PMWCURSOR pcursor)
|
{
|
{
|
int bytes;
|
int bytes;
|
|
|
GdHideCursor(&scrdev);
|
GdHideCursor(&scrdev);
|
curmaxx = curminx + pcursor->width - 1;
|
curmaxx = curminx + pcursor->width - 1;
|
curmaxy = curminy + pcursor->height - 1;
|
curmaxy = curminy + pcursor->height - 1;
|
|
|
curfg = GdFindColor(pcursor->fgcolor);
|
curfg = GdFindColor(pcursor->fgcolor);
|
curbg = GdFindColor(pcursor->bgcolor);
|
curbg = GdFindColor(pcursor->bgcolor);
|
bytes = MWIMAGE_WORDS(pcursor->width) * pcursor->height
|
bytes = MWIMAGE_WORDS(pcursor->width) * pcursor->height
|
* sizeof(MWIMAGEBITS);
|
* sizeof(MWIMAGEBITS);
|
memcpy(cursorcolor, pcursor->image, bytes);
|
memcpy(cursorcolor, pcursor->image, bytes);
|
memcpy(cursormask, pcursor->mask, bytes);
|
memcpy(cursormask, pcursor->mask, bytes);
|
|
|
GdShowCursor(&scrdev);
|
GdShowCursor(&scrdev);
|
}
|
}
|
|
|
|
|
/*
|
/*
|
* Draw the mouse pointer. Save the screen contents underneath
|
* Draw the mouse pointer. Save the screen contents underneath
|
* before drawing. Returns previous cursor state.
|
* before drawing. Returns previous cursor state.
|
*/
|
*/
|
int
|
int
|
GdShowCursor(PSD psd)
|
GdShowCursor(PSD psd)
|
{
|
{
|
MWCOORD x;
|
MWCOORD x;
|
MWCOORD y;
|
MWCOORD y;
|
MWPIXELVAL * saveptr;
|
MWPIXELVAL * saveptr;
|
MWIMAGEBITS * cursorptr;
|
MWIMAGEBITS * cursorptr;
|
MWIMAGEBITS * maskptr;
|
MWIMAGEBITS * maskptr;
|
MWIMAGEBITS curbit, cbits, mbits;
|
MWIMAGEBITS curbit, cbits, mbits;
|
MWPIXELVAL oldcolor;
|
MWPIXELVAL oldcolor;
|
MWPIXELVAL newcolor;
|
MWPIXELVAL newcolor;
|
int oldmode;
|
int oldmode;
|
int prevcursor = curvisible;
|
int prevcursor = curvisible;
|
|
|
if(++curvisible != 1)
|
if(++curvisible != 1)
|
return prevcursor;
|
return prevcursor;
|
oldmode = gr_mode;
|
oldmode = gr_mode;
|
gr_mode = MWMODE_COPY;
|
gr_mode = MWMODE_COPY;
|
|
|
saveptr = cursavbits;
|
saveptr = cursavbits;
|
cursavx = curminx;
|
cursavx = curminx;
|
cursavy = curminy;
|
cursavy = curminy;
|
cursavx2 = curmaxx;
|
cursavx2 = curmaxx;
|
cursavy2 = curmaxy;
|
cursavy2 = curmaxy;
|
cursorptr = cursorcolor;
|
cursorptr = cursorcolor;
|
maskptr = cursormask;
|
maskptr = cursormask;
|
|
|
for (y = curminy; y <= curmaxy; y++) {
|
for (y = curminy; y <= curmaxy; y++) {
|
cbits = *cursorptr++;
|
cbits = *cursorptr++;
|
mbits = *maskptr++;
|
mbits = *maskptr++;
|
curbit = MWIMAGE_FIRSTBIT;
|
curbit = MWIMAGE_FIRSTBIT;
|
for (x = curminx; x <= curmaxx; x++) {
|
for (x = curminx; x <= curmaxx; x++) {
|
if(x >= 0 && x < psd->xvirtres &&
|
if(x >= 0 && x < psd->xvirtres &&
|
y >= 0 && y < psd->yvirtres) {
|
y >= 0 && y < psd->yvirtres) {
|
oldcolor = psd->ReadPixel(psd, x, y);
|
oldcolor = psd->ReadPixel(psd, x, y);
|
if (curbit & mbits) {
|
if (curbit & mbits) {
|
newcolor = (curbit&cbits)? curbg: curfg;
|
newcolor = (curbit&cbits)? curbg: curfg;
|
if (oldcolor != newcolor)
|
if (oldcolor != newcolor)
|
psd->DrawPixel(psd, x, y, newcolor);
|
psd->DrawPixel(psd, x, y, newcolor);
|
}
|
}
|
*saveptr++ = oldcolor;
|
*saveptr++ = oldcolor;
|
}
|
}
|
curbit = MWIMAGE_NEXTBIT(curbit);
|
curbit = MWIMAGE_NEXTBIT(curbit);
|
}
|
}
|
}
|
}
|
|
|
gr_mode = oldmode;
|
gr_mode = oldmode;
|
return prevcursor;
|
return prevcursor;
|
}
|
}
|
|
|
/*
|
/*
|
* Restore the screen overwritten by the cursor.
|
* Restore the screen overwritten by the cursor.
|
*/
|
*/
|
int
|
int
|
GdHideCursor(PSD psd)
|
GdHideCursor(PSD psd)
|
{
|
{
|
MWPIXELVAL * saveptr;
|
MWPIXELVAL * saveptr;
|
MWCOORD x, y;
|
MWCOORD x, y;
|
int oldmode;
|
int oldmode;
|
int prevcursor = curvisible;
|
int prevcursor = curvisible;
|
|
|
if(curvisible-- <= 0)
|
if(curvisible-- <= 0)
|
return prevcursor;
|
return prevcursor;
|
oldmode = gr_mode;
|
oldmode = gr_mode;
|
gr_mode = MWMODE_COPY;
|
gr_mode = MWMODE_COPY;
|
|
|
saveptr = cursavbits;
|
saveptr = cursavbits;
|
for (y = cursavy; y <= cursavy2; y++) {
|
for (y = cursavy; y <= cursavy2; y++) {
|
for (x = cursavx; x <= cursavx2; x++) {
|
for (x = cursavx; x <= cursavx2; x++) {
|
if(x >= 0 && x < psd->xvirtres &&
|
if(x >= 0 && x < psd->xvirtres &&
|
y >= 0 && y < psd->yvirtres) {
|
y >= 0 && y < psd->yvirtres) {
|
psd->DrawPixel(psd, x, y, *saveptr++);
|
psd->DrawPixel(psd, x, y, *saveptr++);
|
}
|
}
|
}
|
}
|
}
|
}
|
gr_mode = oldmode;
|
gr_mode = oldmode;
|
return prevcursor;
|
return prevcursor;
|
}
|
}
|
|
|
/* Check to see if the mouse pointer is about to be overwritten.
|
/* Check to see if the mouse pointer is about to be overwritten.
|
* If so, then remove the cursor so that the graphics operation
|
* If so, then remove the cursor so that the graphics operation
|
* works correctly. If the cursor is removed, then this fact will
|
* works correctly. If the cursor is removed, then this fact will
|
* be remembered and a later call to GdFixCursor will restore it.
|
* be remembered and a later call to GdFixCursor will restore it.
|
*/
|
*/
|
void
|
void
|
GdCheckCursor(PSD psd,MWCOORD x1,MWCOORD y1,MWCOORD x2,MWCOORD y2)
|
GdCheckCursor(PSD psd,MWCOORD x1,MWCOORD y1,MWCOORD x2,MWCOORD y2)
|
{
|
{
|
MWCOORD temp;
|
MWCOORD temp;
|
|
|
if (curvisible <= 0 || (psd->flags & PSF_SCREEN) == 0)
|
if (curvisible <= 0 || (psd->flags & PSF_SCREEN) == 0)
|
return;
|
return;
|
|
|
if (x1 > x2) {
|
if (x1 > x2) {
|
temp = x1;
|
temp = x1;
|
x1 = x2;
|
x1 = x2;
|
x2 = temp;
|
x2 = temp;
|
}
|
}
|
if (y1 > y2) {
|
if (y1 > y2) {
|
temp = y1;
|
temp = y1;
|
y1 = y2;
|
y1 = y2;
|
y2 = temp;
|
y2 = temp;
|
}
|
}
|
if (x1 > curmaxx || x2 < curminx || y1 > curmaxy || y2 < curminy)
|
if (x1 > curmaxx || x2 < curminx || y1 > curmaxy || y2 < curminy)
|
return;
|
return;
|
|
|
GdHideCursor(psd);
|
GdHideCursor(psd);
|
curneedsrestore = TRUE;
|
curneedsrestore = TRUE;
|
}
|
}
|
|
|
|
|
/* Redisplay the cursor if it was removed because of a graphics operation. */
|
/* Redisplay the cursor if it was removed because of a graphics operation. */
|
void
|
void
|
GdFixCursor(PSD psd)
|
GdFixCursor(PSD psd)
|
{
|
{
|
if (curneedsrestore && (psd->flags & PSF_SCREEN)) {
|
if (curneedsrestore && (psd->flags & PSF_SCREEN)) {
|
GdShowCursor(psd);
|
GdShowCursor(psd);
|
curneedsrestore = FALSE;
|
curneedsrestore = FALSE;
|
}
|
}
|
}
|
}
|
|
|