~rycwo/forge

ref: HEAD forge/src/gui_util.c -rw-r--r-- 908 bytes
d7ee94d6Ryan Chan Fix missing cd in .build.yml 10 days ago
                                                                                
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
// This file is part of Forge, the foundation library for Forge tools.
//
// Copyright (C) 2021 Ryan Chan <rycwo@posteo.net>
// SPDX-License-Identifier: GPL-3.0-only
//
// This Source Code Form is subject to the terms of the GNU General Public
// License v3.0 only. You should have received a copy of the license along with
// this program. If not, see <https://www.gnu.org/licenses/>.

#include "forge/gui_util.h"

#include "forge/matrix.h"
#include "forge/vector.h"

void
fg_gui_transform_rect(
		struct fg_gui_context const* context,
		fg_vec4 out,
		fg_vec4 const rect) {
	if (!context->transform_active) {
		fg_vec4_copy(out, rect);
		return;
	}
	fg_vec4 v1 = {rect[0], rect[1], 0.0, 1.0};
	fg_vec4 v2 = {rect[0] + rect[2], rect[1] + rect[3], 0.0, 1.0};
	fg_mat4_mul_vec4(out, context->transform, v1);
	fg_mat4_mul_vec4(v1, context->transform, v2);
	out[2] = v1[0] - out[0];
	out[3] = v1[1] - out[1];
}