1
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
4
* SECTION:st-drawing-area
5
* @short_description: A dynamically-sized Cairo drawing area
7
* #StDrawingArea is similar to #ClutterCairoTexture in that
8
* it allows drawing via Cairo; the primary difference is that
9
* it is dynamically sized. To use, connect to the #StDrawingArea::redraw
10
* signal, and inside the signal handler, call
11
* clutter_cairo_texture_create() to begin drawing. The
12
* #StDrawingArea::redraw signal will be emitted by default when the area is
13
* resized or the CSS style changes; you can use the
14
* st_drawing_area_emit_redraw() as well.
17
#include "st-drawing-area.h"
21
G_DEFINE_TYPE(StDrawingArea, st_drawing_area, ST_TYPE_BIN);
23
struct _StDrawingAreaPrivate {
24
ClutterCairoTexture *texture;
34
static guint st_drawing_area_signals [LAST_SIGNAL] = { 0 };
37
st_drawing_area_allocate (ClutterActor *self,
38
const ClutterActorBox *box,
39
ClutterAllocationFlags flags)
41
StThemeNode *theme_node;
42
ClutterActorBox content_box;
43
StDrawingArea *area = ST_DRAWING_AREA (self);
44
int width = box->x2 - box->x1;
45
int height = box->y2 - box->y1;
47
(CLUTTER_ACTOR_CLASS (st_drawing_area_parent_class))->allocate (self, box, flags);
49
theme_node = st_widget_get_theme_node (ST_WIDGET (self));
51
st_theme_node_get_content_box (theme_node, box, &content_box);
53
if (width > 0 && height > 0)
55
clutter_cairo_texture_set_surface_size (area->priv->texture,
56
content_box.x2 - content_box.x1,
57
content_box.y2 - content_box.y1);
58
g_signal_emit (G_OBJECT (self), st_drawing_area_signals[REDRAW], 0,
64
st_drawing_area_style_changed (StWidget *self)
66
(ST_WIDGET_CLASS (st_drawing_area_parent_class))->style_changed (self);
68
st_drawing_area_emit_redraw (ST_DRAWING_AREA (self));
72
st_drawing_area_class_init (StDrawingAreaClass *klass)
74
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
75
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
76
StWidgetClass *widget_class = ST_WIDGET_CLASS (klass);
78
actor_class->allocate = st_drawing_area_allocate;
79
widget_class->style_changed = st_drawing_area_style_changed;
81
st_drawing_area_signals[REDRAW] =
82
g_signal_new ("redraw",
83
G_TYPE_FROM_CLASS (klass),
85
G_STRUCT_OFFSET (StDrawingAreaClass, redraw),
87
g_cclosure_marshal_VOID__OBJECT,
88
G_TYPE_NONE, 1, CLUTTER_TYPE_CAIRO_TEXTURE);
90
g_type_class_add_private (gobject_class, sizeof (StDrawingAreaPrivate));
94
st_drawing_area_init (StDrawingArea *area)
96
area->priv = G_TYPE_INSTANCE_GET_PRIVATE (area, ST_TYPE_DRAWING_AREA,
97
StDrawingAreaPrivate);
98
area->priv->texture = CLUTTER_CAIRO_TEXTURE (clutter_cairo_texture_new (1, 1));
99
clutter_container_add_actor (CLUTTER_CONTAINER (area), CLUTTER_ACTOR (area->priv->texture));
103
* st_drawing_area_get_texture:
105
* Return Value: (transfer none):
107
ClutterCairoTexture *
108
st_drawing_area_get_texture (StDrawingArea *area)
110
return area->priv->texture;
114
* st_drawing_area_emit_redraw:
115
* @area: A #StDrawingArea
117
* Immediately emit a redraw signal. Useful if
118
* some parameters for the area being drawn other
119
* than the size or style have changed.
122
st_drawing_area_emit_redraw (StDrawingArea *area)
124
g_signal_emit ((GObject*)area, st_drawing_area_signals[REDRAW], 0, area->priv->texture);