Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/post/src/tk/cursor.c
3203 views
1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <string.h>
4
#include "tk.h"
5
#include "private.h"
6
7
/******************************************************************************/
8
9
#define MAX_CURSOR 32
10
11
typedef struct _cursorRec {
12
GLint id;
13
Cursor cursor;
14
} cursorRec;
15
16
int cursorNum = 0;
17
cursorRec cursors[MAX_CURSOR];
18
19
/******************************************************************************/
20
21
void tkNewCursor(GLint id, GLubyte *shapeBuf, GLubyte *maskBuf, GLenum fgColor,
22
GLenum bgColor, GLint hotX, GLint hotY)
23
{
24
GLubyte buf[32];
25
Pixmap shapeMap, maskMap;
26
XColor c1, c2;
27
int i;
28
29
if (cursorNum == MAX_CURSOR-1) {
30
return;
31
}
32
33
for (i = 0; i < 32; i += 2) {
34
buf[i] = shapeBuf[i+1];
35
buf[i+1] = shapeBuf[i];
36
}
37
shapeMap = XCreatePixmapFromBitmapData(xDisplay, wRoot, (char*) buf,
38
16, 16, 1, 0, 1);
39
for (i = 0; i < 32; i += 2) {
40
buf[i] = maskBuf[i+1];
41
buf[i+1] = maskBuf[i];
42
}
43
maskMap = XCreatePixmapFromBitmapData(xDisplay, wRoot, (char*) buf,
44
16, 16, 1, 0, 1);
45
c1.red = (unsigned short)(tkRGBMap[fgColor][0] * 65535.0 + 0.5);
46
c1.green = (unsigned short)(tkRGBMap[fgColor][1] * 65535.0 + 0.5);
47
c1.blue = (unsigned short)(tkRGBMap[fgColor][2] * 65535.0 + 0.5);
48
c1.flags = DoRed | DoGreen | DoBlue;
49
c2.red = (unsigned short)(tkRGBMap[bgColor][0] * 65535.0 + 0.5);
50
c2.green = (unsigned short)(tkRGBMap[bgColor][1] * 65535.0 + 0.5);
51
c2.blue = (unsigned short)(tkRGBMap[bgColor][2] * 65535.0 + 0.5);
52
c2.flags = DoRed | DoGreen | DoBlue;
53
54
cursors[cursorNum].id = id;
55
cursors[cursorNum].cursor = XCreatePixmapCursor(xDisplay, shapeMap, maskMap,
56
&c1, &c2, hotX, hotY);
57
cursorNum++;
58
}
59
60
/******************************************************************************/
61
62
void tkSetCursor(GLint id)
63
{
64
int i;
65
66
for (i = 0; i < cursorNum; i++) {
67
if (cursors[i].id == id) {
68
XDefineCursor(xDisplay, w.wMain, cursors[i].cursor);
69
}
70
}
71
}
72
73
/******************************************************************************/
74
75