-
Notifications
You must be signed in to change notification settings - Fork 2
/
CrCursor.c
77 lines (63 loc) · 1.73 KB
/
CrCursor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "nxlib.h"
static int min(int a, int b)
{
return (a < b)? a: b;
}
/* Calculate the cursor from the given pixmap */
GR_CURSOR_ID
_nxCreateCursor(GR_WINDOW_ID cursor, GR_RECT * cbb,
GR_WINDOW_ID mask, GR_RECT * mbb,
int hotx, int hoty, GR_COLOR fg, GR_COLOR bg)
{
int w, h;
GR_BITMAP *bcursor, *bmask;
GR_CURSOR_ID cursorid;
/* force cursor size to max Microwindows size*/
w = min(cbb->width, MWMAX_CURSOR_SIZE);
h = min(cbb->height, MWMAX_CURSOR_SIZE);
bcursor = GrNewBitmapFromPixmap(cursor, cbb->x, cbb->y, w, h);
if (!bcursor)
return 0;
w = min(mbb->width, MWMAX_CURSOR_SIZE);
h = min(mbb->height, MWMAX_CURSOR_SIZE);
bmask = GrNewBitmapFromPixmap(mask, mbb->x, mbb->y, w, h);
if (!bmask) {
free(bcursor);
return 0;
}
if (cbb->width > w || cbb->height > h)
DPRINTF("nxCreateCursor: truncating original cursor (%d x %d)\n", cbb->width, cbb->height);
/*
* Foreground/background reversed from nano-X !!!
*/
cursorid = GrNewCursor(w, h, hotx, hoty, bg, fg, bcursor, bmask);
free(bcursor);
free(bmask);
return cursorid;
}
Cursor
XCreatePixmapCursor(Display * display, Pixmap source, Pixmap mask,
XColor * fg, XColor * bg, unsigned int x, unsigned y)
{
Cursor ret;
GR_RECT cbb, mbb;
GR_WINDOW_INFO winfo;
GrGetWindowInfo(source, &winfo);
cbb.x = cbb.y = 0;
cbb.width = winfo.width;
cbb.height = winfo.height;
GrGetWindowInfo(mask, &winfo);
mbb.x = mbb.y = 0;
mbb.width = winfo.width;
mbb.height = winfo.height;
ret = _nxCreateCursor(source, &cbb, mask, &mbb, x, y,
GR_RGB(fg->red >> 8, fg->green >> 8, fg->blue >> 8),
GR_RGB(bg->red >> 8, bg->green >> 8, bg->blue >> 8));
return ret;
}
int
XFreeCursor(Display * display, Cursor cursor)
{
GrDestroyCursor(cursor);
return 1;
}