📄 gtkcolorsel.c
字号:
gtk_widget_hide (colorsel->opacity_label); gtk_widget_hide (colorsel->scales[OPACITY]); gtk_widget_hide (colorsel->entries[OPACITY]); } else if (use_opacity && !GTK_WIDGET_VISIBLE (colorsel->scales[OPACITY])) { gtk_widget_show (colorsel->opacity_label); gtk_widget_show (colorsel->scales[OPACITY]); gtk_widget_show (colorsel->entries[OPACITY]); } if (GTK_WIDGET_DRAWABLE (colorsel->sample_area)) gtk_color_selection_draw_sample (colorsel, FALSE);}static voidgtk_color_selection_value_resize (GtkWidget *widget, gpointer data){ GtkColorSelection *colorsel; colorsel = (GtkColorSelection*) gtk_object_get_data (GTK_OBJECT (widget), "_GtkColorSelection"); gtk_color_selection_draw_value_bar (colorsel, TRUE);}static voidgtk_color_selection_wheel_resize (GtkWidget *widget, gpointer data){ GtkColorSelection *colorsel; colorsel = (GtkColorSelection*) gtk_object_get_data (GTK_OBJECT (widget), "_GtkColorSelection"); gtk_color_selection_draw_wheel (colorsel, TRUE);}static voidgtk_color_selection_sample_resize (GtkWidget *widget, gpointer data){ GtkColorSelection *colorsel; colorsel = (GtkColorSelection*) gtk_object_get_data (GTK_OBJECT (widget), "_GtkColorSelection"); gtk_color_selection_draw_sample (colorsel, TRUE);}static voidgtk_color_selection_drag_begin (GtkWidget *widget, GdkDragContext *context, gpointer data){ GtkColorSelection *colorsel = data; GtkWidget *window; gdouble colors[4]; GdkColor bg; window = gtk_window_new (GTK_WINDOW_POPUP); gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE); gtk_widget_set_usize (window, 48, 32); gtk_widget_realize (window); gtk_object_set_data_full (GTK_OBJECT (widget), "gtk-color-selection-drag-window", window, (GtkDestroyNotify) gtk_widget_destroy); gtk_color_selection_get_color (colorsel, colors); bg.red = 0xffff * colors[0]; bg.green = 0xffff * colors[1]; bg.blue = 0xffff * colors[2]; gdk_color_alloc (gtk_widget_get_colormap (window), &bg); gdk_window_set_background (window->window, &bg); gtk_drag_set_icon_widget (context, window, -2, -2);}static voidgtk_color_selection_drag_end (GtkWidget *widget, GdkDragContext *context, gpointer data){ gtk_object_set_data (GTK_OBJECT (widget), "gtk-color-selection-drag-window", NULL);}static voidgtk_color_selection_drop_handle (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint info, guint time, gpointer data){ GtkColorSelection *colorsel = data; guint16 *vals; gdouble colors[4]; /* This is currently a guint16 array of the format: R G B opacity */ if (selection_data->length < 0) return; if ((selection_data->format != 16) || (selection_data->length != 8)) { g_warning ("Received invalid color data\n"); return; } vals = (guint16 *)selection_data->data; colors[0] = (gdouble)vals[0] / 0xffff; colors[1] = (gdouble)vals[1] / 0xffff; colors[2] = (gdouble)vals[2] / 0xffff; colors[3] = (gdouble)vals[3] / 0xffff; gtk_color_selection_set_color(colorsel, colors);}static voidgtk_color_selection_drag_handle (GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data, guint info, guint time, gpointer data){ GtkColorSelection *colorsel = data; guint16 vals[4]; gdouble colors[4]; gtk_color_selection_get_color(colorsel, colors); vals[0] = colors[0] * 0xffff; vals[1] = colors[1] * 0xffff; vals[2] = colors[2] * 0xffff; vals[3] = colorsel->use_opacity ? colors[3] * 0xffff : 0xffff; gtk_selection_data_set (selection_data, gdk_atom_intern ("application/x-color", FALSE), 16, (guchar *)vals, 8);}static voidgtk_color_selection_draw_wheel_marker (GtkColorSelection *colorsel){ gint xpos, ypos; gdk_gc_set_function (colorsel->wheel_gc, GDK_INVERT); xpos = (gint) ((-(gdouble) (colorsel->wheel_area->allocation.width) / 2.0) * colorsel->values[SATURATION] * cos (DEGTORAD ((colorsel->values[HUE] - 90)))) + (colorsel->wheel_area->allocation.width >> 1) - 4; ypos = (gint) (((gdouble) (colorsel->wheel_area->allocation.height) / 2.0) * colorsel->values[SATURATION] * sin (DEGTORAD ((colorsel->values[HUE] - 90)))) + (colorsel->wheel_area->allocation.height >> 1) - 4; gdk_draw_arc (colorsel->wheel_area->window, colorsel->wheel_gc, FALSE, xpos, ypos, 8, 8, 0, 360 * 64);}static voidgtk_color_selection_draw_value_marker (GtkColorSelection *colorsel){ gint y; gdk_gc_set_function (colorsel->value_gc, GDK_INVERT); y = (gint) ((gdouble) (colorsel->value_area->allocation.height) * (1.0 - colorsel->values[VALUE])); gdk_draw_line (colorsel->value_area->window, colorsel->value_gc, 0, y, colorsel->value_area->allocation.width, y);}static voidgtk_color_selection_update_value (GtkColorSelection *colorsel, gint y){ gtk_color_selection_draw_value_marker (colorsel); if (y < 0) y = 0; else if (y > colorsel->value_area->allocation.height - 1) y = colorsel->value_area->allocation.height - 1; colorsel->values[VALUE] = 1.0 - (gdouble) y / (gdouble) (colorsel->value_area->allocation.height); HSV_TO_RGB (); gtk_color_selection_draw_value_marker (colorsel); gtk_color_selection_draw_sample (colorsel, FALSE); gtk_color_selection_update_input (colorsel->scales[VALUE], colorsel->entries[VALUE], colorsel->values[VALUE]); gtk_color_selection_update_inputs (colorsel, RGB_INPUTS, BOTH);}static voidgtk_color_selection_update_wheel (GtkColorSelection *colorsel, gint x, gint y){ gdouble wid, heig; gint res; gtk_color_selection_draw_wheel_marker (colorsel); wid = (gdouble) (colorsel->wheel_area->allocation.width) / 2.0; heig = (gdouble) (colorsel->wheel_area->allocation.height) / 2.0; res = gtk_color_selection_eval_wheel (x, y, wid, heig, &colorsel->values[HUE], &colorsel->values[SATURATION]); HSV_TO_RGB (); gtk_color_selection_draw_wheel_marker (colorsel); gtk_color_selection_draw_value_bar (colorsel, FALSE); gtk_color_selection_draw_sample (colorsel, FALSE); gtk_color_selection_update_inputs (colorsel, RGB_INPUTS | HSV_INPUTS, BOTH);}static gintgtk_color_selection_value_timeout (GtkColorSelection *colorsel){ gint x, y; GDK_THREADS_ENTER (); gdk_window_get_pointer (colorsel->value_area->window, &x, &y, NULL); gtk_color_selection_update_value (colorsel, y); gtk_color_selection_color_changed (colorsel); GDK_THREADS_LEAVE (); return (TRUE);}static gintgtk_color_selection_value_events (GtkWidget *area, GdkEvent *event){ GtkColorSelection *colorsel; gint y; colorsel = (GtkColorSelection*) gtk_object_get_data (GTK_OBJECT (area), "_GtkColorSelection"); if (colorsel->value_gc == NULL) colorsel->value_gc = gdk_gc_new (colorsel->value_area->window); switch (event->type) { case GDK_MAP: gtk_color_selection_draw_value_bar (colorsel, FALSE); gtk_color_selection_draw_value_marker (colorsel); break; case GDK_EXPOSE: gtk_color_selection_draw_value_marker (colorsel); break; case GDK_BUTTON_PRESS: gtk_grab_add (area); gtk_color_selection_update_value (colorsel, event->button.y); gtk_color_selection_color_changed (colorsel); break; case GDK_BUTTON_RELEASE: gtk_grab_remove (area); if (colorsel->timer_active) gtk_timeout_remove (colorsel->timer_tag); colorsel->timer_active = FALSE; y = event->button.y; if (event->button.window != area->window) gdk_window_get_pointer (area->window, NULL, &y, NULL); gtk_color_selection_update_value (colorsel, y); gtk_color_selection_color_changed (colorsel); break; case GDK_MOTION_NOTIFY: /* Even though we select BUTTON_MOTION_MASK, we seem to need * to occasionally get events without buttons pressed. */ if (!(event->motion.state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK))) return FALSE; y = event->motion.y; if (event->motion.is_hint || (event->motion.window != area->window)) gdk_window_get_pointer (area->window, NULL, &y, NULL); switch (colorsel->policy) { case GTK_UPDATE_CONTINUOUS: gtk_color_selection_update_value (colorsel, y); gtk_color_selection_color_changed (colorsel); break; case GTK_UPDATE_DELAYED: if (colorsel->timer_active) gtk_timeout_remove (colorsel->timer_tag); colorsel->timer_tag = gtk_timeout_add (TIMER_DELAY, (GtkFunction) gtk_color_selection_value_timeout, (gpointer) colorsel); colorsel->timer_active = TRUE; break; default: break; } break; default: break; } return (FALSE);}static gintgtk_color_selection_wheel_timeout (GtkColorSelection *colorsel){ gint x, y; GDK_THREADS_ENTER (); gdk_window_get_pointer (colorsel->wheel_area->window, &x, &y, NULL); gtk_color_selection_update_wheel (colorsel, x, y); gtk_color_selection_color_changed (colorsel); GDK_THREADS_LEAVE (); return (TRUE);}static gintgtk_color_selection_wheel_events (GtkWidget *area, GdkEvent *event){ GtkColorSelection *colorsel; gint x, y; colorsel = (GtkColorSelection*) gtk_object_get_data (GTK_OBJECT (area), "_GtkColorSelection"); if (colorsel->wheel_gc == NULL) colorsel->wheel_gc = gdk_gc_new (colorsel->wheel_area->window); if (colorsel->sample_gc == NULL) colorsel->sample_gc = gdk_gc_new (colorsel->sample_area->window); if (colorsel->value_gc == NULL) colorsel->value_gc = gdk_gc_new (colorsel->value_area->window); switch (event->type) { case GDK_MAP: gtk_color_selection_draw_wheel (colorsel, TRUE); gtk_color_selection_draw_wheel_marker (colorsel); gtk_color_selection_draw_sample (colorsel, TRUE); break; case GDK_EXPOSE: gtk_color_selection_draw_wheel_marker (colorsel); gtk_color_selection_draw_wheel_frame (colorsel); break; case GDK_BUTTON_PRESS: gtk_grab_add (area); gtk_color_selection_update_wheel (colorsel, event->button.x, event->button.y); gtk_color_selection_color_changed (colorsel); break; case GDK_BUTTON_RELEASE: gtk_grab_remove (area); if (colorsel->timer_active) gtk_timeout_remove (colorsel->timer_tag); colorsel->timer_active = FALSE; x = event->button.x; y = event->button.y; if (event->button.window != area->window) gdk_window_get_pointer (area->window, &x, &y, NULL); gtk_color_selection_update_wheel (colorsel, x, y); gtk_color_selection_color_changed (colorsel); break; case GDK_MOTION_NOTIFY: /* Even though we select BUTTON_MOTION_MASK, we seem to need * to occasionally get events without buttons pressed. */ if (!(event->motion.state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK))) return FALSE; x = event->motion.x; y = event->motion.y; if (event->motion.is_hint || (event->motion.window != area->window)) gdk_window_get_pointer (area->window, &x, &y, NULL); switch (colorsel->policy) { case GTK_UPDATE_CONTINUOUS: gtk_color_selection_update_wheel (colorsel, x, y); gtk_color_selection_color_changed (colorsel); break; case GTK_UPDATE_DELAYED: if (colorsel->timer_active) gtk_timeout_remove (colorsel->timer_tag); colorsel->timer_tag = gtk_timeout_add (TIMER_DELAY, (GtkFunction) gtk_color_selection_wheel_timeout, (gpointer) colorsel); colorsel->timer_active = TRUE; break; default: break; } break; default: break; } return (FALSE);}static voidgtk_color_selection_draw_value_bar (GtkColorSelection *colorsel, gint resize){ gint x, y, wid, heig, n; gdouble sv, v; wid = colorsel->value_area->allocation.width; heig = colorsel->value_area->allocation.height; if (resize || !colorsel->value_buf) { g_free (colorsel->value_buf); colorsel->value_buf = g_new0 (guchar, 3 * wid); } v = 1.0; sv = 1.0 / (gdouble) MAX (heig - 1, 0); for (y = 0; y < heig; y++) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -