mirror of
https://github.com/cage-kiosk/cage.git
synced 2026-03-02 01:40:56 -05:00
Refactor surface damaging and rendering code
This is based on code from Sway, which is also MIT licensed hence compatible. This makes the surface damaging and rendering code easier to follow and makes it easier to import future changes to Sway as well.
This commit is contained in:
parent
bfd7d605b8
commit
2db815aa23
10 changed files with 408 additions and 243 deletions
36
util.c
Normal file
36
util.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Cage: A Wayland kiosk.
|
||||
*
|
||||
* Copyright (C) 2019 The Sway authors
|
||||
*
|
||||
* See the LICENSE file accompanying this file.
|
||||
*/
|
||||
|
||||
#include <wlr/types/wlr_box.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
int
|
||||
scale_length(int length, int offset, float scale)
|
||||
{
|
||||
/**
|
||||
* One does not simply multiply the width by the scale. We allow fractional
|
||||
* scaling, which means the resulting scaled width might be a decimal.
|
||||
* So we round it.
|
||||
*
|
||||
* But even this can produce undesirable results depending on the X or Y
|
||||
* offset of the box. For example, with a scale of 1.5, a box with
|
||||
* width=1 should not scale to 2px if its X coordinate is 1, because the
|
||||
* X coordinate would have scaled to 2px.
|
||||
*/
|
||||
return round((offset + length) * scale) - round(offset * scale);
|
||||
}
|
||||
|
||||
void
|
||||
scale_box(struct wlr_box *box, float scale)
|
||||
{
|
||||
box->width = scale_length(box->width, box->x, scale);
|
||||
box->height = scale_length(box->height, box->y, scale);
|
||||
box->x = round(box->x * scale);
|
||||
box->y = round(box->y * scale);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue