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 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
/* ghostess - A GUI host for DSSI plugins.
*
* Much of this code comes from aube 0.30.2, copyright (c) 2002
* Conrad Parker, with modifications by Sean Bolton,
* copyright (c) 2006, 2012.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*/
#include <gtk/gtkmain.h>
#include <gtk/gtksignal.h>
#include "eyecandy.h"
#define BLINKY_DEFAULT_WIDTH 4
#define BLINKY_DEFAULT_HEIGHT 16
/* ==== Blinky ==== */
/* Forward declarations */
static void blinky_class_init(BlinkyClass * class);
static void blinky_init(Blinky * blinky);
static void blinky_destroy(GtkObject * object);
static void blinky_realize(GtkWidget * widget);
static gint blinky_expose(GtkWidget * widget, GdkEventExpose * event);
static void blinky_size_request(GtkWidget * widget, GtkRequisition * requisition);
static void blinky_size_allocate(GtkWidget * widget, GtkAllocation * allocation);
static void blinky_update(Blinky * blinky);
/* Local data */
static GdkColor col_darkgreen, col_green;
static GtkStyle *blinky_style = NULL;
G_DEFINE_TYPE(Blinky, blinky, GTK_TYPE_WIDGET);
static void
blinky_class_init(BlinkyClass * class)
{
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
object_class = (GtkObjectClass *) class;
widget_class = (GtkWidgetClass *) class;
blinky_parent_class = gtk_type_class(gtk_widget_get_type());
object_class->destroy = blinky_destroy;
widget_class->realize = blinky_realize;
widget_class->expose_event = blinky_expose;
widget_class->size_request = blinky_size_request;
widget_class->size_allocate = blinky_size_allocate;
col_green.red = 0;
col_green.green = 0xFFFF;
col_green.blue = 0;
gdk_color_alloc(gdk_colormap_get_system(), &col_green);
col_darkgreen.red = 0;
col_darkgreen.green = 0x5555;
col_darkgreen.blue = 0;
gdk_color_alloc(gdk_colormap_get_system(), &col_darkgreen);
}
static void
blinky_init(Blinky * blinky)
{
blinky->state = 0;
}
GtkWidget *
blinky_new(guint state)
{
Blinky *blinky = g_object_new (TYPE_BLINKY, NULL);
blinky_set_state(blinky, state);
return GTK_WIDGET(blinky);
}
static void
blinky_destroy(GtkObject * object)
{
Blinky *blinky;
g_return_if_fail(object != NULL);
g_return_if_fail(IS_BLINKY(object));
blinky = BLINKY(object);
/* unref contained widgets */
if (GTK_OBJECT_CLASS(blinky_parent_class)->destroy)
(*GTK_OBJECT_CLASS(blinky_parent_class)->destroy) (object);
}
guint
blinky_get_state(Blinky * blinky)
{
g_return_val_if_fail(blinky != NULL, 0);
g_return_val_if_fail(IS_BLINKY(blinky), 0);
return blinky->state;
}
void
blinky_set_state(Blinky * blinky, guint state)
{
g_return_if_fail(blinky != NULL);
g_return_if_fail(IS_BLINKY(blinky));
blinky->state = state;
blinky_update(blinky);
}
static void
blinky_realize(GtkWidget * widget)
{
Blinky *blinky;
GdkWindowAttr attributes;
gint attributes_mask;
g_return_if_fail(widget != NULL);
g_return_if_fail(IS_BLINKY(widget));
GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
blinky = BLINKY(widget);
attributes.x = widget->allocation.x;
attributes.y = widget->allocation.y;
attributes.width = widget->allocation.width;
attributes.height = widget->allocation.height;
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.window_type = GDK_WINDOW_CHILD;
attributes.event_mask = gtk_widget_get_events(widget) |
GDK_EXPOSURE_MASK;
attributes.visual = gtk_widget_get_visual(widget);
attributes.colormap = gtk_widget_get_colormap(widget);
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
widget->window = gdk_window_new(widget->parent->window, &attributes,
attributes_mask);
widget->style = gtk_style_attach(widget->style, widget->window);
gdk_window_set_user_data(widget->window, widget);
gtk_style_set_background(widget->style, widget->window, GTK_STATE_ACTIVE);
}
static void
blinky_size_request(GtkWidget * widget, GtkRequisition * requisition)
{
requisition->width = BLINKY_DEFAULT_WIDTH;
requisition->height = BLINKY_DEFAULT_HEIGHT;
}
static void
blinky_size_allocate(GtkWidget * widget, GtkAllocation * allocation)
{
Blinky *blinky;
g_return_if_fail(widget != NULL);
g_return_if_fail(IS_BLINKY(widget));
g_return_if_fail(allocation != NULL);
widget->allocation = *allocation;
if (GTK_WIDGET_REALIZED(widget)) {
blinky = BLINKY(widget);
gdk_window_move_resize(widget->window,
allocation->x, allocation->y, allocation->width, allocation->height);
}
}
static gint
blinky_expose(GtkWidget * widget, GdkEventExpose * event)
{
gdk_window_clear_area(widget->window, 0, 0,
widget->allocation.width, widget->allocation.height); // !FIX! clear to black?
if (!blinky_style) {
blinky_style = gtk_style_new();
blinky_style->fg_gc[GTK_STATE_NORMAL] =
gdk_gc_new(widget->window);
}
if (BLINKY(widget)->state)
gdk_gc_set_foreground(blinky_style->fg_gc[GTK_STATE_NORMAL], &col_green);
else
gdk_gc_set_foreground(blinky_style->fg_gc[GTK_STATE_NORMAL], &col_darkgreen);
gdk_draw_rectangle(widget->window, blinky_style->fg_gc[widget->state],
TRUE, 0, 0,
widget->allocation.width, widget->allocation.height
);
return FALSE;
}
static void
blinky_update(Blinky * blinky)
{
gtk_widget_draw(GTK_WIDGET(blinky), NULL);
}
|