1 /*
2 * FIG : Facility for Interactive Generation of figures
3 * Copyright (c) 1985-1988 by Supoj Sutanthavibul
4 * Parts Copyright (c) 1989-2007 by Brian V. Smith
5 * Parts Copyright (c) 1991 by Paul King
6 *
7 * Any party obtaining a copy of these files is granted, free of charge, a
8 * full and unrestricted irrevocable, world-wide, paid up, royalty-free,
9 * nonexclusive right and license to deal in this software and documentation
10 * files (the "Software"), including without limitation the rights to use,
11 * copy, modify, merge, publish, distribute, sublicense and/or sell copies of
12 * the Software, and to permit persons who receive copies from any such
13 * party to do so, with the only requirement being that the above copyright
14 * and this permission notice remain intact.
15 *
16 */
17
18 #include "fig.h"
19 #include "figx.h"
20 #include "resources.h"
21 #include "paintop.h"
22
23 #include "w_util.h"
24
25 #define magnify_width 16
26 #define magnify_height 16
27 #define magnify_x_hot 6
28 #define magnify_y_hot 6
29 static unsigned char magnify_bits[] = {
30 0x40, 0x00, 0xf8, 0x03, 0x4c, 0x06, 0x46, 0x0c, 0x42, 0x08, 0x42, 0x08,
31 0xff, 0x1f, 0x42, 0x08, 0x42, 0x08, 0x46, 0x0c, 0x4c, 0x1e, 0xf8, 0x3f,
32 0x40, 0x7c, 0x00, 0xf8, 0x00, 0xf0, 0x00, 0x60};
33
34
35
36 void
init_cursor(void)37 init_cursor(void)
38 {
39 register Display *d = tool_d;
40 register Pixmap mag_pixmap;
41
42 arrow_cursor = XCreateFontCursor(d, XC_left_ptr);
43 bull_cursor = XCreateFontCursor(d, XC_circle);
44 buster_cursor = XCreateFontCursor(d, XC_pirate);
45 crosshair_cursor = XCreateFontCursor(d, XC_crosshair);
46 null_cursor = XCreateFontCursor(d, XC_tcross);
47 text_cursor = XCreateFontCursor(d, XC_xterm);
48 pick15_cursor = XCreateFontCursor(d, XC_dotbox);
49 pick9_cursor = XCreateFontCursor(d, XC_hand1);
50 wait_cursor = XCreateFontCursor(d, XC_watch);
51 panel_cursor = XCreateFontCursor(d, XC_icon);
52 lr_arrow_cursor = XCreateFontCursor(d, XC_sb_h_double_arrow);
53 l_arrow_cursor = XCreateFontCursor(d, XC_sb_left_arrow);
54 r_arrow_cursor = XCreateFontCursor(d, XC_sb_right_arrow);
55 ud_arrow_cursor = XCreateFontCursor(d, XC_sb_v_double_arrow);
56 u_arrow_cursor = XCreateFontCursor(d, XC_sb_up_arrow);
57 d_arrow_cursor = XCreateFontCursor(d, XC_sb_down_arrow);
58
59 /* we must make our on magnifying glass cursor as there is none
60 in the cursor font */
61 mag_pixmap = XCreateBitmapFromData(tool_d, DefaultRootWindow(tool_d),
62 (char *) magnify_bits, magnify_width, magnify_height);
63 magnify_cursor = XCreatePixmapCursor(d, mag_pixmap, mag_pixmap,
64 &x_fg_color, &x_bg_color, magnify_x_hot, magnify_y_hot);
65 XFreePixmap(tool_d, mag_pixmap);
66
67 cur_cursor = arrow_cursor; /* current cursor */
68 }
69
70 void
recolor_cursors(void)71 recolor_cursors(void)
72 {
73 register Display *d = tool_d;
74
75 XRecolorCursor(d, arrow_cursor, &x_fg_color, &x_bg_color);
76 XRecolorCursor(d, bull_cursor, &x_fg_color, &x_bg_color);
77 XRecolorCursor(d, buster_cursor, &x_fg_color, &x_bg_color);
78 XRecolorCursor(d, crosshair_cursor, &x_fg_color, &x_bg_color);
79 XRecolorCursor(d, null_cursor, &x_fg_color, &x_bg_color);
80 XRecolorCursor(d, text_cursor, &x_fg_color, &x_bg_color);
81 XRecolorCursor(d, pick15_cursor, &x_fg_color, &x_bg_color);
82 XRecolorCursor(d, pick9_cursor, &x_fg_color, &x_bg_color);
83 XRecolorCursor(d, wait_cursor, &x_fg_color, &x_bg_color);
84 XRecolorCursor(d, panel_cursor, &x_fg_color, &x_bg_color);
85 XRecolorCursor(d, l_arrow_cursor, &x_fg_color, &x_bg_color);
86 XRecolorCursor(d, r_arrow_cursor, &x_fg_color, &x_bg_color);
87 XRecolorCursor(d, lr_arrow_cursor, &x_fg_color, &x_bg_color);
88 XRecolorCursor(d, u_arrow_cursor, &x_fg_color, &x_bg_color);
89 XRecolorCursor(d, d_arrow_cursor, &x_fg_color, &x_bg_color);
90 XRecolorCursor(d, ud_arrow_cursor, &x_fg_color, &x_bg_color);
91 XRecolorCursor(d, magnify_cursor, &x_fg_color, &x_bg_color);
92 }
93
94 static Cursor active_cursor = None;
95
96 void
reset_cursor(void)97 reset_cursor(void)
98 {
99 if (active_cursor != cur_cursor) {
100 active_cursor = cur_cursor;
101 XDefineCursor(tool_d, main_canvas, cur_cursor);
102 app_flush();
103 }
104 }
105
106 void
set_temp_cursor(Cursor cursor)107 set_temp_cursor(Cursor cursor)
108 {
109 if (active_cursor != cursor) {
110 active_cursor = cursor;
111 XDefineCursor(tool_d, main_canvas, cursor);
112 app_flush();
113 }
114 }
115
116 void
set_cursor(Cursor cursor)117 set_cursor(Cursor cursor)
118 {
119 cur_cursor = cursor;
120 if (active_cursor != cur_cursor) {
121 active_cursor = cur_cursor;
122 XDefineCursor(tool_d, main_canvas, cursor);
123 app_flush();
124 }
125 }
126