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
|
#define __SP_CURSOR_C__
/*
* Some convenience stuff
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
*
* Copyright (C) 1999-2002 authors
* Copyright (C) 2001-2002 Ximian, Inc.
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include <string.h>
#include <ctype.h>
#include "sp-cursor.h"
void sp_cursor_bitmap_and_mask_from_xpm (GdkBitmap **bitmap, GdkBitmap **mask, gchar **xpm)
{
int height;
int width;
int colors;
int pix;
sscanf(xpm[0], "%d %d %d %d", &height, &width, &colors, &pix);
g_return_if_fail (height == 32);
g_return_if_fail (width == 32);
g_return_if_fail (colors >= 3);
int transparent_color = ' ';
int black_color = '.';
char pixmap_buffer[(32 * 32)/8];
char mask_buffer[(32 * 32)/8];
for (int i = 0; i < colors; i++) {
char const *p = xpm[1 + i];
char const ccode = *p;
p++;
while (isspace(*p)) {
p++;
}
p++;
while (isspace(*p)) {
p++;
}
if (strcmp(p, "None") == 0) {
transparent_color = ccode;
}
if (strcmp(p, "#000000") == 0) {
black_color = ccode;
}
}
for (int y = 0; y < 32; y++) {
for (int x = 0; x < 32; ) {
char value = 0;
char maskv = 0;
for (int pix = 0; pix < 8; pix++, x++){
if (xpm [4+y][x] != transparent_color) {
maskv |= 1 << pix;
if (xpm [4+y][x] == black_color) {
value |= 1 << pix;
}
}
}
pixmap_buffer[(y * 4 + x/8)-1] = value;
mask_buffer[(y * 4 + x/8)-1] = maskv;
}
}
*bitmap = gdk_bitmap_create_from_data(NULL, pixmap_buffer, 32, 32);
*mask = gdk_bitmap_create_from_data(NULL, mask_buffer, 32, 32);
}
GdkCursor *sp_cursor_new_from_xpm (gchar **xpm, gint hot_x, gint hot_y)
{
GdkDisplay *display=gdk_display_get_default();
if (
gdk_display_supports_cursor_alpha(display) &
gdk_display_supports_cursor_color(display)
)
{
GdkPixbuf *pixbuf=NULL;
GdkCursor *new_cursor=NULL;
pixbuf=gdk_pixbuf_new_from_xpm_data((const char**)xpm);
if (pixbuf != NULL){
new_cursor = gdk_cursor_new_from_pixbuf(display,pixbuf,hot_x,hot_y);
}
return new_cursor;
}
else
{
GdkColor const fg = { 0, 0, 0, 0 };
GdkColor const bg = { 0, 65535, 65535, 65535 };
GdkBitmap *bitmap = NULL;
GdkBitmap *mask = NULL;
sp_cursor_bitmap_and_mask_from_xpm (&bitmap, &mask, xpm);
if ( bitmap != NULL && mask != NULL ) {
GdkCursor *new_cursor = gdk_cursor_new_from_pixmap (bitmap, mask,
&fg, &bg,
hot_x, hot_y);
g_object_unref (bitmap);
g_object_unref (mask);
return new_cursor;
}
}
return NULL;
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
|