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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
// fl_cursor.C
// Change the current cursor.
// Under X the cursor is attached to the X window. I tried to hide
// this and pretend that changing the cursor is a drawing function.
// This avoids a field in the Fl_Window, and I suspect is more
// portable to other systems.
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/x.H>
#ifndef WIN32
#include <X11/cursorfont.h>
#endif
#include <FL/fl_draw.H>
void fl_cursor(Fl_Cursor c, Fl_Color fg, Fl_Color bg) {
if (Fl::first_window()) Fl::first_window()->cursor(c,fg,bg);
}
#ifdef WIN32
void Fl_Window::cursor(Fl_Cursor c, Fl_Color, Fl_Color) {
if (!shown()) return;
if (c > FL_CURSOR_NESW) {
i->cursor = 0;
} else if (c == FL_CURSOR_DEFAULT) {
i->cursor = fl_default_cursor;
} else {
LPSTR n;
switch (c) {
case FL_CURSOR_ARROW: n = IDC_ARROW; break;
case FL_CURSOR_CROSS: n = IDC_CROSS; break;
case FL_CURSOR_WAIT: n = IDC_WAIT; break;
case FL_CURSOR_INSERT: n = IDC_IBEAM; break;
case FL_CURSOR_HELP: n = IDC_HELP; break;
case FL_CURSOR_HAND: n = IDC_UPARROW; break;
case FL_CURSOR_MOVE: n = IDC_SIZEALL; break;
case FL_CURSOR_N:
case FL_CURSOR_S:
case FL_CURSOR_NS: n = IDC_SIZENS; break;
case FL_CURSOR_NE:
case FL_CURSOR_SW:
case FL_CURSOR_NESW: n = IDC_SIZENESW; break;
case FL_CURSOR_E:
case FL_CURSOR_W:
case FL_CURSOR_WE: n = IDC_SIZEWE; break;
case FL_CURSOR_SE:
case FL_CURSOR_NW:
case FL_CURSOR_NWSE: n = IDC_SIZENWSE; break;
default: n = IDC_NO; break;
}
i->cursor = LoadCursor(NULL, n);
}
SetCursor(i->cursor);
}
#else
// I like the MSWindows resize cursors, so I duplicate them here:
#define CURSORSIZE 16
#define HOTXY 7
static struct TableEntry {
uchar bits[CURSORSIZE*CURSORSIZE/8];
uchar mask[CURSORSIZE*CURSORSIZE/8];
Cursor cursor;
} table[] = {
{{ // FL_CURSOR_NS
0x00, 0x00, 0x80, 0x01, 0xc0, 0x03, 0xe0, 0x07, 0x80, 0x01, 0x80, 0x01,
0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,
0xe0, 0x07, 0xc0, 0x03, 0x80, 0x01, 0x00, 0x00},
{
0x80, 0x01, 0xc0, 0x03, 0xe0, 0x07, 0xf0, 0x0f, 0xf0, 0x0f, 0xc0, 0x03,
0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xf0, 0x0f,
0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x01}},
{{ // FL_CURSOR_EW
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x10,
0x0c, 0x30, 0xfe, 0x7f, 0xfe, 0x7f, 0x0c, 0x30, 0x08, 0x10, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x1c, 0x38,
0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0x1c, 0x38, 0x18, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{{ // FL_CURSOR_NWSE
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x38, 0x00, 0x78, 0x00,
0xe8, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x17, 0x00, 0x1e, 0x00, 0x1c,
0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{
0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0xfc, 0x00, 0x7c, 0x00, 0xfc, 0x00,
0xfc, 0x01, 0xec, 0x03, 0xc0, 0x37, 0x80, 0x3f, 0x00, 0x3f, 0x00, 0x3e,
0x00, 0x3f, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00}},
{{ // FL_CURSOR_NESW
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x1c, 0x00, 0x1e,
0x00, 0x17, 0x80, 0x03, 0xc0, 0x01, 0xe8, 0x00, 0x78, 0x00, 0x38, 0x00,
0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x3f, 0x00, 0x3e, 0x00, 0x3f,
0x80, 0x3f, 0xc0, 0x37, 0xec, 0x03, 0xfc, 0x01, 0xfc, 0x00, 0x7c, 0x00,
0xfc, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00}},
{{0}, {0}} // FL_CURSOR_NONE & unknown
};
void Fl_Window::cursor(Fl_Cursor c, Fl_Color fg, Fl_Color bg) {
if (!shown()) return;
Cursor cursor;
int deleteit = 0;
if (!c) {
cursor = None;
} else {
if (c >= FL_CURSOR_NS) {
TableEntry *q = (c > FL_CURSOR_NESW) ? table+4 : table+(c-FL_CURSOR_NS);
if (!(q->cursor)) {
XColor dummy;
Pixmap p = XCreateBitmapFromData(fl_display,
RootWindow(fl_display, fl_screen), (const char*)(q->bits),
CURSORSIZE, CURSORSIZE);
Pixmap m = XCreateBitmapFromData(fl_display,
RootWindow(fl_display, fl_screen), (const char*)(q->mask),
CURSORSIZE, CURSORSIZE);
q->cursor = XCreatePixmapCursor(fl_display, p,m,&dummy, &dummy,
HOTXY, HOTXY);
XFreePixmap(fl_display, m);
XFreePixmap(fl_display, p);
}
cursor = q->cursor;
} else {
cursor = XCreateFontCursor(fl_display, (c-1)*2);
deleteit = 1;
}
XColor fgc;
uchar r,g,b;
Fl::get_color(fg,r,g,b);
fgc.red = r<<8; fgc.green = g<<8; fgc.blue = b<<8;
XColor bgc;
Fl::get_color(bg,r,g,b);
bgc.red = r<<8; bgc.green = g<<8; bgc.blue = b<<8;
XRecolorCursor(fl_display, cursor, &fgc, &bgc);
}
XDefineCursor(fl_display, fl_xid(this), cursor);
if (deleteit) XFreeCursor(fl_display, cursor);
}
#endif
|