2 * object-editor-lsize-page.c
3 * Copyright (C) 2003-2009 Jim Evins <evins@snaught.com>.
5 * This file is part of gLabels.
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.
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.
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/>.
23 #include "object-editor.h"
25 #include <glib/gi18n.h>
30 #include "builder-util.h"
32 #include "object-editor-private.h"
37 /*===========================================*/
39 /*===========================================*/
41 #define LENGTH(x,y) sqrt( (x)*(x) + (y)*(y) )
42 #define ANGLE(x,y) ( (180.0/G_PI)*atan2( -(y), (x) ) )
43 #define COMP_X(l,a) ( (l) * cos( (G_PI/180.0)*(a) ) )
44 #define COMP_Y(l,a) ( -(l) * sin( (G_PI/180.0)*(a) ) )
47 /*===========================================*/
48 /* Private data types */
49 /*===========================================*/
52 /*===========================================*/
54 /*===========================================*/
57 /*===========================================*/
58 /* Local function prototypes */
59 /*===========================================*/
62 /*--------------------------------------------------------------------------*/
63 /* PRIVATE. Prepare line size page. */
64 /*--------------------------------------------------------------------------*/
66 gl_object_editor_prepare_lsize_page (glObjectEditor *editor)
68 const gchar *units_string;
72 gl_debug (DEBUG_EDITOR, "START");
74 /* Extract widgets from XML tree. */
75 gl_builder_util_get_widgets (editor->priv->builder,
76 "lsize_page_vbox", &editor->priv->lsize_page_vbox,
77 "lsize_r_spin", &editor->priv->lsize_r_spin,
78 "lsize_theta_spin", &editor->priv->lsize_theta_spin,
79 "lsize_r_units_label", &editor->priv->lsize_r_units_label,
82 /* Get configuration information */
83 units_string = gl_prefs_get_units_string ();
84 editor->priv->units_per_point = gl_prefs_get_units_per_point ();
85 climb_rate = gl_prefs_get_units_step_size ();
86 digits = gl_prefs_get_units_precision ();
88 /* Modify widgets based on configuration */
89 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->lsize_r_spin), digits);
90 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->lsize_r_spin),
92 gtk_label_set_text (GTK_LABEL(editor->priv->lsize_r_units_label), units_string);
95 gtk_widget_show_all (editor->priv->lsize_page_vbox);
98 g_signal_connect_swapped (G_OBJECT (editor->priv->lsize_r_spin),
100 G_CALLBACK (gl_object_editor_changed_cb),
102 g_signal_connect_swapped (G_OBJECT (editor->priv->lsize_theta_spin),
104 G_CALLBACK (gl_object_editor_changed_cb),
107 gl_debug (DEBUG_EDITOR, "END");
111 /*****************************************************************************/
113 /*****************************************************************************/
115 gl_object_editor_set_lsize (glObjectEditor *editor,
121 gl_debug (DEBUG_EDITOR, "START");
123 editor->priv->stop_signals = TRUE;
125 /* save a copy in internal units */
126 editor->priv->dx = dx;
127 editor->priv->dy = dy;
129 /* convert internal units to displayed units */
130 gl_debug (DEBUG_EDITOR, "internal dx,dy = %g, %g", dx, dy);
131 dx *= editor->priv->units_per_point;
132 dy *= editor->priv->units_per_point;
133 gl_debug (DEBUG_EDITOR, "display dx,dy = %g, %g", dx, dy);
136 theta = ANGLE (dx, dy);
138 /* Set widget values */
139 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->lsize_r_spin), r);
140 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->lsize_theta_spin),
143 editor->priv->stop_signals = FALSE;
145 gl_debug (DEBUG_EDITOR, "END");
149 /*****************************************************************************/
150 /* Set maximum line size. */
151 /*****************************************************************************/
153 gl_object_editor_set_max_lsize (glObjectEditor *editor,
159 gl_debug (DEBUG_EDITOR, "START");
161 if (editor->priv->lsize_page_vbox)
164 editor->priv->stop_signals = TRUE;
166 /* save a copy in internal units */
167 editor->priv->dx_max = dx_max;
168 editor->priv->dy_max = dy_max;
170 /* convert internal units to displayed units */
171 gl_debug (DEBUG_EDITOR, "internal dx_max,dy_max = %g, %g", dx_max, dy_max);
172 dx_max *= editor->priv->units_per_point;
173 dy_max *= editor->priv->units_per_point;
174 gl_debug (DEBUG_EDITOR, "display dx_max,dy_max = %g, %g", dx_max, dy_max);
176 /* Set widget values */
177 tmp = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->lsize_r_spin));
178 gtk_spin_button_set_range (GTK_SPIN_BUTTON (editor->priv->lsize_r_spin),
179 0.0, 2.0*LENGTH (dx_max, dy_max));
180 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->lsize_r_spin), tmp);
182 editor->priv->stop_signals = FALSE;
186 gl_debug (DEBUG_EDITOR, "END");
190 /*****************************************************************************/
191 /* Query line size. */
192 /*****************************************************************************/
194 gl_object_editor_get_lsize (glObjectEditor *editor,
200 gl_debug (DEBUG_EDITOR, "START");
202 /* Get values from widgets */
203 r = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->lsize_r_spin));
204 theta = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->lsize_theta_spin));
206 /* convert everything back to our internal units (points) */
207 r /= editor->priv->units_per_point;
209 *dx = COMP_X (r, theta);
210 *dy = COMP_Y (r, theta);
212 /* save a copy in internal units */
213 editor->priv->dx = *dx;
214 editor->priv->dy = *dy;
216 gl_debug (DEBUG_EDITOR, "END");
220 /*****************************************************************************/
221 /* PRIVATE. Prefs changed callback. Update units related items. */
222 /*****************************************************************************/
224 lsize_prefs_changed_cb (glObjectEditor *editor)
226 const gchar *units_string;
230 gl_debug (DEBUG_EDITOR, "START");
232 /* Get new configuration information */
233 units_string = gl_prefs_get_units_string ();
234 editor->priv->units_per_point = gl_prefs_get_units_per_point ();
235 climb_rate = gl_prefs_get_units_step_size ();
236 digits = gl_prefs_get_units_precision ();
238 /* Update characteristics of r_spin */
239 editor->priv->stop_signals = TRUE;
240 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->lsize_r_spin),
242 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->lsize_r_spin),
244 editor->priv->stop_signals = FALSE;
246 /* Update r_units_label */
247 gtk_label_set_text (GTK_LABEL(editor->priv->lsize_r_units_label),
250 /* Update values of r_spin/theta_spin */
251 gl_object_editor_set_lsize (editor,
254 gl_object_editor_set_max_lsize (editor,
255 editor->priv->dx_max,
256 editor->priv->dy_max);
258 gl_debug (DEBUG_EDITOR, "END");
264 * Local Variables: -- emacs
266 * c-basic-offset: 8 -- emacs
267 * tab-width: 8 -- emacs
268 * indent-tabs-mode: nil -- emacs