public
Description: A Clutter-based Twitter client
Homepage: http://live.gnome.org/Tweet
Clone URL: git://github.com/ebassi/tweet.git
Search Repo:
Cell renderer for the status list

The status list uses a cell renderer providing a representation
for each status.

At the moment, the status text is put inside a label on a
background rectangle, drawn using Cairo.
Emmanuele Bassi (author)
Thu Apr 17 21:37:16 -0700 2008
commit  c392255986da2c9f08d0511826017c1a5ffc2659
tree    a17198e86b53fa17d214b0f5db855a21229c0a6a
parent  437c516113cd12b7e058668f002a03cccaa61c2f
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
0
@@ -1 +1,187 @@
0
+#ifdef HAVE_CONFIG_H
0
+#include "config.h"
0
+#endif
0
+
0
+#include <glib.h>
0
+#include <stdlib.h>
0
+#include <string.h>
0
+
0
+#include <cairo/cairo.h>
0
+
0
+#include <clutter/clutter.h>
0
+#include <clutter-cairo/clutter-cairo.h>
0
+#include <tidy/tidy.h>
0
+
0
+#include <twitter-glib/twitter-glib.h>
0
+
0
+#include "tweet-status-renderer.h"
0
+
0
+#define ICON_WIDTH 96
0
+#define ICON_HEIGHT 96
0
+
0
+#define V_PADDING 6
0
+#define H_PADDING 12
0
+
0
+#define DEFAULT_WIDTH (ICON_WIDTH + (2 * H_PADDING) + 230)
0
+#define DEFAULT_HEIGHT (ICON_HEIGHT + (2 * V_PADDING))
0
+
0
+#define TEXT_X (ICON_WIDTH + (2 * H_PADDING))
0
+#define TEXT_Y (V_PADDING)
0
+
0
+#define BG_ROUND_RADIUS 12
0
+
0
+G_DEFINE_TYPE (TweetStatusRenderer,
0
+ tweet_status_renderer,
0
+ TIDY_TYPE_CELL_RENDERER);
0
+
0
+static ClutterActor *
0
+create_cell (TwitterStatus *status,
0
+ gint width,
0
+ gint height,
0
+ const gchar *font_name)
0
+{
0
+ ClutterActor *base, *bg, *label;
0
+ cairo_t *cr;
0
+ ClutterColor bg_color = { 162, 162, 162, 0xcc };
0
+ ClutterColor label_color = { 0xee, 0xee, 0xee, 255 };
0
+
0
+ if (width < 0)
0
+ width = DEFAULT_WIDTH;
0
+ if (height < 0)
0
+ height = DEFAULT_HEIGHT;
0
+
0
+ base = clutter_group_new ();
0
+
0
+ /* background texture */
0
+ bg = clutter_cairo_new (DEFAULT_WIDTH, DEFAULT_HEIGHT);
0
+ clutter_container_add_actor (CLUTTER_CONTAINER (base), bg);
0
+ clutter_actor_show (bg);
0
+
0
+ cr = clutter_cairo_create (CLUTTER_CAIRO (bg));
0
+ g_assert (cr != NULL);
0
+
0
+ cairo_move_to (cr, BG_ROUND_RADIUS, 0);
0
+ cairo_line_to (cr, width - BG_ROUND_RADIUS, 0);
0
+ cairo_curve_to (cr, width, 0, width, 0, width, BG_ROUND_RADIUS);
0
+ cairo_line_to (cr, width, height - BG_ROUND_RADIUS);
0
+ cairo_curve_to (cr, width, height, width, height, width - BG_ROUND_RADIUS, height);
0
+ cairo_line_to (cr, BG_ROUND_RADIUS, height);
0
+ cairo_curve_to (cr, 0, height, 0, height, 0, height - BG_ROUND_RADIUS);
0
+ cairo_line_to (cr, 0, BG_ROUND_RADIUS);
0
+ cairo_curve_to (cr, 0, 0, 0, 0, BG_ROUND_RADIUS, 0);
0
+
0
+ cairo_close_path (cr);
0
+
0
+ clutter_cairo_set_source_color (cr, &bg_color);
0
+ cairo_fill_preserve (cr);
0
+
0
+ cairo_destroy (cr);
0
+
0
+ g_assert (TWITTER_IS_STATUS (status));
0
+
0
+ /* status text */
0
+ label = clutter_label_new ();
0
+ clutter_label_set_color (CLUTTER_LABEL (label), &label_color);
0
+ clutter_label_set_font_name (CLUTTER_LABEL (label), font_name);
0
+ clutter_label_set_line_wrap (CLUTTER_LABEL (label), TRUE);
0
+ clutter_label_set_text (CLUTTER_LABEL (label), twitter_status_get_text (status));
0
+ clutter_container_add_actor (CLUTTER_CONTAINER (base), label);
0
+ clutter_actor_set_position (label, TEXT_X, TEXT_Y);
0
+ clutter_actor_set_width (label, 230);
0
+ clutter_actor_show (label);
0
+
0
+ return base;
0
+}
0
+
0
+static ClutterActor *
0
+tweet_status_renderer_get_cell_actor (TidyCellRenderer *renderer,
0
+ TidyActor *list_view,
0
+ const GValue *value,
0
+ TidyCellState cell_state,
0
+ ClutterGeometry *size,
0
+ gint row,
0
+ gint column)
0
+{
0
+ ClutterActor *retval = NULL;
0
+ gchar *font_name;
0
+ ClutterColor *background_color, *active_color, *text_color;
0
+ ClutterFixed x_align, y_align;
0
+
0
+ tidy_stylable_get (TIDY_STYLABLE (list_view),
0
+ "font-name", &font_name,
0
+ "bg-color", &background_color,
0
+ "active-color", &active_color,
0
+ "text-color", &text_color,
0
+ NULL);
0
+
0
+ tidy_cell_renderer_get_alignmentx (renderer, &x_align, &y_align);
0
+
0
+ if (row == -1 || cell_state == TIDY_CELL_HEADER)
0
+ {
0
+ ClutterActor *label;
0
+
0
+ retval = tidy_frame_new ();
0
+ tidy_actor_set_alignmentx (TIDY_ACTOR (retval), x_align, y_align);
0
+
0
+ label = g_object_new (CLUTTER_TYPE_LABEL,
0
+ "font-name", font_name,
0
+ "text", g_value_get_string (value),
0
+ "color", text_color,
0
+ "alignment", PANGO_ALIGN_CENTER,
0
+ "ellipsize", PANGO_ELLIPSIZE_END,
0
+ "wrap", FALSE,
0
+ NULL);
0
+ clutter_container_add_actor (CLUTTER_CONTAINER (retval), label);
0
+ clutter_actor_show (label);
0
+
0
+ goto out;
0
+ }
0
+
0
+ if (G_VALUE_TYPE (value) != TWITTER_TYPE_STATUS)
0
+ return NULL;
0
+ else
0
+ {
0
+ TwitterStatus *status;
0
+ gint width, height;
0
+
0
+ status = g_value_get_object (value);
0
+
0
+ width = height = -1;
0
+ if (size)
0
+ {
0
+ width = size->width;
0
+ height = size->height;
0
+ }
0
+
0
+ retval = create_cell (status, width, height, font_name);
0
+ }
0
+
0
+out:
0
+ g_free (font_name);
0
+ clutter_color_free (background_color);
0
+ clutter_color_free (active_color);
0
+ clutter_color_free (text_color);
0
+
0
+ return retval;
0
+}
0
+
0
+static void
0
+tweet_status_renderer_class_init (TweetStatusRendererClass *klass)
0
+{
0
+ TidyCellRendererClass *renderer_class = TIDY_CELL_RENDERER_CLASS (klass);
0
+
0
+ renderer_class->get_cell_actor = tweet_status_renderer_get_cell_actor;
0
+}
0
+
0
+static void
0
+tweet_status_renderer_init (TweetStatusRenderer *renderer)
0
+{
0
+
0
+}
0
+
0
+TidyCellRenderer *
0
+tweet_status_renderer_new (void)
0
+{
0
+ return g_object_new (TWEET_TYPE_STATUS_RENDERER, NULL);
0
+}
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
0
@@ -1 +1,36 @@
0
+#ifndef __TWEET_STATUS_RENDERER_H__
0
+#define __TWEET_STATUS_RENDERER_H__
0
+
0
+#include <glib-object.h>
0
+#include <tidy/tidy-cell-renderer.h>
0
+#include <twitter-glib/twitter-glib.h>
0
+
0
+G_BEGIN_DECLS
0
+
0
+#define TWEET_TYPE_STATUS_RENDERER (tweet_status_renderer_get_type ())
0
+#define TWEET_STATUS_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TWEET_TYPE_STATUS_RENDERER, TweetStatusRenderer))
0
+#define TWEET_IS_STATUS_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TWEET_TYPE_STATUS_RENDERER))
0
+#define TWEET_STATUS_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TWEET_TYPE_STATUS_RENDERER, TweetStatusRendererClass))
0
+#define TWEET_IS_STATUS_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TWEET_TYPE_STATUS_RENDERER))
0
+#define TWEET_STATUS_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TWEET_TYPE_STATUS_RENDERER, TweetStatusRendererClass))
0
+
0
+typedef struct _TweetStatusRenderer TweetStatusRenderer;
0
+typedef struct _TweetStatusRendererClass TweetStatusRendererClass;
0
+
0
+struct _TweetStatusRenderer
0
+{
0
+ TidyCellRenderer parent_instance;
0
+};
0
+
0
+struct _TweetStatusRendererClass
0
+{
0
+ TidyCellRendererClass parent_class;
0
+};
0
+
0
+GType tweet_status_renderer_get_type (void) G_GNUC_CONST;
0
+TidyCellRenderer *tweet_status_renderer_new (void);
0
+
0
+G_END_DECLS
0
+
0
+#endif /* __TWEET_STATUS_RENDERER_H__ */

Comments

    No one has commented yet.