]> git.sur5r.net Git - glabels/blob - src/view-image.c
Add shadow property to image objects.
[glabels] / src / view-image.c
1 /*
2  *  view-image.c
3  *  Copyright (C) 2001-2009  Jim Evins <evins@snaught.com>.
4  *
5  *  This file is part of gLabels.
6  *
7  *  gLabels is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation, either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  gLabels is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include <config.h>
22
23 #include "view-image.h"
24
25 #include "label-image.h"
26
27 #include "pixmaps/cursor_image.xbm"
28 #include "pixmaps/cursor_image_mask.xbm"
29
30 #include "debug.h"
31
32
33 /*========================================================*/
34 /* Private macros and constants.                          */
35 /*========================================================*/
36
37
38 /*========================================================*/
39 /* Private types.                                         */
40 /*========================================================*/
41
42
43 /*========================================================*/
44 /* Private globals.                                       */
45 /*========================================================*/
46
47
48 /*========================================================*/
49 /* Private function prototypes.                           */
50 /*========================================================*/
51
52 /*****************************************************************************/
53 /* Return apropos cursor for create object mode.                             */
54 /*****************************************************************************/
55 GdkCursor *
56 gl_view_image_get_create_cursor (void)
57 {
58         GdkCursor       *cursor = NULL;
59         GdkPixmap       *pixmap_data, *pixmap_mask;
60         GdkColor         fg = { 0, 0, 0, 0 };
61         GdkColor         bg = { 0, 65535, 65535, 65535 };
62
63         gl_debug (DEBUG_VIEW, "START");
64
65         pixmap_data = gdk_bitmap_create_from_data (NULL,
66                                                    (gchar *)cursor_image_bits,
67                                                    cursor_image_width,
68                                                    cursor_image_height);
69         pixmap_mask = gdk_bitmap_create_from_data (NULL,
70                                                    (gchar *)cursor_image_mask_bits,
71                                                    cursor_image_mask_width,
72                                                    cursor_image_mask_height);
73         cursor = gdk_cursor_new_from_pixmap (pixmap_data, pixmap_mask, &fg,
74                                              &bg, cursor_image_x_hot,
75                                              cursor_image_y_hot);
76
77         gl_debug (DEBUG_VIEW, "END");
78
79         return cursor;
80 }
81
82
83 /*****************************************************************************/
84 /* Object creation handler: button press event.                              */
85 /*****************************************************************************/
86 void
87 gl_view_image_create_button_press_event   (glView *view,
88                                            gdouble x,
89                                            gdouble y)
90 {
91         GObject             *object;
92
93         gl_label_unselect_all (view->label);
94
95         object = gl_label_image_new (view->label, TRUE);
96
97         gl_label_object_set_position (GL_LABEL_OBJECT(object), x, y, FALSE);
98         gl_label_object_set_size (GL_LABEL_OBJECT(object), 0.0, 0.0, FALSE);
99
100         view->create_object = GL_LABEL_OBJECT (object);
101         view->create_x0 = x;
102         view->create_y0 = y;
103 }
104
105
106 /*****************************************************************************/
107 /* Object creation handler: motion event.                                    */
108 /*****************************************************************************/
109 void
110 gl_view_image_create_motion_event     (glView *view,
111                                        gdouble x,
112                                        gdouble y)
113 {
114         gdouble w, h;
115
116         gl_label_object_set_position (GL_LABEL_OBJECT(view->create_object),
117                                       MIN (x, view->create_x0), MIN (y, view->create_y0),
118                                       FALSE);
119
120         w = MAX (x, view->create_x0) - MIN (x, view->create_x0);
121         h = MAX (y, view->create_y0) - MIN (y, view->create_y0);
122         gl_label_object_set_size (GL_LABEL_OBJECT(view->create_object), w, h, FALSE);
123 }
124
125
126 /*****************************************************************************/
127 /* Object creation handler: button relesase event.                           */
128 /*****************************************************************************/
129 void
130 gl_view_image_create_button_release_event (glView *view,
131                                            gdouble x,
132                                            gdouble y)
133 {
134         gdouble              w, h;
135
136         if ((view->create_x0 == x) && (view->create_y0 == y)) {
137                 x = view->create_x0 + 36.0;
138                 y = view->create_y0 + 36.0;
139         }
140         gl_label_object_set_position (GL_LABEL_OBJECT(view->create_object),
141                                       MIN (x, view->create_x0), MIN (y, view->create_y0),
142                                       FALSE);
143
144         w = MAX (x, view->create_x0) - MIN (x, view->create_x0);
145         h = MAX (y, view->create_y0) - MIN (y, view->create_y0);
146         gl_label_object_set_size (GL_LABEL_OBJECT(view->create_object), w, h, FALSE);
147 }
148
149
150
151 /*
152  * Local Variables:       -- emacs
153  * mode: C                -- emacs
154  * c-basic-offset: 8      -- emacs
155  * tab-width: 8           -- emacs
156  * indent-tabs-mode: nil  -- emacs
157  * End:                   -- emacs
158  */