mirror of
https://github.com/labwc/labwc.git
synced 2025-11-02 09:01:47 -05:00
ssd: rework titlebar button rendering
- fix that icons for normal/hovered/rounded buttons are not placed exactly the same position - fix blurry window button icons in scaled outputs This commit introduces lab_img and scaled_img_buffer and uses them for rendering icons in the window titlebar. Now the process of rendering button icons are split into 2 phases: loading with lab_img_load() and creating scene-nodes for them with scaled_img_buffer_create(). This might incur some additional overhead since we no longer preload icon textures, but the rendering of icon only happens for the first window as backing buffers are shared and the overhead won't be noticeable. This commit also simplifies the process of centering icon buffer in the button, by creating icon buffers in a fixed geometry via lab_img_render().
This commit is contained in:
parent
9a3412324d
commit
16dbdc64e5
25 changed files with 647 additions and 391 deletions
78
include/img/img.h
Normal file
78
include/img/img.h
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef LABWC_IMG_H
|
||||
#define LABWC_IMG_H
|
||||
|
||||
#include <cairo.h>
|
||||
#include <stdint.h>
|
||||
#include <wayland-util.h>
|
||||
|
||||
struct lab_img_cache;
|
||||
|
||||
enum lab_img_type {
|
||||
LAB_IMG_PNG,
|
||||
LAB_IMG_SVG,
|
||||
LAB_IMG_XBM,
|
||||
LAB_IMG_XPM,
|
||||
};
|
||||
|
||||
struct lab_img {
|
||||
struct theme *theme; /* Used by modifier functions */
|
||||
struct wl_array modifiers; /* lab_img_modifier_func_t */
|
||||
struct lab_img_cache *cache;
|
||||
};
|
||||
|
||||
struct lab_img *lab_img_load(enum lab_img_type type, const char *path,
|
||||
float *xbm_color);
|
||||
|
||||
/**
|
||||
* lab_img_load_from_bitmap() - create button from monochrome bitmap
|
||||
* @bitmap: bitmap data array in hexadecimal xbm format
|
||||
* @rgba: color
|
||||
*
|
||||
* Example bitmap: char button[6] = { 0x3f, 0x3f, 0x21, 0x21, 0x21, 0x3f };
|
||||
*/
|
||||
struct lab_img *lab_img_load_from_bitmap(const char *bitmap, float *rgba);
|
||||
|
||||
typedef void (*lab_img_modifier_func_t)(struct theme *theme, cairo_t *cairo,
|
||||
int w, int h);
|
||||
|
||||
/**
|
||||
* lab_img_copy() - Copy lab_img
|
||||
* @img: source image
|
||||
*
|
||||
* This function duplicates lab_img, but its internal cache for the image is
|
||||
* shared.
|
||||
*/
|
||||
struct lab_img *lab_img_copy(struct lab_img *img);
|
||||
|
||||
/**
|
||||
* lab_img_add_modifier() - Add a modifier function to lab_img
|
||||
* @img: source image
|
||||
* @modifier: function that applies modifications to the image.
|
||||
* @theme: pointer to theme passed to @modifier.
|
||||
*
|
||||
* "Modifiers" are functions that perform some additional drawing operation
|
||||
* after the image is rendered on a buffer with lab_img_render(). For example,
|
||||
* hover effects for window buttons can be drawn over the rendered image.
|
||||
*/
|
||||
void lab_img_add_modifier(struct lab_img *img, lab_img_modifier_func_t modifier,
|
||||
struct theme *theme);
|
||||
|
||||
/**
|
||||
* lab_img_render() - Render lab_img to a buffer
|
||||
* @img: source image
|
||||
* @width: width of the created buffer
|
||||
* @height: height of the created buffer
|
||||
* @padding: padding around the rendered image in the buffer
|
||||
* @scale: scale of the created buffer
|
||||
*/
|
||||
struct lab_data_buffer *lab_img_render(struct lab_img *img,
|
||||
int width, int height, int padding, double scale);
|
||||
|
||||
/**
|
||||
* lab_img_destroy() - destroy lab_img
|
||||
* @img: lab_img to destroy
|
||||
*/
|
||||
void lab_img_destroy(struct lab_img *img);
|
||||
|
||||
#endif /* LABWC_IMG_H */
|
||||
Loading…
Add table
Add a link
Reference in a new issue