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 editor->priv->lsize_page_vbox =
77 glade_xml_get_widget (editor->priv->gui, "lsize_page_vbox");
78 editor->priv->lsize_r_spin =
79 glade_xml_get_widget (editor->priv->gui, "lsize_r_spin");
80 editor->priv->lsize_theta_spin =
81 glade_xml_get_widget (editor->priv->gui, "lsize_theta_spin");
82 editor->priv->lsize_r_units_label =
83 glade_xml_get_widget (editor->priv->gui, "lsize_r_units_label");
85 /* Get configuration information */
86 units_string = gl_prefs_get_units_string ();
87 editor->priv->units_per_point = gl_prefs_get_units_per_point ();
88 climb_rate = gl_prefs_get_units_step_size ();
89 digits = gl_prefs_get_units_precision ();
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, 10.0*climb_rate);
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_changed_cb),
105 g_signal_connect_swapped (G_OBJECT (editor->priv->lsize_theta_spin),
107 G_CALLBACK (gl_object_editor_changed_cb),
110 gl_debug (DEBUG_EDITOR, "END");
113 /*****************************************************************************/
115 /*****************************************************************************/
117 gl_object_editor_set_lsize (glObjectEditor *editor,
123 gl_debug (DEBUG_EDITOR, "START");
125 editor->priv->stop_signals = TRUE;
127 /* save a copy in internal units */
128 editor->priv->dx = dx;
129 editor->priv->dy = dy;
131 /* convert internal units to displayed units */
132 gl_debug (DEBUG_EDITOR, "internal dx,dy = %g, %g", dx, dy);
133 dx *= editor->priv->units_per_point;
134 dy *= editor->priv->units_per_point;
135 gl_debug (DEBUG_EDITOR, "display dx,dy = %g, %g", dx, dy);
138 theta = ANGLE (dx, dy);
140 /* Set widget values */
141 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->lsize_r_spin), r);
142 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->lsize_theta_spin),
145 editor->priv->stop_signals = FALSE;
147 gl_debug (DEBUG_EDITOR, "END");
150 /*****************************************************************************/
151 /* Set maximum line size. */
152 /*****************************************************************************/
154 gl_object_editor_set_max_lsize (glObjectEditor *editor,
160 gl_debug (DEBUG_EDITOR, "START");
162 editor->priv->stop_signals = TRUE;
164 /* save a copy in internal units */
165 editor->priv->dx_max = dx_max;
166 editor->priv->dy_max = dy_max;
168 /* convert internal units to displayed units */
169 gl_debug (DEBUG_EDITOR, "internal dx_max,dy_max = %g, %g", dx_max, dy_max);
170 dx_max *= editor->priv->units_per_point;
171 dy_max *= editor->priv->units_per_point;
172 gl_debug (DEBUG_EDITOR, "display dx_max,dy_max = %g, %g", dx_max, dy_max);
174 /* Set widget values */
175 tmp = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->lsize_r_spin));
176 gtk_spin_button_set_range (GTK_SPIN_BUTTON (editor->priv->lsize_r_spin),
177 0.0, 2.0*LENGTH (dx_max, dy_max));
178 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->lsize_r_spin), tmp);
180 editor->priv->stop_signals = FALSE;
182 gl_debug (DEBUG_EDITOR, "END");
185 /*****************************************************************************/
186 /* Query line size. */
187 /*****************************************************************************/
189 gl_object_editor_get_lsize (glObjectEditor *editor,
195 gl_debug (DEBUG_EDITOR, "START");
197 /* Get values from widgets */
198 r = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->lsize_r_spin));
199 theta = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->lsize_theta_spin));
201 /* convert everything back to our internal units (points) */
202 r /= editor->priv->units_per_point;
204 *dx = COMP_X (r, theta);
205 *dy = COMP_Y (r, theta);
207 /* save a copy in internal units */
208 editor->priv->dx = *dx;
209 editor->priv->dy = *dy;
211 gl_debug (DEBUG_EDITOR, "END");
214 /*****************************************************************************/
215 /* PRIVATE. Prefs changed callback. Update units related items. */
216 /*****************************************************************************/
218 lsize_prefs_changed_cb (glObjectEditor *editor)
220 const gchar *units_string;
224 gl_debug (DEBUG_EDITOR, "START");
226 /* Get new configuration information */
227 units_string = gl_prefs_get_units_string ();
228 editor->priv->units_per_point = gl_prefs_get_units_per_point ();
229 climb_rate = gl_prefs_get_units_step_size ();
230 digits = gl_prefs_get_units_precision ();
232 /* Update characteristics of r_spin */
233 editor->priv->stop_signals = TRUE;
234 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->lsize_r_spin),
236 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->lsize_r_spin),
237 climb_rate, 10.0*climb_rate);
238 editor->priv->stop_signals = FALSE;
240 /* Update r_units_label */
241 gtk_label_set_text (GTK_LABEL(editor->priv->lsize_r_units_label),
244 /* Update values of r_spin/theta_spin */
245 gl_object_editor_set_lsize (editor,
248 gl_object_editor_set_max_lsize (editor,
249 editor->priv->dx_max,
250 editor->priv->dy_max);
252 gl_debug (DEBUG_EDITOR, "END");