~ubuntu-branches/ubuntu/trusty/gnome-shell/trusty-proposed

« back to all changes in this revision

Viewing changes to src/shell-arrow.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2012-03-14 13:47:20 UTC
  • mfrom: (1.1.36) (18.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20120314134720-202sbjbu4a3z1fru
Tags: 3.3.90-0ubuntu1
* Sync with Debian experimental svn packaging (LP: #941755, #937709).
  Remaining changes:
  - debian/gnome-shell.gsettings-override: Update for Ubuntu defaults
  - debian/control.in: Recommend cups-pk-helper
  - debian/patches/10-make-NetworkManager-optional.patch: Disabled
  - Don't run dh-autoreconf

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
 
#include "config.h"
4
 
 
5
 
#include "shell-arrow.h"
6
 
 
7
 
#include <clutter/clutter.h>
8
 
#include <gtk/gtk.h>
9
 
#include <cairo.h>
10
 
 
11
 
enum {
12
 
   PROP_0,
13
 
 
14
 
   PROP_DIRECTION
15
 
};
16
 
 
17
 
G_DEFINE_TYPE(ShellArrow, shell_arrow, CLUTTER_TYPE_CAIRO_TEXTURE);
18
 
 
19
 
struct _ShellArrowPrivate {
20
 
  GtkArrowType direction;
21
 
};
22
 
 
23
 
static void shell_arrow_redraw (ShellArrow *self);
24
 
 
25
 
static void
26
 
shell_arrow_set_property (GObject         *object,
27
 
                          guint            prop_id,
28
 
                          const GValue    *value,
29
 
                          GParamSpec      *pspec)
30
 
{
31
 
  ShellArrow *self = SHELL_ARROW (object);
32
 
 
33
 
  switch (prop_id)
34
 
    {
35
 
    case PROP_DIRECTION:
36
 
      self->priv->direction = g_value_get_enum (value);
37
 
      break;
38
 
 
39
 
    default:
40
 
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
41
 
      break;
42
 
    }
43
 
 
44
 
  shell_arrow_redraw (self);
45
 
}
46
 
 
47
 
static void
48
 
shell_arrow_get_property (GObject         *object,
49
 
                                     guint            prop_id,
50
 
                                     GValue          *value,
51
 
                                     GParamSpec      *pspec)
52
 
{
53
 
  ShellArrow *self = SHELL_ARROW (object);
54
 
 
55
 
  switch (prop_id)
56
 
    {
57
 
    case PROP_DIRECTION:
58
 
      g_value_set_enum (value, self->priv->direction);
59
 
      break;
60
 
 
61
 
    default:
62
 
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
63
 
      break;
64
 
    }
65
 
}
66
 
 
67
 
static void
68
 
shell_arrow_redraw (ShellArrow *self)
69
 
{
70
 
  cairo_t *cr;
71
 
  guint width, height;
72
 
 
73
 
  g_object_get (G_OBJECT (self), "surface-width", &width,
74
 
                                 "surface-height", &height,
75
 
                                 NULL);
76
 
 
77
 
  if (width == 0)
78
 
    return;
79
 
 
80
 
  cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (self));
81
 
 
82
 
  cairo_set_source_rgb (cr, 1, 1, 1);
83
 
 
84
 
  switch (self->priv->direction)
85
 
  {
86
 
    case GTK_ARROW_RIGHT:
87
 
      cairo_move_to (cr, 0, 0);
88
 
      cairo_line_to (cr, width, height*0.5);
89
 
      cairo_line_to (cr, 0, height);
90
 
      break;
91
 
    case GTK_ARROW_LEFT:
92
 
      cairo_move_to (cr, width, 0);
93
 
      cairo_line_to (cr, 0, height*0.5);
94
 
      cairo_line_to (cr, width, height);
95
 
      break;
96
 
    case GTK_ARROW_UP:
97
 
      cairo_move_to (cr, 0, height);
98
 
      cairo_line_to (cr, width*0.5, 0);
99
 
      cairo_line_to (cr, width, height);
100
 
      break;
101
 
    case GTK_ARROW_DOWN:
102
 
      cairo_move_to (cr, 0, 0);
103
 
      cairo_line_to (cr, width*0.5, height);
104
 
      cairo_line_to (cr, width, height);
105
 
      break;
106
 
    case GTK_ARROW_NONE:
107
 
    default:
108
 
      break;
109
 
  }
110
 
 
111
 
  cairo_close_path (cr);
112
 
  cairo_fill (cr);
113
 
 
114
 
  cairo_destroy (cr);
115
 
}
116
 
 
117
 
static void
118
 
shell_arrow_class_init (ShellArrowClass *klass)
119
 
{
120
 
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
121
 
 
122
 
  g_type_class_add_private (klass, sizeof (ShellArrowPrivate));
123
 
 
124
 
  object_class->get_property = shell_arrow_get_property;
125
 
  object_class->set_property = shell_arrow_set_property;
126
 
 
127
 
  g_object_class_install_property (object_class,
128
 
                                   PROP_DIRECTION,
129
 
                                   g_param_spec_enum ("direction",
130
 
                                                      "Direction",
131
 
                                                      "Direction",
132
 
                                                      GTK_TYPE_ARROW_TYPE,
133
 
                                                      GTK_ARROW_NONE,
134
 
                                                      G_PARAM_READWRITE));
135
 
}
136
 
 
137
 
static void
138
 
shell_arrow_init (ShellArrow *actor)
139
 
{
140
 
  actor->priv = G_TYPE_INSTANCE_GET_PRIVATE (actor, SHELL_TYPE_ARROW,
141
 
                                             ShellArrowPrivate);
142
 
  g_signal_connect (actor, "notify::surface-width", G_CALLBACK (shell_arrow_redraw), NULL);
143
 
}