From 0231374c86f43eb9340965f9d714d772982f57f4 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Sun, 3 Apr 2005 15:48:03 +0000 Subject: [PATCH] added new signals "sample-point-added" and "sample-point-removed" and 2005-04-03 Michael Natterer * app/core/gimpimage.[ch]: added new signals "sample-point-added" and "sample-point-removed" and public functions to emit them. * app/core/gimpimage-sample-points.c (gimp_image_add_sample_point) (gimp_image_remove_sample_point): emit them accordingly. * app/core/gimpimage-undo-push.c (undo_pop_image_sample_point): ditto. (undo_pop_image_guide) (undo_pop_image_sample_point): added comments why we add/remove stuff manually instead of using the GimpImage APIs. * app/widgets/Makefile.am * app/widgets/widgets-types.h * app/widgets/gimpcursorview.[ch] * app/widgets/gimpsamplepointeditor.[ch]: new widgets. GimpCursorView is a replacement for the info window's "Cursor" page, GimpSamplePointEditor is a view on an image's sample points. The sample point editor does nothing yet except keeping a 2x2 grid of GimpColorFrames. Addresses bug #137776. * app/dialogs/dialogs.c * app/dialogs/dialogs-constructors.[ch]: register the new widgets as dockable dialogs. * app/actions/dialogs-actions.c (dialogs_dockable_actions) * menus/dialogs-menuitems.xml: added actions and menu items for the new dialogs. * app/display/gimpdisplayshell-cursor.c (gimp_display_shell_update_cursor) (gimp_display_shell_clear_cursor): update the new cursor view. * app/widgets/gimphelp-ids.h: help IDs for the new dialogs. * app/widgets/widgets-enums.[ch] (enum GimpColorFrameMode): changed description "Pixel values" to "Pixel" because the former was too long. --- ChangeLog | 42 +++ app/actions/dialogs-actions.c | 10 + app/core/gimpimage-sample-points.c | 3 + app/core/gimpimage-undo-push.c | 57 +-- app/core/gimpimage.c | 46 +++ app/core/gimpimage.h | 10 +- app/dialogs/dialogs-constructors.c | 24 +- app/dialogs/dialogs-constructors.h | 12 +- app/dialogs/dialogs.c | 14 +- app/display/gimpdisplayshell-cursor.c | 32 ++ app/widgets/Makefile.am | 4 + app/widgets/gimpcursorview.c | 497 ++++++++++++++++++++++++++ app/widgets/gimpcursorview.h | 69 ++++ app/widgets/gimphelp-ids.h | 2 + app/widgets/gimpsamplepointeditor.c | 269 ++++++++++++++ app/widgets/gimpsamplepointeditor.h | 58 +++ app/widgets/widgets-enums.c | 2 +- app/widgets/widgets-enums.h | 8 +- app/widgets/widgets-types.h | 2 + menus/dialogs-menuitems.xml | 2 + 20 files changed, 1127 insertions(+), 36 deletions(-) create mode 100644 app/widgets/gimpcursorview.c create mode 100644 app/widgets/gimpcursorview.h create mode 100644 app/widgets/gimpsamplepointeditor.c create mode 100644 app/widgets/gimpsamplepointeditor.h diff --git a/ChangeLog b/ChangeLog index cc19051ade..c0609ccba0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,45 @@ +2005-04-03 Michael Natterer + + * app/core/gimpimage.[ch]: added new signals "sample-point-added" + and "sample-point-removed" and public functions to emit them. + + * app/core/gimpimage-sample-points.c (gimp_image_add_sample_point) + (gimp_image_remove_sample_point): emit them accordingly. + + * app/core/gimpimage-undo-push.c (undo_pop_image_sample_point): + ditto. + + (undo_pop_image_guide) + (undo_pop_image_sample_point): added comments why we add/remove + stuff manually instead of using the GimpImage APIs. + + * app/widgets/Makefile.am + * app/widgets/widgets-types.h + * app/widgets/gimpcursorview.[ch] + * app/widgets/gimpsamplepointeditor.[ch]: new widgets. + GimpCursorView is a replacement for the info window's "Cursor" + page, GimpSamplePointEditor is a view on an image's sample points. + The sample point editor does nothing yet except keeping a 2x2 grid + of GimpColorFrames. Addresses bug #137776. + + * app/dialogs/dialogs.c + * app/dialogs/dialogs-constructors.[ch]: register the new widgets + as dockable dialogs. + + * app/actions/dialogs-actions.c (dialogs_dockable_actions) + * menus/dialogs-menuitems.xml: added actions and menu items for + the new dialogs. + + * app/display/gimpdisplayshell-cursor.c + (gimp_display_shell_update_cursor) + (gimp_display_shell_clear_cursor): update the new cursor view. + + * app/widgets/gimphelp-ids.h: help IDs for the new dialogs. + + * app/widgets/widgets-enums.[ch] (enum GimpColorFrameMode): + changed description "Pixel values" to "Pixel" because the former + was too long. + 2005-04-02 Michael Natterer * themes/Default/images/Makefile.am diff --git a/app/actions/dialogs-actions.c b/app/actions/dialogs-actions.c index 459f24d776..64c9a9d109 100644 --- a/app/actions/dialogs-actions.c +++ b/app/actions/dialogs-actions.c @@ -111,6 +111,16 @@ GimpStringActionEntry dialogs_dockable_actions[] = "gimp-undo-history", GIMP_HELP_UNDO_DIALOG }, + { "dialogs-cursor", GIMP_STOCK_CURSOR, + N_("_Cursor"), NULL, NULL, + "gimp-cursor-view", + GIMP_HELP_CURSOR_DIALOG }, + + { "dialogs-sample-points", GIMP_STOCK_SAMPLE_POINT, + N_("_Sample Points"), NULL, NULL, + "gimp-sample-point-editor", + GIMP_HELP_SAMPLE_POINT_DIALOG }, + { "dialogs-colors", GIMP_STOCK_DEFAULT_COLORS, N_("Colo_rs"), NULL, NULL, "gimp-color-editor", diff --git a/app/core/gimpimage-sample-points.c b/app/core/gimpimage-sample-points.c index 6d011ef951..00b5d2aea4 100644 --- a/app/core/gimpimage-sample-points.c +++ b/app/core/gimpimage-sample-points.c @@ -101,6 +101,7 @@ gimp_image_add_sample_point (GimpImage *gimage, sample_point->y = y; gimp_image_sample_point_ref (sample_point); + gimp_image_sample_point_added (gimage, sample_point); gimp_image_update_sample_point (gimage, sample_point); } @@ -126,6 +127,8 @@ gimp_image_remove_sample_point (GimpImage *gimage, gimage->sample_points = g_list_remove (gimage->sample_points, sample_point); + gimp_image_sample_point_removed (gimage, sample_point); + sample_point->x = -1; sample_point->y = -1; gimp_image_sample_point_unref (sample_point); diff --git a/app/core/gimpimage-undo-push.c b/app/core/gimpimage-undo-push.c index 9f3ff9bd44..c73fb096d5 100644 --- a/app/core/gimpimage-undo-push.c +++ b/app/core/gimpimage-undo-push.c @@ -369,6 +369,12 @@ undo_pop_image_guide (GimpUndo *undo, old_position = gu->guide->position; old_orientation = gu->guide->orientation; + /* add and move guides manually (nor using the gimp_image_guide + * API), because we might be in the middle of an image resizing + * undo group and the guide's position might be temporarily out of + * image. + */ + if (gu->guide->position == -1) { undo->gimage->guides = g_list_prepend (undo->gimage->guides, gu->guide); @@ -521,11 +527,11 @@ gimp_image_undo_push_image_sample_point (GimpImage *gimage, undo_free_image_sample_point, NULL))) { - SamplePointUndo *gu = new->data; + SamplePointUndo *spu = new->data; - gu->sample_point = gimp_image_sample_point_ref (sample_point); - gu->x = sample_point->x; - gu->y = sample_point->y; + spu->sample_point = gimp_image_sample_point_ref (sample_point); + spu->x = sample_point->x; + spu->y = sample_point->y; return TRUE; } @@ -538,36 +544,45 @@ undo_pop_image_sample_point (GimpUndo *undo, GimpUndoMode undo_mode, GimpUndoAccumulator *accum) { - SamplePointUndo *gu = undo->data; + SamplePointUndo *spu = undo->data; gint old_x; gint old_y; - old_x = gu->sample_point->x; - old_y = gu->sample_point->y; + old_x = spu->sample_point->x; + old_y = spu->sample_point->y; - if (gu->sample_point->x == -1) + /* add and move sample points manually (nor using the + * gimp_image_sample_point API), because we might be in the middle + * of an image resizing undo group and the sample point's position + * might be temporarily out of image. + */ + + if (spu->sample_point->x == -1) { undo->gimage->sample_points = g_list_append (undo->gimage->sample_points, - gu->sample_point); - gu->sample_point->x = gu->x; - gu->sample_point->y = gu->y; - gimp_image_sample_point_ref (gu->sample_point); - gimp_image_update_sample_point (undo->gimage, gu->sample_point); + spu->sample_point); + + spu->sample_point->x = spu->x; + spu->sample_point->y = spu->y; + gimp_image_sample_point_ref (spu->sample_point); + + gimp_image_sample_point_added (undo->gimage, spu->sample_point); + gimp_image_update_sample_point (undo->gimage, spu->sample_point); } - else if (gu->x == -1) + else if (spu->x == -1) { - gimp_image_remove_sample_point (undo->gimage, gu->sample_point, FALSE); + gimp_image_remove_sample_point (undo->gimage, spu->sample_point, FALSE); } else { - gimp_image_update_sample_point (undo->gimage, gu->sample_point); - gu->sample_point->x = gu->x; - gu->sample_point->y = gu->y; - gimp_image_update_sample_point (undo->gimage, gu->sample_point); + gimp_image_update_sample_point (undo->gimage, spu->sample_point); + spu->sample_point->x = spu->x; + spu->sample_point->y = spu->y; + gimp_image_update_sample_point (undo->gimage, spu->sample_point); } - gu->x = old_x; - gu->y = old_y; + spu->x = old_x; + spu->y = old_y; return TRUE; } diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c index ed152078c9..f3ec530379 100644 --- a/app/core/gimpimage.c +++ b/app/core/gimpimage.c @@ -94,6 +94,8 @@ enum UPDATE, UPDATE_GUIDE, UPDATE_SAMPLE_POINT, + SAMPLE_POINT_ADDED, + SAMPLE_POINT_REMOVED, COLORMAP_CHANGED, UNDO_EVENT, FLUSH, @@ -410,6 +412,26 @@ gimp_image_class_init (GimpImageClass *klass) G_TYPE_NONE, 1, G_TYPE_POINTER); + gimp_image_signals[SAMPLE_POINT_ADDED] = + g_signal_new ("sample_point_added", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (GimpImageClass, sample_point_added), + NULL, NULL, + gimp_marshal_VOID__POINTER, + G_TYPE_NONE, 1, + G_TYPE_POINTER); + + gimp_image_signals[SAMPLE_POINT_REMOVED] = + g_signal_new ("sample_point_removed", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (GimpImageClass, sample_point_removed), + NULL, NULL, + gimp_marshal_VOID__POINTER, + G_TYPE_NONE, 1, + G_TYPE_POINTER); + gimp_image_signals[COLORMAP_CHANGED] = g_signal_new ("colormap_changed", G_TYPE_FROM_CLASS (klass), @@ -473,6 +495,8 @@ gimp_image_class_init (GimpImageClass *klass) klass->update = NULL; klass->update_guide = NULL; klass->update_sample_point = NULL; + klass->sample_point_added = NULL; + klass->sample_point_removed = NULL; klass->colormap_changed = gimp_image_real_colormap_changed; klass->undo_event = NULL; klass->flush = gimp_image_real_flush; @@ -1665,6 +1689,28 @@ gimp_image_update_sample_point (GimpImage *gimage, sample_point); } +void +gimp_image_sample_point_added (GimpImage *gimage, + GimpSamplePoint *sample_point) +{ + g_return_if_fail (GIMP_IS_IMAGE (gimage)); + g_return_if_fail (sample_point != NULL); + + g_signal_emit (gimage, gimp_image_signals[SAMPLE_POINT_ADDED], 0, + sample_point); +} + +void +gimp_image_sample_point_removed (GimpImage *gimage, + GimpSamplePoint *sample_point) +{ + g_return_if_fail (GIMP_IS_IMAGE (gimage)); + g_return_if_fail (sample_point != NULL); + + g_signal_emit (gimage, gimp_image_signals[SAMPLE_POINT_REMOVED], 0, + sample_point); +} + void gimp_image_colormap_changed (GimpImage *gimage, gint color_index) diff --git a/app/core/gimpimage.h b/app/core/gimpimage.h index ae8985bad8..424d7bd62c 100644 --- a/app/core/gimpimage.h +++ b/app/core/gimpimage.h @@ -210,6 +210,10 @@ struct _GimpImageClass GimpGuide *guide); void (* update_sample_point) (GimpImage *gimage, GimpSamplePoint *sample_point); + void (* sample_point_added) (GimpImage *gimage, + GimpSamplePoint *sample_point); + void (* sample_point_removed) (GimpImage *gimage, + GimpSamplePoint *sample_point); void (* colormap_changed) (GimpImage *gimage, gint color_index); void (* undo_event) (GimpImage *gimage, @@ -299,6 +303,10 @@ void gimp_image_update_guide (GimpImage *gimage, GimpGuide *guide); void gimp_image_update_sample_point (GimpImage *gimage, GimpSamplePoint *sample_point); +void gimp_image_sample_point_added (GimpImage *gimage, + GimpSamplePoint *sample_point); +void gimp_image_sample_point_removed (GimpImage *gimage, + GimpSamplePoint *sample_point); void gimp_image_colormap_changed (GimpImage *gimage, gint col); void gimp_image_selection_control (GimpImage *gimage, @@ -386,7 +394,7 @@ gboolean gimp_image_set_tattoo_state (GimpImage *gimage, GimpTattoo gimp_image_get_tattoo_state (GimpImage *gimage); -/* layers / channels / vectors / old paths */ +/* layers / channels / vectors */ GimpContainer * gimp_image_get_layers (const GimpImage *gimage); GimpContainer * gimp_image_get_channels (const GimpImage *gimage); diff --git a/app/dialogs/dialogs-constructors.c b/app/dialogs/dialogs-constructors.c index 1e52cda827..488bba98fe 100644 --- a/app/dialogs/dialogs-constructors.c +++ b/app/dialogs/dialogs-constructors.c @@ -40,6 +40,7 @@ #include "widgets/gimpcontainergridview.h" #include "widgets/gimpcontainertreeview.h" #include "widgets/gimpcontainerview-utils.h" +#include "widgets/gimpcursorview.h" #include "widgets/gimpdataeditor.h" #include "widgets/gimpdevicestatus.h" #include "widgets/gimpdialogfactory.h" @@ -56,6 +57,7 @@ #include "widgets/gimplayertreeview.h" #include "widgets/gimppaletteeditor.h" #include "widgets/gimppatternfactoryview.h" +#include "widgets/gimpsamplepointeditor.h" #include "widgets/gimpselectioneditor.h" #include "widgets/gimptemplateview.h" #include "widgets/gimptoolbox.h" @@ -232,7 +234,7 @@ dialogs_dockable_constructor (GimpDialogFactory *factory, /***** singleton dialogs *****/ GtkWidget * -dialogs_tool_options_get (GimpDialogFactory *factory, +dialogs_tool_options_new (GimpDialogFactory *factory, GimpContext *context, gint preview_size) { @@ -241,7 +243,7 @@ dialogs_tool_options_get (GimpDialogFactory *factory, } GtkWidget * -dialogs_device_status_get (GimpDialogFactory *factory, +dialogs_device_status_new (GimpDialogFactory *factory, GimpContext *context, gint preview_size) { @@ -249,7 +251,7 @@ dialogs_device_status_get (GimpDialogFactory *factory, } GtkWidget * -dialogs_error_console_get (GimpDialogFactory *factory, +dialogs_error_console_new (GimpDialogFactory *factory, GimpContext *context, gint preview_size) { @@ -257,6 +259,14 @@ dialogs_error_console_get (GimpDialogFactory *factory, factory->menu_factory); } +GtkWidget * +dialogs_cursor_view_new (GimpDialogFactory *factory, + GimpContext *context, + gint preview_size) +{ + return gimp_cursor_view_new (context); +} + /***** list views *****/ @@ -602,6 +612,14 @@ dialogs_undo_editor_new (GimpDialogFactory *factory, factory->menu_factory); } +GtkWidget * +dialogs_sample_point_editor_new (GimpDialogFactory *factory, + GimpContext *context, + gint preview_size) +{ + return gimp_sample_point_editor_new (factory->menu_factory); +} + /***** display related dialogs *****/ diff --git a/app/dialogs/dialogs-constructors.h b/app/dialogs/dialogs-constructors.h index 11c0dcd5e5..6fe358d968 100644 --- a/app/dialogs/dialogs-constructors.h +++ b/app/dialogs/dialogs-constructors.h @@ -71,13 +71,16 @@ GtkWidget * dialogs_dockable_constructor (GimpDialogFactory *factory, GimpContext *context, gint preview_size); -GtkWidget * dialogs_tool_options_get (GimpDialogFactory *factory, +GtkWidget * dialogs_tool_options_new (GimpDialogFactory *factory, GimpContext *context, gint preview_size); -GtkWidget * dialogs_device_status_get (GimpDialogFactory *factory, +GtkWidget * dialogs_device_status_new (GimpDialogFactory *factory, GimpContext *context, gint preview_size); -GtkWidget * dialogs_error_console_get (GimpDialogFactory *factory, +GtkWidget * dialogs_error_console_new (GimpDialogFactory *factory, + GimpContext *context, + gint preview_size); +GtkWidget * dialogs_cursor_view_new (GimpDialogFactory *factory, GimpContext *context, gint preview_size); @@ -167,6 +170,9 @@ GtkWidget * dialogs_selection_editor_new (GimpDialogFactory *factory, GtkWidget * dialogs_undo_editor_new (GimpDialogFactory *factory, GimpContext *context, gint preview_size); +GtkWidget * dialogs_sample_point_editor_new(GimpDialogFactory *factory, + GimpContext *context, + gint preview_size); GtkWidget * dialogs_navigation_editor_new (GimpDialogFactory *factory, GimpContext *context, diff --git a/app/dialogs/dialogs.c b/app/dialogs/dialogs.c index f7185736a4..e2736af02f 100644 --- a/app/dialogs/dialogs.c +++ b/app/dialogs/dialogs.c @@ -122,15 +122,19 @@ static const GimpDialogFactoryEntry dock_entries[] = DOCKABLE ("gimp-tool-options", N_("Tool Options"), NULL, GIMP_STOCK_TOOL_OPTIONS, GIMP_HELP_TOOL_OPTIONS_DIALOG, - dialogs_tool_options_get, 0, TRUE), + dialogs_tool_options_new, 0, TRUE), DOCKABLE ("gimp-device-status", N_("Devices"), N_("Device Status"), GIMP_STOCK_DEVICE_STATUS, GIMP_HELP_DEVICE_STATUS_DIALOG, - dialogs_device_status_get, 0, TRUE), + dialogs_device_status_new, 0, TRUE), DOCKABLE ("gimp-error-console", N_("Errors"), N_("Error Console"), GIMP_STOCK_WARNING, GIMP_HELP_ERRORS_DIALOG, - dialogs_error_console_get, 0, TRUE), + dialogs_error_console_new, 0, TRUE), + DOCKABLE ("gimp-cursor-view", + N_("Cursor"), N_("Cursor Info"), GIMP_STOCK_CURSOR, + GIMP_HELP_CURSOR_DIALOG, + dialogs_cursor_view_new, 0, TRUE), /* list & grid views */ LISTGRID (image, N_("Images"), NULL, GIMP_STOCK_IMAGES, @@ -183,6 +187,10 @@ static const GimpDialogFactoryEntry dock_entries[] = N_("Undo"), N_("Undo History"), GIMP_STOCK_UNDO_HISTORY, GIMP_HELP_UNDO_DIALOG, dialogs_undo_editor_new, 0, FALSE), + DOCKABLE ("gimp-sample-point-editor", + N_("Sample Points"), N_("Sample Points"), GIMP_STOCK_SAMPLE_POINT, + GIMP_HELP_SAMPLE_POINT_DIALOG, + dialogs_sample_point_editor_new, 0, FALSE), /* display related */ DOCKABLE ("gimp-navigation-view", diff --git a/app/display/gimpdisplayshell-cursor.c b/app/display/gimpdisplayshell-cursor.c index 8b7be25220..b7f7e35844 100644 --- a/app/display/gimpdisplayshell-cursor.c +++ b/app/display/gimpdisplayshell-cursor.c @@ -34,6 +34,9 @@ #include "dialogs/info-window.h" #include "widgets/gimpcursor.h" +#include "widgets/gimpcursorview.h" +#include "widgets/gimpdialogfactory.h" +#include "widgets/gimpsessioninfo.h" #include "gimpdisplay.h" #include "gimpdisplayshell.h" @@ -117,6 +120,10 @@ gimp_display_shell_update_cursor (GimpDisplayShell *shell, gint t_x = -1; gint t_y = -1; + GimpDialogFactory *factory; + GimpSessionInfo *session_info; + GtkWidget *cursor_view = NULL; + g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); gimage = shell->gdisp->gimage; @@ -155,6 +162,12 @@ gimp_display_shell_update_cursor (GimpDisplayShell *shell, gimp_display_shell_untransform_xy (shell, display_x, display_y, &t_x, &t_y, FALSE, FALSE); + factory = gimp_dialog_factory_from_name ("dock"); + session_info = gimp_dialog_factory_find_session_info (factory, + "gimp-cursor-view"); + if (session_info && session_info->widget) + cursor_view = gtk_bin_get_child (GTK_BIN (session_info->widget)); + if (t_x < 0 || t_y < 0 || t_x >= gimage->width || @@ -166,16 +179,35 @@ gimp_display_shell_update_cursor (GimpDisplayShell *shell, { info_window_update_cursor (shell->gdisp, t_x, t_y); } + + if (cursor_view) + gimp_cursor_view_update_cursor (GIMP_CURSOR_VIEW (cursor_view), + shell->gdisp->gimage, shell->unit, + t_x, t_y); } void gimp_display_shell_clear_cursor (GimpDisplayShell *shell) { + GimpDialogFactory *factory; + GimpSessionInfo *session_info; + GtkWidget *cursor_view = NULL; + g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); gimp_statusbar_clear_cursor (GIMP_STATUSBAR (shell->statusbar)); info_window_update_cursor (shell->gdisp, -1, -1); + + factory = gimp_dialog_factory_from_name ("dock"); + session_info = gimp_dialog_factory_find_session_info (factory, + "gimp-cursor-view"); + if (session_info && session_info->widget) + cursor_view = gtk_bin_get_child (GTK_BIN (session_info->widget)); + + if (cursor_view) + gimp_cursor_view_update_cursor (GIMP_CURSOR_VIEW (cursor_view), + NULL, GIMP_UNIT_PIXEL, 0, 0); } static void diff --git a/app/widgets/Makefile.am b/app/widgets/Makefile.am index 2f15ed954e..aa5d5a1f82 100644 --- a/app/widgets/Makefile.am +++ b/app/widgets/Makefile.am @@ -92,6 +92,8 @@ libappwidgets_a_sources = \ gimpcontrollerwheel.h \ gimpcursor.c \ gimpcursor.h \ + gimpcursorview.c \ + gimpcursorview.h \ gimpdasheditor.c \ gimpdasheditor.h \ gimpdataeditor.c \ @@ -193,6 +195,8 @@ libappwidgets_a_sources = \ gimpprogressdialog.h \ gimppropwidgets.c \ gimppropwidgets.h \ + gimpsamplepointeditor.c \ + gimpsamplepointeditor.h \ gimpselectiondata.c \ gimpselectiondata.h \ gimpselectioneditor.c \ diff --git a/app/widgets/gimpcursorview.c b/app/widgets/gimpcursorview.c new file mode 100644 index 0000000000..7df5bff7a5 --- /dev/null +++ b/app/widgets/gimpcursorview.c @@ -0,0 +1,497 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * gimpcursorview.c + * Copyright (C) 2005 Michael Natterer + * + * 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 + +#include + +#include "libgimpcolor/gimpcolor.h" +#include "libgimpwidgets/gimpwidgets.h" + +#include "widgets-types.h" + +#include "core/gimpcontext.h" +#include "core/gimpimage.h" +#include "core/gimppickable.h" +#include "core/gimpunit.h" + +#include "gimpcolorframe.h" +#include "gimpcursorview.h" +#include "gimpdocked.h" +#include "gimpsessioninfo.h" + +#include "gimp-intl.h" + + +static void gimp_cursor_view_class_init (GimpCursorViewClass *klass); +static void gimp_cursor_view_init (GimpCursorView *view); +static void gimp_cursor_view_docked_iface_init (GimpDockedInterface *docked_iface); + +static void gimp_cursor_view_destroy (GtkObject *object); +static void gimp_cursor_view_style_set (GtkWidget *widget, + GtkStyle *prev_style); + +static void gimp_cursor_view_set_aux_info (GimpDocked *docked, + GList *aux_info); +static GList *gimp_cursor_view_get_aux_info (GimpDocked *docked); +static void gimp_cursor_view_set_context (GimpDocked *docked, + GimpContext *context); + +static void gimp_cursor_view_destroy (GtkObject *object); + +#if 0 +static void gimp_cursor_view_fg_changed (GimpContext *context, + const GimpRGB *rgb, + GimpCursorView *view); +static void gimp_cursor_view_bg_changed (GimpContext *context, + const GimpRGB *rgb, + GimpCursorView *view); +#endif + + +static GimpEditorClass *parent_class = NULL; + + +GType +gimp_cursor_view_get_type (void) +{ + static GType type = 0; + + if (! type) + { + static const GTypeInfo view_info = + { + sizeof (GimpCursorViewClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) gimp_cursor_view_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (GimpCursorView), + 0, /* n_preallocs */ + (GInstanceInitFunc) gimp_cursor_view_init, + }; + static const GInterfaceInfo docked_iface_info = + { + (GInterfaceInitFunc) gimp_cursor_view_docked_iface_init, + NULL, /* iface_finalize */ + NULL /* iface_data */ + }; + + type = g_type_register_static (GIMP_TYPE_EDITOR, + "GimpCursorView", + &view_info, 0); + + g_type_add_interface_static (type, GIMP_TYPE_DOCKED, + &docked_iface_info); + } + + return type; +} + +static void +gimp_cursor_view_class_init (GimpCursorViewClass* klass) +{ + GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + parent_class = g_type_class_peek_parent (klass); + + object_class->destroy = gimp_cursor_view_destroy; + + widget_class->style_set = gimp_cursor_view_style_set; +} + +static void +gimp_cursor_view_init (GimpCursorView *view) +{ + GtkWidget *hbox; + GtkWidget *frame; + GtkWidget *table; + gint content_spacing; + gint button_spacing; + GtkIconSize button_icon_size; + + gtk_widget_style_get (GTK_WIDGET (view), + "content_spacing", &content_spacing, + "button_spacing", &button_spacing, + "button_icon_size", &button_icon_size, + NULL); + + + /* cursor information */ + + hbox = gtk_hbox_new (TRUE, content_spacing); + gtk_box_pack_start (GTK_BOX (view), hbox, FALSE, FALSE, 0); + gtk_widget_show (hbox); + + frame = gimp_frame_new (_("Pixels")); + gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0); + gtk_widget_show (frame); + + table = gtk_table_new (2, 2, FALSE); + gtk_table_set_col_spacings (GTK_TABLE (table), 4); + gtk_table_set_row_spacings (GTK_TABLE (table), 2); + gtk_container_add (GTK_CONTAINER (frame), table); + gtk_widget_show (table); + + view->pixel_x_label = gtk_label_new (_("n/a")); + gtk_misc_set_alignment (GTK_MISC (view->pixel_x_label), 1.0, 0.5); + gimp_table_attach_aligned (GTK_TABLE (table), 0, 0, + _("X"), 0.5, 0.5, + view->pixel_x_label, 1, FALSE); + + view->pixel_y_label = gtk_label_new (_("n/a")); + gtk_misc_set_alignment (GTK_MISC (view->pixel_y_label), 1.0, 0.5); + gimp_table_attach_aligned (GTK_TABLE (table), 0, 1, + _("Y"), 0.5, 0.5, + view->pixel_y_label, 1, FALSE); + + frame = gimp_frame_new (_("Units")); + gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0); + gtk_widget_show (frame); + + table = gtk_table_new (2, 2, FALSE); + gtk_table_set_col_spacings (GTK_TABLE (table), 4); + gtk_table_set_row_spacings (GTK_TABLE (table), 2); + gtk_container_add (GTK_CONTAINER (frame), table); + gtk_widget_show (table); + + view->unit_x_label = gtk_label_new (_("n/a")); + gtk_misc_set_alignment (GTK_MISC (view->unit_x_label), 1.0, 0.5); + gimp_table_attach_aligned (GTK_TABLE (table), 0, 0, + _("X"), 0.5, 0.5, + view->unit_x_label, 1, FALSE); + + view->unit_y_label = gtk_label_new (_("n/a")); + gtk_misc_set_alignment (GTK_MISC (view->unit_y_label), 1.0, 0.5); + gimp_table_attach_aligned (GTK_TABLE (table), 0, 1, + _("Y"), 0.5, 0.5, + view->unit_y_label, 1, FALSE); + + + /* color information */ + + hbox = gtk_hbox_new (TRUE, 6); + gtk_box_pack_start (GTK_BOX (view), hbox, FALSE, FALSE, 0); + gtk_widget_show (hbox); + + view->color_frame_1 = gimp_color_frame_new (); + gimp_color_frame_set_mode (GIMP_COLOR_FRAME (view->color_frame_1), + GIMP_COLOR_FRAME_MODE_PIXEL); + gtk_box_pack_start (GTK_BOX (hbox), view->color_frame_1, TRUE, TRUE, 0); + gtk_widget_show (view->color_frame_1); + + view->color_frame_2 = gimp_color_frame_new (); + gimp_color_frame_set_mode (GIMP_COLOR_FRAME (view->color_frame_2), + GIMP_COLOR_FRAME_MODE_RGB); + gtk_box_pack_start (GTK_BOX (hbox), view->color_frame_2, TRUE, TRUE, 0); + gtk_widget_show (view->color_frame_2); +} + +static void +gimp_cursor_view_docked_iface_init (GimpDockedInterface *docked_iface) +{ + docked_iface->set_aux_info = gimp_cursor_view_set_aux_info; + docked_iface->get_aux_info = gimp_cursor_view_get_aux_info; + docked_iface->set_context = gimp_cursor_view_set_context; +} + +#define AUX_INFO_CURRENT_PAGE "current-page" + +static void +gimp_cursor_view_set_aux_info (GimpDocked *docked, + GList *aux_info) +{ + GimpCursorView *view = GIMP_CURSOR_VIEW (docked); + GList *list; + + for (list = aux_info; list; list = g_list_next (list)) + { + GimpSessionInfoAux *aux = list->data; + + if (! strcmp (aux->name, AUX_INFO_CURRENT_PAGE)) + { + } + } +} + +static GList * +gimp_cursor_view_get_aux_info (GimpDocked *docked) +{ + GimpCursorView *view = GIMP_CURSOR_VIEW (docked); + GList *aux_info = NULL; + +#if 0 + if (notebook->cur_page) + { + GimpSessionInfoAux *aux; + + aux = gimp_session_info_aux_new (AUX_INFO_CURRENT_PAGE, + G_OBJECT_TYPE_NAME (notebook->cur_page)); + aux_info = g_list_append (aux_info, aux); + } +#endif + + return aux_info; +} + +static void +gimp_cursor_view_set_context (GimpDocked *docked, + GimpContext *context) +{ + GimpCursorView *view = GIMP_CURSOR_VIEW (docked); + + if (context == view->context) + return; + + if (view->context) + { +#if 0 + g_signal_handlers_disconnect_by_func (view->context, + gimp_cursor_view_fg_changed, + view); + g_signal_handlers_disconnect_by_func (view->context, + gimp_cursor_view_bg_changed, + view); +#endif + + g_object_unref (view->context); + view->context = NULL; + } + + if (context) + { +#if 0 + GimpRGB rgb; +#endif + + view->context = g_object_ref (context); + +#if 0 + g_signal_connect (view->context, "foreground_changed", + G_CALLBACK (gimp_cursor_view_fg_changed), + view); + g_signal_connect (view->context, "background_changed", + G_CALLBACK (gimp_cursor_view_bg_changed), + view); + + if (view->edit_bg) + { + gimp_context_get_background (view->context, &rgb); + gimp_cursor_view_bg_changed (view->context, &rgb, view); + } + else + { + gimp_context_get_foreground (view->context, &rgb); + gimp_cursor_view_fg_changed (view->context, &rgb, view); + } +#endif + } +} + +static void +gimp_cursor_view_destroy (GtkObject *object) +{ + GimpCursorView *view = GIMP_CURSOR_VIEW (object); + + if (view->context) + gimp_docked_set_context (GIMP_DOCKED (view), NULL); + + GTK_OBJECT_CLASS (parent_class)->destroy (object); +} + +static void +gimp_cursor_view_style_set (GtkWidget *widget, + GtkStyle *prev_style) +{ + GimpCursorView *view = GIMP_CURSOR_VIEW (widget); + + if (GTK_WIDGET_CLASS (parent_class)->style_set) + GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style); +} + + +/* public functions */ + +GtkWidget * +gimp_cursor_view_new (GimpContext *context) +{ + GimpCursorView *view; + + g_return_val_if_fail (context == NULL || GIMP_IS_CONTEXT (context), NULL); + + view = g_object_new (GIMP_TYPE_CURSOR_VIEW, NULL); + + if (context) + gimp_docked_set_context (GIMP_DOCKED (view), context); + + return GTK_WIDGET (view); +} + +void +gimp_cursor_view_update_cursor (GimpCursorView *view, + GimpImage *image, + GimpUnit unit, + gdouble x, + gdouble y) +{ + GimpPickable *pickable = NULL; + guchar *color = NULL; + + g_return_if_fail (GIMP_IS_CURSOR_VIEW (view)); + g_return_if_fail (image == NULL || GIMP_IS_IMAGE (image)); + + if (image && unit == GIMP_UNIT_PIXEL) + unit = gimp_image_get_unit (image); + + if (image) + { + gboolean in_image; + gdouble unit_factor; + gint unit_digits; + const gchar *unit_str; + gchar format_buf[32]; + gchar buf[32]; + + in_image = (x >= 0.0 && x < gimp_image_get_width (image) && + y >= 0.0 && y < gimp_image_get_height (image)); + + unit_factor = _gimp_unit_get_factor (image->gimp, unit); + unit_digits = _gimp_unit_get_digits (image->gimp, unit); + unit_str = _gimp_unit_get_abbreviation (image->gimp, unit); + +#define FORMAT_STRING(s) (in_image ? (s) : "("s")") + + g_snprintf (buf, sizeof (buf), FORMAT_STRING ("%d"), (gint) floor (x)); + gtk_label_set_text (GTK_LABEL (view->pixel_x_label), buf); + + g_snprintf (buf, sizeof (buf), FORMAT_STRING ("%d"), (gint) floor (y)); + gtk_label_set_text (GTK_LABEL (view->pixel_y_label), buf); + + g_snprintf (format_buf, sizeof (format_buf), + FORMAT_STRING ("%%.%df %s"), unit_digits, unit_str); + + g_snprintf (buf, sizeof (buf), format_buf, + x * unit_factor / image->xresolution); + gtk_label_set_text (GTK_LABEL (view->unit_x_label), buf); + + g_snprintf (buf, sizeof (buf), format_buf, + y * unit_factor / image->yresolution); + gtk_label_set_text (GTK_LABEL (view->unit_y_label), buf); + } + else + { + gtk_label_set_text (GTK_LABEL (view->pixel_x_label), _("n/a")); + gtk_label_set_text (GTK_LABEL (view->pixel_y_label), _("n/a")); + gtk_label_set_text (GTK_LABEL (view->unit_x_label), _("n/a")); + gtk_label_set_text (GTK_LABEL (view->unit_y_label), _("n/a")); + } + + if (image) + { + pickable = GIMP_PICKABLE (image->projection); + + color = gimp_pickable_get_color_at (pickable, + (gint) floor (x), (gint) floor (y)); + } + + if (color) + { + GimpImageType sample_type; + GimpRGB rgb; + + sample_type = gimp_pickable_get_image_type (pickable); + + gimp_rgba_set_uchar (&rgb, + color[RED_PIX], + color[GREEN_PIX], + color[BLUE_PIX], + color[ALPHA_PIX]); + + gimp_color_frame_set_color (GIMP_COLOR_FRAME (view->color_frame_1), + sample_type, &rgb, -1); + gimp_color_frame_set_color (GIMP_COLOR_FRAME (view->color_frame_2), + sample_type, &rgb, -1); + + g_free (color); + } + else + { + gimp_color_frame_set_invalid (GIMP_COLOR_FRAME (view->color_frame_1)); + gimp_color_frame_set_invalid (GIMP_COLOR_FRAME (view->color_frame_2)); + } +} + + +/* private functions */ + +#if 0 +static void +gimp_cursor_view_fg_changed (GimpContext *context, + const GimpRGB *rgb, + GimpCursorView *view) +{ + if (! view->edit_bg) + { + GimpHSV hsv; + + gimp_rgb_to_hsv (rgb, &hsv); + + g_signal_handlers_block_by_func (view->notebook, + gimp_cursor_view_info_changed, + view); + + gimp_info_selector_set_info (GIMP_INFO_SELECTOR (view->notebook), + rgb, &hsv); + + g_signal_handlers_unblock_by_func (view->notebook, + gimp_cursor_view_info_changed, + view); + } +} + +static void +gimp_cursor_view_bg_changed (GimpContext *context, + const GimpRGB *rgb, + GimpCursorView *view) +{ + if (view->edit_bg) + { + GimpHSV hsv; + + gimp_rgb_to_hsv (rgb, &hsv); + + g_signal_handlers_block_by_func (view->notebook, + gimp_cursor_view_info_changed, + view); + + gimp_info_selector_set_info (GIMP_INFO_SELECTOR (view->notebook), + rgb, &hsv); + + g_signal_handlers_unblock_by_func (view->notebook, + gimp_cursor_view_info_changed, + view); + } +} +#endif diff --git a/app/widgets/gimpcursorview.h b/app/widgets/gimpcursorview.h new file mode 100644 index 0000000000..3af18f2852 --- /dev/null +++ b/app/widgets/gimpcursorview.h @@ -0,0 +1,69 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * gimpcursorview.h + * Copyright (C) 2005 Michael Natterer + * + * 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 __GIMP_CURSOR_VIEW_H__ +#define __GIMP_CURSOR_VIEW_H__ + + +#include "gimpeditor.h" + + +#define GIMP_TYPE_CURSOR_VIEW (gimp_cursor_view_get_type ()) +#define GIMP_CURSOR_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_CURSOR_VIEW, GimpCursorView)) +#define GIMP_CURSOR_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_CURSOR_VIEW, GimpCursorViewClass)) +#define GIMP_IS_CURSOR_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_CURSOR_VIEW)) +#define GIMP_IS_CURSOR_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_CURSOR_VIEW)) +#define GIMP_CURSOR_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_CURSOR_VIEW, GimpCursorViewClass)) + + +typedef struct _GimpCursorViewClass GimpCursorViewClass; + +struct _GimpCursorView +{ + GimpEditor parent_instance; + + GimpContext *context; + + GtkWidget *pixel_x_label; + GtkWidget *pixel_y_label; + GtkWidget *unit_x_label; + GtkWidget *unit_y_label; + GtkWidget *color_frame_1; + GtkWidget *color_frame_2; +}; + +struct _GimpCursorViewClass +{ + GimpEditorClass parent_class; +}; + + +GType gimp_cursor_view_get_type (void) G_GNUC_CONST; + +GtkWidget * gimp_cursor_view_new (GimpContext *context); + +void gimp_cursor_view_update_cursor (GimpCursorView *view, + GimpImage *image, + GimpUnit unit, + gdouble x, + gdouble y); + +#endif /* __GIMP_CURSOR_VIEW_H__ */ diff --git a/app/widgets/gimphelp-ids.h b/app/widgets/gimphelp-ids.h index 13859a0421..47ba9cd4fa 100644 --- a/app/widgets/gimphelp-ids.h +++ b/app/widgets/gimphelp-ids.h @@ -430,6 +430,8 @@ #define GIMP_HELP_DISPLAY_FILTER_DIALOG "gimp-display-filter-dialog" #define GIMP_HELP_HISTOGRAM_DIALOG "gimp-histogram-dialog" #define GIMP_HELP_INFO_DIALOG "gimp-info-dialog" +#define GIMP_HELP_CURSOR_DIALOG "gimp-cursor-dialog" +#define GIMP_HELP_SAMPLE_POINT_DIALOG "gimp-sample-point-dialog" #define GIMP_HELP_MODULE_DIALOG "gimp-module-dialog" #define GIMP_HELP_NAVIGATION_DIALOG "gimp-navigation-dialog" #define GIMP_HELP_TEXT_EDITOR_DIALOG "gimp-text-editor-dialog" diff --git a/app/widgets/gimpsamplepointeditor.c b/app/widgets/gimpsamplepointeditor.c new file mode 100644 index 0000000000..b2b1dfb9f4 --- /dev/null +++ b/app/widgets/gimpsamplepointeditor.c @@ -0,0 +1,269 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * gimpsamplepointeditor.c + * Copyright (C) 2005 Michael Natterer + * + * 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 + +#include "libgimpwidgets/gimpwidgets.h" + +#include "widgets-types.h" + +#include "core/gimp.h" +#include "core/gimpimage.h" +#include "core/gimpimage-pick-color.h" + +#include "gimpcolorframe.h" +#include "gimpmenufactory.h" +#include "gimpsamplepointeditor.h" +#include "gimpwidgets-utils.h" + +#include "gimp-intl.h" + + +static void gimp_sample_point_editor_class_init (GimpSamplePointEditorClass *klass); +static void gimp_sample_point_editor_init (GimpSamplePointEditor *editor); + +static GObject * gimp_sample_point_editor_constructor (GType type, + guint n_params, + GObjectConstructParam *params); + +static void gimp_sample_point_editor_style_set (GtkWidget *widget, + GtkStyle *prev_style); +static void gimp_sample_point_editor_set_image (GimpImageEditor *editor, + GimpImage *gimage); + +static void gimp_sample_point_editor_point_added (GimpImage *gimage, + GimpSamplePoint *sample_point, + GimpSamplePointEditor *editor); +static void gimp_sample_point_editor_point_removed (GimpImage *gimage, + GimpSamplePoint *sample_point, + GimpSamplePointEditor *editor); +static void gimp_sample_point_editor_points_changed (GimpSamplePointEditor *editor); + + +static GimpImageEditorClass *parent_class = NULL; + + +GType +gimp_sample_point_editor_get_type (void) +{ + static GType editor_type = 0; + + if (! editor_type) + { + static const GTypeInfo editor_info = + { + sizeof (GimpSamplePointEditorClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) gimp_sample_point_editor_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (GimpSamplePointEditor), + 0, /* n_preallocs */ + (GInstanceInitFunc) gimp_sample_point_editor_init, + }; + + editor_type = g_type_register_static (GIMP_TYPE_IMAGE_EDITOR, + "GimpSamplePointEditor", + &editor_info, 0); + } + + return editor_type; +} + +static void +gimp_sample_point_editor_class_init (GimpSamplePointEditorClass* klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + GimpImageEditorClass *image_editor_class = GIMP_IMAGE_EDITOR_CLASS (klass); + + parent_class = g_type_class_peek_parent (klass); + + object_class->constructor = gimp_sample_point_editor_constructor; + + widget_class->style_set = gimp_sample_point_editor_style_set; + + image_editor_class->set_image = gimp_sample_point_editor_set_image; +} + +static void +gimp_sample_point_editor_init (GimpSamplePointEditor *editor) +{ + gint content_spacing; + gint i; + gint row = 0; + gint column = 0; + + gtk_widget_style_get (GTK_WIDGET (editor), + "content_spacing", &content_spacing, + NULL); + + editor->table = gtk_table_new (2, 2, TRUE); + gtk_table_set_row_spacing (GTK_TABLE (editor->table), 0, content_spacing); + gtk_table_set_col_spacing (GTK_TABLE (editor->table), 0, content_spacing); + gtk_box_pack_start (GTK_BOX (editor), editor->table, FALSE, FALSE, 0); + gtk_widget_show (editor->table); + + for (i = 0; i < 4; i++) + { + editor->color_frames[i] = gimp_color_frame_new (); + gimp_color_frame_set_mode (GIMP_COLOR_FRAME (editor->color_frames[i]), + GIMP_COLOR_FRAME_MODE_PIXEL); + gtk_widget_set_sensitive (editor->color_frames[i], FALSE); + gtk_table_attach (GTK_TABLE (editor->table), editor->color_frames[i], + column, column + 1, row, row + 1, + GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + gtk_widget_show (editor->color_frames[i]); + + column++; + + if (column > 1) + { + column = 0; + row++; + } + } +} + +static GObject * +gimp_sample_point_editor_constructor (GType type, + guint n_params, + GObjectConstructParam *params) +{ + GObject *object; + GimpSamplePointEditor *editor; + + object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params); + + editor = GIMP_SAMPLE_POINT_EDITOR (object); + + return object; +} + +static void +gimp_sample_point_editor_style_set (GtkWidget *widget, + GtkStyle *prev_style) +{ + GimpSamplePointEditor *editor = GIMP_SAMPLE_POINT_EDITOR (widget); + gint content_spacing; + + if (GTK_WIDGET_CLASS (parent_class)->style_set) + GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style); + + gtk_widget_style_get (widget, + "content_spacing", &content_spacing, + NULL); + + gtk_table_set_row_spacing (GTK_TABLE (editor->table), 0, content_spacing); + gtk_table_set_col_spacing (GTK_TABLE (editor->table), 0, content_spacing); +} + +static void +gimp_sample_point_editor_set_image (GimpImageEditor *image_editor, + GimpImage *gimage) +{ + GimpSamplePointEditor *editor = GIMP_SAMPLE_POINT_EDITOR (image_editor); + + if (image_editor->gimage) + { + g_signal_handlers_disconnect_by_func (image_editor->gimage, + gimp_sample_point_editor_point_added, + editor); + g_signal_handlers_disconnect_by_func (image_editor->gimage, + gimp_sample_point_editor_point_removed, + editor); + } + + GIMP_IMAGE_EDITOR_CLASS (parent_class)->set_image (image_editor, gimage); + + if (gimage) + { + g_signal_connect (gimage, "sample-point-added", + G_CALLBACK (gimp_sample_point_editor_point_added), + editor); + g_signal_connect (gimage, "sample-point-removed", + G_CALLBACK (gimp_sample_point_editor_point_removed), + editor); + } + + gimp_sample_point_editor_points_changed (editor); +} + + +/* public functions */ + +GtkWidget * +gimp_sample_point_editor_new (GimpMenuFactory *menu_factory) +{ + g_return_val_if_fail (GIMP_IS_MENU_FACTORY (menu_factory), NULL); + + return g_object_new (GIMP_TYPE_SAMPLE_POINT_EDITOR, +#if 0 + "menu-factory", menu_factory, + "menu-identifier", "", + "ui-path", "/selection-editor-popup", +#endif + NULL); +} + + +/* private functions */ + +static void +gimp_sample_point_editor_point_added (GimpImage *gimage, + GimpSamplePoint *sample_point, + GimpSamplePointEditor *editor) +{ + gimp_sample_point_editor_points_changed (editor); +} + +static void +gimp_sample_point_editor_point_removed (GimpImage *gimage, + GimpSamplePoint *sample_point, + GimpSamplePointEditor *editor) +{ + gimp_sample_point_editor_points_changed (editor); +} + +static void +gimp_sample_point_editor_points_changed (GimpSamplePointEditor *editor) +{ + GimpImageEditor *image_editor = GIMP_IMAGE_EDITOR (editor); + gint n_points = 0; + gint i; + + if (image_editor->gimage) + n_points = MIN (4, g_list_length (image_editor->gimage->sample_points)); + + for (i = 0; i < n_points; i++) + { + gtk_widget_set_sensitive (editor->color_frames[i], TRUE); + } + + for (i = n_points; i < 4; i++) + { + gtk_widget_set_sensitive (editor->color_frames[i], FALSE); + gimp_color_frame_set_invalid (GIMP_COLOR_FRAME (editor->color_frames[i])); + } +} diff --git a/app/widgets/gimpsamplepointeditor.h b/app/widgets/gimpsamplepointeditor.h new file mode 100644 index 0000000000..e28df31048 --- /dev/null +++ b/app/widgets/gimpsamplepointeditor.h @@ -0,0 +1,58 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * gimpsamplepointeditor.h + * Copyright (C) 2005 Michael Natterer + * + * 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 __GIMP_SAMPLE_POINT_EDITOR_H__ +#define __GIMP_SAMPLE_POINT_EDITOR_H__ + + +#include "gimpimageeditor.h" + + +#define GIMP_TYPE_SAMPLE_POINT_EDITOR (gimp_sample_point_editor_get_type ()) +#define GIMP_SAMPLE_POINT_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_SAMPLE_POINT_EDITOR, GimpSamplePointEditor)) +#define GIMP_SAMPLE_POINT_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_SAMPLE_POINT_EDITOR, GimpSamplePointEditorClass)) +#define GIMP_IS_SAMPLE_POINT_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_SAMPLE_POINT_EDITOR)) +#define GIMP_IS_SAMPLE_POINT_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_SAMPLE_POINT_EDITOR)) +#define GIMP_SAMPLE_POINT_EDITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_SAMPLE_POINT_EDITOR, GimpSamplePointEditorClass)) + + +typedef struct _GimpSamplePointEditorClass GimpSamplePointEditorClass; + +struct _GimpSamplePointEditor +{ + GimpImageEditor parent_instance; + + GtkWidget *table; + GtkWidget *color_frames[4]; +}; + +struct _GimpSamplePointEditorClass +{ + GimpImageEditorClass parent_class; +}; + + +GType gimp_sample_point_editor_get_type (void) G_GNUC_CONST; + +GtkWidget * gimp_sample_point_editor_new (GimpMenuFactory *menu_factory); + + +#endif /* __GIMP_SAMPLE_POINT_EDITOR_H__ */ diff --git a/app/widgets/widgets-enums.c b/app/widgets/widgets-enums.c index fc0033eb18..4cd7cf1939 100644 --- a/app/widgets/widgets-enums.c +++ b/app/widgets/widgets-enums.c @@ -110,7 +110,7 @@ gimp_color_frame_mode_get_type (void) static const GimpEnumDesc descs[] = { - { GIMP_COLOR_FRAME_MODE_PIXEL, N_("Pixel values"), NULL }, + { GIMP_COLOR_FRAME_MODE_PIXEL, N_("Pixel"), NULL }, { GIMP_COLOR_FRAME_MODE_RGB, N_("RGB"), NULL }, { GIMP_COLOR_FRAME_MODE_HSV, N_("HSV"), NULL }, { GIMP_COLOR_FRAME_MODE_CMYK, N_("CMYK"), NULL }, diff --git a/app/widgets/widgets-enums.h b/app/widgets/widgets-enums.h index 016b3aa168..f5c8711373 100644 --- a/app/widgets/widgets-enums.h +++ b/app/widgets/widgets-enums.h @@ -65,10 +65,10 @@ GType gimp_color_frame_mode_get_type (void) G_GNUC_CONST; typedef enum { - GIMP_COLOR_FRAME_MODE_PIXEL, /*< desc="Pixel values" >*/ - GIMP_COLOR_FRAME_MODE_RGB, /*< desc="RGB" >*/ - GIMP_COLOR_FRAME_MODE_HSV, /*< desc="HSV" >*/ - GIMP_COLOR_FRAME_MODE_CMYK /*< desc="CMYK" >*/ + GIMP_COLOR_FRAME_MODE_PIXEL, /*< desc="Pixel" >*/ + GIMP_COLOR_FRAME_MODE_RGB, /*< desc="RGB" >*/ + GIMP_COLOR_FRAME_MODE_HSV, /*< desc="HSV" >*/ + GIMP_COLOR_FRAME_MODE_CMYK /*< desc="CMYK" >*/ } GimpColorFrameMode; diff --git a/app/widgets/widgets-types.h b/app/widgets/widgets-types.h index 6669d024e3..255a003922 100644 --- a/app/widgets/widgets-types.h +++ b/app/widgets/widgets-types.h @@ -49,6 +49,7 @@ typedef struct _GimpDocked GimpDocked; /* dummy typedef */ typedef struct _GimpEditor GimpEditor; typedef struct _GimpColorEditor GimpColorEditor; +typedef struct _GimpCursorView GimpCursorView; typedef struct _GimpDeviceStatus GimpDeviceStatus; typedef struct _GimpErrorConsole GimpErrorConsole; typedef struct _GimpToolOptionsEditor GimpToolOptionsEditor; @@ -68,6 +69,7 @@ typedef struct _GimpImageEditor GimpImageEditor; typedef struct _GimpColormapEditor GimpColormapEditor; typedef struct _GimpComponentEditor GimpComponentEditor; typedef struct _GimpHistogramEditor GimpHistogramEditor; +typedef struct _GimpSamplePointEditor GimpSamplePointEditor; typedef struct _GimpSelectionEditor GimpSelectionEditor; typedef struct _GimpUndoEditor GimpUndoEditor; diff --git a/menus/dialogs-menuitems.xml b/menus/dialogs-menuitems.xml index 3eb9a85902..2c708accae 100644 --- a/menus/dialogs-menuitems.xml +++ b/menus/dialogs-menuitems.xml @@ -12,6 +12,8 @@ + +