background: Make paintable light/dark adjustable
In order to make the CcBackgroundPaintable more reusable, the way it draws itself either light, dark, or both needs to be adjustable. We therefore introduce CcBackgroundPaintFlags that indicate the desired drawing behavior.
This commit is contained in:
parent
50411b206d
commit
761367ac4a
4 changed files with 66 additions and 21 deletions
|
@ -112,7 +112,7 @@ create_widget_func (gpointer model_item,
|
|||
source = BG_SOURCE (user_data);
|
||||
item = CC_BACKGROUND_ITEM (model_item);
|
||||
|
||||
paintable = cc_background_paintable_new (source, item);
|
||||
paintable = cc_background_paintable_new (source, item, CC_BACKGROUND_PAINT_LIGHT_DARK);
|
||||
|
||||
picture = gtk_picture_new_for_paintable (GDK_PAINTABLE (paintable));
|
||||
gtk_picture_set_can_shrink (GTK_PICTURE (picture), FALSE);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include <config.h>
|
||||
|
||||
#include "cc-background-enum-types.h"
|
||||
#include "cc-background-paintable.h"
|
||||
|
||||
struct _CcBackgroundPaintable
|
||||
|
@ -32,6 +33,8 @@ struct _CcBackgroundPaintable
|
|||
|
||||
GdkPaintable *texture;
|
||||
GdkPaintable *dark_texture;
|
||||
|
||||
CcBackgroundPaintFlags paint_flags;
|
||||
};
|
||||
|
||||
enum
|
||||
|
@ -41,6 +44,7 @@ enum
|
|||
PROP_ITEM,
|
||||
PROP_SCALE_FACTOR,
|
||||
PROP_TEXT_DIRECTION,
|
||||
PROP_PAINT_FLAGS,
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
|
@ -56,8 +60,10 @@ static void
|
|||
update_cache (CcBackgroundPaintable *self)
|
||||
{
|
||||
g_autoptr(GdkPixbuf) pixbuf = NULL;
|
||||
g_autoptr(GdkPixbuf) dark_pixbuf = NULL;
|
||||
GnomeDesktopThumbnailFactory *factory;
|
||||
int width, height;
|
||||
gboolean has_dark;
|
||||
|
||||
g_clear_object (&self->texture);
|
||||
g_clear_object (&self->dark_texture);
|
||||
|
@ -65,20 +71,21 @@ update_cache (CcBackgroundPaintable *self)
|
|||
factory = bg_source_get_thumbnail_factory (self->source);
|
||||
width = bg_source_get_thumbnail_width (self->source);
|
||||
height = bg_source_get_thumbnail_height (self->source);
|
||||
has_dark = cc_background_item_has_dark_version (self->item);
|
||||
|
||||
if ((self->paint_flags & CC_BACKGROUND_PAINT_LIGHT) || !has_dark)
|
||||
{
|
||||
pixbuf = cc_background_item_get_thumbnail (self->item,
|
||||
factory,
|
||||
width,
|
||||
height,
|
||||
self->scale_factor,
|
||||
FALSE);
|
||||
|
||||
self->texture = GDK_PAINTABLE (gdk_texture_new_for_pixbuf (pixbuf));
|
||||
}
|
||||
|
||||
if (cc_background_item_has_dark_version (self->item))
|
||||
if ((self->paint_flags & CC_BACKGROUND_PAINT_DARK) && has_dark)
|
||||
{
|
||||
g_autoptr (GdkPixbuf) dark_pixbuf = NULL;
|
||||
|
||||
dark_pixbuf = cc_background_item_get_thumbnail (self->item,
|
||||
factory,
|
||||
width,
|
||||
|
@ -140,6 +147,10 @@ cc_background_paintable_get_property (GObject *object,
|
|||
g_value_set_enum (value, self->text_direction);
|
||||
break;
|
||||
|
||||
case PROP_PAINT_FLAGS:
|
||||
g_value_set_flags (value, self->paint_flags);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
|
@ -173,6 +184,10 @@ cc_background_paintable_set_property (GObject *object,
|
|||
gdk_paintable_invalidate_contents (GDK_PAINTABLE (self));
|
||||
break;
|
||||
|
||||
case PROP_PAINT_FLAGS:
|
||||
self->paint_flags = g_value_get_flags (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
|
@ -223,6 +238,16 @@ cc_background_paintable_class_init (CcBackgroundPaintableClass *klass)
|
|||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
|
||||
properties[PROP_PAINT_FLAGS] =
|
||||
g_param_spec_flags ("paint-flags",
|
||||
"Paint Flags",
|
||||
"Paint Flags",
|
||||
CC_TYPE_BACKGROUND_PAINT_FLAGS,
|
||||
CC_BACKGROUND_PAINT_LIGHT,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
|
||||
g_object_class_install_properties (object_class, N_PROPS, properties);
|
||||
}
|
||||
|
||||
|
@ -248,6 +273,12 @@ cc_background_paintable_snapshot (GdkPaintable *paintable,
|
|||
return;
|
||||
}
|
||||
|
||||
if (!self->texture)
|
||||
{
|
||||
gdk_paintable_snapshot (self->dark_texture, snapshot, width, height);
|
||||
return;
|
||||
}
|
||||
|
||||
is_rtl = self->text_direction == GTK_TEXT_DIR_RTL;
|
||||
|
||||
gtk_snapshot_push_clip (GTK_SNAPSHOT (snapshot),
|
||||
|
@ -271,24 +302,27 @@ static int
|
|||
cc_background_paintable_get_intrinsic_width (GdkPaintable *paintable)
|
||||
{
|
||||
CcBackgroundPaintable *self = CC_BACKGROUND_PAINTABLE (paintable);
|
||||
GdkPaintable *valid_texture = self->texture ? self->texture : self->dark_texture;
|
||||
|
||||
return gdk_paintable_get_intrinsic_width (self->texture) / self->scale_factor;
|
||||
return gdk_paintable_get_intrinsic_width (valid_texture) / self->scale_factor;
|
||||
}
|
||||
|
||||
static int
|
||||
cc_background_paintable_get_intrinsic_height (GdkPaintable *paintable)
|
||||
{
|
||||
CcBackgroundPaintable *self = CC_BACKGROUND_PAINTABLE (paintable);
|
||||
GdkPaintable *valid_texture = self->texture ? self->texture : self->dark_texture;
|
||||
|
||||
return gdk_paintable_get_intrinsic_height (self->texture) / self->scale_factor;
|
||||
return gdk_paintable_get_intrinsic_height (valid_texture) / self->scale_factor;
|
||||
}
|
||||
|
||||
static double
|
||||
cc_background_paintable_get_intrinsic_aspect_ratio (GdkPaintable *paintable)
|
||||
{
|
||||
CcBackgroundPaintable *self = CC_BACKGROUND_PAINTABLE (paintable);
|
||||
GdkPaintable *valid_texture = self->texture ? self->texture : self->dark_texture;
|
||||
|
||||
return gdk_paintable_get_intrinsic_aspect_ratio (self->texture);
|
||||
return gdk_paintable_get_intrinsic_aspect_ratio (valid_texture);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -302,7 +336,8 @@ cc_background_paintable_paintable_init (GdkPaintableInterface *iface)
|
|||
|
||||
CcBackgroundPaintable *
|
||||
cc_background_paintable_new (BgSource *source,
|
||||
CcBackgroundItem *item)
|
||||
CcBackgroundItem *item,
|
||||
CcBackgroundPaintFlags paint_flags)
|
||||
{
|
||||
g_return_val_if_fail (BG_IS_SOURCE (source), NULL);
|
||||
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), NULL);
|
||||
|
@ -310,5 +345,6 @@ cc_background_paintable_new (BgSource *source,
|
|||
return g_object_new (CC_TYPE_BACKGROUND_PAINTABLE,
|
||||
"source", source,
|
||||
"item", item,
|
||||
"paint-flags", paint_flags,
|
||||
NULL);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,16 @@ G_BEGIN_DECLS
|
|||
#define CC_TYPE_BACKGROUND_PAINTABLE (cc_background_paintable_get_type ())
|
||||
G_DECLARE_FINAL_TYPE (CcBackgroundPaintable, cc_background_paintable, CC, BACKGROUND_PAINTABLE, GObject)
|
||||
|
||||
typedef enum {
|
||||
CC_BACKGROUND_PAINT_LIGHT = 1 << 0,
|
||||
CC_BACKGROUND_PAINT_DARK = 1 << 1
|
||||
} CcBackgroundPaintFlags;
|
||||
|
||||
#define CC_BACKGROUND_PAINT_LIGHT_DARK (CC_BACKGROUND_PAINT_LIGHT | \
|
||||
CC_BACKGROUND_PAINT_DARK)
|
||||
|
||||
CcBackgroundPaintable * cc_background_paintable_new (BgSource *source,
|
||||
CcBackgroundItem *item);
|
||||
CcBackgroundItem *item,
|
||||
CcBackgroundPaintFlags paint_flags);
|
||||
|
||||
G_END_DECLS
|
||||
|
|
|
@ -19,7 +19,7 @@ common_sources = []
|
|||
|
||||
common_sources += gnome.mkenums_simple(
|
||||
'cc-background-enum-types',
|
||||
sources: ['cc-background-item.h']
|
||||
sources: ['cc-background-item.h', 'cc-background-paintable.h']
|
||||
)
|
||||
|
||||
enums = 'gdesktop-enums-types'
|
||||
|
|
Loading…
Add table
Reference in a new issue