]> git.sur5r.net Git - glabels/blob - src/view-box.c
Added undo/redo feature
[glabels] / src / view-box.c
1 /*
2  *  view-box.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-box.h"
24
25 #include "label-box.h"
26
27 #include "pixmaps/cursor_box.xbm"
28 #include "pixmaps/cursor_box_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 /*****************************************************************************/
54 /* Return apropos cursor for create object mode.                             */
55 /*****************************************************************************/
56 GdkCursor *
57 gl_view_box_get_create_cursor (void)
58 {
59         GdkCursor       *cursor = NULL;
60         GdkPixmap       *pixmap_data, *pixmap_mask;
61         GdkColor         fg = { 0, 0, 0, 0 };
62         GdkColor         bg = { 0, 65535, 65535, 65535 };
63
64         gl_debug (DEBUG_VIEW, "START");
65
66         pixmap_data = gdk_bitmap_create_from_data (NULL,
67                                                    (gchar *)cursor_box_bits,
68                                                    cursor_box_width,
69                                                    cursor_box_height);
70         pixmap_mask = gdk_bitmap_create_from_data (NULL,
71                                                    (gchar *)cursor_box_mask_bits,
72                                                    cursor_box_mask_width,
73                                                    cursor_box_mask_height);
74         cursor = gdk_cursor_new_from_pixmap (pixmap_data, pixmap_mask, &fg,
75                                              &bg, cursor_box_x_hot,
76                                              cursor_box_y_hot);
77
78         gl_debug (DEBUG_VIEW, "END");
79
80         return cursor;
81 }
82
83
84 /*****************************************************************************/
85 /* Object creation handler: button press event.                              */
86 /*****************************************************************************/
87 void
88 gl_view_box_create_button_press_event   (glView *view,
89                                          gdouble x,
90                                          gdouble y)
91 {
92         GObject             *object;
93
94         gl_label_unselect_all (view->label);
95
96         object = gl_label_box_new (view->label, TRUE);
97
98         gl_label_object_set_position (GL_LABEL_OBJECT(object), x, y, FALSE);
99         gl_label_object_set_size (GL_LABEL_OBJECT(object), 0.0, 0.0, FALSE);
100                         
101         view->create_object = GL_LABEL_OBJECT (object);
102         view->create_x0 = x;
103         view->create_y0 = y;
104 }
105
106
107 /*****************************************************************************/
108 /* Object creation handler: motion event.                                    */
109 /*****************************************************************************/
110 void
111 gl_view_box_create_motion_event         (glView *view,
112                                          gdouble x,
113                                          gdouble y)
114 {
115         gdouble w, h;
116
117         gl_label_object_set_position (GL_LABEL_OBJECT(view->create_object),
118                                       MIN (x, view->create_x0), MIN (y, view->create_y0),
119                                       FALSE);
120
121         w = MAX (x, view->create_x0) - MIN (x, view->create_x0);
122         h = MAX (y, view->create_y0) - MIN (y, view->create_y0);
123         gl_label_object_set_size (GL_LABEL_OBJECT(view->create_object), w, h, FALSE);
124 }
125
126
127 /*****************************************************************************/
128 /* Object creation handler: button relesase event.                           */
129 /*****************************************************************************/
130 void
131 gl_view_box_create_button_release_event (glView *view,
132                                          gdouble x,
133                                          gdouble y)
134 {
135         gdouble              w, h;
136
137         if ((view->create_x0 == x) && (view->create_y0 == y)) {
138                 x = view->create_x0 + 36.0;
139                 y = view->create_y0 + 36.0;
140         }
141         gl_label_object_set_position (GL_LABEL_OBJECT(view->create_object),
142                                       MIN (x, view->create_x0), MIN (y, view->create_y0),
143                                       FALSE);
144
145         w = MAX (x, view->create_x0) - MIN (x, view->create_x0);
146         h = MAX (y, view->create_y0) - MIN (y, view->create_y0);
147         gl_label_object_set_size (GL_LABEL_OBJECT(view->create_object), w, h, FALSE);
148 }
149
150
151
152 /*
153  * Local Variables:       -- emacs
154  * mode: C                -- emacs
155  * c-basic-offset: 8      -- emacs
156  * tab-width: 8           -- emacs
157  * indent-tabs-mode: nil  -- emacs
158  * End:                   -- emacs
159  */