[gnome-shell] Move ShellDrawingArea to StDrawingArea
- From: Colin Walters <walters src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-shell] Move ShellDrawingArea to StDrawingArea
- Date: Mon, 23 Nov 2009 19:34:54 +0000 (UTC)
commit f815844eb4d9aa5bf7b53a87941cfc97921cf97f
Author: Colin Walters <walters verbum org>
Date: Sat Nov 14 16:39:22 2009 -0500
Move ShellDrawingArea to StDrawingArea
It's nicer to have ShellDrawingArea as a St widget so it can
participate more cleanly in CSS styling, such as queuing a redraw
automatically on style changes, and allowing subclasses to use
CSS styling.
https://bugzilla.gnome.org/show_bug.cgi?id=602131
js/ui/altTab.js | 2 +-
js/ui/appIcon.js | 2 +-
src/Makefile-st.am | 2 +
src/Makefile.am | 2 -
src/shell-drawing-area.c | 102 -------------------------------------
src/shell-drawing-area.h | 38 --------------
src/shell-drawing.c | 96 -----------------------------------
src/shell-drawing.h | 6 --
src/st/st-drawing-area.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++
src/st/st-drawing-area.h | 39 ++++++++++++++
10 files changed, 168 insertions(+), 246 deletions(-)
---
diff --git a/js/ui/altTab.js b/js/ui/altTab.js
index dd77266..add986f 100644
--- a/js/ui/altTab.js
+++ b/js/ui/altTab.js
@@ -686,7 +686,7 @@ AppSwitcher.prototype = {
appIcon.actor.reactive = false;
let n = this._arrows.length;
- let arrow = new Shell.DrawingArea();
+ let arrow = new St.DrawingArea();
arrow.connect('redraw', Lang.bind(this,
function (area, texture) {
Shell.draw_box_pointer(texture, Shell.PointerDirection.DOWN,
diff --git a/js/ui/appIcon.js b/js/ui/appIcon.js
index 571e050..5202a1d 100644
--- a/js/ui/appIcon.js
+++ b/js/ui/appIcon.js
@@ -307,7 +307,7 @@ AppIconMenu.prototype = {
this._windowContainer.connect('leave-event', Lang.bind(this, this._onMenuLeave));
this._windowContainer.connect('button-release-event', Lang.bind(this, this._onMenuButtonRelease));
- this._arrow = new Shell.DrawingArea();
+ this._arrow = new St.DrawingArea();
this._arrow.connect('redraw', Lang.bind(this, function (area, texture) {
Shell.draw_box_pointer(texture,
this._type == MenuType.ON_RIGHT ? Shell.PointerDirection.LEFT : Shell.PointerDirection.UP,
diff --git a/src/Makefile-st.am b/src/Makefile-st.am
index 9cb69f5..618e334 100644
--- a/src/Makefile-st.am
+++ b/src/Makefile-st.am
@@ -73,6 +73,7 @@ st_source_h = \
st/st-box-layout-child.h \
st/st-button.h \
st/st-clipboard.h \
+ st/st-drawing-area.h \
st/st-entry.h \
st/st-im-text.h \
st/st-label.h \
@@ -109,6 +110,7 @@ st_source_c = \
st/st-box-layout-child.c \
st/st-button.c \
st/st-clipboard.c \
+ st/st-drawing-area.c \
st/st-entry.c \
st/st-im-text.c \
st/st-label.c \
diff --git a/src/Makefile.am b/src/Makefile.am
index 4b11e83..ed9ae60 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -67,8 +67,6 @@ libgnome_shell_la_SOURCES = \
shell-button-box.h \
shell-drawing.c \
shell-drawing.h \
- shell-drawing-area.c \
- shell-drawing-area.h \
shell-embedded-window.c \
shell-embedded-window.h \
shell-embedded-window-private.h \
diff --git a/src/shell-drawing.c b/src/shell-drawing.c
index 69c47b9..78a7f54 100644
--- a/src/shell-drawing.c
+++ b/src/shell-drawing.c
@@ -3,102 +3,6 @@
#include "shell-drawing.h"
#include <math.h>
-/**
- * shell_create_vertical_gradient:
- * @top: the color at the top
- * @bottom: the color at the bottom
- *
- * Creates a vertical gradient actor.
- *
- * Return value: (transfer none): a #ClutterCairoTexture actor with the
- * gradient. The texture actor is floating, hence (transfer none).
- */
-ClutterCairoTexture *
-shell_create_vertical_gradient (ClutterColor *top,
- ClutterColor *bottom)
-{
- ClutterCairoTexture *texture;
- cairo_t *cr;
- cairo_pattern_t *pattern;
-
- /* Draw the gradient on an 8x8 pixel texture. Because the gradient is drawn
- * from the uppermost to the lowermost row, after stretching 1/16 of the
- * texture height has the top color and 1/16 has the bottom color. The 8
- * pixel width is chosen for reasons related to graphics hardware internals.
- */
- texture = CLUTTER_CAIRO_TEXTURE (clutter_cairo_texture_new (8, 8));
- cr = clutter_cairo_texture_create (texture);
-
- pattern = cairo_pattern_create_linear (0, 0, 0, 8);
- cairo_pattern_add_color_stop_rgba (pattern, 0,
- top->red / 255.,
- top->green / 255.,
- top->blue / 255.,
- top->alpha / 255.);
- cairo_pattern_add_color_stop_rgba (pattern, 1,
- bottom->red / 255.,
- bottom->green / 255.,
- bottom->blue / 255.,
- bottom->alpha / 255.);
-
- cairo_set_source (cr, pattern);
- cairo_paint (cr);
-
- cairo_pattern_destroy (pattern);
- cairo_destroy (cr);
-
- return texture;
-}
-
-/**
- * shell_create_horizontal_gradient:
- * @left: the color on the left
- * @right: the color on the right
- *
- * Creates a horizontal gradient actor.
- *
- * Return value: (transfer none): a #ClutterCairoTexture actor with the
- * gradient. The texture actor is floating, hence (transfer none).
- */
-ClutterCairoTexture *
-shell_create_horizontal_gradient (ClutterColor *left,
- ClutterColor *right)
-{
- ClutterCairoTexture *texture;
- cairo_t *cr;
- cairo_pattern_t *pattern;
-
- /* Draw the gradient on an 8x1 pixel texture. Because the gradient is drawn
- * from the left to the right column, after stretching 1/16 of the
- * texture width has the left side color and 1/16 has the right side color.
- * There is no reason to use the 8 pixel height that would be similar to the
- * reason we are using the 8 pixel width for the vertical gradient, so we
- * are just using the 1 pixel height instead.
- */
- texture = CLUTTER_CAIRO_TEXTURE (clutter_cairo_texture_new (8, 1));
- cr = clutter_cairo_texture_create (texture);
-
- pattern = cairo_pattern_create_linear (0, 0, 8, 0);
- cairo_pattern_add_color_stop_rgba (pattern, 0,
- left->red / 255.,
- left->green / 255.,
- left->blue / 255.,
- left->alpha / 255.);
- cairo_pattern_add_color_stop_rgba (pattern, 1,
- right->red / 255.,
- right->green / 255.,
- right->blue / 255.,
- right->alpha / 255.);
-
- cairo_set_source (cr, pattern);
- cairo_paint (cr);
-
- cairo_pattern_destroy (pattern);
- cairo_destroy (cr);
-
- return texture;
-}
-
void
shell_draw_clock (ClutterCairoTexture *texture,
int hour,
diff --git a/src/shell-drawing.h b/src/shell-drawing.h
index eae39fc..4b48d11 100644
--- a/src/shell-drawing.h
+++ b/src/shell-drawing.h
@@ -7,12 +7,6 @@
G_BEGIN_DECLS
-ClutterCairoTexture *shell_create_vertical_gradient (ClutterColor *top,
- ClutterColor *bottom);
-
-ClutterCairoTexture *shell_create_horizontal_gradient (ClutterColor *left,
- ClutterColor *right);
-
typedef enum {
SHELL_POINTER_UP,
SHELL_POINTER_DOWN,
diff --git a/src/st/st-drawing-area.c b/src/st/st-drawing-area.c
new file mode 100644
index 0000000..4391ac1
--- /dev/null
+++ b/src/st/st-drawing-area.c
@@ -0,0 +1,125 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
+/**
+ * SECTION:st-drawing-area
+ * @short_description: A dynamically-sized Cairo drawing area
+ *
+ * #StDrawingArea is similar to #ClutterCairoTexture in that
+ * it allows drawing via Cairo; the primary difference is that
+ * it is dynamically sized. To use, connect to the #StDrawingArea::redraw
+ * signal, and inside the signal handler, call
+ * clutter_cairo_texture_create() to begin drawing. The
+ * #StDrawingArea::redraw signal will be emitted by default when the area is
+ * resized or the CSS style changes; you can use the
+ * st_drawing_area_emit_redraw() as well.
+ */
+
+#include "st-drawing-area.h"
+
+#include <cairo.h>
+
+G_DEFINE_TYPE(StDrawingArea, st_drawing_area, ST_TYPE_BIN);
+
+struct _StDrawingAreaPrivate {
+ ClutterCairoTexture *texture;
+};
+
+/* Signals */
+enum
+{
+ REDRAW,
+ LAST_SIGNAL
+};
+
+static guint st_drawing_area_signals [LAST_SIGNAL] = { 0 };
+
+static void
+st_drawing_area_allocate (ClutterActor *self,
+ const ClutterActorBox *box,
+ ClutterAllocationFlags flags)
+{
+ StThemeNode *theme_node;
+ ClutterActorBox content_box;
+ StDrawingArea *area = ST_DRAWING_AREA (self);
+ int width = box->x2 - box->x1;
+ int height = box->y2 - box->y1;
+
+ (CLUTTER_ACTOR_CLASS (st_drawing_area_parent_class))->allocate (self, box, flags);
+
+ theme_node = st_widget_get_theme_node (ST_WIDGET (self));
+
+ st_theme_node_get_content_box (theme_node, box, &content_box);
+
+ if (width > 0 && height > 0)
+ {
+ clutter_cairo_texture_set_surface_size (area->priv->texture,
+ content_box.x2 - content_box.x1,
+ content_box.y2 - content_box.y1);
+ g_signal_emit (G_OBJECT (self), st_drawing_area_signals[REDRAW], 0,
+ area->priv->texture);
+ }
+}
+
+static void
+st_drawing_area_style_changed (StWidget *self)
+{
+ (ST_WIDGET_CLASS (st_drawing_area_parent_class))->style_changed (self);
+
+ st_drawing_area_emit_redraw (ST_DRAWING_AREA (self));
+}
+
+static void
+st_drawing_area_class_init (StDrawingAreaClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+ ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
+ StWidgetClass *widget_class = ST_WIDGET_CLASS (klass);
+
+ actor_class->allocate = st_drawing_area_allocate;
+ widget_class->style_changed = st_drawing_area_style_changed;
+
+ st_drawing_area_signals[REDRAW] =
+ g_signal_new ("redraw",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (StDrawingAreaClass, redraw),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE, 1, CLUTTER_TYPE_CAIRO_TEXTURE);
+
+ g_type_class_add_private (gobject_class, sizeof (StDrawingAreaPrivate));
+}
+
+static void
+st_drawing_area_init (StDrawingArea *area)
+{
+ area->priv = G_TYPE_INSTANCE_GET_PRIVATE (area, ST_TYPE_DRAWING_AREA,
+ StDrawingAreaPrivate);
+ area->priv->texture = CLUTTER_CAIRO_TEXTURE (clutter_cairo_texture_new (1, 1));
+ clutter_container_add_actor (CLUTTER_CONTAINER (area), CLUTTER_ACTOR (area->priv->texture));
+}
+
+/**
+ * st_drawing_area_get_texture:
+ *
+ * Return Value: (transfer none):
+ */
+ClutterCairoTexture *
+st_drawing_area_get_texture (StDrawingArea *area)
+{
+ return area->priv->texture;
+}
+
+/**
+ * st_drawing_area_emit_redraw:
+ * @area: A #StDrawingArea
+ *
+ * Immediately emit a redraw signal. Useful if
+ * some parameters for the area being drawn other
+ * than the size or style have changed.
+ */
+void
+st_drawing_area_emit_redraw (StDrawingArea *area)
+{
+ g_signal_emit ((GObject*)area, st_drawing_area_signals[REDRAW], 0, area->priv->texture);
+}
diff --git a/src/st/st-drawing-area.h b/src/st/st-drawing-area.h
new file mode 100644
index 0000000..3608372
--- /dev/null
+++ b/src/st/st-drawing-area.h
@@ -0,0 +1,39 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+#ifndef __ST_DRAWING_AREA_H__
+#define __ST_DRAWING_AREA_H__
+
+#include "st-bin.h"
+
+#define ST_TYPE_DRAWING_AREA (st_drawing_area_get_type ())
+#define ST_DRAWING_AREA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ST_TYPE_DRAWING_AREA, StDrawingArea))
+#define ST_DRAWING_AREA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ST_TYPE_DRAWING_AREA, StDrawingAreaClass))
+#define ST_IS_DRAWING_AREA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ST_TYPE_DRAWING_AREA))
+#define ST_IS_DRAWING_AREA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ST_TYPE_DRAWING_AREA))
+#define ST_DRAWING_AREA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ST_TYPE_DRAWING_AREA, StDrawingAreaClass))
+
+typedef struct _StDrawingArea StDrawingArea;
+typedef struct _StDrawingAreaClass StDrawingAreaClass;
+
+typedef struct _StDrawingAreaPrivate StDrawingAreaPrivate;
+
+struct _StDrawingArea
+{
+ StBin parent;
+
+ StDrawingAreaPrivate *priv;
+};
+
+struct _StDrawingAreaClass
+{
+ StBinClass parent_class;
+
+ void (*redraw) (StDrawingArea *area, ClutterCairoTexture *texture);
+};
+
+GType st_drawing_area_get_type (void) G_GNUC_CONST;
+
+ClutterCairoTexture *st_drawing_area_get_texture (StDrawingArea *area);
+
+void st_drawing_area_emit_redraw (StDrawingArea *area);
+
+#endif /* __ST_DRAWING_AREA_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]