VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
screenComponent.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2025-2026 Arnis Lektauers
3#include "screenComponent.h"
4
5#include <algorithm>
6
7namespace visutwin::canvas
8{
11 {
12 _instances.push_back(this);
13 }
14
16 {
17 std::erase(_instances, this);
18 }
19
20 void ScreenComponent::updateScaleFromWindow(const int windowWidth, const int windowHeight)
21 {
22 const float w = static_cast<float>(std::max(windowWidth, 1));
23 const float h = static_cast<float>(std::max(windowHeight, 1));
24 _resolution = Vector2(w, h);
25
26 if (!_screenSpace) {
27 _scale = 1.0f;
28 return;
29 }
30
31 const float refW = std::max(_referenceResolution.x, 1.0f);
32 const float refH = std::max(_referenceResolution.y, 1.0f);
33 _scale = std::min(w / refW, h / refH);
34 if (_scale <= 1e-6f) {
35 _scale = 1.0f;
36 }
37 }
38}
Entity * entity() const
Definition component.cpp:16
Component(IComponentSystem *system, Entity *entity)
Definition component.cpp:12
IComponentSystem * system() const
Definition component.h:47
ECS entity — a GraphNode that hosts components defining its behavior.
Definition entity.h:32
ScreenComponent(IComponentSystem *system, Entity *entity)
void updateScaleFromWindow(int windowWidth, int windowHeight)
2D vector for UV coordinates, screen positions, and 2D math.
Definition vector2.h:18