mirror of https://github.com/GNOME/gimp.git
app: use gimp_prop_spin_scale_new() in GimpPosterizeTool
and remove tons of code needed to update the old stuff.
This commit is contained in:
parent
4c0169aaaf
commit
783edc1e7b
|
@ -20,21 +20,15 @@
|
||||||
#include <gegl.h>
|
#include <gegl.h>
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
#include "libgimpmath/gimpmath.h"
|
|
||||||
#include "libgimpconfig/gimpconfig.h"
|
|
||||||
#include "libgimpwidgets/gimpwidgets.h"
|
#include "libgimpwidgets/gimpwidgets.h"
|
||||||
|
|
||||||
#include "tools-types.h"
|
#include "tools-types.h"
|
||||||
|
|
||||||
#include "operations/gimpposterizeconfig.h"
|
#include "operations/gimpposterizeconfig.h"
|
||||||
|
|
||||||
#include "core/gimpdrawable.h"
|
|
||||||
#include "core/gimperror.h"
|
|
||||||
#include "core/gimpimage.h"
|
|
||||||
|
|
||||||
#include "widgets/gimphelp-ids.h"
|
#include "widgets/gimphelp-ids.h"
|
||||||
|
#include "widgets/gimppropwidgets.h"
|
||||||
#include "display/gimpdisplay.h"
|
#include "widgets/gimpspinscale.h"
|
||||||
|
|
||||||
#include "gimpimagemapoptions.h"
|
#include "gimpimagemapoptions.h"
|
||||||
#include "gimpposterizetool.h"
|
#include "gimpposterizetool.h"
|
||||||
|
@ -42,24 +36,10 @@
|
||||||
#include "gimp-intl.h"
|
#include "gimp-intl.h"
|
||||||
|
|
||||||
|
|
||||||
#define SLIDER_WIDTH 200
|
static GeglNode * gimp_posterize_tool_get_operation (GimpImageMapTool *im_tool,
|
||||||
|
GObject **config,
|
||||||
|
gchar **undo_desc);
|
||||||
static gboolean gimp_posterize_tool_initialize (GimpTool *tool,
|
static void gimp_posterize_tool_dialog (GimpImageMapTool *im_tool);
|
||||||
GimpDisplay *display,
|
|
||||||
GError **error);
|
|
||||||
|
|
||||||
static GeglNode * gimp_posterize_tool_get_operation (GimpImageMapTool *im_tool,
|
|
||||||
GObject **config,
|
|
||||||
gchar **undo_desc);
|
|
||||||
static void gimp_posterize_tool_dialog (GimpImageMapTool *im_tool);
|
|
||||||
|
|
||||||
static void gimp_posterize_tool_config_notify (GObject *object,
|
|
||||||
GParamSpec *pspec,
|
|
||||||
GimpPosterizeTool *posterize_tool);
|
|
||||||
|
|
||||||
static void gimp_posterize_tool_levels_changed (GtkAdjustment *adjustment,
|
|
||||||
GimpPosterizeTool *posterize_tool);
|
|
||||||
|
|
||||||
|
|
||||||
G_DEFINE_TYPE (GimpPosterizeTool, gimp_posterize_tool,
|
G_DEFINE_TYPE (GimpPosterizeTool, gimp_posterize_tool,
|
||||||
|
@ -87,11 +67,8 @@ gimp_posterize_tool_register (GimpToolRegisterCallback callback,
|
||||||
static void
|
static void
|
||||||
gimp_posterize_tool_class_init (GimpPosterizeToolClass *klass)
|
gimp_posterize_tool_class_init (GimpPosterizeToolClass *klass)
|
||||||
{
|
{
|
||||||
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
|
|
||||||
GimpImageMapToolClass *im_tool_class = GIMP_IMAGE_MAP_TOOL_CLASS (klass);
|
GimpImageMapToolClass *im_tool_class = GIMP_IMAGE_MAP_TOOL_CLASS (klass);
|
||||||
|
|
||||||
tool_class->initialize = gimp_posterize_tool_initialize;
|
|
||||||
|
|
||||||
im_tool_class->dialog_desc = _("Posterize (Reduce Number of Colors)");
|
im_tool_class->dialog_desc = _("Posterize (Reduce Number of Colors)");
|
||||||
|
|
||||||
im_tool_class->get_operation = gimp_posterize_tool_get_operation;
|
im_tool_class->get_operation = gimp_posterize_tool_get_operation;
|
||||||
|
@ -103,42 +80,16 @@ gimp_posterize_tool_init (GimpPosterizeTool *posterize_tool)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
|
||||||
gimp_posterize_tool_initialize (GimpTool *tool,
|
|
||||||
GimpDisplay *display,
|
|
||||||
GError **error)
|
|
||||||
{
|
|
||||||
GimpPosterizeTool *posterize_tool = GIMP_POSTERIZE_TOOL (tool);
|
|
||||||
|
|
||||||
if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error))
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
gtk_adjustment_set_value (posterize_tool->levels_data,
|
|
||||||
posterize_tool->config->levels);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static GeglNode *
|
static GeglNode *
|
||||||
gimp_posterize_tool_get_operation (GimpImageMapTool *image_map_tool,
|
gimp_posterize_tool_get_operation (GimpImageMapTool *image_map_tool,
|
||||||
GObject **config,
|
GObject **config,
|
||||||
gchar **undo_desc)
|
gchar **undo_desc)
|
||||||
{
|
{
|
||||||
GimpPosterizeTool *posterize_tool = GIMP_POSTERIZE_TOOL (image_map_tool);
|
*config = g_object_new (GIMP_TYPE_POSTERIZE_CONFIG, NULL);
|
||||||
|
|
||||||
posterize_tool->config = g_object_new (GIMP_TYPE_POSTERIZE_CONFIG, NULL);
|
|
||||||
|
|
||||||
g_signal_connect_object (posterize_tool->config, "notify",
|
|
||||||
G_CALLBACK (gimp_posterize_tool_config_notify),
|
|
||||||
G_OBJECT (posterize_tool), 0);
|
|
||||||
|
|
||||||
*config = G_OBJECT (posterize_tool->config);
|
|
||||||
|
|
||||||
return gegl_node_new_child (NULL,
|
return gegl_node_new_child (NULL,
|
||||||
"operation", "gimp:posterize",
|
"operation", "gimp:posterize",
|
||||||
"config", posterize_tool->config,
|
"config", *config,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,58 +101,15 @@ gimp_posterize_tool_get_operation (GimpImageMapTool *image_map_tool,
|
||||||
static void
|
static void
|
||||||
gimp_posterize_tool_dialog (GimpImageMapTool *image_map_tool)
|
gimp_posterize_tool_dialog (GimpImageMapTool *image_map_tool)
|
||||||
{
|
{
|
||||||
GimpPosterizeTool *posterize_tool = GIMP_POSTERIZE_TOOL (image_map_tool);
|
GtkWidget *main_vbox;
|
||||||
GtkWidget *main_vbox;
|
GtkWidget *scale;
|
||||||
GtkWidget *table;
|
|
||||||
GtkObject *data;
|
|
||||||
|
|
||||||
main_vbox = gimp_image_map_tool_dialog_get_vbox (image_map_tool);
|
main_vbox = gimp_image_map_tool_dialog_get_vbox (image_map_tool);
|
||||||
|
|
||||||
/* The table containing sliders */
|
scale = gimp_prop_spin_scale_new (image_map_tool->config, "levels",
|
||||||
table = gtk_table_new (1, 3, FALSE);
|
_("Posterize _levels"),
|
||||||
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
|
1.0, 10.0, 0);
|
||||||
gtk_box_pack_start (GTK_BOX (main_vbox), table, FALSE, FALSE, 0);
|
gimp_spin_scale_set_gamma (GIMP_SPIN_SCALE (scale), 1.5);
|
||||||
gtk_widget_show (table);
|
gtk_box_pack_start (GTK_BOX (main_vbox), scale, FALSE, FALSE, 0);
|
||||||
|
gtk_widget_show (scale);
|
||||||
data = gimp_scale_entry_new (GTK_TABLE (table), 0, 0,
|
|
||||||
_("Posterize _levels:"), SLIDER_WIDTH, -1,
|
|
||||||
posterize_tool->config->levels,
|
|
||||||
2.0, 256.0, 1.0, 10.0, 0,
|
|
||||||
TRUE, 0.0, 0.0,
|
|
||||||
NULL, NULL);
|
|
||||||
|
|
||||||
gimp_scale_entry_set_logarithmic (data, TRUE);
|
|
||||||
|
|
||||||
posterize_tool->levels_data = GTK_ADJUSTMENT (data);
|
|
||||||
|
|
||||||
g_signal_connect (posterize_tool->levels_data, "value-changed",
|
|
||||||
G_CALLBACK (gimp_posterize_tool_levels_changed),
|
|
||||||
posterize_tool);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gimp_posterize_tool_config_notify (GObject *object,
|
|
||||||
GParamSpec *pspec,
|
|
||||||
GimpPosterizeTool *posterize_tool)
|
|
||||||
{
|
|
||||||
GimpPosterizeConfig *config = GIMP_POSTERIZE_CONFIG (object);
|
|
||||||
|
|
||||||
if (! posterize_tool->levels_data)
|
|
||||||
return;
|
|
||||||
|
|
||||||
gtk_adjustment_set_value (posterize_tool->levels_data, config->levels);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gimp_posterize_tool_levels_changed (GtkAdjustment *adjustment,
|
|
||||||
GimpPosterizeTool *posterize_tool)
|
|
||||||
{
|
|
||||||
gint value = ROUND (gtk_adjustment_get_value (adjustment));
|
|
||||||
|
|
||||||
if (posterize_tool->config->levels != value)
|
|
||||||
{
|
|
||||||
g_object_set (posterize_tool->config,
|
|
||||||
"levels", value,
|
|
||||||
NULL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,12 +35,7 @@ typedef struct _GimpPosterizeToolClass GimpPosterizeToolClass;
|
||||||
|
|
||||||
struct _GimpPosterizeTool
|
struct _GimpPosterizeTool
|
||||||
{
|
{
|
||||||
GimpImageMapTool parent_instance;
|
GimpImageMapTool parent_instance;
|
||||||
|
|
||||||
GimpPosterizeConfig *config;
|
|
||||||
|
|
||||||
/* dialog */
|
|
||||||
GtkAdjustment *levels_data;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GimpPosterizeToolClass
|
struct _GimpPosterizeToolClass
|
||||||
|
|
Loading…
Reference in New Issue