]> git.sur5r.net Git - glabels/blob - src/view-line.c
Imported Upstream version 3.4.0
[glabels] / src / view-line.c
1 /*
2  *  view-line.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-line.h"
24
25 #include <gdk-pixbuf/gdk-pixdata.h>
26
27 #include "label-line.h"
28 #include "cursors/cursor_pixdata.h"
29
30 #include "debug.h"
31
32
33 /*========================================================*/
34 /* Private macros and constants.                          */
35 /*========================================================*/
36
37 #define X_HOTSPOT 7
38 #define Y_HOTSPOT 7
39
40
41 /*========================================================*/
42 /* Private types.                                         */
43 /*========================================================*/
44
45
46 /*========================================================*/
47 /* Private globals.                                       */
48 /*========================================================*/
49
50
51 /*========================================================*/
52 /* Private function prototypes.                           */
53 /*========================================================*/
54
55
56 /*****************************************************************************/
57 /* Return apropos cursor for create object mode.                             */
58 /*****************************************************************************/
59 GdkCursor *
60 gl_view_line_get_create_cursor (void)
61 {
62         GdkCursor       *cursor = NULL;
63         GdkPixbuf       *pixbuf;
64
65         gl_debug (DEBUG_VIEW, "START");
66
67         pixbuf = gdk_pixbuf_from_pixdata (&cursor_line_pixdata, FALSE, NULL);
68         cursor = gdk_cursor_new_from_pixbuf (gdk_display_get_default (), pixbuf, X_HOTSPOT, Y_HOTSPOT);
69         g_object_unref (pixbuf);
70
71         gl_debug (DEBUG_VIEW, "END");
72
73         return cursor;
74 }
75
76
77 /*****************************************************************************/
78 /* Object creation handler: button press event.                              */
79 /*****************************************************************************/
80 void
81 gl_view_line_create_button_press_event (glView  *view,
82                                         gdouble  x,
83                                         gdouble  y)
84 {
85         GObject             *object;
86
87         gl_label_unselect_all (view->label);
88
89         object = gl_label_line_new (view->label, TRUE);
90
91         gl_label_object_set_position (GL_LABEL_OBJECT(object), x, y, FALSE);
92         gl_label_object_set_size (GL_LABEL_OBJECT(object), 0.0, 0.0, FALSE);
93
94         view->create_object = GL_LABEL_OBJECT (object);
95         view->create_x0 = x;
96         view->create_y0 = y;
97 }
98
99
100 /*****************************************************************************/
101 /* Object creation handler: motion event.                                    */
102 /*****************************************************************************/
103 void
104 gl_view_line_create_motion_event (glView  *view,
105                                   gdouble  x,
106                                   gdouble  y,
107                                   gboolean fixed_angle)
108 {
109         gdouble w, h;
110
111         w = x - view->create_x0;
112         h = y - view->create_y0;
113
114         if (fixed_angle &&                                /* step by 45 degree */
115             h != 0) {                                     /* avoid divide by 0 */
116                 if (ABS (w) / ABS (h) < 0.414213562)      /* precalculated tangent of 22,5 degree */
117                         w = 0;                            /* horizontal line */
118                 else if (ABS (w) / ABS (h) > 2.414213562) /* precalculated tangent of 67,5 degree */
119                         h = 0;                            /* vertical line */
120                 else                                      /* diagonal line */
121                         if (w < h)
122                                 h = SIGN_AND_VALUE(h, w);
123                         else
124                                 w = SIGN_AND_VALUE(w, h);
125         }
126
127         gl_label_object_set_size (GL_LABEL_OBJECT(view->create_object), w, h, FALSE);
128 }
129
130
131 /*****************************************************************************/
132 /* Object creation handler: button relesase event.                           */
133 /*****************************************************************************/
134 void
135 gl_view_line_create_button_release_event (glView  *view,
136                                           gdouble  x,
137                                           gdouble  y,
138                                           gboolean fixed_angle)
139 {
140         if ((view->create_x0 == x) && (view->create_y0 == y)) {
141                 x = view->create_x0 + 36.0;
142                 y = view->create_y0 + 36.0;
143         }
144
145         gl_view_line_create_motion_event (view, x, y, fixed_angle);
146 }
147
148
149
150 /*
151  * Local Variables:       -- emacs
152  * mode: C                -- emacs
153  * c-basic-offset: 8      -- emacs
154  * tab-width: 8           -- emacs
155  * indent-tabs-mode: nil  -- emacs
156  * End:                   -- emacs
157  */