]> git.sur5r.net Git - glabels/blob - src/object-editor-lsize-page.c
Cleanup of shadows for boxes and ellipses.
[glabels] / src / object-editor-lsize-page.c
1 /*
2  *  object-editor-lsize-page.c
3  *  Copyright (C) 2003-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 "object-editor.h"
24
25 #include <glib/gi18n.h>
26 #include <gtk/gtk.h>
27 #include <math.h>
28
29 #include "prefs.h"
30 #include "builder-util.h"
31 #include "units-util.h"
32
33 #include "object-editor-private.h"
34
35 #include "debug.h"
36
37
38 /*===========================================*/
39 /* Private macros                            */
40 /*===========================================*/
41
42 #define LENGTH(x,y) sqrt( (x)*(x) + (y)*(y) )
43 #define ANGLE(x,y)  ( (180.0/G_PI)*atan2( -(y), (x) ) )
44 #define COMP_X(l,a) ( (l) * cos( (G_PI/180.0)*(a) ) )
45 #define COMP_Y(l,a) ( -(l) * sin( (G_PI/180.0)*(a) ) )
46                                                                                 
47
48 /*===========================================*/
49 /* Private data types                        */
50 /*===========================================*/
51
52
53 /*===========================================*/
54 /* Private globals                           */
55 /*===========================================*/
56
57
58 /*===========================================*/
59 /* Local function prototypes                 */
60 /*===========================================*/
61
62
63 /*--------------------------------------------------------------------------*/
64 /* PRIVATE.  Prepare line size page.                                        */
65 /*--------------------------------------------------------------------------*/
66 void
67 gl_object_editor_prepare_lsize_page (glObjectEditor       *editor)
68 {
69         lglUnits      units;
70         const gchar  *units_string;
71         gdouble       climb_rate;
72         gint          digits;
73
74         gl_debug (DEBUG_EDITOR, "START");
75
76         /* Extract widgets from XML tree. */
77         gl_builder_util_get_widgets (editor->priv->builder,
78                                      "lsize_page_vbox",     &editor->priv->lsize_page_vbox,
79                                      "lsize_r_spin",        &editor->priv->lsize_r_spin,
80                                      "lsize_theta_spin",    &editor->priv->lsize_theta_spin,
81                                      "lsize_r_units_label", &editor->priv->lsize_r_units_label,
82                                      NULL);
83
84         /* Get configuration information */
85         units = gl_prefs_model_get_units (gl_prefs);
86         units_string = lgl_units_get_name (units);
87         editor->priv->units_per_point = lgl_units_get_units_per_point (units);
88         climb_rate = gl_units_util_get_step_size (units);
89         digits = gl_units_util_get_precision (units);
90
91         /* Modify widgets based on configuration */
92         gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->lsize_r_spin), digits);
93         gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->lsize_r_spin),
94                                         climb_rate, 0);
95         gtk_label_set_text (GTK_LABEL(editor->priv->lsize_r_units_label), units_string);
96
97         /* Un-hide */
98         gtk_widget_show_all (editor->priv->lsize_page_vbox);
99
100         /* Connect signals */
101         g_signal_connect_swapped (G_OBJECT (editor->priv->lsize_r_spin),
102                                   "changed",
103                                   G_CALLBACK (gl_object_editor_size_changed_cb),
104                                   G_OBJECT (editor));
105         g_signal_connect_swapped (G_OBJECT (editor->priv->lsize_theta_spin),
106                                   "changed",
107                                   G_CALLBACK (gl_object_editor_size_changed_cb),
108                                   G_OBJECT (editor));
109
110         gl_debug (DEBUG_EDITOR, "END");
111 }
112
113
114 /*****************************************************************************/
115 /* Set line size.                                                            */
116 /*****************************************************************************/
117 void
118 gl_object_editor_set_lsize (glObjectEditor      *editor,
119                             gdouble              dx,
120                             gdouble              dy)
121 {
122         gdouble r, theta;
123
124         gl_debug (DEBUG_EDITOR, "START");
125
126         editor->priv->stop_signals = TRUE;
127
128         /* save a copy in internal units */
129         editor->priv->dx = dx;
130         editor->priv->dy = dy;
131
132         /* convert internal units to displayed units */
133         gl_debug (DEBUG_EDITOR, "internal dx,dy = %g, %g", dx, dy);
134         dx *= editor->priv->units_per_point;
135         dy *= editor->priv->units_per_point;
136         gl_debug (DEBUG_EDITOR, "display dx,dy = %g, %g", dx, dy);
137
138         r     = LENGTH (dx, dy);
139         theta = ANGLE (dx, dy);
140
141         /* Set widget values */
142         gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->lsize_r_spin), r);
143         gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->lsize_theta_spin),
144                                    theta);
145
146         editor->priv->stop_signals = FALSE;
147
148         gl_debug (DEBUG_EDITOR, "END");
149 }
150
151
152 /*****************************************************************************/
153 /* Set maximum line size.                                                    */
154 /*****************************************************************************/
155 void
156 gl_object_editor_set_max_lsize (glObjectEditor      *editor,
157                                 gdouble              dx_max,
158                                 gdouble              dy_max)
159 {
160         gdouble tmp;
161
162         gl_debug (DEBUG_EDITOR, "START");
163
164         if (editor->priv->lsize_page_vbox)
165         {
166
167                 editor->priv->stop_signals = TRUE;
168
169                 /* save a copy in internal units */
170                 editor->priv->dx_max = dx_max;
171                 editor->priv->dy_max = dy_max;
172
173                 /* convert internal units to displayed units */
174                 gl_debug (DEBUG_EDITOR, "internal dx_max,dy_max = %g, %g", dx_max, dy_max);
175                 dx_max *= editor->priv->units_per_point;
176                 dy_max *= editor->priv->units_per_point;
177                 gl_debug (DEBUG_EDITOR, "display dx_max,dy_max = %g, %g", dx_max, dy_max);
178
179                 /* Set widget values */
180                 tmp = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->lsize_r_spin));
181                 gtk_spin_button_set_range (GTK_SPIN_BUTTON (editor->priv->lsize_r_spin),
182                                            0.0, 2.0*LENGTH (dx_max, dy_max));
183                 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->lsize_r_spin), tmp);
184
185                 editor->priv->stop_signals = FALSE;
186
187         }
188
189         gl_debug (DEBUG_EDITOR, "END");
190 }
191
192
193 /*****************************************************************************/
194 /* Query line size.                                                          */
195 /*****************************************************************************/
196 void
197 gl_object_editor_get_lsize (glObjectEditor      *editor,
198                             gdouble             *dx,
199                             gdouble             *dy)
200 {
201         gdouble r, theta;
202
203         gl_debug (DEBUG_EDITOR, "START");
204
205         /* Get values from widgets */
206         r = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->lsize_r_spin));
207         theta = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->lsize_theta_spin));
208
209         /* convert everything back to our internal units (points) */
210         r /= editor->priv->units_per_point;
211
212         *dx = COMP_X (r, theta);
213         *dy = COMP_Y (r, theta);
214
215         /* save a copy in internal units */
216         editor->priv->dx = *dx;
217         editor->priv->dy = *dy;
218
219         gl_debug (DEBUG_EDITOR, "END");
220 }
221
222
223 /*****************************************************************************/
224 /* PRIVATE. Prefs changed callback.  Update units related items.            */
225 /*****************************************************************************/
226 void
227 lsize_prefs_changed_cb (glObjectEditor *editor)
228 {
229         lglUnits      units;
230         const gchar  *units_string;
231         gdouble       climb_rate;
232         gint          digits;
233
234         gl_debug (DEBUG_EDITOR, "START");
235
236         /* Get new configuration information */
237         units = gl_prefs_model_get_units (gl_prefs);
238         units_string = lgl_units_get_name (units);
239         editor->priv->units_per_point = lgl_units_get_units_per_point (units);
240         climb_rate = gl_units_util_get_step_size (units);
241         digits = gl_units_util_get_precision (units);
242
243         /* Update characteristics of r_spin */
244         editor->priv->stop_signals = TRUE;
245         gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->lsize_r_spin),
246                                     digits);
247         gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->lsize_r_spin),
248                                         climb_rate, 0);
249         editor->priv->stop_signals = FALSE;
250
251         /* Update r_units_label */
252         gtk_label_set_text (GTK_LABEL(editor->priv->lsize_r_units_label),
253                             units_string);
254
255         /* Update values of r_spin/theta_spin */
256         gl_object_editor_set_lsize (editor,
257                                     editor->priv->dx,
258                                     editor->priv->dy);
259         gl_object_editor_set_max_lsize (editor,
260                                         editor->priv->dx_max,
261                                         editor->priv->dy_max);
262
263         gl_debug (DEBUG_EDITOR, "END");
264 }
265
266
267
268 /*
269  * Local Variables:       -- emacs
270  * mode: C                -- emacs
271  * c-basic-offset: 8      -- emacs
272  * tab-width: 8           -- emacs
273  * indent-tabs-mode: nil  -- emacs
274  * End:                   -- emacs
275  */