1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2025-02-10 15:44:41 -05:00

[Widget] with background image, draw background-color first.

This commit is contained in:
Dave Davenport 2021-06-13 21:41:31 +02:00
parent 1e25ae03b7
commit beccfe4178
4 changed files with 21 additions and 6 deletions

View file

@ -260,6 +260,18 @@ double rofi_theme_get_double ( const widget *widget, const char *property, doub
*/ */
void rofi_theme_get_color ( const widget *widget, const char *property, cairo_t *d ); void rofi_theme_get_color ( const widget *widget, const char *property, cairo_t *d );
/**
* @param widget The widget to query
* @param property The property to query.
* @param d The drawable to apply color.
*
* Obtain the image of the widget and applies this to the drawable d.
*
* @return true if image is set.
*/
gboolean rofi_theme_get_image ( const widget *widget, const char *property, cairo_t *d );
/** /**
* @param widget The widget to query * @param widget The widget to query
* @param property The property to query. * @param property The property to query.

View file

@ -347,7 +347,5 @@ int widget_get_absolute_xpos ( widget *wid );
* @returns the absolute y-position of widget of the widget in pixels. * @returns the absolute y-position of widget of the widget in pixels.
*/ */
int widget_get_absolute_ypos ( widget *wid ); int widget_get_absolute_ypos ( widget *wid );
void rofi_theme_get_image ( const widget *widget, const char *property, cairo_t *d );
/**@}*/ /**@}*/
#endif // ROFI_WIDGET_H #endif // ROFI_WIDGET_H

View file

@ -918,16 +918,16 @@ void rofi_theme_get_color ( const widget *widget, const char *property, cairo_t
g_debug ( "Theme entry: #%s %s property %s unset.", widget->name, widget->state ? widget->state : "", property ); g_debug ( "Theme entry: #%s %s property %s unset.", widget->name, widget->state ? widget->state : "", property );
} }
} }
void rofi_theme_get_image ( const widget *widget, const char *property, cairo_t *d ) gboolean rofi_theme_get_image ( const widget *widget, const char *property, cairo_t *d )
{ {
ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, FALSE ); ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, FALSE );
Property *p = rofi_theme_find_property ( wid, P_IMAGE , property, FALSE ); Property *p = rofi_theme_find_property ( wid, P_IMAGE , property, FALSE );
if ( p ) { if ( p ) {
if ( p->type == P_INHERIT ) { if ( p->type == P_INHERIT ) {
if ( widget->parent ) { if ( widget->parent ) {
rofi_theme_get_image ( widget->parent, property, d ); return rofi_theme_get_image ( widget->parent, property, d );
} }
return; return FALSE;
} }
if ( p->value.image.type == ROFI_IMAGE_URL ) { if ( p->value.image.type == ROFI_IMAGE_URL ) {
if ( p->value.image.surface_id == 0 ) { if ( p->value.image.surface_id == 0 ) {
@ -940,6 +940,7 @@ void rofi_theme_get_image ( const widget *widget, const char *property, cairo_t
cairo_pattern_set_extend ( pat, CAIRO_EXTEND_REPEAT ); cairo_pattern_set_extend ( pat, CAIRO_EXTEND_REPEAT );
cairo_set_source ( d, pat ); cairo_set_source ( d, pat );
cairo_pattern_destroy ( pat ); cairo_pattern_destroy ( pat );
return TRUE;
} }
} else if ( p->value.image.type == ROFI_IMAGE_LINEAR_GRADIENT ) { } else if ( p->value.image.type == ROFI_IMAGE_LINEAR_GRADIENT ) {
cairo_pattern_t * pat = cairo_pattern_create_linear (0.0,0.0, widget->w, 0.0); cairo_pattern_t * pat = cairo_pattern_create_linear (0.0,0.0, widget->w, 0.0);
@ -951,11 +952,13 @@ void rofi_theme_get_image ( const widget *widget, const char *property, cairo_t
p->value.image.stop.blue, p->value.image.stop.alpha); p->value.image.stop.blue, p->value.image.stop.alpha);
cairo_set_source ( d, pat ); cairo_set_source ( d, pat );
cairo_pattern_destroy ( pat ); cairo_pattern_destroy ( pat );
return TRUE;
} }
} }
else { else {
g_debug ( "Theme entry: #%s %s property %s unset.", widget->name, widget->state ? widget->state : "", property ); g_debug ( "Theme entry: #%s %s property %s unset.", widget->name, widget->state ? widget->state : "", property );
} }
return FALSE;
} }
RofiPadding rofi_theme_get_padding ( const widget *widget, const char *property, RofiPadding pad ) RofiPadding rofi_theme_get_padding ( const widget *widget, const char *property, RofiPadding pad )
{ {

View file

@ -267,8 +267,10 @@ void widget_draw ( widget *widget, cairo_t *d )
cairo_set_source_rgba ( d, 1.0, 1.0, 1.0, 1.0 ); cairo_set_source_rgba ( d, 1.0, 1.0, 1.0, 1.0 );
rofi_theme_get_color ( widget, "background-color", d ); rofi_theme_get_color ( widget, "background-color", d );
rofi_theme_get_image ( widget, "background-image", d );
cairo_fill_preserve ( d ); cairo_fill_preserve ( d );
if ( rofi_theme_get_image ( widget, "background-image", d ) ) {
cairo_fill_preserve ( d );
}
cairo_clip ( d ); cairo_clip ( d );
widget->draw ( widget, d ); widget->draw ( widget, d );