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"
31 #include "units-util.h"
33 #include "object-editor-private.h"
38 /*===========================================*/
40 /*===========================================*/
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) ) )
48 /*===========================================*/
49 /* Private data types */
50 /*===========================================*/
53 /*===========================================*/
55 /*===========================================*/
58 /*===========================================*/
59 /* Local function prototypes */
60 /*===========================================*/
63 /*--------------------------------------------------------------------------*/
64 /* PRIVATE. Prepare line size page. */
65 /*--------------------------------------------------------------------------*/
67 gl_object_editor_prepare_lsize_page (glObjectEditor *editor)
70 const gchar *units_string;
74 gl_debug (DEBUG_EDITOR, "START");
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,
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);
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),
95 gtk_label_set_text (GTK_LABEL(editor->priv->lsize_r_units_label), units_string);
98 gtk_widget_show_all (editor->priv->lsize_page_vbox);
100 /* Connect signals */
101 g_signal_connect_swapped (G_OBJECT (editor->priv->lsize_r_spin),
103 G_CALLBACK (gl_object_editor_size_changed_cb),
105 g_signal_connect_swapped (G_OBJECT (editor->priv->lsize_theta_spin),
107 G_CALLBACK (gl_object_editor_size_changed_cb),
110 gl_debug (DEBUG_EDITOR, "END");
114 /*****************************************************************************/
116 /*****************************************************************************/
118 gl_object_editor_set_lsize (glObjectEditor *editor,
124 gl_debug (DEBUG_EDITOR, "START");
126 editor->priv->stop_signals = TRUE;
128 /* save a copy in internal units */
129 editor->priv->dx = dx;
130 editor->priv->dy = dy;
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);
139 theta = ANGLE (dx, dy);
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),
146 editor->priv->stop_signals = FALSE;
148 gl_debug (DEBUG_EDITOR, "END");
152 /*****************************************************************************/
153 /* Set maximum line size. */
154 /*****************************************************************************/
156 gl_object_editor_set_max_lsize (glObjectEditor *editor,
162 gl_debug (DEBUG_EDITOR, "START");
164 if (editor->priv->lsize_page_vbox)
167 editor->priv->stop_signals = TRUE;
169 /* save a copy in internal units */
170 editor->priv->dx_max = dx_max;
171 editor->priv->dy_max = dy_max;
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);
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);
185 editor->priv->stop_signals = FALSE;
189 gl_debug (DEBUG_EDITOR, "END");
193 /*****************************************************************************/
194 /* Query line size. */
195 /*****************************************************************************/
197 gl_object_editor_get_lsize (glObjectEditor *editor,
203 gl_debug (DEBUG_EDITOR, "START");
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));
209 /* convert everything back to our internal units (points) */
210 r /= editor->priv->units_per_point;
212 *dx = COMP_X (r, theta);
213 *dy = COMP_Y (r, theta);
215 /* save a copy in internal units */
216 editor->priv->dx = *dx;
217 editor->priv->dy = *dy;
219 gl_debug (DEBUG_EDITOR, "END");
223 /*****************************************************************************/
224 /* PRIVATE. Prefs changed callback. Update units related items. */
225 /*****************************************************************************/
227 lsize_prefs_changed_cb (glObjectEditor *editor)
230 const gchar *units_string;
234 gl_debug (DEBUG_EDITOR, "START");
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);
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),
247 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->lsize_r_spin),
249 editor->priv->stop_signals = FALSE;
251 /* Update r_units_label */
252 gtk_label_set_text (GTK_LABEL(editor->priv->lsize_r_units_label),
255 /* Update values of r_spin/theta_spin */
256 gl_object_editor_set_lsize (editor,
259 gl_object_editor_set_max_lsize (editor,
260 editor->priv->dx_max,
261 editor->priv->dy_max);
263 gl_debug (DEBUG_EDITOR, "END");
269 * Local Variables: -- emacs
271 * c-basic-offset: 8 -- emacs
272 * tab-width: 8 -- emacs
273 * indent-tabs-mode: nil -- emacs