diff options
Diffstat (limited to 'eel/eel-gdk-extensions.c')
-rw-r--r-- | eel/eel-gdk-extensions.c | 310 |
1 files changed, 24 insertions, 286 deletions
diff --git a/eel/eel-gdk-extensions.c b/eel/eel-gdk-extensions.c index 86a8600e..ed694277 100644 --- a/eel/eel-gdk-extensions.c +++ b/eel/eel-gdk-extensions.c @@ -40,48 +40,6 @@ #define GRADIENT_BAND_SIZE 4 /** - * eel_gdk_rectangle_contains_rectangle: - * @outer: Rectangle possibly containing another rectangle. - * @inner: Rectangle that might be inside. - * - * Retun TRUE if inner rectangle is contained inside outer rectangle - */ -gboolean -eel_gdk_rectangle_contains_rectangle (GdkRectangle outer, GdkRectangle inner) -{ - return outer.x <= inner.x && outer.x + outer.width >= inner.x + inner.width - && outer.y <= inner.y && outer.y + outer.height >= inner.y + inner.height; -} - -/** - * eel_interpolate_color: - * @ratio: Place on line between colors to interpolate. - * @start_color: Color for one end. - * @end_color: Color for the other end - * @interpolated_color: Result. - * - * Compute a color between @start_color and @end_color in color space. - * Currently, the color space used is RGB, but a future version could - * instead do the interpolation in the best color space for expressing - * human perception. - */ -guint32 -eel_interpolate_color (gdouble ratio, - guint32 start_rgb, - guint32 end_rgb) -{ - guchar red, green, blue; - - g_return_val_if_fail (ratio >= 0.0, 0); - g_return_val_if_fail (ratio <= 1.0, 0); - - red = ((start_rgb >> 16) & 0xFF) * (1.0 - ratio) + ((end_rgb >> 16) & 0xFF) * ratio; - green = ((start_rgb >> 8) & 0xFF) * (1.0 - ratio) + ((end_rgb >> 8) & 0xFF) * ratio; - blue = (start_rgb & 0xFF) * (1.0 - ratio) + (end_rgb & 0xFF) * ratio; - return (((red << 8) | green) << 8) | blue; -} - -/** * eel_gradient_new * @start_color: Color for the top or left. * @end_color: Color for the bottom or right. @@ -387,26 +345,6 @@ eel_gdk_color_parse_with_white_default (const char *color_spec, } } -/** - * eel_parse_rgb_with_white_default - * @color_spec: A color spec, or NULL. - * Returns: An rgb value. - * - * The same as gdk_color_parse, except sets the color to white if - * the spec. can't be parsed instead of returning a boolean flag - * and returns a guint32 rgb value instead of a GdkColor. - */ -guint32 -eel_parse_rgb_with_white_default (const char *color_spec) -{ - GdkColor color; - - eel_gdk_color_parse_with_white_default (color_spec, &color); - return ((color.red << 8) & EEL_RGB_COLOR_RED) - | (color.green & EEL_RGB_COLOR_GREEN) - | ((color.blue >> 8) & EEL_RGB_COLOR_BLUE); -} - guint32 eel_rgb16_to_rgb (gushort r, gushort g, gushort b) { @@ -476,51 +414,6 @@ eel_gdk_rgb_to_color_spec (const guint32 color) return g_strdup_printf ("#%06X", (guint) (color & 0xFFFFFF)); } -static guint32 -eel_shift_color_component (guchar component, float shift_by) -{ - guint32 result; - if (shift_by > 1.0) - { - result = component * (2 - shift_by); - } - else - { - result = 0xff - shift_by * (0xff - component); - } - - return result & 0xff; -} - -/** - * eel_rgb_shift_color - * @color: A color. - * @shift_by: darken or lighten factor. - * Returns: An darkened or lightened rgb value. - * - * Darkens (@shift_by > 1) or lightens (@shift_by < 1) - * @color. - */ -guint32 -eel_rgb_shift_color (guint32 color, float shift_by) -{ - guint32 result; - - /* shift red by shift_by */ - result = eel_shift_color_component((color & 0x00ff0000) >> 16, shift_by); - result <<= 8; - /* shift green by shift_by */ - result |= eel_shift_color_component((color & 0x0000ff00) >> 8, shift_by); - result <<= 8; - /* shift blue by shift_by */ - result |= eel_shift_color_component((color & 0x000000ff), shift_by); - - /* alpha doesn't change */ - result |= (0xff000000 & color); - - return result; -} - /** * eel_gdk_color_is_dark: * @@ -538,169 +431,6 @@ eel_gdk_color_is_dark (GdkColor *color) return intensity < 128; } -/** - * eel_stipple_bitmap_for_screen: - * - * Get pointer to 50% stippled bitmap suitable for use - * on @screen. This is a global object; do not free. - */ -GdkBitmap * -eel_stipple_bitmap_for_screen (GdkScreen *screen) -{ - static char stipple_bits[] = { 0x02, 0x01 }; - static GPtrArray *stipples = NULL; - int screen_num, n_screens, i; - - if (stipples == NULL) - { - n_screens = gdk_display_get_n_screens ( - gdk_screen_get_display (screen)); - stipples = g_ptr_array_sized_new (n_screens); - - for (i = 0; i < n_screens; i++) - { - g_ptr_array_index (stipples, i) = NULL; - } - } - - screen_num = gdk_screen_get_number (screen); - - if (g_ptr_array_index (stipples, screen_num) == NULL) - { - g_ptr_array_index (stipples, screen_num) = - gdk_bitmap_create_from_data ( - gdk_screen_get_root_window (screen), - stipple_bits, 2, 2); - } - - return g_ptr_array_index (stipples, screen_num); -} - -/** - * eel_stipple_bitmap: - * - * Get pointer to 50% stippled bitmap suitable for use - * on the default screen. This is a global object; do - * not free. - * - * This method is not multiscreen safe. Do not use it. - */ -GdkBitmap * -eel_stipple_bitmap (void) -{ - return eel_stipple_bitmap_for_screen (gdk_screen_get_default ()); -} - -/** - * eel_gdk_window_bring_to_front: - * - * Raise window and give it focus. - */ -void -eel_gdk_window_bring_to_front (GdkWindow *window) -{ - /* This takes care of un-iconifying the window and - * raising it if needed. - */ - gdk_window_show (window); - - /* If the window was already showing, it would not have - * the focus at this point. Do a little X trickery to - * ensure it is focused. - */ - eel_gdk_window_focus (window, GDK_CURRENT_TIME); -} - -void -eel_gdk_window_focus (GdkWindow *window, guint32 timestamp) -{ - gdk_error_trap_push (); - XSetInputFocus (GDK_DISPLAY (), - GDK_WINDOW_XWINDOW (window), - RevertToParent, - timestamp); - gdk_flush(); - gdk_error_trap_pop (); -} - -void -eel_gdk_window_set_wm_protocols (GdkWindow *window, - GdkAtom *protocols, - int nprotocols) -{ - Atom *atoms; - int i; - - atoms = g_new (Atom, nprotocols); - for (i = 0; i < nprotocols; i++) - { - atoms[i] = gdk_x11_atom_to_xatom (protocols[i]); - } - - XSetWMProtocols (GDK_WINDOW_XDISPLAY (window), - GDK_WINDOW_XWINDOW (window), - atoms, nprotocols); - - g_free (atoms); -} - -/** - * eel_gdk_window_set_wm_hints_input: - * - * Set the WM_HINTS.input flag to the passed in value - */ -void -eel_gdk_window_set_wm_hints_input (GdkWindow *window, gboolean status) -{ - Display *dpy; - Window id; - XWMHints *wm_hints; - - g_return_if_fail (window != NULL); - - dpy = GDK_WINDOW_XDISPLAY (window); - id = GDK_WINDOW_XWINDOW (window); - - wm_hints = XGetWMHints (dpy, id); - if (wm_hints == 0) - { - wm_hints = XAllocWMHints (); - } - - wm_hints->flags |= InputHint; - wm_hints->input = (status == FALSE) ? False : True; - - XSetWMHints (dpy, id, wm_hints); - XFree (wm_hints); -} - -void -eel_gdk_window_set_invisible_cursor (GdkWindow *window) -{ - GdkBitmap *empty_bitmap; - GdkCursor *cursor; - GdkColor useless; - char invisible_cursor_bits[] = { 0x0 }; - - useless.red = useless.green = useless.blue = 0; - useless.pixel = 0; - - empty_bitmap = gdk_bitmap_create_from_data (window, - invisible_cursor_bits, - 1, 1); - - cursor = gdk_cursor_new_from_pixmap (empty_bitmap, - empty_bitmap, - &useless, - &useless, 0, 0); - - gdk_window_set_cursor (window, cursor); - - gdk_cursor_unref (cursor); - - g_object_unref (empty_bitmap); -} - EelGdkGeometryFlags eel_gdk_parse_geometry (const char *string, int *x_return, int *y_return, guint *width_return, guint *height_return) @@ -747,23 +477,37 @@ eel_gdk_parse_geometry (const char *string, int *x_return, int *y_return, } void +#if GTK_CHECK_VERSION(3,0,0) +eel_cairo_draw_layout_with_drop_shadow (cairo_t *cr, +#else eel_gdk_draw_layout_with_drop_shadow (GdkDrawable *drawable, - GdkGC *gc, +#endif GdkColor *text_color, GdkColor *shadow_color, int x, int y, PangoLayout *layout) { - gdk_draw_layout_with_colors (drawable, gc, - x+1, y+1, - layout, - shadow_color, NULL); - - gdk_draw_layout_with_colors (drawable, gc, - x, y, - layout, - text_color, NULL); +#if GTK_CHECK_VERSION(3,0,0) + cairo_save (cr); +#else + cairo_t *cr; + cr = gdk_cairo_create (drawable); +#endif + + gdk_cairo_set_source_color (cr, shadow_color); + cairo_move_to (cr, x+1, y+1); + pango_cairo_show_layout (cr, layout); + + gdk_cairo_set_source_color (cr, text_color); + cairo_move_to (cr, x, y); + pango_cairo_show_layout (cr, layout); + +#if GTK_CHECK_VERSION(3,0,0) + cairo_restore +#else + cairo_destroy (cr); +#endif } #if ! defined (EEL_OMIT_SELF_CHECK) @@ -797,12 +541,6 @@ eel_self_check_gdk_rgb_to_color (guint32 color) void eel_self_check_gdk_extensions (void) { - /* eel_interpolate_color */ - EEL_CHECK_INTEGER_RESULT (eel_interpolate_color (0.0, 0, 0), 0); - EEL_CHECK_INTEGER_RESULT (eel_interpolate_color (0.0, 0, 0xFFFFFF), 0); - EEL_CHECK_INTEGER_RESULT (eel_interpolate_color (0.5, 0, 0xFFFFFF), 0x7F7F7F); - EEL_CHECK_INTEGER_RESULT (eel_interpolate_color (1.0, 0, 0xFFFFFF), 0xFFFFFF); - /* eel_gradient_new */ EEL_CHECK_STRING_RESULT (eel_gradient_new ("", "", FALSE), ""); EEL_CHECK_STRING_RESULT (eel_gradient_new ("a", "b", FALSE), "a-b"); |