From d998099612f0397234910ce753859ee127ec5b45 Mon Sep 17 00:00:00 2001 From: William McKinnon Date: Fri, 25 Oct 2024 11:14:37 -0400 Subject: feat: add shadow_node (#66) --------- Co-authored-by: Erik Reider <35975961+ErikReider@users.noreply.github.com> --- include/scenefx/render/pass.h | 9 +++--- include/scenefx/types/fx/shadow_data.h | 20 ------------- include/scenefx/types/wlr_scene.h | 51 ++++++++++++++++++++++++++++------ 3 files changed, 48 insertions(+), 32 deletions(-) delete mode 100644 include/scenefx/types/fx/shadow_data.h (limited to 'include/scenefx') diff --git a/include/scenefx/render/pass.h b/include/scenefx/render/pass.h index d005c37..9e92f90 100644 --- a/include/scenefx/render/pass.h +++ b/include/scenefx/render/pass.h @@ -4,7 +4,6 @@ #include #include #include -#include "scenefx/types/fx/shadow_data.h" struct fx_gles_render_pass { struct wlr_render_pass base; @@ -43,13 +42,15 @@ struct fx_render_rect_options { }; struct fx_render_box_shadow_options { - struct wlr_box shadow_box; - struct wlr_box clip_box; + struct wlr_box box; + struct wlr_box window_box; + int window_corner_radius; /* Clip region, leave NULL to disable clipping */ const pixman_region32_t *clip; - struct shadow_data *shadow_data; + float blur_sigma; int corner_radius; + struct wlr_render_color color; }; struct fx_render_rounded_rect_options { diff --git a/include/scenefx/types/fx/shadow_data.h b/include/scenefx/types/fx/shadow_data.h deleted file mode 100644 index c307871..0000000 --- a/include/scenefx/types/fx/shadow_data.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef TYPES_DECORATION_DATA -#define TYPES_DECORATION_DATA - -#include -#include -#include - -struct shadow_data { - bool enabled; - struct wlr_render_color color; - float blur_sigma; - float offset_x; - float offset_y; -}; - -struct shadow_data shadow_data_get_default(void); - -bool scene_buffer_has_shadow(struct shadow_data *data); - -#endif diff --git a/include/scenefx/types/wlr_scene.h b/include/scenefx/types/wlr_scene.h index 5925931..9b68c4b 100644 --- a/include/scenefx/types/wlr_scene.h +++ b/include/scenefx/types/wlr_scene.h @@ -20,7 +20,6 @@ */ #include -#include "scenefx/types/fx/shadow_data.h" #include #include #include @@ -54,6 +53,7 @@ typedef void (*wlr_scene_buffer_iterator_func_t)( enum wlr_scene_node_type { WLR_SCENE_NODE_TREE, WLR_SCENE_NODE_RECT, + WLR_SCENE_NODE_SHADOW, WLR_SCENE_NODE_BUFFER, }; @@ -140,6 +140,15 @@ struct wlr_scene_rect { float color[4]; }; +/** A scene-graph node displaying a shadow */ +struct wlr_scene_shadow { + struct wlr_scene_node node; + int width, height; + int corner_radius; + float color[4]; + float blur_sigma; +}; + struct wlr_scene_outputs_update_event { struct wlr_scene_output **active; size_t size; @@ -178,7 +187,6 @@ struct wlr_scene_buffer { float opacity; int corner_radius; - struct shadow_data shadow_data; enum wlr_scale_filter_mode filter_mode; struct wlr_fbox src_box; @@ -358,6 +366,12 @@ struct wlr_scene_tree *wlr_scene_tree_from_node(struct wlr_scene_node *node); */ struct wlr_scene_rect *wlr_scene_rect_from_node(struct wlr_scene_node *node); +/** + * If this node represents a wlr_scene_shadow, that shadow will be returned. It + * is not legal to feed a node that does not represent a wlr_scene_shadow. + */ +struct wlr_scene_shadow *wlr_scene_shadow_from_node(struct wlr_scene_node *node); + /** * If this buffer is backed by a surface, then the struct wlr_scene_surface is * returned. If not, NULL will be returned. @@ -381,6 +395,33 @@ void wlr_scene_rect_set_size(struct wlr_scene_rect *rect, int width, int height) */ void wlr_scene_rect_set_color(struct wlr_scene_rect *rect, const float color[static 4]); +/** + * Add a node displaying a shadow to the scene-graph. + */ +struct wlr_scene_shadow *wlr_scene_shadow_create(struct wlr_scene_tree *parent, + int width, int height, int corner_radius, float blur_sigma, + const float color[static 4]); + +/** + * Change the width and height of an existing shadow node. + */ +void wlr_scene_shadow_set_size(struct wlr_scene_shadow *shadow, int width, int height); + +/** + * Change the corner radius of an existing shadow node. + */ +void wlr_scene_shadow_set_corner_radius(struct wlr_scene_shadow *shadow, int corner_radius); + +/** + * Change the blur_sigma of an existing shadow node. + */ +void wlr_scene_shadow_set_blur_sigma(struct wlr_scene_shadow *shadow, float blur_sigma); + +/** + * Change the color of an existing shadow node. + */ +void wlr_scene_shadow_set_color(struct wlr_scene_shadow *shadow, const float color[static 4]); + /** * Add a node displaying a buffer to the scene-graph. * @@ -456,12 +497,6 @@ void wlr_scene_buffer_set_filter_mode(struct wlr_scene_buffer *scene_buffer, void wlr_scene_buffer_set_corner_radius(struct wlr_scene_buffer *scene_buffer, int radii); -/** -* Sets the shadow of this buffer -*/ -void wlr_scene_buffer_set_shadow_data(struct wlr_scene_buffer *scene_buffer, - struct shadow_data shadow_data); - /** * Calls the buffer's frame_done signal. */ -- cgit v1.2.3