From e406c332499f01a97379c163ce1326cfc13ee570 Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Sun, 22 Apr 2001 00:04:10 +0000 Subject: color custumozation added --- mixgtk/Makefile.am | 3 +- mixgtk/mixgtk.c | 5 +- mixgtk/mixgtk.glade | 384 ++++++++++++++++++++++++++++++++++++++++++++++- mixgtk/mixgtk_colorsel.c | 181 ++++++++++++++++++++++ mixgtk/mixgtk_colorsel.h | 40 +++++ mixgtk/mixgtk_mixal.c | 18 +-- mixgtk/mixgtk_mixal.h | 24 ++- mixgtk/mixgtk_widgets.c | 3 +- mixgtk/mixgtk_widgets.h | 3 +- 9 files changed, 641 insertions(+), 20 deletions(-) create mode 100644 mixgtk/mixgtk_colorsel.c create mode 100644 mixgtk/mixgtk_colorsel.h (limited to 'mixgtk') diff --git a/mixgtk/Makefile.am b/mixgtk/Makefile.am index a385647..adf036e 100644 --- a/mixgtk/Makefile.am +++ b/mixgtk/Makefile.am @@ -25,7 +25,8 @@ gmixvm_SOURCES = mixgtk.c mixgtk_gen_handlers.h mixgtk_gen_handlers.c \ mixgtk_device.h mixgtk_device.c \ mixgtk_mixvm.h mixgtk_mixvm.c \ mixgtk_mixal.h mixgtk_mixal.c \ - mixgtk_input.h mixgtk_input.c + mixgtk_input.h mixgtk_input.c \ + mixgtk_colorsel.h mixgtk_colorsel.c endif diff --git a/mixgtk/mixgtk.c b/mixgtk/mixgtk.c index 1bbc175..2e2b44c 100644 --- a/mixgtk/mixgtk.c +++ b/mixgtk/mixgtk.c @@ -1,7 +1,7 @@ /* -*-c-*- -------------- mixgtk.c : * Main function of the mix gtk front-end * ------------------------------------------------------------------ - * Last change: Time-stamp: "01/03/14 23:08:50 jose" + * Last change: Time-stamp: "2001-04-22 01:00:42 jao" * ------------------------------------------------------------------ * Copyright (C) 2001 Free Software Foundation, Inc. * @@ -30,6 +30,7 @@ #include "mixgtk_mixvm.h" #include "mixgtk_mixal.h" #include "mixgtk_input.h" +#include "mixgtk_colorsel.h" int main(int argc, char *argv[]) @@ -70,7 +71,7 @@ main(int argc, char *argv[]) return EXIT_FAILURE; } - if (!mixgtk_mixal_init (vm)) + if (!mixgtk_mixal_init (vm) || !mixgtk_colorsel_init ()) { g_error ("Unable to initialise application (mixal widgets)\n"); return EXIT_FAILURE; diff --git a/mixgtk/mixgtk.glade b/mixgtk/mixgtk.glade index ced029b..665c8ec 100644 --- a/mixgtk/mixgtk.glade +++ b/mixgtk/mixgtk.glade @@ -101,7 +101,7 @@ GtkMenuItem debug - + False @@ -162,6 +162,42 @@ + + GtkMenuItem + settings1 + + False + + + GtkMenu + settings1_menu + + + GtkMenuItem + colors + + activate + on_colors_activate + Wed, 11 Apr 2001 23:15:11 GMT + + + False + + + + GtkMenuItem + fonts1 + + activate + on_fonts1_activate + Wed, 11 Apr 2001 23:15:11 GMT + + + False + + + + GtkMenuItem help @@ -230,6 +266,11 @@ GtkNotebook main_notebook True + + switch_page + mixgtk_mixal_update + Sat, 21 Apr 2001 20:24:38 GMT + True True GTK_POS_TOP @@ -1700,4 +1741,345 @@ + + GtkDialog + color_dialog + 275 + 214 + False + + delete_event + gtk_widget_hide + Thu, 12 Apr 2001 21:05:54 GMT + + + destroy_event + gtk_widget_hide + Thu, 12 Apr 2001 21:06:09 GMT + + + destroy + gtk_widget_hide + Thu, 12 Apr 2001 21:06:23 GMT + + MIXAL colors + GTK_WINDOW_DIALOG + GTK_WIN_POS_NONE + True + False + False + False + + + GtkVBox + Dialog:vbox + dialog-vbox7 + False + 0 + + + GtkHBox + Dialog:action_area + dialog-action_area7 + 10 + True + 5 + + 0 + False + True + GTK_PACK_END + + + + GtkHButtonBox + hbuttonbox7 + GTK_BUTTONBOX_DEFAULT_STYLE + 30 + 85 + 27 + 7 + 0 + + 0 + True + True + + + + GtkButton + colors_ok + True + True + + clicked + on_colors_ok_clicked + Thu, 12 Apr 2001 21:05:07 GMT + + + GTK_RELIEF_NORMAL + + + + GtkButton + colors_apply + True + True + + clicked + on_colors_apply_clicked + Thu, 12 Apr 2001 21:04:56 GMT + + + GTK_RELIEF_NORMAL + + + + GtkButton + colors_cancel + True + True + + clicked + on_colors_cancel_clicked + Thu, 12 Apr 2001 21:04:45 GMT + + + GTK_RELIEF_NORMAL + + + + + + GtkFixed + fixed1 + + 0 + True + True + + + + GtkLabel + label230 + 184 + 32 + 78 + 16 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + + + GtkLabel + label226 + 0 + 8 + 143 + 16 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + + + GtkLabel + label227 + 0 + 56 + 79 + 16 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + + + GtkLabel + label229 + 88 + 32 + 78 + 16 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + + + GtkDrawingArea + clbg_area + 90 + 56 + 75 + 15 + + + + GtkDrawingArea + clfg_area + 184 + 56 + 75 + 15 + + + + GtkDrawingArea + bpfg_area + 184 + 94 + 75 + 15 + + + + GtkDrawingArea + plbg_area + 90 + 128 + 75 + 15 + + + + GtkLabel + label231 + 1 + 128 + 77 + 16 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + + + GtkDrawingArea + bpbg_area + 90 + 93 + 75 + 15 + + + + GtkDrawingArea + plfg_area + 184 + 128 + 75 + 15 + + + + GtkLabel + label228 + 0 + 94 + 76 + 16 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + + + + + + GtkColorSelectionDialog + colorsel_dialog + 10 + False + + delete_event + gtk_widget_hide + Sat, 21 Apr 2001 23:14:28 GMT + + + destroy_event + gtk_widget_hide + Sat, 21 Apr 2001 23:14:54 GMT + + + destroy + gtk_widget_hide + Sat, 21 Apr 2001 23:15:12 GMT + + Select Color + GTK_WINDOW_DIALOG + GTK_WIN_POS_NONE + True + False + True + False + GTK_UPDATE_CONTINUOUS + + + GtkButton + ColorSel:ok_button + ok_colorserdlg + True + True + + clicked + on_ok_colorseldlg_clicked + Sat, 21 Apr 2001 23:17:15 GMT + + + GTK_RELIEF_NORMAL + + + + GtkButton + ColorSel:cancel_button + cancel_colorseldlg + True + True + + clicked + on_cancel_colorseldlg_clicked + Sat, 21 Apr 2001 23:17:37 GMT + + + GTK_RELIEF_NORMAL + + + + GtkButton + ColorSel:help_button + help_button1 + True + True + + GTK_RELIEF_NORMAL + + + diff --git a/mixgtk/mixgtk_colorsel.c b/mixgtk/mixgtk_colorsel.c new file mode 100644 index 0000000..c1f5a3d --- /dev/null +++ b/mixgtk/mixgtk_colorsel.c @@ -0,0 +1,181 @@ +/* -*-c-*- -------------- mixgtk_colorsel.c : + * Implementation of the functions declared in mixgtk_colorsel.h + * ------------------------------------------------------------------ + * Last change: Time-stamp: "2001-04-22 01:54:20 jao" + * ------------------------------------------------------------------ + * Copyright (C) 2001 Free Software Foundation, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include +#include "mixgtk_widgets.h" +#include "mixgtk_mixal.h" +#include "mixgtk_colorsel.h" + +/* types of line colors */ +#define LNO_ 3 +/* colors per line */ +#define ZNO_ 2 + + +static GtkWidget *color_dialog_ = NULL; +static const char *anames_[LNO_][ZNO_] = { + {"bpbg_area", "bpfg_area"}, + {"clbg_area", "clfg_area"}, + {"plbg_area", "plfg_area"} +}; + +typedef struct +{ + GtkWidget *area; + gboolean changed; + GdkColor color; +} area_id_t; + +static area_id_t areas_[LNO_][ZNO_]; +static area_id_t *current_ = NULL; + +#define COLORSEL_DLG_NAME_ "colorsel_dialog" +static GtkWidget *colorseldlg_ = NULL; + + +static void +set_area_color_ (GtkWidget *area, const GdkColor *color) +{ + static GdkColor gdk_color; + + GdkColormap *colormap = gdk_window_get_colormap (area->window); + + g_assert (area); + g_assert (color); + + gdk_color.red = color->red; + gdk_color.green = color->green; + gdk_color.blue = color->blue; + gdk_color_alloc (colormap, &gdk_color); + gdk_window_set_background (area->window, &gdk_color); + gdk_window_clear (area->window); + gtk_widget_draw (area, FALSE); +} + + + +/* drawingarea event handler */ +static gint +area_event_(GtkWidget *widget, GdkEvent *event, gpointer areaid) +{ + gint handled = FALSE; + /* Check if we've received a button pressed event */ + if (event->type == GDK_BUTTON_PRESS) + { +/* handled = TRUE; */ + current_ = (area_id_t *)areaid; + /* Show the dialog */ + gtk_widget_show (colorseldlg_); + } + return handled; +} + +/* initialise the color selection dialog */ +gboolean +mixgtk_colorsel_init (void) +{ + int i, j; + color_dialog_ = mixgtk_widget_factory_get (MIXGTK_WIDGET_COLORSEL_DIALOG); + g_return_val_if_fail (color_dialog_ != NULL, FALSE); + colorseldlg_ = mixgtk_widget_factory_get_by_name (COLORSEL_DLG_NAME_); + g_return_val_if_fail (colorseldlg_ != NULL, FALSE); + for (i = 0; i < LNO_; ++i) + for (j = 0; j < ZNO_; ++j) + { + areas_[i][j].area = mixgtk_widget_factory_get_by_name (anames_[i][j]); + g_return_val_if_fail (areas_[i][j].area != NULL, FALSE); + areas_[i][j].changed = FALSE; + gtk_widget_set_events (areas_[i][j].area, GDK_BUTTON_PRESS_MASK); + gtk_signal_connect (GTK_OBJECT(areas_[i][j].area), "event", + (GtkSignalFunc)area_event_, (gpointer)&areas_[i][j]); + + } + return TRUE; +} + +/* gtk callbacks */ +void +on_colors_activate (GtkWidget *w, gpointer p) +{ + int i, j; + + /* must show widget before changing its colors */ + gtk_widget_show (color_dialog_); + + for (i = 0; i < LNO_; ++i) + for (j = 0; j < ZNO_; ++j) + { + areas_[i][j].changed = FALSE; + set_area_color_ (areas_[i][j].area, mixgtk_mixal_get_color (i, j)); + } + current_ = NULL; +} + +void +on_ok_colorseldlg_clicked (GtkWidget *widget, gpointer data) +{ + static gdouble color[3]; + GtkWidget *colorsel = GTK_COLOR_SELECTION_DIALOG (colorseldlg_)->colorsel; + gtk_widget_hide (colorseldlg_); + /* Get current color */ + gtk_color_selection_get_color (GTK_COLOR_SELECTION (colorsel), color); + /* Fit to a unsigned 16 bit integer (0..65535) and + * insert into the GdkColor structure */ + current_->color.red = (guint16)(color[0]*65535.0); + current_->color.green = (guint16)(color[1]*65535.0); + current_->color.blue = (guint16)(color[2]*65535.0); + set_area_color_ (current_->area, ¤t_->color); + current_->changed = TRUE; +} + +void +on_cancel_colorseldlg_clicked (GtkWidget *widget, gpointer data) +{ + gtk_widget_hide (colorseldlg_); +} + +void +on_colors_apply_clicked (GtkWidget *widget, gpointer data) +{ + int i, j; + for (i = 0; i < LNO_; ++i) + for (j = 0; j < ZNO_; ++j) + { + if (areas_[i][j].changed) + mixgtk_mixal_set_color (i, j, &areas_[i][j].color); + } +} + +void +on_colors_ok_clicked (GtkWidget *widget, gpointer data) +{ + on_colors_apply_clicked (widget, data); + gtk_widget_hide (color_dialog_); +} + +void +on_colors_cancel_clicked (GtkWidget *widget, gpointer data) +{ + gtk_widget_hide (color_dialog_); +} + diff --git a/mixgtk/mixgtk_colorsel.h b/mixgtk/mixgtk_colorsel.h new file mode 100644 index 0000000..aa50724 --- /dev/null +++ b/mixgtk/mixgtk_colorsel.h @@ -0,0 +1,40 @@ +/* -*-c-*- ---------------- mixgtk_colorsel.h : + * Functions to handle the color selection customization + * ------------------------------------------------------------------ + * Last change: Time-stamp: <2001-04-22 00:52:11 jao> + * ------------------------------------------------------------------ + * Copyright (C) 2001 Free Software Foundation, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + + +#ifndef MIXGTK_COLORSEL_H +#define MIXGTK_COLORSEL_H + +#include + +/* initialise the color selection dialog */ +extern gboolean +mixgtk_colorsel_init (void); + +/* gtk callbacks */ +extern void +on_colors_activate (GtkWidget *w, gpointer p); + + +#endif /* MIXGTK_COLORSEL_H */ + diff --git a/mixgtk/mixgtk_mixal.c b/mixgtk/mixgtk_mixal.c index 21c83e9..14afacc 100644 --- a/mixgtk/mixgtk_mixal.c +++ b/mixgtk/mixgtk_mixal.c @@ -1,7 +1,7 @@ /* -*-c-*- -------------- mixgtk_mixal.c : * Implementation of the functions declared in mixgtk_mixal.h * ------------------------------------------------------------------ - * Last change: Time-stamp: "2001-04-21 23:19:05 jao" + * Last change: Time-stamp: "2001-04-22 01:02:28 jao" * ------------------------------------------------------------------ * Copyright (C) 2001 Free Software Foundation, Inc. * @@ -72,14 +72,14 @@ mixgtk_mixal_init (mix_vm_t *vm) /* set the plain, location pointer and break colors */ void mixgtk_mixal_set_color (mixal_line_t line, mixal_line_zone_t zone, - guint16 color[3]) + const GdkColor *color) { g_return_if_fail (color != NULL); - g_return_if_fail (line > MIXAL_LINE_PLAIN); - g_return_if_fail (zone > MIXAL_LINE_FG); - colors_[line][zone].red = color[0]; - colors_[line][zone].green = color[1]; - colors_[line][zone].blue = color[2]; + g_return_if_fail (line <= MIXAL_LINE_PLAIN); + g_return_if_fail (zone <= MIXAL_LINE_FG); + colors_[line][zone].red = color->red; + colors_[line][zone].green = color->green; + colors_[line][zone].blue = color->blue; gdk_colormap_alloc_color (colormap_, &colors_[line][zone], FALSE, TRUE); mixgtk_mixal_update_bp_all (); } @@ -87,8 +87,8 @@ mixgtk_mixal_set_color (mixal_line_t line, mixal_line_zone_t zone, const GdkColor * mixgtk_mixal_get_color (mixal_line_t line, mixal_line_zone_t zone) { - g_return_val_if_fail (line > MIXAL_LINE_PLAIN, FALSE); - g_return_val_if_fail (zone > MIXAL_LINE_FG, FALSE); + g_return_val_if_fail (line <= MIXAL_LINE_PLAIN, FALSE); + g_return_val_if_fail (zone <= MIXAL_LINE_FG, FALSE); return &colors_[line][zone]; } diff --git a/mixgtk/mixgtk_mixal.h b/mixgtk/mixgtk_mixal.h index 89ef52a..eaf0e23 100644 --- a/mixgtk/mixgtk_mixal.h +++ b/mixgtk/mixgtk_mixal.h @@ -1,7 +1,7 @@ /* -*-c-*- ---------------- mixgtk_mixal.h : * Declarations for functions displaying the mixal source file * ------------------------------------------------------------------ - * Last change: Time-stamp: <01/03/31 01:02:31 jose> + * Last change: Time-stamp: <2001-04-21 23:54:18 jao> * ------------------------------------------------------------------ * Copyright (C) 2001 Free Software Foundation, Inc. * @@ -28,16 +28,30 @@ #include #include +/* the possible colorised elements */ +typedef enum { + MIXAL_LINE_BREAK, + MIXAL_LINE_LOC, + MIXAL_LINE_PLAIN +} mixal_line_t; + +typedef enum { + MIXAL_LINE_BG, + MIXAL_LINE_FG +} mixal_line_zone_t; + + /* initialise the mixal widget */ extern gboolean mixgtk_mixal_init (mix_vm_t *vm); -/* set the location pointer and break colors */ +/* set the plain, location pointer and break colors */ extern void -mixgtk_mixal_set_loc_color (GdkColor *bg, GdkColor *fg); +mixgtk_mixal_set_color (mixal_line_t line, mixal_line_zone_t zone, + const GdkColor *color); -extern void -mixgtk_mixal_set_break_color (GdkColor *bg, GdkColor *fg); +extern const GdkColor * +mixgtk_mixal_get_color (mixal_line_t line, mixal_line_zone_t zone); /* load the corresponding mixal file */ diff --git a/mixgtk/mixgtk_widgets.c b/mixgtk/mixgtk_widgets.c index 165da81..c27b707 100644 --- a/mixgtk/mixgtk_widgets.c +++ b/mixgtk/mixgtk_widgets.c @@ -1,7 +1,7 @@ /* -*-c-*- -------------- mixgtk_widgets.c : * Implementation of the functions declared in mixgtk_widgets.h * ------------------------------------------------------------------ - * Last change: Time-stamp: "01/03/15 14:42:37 jose" + * Last change: Time-stamp: "2001-04-22 00:01:30 jao" * ------------------------------------------------------------------ * Copyright (C) 2001 Free Software Foundation, Inc. * @@ -37,6 +37,7 @@ static const gchar *names_[] = { "word_dialog", "about_dialog", "goto_dialog", + "color_dialog", "command_prompt", "command_log", "mixal_clist", diff --git a/mixgtk/mixgtk_widgets.h b/mixgtk/mixgtk_widgets.h index f20ddc3..00147fc 100644 --- a/mixgtk/mixgtk_widgets.h +++ b/mixgtk/mixgtk_widgets.h @@ -1,7 +1,7 @@ /* -*-c-*- ---------------- mixgtk_widgets.h : * glade-based factory of mixvm widgets * ------------------------------------------------------------------ - * Last change: Time-stamp: <01/03/15 14:42:13 jose> + * Last change: Time-stamp: <2001-04-22 00:01:13 jao> * ------------------------------------------------------------------ * Copyright (C) 2001 Free Software Foundation, Inc. * @@ -35,6 +35,7 @@ typedef enum { MIXGTK_WIDGET_WORD_DIALOG, /* input dialog for a mix word */ MIXGTK_WIDGET_ABOUT_DIALOG, MIXGTK_WIDGET_GOTO_DIALOG, + MIXGTK_WIDGET_COLORSEL_DIALOG, /* color selection dialog */ MIXGTK_WIDGET_PROMPT, /* command prompt */ MIXGTK_WIDGET_LOG, /* command output */ MIXGTK_WIDGET_MIXAL, /* mixal source file */ -- cgit v1.2.3