The R Project SVN R

Rev

Rev 44004 | Rev 79040 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 44004 Rev 45017
Line 44... Line 44...
44
/*
44
/*
45
 *  Define the 'Hand' image shape:
45
 *  Define the 'Hand' image shape:
46
 */
46
 */
47
 
47
 
48
static rgb cursor_cmap [] = {
48
static rgb cursor_cmap [] = {
49
	0x00000000L,
49
    0x00000000L,
50
	0x00FFFFFFL,
50
    0x00FFFFFFL,
51
	0xFFFFFFFFL,
51
    0xFFFFFFFFL,
52
};
52
};
53
 
53
 
54
static byte hand_pixels [] = {
54
static byte hand_pixels [] = {
55
	2,2,2,2,2,2,0,0,0,2,2,2,2,2,2,2,
55
    2,2,2,2,2,2,0,0,0,2,2,2,2,2,2,2,
56
	2,2,2,2,2,0,1,1,0,0,2,2,2,2,2,2,
56
    2,2,2,2,2,0,1,1,0,0,2,2,2,2,2,2,
57
	2,2,2,2,2,0,1,1,0,0,2,2,2,2,2,2,
57
    2,2,2,2,2,0,1,1,0,0,2,2,2,2,2,2,
58
	2,2,2,2,2,0,1,1,0,0,2,2,2,2,2,2,
58
    2,2,2,2,2,0,1,1,0,0,2,2,2,2,2,2,
59
	2,2,2,2,2,0,1,1,0,0,2,2,2,2,2,2,
59
    2,2,2,2,2,0,1,1,0,0,2,2,2,2,2,2,
60
	2,2,2,2,2,0,1,1,0,0,2,2,2,2,2,2,
60
    2,2,2,2,2,0,1,1,0,0,2,2,2,2,2,2,
61
	2,0,0,0,2,0,1,1,0,0,0,0,0,2,2,2,
61
    2,0,0,0,2,0,1,1,0,0,0,0,0,2,2,2,
62
	0,1,1,0,0,0,1,1,0,1,0,1,0,0,0,2,
62
    0,1,1,0,0,0,1,1,0,1,0,1,0,0,0,2,
63
	2,0,1,1,0,0,1,1,0,1,0,1,0,1,0,0,
63
    2,0,1,1,0,0,1,1,0,1,0,1,0,1,0,0,
64
	2,2,0,1,1,0,1,1,1,1,1,1,0,1,0,0,
64
    2,2,0,1,1,0,1,1,1,1,1,1,0,1,0,0,
65
	2,2,0,1,1,0,1,1,1,1,1,1,1,1,0,0,
65
    2,2,0,1,1,0,1,1,1,1,1,1,1,1,0,0,
66
	2,2,2,0,1,1,1,1,1,1,1,1,1,1,0,0,
66
    2,2,2,0,1,1,1,1,1,1,1,1,1,1,0,0,
67
	2,2,2,2,0,1,1,1,1,1,1,1,1,1,0,0,
67
    2,2,2,2,0,1,1,1,1,1,1,1,1,1,0,0,
68
	2,2,2,2,0,1,1,1,1,1,1,1,1,0,0,2,
68
    2,2,2,2,0,1,1,1,1,1,1,1,1,0,0,2,
69
	2,2,2,2,2,0,1,1,1,1,1,1,1,0,0,2,
69
    2,2,2,2,2,0,1,1,1,1,1,1,1,0,0,2,
70
	2,2,2,2,2,0,1,1,1,1,1,1,1,0,0,2,
70
    2,2,2,2,2,0,1,1,1,1,1,1,1,0,0,2,
71
};
71
};
72
 
72
 
73
static imagedata hand_imagedata = {
73
static imagedata hand_imagedata = {
74
	8,	/* depth */
74
    8,	/* depth */
75
	16,	/* width */
75
    16,	/* width */
76
	16,	/* height */
76
    16,	/* height */
77
	3,	/* cmapsize */
77
    3,	/* cmapsize */
78
	cursor_cmap,
78
    cursor_cmap,
79
	hand_pixels
79
    hand_pixels
80
};
80
};
81
 
81
 
82
static image hand_image = & hand_imagedata;
82
static image hand_image = & hand_imagedata;
83
static point hand_hotspot = {7,0};
83
static point hand_hotspot = {7,0};
84
 
84
 
85
/*
85
/*
86
 *  Private cursor destructor.
86
 *  Private cursor destructor.
87
 */
87
 */
88
static void private_delcursor(cursor c)
88
static void private_delcursor(cursor c)
89
{
89
{
90
	DestroyCursor(c->handle);
90
    DestroyCursor(c->handle);
91
}
91
}
92
 
92
 
93
/*
93
/*
94
 *  Private constructor.
94
 *  Private constructor.
95
 */
95
 */
96
static object get_cursor_base(void)
96
static object get_cursor_base(void)
97
{
97
{
98
	static object cursor_base = NULL;
98
    static object cursor_base = NULL;
99
 
99
 
100
	if (! cursor_base)
100
    if (! cursor_base)
101
		cursor_base = new_object(BaseObject, 0, NULL);
101
	cursor_base = new_object(BaseObject, 0, NULL);
102
	return cursor_base;
102
    return cursor_base;
103
}
103
}
104
 
104
 
105
static cursor new_cursor_object(HCURSOR hc)
105
static cursor new_cursor_object(HCURSOR hc)
106
{
106
{
107
	cursor c = new_object(CursorObject, hc, get_cursor_base());
107
    cursor c = new_object(CursorObject, hc, get_cursor_base());
108
	if (c) {
108
    if (c) {
109
		c->rect = rect(0,0,16,16);
109
	c->rect = rect(0,0,16,16);
110
		c->depth = 1;
110
	c->depth = 1;
111
		c->die = private_delcursor;
111
	c->die = private_delcursor;
112
	}
112
    }
113
	return c;
113
    return c;
114
}
114
}
115
 
115
 
116
/*
116
/*
117
 *  Public constructors.
117
 *  Public constructors.
118
 */
118
 */
119
cursor createcursor(point offset, byte *white, byte *black)
119
cursor createcursor(point offset, byte *white, byte *black)
120
{
120
{
121
	cursor c;
121
    cursor c;
122
	HCURSOR hc;
122
    HCURSOR hc;
123
	byte *andmask;	/* andmask = ~blackmask & ~whitemask */
123
    byte *andmask;	/* andmask = ~blackmask & ~whitemask */
124
	byte *xormask;	/* xormask = ~blackmask &  whitemask */
124
    byte *xormask;	/* xormask = ~blackmask &  whitemask */
125
	int w, y;
125
    int w, y;
126
	int max_width, max_height, row_bytes;
126
    int max_width, max_height, row_bytes;
127
 
127
 
128
	/* Library cursors: D = (D | whitemask) & ~blackmask */
128
    /* Library cursors: D = (D | whitemask) & ~blackmask */
129
	/* MS-Windows does: D = (D & andmask) ^ xormask */
129
    /* MS-Windows does: D = (D & andmask) ^ xormask */
130
 
130
 
131
	/* Determine the best cursor size: */
131
    /* Determine the best cursor size: */
132
	max_width  = GetSystemMetrics(SM_CXCURSOR);
132
    max_width  = GetSystemMetrics(SM_CXCURSOR);
133
	max_height = GetSystemMetrics(SM_CYCURSOR);
133
    max_height = GetSystemMetrics(SM_CYCURSOR);
134
	row_bytes  = (max_width + 7) / 8;
134
    row_bytes  = (max_width + 7) / 8;
135
 
135
 
136
	/* Create the data arrays: */
136
    /* Create the data arrays: */
137
	andmask = array(max_height * row_bytes, byte);
137
    andmask = array(max_height * row_bytes, byte);
138
	xormask = array(max_height * row_bytes, byte);
138
    xormask = array(max_height * row_bytes, byte);
139
 
139
 
140
	/* Assign the data into the arrays: */
140
    /* Assign the data into the arrays: */
141
	for (y=0; y < max_height; y++) {
141
    for (y=0; y < max_height; y++) {
142
	    for (w=0; w < row_bytes; w++) {
142
	for (w=0; w < row_bytes; w++) {
143
		if ((w<2) && (y<16)) {
143
	    if ((w<2) && (y<16)) {
144
		    andmask[w+y*row_bytes] = ~(black[w+y*2]) & ~(white[w+y*2]);
144
		andmask[w+y*row_bytes] = ~(black[w+y*2]) & ~(white[w+y*2]);
145
		    xormask[w+y*row_bytes] = ~(black[w+y*2]) &  (white[w+y*2]);
145
		xormask[w+y*row_bytes] = ~(black[w+y*2]) &  (white[w+y*2]);
146
		}
146
	    }
147
		else {
147
	    else {
148
		    andmask[w+y*row_bytes] = 0xFF;
148
		andmask[w+y*row_bytes] = 0xFF;
149
		    xormask[w+y*row_bytes] = 0x00;
149
		xormask[w+y*row_bytes] = 0x00;
150
		}
-
 
151
	    }
150
	    }
152
	}
151
	}
-
 
152
    }
-
 
153
 
-
 
154
    /* Create the cursor: */
-
 
155
    hc = CreateCursor (this_instance, -offset.x, -offset.y,
-
 
156
		       max_width, max_height,
-
 
157
		       (void FAR *) andmask, (void FAR *) xormask);
153
 
158
 
154
	/* Create the cursor: */
-
 
155
	hc = CreateCursor (this_instance, -offset.x, -offset.y,
-
 
156
		max_width, max_height,
-
 
157
		(void FAR *) andmask, (void FAR *) xormask);
-
 
158
 
-
 
159
	c = new_cursor_object(hc);
159
    c = new_cursor_object(hc);
160
 
-
 
161
	/* Clean up: */
-
 
162
	discard(andmask);
-
 
163
	discard(xormask);
-
 
164
 
160
 
-
 
161
    /* Clean up: */
-
 
162
    discard(andmask);
-
 
163
    discard(xormask);
-
 
164
 
165
	return c;
165
    return c;
166
}
166
}
167
 
167
 
168
static byte form_and_byte(image img, int x, int y)
168
static byte form_and_byte(image img, int x, int y)
169
{
169
{
170
	int i;
170
    int i;
171
	rgb pixel;
171
    rgb pixel;
172
	byte result = 0x00;
172
    byte result = 0x00;
173
 
173
 
174
	for (i=0; i<8; i++) {
174
    for (i=0; i<8; i++) {
175
		result <<= 1;
175
	result <<= 1;
176
		pixel = get_monochrome_pixel(img, x+i, y);
176
	pixel = get_monochrome_pixel(img, x+i, y);
177
		if (pixel == Transparent)
177
	if (pixel == Transparent)
178
			result |= 0x01;
178
	    result |= 0x01;
179
	}
179
    }
180
	return result;
180
    return result;
181
}
181
}
182
 
182
 
183
static byte form_xor_byte(image img, int x, int y)
183
static byte form_xor_byte(image img, int x, int y)
184
{
184
{
185
	int i;
185
    int i;
186
	rgb pixel;
186
    rgb pixel;
187
	byte result = 0x00;
187
    byte result = 0x00;
188
 
188
 
189
	for (i=0; i<8; i++) {
189
    for (i=0; i<8; i++) {
190
		result <<= 1;
190
	result <<= 1;
191
		pixel = get_monochrome_pixel(img, x+i, y);
191
	pixel = get_monochrome_pixel(img, x+i, y);
192
		if (pixel == White)
192
	if (pixel == White)
193
			result |= 0x01;
193
	    result |= 0x01;
194
	}
194
    }
195
	return result;
195
    return result;
196
}
196
}
197
 
197
 
198
cursor newcursor(point p, image img)
198
cursor newcursor(point p, image img)
199
{
199
{
200
	cursor c;
200
    cursor c;
201
	HCURSOR hc;
201
    HCURSOR hc;
202
	byte *andmask;
202
    byte *andmask;
203
	byte *xormask;
203
    byte *xormask;
204
	int w, y;
204
    int w, y;
205
	int max_width, max_height, row_bytes;
205
    int max_width, max_height, row_bytes;
206
 
206
 
207
	if (! img) return NULL;
207
    if (! img) return NULL;
208
 
208
 
209
	/* Determine the best cursor size: */
209
    /* Determine the best cursor size: */
210
	max_width  = GetSystemMetrics(SM_CXCURSOR);
210
    max_width  = GetSystemMetrics(SM_CXCURSOR);
211
	max_height = GetSystemMetrics(SM_CYCURSOR);
211
    max_height = GetSystemMetrics(SM_CYCURSOR);
212
	row_bytes  = (max_width + 7) / 8;
212
    row_bytes  = (max_width + 7) / 8;
213
 
213
 
214
	/* Create the data arrays: */
214
    /* Create the data arrays: */
215
	andmask = array(max_height * row_bytes, byte);
215
    andmask = array(max_height * row_bytes, byte);
216
	xormask = array(max_height * row_bytes, byte);
216
    xormask = array(max_height * row_bytes, byte);
217
 
217
 
218
	/* Assign the data into the arrays: */
218
    /* Assign the data into the arrays: */
219
	for (y=0; y < max_height; y++) {
219
    for (y=0; y < max_height; y++) {
220
	    for (w=0; w < row_bytes; w++) {
220
	for (w=0; w < row_bytes; w++) {
221
		andmask[w+y*row_bytes] = form_and_byte(img, w*8, y);
221
	    andmask[w+y*row_bytes] = form_and_byte(img, w*8, y);
222
		xormask[w+y*row_bytes] = form_xor_byte(img, w*8, y);
222
	    xormask[w+y*row_bytes] = form_xor_byte(img, w*8, y);
223
	    }
-
 
224
	}
223
	}
-
 
224
    }
-
 
225
 
-
 
226
    /* Create the cursor: */
-
 
227
    hc = CreateCursor (this_instance, p.x, p.y,
-
 
228
		       max_width, max_height,
-
 
229
		       (void FAR *) andmask, (void FAR *) xormask);
-
 
230
 
-
 
231
    c = new_cursor_object(hc);
225
 
232
 
226
	/* Create the cursor: */
-
 
227
	hc = CreateCursor (this_instance, p.x, p.y,
-
 
228
		max_width, max_height,
-
 
229
		(void FAR *) andmask, (void FAR *) xormask);
-
 
230
 
-
 
231
	c = new_cursor_object(hc);
-
 
232
 
-
 
233
	/* Clean up: */
233
    /* Clean up: */
234
	discard(andmask);
234
    discard(andmask);
235
	discard(xormask);
235
    discard(xormask);
236
 
236
 
237
	return c;
237
    return c;
238
}
238
}
239
 
239
 
240
#ifdef UNUSED
240
#ifdef UNUSED
241
/*
241
/*
242
 *  Load a cursor from resources.
242
 *  Load a cursor from resources.
243
 */
243
 */
244
static point load_hotspot(const char *filename)
244
static point load_hotspot(const char *filename)
245
{
245
{
246
	FILE *file;
246
    FILE *file;
247
	char line[100];
247
    char line[100];
248
	int i, x, y;
248
    int i, x, y;
249
	point p = pt(0,0);
249
    point p = pt(0,0);
250
 
250
 
251
	file = fopen(filename, "rt");
251
    file = fopen(filename, "rt");
252
	while (fgets(line, sizeof(line)-2, file)) {
252
    while (fgets(line, sizeof(line)-2, file)) {
253
		if ( (! strncmp(line, "point", 5))
253
	if ( (! strncmp(line, "point", 5))
254
		  || (! strncmp(line, "/* point", 8)) )
254
	     || (! strncmp(line, "/* point", 8)) )
255
		{
255
	{
256
			i = 5;
256
	    i = 5;
257
			x = y = 0;
257
	    x = y = 0;
258
			while (line[i] && (! isdigit(line[i])) )
258
	    while (line[i] && (! isdigit(line[i])) )
259
				i++; /* skip "hotspot = {" */
259
		i++; /* skip "hotspot = {" */
260
			x = atoi(line+i);
260
	    x = atoi(line+i);
261
			while (line[i] && isdigit(line[i]))
261
	    while (line[i] && isdigit(line[i]))
262
				i++; /* skip x-location */
262
		i++; /* skip x-location */
263
			while (line[i] && (! isdigit(line[i])) )
263
	    while (line[i] && (! isdigit(line[i])) )
264
				i++; /* skip comma */
264
		i++; /* skip comma */
265
			y = atoi(line+i);
265
	    y = atoi(line+i);
266
			p = pt(x,y);
266
	    p = pt(x,y);
267
			break;
267
	    break;
268
		}
-
 
269
	}
268
	}
-
 
269
    }
270
	fclose(file);
270
    fclose(file);
271
	return p;
271
    return p;
272
}
272
}
273
 
273
 
274
static cursor load_image_cursor(const char *filename)
274
static cursor load_image_cursor(const char *filename)
275
{
275
{
276
	cursor c = NULL;
276
    cursor c = NULL;
277
	image img;
277
    image img;
278
	point p;
278
    point p;
279
 
279
 
280
	img = loadimage(filename);
280
    img = loadimage(filename);
281
	if (img) {
281
    if (img) {
282
		p = load_hotspot(filename);
282
	p = load_hotspot(filename);
283
		c = newcursor(p, img);
283
	c = newcursor(p, img);
284
		delimage(img);
284
	delimage(img);
285
	}
285
    }
286
	return c;
286
    return c;
287
}
287
}
288
 
288
 
289
cursor loadcursor(const char *name)
289
cursor loadcursor(const char *name)
290
{
290
{
291
	HCURSOR hc;
291
    HCURSOR hc;
292
	cursor c;
292
    cursor c;
293
 
293
 
294
	if (this_instance == 0)
294
    if (this_instance == 0)
295
		return ArrowCursor;
295
	return ArrowCursor;
296
 
296
 
297
	hc = LoadCursor(this_instance, name);
297
    hc = LoadCursor(this_instance, name);
298
 
298
 
299
	if (hc)	c = new_cursor_object(hc);
299
    if (hc)	c = new_cursor_object(hc);
300
	else	c = load_image_cursor(name);
300
    else	c = load_image_cursor(name);
301
 
301
 
302
	if (c)	c->text = new_string(name);
302
    if (c)	c->text = new_string(name);
303
 
303
 
304
	return c;
304
    return c;
305
}
305
}
306
#endif
306
#endif
307
 
307
 
308
/*
308
/*
309
 *  Private cursor initialisation routines.
309
 *  Private cursor initialisation routines.
310
 */
310
 */
311
static cursor make_special_cursor(const char *name, LPCSTR idc)
311
static cursor make_special_cursor(const char *name, LPCSTR idc)
312
{
312
{
313
	cursor c;
313
    cursor c;
314
 
314
 
315
	if (idc) c = new_cursor_object(LoadCursor(0, idc));
315
    if (idc) c = new_cursor_object(LoadCursor(0, idc));
316
	else	 c = new_cursor_object(NULL);
316
    else	 c = new_cursor_object(NULL);
317
 
317
 
318
	if (c) {
318
    if (c) {
319
		c->text = new_string(name);
319
	c->text = new_string(name);
320
		protect_object(c);
320
	protect_object(c);
321
	}
321
    }
322
	return c;
322
    return c;
323
}
323
}
324
 
324
 
325
PROTECTED
325
PROTECTED
326
void init_cursors(void)
326
void init_cursors(void)
327
{
327
{
328
	ArrowCursor = make_special_cursor("ArrowCursor", IDC_ARROW);
328
    ArrowCursor = make_special_cursor("ArrowCursor", IDC_ARROW);
329
	BlankCursor = make_special_cursor("BlankCursor", NULL);
329
    BlankCursor = make_special_cursor("BlankCursor", NULL);
330
	WatchCursor = make_special_cursor("WatchCursor", IDC_WAIT);
330
    WatchCursor = make_special_cursor("WatchCursor", IDC_WAIT);
331
	CaretCursor = make_special_cursor("CaretCursor", IDC_IBEAM);
331
    CaretCursor = make_special_cursor("CaretCursor", IDC_IBEAM);
332
	TextCursor  = make_special_cursor("TextCursor",  IDC_IBEAM);
332
    TextCursor  = make_special_cursor("TextCursor",  IDC_IBEAM);
333
        CrossCursor = make_special_cursor("CrossCursor",  IDC_CROSS);       
333
    CrossCursor = make_special_cursor("CrossCursor",  IDC_CROSS);       
334
 
334
 
335
	HandCursor  = newcursor(hand_hotspot, hand_image);
335
    HandCursor  = newcursor(hand_hotspot, hand_image);
336
	if (HandCursor) {
336
    if (HandCursor) {
337
		settext(HandCursor, "HandCursor");
337
	settext(HandCursor, "HandCursor");
338
		protect_object(HandCursor);
338
	protect_object(HandCursor);
339
	}
339
    }
340
 
340
 
341
	setcursor(ArrowCursor);
341
    setcursor(ArrowCursor);
342
}
342
}