[go: up one dir, main page]

File: util.c

package info (click to toggle)
cage 0.1.4-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 372 kB
  • sloc: ansic: 2,770; sh: 53; makefile: 8
file content (34 lines) | stat: -rw-r--r-- 944 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
 * Cage: A Wayland kiosk.
 *
 * Copyright (C) 2019 The Sway authors
 *
 * See the LICENSE file accompanying this file.
 */

#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);
}