1 /* logjam - a GTK client for LiveJournal.
2 * Copyright (C) 2000-2003 Evan Martin <evan@livejournal.com>
9 # include <librsvg/rsvg.h>
10 # include "logo-svg.h"
26 GdkPixbuf
*pb
[THROBBER_COUNT
];
32 /* delay in ms between frames of the throbber */
33 #define THROBBER_FRAME_DELAY (20)
34 static void update_svg (Throbber
*t
);
37 void throbber_reset (Throbber
*t
) {
43 static void throbber_finalize (GObject
*object
) {
44 GObjectClass
*parent_class
;
45 throbber_stop(THROBBER(object
));
46 parent_class
= g_type_class_peek_parent(G_OBJECT_GET_CLASS(object
));
47 parent_class
->finalize(object
);
51 static void size_cb (gint
*width
, gint
*height
, gpointer data
) {
52 *width
= *height
= 48;
56 static void update_svg (Throbber
*t
) {
62 handle
= rsvg_handle_new();
63 rsvg_handle_set_size_callback(handle
, size_cb
, NULL
, NULL
);
65 if (!rsvg_handle_write(handle
, (unsigned char *)logo_svg_data_1
, sizeof(logo_svg_data_1
)-1, &err
)) {
66 g_print("error: %s\n", err
->message
);
71 transform
= g_strdup_printf("transform=\"translate(%d, %d) rotate(%d) translate(%d, %d)\"\n",
72 logo_svg_translate2_x
, logo_svg_translate2_y
, t
->angle
, logo_svg_translate1_x
, logo_svg_translate1_y
);
73 rsvg_handle_write(handle
, (unsigned char *)transform
, strlen(transform
), NULL
);
76 if (!rsvg_handle_write(handle
, (unsigned char *)logo_svg_data_2
, sizeof(logo_svg_data_2
)-1, &err
)) {
77 g_print("error: %s\n", err
->message
);
81 if (!rsvg_handle_close(handle
, &err
)) {
82 g_print("error: %s\n", err
->message
);
87 pb
= rsvg_handle_get_pixbuf(handle
);
89 gtk_image_set_from_pixbuf(GTK_IMAGE(t
), pb
);
90 g_object_unref(G_OBJECT(pb
));
91 rsvg_handle_free(handle
);
95 static gboolean
throbber_cb (Throbber
*t
) {
102 /* we're doing the image-based throbber. */
104 /* delay in ms between frames of the throbber */
105 #define THROBBER_FRAME_DELAY (400)
107 void throbber_reset (Throbber
*t
) {
108 icons_load_throbber(t
->pb
);
109 gtk_image_set_from_pixbuf(GTK_IMAGE(t
), t
->pb
[0]);
113 static gboolean
throbber_cb (Throbber
*t
) {
114 t
->state
= (t
->state
+1)%THROBBER_COUNT
;
115 gtk_image_set_from_pixbuf(GTK_IMAGE(t
), t
->pb
[t
->state
]);
120 static void throbber_finalize (GObject
*object
) {
121 GObjectClass
*parent_class
;
122 throbber_stop(THROBBER(object
));
123 for (int i
= 0; i
< THROBBER_COUNT
; ++i
) g_object_unref(G_OBJECT(THROBBER(object
)->pb
[i
]));
124 parent_class
= g_type_class_peek_parent(G_OBJECT_GET_CLASS(object
));
125 parent_class
->finalize(object
);
131 static void throbber_init (Throbber
*t
) {
136 void throbber_start (Throbber
*t
) {
138 t
->tag
= gtk_timeout_add(THROBBER_FRAME_DELAY
, (GSourceFunc
) throbber_cb
, t
);
142 void throbber_stop (Throbber
*t
) {
144 gtk_timeout_remove(t
->tag
);
149 static void throbber_class_init (gpointer klass
, gpointer class_data
) {
150 GObjectClass
*gclass
= G_OBJECT_CLASS(klass
);
151 gclass
->finalize
= throbber_finalize
;
155 GType
throbber_get_type (void) {
156 static GType throbber_type
= 0;
157 if (!throbber_type
) {
158 static const GTypeInfo throbber_info
= {
159 sizeof(GtkImageClass
),
162 (GClassInitFunc
) throbber_class_init
,
167 (GInstanceInitFunc
) throbber_init
,
169 throbber_type
= g_type_register_static(GTK_TYPE_IMAGE
, "Throbber", &throbber_info
, 0);
171 return throbber_type
;
175 GtkWidget
*throbber_new (void) {
176 Throbber
*throbber
= THROBBER(g_object_new(throbber_get_type(), NULL
));
177 return GTK_WIDGET(throbber
);