[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gEDA: gschem color select patch
Hi,
here's a small patch against gschem to have the color picker always show
either the color of the (first) selected object, or the edit_color if no
object is selected.
Also the color picker is now included in the "Edit Text..." menu.
Comments are very appreciated as this is my first hack in geda/gschem.
I intend to make the GUI usable more intuitivly, e.g. IMO "Add Text"
should be the same Window as "Edit Text", text should be rotateable 180
degrees (not only 90 and 270), attributes could also be accessible easier.
Usability discussions anyone?
matthias
diff -Nur geda-orig-cvs/devel/gschem/noweb/o_text.nw geda/devel/gschem/noweb/o_text.nw
--- geda-orig-cvs/devel/gschem/noweb/o_text.nw 2005-08-07 20:30:03.000000000 +0200
+++ geda/devel/gschem/noweb/o_text.nw 2005-08-07 20:57:26.000000000 +0200
@@ -761,6 +761,10 @@
object->text->size = text_size;
object->text->alignment = text_alignment;
+ /* probably the text object should be extended to carry a color */
+ /* and we should pass it here with a function parameter (?) */
+ object->saved_color = w_current->edit_color;
+
o_text_erase(w_current, object);
o_text_recreate(w_current, object);
o_text_draw(w_current, object);
diff -Nur geda-orig-cvs/devel/gschem/noweb/x_dialog.nw geda/devel/gschem/noweb/x_dialog.nw
--- geda-orig-cvs/devel/gschem/noweb/x_dialog.nw 2005-08-07 20:30:03.000000000 +0200
+++ geda/devel/gschem/noweb/x_dialog.nw 2005-08-08 21:08:08.000000000 +0200
@@ -768,6 +768,8 @@
return(menu);
}
+/* we reuse the color menu so we need to declare it */
+static GtkWidget *create_color_menu(TOPLEVEL * w_current, int * select_index);
@ %def create_menu_alignement
@@ -970,6 +972,19 @@
gtk_widget_grab_focus(w_current->teentry);
}
+ label = gtk_label_new(_("Edit Text Color"));
+ gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 0);
+ gtk_widget_show(label);
+
+ optionmenu = gtk_option_menu_new();
+ int select_index=0;
+
+ gtk_option_menu_set_menu(GTK_OPTION_MENU(optionmenu), create_color_menu(w_current, &select_index));
+ gtk_option_menu_set_history(GTK_OPTION_MENU(optionmenu), select_index);
+
+ gtk_box_pack_start(GTK_BOX(vbox), optionmenu, FALSE, TRUE, 5);
+ gtk_widget_show(optionmenu);
+
label = gtk_label_new (_("Edit Text Size"));
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 0);
gtk_widget_show (label);
@@ -3434,13 +3449,13 @@
@section Function @code{create_color_menu()}
-@defun create_color_menu w_current
+@defun create_color_menu w_current select_index
@end defun
<<x_dialog.c : create_color_menu()>>=
/* this is from gtktest.c */
static GtkWidget*
-create_color_menu (TOPLEVEL *w_current)
+create_color_menu (TOPLEVEL * w_current, int * select_index)
{
GtkWidget *menu;
GtkWidget *menuitem;
@@ -3450,22 +3465,35 @@
char *menu_string;
char *temp=NULL;
int found=0;
- int set_first=0;
menu = gtk_menu_new ();
group = NULL;
+ /* first lets see if we have a selected object, if so select its color */
+ int select_col = -1;
+ int item_index = 0;
+ SELECTION *s_current = NULL;
+ OBJECT *object = NULL;
+ /* skip over head */
+ s_current = w_current->page_current->selection2_head->next;
+
+ if (s_current != NULL) {
+
+ object = s_current->selected_object;
+ if (object == NULL) {
+ fprintf(stderr, "no object selected - WHEE!\n");
+ }else{
+ select_col = object->saved_color;
+ //fprintf(stderr, "setting object color %d\n", select_col);
+ }
+ }else /*fprintf(stderr, "no object selected\n")*/;
+
found = x_color_get_name(index, buf);
+ /* this looks weired, but besides TRUE(1) and FALSE(0) there's -1 */
while (found != FALSE) {
if (found == TRUE) {
- /* set the default to the first entry */
- if (!set_first) {
- global_window_current->edit_color = index;
- set_first = 1;
- }
-
temp = index2functionstring(index);
menu_string = g_strdup_printf("%d | %s | %s", index,
temp,
@@ -3490,7 +3518,22 @@
/* treated as one, it's then cast to an int in */
/* color_set. This should be ok as long as sizeof(void *) >= sizeof(int) */
- gtk_widget_show (menuitem);
+ if (select_col == -1){
+ /* set the default to the current color */
+ if (index == global_window_current->edit_color) {
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
+ //fprintf(stderr, "checking item %d\n", index);
+ *select_index = item_index;
+ }
+ }else{
+ if (index == select_col){
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
+ //fprintf(stderr, "checking selected item %d\n", index);
+ *select_index = item_index;
+ }
+ }
+ gtk_widget_show(menuitem);
+ item_index++;
}
index++;
@@ -3636,9 +3679,10 @@
#endif
optionmenu = gtk_option_menu_new ();
+ int select_index = 0;
gtk_option_menu_set_menu(GTK_OPTION_MENU(optionmenu),
- create_color_menu (w_current));
- gtk_option_menu_set_history(GTK_OPTION_MENU (optionmenu), 0);
+ create_color_menu (w_current, &select_index));
+ gtk_option_menu_set_history(GTK_OPTION_MENU (optionmenu), select_index);
gtk_box_pack_start(
GTK_BOX(vbox),
optionmenu, TRUE, TRUE, 0);