~ubuntu-branches/debian/squeeze/gnome-shell/squeeze

« back to all changes in this revision

Viewing changes to src/st/st-drawing-area.c

  • Committer: Bazaar Package Importer
  • Author(s): Gustavo Noronha Silva
  • Date: 2009-11-25 19:06:40 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20091125190640-cl36tq1pgy3gkws5
Tags: 2.28.1~git20091125-1
New upstream snapshot

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
 
2
 
 
3
/**
 
4
 * SECTION:st-drawing-area
 
5
 * @short_description: A dynamically-sized Cairo drawing area
 
6
 *
 
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.
 
15
 */
 
16
 
 
17
#include "st-drawing-area.h"
 
18
 
 
19
#include <cairo.h>
 
20
 
 
21
G_DEFINE_TYPE(StDrawingArea, st_drawing_area, ST_TYPE_BIN);
 
22
 
 
23
struct _StDrawingAreaPrivate {
 
24
  ClutterCairoTexture *texture;
 
25
};
 
26
 
 
27
/* Signals */
 
28
enum
 
29
{
 
30
  REDRAW,
 
31
  LAST_SIGNAL
 
32
};
 
33
 
 
34
static guint st_drawing_area_signals [LAST_SIGNAL] = { 0 };
 
35
 
 
36
static void
 
37
st_drawing_area_allocate (ClutterActor          *self,
 
38
                          const ClutterActorBox *box,
 
39
                          ClutterAllocationFlags flags)
 
40
{
 
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;
 
46
 
 
47
  (CLUTTER_ACTOR_CLASS (st_drawing_area_parent_class))->allocate (self, box, flags);
 
48
 
 
49
  theme_node = st_widget_get_theme_node (ST_WIDGET (self));
 
50
 
 
51
  st_theme_node_get_content_box (theme_node, box, &content_box);
 
52
 
 
53
  if (width > 0 && height > 0)
 
54
    {
 
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,
 
59
                     area->priv->texture);
 
60
    }
 
61
}
 
62
 
 
63
static void
 
64
st_drawing_area_style_changed (StWidget  *self)
 
65
{
 
66
  (ST_WIDGET_CLASS (st_drawing_area_parent_class))->style_changed (self);
 
67
 
 
68
  st_drawing_area_emit_redraw (ST_DRAWING_AREA (self));
 
69
}
 
70
 
 
71
static void
 
72
st_drawing_area_class_init (StDrawingAreaClass *klass)
 
73
{
 
74
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
75
  ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
 
76
  StWidgetClass *widget_class = ST_WIDGET_CLASS (klass);
 
77
 
 
78
  actor_class->allocate = st_drawing_area_allocate;
 
79
  widget_class->style_changed = st_drawing_area_style_changed;
 
80
 
 
81
  st_drawing_area_signals[REDRAW] =
 
82
    g_signal_new ("redraw",
 
83
                  G_TYPE_FROM_CLASS (klass),
 
84
                  G_SIGNAL_RUN_LAST,
 
85
                  G_STRUCT_OFFSET (StDrawingAreaClass, redraw),
 
86
                  NULL, NULL,
 
87
                  g_cclosure_marshal_VOID__OBJECT,
 
88
                  G_TYPE_NONE, 1, CLUTTER_TYPE_CAIRO_TEXTURE);
 
89
 
 
90
  g_type_class_add_private (gobject_class, sizeof (StDrawingAreaPrivate));
 
91
}
 
92
 
 
93
static void
 
94
st_drawing_area_init (StDrawingArea *area)
 
95
{
 
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));
 
100
}
 
101
 
 
102
/**
 
103
 * st_drawing_area_get_texture:
 
104
 *
 
105
 * Return Value: (transfer none):
 
106
 */
 
107
ClutterCairoTexture *
 
108
st_drawing_area_get_texture (StDrawingArea *area)
 
109
{
 
110
  return area->priv->texture;
 
111
}
 
112
 
 
113
/**
 
114
 * st_drawing_area_emit_redraw:
 
115
 * @area: A #StDrawingArea
 
116
 *
 
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.
 
120
 */
 
121
void
 
122
st_drawing_area_emit_redraw (StDrawingArea *area)
 
123
{
 
124
  g_signal_emit ((GObject*)area, st_drawing_area_signals[REDRAW], 0, area->priv->texture);
 
125
}