]> git.0d.be Git - empathy.git/blob - src/empathy-rounded-actor.c
Merge remote-tracking branch 'glassrose/add-All-service-selection-in-debug-window'
[empathy.git] / src / empathy-rounded-actor.c
1 /*
2  * empathy-rounded-actor.c - Source for EmpathyRoundedActor
3  * Copyright (C) 2011 Collabora Ltd.
4  * @author Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20
21 #include "config.h"
22
23 #include <clutter/clutter.h>
24 #include <clutter-gtk/clutter-gtk.h>
25
26 #include "empathy-rounded-actor.h"
27
28 G_DEFINE_TYPE(EmpathyRoundedActor, empathy_rounded_actor, GTK_CLUTTER_TYPE_ACTOR)
29
30 struct _EmpathyRoundedActorPriv
31 {
32   guint round_factor;
33 };
34
35 static void
36 empathy_rounded_actor_paint (ClutterActor *actor)
37 {
38   EmpathyRoundedActor *self = EMPATHY_ROUNDED_ACTOR (actor);
39   ClutterActorBox allocation = { 0, };
40   gfloat width, height;
41
42   clutter_actor_get_allocation_box (actor, &allocation);
43   clutter_actor_box_get_size (&allocation, &width, &height);
44
45   cogl_path_new ();
46
47   /* create and store a path describing a rounded rectangle */
48   cogl_path_round_rectangle (0, 0, width, height,
49       height / self->priv->round_factor, 0.1);
50
51   cogl_clip_push_from_path ();
52
53   CLUTTER_ACTOR_CLASS (empathy_rounded_actor_parent_class)->paint (actor);
54
55   cogl_clip_pop ();
56 }
57
58 static void
59 empathy_rounded_actor_init (EmpathyRoundedActor *self)
60 {
61   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
62       EMPATHY_TYPE_ROUNDED_ACTOR, EmpathyRoundedActorPriv);
63
64   self->priv->round_factor = 2;
65 }
66
67 static void
68 empathy_rounded_actor_class_init (EmpathyRoundedActorClass *klass)
69 {
70   ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
71
72   actor_class->paint = empathy_rounded_actor_paint;
73
74   g_type_class_add_private (klass, sizeof (EmpathyRoundedActorPriv));
75 }
76
77 ClutterActor *
78 empathy_rounded_actor_new (void)
79 {
80   return CLUTTER_ACTOR (
81     g_object_new (EMPATHY_TYPE_ROUNDED_ACTOR, NULL));
82 }
83
84 void
85 empathy_rounded_actor_set_round_factor (EmpathyRoundedActor *self,
86     guint round_factor)
87 {
88   self->priv->round_factor = round_factor;
89 }