33#include <glib/gi18n.h>
56G_DEFINE_TYPE(RendererSettingsDialog, renderer_settings_dialog, GTK_TYPE_DIALOG)
66 const GValue *value, GParamSpec *pspec)
68 const gchar *title = NULL;
70 switch (property_id) {
72 title = g_value_get_string(value);
74 gtk_window_set_title(GTK_WINDOW(
object), title);
77 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, property_id, pspec);
83 GValue *value, GParamSpec *pspec)
87 switch (property_id) {
89 title = gtk_window_get_title(GTK_WINDOW(
object));
90 g_value_set_string(value, title);
93 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, property_id, pspec);
100 GObjectClass *oclass = G_OBJECT_CLASS(klass);
108 N_(
"Cell name to be displayed in header bar"),
116 gtk_widget_show(self->layer_check);
117 gtk_widget_show(self->standalone_check);
123 gtk_widget_hide(self->layer_check);
124 gtk_widget_hide(self->standalone_check);
129 if (gtk_toggle_button_get_active(radio))
139 GtkStyleContext *style_context;
140 GdkRGBA foreground_color;
141 RendererSettingsDialog *dialog = (RendererSettingsDialog *)data;
143 double usable_height;
146 double final_scale_value;
148 style_context = gtk_widget_get_style_context(widget);
149 width = gtk_widget_get_allocated_width(widget);
150 height = gtk_widget_get_allocated_height(widget);
152 gtk_render_background(style_context, cr, 0, 0, width, height);
154 gtk_style_context_get_color(style_context, gtk_style_context_get_state(style_context),
157 gdk_cairo_set_source_rgba(cr, &foreground_color);
162 cairo_scale(cr, 1, -1);
163 cairo_translate(cr, (
double)width/2.0, -(
double)height/2.0);
166 usable_width = (0.95*(double)width) - 15.0;
167 usable_height = (0.95*(double)height) - 15.0;
169 width_scale = usable_width/(double)dialog->cell_width;
170 height_scale = usable_height/(
double)dialog->cell_height;
172 final_scale_value = (width_scale < height_scale ? width_scale : height_scale);
175 -(
double)dialog->cell_width * final_scale_value / 2.0,
176 -(
double)dialog->cell_height * final_scale_value / 2.0,
177 (
double)dialog->cell_width * final_scale_value,
178 (
double)dialog->cell_height * final_scale_value);
187 const char *selected_prefix = NULL;
188 double return_val = 0.0;
190 static const char *
const prefixes[] = {
"y",
"z",
"a",
"f",
"p",
"n",
"u",
"m",
"c",
"d",
192 "h",
"k",
"M",
"G",
"T",
"P",
"E",
"Z",
"Y"};
193 static const double scale[] = {1E-24, 1E-21, 1E-18, 1E-15, 1E-12, 1E-9, 1E-6, 1E-3, 1E-2, 1E-1,
195 1E2, 1E3, 1E6, 1E9, 1E12, 1E15, 1E18, 1E21, 1E24};
196 const int prefix_count = (int)(
sizeof(prefixes)/
sizeof(
char *));
203 for (idx = 1; idx < prefix_count; idx++) {
204 if (input < scale[idx]) {
206 selected_prefix = prefixes[idx-1];
207 return_val = input / scale[idx-1];
213 if (selected_prefix == NULL) {
214 selected_prefix = prefixes[prefix_count-1];
215 return_val = input / scale[prefix_count-1];
219 *out_prefix = selected_prefix;
226 char default_buff[100];
229 double height_meters;
230 double width_engineering;
231 const char *width_prefix;
232 double height_engineering;
233 const char *height_prefix;
238 width_meters = (double)self->cell_width * self->unit_in_meters;
239 height_meters = (
double)self->cell_height * self->unit_in_meters;
244 snprintf(default_buff,
sizeof(default_buff), _(
"Width: %.3lf %sm"), width_engineering, width_prefix);
245 gtk_label_set_text(self->x_label, default_buff);
246 snprintf(default_buff,
sizeof(default_buff), _(
"Height: %.3lf %sm"), height_engineering, height_prefix);
247 gtk_label_set_text(self->y_label, default_buff);
249 scale = gtk_range_get_value(GTK_RANGE(self->scale));
252 snprintf(default_buff,
sizeof(default_buff), _(
"Output Width: %u px"),
253 (
unsigned int)((
double)self->cell_width / scale));
254 gtk_label_set_text(self->x_output_label, default_buff);
255 snprintf(default_buff,
sizeof(default_buff), _(
"Output Height: %u px"),
256 (
unsigned int)((
double)self->cell_height / scale));
257 gtk_label_set_text(self->y_output_label, default_buff);
263 RendererSettingsDialog *dialog;
265 dialog = RENDERER_SETTINGS_DIALOG(user_data);
275 dialog = &self->parent;
277 builder = gtk_builder_new_from_resource(
"/gui/dialog.glade");
278 box = GTK_WIDGET(gtk_builder_get_object(builder,
"dialog-box"));
279 self->radio_latex = GTK_WIDGET(gtk_builder_get_object(builder,
"latex-radio"));
280 self->radio_cairo_pdf = GTK_WIDGET(gtk_builder_get_object(builder,
"cairo-pdf-radio"));
281 self->radio_cairo_svg = GTK_WIDGET(gtk_builder_get_object(builder,
"cairo-svg-radio"));
282 self->scale = GTK_WIDGET(gtk_builder_get_object(builder,
"dialog-scale"));
283 self->standalone_check = GTK_WIDGET(gtk_builder_get_object(builder,
"standalone-check"));
284 self->layer_check = GTK_WIDGET(gtk_builder_get_object(builder,
"layer-check"));
285 self->shape_drawing = GTK_DRAWING_AREA(gtk_builder_get_object(builder,
"shape-drawer"));
286 self->x_label = GTK_LABEL(gtk_builder_get_object(builder,
"x-label"));
287 self->y_label = GTK_LABEL(gtk_builder_get_object(builder,
"y-label"));
288 self->x_output_label = GTK_LABEL(gtk_builder_get_object(builder,
"x-output-label"));
289 self->y_output_label = GTK_LABEL(gtk_builder_get_object(builder,
"y-output-label"));
291 gtk_dialog_add_buttons(dialog, _(
"Cancel"), GTK_RESPONSE_CANCEL, _(
"OK"), GTK_RESPONSE_OK, NULL);
292 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(dialog)), box);
293 gtk_window_set_title(GTK_WINDOW(self), _(
"Renderer Settings"));
296 g_signal_connect(G_OBJECT(self->shape_drawing),
299 g_signal_connect(self->scale,
"value-changed", G_CALLBACK(
scale_value_changed), (gpointer)self);
302 self->cell_width = 1;
303 self->cell_height = 1;
304 self->unit_in_meters = 1E-6;
307 g_object_unref(builder);
312 RendererSettingsDialog *res;
316 gtk_window_set_transient_for(GTK_WINDOW(res), parent);
324 if (!settings || !dialog)
326 settings->
scale = gtk_range_get_value(GTK_RANGE(dialog->scale));
329 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->radio_latex)) == TRUE)
331 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->radio_cairo_pdf)) == TRUE)
333 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->radio_cairo_svg)) == TRUE)
336 settings->
tex_pdf_layers = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->layer_check));
337 settings->
tex_standalone = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->standalone_check));
342 if (!settings || !dialog)
345 gtk_range_set_value(GTK_RANGE(dialog->scale), settings->
scale);
346 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->layer_check), settings->
tex_pdf_layers);
347 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->standalone_check), settings->
tex_standalone);
351 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->radio_latex), TRUE);
356 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->radio_cairo_pdf), TRUE);
360 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->radio_cairo_svg), TRUE);
373 dialog->cell_width = width;
385 dialog->cell_height = height;
394 if (unit_in_meters < 0)
395 unit_in_meters *= -1;
397 dialog->unit_in_meters = unit_in_meters;
Header file for the Conversion Settings Dialog.
static void hide_tex_options(RendererSettingsDialog *self)
static GParamSpec * properties[PROP_COUNT]
static double convert_number_to_engineering(double input, const char **out_prefix)
static void renderer_settings_dialog_update_labels(RendererSettingsDialog *self)
void renderer_settings_dialog_get_settings(RendererSettingsDialog *dialog, struct render_settings *settings)
Get the settings configured in the dialog.
void renderer_settings_dialog_set_cell_height(RendererSettingsDialog *dialog, unsigned int height)
renderer_settings_dialog_set_cell_height Set height for rendered cell
static void renderer_settings_dialog_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
static void latex_render_callback(GtkToggleButton *radio, RendererSettingsDialog *dialog)
static void renderer_settings_dialog_class_init(RendererSettingsDialogClass *klass)
static void show_tex_options(RendererSettingsDialog *self)
void renderer_settings_dialog_set_database_unit_scale(RendererSettingsDialog *dialog, double unit_in_meters)
renderer_settings_dialog_set_database_unit_scale Set database scale
static void scale_value_changed(GtkRange *range, gpointer user_data)
G_END_DECLS void renderer_settings_dialog_set_settings(RendererSettingsDialog *dialog, struct render_settings *settings)
Apply settings to dialog.
static gboolean shape_drawer_drawing_callback(GtkWidget *widget, cairo_t *cr, gpointer data)
static void renderer_settings_dialog_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
static void renderer_settings_dialog_init(RendererSettingsDialog *self)
#define RENDERER_TYPE_SETTINGS_DIALOG
void renderer_settings_dialog_set_cell_width(RendererSettingsDialog *dialog, unsigned int width)
renderer_settings_dialog_set_cell_width Set width for rendered cell
RendererSettingsDialog * renderer_settings_dialog_new(GtkWindow *parent)
Create a new RedererSettingsDialog GObject.
@ RENDERER_CAIROGRAPHICS_PDF
@ RENDERER_CAIROGRAPHICS_SVG
GtkWidget * standalone_check
GtkLabel * x_output_label
GtkLabel * y_output_label
GtkWidget * radio_cairo_pdf
GtkWidget * radio_cairo_svg
GtkDrawingArea * shape_drawing
This struct holds the renderer configuration.
double scale
Scale image down by this factor.
enum output_renderer renderer