Commit a622f98e authored by Michael Natterer's avatar Michael Natterer 😴

app: add new widget GimpLayerModeBox

which is a hbox with a GimpLayerModeComboBox and another combo box to
control the mode combo's group. Absolutely horrible WIP and not used
yet.
parent 0b7b1206
......@@ -237,6 +237,8 @@ libappwidgets_a_sources = \
gimplanguagestore.h \
gimplanguagestore-parser.c \
gimplanguagestore-parser.h \
gimplayermodebox.c \
gimplayermodebox.h \
gimplayermodecombobox.c \
gimplayermodecombobox.h \
gimplayertreeview.c \
......
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1999 Peter Mattis and Spencer Kimball
*
* gimplayermodebox.c
* Copyright (C) 2017 Michael Natterer <mitch@gimp.org>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gtk/gtk.h>
#include <gegl.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "widgets-types.h"
#include "core/gimp-layer-modes.h"
#include "gimplayermodebox.h"
#include "gimplayermodecombobox.h"
#include "gimp-intl.h"
/**
* SECTION: gimplayermodebox
* @title: GimpLayerModeBox
* @short_description: A #GtkBox subclass for selecting a layer mode.
*
* A #GtkBox subclass for selecting a layer mode
**/
enum
{
PROP_0,
PROP_LAYER_MODE,
PROP_WITH_BEHIND,
PROP_WITH_REPLACE
};
struct _GimpLayerModeBoxPrivate
{
GimpLayerMode layer_mode;
gboolean with_behind;
gboolean with_replace;
};
static void gimp_layer_mode_box_constructed (GObject *object);
static void gimp_layer_mode_box_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_layer_mode_box_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
G_DEFINE_TYPE (GimpLayerModeBox, gimp_layer_mode_box,
GTK_TYPE_BOX)
#define parent_class gimp_layer_mode_box_parent_class
static void
gimp_layer_mode_box_class_init (GimpLayerModeBoxClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->constructed = gimp_layer_mode_box_constructed;
object_class->set_property = gimp_layer_mode_box_set_property;
object_class->get_property = gimp_layer_mode_box_get_property;
g_object_class_install_property (object_class, PROP_LAYER_MODE,
g_param_spec_enum ("layer-mode",
NULL, NULL,
GIMP_TYPE_LAYER_MODE,
GIMP_LAYER_MODE_NORMAL,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_WITH_BEHIND,
g_param_spec_boolean ("with-behind",
NULL, NULL,
FALSE,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_WITH_REPLACE,
g_param_spec_boolean ("with-replace",
NULL, NULL,
FALSE,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_type_class_add_private (klass, sizeof (GimpLayerModeBoxPrivate));
}
static void
gimp_layer_mode_box_init (GimpLayerModeBox *box)
{
box->priv = G_TYPE_INSTANCE_GET_PRIVATE (box,
GIMP_TYPE_LAYER_MODE_BOX,
GimpLayerModeBoxPrivate);
gtk_orientable_set_orientation (GTK_ORIENTABLE (box),
GTK_ORIENTATION_HORIZONTAL);
gtk_box_set_spacing (GTK_BOX (box), 4);
}
static void
gimp_layer_mode_box_constructed (GObject *object)
{
GimpLayerModeBox *box = GIMP_LAYER_MODE_BOX (object);
GtkWidget *mode_combo;
GtkWidget *group_combo;
GtkCellLayout *layout;
GtkCellRenderer *cell;
G_OBJECT_CLASS (parent_class)->constructed (object);
mode_combo = gimp_layer_mode_combo_box_new (box->priv->with_behind,
box->priv->with_replace);
gimp_int_combo_box_set_label (GIMP_INT_COMBO_BOX (mode_combo),
_("Mode"));
gtk_box_pack_start (GTK_BOX (box), mode_combo, TRUE, TRUE, 0);
gtk_widget_show (mode_combo);
g_object_bind_property (object, "layer-mode",
G_OBJECT (mode_combo), "layer-mode",
G_BINDING_BIDIRECTIONAL |
G_BINDING_SYNC_CREATE);
group_combo = gimp_prop_enum_combo_box_new (G_OBJECT (mode_combo),
"group", 0, 0);
gtk_box_pack_start (GTK_BOX (box), group_combo, FALSE, FALSE, 0);
gtk_widget_show (group_combo);
layout = GTK_CELL_LAYOUT (gtk_bin_get_child (GTK_BIN (group_combo)));
gtk_cell_layout_clear (layout);
cell = gtk_cell_renderer_text_new ();
g_object_set (cell,
"width-chars", 1,
NULL);
gtk_cell_layout_pack_start (layout, cell, TRUE);
gtk_cell_layout_set_attributes (layout, cell,
"text", GIMP_INT_STORE_LABEL,
NULL);
}
static void
gimp_layer_mode_box_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GimpLayerModeBox *box = GIMP_LAYER_MODE_BOX (object);
switch (prop_id)
{
case PROP_LAYER_MODE:
gimp_layer_mode_box_set_mode (box, g_value_get_enum (value));
break;
case PROP_WITH_BEHIND:
box->priv->with_behind = g_value_get_boolean (value);
break;
case PROP_WITH_REPLACE:
box->priv->with_replace = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gimp_layer_mode_box_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GimpLayerModeBox *box = GIMP_LAYER_MODE_BOX (object);
switch (prop_id)
{
case PROP_LAYER_MODE:
g_value_set_enum (value, box->priv->layer_mode);
break;
case PROP_WITH_BEHIND:
g_value_set_boolean (value, box->priv->with_behind);
break;
case PROP_WITH_REPLACE:
g_value_set_boolean (value, box->priv->with_replace);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
/**
* gimp_layer_mode_box_new:
* Foo.
*
* Return value: a new #GimpLayerModeBox.
**/
GtkWidget *
gimp_layer_mode_box_new (gboolean with_behind,
gboolean with_replace)
{
return g_object_new (GIMP_TYPE_LAYER_MODE_BOX,
"with-behind", with_behind,
"with-replace", with_replace,
NULL);
}
void
gimp_layer_mode_box_set_mode (GimpLayerModeBox *box,
GimpLayerMode mode)
{
g_return_if_fail (GIMP_IS_LAYER_MODE_BOX (box));
if (mode != box->priv->layer_mode)
{
box->priv->layer_mode = mode;
g_object_notify (G_OBJECT (box), "layer-mode");
}
}
GimpLayerMode
gimp_layer_mode_box_get_mode (GimpLayerModeBox *box)
{
g_return_val_if_fail (GIMP_IS_LAYER_MODE_BOX (box),
GIMP_LAYER_MODE_NORMAL);
return box->priv->layer_mode;
}
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1999 Peter Mattis and Spencer Kimball
*
* gimplayermodebox.h
* Copyright (C) 2017 Michael Natterer <mitch@gimp.org>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_LAYER_MODE_BOX_H__
#define __GIMP_LAYER_MODE_BOX_H__
#define GIMP_TYPE_LAYER_MODE_BOX (gimp_layer_mode_box_get_type ())
#define GIMP_LAYER_MODE_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_LAYER_MODE_BOX, GimpLayerModeBox))
#define GIMP_LAYER_MODE_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_LAYER_MODE_BOX, GimpLayerModeBoxClass))
#define GIMP_IS_LAYER_MODE_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_LAYER_MODE_BOX))
#define GIMP_IS_LAYER_MODE_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_LAYER_MODE_BOX))
#define GIMP_LAYER_MODE_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_LAYER_MODE_BOX, GimpLayerModeBoxClass))
typedef struct _GimpLayerModeBoxPrivate GimpLayerModeBoxPrivate;
typedef struct _GimpLayerModeBoxClass GimpLayerModeBoxClass;
struct _GimpLayerModeBox
{
GtkBox parent_instance;
GimpLayerModeBoxPrivate *priv;
};
struct _GimpLayerModeBoxClass
{
GtkBoxClass parent_class;
};
GType gimp_layer_mode_box_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_layer_mode_box_new (gboolean with_behind,
gboolean with_replace);
void gimp_layer_mode_box_set_mode (GimpLayerModeBox *combo,
GimpLayerMode mode);
GimpLayerMode gimp_layer_mode_box_get_mode (GimpLayerModeBox *combo);
#endif /* __GIMP_LAYER_MODE_BOX_H__ */
......@@ -250,9 +250,13 @@ gimp_layer_mode_combo_box_changed (GtkComboBox *gtk_combo)
* Return value: a new #GimpLayerModeComboBox.
**/
GtkWidget *
gimp_layer_mode_combo_box_new (void)
gimp_layer_mode_combo_box_new (gboolean with_behind,
gboolean with_replace)
{
return g_object_new (GIMP_TYPE_LAYER_MODE_COMBO_BOX, NULL);
return g_object_new (GIMP_TYPE_LAYER_MODE_COMBO_BOX,
"with-behind", with_behind,
"with-replace", with_replace,
NULL);
}
void
......
......@@ -48,7 +48,8 @@ struct _GimpLayerModeComboBoxClass
GType gimp_layer_mode_combo_box_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_layer_mode_combo_box_new (void);
GtkWidget * gimp_layer_mode_combo_box_new (gboolean with_behind,
gboolean with_replace);
void gimp_layer_mode_combo_box_set_mode (GimpLayerModeComboBox *combo,
GimpLayerMode mode);
......
......@@ -198,6 +198,7 @@ typedef struct _GimpImagePropView GimpImagePropView;
typedef struct _GimpLanguageComboBox GimpLanguageComboBox;
typedef struct _GimpLanguageEntry GimpLanguageEntry;
typedef struct _GimpLanguageStore GimpLanguageStore;
typedef struct _GimpLayerModeBox GimpLayerModeBox;
typedef struct _GimpLayerModeComboBox GimpLayerModeComboBox;
typedef struct _GimpMessageBox GimpMessageBox;
typedef struct _GimpOverlayBox GimpOverlayBox;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment