3
* This file is part of Open Sound System.
5
* Copyright (C) 4Front Technologies 1996-2008.
7
* This this source file is released under GPL v2 license (no other versions).
8
* See the COPYING file included in the main directory of this source
9
* distribution for the license terms and conditions.
18
#include <gtk/gtkmain.h>
19
#include <gtk/gtksignal.h>
23
extern int width_adjust;
25
#define SCROLL_DELAY_LENGTH 300
26
#define VU_DEFAULT_SIZE 100
27
#define VU_MARGIN (widget->allocation.width/3)
29
/* Forward declarations */
31
static void gtk_vu_class_init (GtkVUClass * klass);
32
static void gtk_vu_init (GtkVU * vu);
33
static void gtk_vu_destroy (GtkObject * object);
34
static void gtk_vu_realize (GtkWidget * widget);
35
static void gtk_vu_unrealize (GtkWidget * widget);
36
static void gtk_vu_size_request (GtkWidget * widget,
37
GtkRequisition * requisition);
38
static void gtk_vu_size_allocate (GtkWidget * widget,
39
GtkAllocation * allocation);
40
static gint gtk_vu_expose (GtkWidget * widget, GdkEventExpose * event);
44
static GtkWidgetClass *parent_class = NULL;
47
gtk_vu_get_type (void)
49
static GtkType vu_type = 0;
53
GtkTypeInfo vu_info = {
57
(GtkClassInitFunc) gtk_vu_class_init,
58
(GtkObjectInitFunc) gtk_vu_init,
63
vu_type = gtk_type_unique (gtk_widget_get_type (), &vu_info);
70
gtk_vu_class_init (GtkVUClass * gvclass)
72
GtkObjectClass *object_class;
73
GtkWidgetClass *widget_class;
75
object_class = (GtkObjectClass *) gvclass;
76
widget_class = (GtkWidgetClass *) gvclass;
78
parent_class = GTK_WIDGET_CLASS (gtk_type_class (gtk_widget_get_type ()));
80
object_class->destroy = gtk_vu_destroy;
82
widget_class->realize = gtk_vu_realize;
83
widget_class->unrealize = gtk_vu_unrealize;
84
widget_class->expose_event = gtk_vu_expose;
85
widget_class->size_request = gtk_vu_size_request;
86
widget_class->size_allocate = gtk_vu_size_allocate;
90
gtk_vu_init (GtkVU * vu)
100
vu = GTK_VU (gtk_type_new (gtk_vu_get_type ()));
102
return GTK_WIDGET (vu);
106
gtk_vu_destroy (GtkObject * object)
110
g_return_if_fail (object != NULL);
111
g_return_if_fail (GTK_IS_VU (object));
113
/* vu = GTK_VU (object); */
115
if (GTK_OBJECT_CLASS (parent_class)->destroy)
116
(*GTK_OBJECT_CLASS (parent_class)->destroy) (object);
120
gtk_vu_realize (GtkWidget * widget)
123
GdkWindowAttr attributes;
124
gint attributes_mask;
125
gboolean alloc_success[7];
127
g_return_if_fail (widget != NULL);
128
g_return_if_fail (GTK_IS_VU (widget));
130
GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
131
vu = GTK_VU (widget);
133
attributes.x = widget->allocation.x;
134
attributes.y = widget->allocation.y;
135
attributes.width = widget->allocation.width;
136
attributes.height = widget->allocation.height;
137
attributes.wclass = GDK_INPUT_OUTPUT;
138
attributes.window_type = GDK_WINDOW_CHILD;
139
attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
140
attributes.visual = gtk_widget_get_visual (widget);
141
attributes.colormap = gtk_widget_get_colormap (widget);
143
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
145
gdk_window_new (widget->parent->window, &attributes, attributes_mask);
147
widget->style = gtk_style_attach (widget->style, widget->window);
149
gdk_window_set_user_data (widget->window, widget);
153
vu->colors[0].red = 0x0000;
154
vu->colors[0].green = 0x30FF;
155
vu->colors[0].blue = 0x0000;
159
vu->colors[1].red = 0x0000;
160
vu->colors[1].green = 0xBFFF;
161
vu->colors[1].blue = 0x0000;
165
vu->colors[2].red = 0x30FF;
166
vu->colors[2].green = 0x30FF;
167
vu->colors[2].blue = 0x0000;
171
vu->colors[3].red = 0xBFFF;
172
vu->colors[3].green = 0xBFFF;
173
vu->colors[3].blue = 0x0000;
177
vu->colors[4].red = 0x30FF;
178
vu->colors[4].green = 0x0000;
179
vu->colors[4].blue = 0x0000;
183
vu->colors[5].red = 0xBFFF;
184
vu->colors[5].green = 0x0000;
185
vu->colors[5].blue = 0x0000;
189
vu->colors[6].red = 0x0000;
190
vu->colors[6].green = 0x0000;
191
vu->colors[6].blue = 0x0000;
193
gdk_colormap_alloc_colors (gtk_widget_get_colormap (widget), vu->colors, 7,
194
FALSE, TRUE, alloc_success);
195
vu->gc = gdk_gc_new (widget->window);
197
gdk_pixmap_new (widget->window, widget->allocation.width,
198
widget->allocation.height, -1);
200
/* gtk_style_set_background (widget->style, widget->window, GTK_STATE_ACTIVE); */
204
gtk_vu_unrealize (GtkWidget * widget)
207
g_return_if_fail (widget != NULL);
208
g_return_if_fail (GTK_IS_VU (widget));
210
GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
211
vu = GTK_VU (widget);
213
gdk_colormap_free_colors (gtk_widget_get_colormap (widget), vu->colors, 7);
214
gdk_pixmap_unref (vu->pixmap);
215
gdk_gc_unref (vu->gc);
216
gdk_window_unref (widget->window);
221
gtk_vu_size_request (GtkWidget * widget, GtkRequisition * requisition)
223
if (width_adjust <= 0)
224
requisition->width = 20;
226
requisition->width = 28;
227
requisition->height = 85;
231
gtk_vu_size_allocate (GtkWidget * widget, GtkAllocation * allocation)
235
g_return_if_fail (widget != NULL);
236
g_return_if_fail (GTK_IS_VU (widget));
237
g_return_if_fail (allocation != NULL);
239
widget->allocation = *allocation;
240
vu = GTK_VU (widget);
242
if (GTK_WIDGET_REALIZED (widget))
245
gdk_window_move_resize (widget->window,
246
allocation->x, allocation->y,
247
allocation->width, allocation->height);
248
gdk_pixmap_unref (vu->pixmap);
250
gdk_pixmap_new (widget->window, widget->allocation.width,
251
widget->allocation.height,
252
gdk_window_get_visual (widget->window)->depth);
257
gtk_vu_expose (GtkWidget * widget, GdkEventExpose * event)
262
g_return_val_if_fail (widget != NULL, FALSE);
263
g_return_val_if_fail (GTK_IS_VU (widget), FALSE);
264
g_return_val_if_fail (event != NULL, FALSE);
266
if (event->count > 0)
269
vu = GTK_VU (widget);
271
gdk_gc_set_foreground (vu->gc, &vu->colors[6]);
272
gdk_draw_rectangle (vu->pixmap, vu->gc, TRUE, 0, 0,
273
widget->allocation.width, widget->allocation.height);
274
/* gdk_window_clear_area (vu->pixmap,
276
widget->allocation.width,
277
widget->allocation.height); */
279
y_size = (widget->allocation.height - 50) / 8;
281
for (i = 0; i < 8; i++)
283
gdk_gc_set_foreground (vu->gc,
284
&vu->colors[((7 - i) / 3) * 2 +
285
(((8 - vu->level) > i) ? 0 : 1)]);
286
gdk_draw_rectangle (vu->pixmap, vu->gc, TRUE, VU_MARGIN,
287
(i * (y_size + 5)) + 10,
288
widget->allocation.width - VU_MARGIN * 2, y_size);
291
gdk_draw_pixmap (widget->window, vu->gc, vu->pixmap, 0, 0, 0, 0,
292
widget->allocation.width, widget->allocation.height);
297
gtk_vu_set_level (GtkVU * vu, guint new_level)
299
if (new_level != vu->level)
301
vu->level = new_level;
302
gtk_widget_queue_draw (GTK_WIDGET (vu));