Add cell size preview to dialog
This commit is contained in:
parent
4f9e5ca0b4
commit
b5087769ee
@ -4,7 +4,7 @@
|
|||||||
<requires lib="gtk+" version="3.20"/>
|
<requires lib="gtk+" version="3.20"/>
|
||||||
<object class="GtkAdjustment" id="adjustment1">
|
<object class="GtkAdjustment" id="adjustment1">
|
||||||
<property name="lower">1</property>
|
<property name="lower">1</property>
|
||||||
<property name="upper">3000</property>
|
<property name="upper">4000</property>
|
||||||
<property name="value">1000</property>
|
<property name="value">1000</property>
|
||||||
<property name="step_increment">10</property>
|
<property name="step_increment">10</property>
|
||||||
<property name="page_increment">1000</property>
|
<property name="page_increment">1000</property>
|
||||||
@ -69,6 +69,7 @@
|
|||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="adjustment">adjustment1</property>
|
<property name="adjustment">adjustment1</property>
|
||||||
|
<property name="fill_level">4000</property>
|
||||||
<property name="round_digits">0</property>
|
<property name="round_digits">0</property>
|
||||||
<property name="digits">0</property>
|
<property name="digits">0</property>
|
||||||
</object>
|
</object>
|
||||||
@ -108,7 +109,7 @@
|
|||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkDrawingArea" id="shape-drawer">
|
<object class="GtkDrawingArea" id="shape-drawer">
|
||||||
<property name="height_request">100</property>
|
<property name="height_request">200</property>
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
</object>
|
</object>
|
||||||
@ -118,5 +119,38 @@
|
|||||||
<property name="position">6</property>
|
<property name="position">6</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkBox">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel" id="x-label">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">True</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel" id="y-label">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">True</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">7</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</interface>
|
</interface>
|
||||||
|
@ -39,12 +39,16 @@ struct _RendererSettingsDialog {
|
|||||||
GtkWidget *scale;
|
GtkWidget *scale;
|
||||||
GtkWidget *layer_check;
|
GtkWidget *layer_check;
|
||||||
GtkWidget *standalone_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)
|
G_DEFINE_TYPE(RendererSettingsDialog, renderer_settings_dialog, GTK_TYPE_DIALOG)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void renderer_settings_dialog_class_init(RendererSettingsDialogClass *klass)
|
static void renderer_settings_dialog_class_init(RendererSettingsDialogClass *klass)
|
||||||
{
|
{
|
||||||
/* No special code needed. Child cells are destroyed automatically due to reference counter */
|
/* 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);
|
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)
|
static void renderer_settings_dialog_init(RendererSettingsDialog *self)
|
||||||
{
|
{
|
||||||
GtkBuilder *builder;
|
GtkBuilder *builder;
|
||||||
GtkWidget *box;
|
GtkWidget *box;
|
||||||
GtkDialog *dialog;
|
GtkDialog *dialog;
|
||||||
|
char default_buff[100];
|
||||||
|
|
||||||
|
|
||||||
dialog = &(self->parent);
|
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->scale = GTK_WIDGET(gtk_builder_get_object(builder, "dialog-scale"));
|
||||||
self->standalone_check = GTK_WIDGET(gtk_builder_get_object(builder, "standalone-check"));
|
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->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_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_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(dialog)), box);
|
||||||
gtk_window_set_title(GTK_WINDOW(self), "Renderer Settings");
|
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(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);
|
g_object_unref(builder);
|
||||||
}
|
}
|
||||||
@ -155,9 +221,35 @@ void renderer_settings_dialog_set_settings(RendererSettingsDialog *dialog, struc
|
|||||||
hide_tex_options(dialog);
|
hide_tex_options(dialog);
|
||||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->radio_cairo_svg), TRUE);
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->radio_cairo_svg), TRUE);
|
||||||
break;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
@ -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);
|
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__ */
|
#endif /* __CONV_SETTINGS_DIALOG_H__ */
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
Loading…
Reference in New Issue
Block a user