-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Render drop shadow for active window #58
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
#include "apps_multi.h" | ||
|
||
#define D(x) twin_double_to_fixed(x) | ||
#define ASSET_PATH "assets/" | ||
|
||
static void apps_line_start(twin_screen_t *screen, int x, int y, int w, int h) | ||
{ | ||
|
@@ -272,6 +273,50 @@ static void apps_flower_start(twin_screen_t *screen, int x, int y, int w, int h) | |
twin_window_show(window); | ||
} | ||
|
||
static void apps_blur(twin_screen_t *screen, int x, int y, int w, int h) | ||
{ | ||
twin_pixmap_t *raw_background = | ||
twin_pixmap_from_file(ASSET_PATH "tux.png", TWIN_ARGB32); | ||
twin_window_t *window = twin_window_create( | ||
screen, TWIN_ARGB32, TwinWindowApplication, x, y, w, h); | ||
twin_window_set_name(window, "Blur"); | ||
twin_pixmap_t *scaled_background = twin_pixmap_create( | ||
TWIN_ARGB32, window->pixmap->width, window->pixmap->height); | ||
twin_fixed_t sx, sy; | ||
sx = twin_fixed_div( | ||
twin_int_to_fixed(raw_background->width), | ||
twin_int_to_fixed(window->client.right - window->client.left)); | ||
sy = twin_fixed_div( | ||
twin_int_to_fixed(raw_background->height), | ||
twin_int_to_fixed(window->client.bottom - window->client.top)); | ||
|
||
twin_matrix_scale(&raw_background->transform, sx, sy); | ||
twin_operand_t srcop = { | ||
.source_kind = TWIN_PIXMAP, | ||
.u.pixmap = raw_background, | ||
}; | ||
|
||
twin_composite(scaled_background, 0, 0, &srcop, 0, 0, 0, 0, 0, TWIN_SOURCE, | ||
screen->width, screen->height); | ||
|
||
twin_pointer_t src, dst; | ||
for (int y = window->client.top; y < window->client.bottom; y++) | ||
for (int x = window->client.left; x < window->client.right; x++) { | ||
src = | ||
twin_pixmap_pointer(scaled_background, x - window->client.left, | ||
y - window->client.top); | ||
dst = twin_pixmap_pointer(window->pixmap, x, y); | ||
*dst.argb32 = *src.argb32 | 0xff000000; | ||
} | ||
twin_stack_blur(window->pixmap, 5, window->client.left, | ||
window->client.right, window->client.top, | ||
window->client.bottom); | ||
jserv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
twin_pixmap_destroy(scaled_background); | ||
twin_pixmap_destroy(raw_background); | ||
twin_window_show(window); | ||
} | ||
|
||
void apps_multi_start(twin_screen_t *screen, | ||
const char *name, | ||
int x, | ||
|
@@ -286,4 +331,5 @@ void apps_multi_start(twin_screen_t *screen, | |
apps_ascii_start(screen, x += 20, y += 20, w, h); | ||
apps_jelly_start(screen, x += 20, y += 20, w / 2, h); | ||
apps_flower_start(screen, x += 20, y += 20, w, h); | ||
apps_blur(screen, x += 20, y += 20, w / 2, h / 2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it is worthy to have an application for stack blur. Any idea to keep it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The apps_blur() function currently only resizes tux.png. This function isn't worthwhile to show by creating a standalone window feature. If it is still not worthy to have an application by adding another function, "blur," the apps_blur() function could be removed entirely. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The drop shadow feature's availability depends on configuration settings, so it should not expose any public functions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The drop shadow functionality relies on the blur effect, but the blur effect is designed to be used independently as well. This is why in draw.c, the function twin_shadow_border() is conditionally built, while the function twin_stack_blur() is not. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should be built only if PNG support is specified.