Commit a74d52fb authored by Michael Natterer's avatar Michael Natterer

Use the context almost everywhere.

parent 8208cb72
1999-10-26 Michael Natterer <mitch@gimp.org>
Put the active tool, brush, pattern and gradient to the context
and use contexts in most places which have references to one of
those. This is not _really_ a bugfix-only checkin but solves many
inconsistencies esp. with the "refresh" functionality and fixes
some SEGVs e.g. in the device status dialog.
The UI view should now always be in sync with the internal data
structures.
Introduced a hardcoded brush, pattern and gradient, so "no_data"
should actually work, too.
New Files:
* app/Makefile.am
* app/paletteP.h: used by palette_select.c
Removed Files:
* app/actionarea.[ch]: now done by gimpui.[ch].
Modified Files:
* gimprc.in: use brush and pattern name, not filename for the
default settings.
* app/gimpcontext.[ch]: connect to brush and brushlist signals to
keep the context up-to-date. Remember the name of the
active brush/pattern/gradient to find them again after a
refresh. Provide functions to refresh the pointers of all contexts
after refreshing or deleting brushes/patterns/gradients.
* app/context_manager.c: connect to the user context's
"tool_changed" signal to call the tools_select() function. Update
the colormap's fg/bg_pixel in "*_changed" callbacks, too.
* app/tools.c: tool switching is now triggered by the user context.
* app/app_procs.c: no need any more to call
get_active_brush/... because the brush/pattern/... init functions
refresh all contexts after loading the data. Slightly reordered the
brush/pattern... init/free calls due to the new context stuff.
* app/color_area.[ch]
* app/indicator_area.[ch]: removed all update functions and
connect to the user context instead.
* app/gimprc.c
* app/devices.[ch]: allocate a private context for each device and
removed the update function. Prepared for adding the BG color and
a gradient to the device status.
* app/gimpbrushgenerated.[ch]: new function
gimp_brush_generated_delete() to get rid of this in the brush
selection dialog.
* app/gimpbrushpipe.c
* app/gimpbrushlist.[ch]: removed the "select", "get_active" and
the brush select dialog functions, added a function to get the
hardcoded standard brush, namespace cleanups.
* app/brushes_cmds.c
* tools/pdbgen/pdb/brushes.pdb: use the brush of the current context.
* app/brush_select.[ch]
* app/brush_select_cmds.c
* tools/pdbgen/pdb/brush_select.pdb: allocate a context for brush
selections which are not the main one. Append the main dialog to
the list of dialogs. Factored out the preview redraw code to the
scrollbar update callback. Enabled editing, deleting and
refreshing brushes in all dialogs. Functions to freeze and thaw
all dialogs on refresh. All dialogs are now always up-to-date by
connecting to the brush list signals. Moved the create/free
functions of the main brush selection to this files.
* app/gradient.[ch]
* app/gradient_cmds.c
* tools/pdbgen/pdb/gradient.pdb: grad_get_color_at() now takes a
gradient as parameter instead of using the current gradient of the
gradient editor.
* app/gradient_header.h
* app/gradient_select.c
* app/gradient_select_cmds.c
* tools/pdbgen/pdb/gradient_select.pdb: updates like above.
(The gradient stuff should really be split up into separate
gradient, selection and editor files before 1.2)
* app/palette.[ch]
* app/palette_cmds.c
* app/palette_entries.h
* app/palette_select.[ch]
* tools/pdbgen/pdb/palette.pdb: removed all the get/set fg/bg
functions and the functions to update the import dialog. All
changes in all dialogs are now immediately propagated to all the
other dialogs on screen. Namespace cleanups. The active palette
will soon go to the context as well.
* app/pattern_select.[ch]
* app/pattern_select_cmds.c
* app/patterns.[ch]
* app/patterns_cmds.c
* tools/pdbgen/pdb/pattern_select.pdb
* tools/pdbgen/pdb/patterns.pdb: exactly the same changes as for
the brushlist and the brush selections (except the signal stuff).
* app/[all files needing a brush/pattern/gradient or switching the
active tool]: use context functions.
* app/convert.c: tweaked the ui to match the other dialogs.
* app/gimpui.c
* app/gimpui.h: new functions to create an action area without
creating a dialog.
* app/[all files using an info_dialog]: use the action_area
constructor from gimpui.[ch].
I also used some gimpui.c functions in various files which reduces
code duplication and removes some gtk 1.0 artefacts.
* app/[some files not related to the changes above]: While having
all the stuff in my emacs I removed dozens of useless includes and
did some indentation and cleanups (not changing any functionality).
Tue Oct 26 02:49:30 BST 1999 Nick Lamb <njl195@zepler.org>
* plug-ins/common/pix.c: Doesn't actually have ALPHA, so
......
......@@ -30,8 +30,6 @@ libgimpim_a_SOURCES = \
gimp_SOURCES = \
about_dialog.c \
about_dialog.h \
actionarea.c \
actionarea.h \
airbrush.c \
airbrush.h \
airbrush_blob.c \
......@@ -315,6 +313,7 @@ gimp_SOURCES = \
palette_cmds.c \
palette_select.c \
palette_select.h \
paletteP.h \
paint_core.c \
paint_core.h \
paint_funcs.c \
......
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 "config.h"
#include "actionarea.h"
#include "libgimp/gimpintl.h"
void
build_action_area (GtkDialog *dlg,
ActionAreaItem *actions,
gint num_actions,
gint default_action)
{
GtkWidget *button;
GList *children;
GtkWidget *hbbox;
gint i;
gtk_container_set_border_width (GTK_CONTAINER (dlg->action_area), 2);
gtk_box_set_homogeneous (GTK_BOX (dlg->action_area), FALSE);
children = gtk_container_children (GTK_CONTAINER (dlg->action_area));
if (children == NULL)
{
/* add a right packed hbbox */
hbbox = gtk_hbutton_box_new ();
gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbbox), 4);
gtk_box_pack_end (GTK_BOX (dlg->action_area), hbbox, FALSE, FALSE, 0);
gtk_widget_show (hbbox);
}
else
{
/* get the hbbox */
hbbox = (GtkWidget*) (g_list_first(children)->data);
}
for (i = 0; i < num_actions; i++)
{
button = gtk_button_new_with_label (gettext(actions[i].label));
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_box_pack_start (GTK_BOX (hbbox), button, FALSE, FALSE, 0);
if (actions[i].callback)
gtk_signal_connect (GTK_OBJECT (button), "clicked",
(GtkSignalFunc) actions[i].callback,
actions[i].user_data);
if (default_action == i)
gtk_widget_grab_default (button);
gtk_widget_show (button);
actions[i].widget = button;
}
}
......@@ -18,7 +18,7 @@
#include "appenv.h"
#include "about_dialog.h"
#include "app_procs.h"
#include "gimpbrushlist.h"
#include "brush_select.h"
#include "colormaps.h"
#include "colormap_dialog.i.h"
#include "color_area.h"
......@@ -48,7 +48,7 @@
#include "layer_select.h"
#include "module_db.h"
#include "palette.h"
#include "patterns.h"
#include "pattern_select.h"
#include "plug_in.h"
#include "resize.h"
#include "scale.h"
......@@ -1029,14 +1029,14 @@ void
tools_default_colors_cmd_callback (GtkWidget *widget,
gpointer client_data)
{
palette_set_default_colors ();
gimp_context_set_default_colors (gimp_context_get_user ());
}
void
tools_swap_colors_cmd_callback (GtkWidget *widget,
gpointer client_data)
{
palette_swap_colors ();
gimp_context_swap_colors (gimp_context_get_user ());
}
void
......@@ -1044,13 +1044,13 @@ tools_select_cmd_callback (GtkWidget *widget,
gpointer callback_data,
guint callback_action)
{
ToolType tool_type;
GDisplay * gdisp;
gdisp = gdisplay_active ();
/* Activate the appropriate widget.
* Implicitly calls tools_select()
*/
gtk_widget_activate (tool_info[callback_action].tool_widget);
tool_type = (ToolType) callback_action;
gimp_context_set_tool (gimp_context_get_user (), tool_type);
/* Paranoia */
active_tool->drawable = NULL;
......@@ -1085,21 +1085,21 @@ void
dialogs_brushes_cmd_callback (GtkWidget *widget,
gpointer client_data)
{
create_brush_dialog ();
brush_dialog_create ();
}
void
dialogs_patterns_cmd_callback (GtkWidget *widget,
gpointer client_data)
{
create_pattern_dialog ();
pattern_dialog_create ();
}
void
dialogs_palette_cmd_callback (GtkWidget *widget,
gpointer client_data)
{
palette_create ();
palette_dialog_create ();
}
void
......@@ -1129,16 +1129,16 @@ cmap_dlg_sel_cb (ColormapDialog *dlg,
c = &img->cmap[colormap_dialog_col_index(dlg) * 3];
if(active_color == FOREGROUND)
palette_set_foreground (c[0], c[1], c[2]);
gimp_context_set_foreground (gimp_context_get_user (), c[0], c[1], c[2]);
else if(active_color == BACKGROUND)
palette_set_background (c[0], c[1], c[2]);
gimp_context_set_background (gimp_context_get_user (), c[0], c[1], c[2]);
}
void
dialogs_indexed_palette_cmd_callback (GtkWidget *widget,
gpointer client_data)
{
static ColormapDialog * cmap_dlg;
static ColormapDialog *cmap_dlg;
if (!cmap_dlg)
{
......@@ -1160,14 +1160,14 @@ void
dialogs_input_devices_cmd_callback (GtkWidget *widget,
gpointer client_data)
{
create_input_dialog ();
input_dialog_create ();
}
void
dialogs_device_status_cmd_callback (GtkWidget *widget,
gpointer client_data)
{
create_device_status ();
device_status_create ();
}
void
......
......@@ -15,24 +15,23 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdlib.h>
#include "appenv.h"
#include "gimpbrushlist.h"
#include "gimpbrushpipe.h"
#include "gradient.h"
#include "airbrush.h"
#include "drawable.h"
#include "errors.h"
#include "gdisplay.h"
#include "gimpbrushpipe.h"
#include "gradient.h"
#include "gimage.h"
#include "gimpui.h"
#include "paint_funcs.h"
#include "paint_core.h"
#include "paint_options.h"
#include "palette.h"
#include "airbrush.h"
#include "selection.h"
#include "tool_options_ui.h"
#include "tools.h"
#include "gimage.h"
#include "libgimp/gimpintl.h"
......@@ -49,6 +48,7 @@
/* the airbrush structures */
typedef struct _AirbrushTimeout AirbrushTimeout;
struct _AirbrushTimeout
{
PaintCore *paint_core;
......@@ -56,16 +56,17 @@ struct _AirbrushTimeout
};
typedef struct _AirbrushOptions AirbrushOptions;
struct _AirbrushOptions
{
PaintOptions paint_options;
double rate;
double rate_d;
gdouble rate;
gdouble rate_d;
GtkObject *rate_w;
double pressure;
double pressure_d;
gdouble pressure;
gdouble pressure_d;
GtkObject *pressure_w;
};
......@@ -75,16 +76,17 @@ static AirbrushOptions *airbrush_options = NULL;
/* local variables */
static gint timer; /* timer for successive paint applications */
static int timer_state = OFF; /* state of airbrush tool */
static gint timer_state = OFF; /* state of airbrush tool */
static AirbrushTimeout airbrush_timeout;
static double non_gui_pressure;
static gdouble non_gui_pressure;
static gboolean non_gui_incremental;
/* forward function declarations */
static void airbrush_motion (PaintCore *, GimpDrawable *, PaintPressureOptions *,
double, PaintApplicationMode);
static gint airbrush_time_out (gpointer);
static void airbrush_motion (PaintCore *, GimpDrawable *,
PaintPressureOptions *,
gdouble, PaintApplicationMode);
static gint airbrush_time_out (gpointer);
/* functions */
......@@ -109,7 +111,6 @@ airbrush_options_new (void)
GtkWidget *vbox;
GtkWidget *table;
GtkWidget *label;
GtkWidget *scale;
/* the new airbrush tool options structure */
......@@ -129,40 +130,30 @@ airbrush_options_new (void)
gtk_table_set_row_spacings (GTK_TABLE (table), 1);
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
label = gtk_label_new (_("Rate:"));
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 1.0);
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (label);
options->rate_w =
gtk_adjustment_new (options->rate_d, 0.0, 150.0, 1.0, 1.0, 0.0);
scale = gtk_hscale_new (GTK_ADJUSTMENT (options->rate_w));
gtk_table_attach_defaults (GTK_TABLE (table), scale, 1, 2, 0, 1);
gtk_scale_set_value_pos (GTK_SCALE (scale), GTK_POS_TOP);
gtk_range_set_update_policy (GTK_RANGE (scale), GTK_UPDATE_DELAYED);
gtk_signal_connect (GTK_OBJECT (options->rate_w), "value_changed",
(GtkSignalFunc) tool_options_double_adjustment_update,
&options->rate);
gtk_widget_show (scale);
gimp_table_attach_aligned (GTK_TABLE (table), 0,
_("Rate:"), 1.0, 1.0,
scale, FALSE);
/* the pressure scale */
label = gtk_label_new (_("Pressure:"));
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 1.0);
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (label);
options->pressure_w =
gtk_adjustment_new (options->pressure_d, 0.0, 100.0, 1.0, 1.0, 0.0);
scale = gtk_hscale_new (GTK_ADJUSTMENT (options->pressure_w));
gtk_table_attach_defaults (GTK_TABLE (table), scale, 1, 2, 1, 2);
gtk_scale_set_value_pos (GTK_SCALE (scale), GTK_POS_TOP);
gtk_range_set_update_policy (GTK_RANGE (scale), GTK_UPDATE_DELAYED);
gtk_signal_connect (GTK_OBJECT (options->pressure_w), "value_changed",
(GtkSignalFunc) tool_options_double_adjustment_update,
&options->pressure);
gtk_widget_show (scale);
gimp_table_attach_aligned (GTK_TABLE (table), 1,
_("Pressure:"), 1.0, 1.0,
scale, FALSE);
gtk_widget_show (table);
......@@ -202,7 +193,7 @@ airbrush_paint_func (PaintCore *paint_core,
if (!drawable)
return NULL;
brush = get_active_brush ();
brush = gimp_context_get_brush (NULL);
switch (state)
{
case INIT_PAINT :
......@@ -320,7 +311,8 @@ airbrush_motion (PaintCore *paint_core,
{
gdouble r, g, b, a;
grad_get_color_at (paint_core->curpressure, &r, &g, &b, &a);
gradient_get_color_at (gimp_context_get_gradient (NULL),
paint_core->curpressure, &r, &g, &b, &a);
col[0] = r * 255.0;
col[1] = g * 255.0;
col[2] = b * 255.0;
......
......@@ -44,17 +44,18 @@
#include "appenv.h"
#include "app_procs.h"
#include "batch.h"
#include "gimpbrushlist.h"
#include "brush_select.h"
#include "color_transfer.h"
#include "curves.h"
#include "devices.h"
#include "gdisplay.h"
#include "gdisplay_color.h"
#include "gdisplay_ops.h"
#include "colormaps.h"
#include "context_manager.h"
#include "devices.h"
#include "errorconsole.h"
#include "fileops.h"
#include "gdisplay.h"
#include "gdisplay_color.h"
#include "gdisplay_ops.h"
#include "gimpbrushlist.h"
#include "gimprc.h"
#include "gimpparasite.h"
#include "gimpset.h"
......@@ -71,6 +72,7 @@
#include "menus.h"
#include "paint_funcs.h"
#include "palette.h"
#include "pattern_select.h"
#include "patterns.h"
#include "plug_in.h"
#include "module_db.h"
......@@ -486,6 +488,9 @@ app_init (void)
/* Create the context of all existing images */
image_context = gimp_set_new (GIMP_TYPE_IMAGE, TRUE);
/* Initialize the context system before loading any data */
context_manager_init ();
/* Initialize the procedural database
* We need to do this first because any of the init
* procedures might install or query it as needed.
......@@ -498,8 +503,8 @@ app_init (void)
RESET_BAR();
parse_buffers_init ();
parse_unitrc (); /* this needs to be done before gimprc loading */
parse_gimprc (); /* parse the local GIMP configuration file */
parse_unitrc (); /* this needs to be done before gimprc loading */
parse_gimprc (); /* parse the local GIMP configuration file */
if (always_restore_session)
restore_session = TRUE;
......@@ -529,21 +534,21 @@ app_init (void)
xcf_init (); /* initialize the xcf file format routines */
app_init_update_status (_("Looking for data files"), _("Parasites"), 0.00);
gimp_init_parasites (); /* initialize the global parasite table */
gimp_init_parasites (); /* initialize the global parasite table */
app_init_update_status (NULL, _("Brushes"), 0.20);
brushes_init (no_data); /* initialize the list of gimp brushes */
brushes_init (no_data); /* initialize the list of gimp brushes */
app_init_update_status (NULL, _("Patterns"), 0.40);
patterns_init (no_data); /* initialize the list of gimp patterns */
patterns_init (no_data); /* initialize the list of gimp patterns */
app_init_update_status (NULL, _("Palettes"), 0.60);
palettes_init (no_data); /* initialize the list of gimp palettes */
palettes_init (no_data); /* initialize the list of gimp palettes */
app_init_update_status (NULL, _("Gradients"), 0.80);
gradients_init (no_data); /* initialize the list of gimp gradients */
gradients_init (no_data); /* initialize the list of gimp gradients */
app_init_update_status (NULL, NULL, 1.00);
plug_in_init (); /* initialize the plug in structures */
module_db_init (); /* load any modules we need */
plug_in_init (); /* initialize the plug in structures */
module_db_init (); /* load any modules we need */
RESET_BAR();
file_ops_post_init (); /* post-initialize the file types */
file_ops_post_init (); /* post-initialize the file types */
/* Add the swap file */
if (swap_path == NULL)
......@@ -555,9 +560,6 @@ app_init (void)
tile_swap_add (path, NULL, NULL);
g_free (path);
/* Initialize the context system */
context_manager_init ();
destroy_initialization_status_window ();
/* Things to do only if there is an interface */
......@@ -597,14 +599,23 @@ app_init (void)
gximage_init ();
render_setup (transparency_type, transparency_size);
tools_options_dialog_new ();
tools_select (RECT_SELECT);
/* FIXME: This needs to go in preferences */
/* EEK: force signal emission */
if (gimp_context_get_tool (gimp_context_get_user ()) == RECT_SELECT)
{
gtk_signal_emit_by_name (GTK_OBJECT (gimp_context_get_user ()),
"tool_changed", RECT_SELECT);
}
else
{
gimp_context_set_tool (gimp_context_get_user (), RECT_SELECT);
}
/* FIXME: This needs to go in preferences */
message_handler = MESSAGE_BOX;
}
color_transfer_init ();
get_active_brush ();
get_active_pattern ();
paint_funcs_setup ();
/* register internal color selectors */
......@@ -612,9 +623,7 @@ app_init (void)
if (no_interface == FALSE)
{
devices_restore (); /* Must be done AFTER get_active_{brush|pattern}
* because these functions set the brush/pattern.
*/
devices_restore ();
session_restore ();
}
}
......@@ -645,18 +654,23 @@ app_exit_finish (void)
global_edit_free ();
named_buffers_free ();
swapping_free ();
context_manager_free ();
brush_select_dialog_free ();
brush_dialog_free ();
/* there may be dialogs still waiting for brush signals */
if (!no_interface)
brush_select_freeze_all ();
brushes_free ();
pattern_dialog_free ();
patterns_free ();
palette_dialog_free ();
palettes_free ();
gradients_free ();
grad_free_gradient_editor ();
gradients_free ();
context_manager_free ();
hue_saturation_free ();
curves_free ();
levels_free ();
pattern_select_dialog_free ();
palette_free ();
paint_funcs_free ();
plug_in_kill ();
procedural_db_free ();
......
......@@ -21,7 +21,6 @@
#include <string.h>
#include "appenv.h"
#include "actionarea.h"
#include "color_balance.h"
#include "color_transfer.h"
#include "drawable.h"
......@@ -276,7 +275,7 @@ color_balance_new_dialog ()
N_("Highlights")
};
ActionCallback appl_mode_callbacks[] =
GtkSignalFunc appl_mode_callbacks[] =
{
color_balance_shadows_callback,
color_balance_midtones_callback,
......
......@@ -20,7 +20,6 @@
#include <math.h>