diff --git a/glade/dialog.glade b/glade/dialog.glade
index f5aeed0..527d0ad 100644
--- a/glade/dialog.glade
+++ b/glade/dialog.glade
@@ -4,7 +4,7 @@
@@ -108,7 +109,7 @@
@@ -118,5 +119,38 @@
6
+
+
+
+ False
+ True
+ 7
+
+
diff --git a/widgets/conv-settings-dialog.c b/widgets/conv-settings-dialog.c
index e4280e1..14c8922 100644
--- a/widgets/conv-settings-dialog.c
+++ b/widgets/conv-settings-dialog.c
@@ -39,12 +39,16 @@ struct _RendererSettingsDialog {
GtkWidget *scale;
GtkWidget *layer_check;
GtkWidget *standalone_check;
+ GtkDrawingArea *shape_drawing;
+ GtkLabel *x_label;
+ GtkLabel *y_label;
+
+ double cell_height;
+ double cell_width;
};
G_DEFINE_TYPE(RendererSettingsDialog, renderer_settings_dialog, GTK_TYPE_DIALOG)
-
-
static void renderer_settings_dialog_class_init(RendererSettingsDialogClass *klass)
{
/* No special code needed. Child cells are destroyed automatically due to reference counter */
@@ -72,11 +76,59 @@ static void latex_render_callback(GtkToggleButton *radio, RendererSettingsDialog
hide_tex_options(dialog);
}
+static gboolean shape_drawer_drawing_callback(GtkWidget *widget, cairo_t *cr, gpointer data)
+{
+ int width;
+ int height;
+ GtkStyleContext *style_context;
+ GdkRGBA foreground_color;
+ RendererSettingsDialog *dialog = (RendererSettingsDialog *)data;
+ double usable_width;
+ double usable_height;
+ double height_scale;
+ double width_scale;
+ double final_scale_value;
+
+ style_context = gtk_widget_get_style_context(widget);
+ width = gtk_widget_get_allocated_width(widget);
+ height = gtk_widget_get_allocated_height(widget);
+
+ gtk_render_background(style_context, cr, 0, 0, width, height);
+
+ gtk_style_context_get_color(style_context, gtk_style_context_get_state(style_context),
+ &foreground_color);
+
+ gdk_cairo_set_source_rgba(cr, &foreground_color);
+
+ cairo_save(cr);
+
+ /* Tranform coordiante system */
+ cairo_scale(cr, 1, -1);
+ cairo_translate(cr, (double)width/2.0, -(double)height/2.0);
+
+ /* Define usable drawing area */
+ usable_width = (0.95*(double)width) - 15.0;
+ usable_height = (0.95*(double)height) - 15.0;
+
+ width_scale = usable_width/dialog->cell_width;
+ height_scale = usable_height/dialog->cell_height;
+
+ final_scale_value = (width_scale < height_scale ? width_scale : height_scale);
+
+ cairo_rectangle(cr, -dialog->cell_width*final_scale_value/2, -dialog->cell_height*final_scale_value/2,
+ dialog->cell_width*final_scale_value, dialog->cell_height*final_scale_value);
+ cairo_stroke(cr);
+ cairo_restore(cr);
+
+ return FALSE;
+}
+
static void renderer_settings_dialog_init(RendererSettingsDialog *self)
{
GtkBuilder *builder;
GtkWidget *box;
GtkDialog *dialog;
+ char default_buff[100];
dialog = &(self->parent);
@@ -89,12 +141,26 @@ static void renderer_settings_dialog_init(RendererSettingsDialog *self)
self->scale = GTK_WIDGET(gtk_builder_get_object(builder, "dialog-scale"));
self->standalone_check = GTK_WIDGET(gtk_builder_get_object(builder, "standalone-check"));
self->layer_check = GTK_WIDGET(gtk_builder_get_object(builder, "layer-check"));
+ self->shape_drawing = GTK_DRAWING_AREA(gtk_builder_get_object(builder, "shape-drawer"));
+ self->x_label = GTK_LABEL(gtk_builder_get_object(builder, "x-label"));
+ self->y_label = GTK_LABEL(gtk_builder_get_object(builder, "y-label"));
gtk_dialog_add_buttons(dialog, "Cancel", GTK_RESPONSE_CANCEL, "OK", GTK_RESPONSE_OK, NULL);
gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(dialog)), box);
gtk_window_set_title(GTK_WINDOW(self), "Renderer Settings");
g_signal_connect(self->radio_latex, "toggled", G_CALLBACK(latex_render_callback), (gpointer)self);
+ g_signal_connect(G_OBJECT(self->shape_drawing),
+ "draw", G_CALLBACK(shape_drawer_drawing_callback), (gpointer)self);
+
+ /* Default values */
+ self->cell_width = 1E-6;
+ self->cell_height = 1E-6;
+
+ snprintf(default_buff, sizeof(default_buff), "Width: %E", self->cell_width);
+ gtk_label_set_text(self->x_label, default_buff);
+ snprintf(default_buff, sizeof(default_buff), "Height: %E", self->cell_height);
+ gtk_label_set_text(self->y_label, default_buff);
g_object_unref(builder);
}
@@ -155,9 +221,35 @@ void renderer_settings_dialog_set_settings(RendererSettingsDialog *dialog, struc
hide_tex_options(dialog);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->radio_cairo_svg), TRUE);
break;
-
-
}
}
+void renderer_settings_dialog_set_cell_width(RendererSettingsDialog *dialog, double width)
+{
+ if (!dialog)
+ return;
+
+ if (width == 0.0)
+ width = 1E-6;
+
+ if (width < 0.0)
+ width = -width;
+
+ dialog->cell_width = width;
+}
+
+void renderer_settings_dialog_set_cell_height(RendererSettingsDialog *dialog, double height)
+{
+ if (!dialog)
+ return;
+
+ if (height == 0.0)
+ height = 1E-6;
+
+ if (height < 0.0)
+ height = -height;
+
+ dialog->cell_height = height;
+}
+
/** @} */
diff --git a/widgets/conv-settings-dialog.h b/widgets/conv-settings-dialog.h
index 909ceaa..3680c04 100644
--- a/widgets/conv-settings-dialog.h
+++ b/widgets/conv-settings-dialog.h
@@ -75,6 +75,20 @@ void renderer_settings_dialog_set_settings(RendererSettingsDialog *dialog, struc
*/
void renderer_settings_dialog_get_settings(RendererSettingsDialog *dialog, struct render_settings *settings);
+/**
+ * @brief renderer_settings_dialog_set_cell_width Set width for rendered cell
+ * @param dialog
+ * @param width Width in meters
+ */
+void renderer_settings_dialog_set_cell_width(RendererSettingsDialog *dialog, double width);
+
+/**
+ * @brief renderer_settings_dialog_set_cell_height Set height for rendered cell
+ * @param dialog
+ * @param height Height in meters
+ */
+void renderer_settings_dialog_set_cell_height(RendererSettingsDialog *dialog, double height);
+
#endif /* __CONV_SETTINGS_DIALOG_H__ */
/** @} */