1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
4 * (GLABELS) Label and Business Card Creation program for GNOME
6 * object-editor.c: object properties editor module
8 * Copyright (C) 2003 Jim Evins <evins@snaught.com>.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "object-editor.h"
28 #include <glib/gi18n.h>
29 #include <gtk/gtklabel.h>
30 #include <gtk/gtkspinbutton.h>
35 #include "object-editor-private.h"
39 /*===========================================*/
41 /*===========================================*/
43 #define LENGTH(x,y) sqrt( (x)*(x) + (y)*(y) )
44 #define ANGLE(x,y) ( (180.0/G_PI)*atan2( -(y), (x) ) )
45 #define COMP_X(l,a) ( (l) * cos( (G_PI/180.0)*(a) ) )
46 #define COMP_Y(l,a) ( -(l) * sin( (G_PI/180.0)*(a) ) )
49 /*===========================================*/
50 /* Private data types */
51 /*===========================================*/
53 /*===========================================*/
55 /*===========================================*/
57 /*===========================================*/
58 /* Local function prototypes */
59 /*===========================================*/
63 /*--------------------------------------------------------------------------*/
64 /* PRIVATE. Prepare line size page. */
65 /*--------------------------------------------------------------------------*/
67 gl_object_editor_prepare_lsize_page (glObjectEditor *editor)
69 const gchar *units_string;
73 gl_debug (DEBUG_EDITOR, "START");
75 /* Extract widgets from XML tree. */
76 gl_util_get_builder_widgets (editor->priv->gui,
77 "lsize_page_vbox", &editor->priv->lsize_page_vbox,
78 "lsize_r_spin", &editor->priv->lsize_r_spin,
79 "lsize_theta_spin", &editor->priv->lsize_theta_spin,
80 "lsize_r_units_label", &editor->priv->lsize_r_units_label,
83 /* Get configuration information */
84 units_string = gl_prefs_get_units_string ();
85 editor->priv->units_per_point = gl_prefs_get_units_per_point ();
86 climb_rate = gl_prefs_get_units_step_size ();
87 digits = gl_prefs_get_units_precision ();
89 /* Modify widgets based on configuration */
90 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->lsize_r_spin), digits);
91 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->lsize_r_spin),
93 gtk_label_set_text (GTK_LABEL(editor->priv->lsize_r_units_label), units_string);
96 gtk_widget_show_all (editor->priv->lsize_page_vbox);
99 g_signal_connect_swapped (G_OBJECT (editor->priv->lsize_r_spin),
101 G_CALLBACK (gl_object_editor_changed_cb),
103 g_signal_connect_swapped (G_OBJECT (editor->priv->lsize_theta_spin),
105 G_CALLBACK (gl_object_editor_changed_cb),
108 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");
148 /*****************************************************************************/
149 /* Set maximum line size. */
150 /*****************************************************************************/
152 gl_object_editor_set_max_lsize (glObjectEditor *editor,
158 gl_debug (DEBUG_EDITOR, "START");
160 if (editor->priv->lsize_page_vbox)
163 editor->priv->stop_signals = TRUE;
165 /* save a copy in internal units */
166 editor->priv->dx_max = dx_max;
167 editor->priv->dy_max = dy_max;
169 /* convert internal units to displayed units */
170 gl_debug (DEBUG_EDITOR, "internal dx_max,dy_max = %g, %g", dx_max, dy_max);
171 dx_max *= editor->priv->units_per_point;
172 dy_max *= editor->priv->units_per_point;
173 gl_debug (DEBUG_EDITOR, "display dx_max,dy_max = %g, %g", dx_max, dy_max);
175 /* Set widget values */
176 tmp = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->lsize_r_spin));
177 gtk_spin_button_set_range (GTK_SPIN_BUTTON (editor->priv->lsize_r_spin),
178 0.0, 2.0*LENGTH (dx_max, dy_max));
179 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->lsize_r_spin), tmp);
181 editor->priv->stop_signals = FALSE;
185 gl_debug (DEBUG_EDITOR, "END");
188 /*****************************************************************************/
189 /* Query line size. */
190 /*****************************************************************************/
192 gl_object_editor_get_lsize (glObjectEditor *editor,
198 gl_debug (DEBUG_EDITOR, "START");
200 /* Get values from widgets */
201 r = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->lsize_r_spin));
202 theta = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->lsize_theta_spin));
204 /* convert everything back to our internal units (points) */
205 r /= editor->priv->units_per_point;
207 *dx = COMP_X (r, theta);
208 *dy = COMP_Y (r, theta);
210 /* save a copy in internal units */
211 editor->priv->dx = *dx;
212 editor->priv->dy = *dy;
214 gl_debug (DEBUG_EDITOR, "END");
217 /*****************************************************************************/
218 /* PRIVATE. Prefs changed callback. Update units related items. */
219 /*****************************************************************************/
221 lsize_prefs_changed_cb (glObjectEditor *editor)
223 const gchar *units_string;
227 gl_debug (DEBUG_EDITOR, "START");
229 /* Get new configuration information */
230 units_string = gl_prefs_get_units_string ();
231 editor->priv->units_per_point = gl_prefs_get_units_per_point ();
232 climb_rate = gl_prefs_get_units_step_size ();
233 digits = gl_prefs_get_units_precision ();
235 /* Update characteristics of r_spin */
236 editor->priv->stop_signals = TRUE;
237 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->lsize_r_spin),
239 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->lsize_r_spin),
241 editor->priv->stop_signals = FALSE;
243 /* Update r_units_label */
244 gtk_label_set_text (GTK_LABEL(editor->priv->lsize_r_units_label),
247 /* Update values of r_spin/theta_spin */
248 gl_object_editor_set_lsize (editor,
251 gl_object_editor_set_max_lsize (editor,
252 editor->priv->dx_max,
253 editor->priv->dy_max);
255 gl_debug (DEBUG_EDITOR, "END");