2
* nvidia-settings: A tool for configuring the NVIDIA X driver on Unix
5
* Copyright (C) 2004 NVIDIA Corporation.
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of Version 2 of the GNU General Public
9
* License as published by the Free Software Foundation.
11
* This program is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See Version 2
14
* of the GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the:
19
* Free Software Foundation, Inc.
20
* 59 Temple Place - Suite 330
21
* Boston, MA 02111-1307, USA
27
#include "NvCtrlAttributes.h"
32
#define REQUESTED_WIDTH 94
33
#define REQUESTED_HEIGHT 94
36
ctk_curve_class_init (CtkCurveClass *);
39
ctk_curve_finalize (GObject *);
42
ctk_curve_expose_event (GtkWidget *, GdkEventExpose *);
45
ctk_curve_size_request (GtkWidget *, GtkRequisition *);
48
ctk_curve_configure_event(GtkWidget *, GdkEventConfigure *);
51
plot_color_ramp (GdkPixmap *, GdkGC *, gushort *, gint, gint, gint);
54
static void draw(CtkCurve *ctk_curve);
56
static GObjectClass *parent_class;
59
GType ctk_curve_get_type(
63
static GType ctk_curve_type = 0;
65
if (!ctk_curve_type) {
66
static const GTypeInfo ctk_curve_info = {
67
sizeof (CtkCurveClass),
69
NULL, /* base_finalize */
70
(GClassInitFunc) ctk_curve_class_init,
71
NULL, /* class_finalize */
72
NULL, /* class_data */
75
NULL, /* instance_init */
78
ctk_curve_type = g_type_register_static (GTK_TYPE_DRAWING_AREA,
79
"CtkCurve", &ctk_curve_info, 0);
82
return ctk_curve_type;
85
static void ctk_curve_class_init(
86
CtkCurveClass *ctk_curve_class
89
GObjectClass *gobject_class;
90
GtkWidgetClass *widget_class;
92
widget_class = (GtkWidgetClass *) ctk_curve_class;
93
gobject_class = (GObjectClass *) ctk_curve_class;
95
parent_class = g_type_class_peek_parent(ctk_curve_class);
97
gobject_class->finalize = ctk_curve_finalize;
99
widget_class->expose_event = ctk_curve_expose_event;
100
widget_class->size_request = ctk_curve_size_request;
101
widget_class->configure_event = ctk_curve_configure_event;
106
static void ctk_curve_finalize(
111
GdkColormap *gdk_colormap;
114
ctk_curve = CTK_CURVE(object);
116
gdk_colormap = ctk_curve->gdk_colormap;
118
gdk_color = &ctk_curve->gdk_color_red;
119
gdk_colormap_free_colors(gdk_colormap, gdk_color, 1);
121
gdk_color = &ctk_curve->gdk_color_green;
122
gdk_colormap_free_colors(gdk_colormap, gdk_color, 1);
124
gdk_color = &ctk_curve->gdk_color_blue;
125
gdk_colormap_free_colors(gdk_colormap, gdk_color, 1);
127
g_object_unref(gdk_colormap);
130
static gboolean ctk_curve_expose_event(
132
GdkEventExpose *event
138
ctk_curve = CTK_CURVE(widget);
140
width = widget->allocation.width - 2 * widget->style->xthickness;
141
height = widget->allocation.height - 2 * widget->style->ythickness;
143
gtk_paint_shadow(widget->style, widget->window,
144
GTK_STATE_NORMAL, GTK_SHADOW_IN,
145
&event->area, widget, "ctk_curve", 0, 0,
146
widget->allocation.width, widget->allocation.height);
148
gdk_gc_set_function(ctk_curve->gdk_gc, GDK_COPY);
150
gdk_draw_drawable(widget->window, ctk_curve->gdk_gc, ctk_curve->gdk_pixmap,
151
0, 0, widget->style->xthickness,
152
widget->style->ythickness,
157
static gboolean ctk_curve_configure_event
160
GdkEventConfigure *event
163
CtkCurve *ctk_curve = CTK_CURVE(widget);
165
ctk_curve->width = event->width;
166
ctk_curve->height = event->height;
168
if (ctk_curve->gdk_pixmap) g_object_unref(ctk_curve->gdk_pixmap);
169
if (ctk_curve->gdk_gc) g_object_unref(ctk_curve->gdk_gc);
171
ctk_curve->gdk_pixmap = gdk_pixmap_new(widget->window, ctk_curve->width,
172
ctk_curve->height, -1);
173
ctk_curve->gdk_gc = gdk_gc_new(ctk_curve->gdk_pixmap);
181
static void plot_color_ramp(
182
GdkPixmap *gdk_pixmap,
185
gint n_color_ramp_entries,
191
GdkPoint *gdk_points;
194
gdk_points = g_malloc(width * sizeof(GdkPoint));
197
dx = (n_color_ramp_entries - 1.0) / (width - 1.0);
199
for (i = 0; i < width; i++, x += dx) {
200
y = (gfloat) color_ramp[(int) (x + 0.5)];
202
gdk_points[i].y = height - ((height - 1) * (y / 65535) + 0.5);
205
gdk_draw_lines(gdk_pixmap, gdk_gc, gdk_points, width);
210
static void ctk_curve_size_request(
212
GtkRequisition *requisition
215
requisition->width = REQUESTED_WIDTH;
216
requisition->height = REQUESTED_HEIGHT;
219
static void color_changed(
223
GdkRectangle rectangle;
225
rectangle.x = widget->style->xthickness;
226
rectangle.y = widget->style->ythickness;
228
rectangle.width = widget->allocation.width - 2 * rectangle.x;
229
rectangle.height = widget->allocation.height - 2 * rectangle.y;
231
if (GTK_WIDGET_DRAWABLE(widget)) {
232
draw(CTK_CURVE(widget)); /* only draw when visible */
233
gdk_window_invalidate_rect(widget->window, &rectangle, FALSE);
237
GtkWidget* ctk_curve_new(NvCtrlAttributeHandle *handle, GtkWidget *color)
241
GdkColormap *gdk_colormap;
244
object = g_object_new(CTK_TYPE_CURVE, NULL);
246
ctk_curve = CTK_CURVE(object);
248
ctk_curve->handle = handle;
249
ctk_curve->color = color;
251
ctk_curve->gdk_pixmap = NULL;
252
ctk_curve->gdk_gc = NULL;
254
ctk_curve->gdk_colormap = gdk_colormap = gdk_colormap_get_system();
256
gdk_color = &ctk_curve->gdk_color_red;
257
memset(gdk_color, 0, sizeof(GdkColor));
258
gdk_color->red = 65535;
259
gdk_colormap_alloc_color(gdk_colormap, gdk_color, FALSE, TRUE);
261
gdk_color = &ctk_curve->gdk_color_green;
262
memset(gdk_color, 0, sizeof(GdkColor));
263
gdk_color->green = 65535;
264
gdk_colormap_alloc_color(gdk_colormap, gdk_color, FALSE, TRUE);
266
gdk_color = &ctk_curve->gdk_color_blue;
267
memset(gdk_color, 0, sizeof(GdkColor));
268
gdk_color->blue = 65535;
269
gdk_colormap_alloc_color(gdk_colormap, gdk_color, FALSE, TRUE);
272
g_signal_connect_swapped(G_OBJECT(ctk_curve->color), "changed",
273
G_CALLBACK(color_changed), (gpointer) ctk_curve);
275
return GTK_WIDGET(object);
280
static void draw(CtkCurve *ctk_curve)
282
GtkWidget *widget = GTK_WIDGET(ctk_curve);
287
gdk_gc_set_function(ctk_curve->gdk_gc, GDK_COPY);
289
gdk_draw_rectangle(ctk_curve->gdk_pixmap, widget->style->black_gc,
290
TRUE, 0, 0, ctk_curve->width, ctk_curve->height);
292
gdk_gc_set_function(ctk_curve->gdk_gc, GDK_XOR);
294
gdk_gc_set_foreground(ctk_curve->gdk_gc, &ctk_curve->gdk_color_red);
295
NvCtrlGetColorRamp(ctk_curve->handle, RED_CHANNEL, &lut, &n_lut_entries);
296
plot_color_ramp(ctk_curve->gdk_pixmap, ctk_curve->gdk_gc,
297
lut, n_lut_entries, ctk_curve->width, ctk_curve->height);
299
gdk_gc_set_foreground(ctk_curve->gdk_gc, &ctk_curve->gdk_color_green);
300
NvCtrlGetColorRamp(ctk_curve->handle, GREEN_CHANNEL, &lut, &n_lut_entries);
301
plot_color_ramp(ctk_curve->gdk_pixmap, ctk_curve->gdk_gc,
302
lut, n_lut_entries, ctk_curve->width, ctk_curve->height);
304
gdk_gc_set_foreground(ctk_curve->gdk_gc, &ctk_curve->gdk_color_blue);
305
NvCtrlGetColorRamp(ctk_curve->handle, BLUE_CHANNEL, &lut, &n_lut_entries);
306
plot_color_ramp(ctk_curve->gdk_pixmap, ctk_curve->gdk_gc,
307
lut, n_lut_entries, ctk_curve->width, ctk_curve->height);