diff options
Diffstat (limited to 'tikzit/src/gtk/EdgeStyleEditor.m')
-rw-r--r-- | tikzit/src/gtk/EdgeStyleEditor.m | 199 |
1 files changed, 142 insertions, 57 deletions
diff --git a/tikzit/src/gtk/EdgeStyleEditor.m b/tikzit/src/gtk/EdgeStyleEditor.m index a0b3df2..477ce28 100644 --- a/tikzit/src/gtk/EdgeStyleEditor.m +++ b/tikzit/src/gtk/EdgeStyleEditor.m @@ -28,18 +28,44 @@ #pragma GCC diagnostic pop enum { - ED_NAME_COL = 0, - ED_ICON_COL, - ED_VALUE_COL, - ED_N_COLS + DEC_NAME_COL = 0, + DEC_PREVIEW_COL, + DEC_VALUE_COL, + DEC_N_COLS }; +struct dec_info { + const gchar *name; + const GdkPixdata *pixdata; + int value; +}; +static struct dec_info ed_entries[] = { + { "None", &ED_none_pixdata, ED_None }, + { "Arrow", &ED_arrow_pixdata, ED_Arrow }, + { "Tick", &ED_tick_pixdata, ED_Tick } +}; +static guint n_ed_entries = G_N_ELEMENTS (ed_entries); +static struct dec_info ah_head_entries[] = { + { "None", &AH_none_pixdata, AH_None }, + { "Plain", &AH_plain_head_pixdata, AH_Plain }, + { "Latex", &AH_latex_head_pixdata, AH_Latex } +}; +static guint n_ah_head_entries = G_N_ELEMENTS (ah_head_entries); +static struct dec_info ah_tail_entries[] = { + { "None", &AH_none_pixdata, AH_None }, + { "Plain", &AH_plain_tail_pixdata, AH_Plain }, + { "Latex", &AH_latex_tail_pixdata, AH_Latex } +}; +static guint n_ah_tail_entries = G_N_ELEMENTS (ah_tail_entries); + static const guint row_count = 5; // {{{ Internal interfaces // {{{ GTK+ Callbacks static void style_name_edit_changed_cb (GtkEditable *widget, EdgeStyleEditor *editor); static void decoration_combo_changed_cb (GtkComboBox *widget, EdgeStyleEditor *editor); +static void head_arrow_combo_changed_cb (GtkComboBox *widget, EdgeStyleEditor *editor); +static void tail_arrow_combo_changed_cb (GtkComboBox *widget, EdgeStyleEditor *editor); static void thickness_adjustment_changed_cb (GtkAdjustment *widget, EdgeStyleEditor *editor); // }}} // {{{ Notifications @@ -47,6 +73,8 @@ static void thickness_adjustment_changed_cb (GtkAdjustment *widget, EdgeStyleEdi @interface EdgeStyleEditor (Notifications) - (void) nameChangedTo:(NSString*)value; - (void) edgeDecorationChangedTo:(EdgeDectorationStyle)value; +- (void) headArrowChangedTo:(ArrowHeadStyle)value; +- (void) tailArrowChangedTo:(ArrowHeadStyle)value; - (void) thicknessChangedTo:(double)value; @end @@ -54,9 +82,9 @@ static void thickness_adjustment_changed_cb (GtkAdjustment *widget, EdgeStyleEdi // {{{ Private @interface EdgeStyleEditor (Private) -- (void) loadDecorationStylesInto:(GtkListStore*)list; -- (void) clearEdgeDecorationStyle; -- (void) setEdgeDecorationStyle:(EdgeDectorationStyle)value; +- (void) load:(guint)count decorationStylesFrom:(struct dec_info*)info into:(GtkListStore*)list; +- (void) clearDecCombo:(GtkComboBox*)combo; +- (void) setDecCombo:(GtkComboBox*)combo toValue:(int)value; @end // }}} @@ -88,6 +116,22 @@ static void thickness_adjustment_changed_cb (GtkAdjustment *widget, EdgeStyleEdi 0); // y padding } +- (GtkComboBox*) _createDecComboWithEntries:(struct dec_info*)entries count:(guint)n { + GtkListStore *store = gtk_list_store_new (DEC_N_COLS, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_INT); + [self load:n decorationStylesFrom:entries into:store]; + + GtkComboBox *combo = GTK_COMBO_BOX (gtk_combo_box_new_with_model (GTK_TREE_MODEL (store))); + g_object_unref (store); + GtkCellRenderer *cellRend = gtk_cell_renderer_pixbuf_new (); + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), + cellRend, + TRUE); + gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo), cellRend, "pixbuf", DEC_PREVIEW_COL); + g_object_ref_sink (combo); + + return combo; +} + - (id) init { self = [super init]; @@ -116,18 +160,7 @@ static void thickness_adjustment_changed_cb (GtkAdjustment *widget, EdgeStyleEdi /** * Edge decoration style */ - GtkListStore *store = gtk_list_store_new (ED_N_COLS, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_INT); - [self loadDecorationStylesInto:store]; - - decorationCombo = GTK_COMBO_BOX (gtk_combo_box_new_with_model (GTK_TREE_MODEL (store))); - g_object_unref (store); - GtkCellRenderer *cellRend = gtk_cell_renderer_pixbuf_new (); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (decorationCombo), - cellRend, - TRUE); - gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (decorationCombo), cellRend, "pixbuf", ED_ICON_COL); - g_object_ref_sink (decorationCombo); - + decorationCombo = [self _createDecComboWithEntries:ed_entries count:n_ed_entries]; [self _addWidget:GTK_WIDGET (decorationCombo) withLabel:"Decoration" atRow:1]; @@ -138,6 +171,32 @@ static void thickness_adjustment_changed_cb (GtkAdjustment *widget, EdgeStyleEdi /** + * Head arrow style + */ + headArrowCombo = [self _createDecComboWithEntries:ah_head_entries count:n_ah_head_entries]; + [self _addWidget:GTK_WIDGET (headArrowCombo) + withLabel:"Arrow head" + atRow:2]; + g_signal_connect (G_OBJECT (headArrowCombo), + "changed", + G_CALLBACK (head_arrow_combo_changed_cb), + self); + + + /** + * Tail arrow style + */ + tailArrowCombo = [self _createDecComboWithEntries:ah_tail_entries count:n_ah_tail_entries]; + [self _addWidget:GTK_WIDGET (tailArrowCombo) + withLabel:"Arrow tail" + atRow:3]; + g_signal_connect (G_OBJECT (tailArrowCombo), + "changed", + G_CALLBACK (tail_arrow_combo_changed_cb), + self); + + + /** * Thickness */ thicknessAdj = GTK_ADJUSTMENT (gtk_adjustment_new ( @@ -187,12 +246,16 @@ static void thickness_adjustment_changed_cb (GtkAdjustment *widget, EdgeStyleEdi gtk_entry_set_text(nameEdit, [[style name] UTF8String]); - [self setEdgeDecorationStyle:[style decorationStyle]]; + [self setDecCombo:decorationCombo toValue:[style decorationStyle]]; + [self setDecCombo:headArrowCombo toValue:[style headStyle]]; + [self setDecCombo:tailArrowCombo toValue:[style tailStyle]]; gtk_adjustment_set_value(thicknessAdj, [style thickness]); } else { gtk_entry_set_text(nameEdit, ""); - [self clearEdgeDecorationStyle]; + [self clearDecCombo:decorationCombo]; + [self clearDecCombo:headArrowCombo]; + [self clearDecCombo:tailArrowCombo]; gtk_adjustment_set_value(thicknessAdj, 1.0); gtk_widget_set_sensitive (GTK_WIDGET (table), FALSE); } @@ -219,6 +282,14 @@ static void thickness_adjustment_changed_cb (GtkAdjustment *widget, EdgeStyleEdi [style setDecorationStyle:value]; } +- (void) headArrowChangedTo:(ArrowHeadStyle)value { + [style setHeadStyle:value]; +} + +- (void) tailArrowChangedTo:(ArrowHeadStyle)value { + [style setTailStyle:value]; +} + - (void) thicknessChangedTo:(double)value { [style setThickness:(float)value]; } @@ -230,50 +301,34 @@ static void thickness_adjustment_changed_cb (GtkAdjustment *widget, EdgeStyleEdi @implementation EdgeStyleEditor (Private) - (BOOL) signalsBlocked { return blockSignals; } -- (void) loadDecorationStylesInto:(GtkListStore*)list { +- (void) load:(guint)count decorationStylesFrom:(struct dec_info*)info into:(GtkListStore*)list { GtkTreeIter iter; - GdkPixbuf *buf = gdk_pixbuf_from_pixdata (&ED_none_pixdata, FALSE, NULL); - gtk_list_store_append (list, &iter); - gtk_list_store_set (list, &iter, - ED_NAME_COL, "None", - ED_ICON_COL, buf, - ED_VALUE_COL, ED_None, - -1); - g_object_unref (buf); - - buf = gdk_pixbuf_from_pixdata (&ED_arrow_pixdata, FALSE, NULL); - gtk_list_store_append (list, &iter); - gtk_list_store_set (list, &iter, - ED_NAME_COL, "Arrow", - ED_ICON_COL, buf, - ED_VALUE_COL, ED_Arrow, - -1); - g_object_unref (buf); - - buf = gdk_pixbuf_from_pixdata (&ED_tick_pixdata, FALSE, NULL); - gtk_list_store_append (list, &iter); - gtk_list_store_set (list, &iter, - ED_NAME_COL, "Tick", - ED_ICON_COL, buf, - ED_VALUE_COL, ED_Tick, - -1); - g_object_unref (buf); + for (guint i = 0; i < count; ++i) { + GdkPixbuf *buf = gdk_pixbuf_from_pixdata (info[i].pixdata, FALSE, NULL); + gtk_list_store_append (list, &iter); + gtk_list_store_set (list, &iter, + DEC_NAME_COL, info[i].name, + DEC_PREVIEW_COL, buf, + DEC_VALUE_COL, info[i].value, + -1); + g_object_unref (buf); + } } -- (void) clearEdgeDecorationStyle { - gtk_combo_box_set_active (decorationCombo, -1); +- (void) clearDecCombo:(GtkComboBox*)combo { + gtk_combo_box_set_active (combo, -1); } -- (void) setEdgeDecorationStyle:(EdgeDectorationStyle)value { - GtkTreeModel *model = gtk_combo_box_get_model (decorationCombo); +- (void) setDecCombo:(GtkComboBox*)combo toValue:(int)value { + GtkTreeModel *model = gtk_combo_box_get_model (combo); GtkTreeIter iter; if (gtk_tree_model_get_iter_first (model, &iter)) { do { - EdgeDectorationStyle ed_style; - gtk_tree_model_get (model, &iter, ED_VALUE_COL, &ed_style, -1); - if (ed_style == value) { - gtk_combo_box_set_active_iter (decorationCombo, &iter); + int rowValue; + gtk_tree_model_get (model, &iter, DEC_VALUE_COL, &rowValue, -1); + if (rowValue == value) { + gtk_combo_box_set_active_iter (combo, &iter); return; } } while (gtk_tree_model_iter_next (model, &iter)); @@ -305,12 +360,42 @@ static void decoration_combo_changed_cb (GtkComboBox *widget, EdgeStyleEditor *e GtkTreeIter iter; gtk_combo_box_get_active_iter (widget, &iter); EdgeDectorationStyle dec = ED_None; - gtk_tree_model_get (gtk_combo_box_get_model (widget), &iter, ED_VALUE_COL, &dec, -1); + gtk_tree_model_get (gtk_combo_box_get_model (widget), &iter, DEC_VALUE_COL, &dec, -1); [editor edgeDecorationChangedTo:dec]; [pool drain]; } +static void head_arrow_combo_changed_cb (GtkComboBox *widget, EdgeStyleEditor *editor) { + if ([editor signalsBlocked]) + return; + + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + GtkTreeIter iter; + gtk_combo_box_get_active_iter (widget, &iter); + ArrowHeadStyle dec = AH_None; + gtk_tree_model_get (gtk_combo_box_get_model (widget), &iter, DEC_VALUE_COL, &dec, -1); + [editor headArrowChangedTo:dec]; + + [pool drain]; +} + +static void tail_arrow_combo_changed_cb (GtkComboBox *widget, EdgeStyleEditor *editor) { + if ([editor signalsBlocked]) + return; + + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + GtkTreeIter iter; + gtk_combo_box_get_active_iter (widget, &iter); + ArrowHeadStyle dec = AH_None; + gtk_tree_model_get (gtk_combo_box_get_model (widget), &iter, DEC_VALUE_COL, &dec, -1); + [editor tailArrowChangedTo:dec]; + + [pool drain]; +} + static void thickness_adjustment_changed_cb (GtkAdjustment *adj, EdgeStyleEditor *editor) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; [editor thicknessChangedTo:gtk_adjustment_get_value (adj)]; |