~ubuntu-branches/ubuntu/oneiric/oss4/oneiric-proposed

« back to all changes in this revision

Viewing changes to cmd/ossxmix/gtkvu.c

  • Committer: Bazaar Package Importer
  • Author(s): Stefano Rivera
  • Date: 2011-06-16 20:37:48 UTC
  • mfrom: (5.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110616203748-jbrxik6ql33z54co
Tags: 4.2-build2004-1ubuntu1
* Merge from Debian unstable.
  - Supports our current kernel (LP: #746048)
  Remaining changes:
  - debian/oss4-dkms.dkms.in: s/source/build/ in Kernel headers paths.
* ld-as-needed.patch: Re-order CC arguments to enable building with ld
  --as-needed (LP: #770972)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 * This file is part of Open Sound System.
 
4
 *
 
5
 * Copyright (C) 4Front Technologies 1996-2008.
 
6
 *
 
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.
 
10
 *
 
11
 */
 
12
 
 
13
#ifdef __hpux
 
14
#define G_INLINE_FUNC
 
15
#endif
 
16
 
 
17
#include <stdio.h>
 
18
#include <gtk/gtkmain.h>
 
19
#include <gtk/gtksignal.h>
 
20
 
 
21
#include "gtkvu.h"
 
22
 
 
23
extern int width_adjust;
 
24
 
 
25
#define SCROLL_DELAY_LENGTH  300
 
26
#define VU_DEFAULT_SIZE 100
 
27
#define VU_MARGIN       (widget->allocation.width/3)
 
28
 
 
29
/* Forward declarations */
 
30
 
 
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);
 
41
 
 
42
/* Local data */
 
43
 
 
44
static GtkWidgetClass *parent_class = NULL;
 
45
 
 
46
GtkType
 
47
gtk_vu_get_type (void)
 
48
{
 
49
  static GtkType vu_type = 0;
 
50
 
 
51
  if (!vu_type)
 
52
    {
 
53
      GtkTypeInfo vu_info = {
 
54
        "GtkVU",
 
55
        sizeof (GtkVU),
 
56
        sizeof (GtkVUClass),
 
57
        (GtkClassInitFunc) gtk_vu_class_init,
 
58
        (GtkObjectInitFunc) gtk_vu_init,
 
59
        NULL,
 
60
        NULL,
 
61
      };
 
62
 
 
63
      vu_type = gtk_type_unique (gtk_widget_get_type (), &vu_info);
 
64
    }
 
65
 
 
66
  return vu_type;
 
67
}
 
68
 
 
69
static void
 
70
gtk_vu_class_init (GtkVUClass * gvclass)
 
71
{
 
72
  GtkObjectClass *object_class;
 
73
  GtkWidgetClass *widget_class;
 
74
 
 
75
  object_class = (GtkObjectClass *) gvclass;
 
76
  widget_class = (GtkWidgetClass *) gvclass;
 
77
 
 
78
  parent_class = GTK_WIDGET_CLASS (gtk_type_class (gtk_widget_get_type ()));
 
79
 
 
80
  object_class->destroy = gtk_vu_destroy;
 
81
 
 
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;
 
87
}
 
88
 
 
89
static void
 
90
gtk_vu_init (GtkVU * vu)
 
91
{
 
92
  vu->level = 0;
 
93
}
 
94
 
 
95
GtkWidget *
 
96
gtk_vu_new (void)
 
97
{
 
98
  GtkVU *vu;
 
99
 
 
100
  vu = GTK_VU (gtk_type_new (gtk_vu_get_type ()));
 
101
 
 
102
  return GTK_WIDGET (vu);
 
103
}
 
104
 
 
105
static void
 
106
gtk_vu_destroy (GtkObject * object)
 
107
{
 
108
  /* GtkVU *vu; */
 
109
 
 
110
  g_return_if_fail (object != NULL);
 
111
  g_return_if_fail (GTK_IS_VU (object));
 
112
 
 
113
  /* vu = GTK_VU (object); */
 
114
 
 
115
  if (GTK_OBJECT_CLASS (parent_class)->destroy)
 
116
    (*GTK_OBJECT_CLASS (parent_class)->destroy) (object);
 
117
}
 
118
 
 
119
static void
 
120
gtk_vu_realize (GtkWidget * widget)
 
121
{
 
122
  GtkVU *vu;
 
123
  GdkWindowAttr attributes;
 
124
  gint attributes_mask;
 
125
  gboolean alloc_success[7];
 
126
 
 
127
  g_return_if_fail (widget != NULL);
 
128
  g_return_if_fail (GTK_IS_VU (widget));
 
129
 
 
130
  GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
 
131
  vu = GTK_VU (widget);
 
132
 
 
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);
 
142
 
 
143
  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
 
144
  widget->window =
 
145
    gdk_window_new (widget->parent->window, &attributes, attributes_mask);
 
146
 
 
147
  widget->style = gtk_style_attach (widget->style, widget->window);
 
148
 
 
149
  gdk_window_set_user_data (widget->window, widget);
 
150
 
 
151
  /* Dark green */
 
152
 
 
153
  vu->colors[0].red = 0x0000;
 
154
  vu->colors[0].green = 0x30FF;
 
155
  vu->colors[0].blue = 0x0000;
 
156
 
 
157
  /* Green */
 
158
 
 
159
  vu->colors[1].red = 0x0000;
 
160
  vu->colors[1].green = 0xBFFF;
 
161
  vu->colors[1].blue = 0x0000;
 
162
 
 
163
  /* Dark Orange */
 
164
 
 
165
  vu->colors[2].red = 0x30FF;
 
166
  vu->colors[2].green = 0x30FF;
 
167
  vu->colors[2].blue = 0x0000;
 
168
 
 
169
  /* Orange */
 
170
 
 
171
  vu->colors[3].red = 0xBFFF;
 
172
  vu->colors[3].green = 0xBFFF;
 
173
  vu->colors[3].blue = 0x0000;
 
174
 
 
175
  /* Dark Red */
 
176
 
 
177
  vu->colors[4].red = 0x30FF;
 
178
  vu->colors[4].green = 0x0000;
 
179
  vu->colors[4].blue = 0x0000;
 
180
 
 
181
  /* Red */
 
182
 
 
183
  vu->colors[5].red = 0xBFFF;
 
184
  vu->colors[5].green = 0x0000;
 
185
  vu->colors[5].blue = 0x0000;
 
186
 
 
187
  /* Black */
 
188
 
 
189
  vu->colors[6].red = 0x0000;
 
190
  vu->colors[6].green = 0x0000;
 
191
  vu->colors[6].blue = 0x0000;
 
192
 
 
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);
 
196
  vu->pixmap =
 
197
    gdk_pixmap_new (widget->window, widget->allocation.width,
 
198
                    widget->allocation.height, -1);
 
199
 
 
200
  /*  gtk_style_set_background (widget->style, widget->window, GTK_STATE_ACTIVE); */
 
201
}
 
202
 
 
203
static void
 
204
gtk_vu_unrealize (GtkWidget * widget)
 
205
{
 
206
  GtkVU *vu;
 
207
  g_return_if_fail (widget != NULL);
 
208
  g_return_if_fail (GTK_IS_VU (widget));
 
209
 
 
210
  GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
 
211
  vu = GTK_VU (widget);
 
212
 
 
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);
 
217
}
 
218
 
 
219
/*ARGSUSED*/
 
220
static void
 
221
gtk_vu_size_request (GtkWidget * widget, GtkRequisition * requisition)
 
222
{
 
223
  if (width_adjust <= 0)
 
224
    requisition->width = 20;
 
225
  else
 
226
    requisition->width = 28;
 
227
  requisition->height = 85;
 
228
}
 
229
 
 
230
static void
 
231
gtk_vu_size_allocate (GtkWidget * widget, GtkAllocation * allocation)
 
232
{
 
233
  GtkVU *vu;
 
234
 
 
235
  g_return_if_fail (widget != NULL);
 
236
  g_return_if_fail (GTK_IS_VU (widget));
 
237
  g_return_if_fail (allocation != NULL);
 
238
 
 
239
  widget->allocation = *allocation;
 
240
  vu = GTK_VU (widget);
 
241
 
 
242
  if (GTK_WIDGET_REALIZED (widget))
 
243
    {
 
244
 
 
245
      gdk_window_move_resize (widget->window,
 
246
                              allocation->x, allocation->y,
 
247
                              allocation->width, allocation->height);
 
248
      gdk_pixmap_unref (vu->pixmap);
 
249
      vu->pixmap =
 
250
        gdk_pixmap_new (widget->window, widget->allocation.width,
 
251
                        widget->allocation.height,
 
252
                        gdk_window_get_visual (widget->window)->depth);
 
253
    }
 
254
}
 
255
 
 
256
static gint
 
257
gtk_vu_expose (GtkWidget * widget, GdkEventExpose * event)
 
258
{
 
259
  GtkVU *vu;
 
260
  guint i, y_size;
 
261
 
 
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);
 
265
 
 
266
  if (event->count > 0)
 
267
    return FALSE;
 
268
 
 
269
  vu = GTK_VU (widget);
 
270
 
 
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,
 
275
     0, 0,
 
276
     widget->allocation.width,
 
277
     widget->allocation.height); */
 
278
 
 
279
  y_size = (widget->allocation.height - 50) / 8;
 
280
 
 
281
  for (i = 0; i < 8; i++)
 
282
    {
 
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);
 
289
    }
 
290
 
 
291
  gdk_draw_pixmap (widget->window, vu->gc, vu->pixmap, 0, 0, 0, 0,
 
292
                   widget->allocation.width, widget->allocation.height);
 
293
  return FALSE;
 
294
}
 
295
 
 
296
void
 
297
gtk_vu_set_level (GtkVU * vu, guint new_level)
 
298
{
 
299
  if (new_level != vu->level)
 
300
    {
 
301
      vu->level = new_level;
 
302
      gtk_widget_queue_draw (GTK_WIDGET (vu));
 
303
    }
 
304
}