[gimp] app: split out the round corners code from GimpOverlayDialog
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: split out the round corners code from GimpOverlayDialog
- Date: Sat, 12 Jun 2010 17:03:56 +0000 (UTC)
commit cabc3aa67a61fac6d7415713a2269359e2051434
Author: Michael Natterer <mitch gimp org>
Date: Sat Jun 12 19:02:51 2010 +0200
app: split out the round corners code from GimpOverlayDialog
into a new GtkBin subclass called GimpOverlayFrame.
app/widgets/Makefile.am | 2 +
app/widgets/gimpoverlaydialog.c | 96 +-------------------------
app/widgets/gimpoverlaydialog.h | 9 ++-
app/widgets/gimpoverlayframe.c | 143 +++++++++++++++++++++++++++++++++++++++
app/widgets/gimpoverlayframe.h | 52 ++++++++++++++
5 files changed, 206 insertions(+), 96 deletions(-)
---
diff --git a/app/widgets/Makefile.am b/app/widgets/Makefile.am
index 1166d02..8975ce8 100644
--- a/app/widgets/Makefile.am
+++ b/app/widgets/Makefile.am
@@ -235,6 +235,8 @@ libappwidgets_a_sources = \
gimpoverlaychild.h \
gimpoverlaydialog.c \
gimpoverlaydialog.h \
+ gimpoverlayframe.c \
+ gimpoverlayframe.h \
gimppaletteeditor.c \
gimppanedbox.c \
gimppanedbox.h \
diff --git a/app/widgets/gimpoverlaydialog.c b/app/widgets/gimpoverlaydialog.c
index 5195519..24581e4 100644
--- a/app/widgets/gimpoverlaydialog.c
+++ b/app/widgets/gimpoverlaydialog.c
@@ -55,8 +55,6 @@ static void gimp_overlay_dialog_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void gimp_overlay_dialog_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
-static gboolean gimp_overlay_dialog_expose (GtkWidget *widget,
- GdkEventExpose *eevent);
static void gimp_overlay_dialog_forall (GtkContainer *container,
gboolean include_internals,
@@ -69,7 +67,8 @@ static ResponseData * get_response_data (GtkWidget *widget,
gboolean create);
-G_DEFINE_TYPE (GimpOverlayDialog, gimp_overlay_dialog, GTK_TYPE_BIN)
+G_DEFINE_TYPE (GimpOverlayDialog, gimp_overlay_dialog,
+ GIMP_TYPE_OVERLAY_FRAME)
static guint signals[LAST_SIGNAL] = { 0, };
@@ -87,7 +86,6 @@ gimp_overlay_dialog_class_init (GimpOverlayDialogClass *klass)
widget_class->size_request = gimp_overlay_dialog_size_request;
widget_class->size_allocate = gimp_overlay_dialog_size_allocate;
- widget_class->expose_event = gimp_overlay_dialog_expose;
container_class->forall = gimp_overlay_dialog_forall;
@@ -119,24 +117,10 @@ gimp_overlay_dialog_class_init (GimpOverlayDialogClass *klass)
static void
gimp_overlay_dialog_init (GimpOverlayDialog *dialog)
{
- GtkWidget *widget = GTK_WIDGET (dialog);
-
-#if 0 /* crashes badly beause gtk+ doesn't support offscreen windows
- * with colormap != parent_colormap yet
- */
- GdkScreen *screen = gtk_widget_get_screen (widget);
- GdkColormap *rgba = gdk_screen_get_rgba_colormap (screen);
-
- if (rgba)
- gtk_widget_set_colormap (widget, rgba);
-#endif
-
- gtk_widget_set_app_paintable (widget, TRUE);
-
dialog->action_area = gtk_hbutton_box_new ();
gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog->action_area),
GTK_BUTTONBOX_END);
- gtk_widget_set_parent (dialog->action_area, widget);
+ gtk_widget_set_parent (dialog->action_area, GTK_WIDGET (dialog));
gtk_widget_show (dialog->action_area);
}
@@ -228,80 +212,6 @@ gimp_overlay_dialog_size_allocate (GtkWidget *widget,
gtk_widget_size_allocate (dialog->action_area, &action_allocation);
}
-static gboolean
-gimp_overlay_dialog_expose (GtkWidget *widget,
- GdkEventExpose *eevent)
-{
- cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget));
- GtkStyle *style;
- GtkAllocation allocation;
- gint border_width;
- gint inner_width;
- gint inner_height;
-
- style = gtk_widget_get_style (widget);
- gtk_widget_get_allocation (widget, &allocation);
-
- border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
-
- inner_width = allocation.width - border_width / 2;
- inner_height = allocation.height - border_width / 2;
-
- cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
- gdk_cairo_region (cr, eevent->region);
- cairo_clip_preserve (cr);
- cairo_fill (cr);
-
- cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
- gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_NORMAL]);
-
-#define TO_RAD(deg) (deg * (G_PI / 180.0))
-
- cairo_arc (cr,
- border_width,
- border_width,
- border_width,
- TO_RAD (180),
- TO_RAD (270));
- cairo_line_to (cr,
- allocation.width - border_width,
- 0);
-
- cairo_arc (cr,
- allocation.width - border_width,
- border_width,
- border_width,
- TO_RAD (270),
- TO_RAD (0));
- cairo_line_to (cr,
- allocation.width,
- allocation.height - border_width);
-
- cairo_arc (cr,
- allocation.width - border_width,
- allocation.height - border_width,
- border_width,
- TO_RAD (0),
- TO_RAD (90));
- cairo_line_to (cr,
- border_width,
- allocation.height);
-
- cairo_arc (cr,
- border_width,
- allocation.height - border_width,
- border_width,
- TO_RAD (90),
- TO_RAD (180));
- cairo_close_path (cr);
-
- cairo_fill (cr);
-
- cairo_destroy (cr);
-
- return GTK_WIDGET_CLASS (parent_class)->expose_event (widget, eevent);
-}
-
static void
gimp_overlay_dialog_forall (GtkContainer *container,
gboolean include_internals,
diff --git a/app/widgets/gimpoverlaydialog.h b/app/widgets/gimpoverlaydialog.h
index 1a72d92..72c396c 100644
--- a/app/widgets/gimpoverlaydialog.h
+++ b/app/widgets/gimpoverlaydialog.h
@@ -22,6 +22,9 @@
#define __GIMP_OVERLAY_DIALOG_H__
+#include "gimpoverlayframe.h"
+
+
#define GIMP_TYPE_OVERLAY_DIALOG (gimp_overlay_dialog_get_type ())
#define GIMP_OVERLAY_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_OVERLAY_DIALOG, GimpOverlayDialog))
#define GIMP_OVERLAY_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_OVERLAY_DIALOG, GimpOverlayDialogClass))
@@ -35,14 +38,14 @@ typedef struct _GimpOverlayDialogClass GimpOverlayDialogClass;
struct _GimpOverlayDialog
{
- GtkBin parent_instance;
+ GimpOverlayFrame parent_instance;
- GtkWidget *action_area;
+ GtkWidget *action_area;
};
struct _GimpOverlayDialogClass
{
- GtkBinClass parent_class;
+ GimpOverlayFrameClass parent_class;
void (* response) (GimpOverlayDialog *overlay,
gint response_id);
diff --git a/app/widgets/gimpoverlayframe.c b/app/widgets/gimpoverlayframe.c
new file mode 100644
index 0000000..f6e61b8
--- /dev/null
+++ b/app/widgets/gimpoverlayframe.c
@@ -0,0 +1,143 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpoverlayframe.c
+ * Copyright (C) 2010 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 "widgets-types.h"
+
+#include "gimpoverlayframe.h"
+
+
+static gboolean gimp_overlay_frame_expose (GtkWidget *widget,
+ GdkEventExpose *eevent);
+
+
+G_DEFINE_TYPE (GimpOverlayFrame, gimp_overlay_frame, GTK_TYPE_BIN)
+
+#define parent_class gimp_overlay_frame_parent_class
+
+
+static void
+gimp_overlay_frame_class_init (GimpOverlayFrameClass *klass)
+{
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ widget_class->expose_event = gimp_overlay_frame_expose;
+}
+
+static void
+gimp_overlay_frame_init (GimpOverlayFrame *frame)
+{
+ GtkWidget *widget = GTK_WIDGET (frame);
+
+#if 0 /* crashes badly beause gtk+ doesn't support offscreen windows
+ * with colormap != parent_colormap yet
+ */
+ GdkScreen *screen = gtk_widget_get_screen (widget);
+ GdkColormap *rgba = gdk_screen_get_rgba_colormap (screen);
+
+ if (rgba)
+ gtk_widget_set_colormap (widget, rgba);
+#endif
+
+ gtk_widget_set_app_paintable (widget, TRUE);
+}
+
+static gboolean
+gimp_overlay_frame_expose (GtkWidget *widget,
+ GdkEventExpose *eevent)
+{
+ cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget));
+ GtkStyle *style;
+ GtkAllocation allocation;
+ gint border_width;
+ gint inner_width;
+ gint inner_height;
+
+ style = gtk_widget_get_style (widget);
+ gtk_widget_get_allocation (widget, &allocation);
+
+ border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
+
+ inner_width = allocation.width - border_width / 2;
+ inner_height = allocation.height - border_width / 2;
+
+ cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
+ gdk_cairo_region (cr, eevent->region);
+ cairo_clip_preserve (cr);
+ cairo_fill (cr);
+
+ cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+ gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_NORMAL]);
+
+#define TO_RAD(deg) (deg * (G_PI / 180.0))
+
+ cairo_arc (cr,
+ border_width,
+ border_width,
+ border_width,
+ TO_RAD (180),
+ TO_RAD (270));
+ cairo_line_to (cr,
+ allocation.width - border_width,
+ 0);
+
+ cairo_arc (cr,
+ allocation.width - border_width,
+ border_width,
+ border_width,
+ TO_RAD (270),
+ TO_RAD (0));
+ cairo_line_to (cr,
+ allocation.width,
+ allocation.height - border_width);
+
+ cairo_arc (cr,
+ allocation.width - border_width,
+ allocation.height - border_width,
+ border_width,
+ TO_RAD (0),
+ TO_RAD (90));
+ cairo_line_to (cr,
+ border_width,
+ allocation.height);
+
+ cairo_arc (cr,
+ border_width,
+ allocation.height - border_width,
+ border_width,
+ TO_RAD (90),
+ TO_RAD (180));
+ cairo_close_path (cr);
+
+ cairo_fill (cr);
+
+ cairo_destroy (cr);
+
+ return GTK_WIDGET_CLASS (parent_class)->expose_event (widget, eevent);
+}
+
+GtkWidget *
+gimp_overlay_frame_new (void)
+{
+ return g_object_new (GIMP_TYPE_OVERLAY_FRAME, NULL);
+}
diff --git a/app/widgets/gimpoverlayframe.h b/app/widgets/gimpoverlayframe.h
new file mode 100644
index 0000000..8b38ba9
--- /dev/null
+++ b/app/widgets/gimpoverlayframe.h
@@ -0,0 +1,52 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpoverlayframe.h
+ * Copyright (C) 2010 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_OVERLAY_FRAME_H__
+#define __GIMP_OVERLAY_FRAME_H__
+
+
+#define GIMP_TYPE_OVERLAY_FRAME (gimp_overlay_frame_get_type ())
+#define GIMP_OVERLAY_FRAME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_OVERLAY_FRAME, GimpOverlayFrame))
+#define GIMP_OVERLAY_FRAME_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_OVERLAY_FRAME, GimpOverlayFrameClass))
+#define GIMP_IS_OVERLAY_FRAME(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_OVERLAY_FRAME))
+#define GIMP_IS_OVERLAY_FRAME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_OVERLAY_FRAME))
+#define GIMP_OVERLAY_FRAME_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_OVERLAY_FRAME, GimpOverlayFrameClass))
+
+
+typedef struct _GimpOverlayFrame GimpOverlayFrame;
+typedef struct _GimpOverlayFrameClass GimpOverlayFrameClass;
+
+struct _GimpOverlayFrame
+{
+ GtkBin parent_instance;
+};
+
+struct _GimpOverlayFrameClass
+{
+ GtkBinClass parent_class;
+};
+
+
+GType gimp_overlay_frame_get_type (void) G_GNUC_CONST;
+
+GtkWidget * gimp_overlay_frame_new (void);
+
+
+#endif /* __GIMP_OVERLAY_FRAME_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]