Just some CVS ignore stuff.
[dia.git] / app / cursor.c
bloba735951f602e0094566f58dc5ec69a42fb6a4ea4
1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1998 Alexander Larsson
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #include <config.h>
21 #include <gdk/gdk.h>
23 #define DIA_CURSOR GDK_LAST_CURSOR
25 #include "display.h"
26 #include "cursor.h"
28 #include "pixmaps/hand-open-data.xbm"
29 #include "pixmaps/hand-open-mask.xbm"
30 #include "pixmaps/hand-closed-data.xbm"
31 #include "pixmaps/hand-closed-mask.xbm"
32 #include "pixmaps/magnify-plus-data.xbm"
33 #include "pixmaps/magnify-plus-mask.xbm"
34 #include "pixmaps/magnify-minus-data.xbm"
35 #include "pixmaps/magnify-minus-mask.xbm"
37 static struct {
38 /* Can't use a union because it can't be statically initialized
39 (except for the first element) */
40 int gdk_cursor_number;
41 gchar *data;
42 int width;
43 int height;
44 gchar *mask;
45 int hot_x;
46 int hot_y;
47 GdkCursor *cursor;
48 } cursors[MAX_CURSORS] = {
49 { GDK_LEFT_PTR },
50 { GDK_FLEUR },
51 { DIA_CURSOR,
52 hand_open_data_bits,
53 hand_open_data_width, hand_open_data_height,
54 hand_open_mask_bits,
55 hand_open_data_width/2, hand_open_data_height/2},
56 { DIA_CURSOR,
57 hand_closed_data_bits,
58 hand_closed_data_width, hand_closed_data_height,
59 hand_closed_mask_bits,
60 hand_closed_data_width/2, hand_closed_data_height/2},
61 { DIA_CURSOR,
62 magnify_minus_data_bits,
63 magnify_minus_data_width, magnify_minus_data_height,
64 magnify_minus_mask_bits,
65 magnify_minus_data_x_hot, magnify_minus_data_y_hot},
66 { DIA_CURSOR,
67 magnify_plus_data_bits,
68 magnify_plus_data_width, magnify_plus_data_height,
69 magnify_plus_mask_bits,
70 magnify_plus_data_x_hot, magnify_plus_data_y_hot},
71 { GDK_CROSS_REVERSE },
74 GdkCursor *
75 get_cursor(DiaCursorType ctype) {
76 if (ctype >= MAX_CURSORS || ctype < 0) {
77 return NULL;
79 if (cursors[ctype].cursor == NULL) {
80 GdkCursor *new_cursor = NULL;
82 if (cursors[ctype].gdk_cursor_number != DIA_CURSOR) {
83 new_cursor = gdk_cursor_new(cursors[ctype].gdk_cursor_number);
84 } else {
85 DDisplay *active_display = ddisplay_active ();
86 if (active_display != NULL)
87 new_cursor = create_cursor(active_display->canvas->window,
88 cursors[ctype].data,
89 cursors[ctype].width,
90 cursors[ctype].height,
91 cursors[ctype].mask,
92 cursors[ctype].hot_x,
93 cursors[ctype].hot_y);
95 cursors[ctype].cursor = new_cursor;
98 return cursors[ctype].cursor;
101 GdkCursor *
102 create_cursor(GdkWindow *window,
103 const gchar *data, int width, int height,
104 const gchar *mask, int hot_x, int hot_y)
106 GdkBitmap *dbit, *mbit;
107 GdkColor black, white;
108 GdkCursor *cursor;
110 g_return_val_if_fail(window != NULL, NULL);
112 dbit = gdk_bitmap_create_from_data(window, data, width, height);
113 mbit = gdk_bitmap_create_from_data(window, mask, width, height);
114 g_assert(dbit != NULL && mbit != NULL);
116 /* For some odd reason, black and white is inverted */
117 gdk_color_black(gdk_window_get_colormap(window), &white);
118 gdk_color_white(gdk_window_get_colormap(window), &black);
120 cursor = gdk_cursor_new_from_pixmap(dbit, mbit, &white, &black, hot_x,hot_y);
121 g_assert(cursor != NULL);
123 gdk_bitmap_unref(dbit);
124 gdk_bitmap_unref(mbit);
126 return cursor;