guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
clip.cpp
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23#include "guillaume/systems/clip.hpp"
24
25namespace guillaume::systems
26{
27 Clip::Clip(utility::Engine &engine)
28 : ecs::SystemFiller<components::Transform, components::Bound,
29 components::Clip>(ecs::Phase::Layout)
30 , _engine(engine)
31 {
32 }
33
34 void Clip::prepare(void)
35 {
36 _engine.clearScissor();
37 }
38
40 Clip::computeRect(const utility::graphic::PoseF &pose, float width,
41 float height, float margin)
42 {
44
45 rect.x = pose.getPosition().getX() + margin;
46 rect.y = pose.getPosition().getY() + margin;
47 rect.width = width - 2.0f * margin;
48 rect.height = height - 2.0f * margin;
49
50 return rect;
51 }
52
53 void Clip::update(const ecs::Entity::Identifier &entityIdentifier)
54 {
55 if (!requireComponent<components::Bound>(entityIdentifier)
56 || !requireComponent<components::Transform>(entityIdentifier)
57 || !requireComponent<components::Clip>(entityIdentifier)) {
58 return;
59 }
60
61 auto &clip = getComponent<components::Clip>(entityIdentifier);
62 if (!clip.isEnabled()) {
63 return;
64 }
65
66 const auto &pose =
67 getComponent<components::Transform>(entityIdentifier).getPose();
68 const auto &bound = getComponent<components::Bound>(entityIdentifier);
69
70 const auto rect = computeRect(pose, bound.getWidth(), bound.getHeight(),
71 clip.getMargin());
72 clip.setRect(rect);
73
74 _engine.setScissor(utility::graphic::ScissorRect {
75 rect.x, rect.y, rect.width, rect.height });
76 }
77
78} // namespace guillaume::systems
std::size_t Identifier
The key under which an entity's components are stored. Systems and components refer to entities by th...
Definition entity.hpp:86
ComponentType & getComponent(const ecs::Entity::Identifier &entityIdentifier)
Get a component of an entity from the bound registry, to read or modify it.
bool requireComponent(const ecs::Entity::Identifier &entityIdentifier)
Tell whether an entity has a component, and log a warning naming the entity and the component when it...
void update(const ecs::Entity::Identifier &entityIdentifier) override
Resolve the clip rectangle of one entity, store it in its components::Clip and make it the engine sci...
Definition clip.cpp:53
static components::Clip::Rect computeRect(const utility::graphic::PoseF &pose, float width, float height, float margin)
Compute a clip rectangle from the pose and size of a bound.
Definition clip.cpp:40
Clip(utility::Engine &engine)
Create the system in the Layout phase.
Definition clip.cpp:27
void prepare(void) override
Clear the engine scissor. Called once per frame before the entities are visited, so a frame without a...
Definition clip.cpp:34
Arranges the children of a container in a row or a column and sizes the container around them.
Definition layout.hpp:84
State. Every class here is plain data attached to an entity.
The entity-component-system core, independent of any widget.
Definition component.hpp:28
Rules. Every class here runs each frame on the entities that have the components it declares.
The clip rectangle, in the same coordinates as the position of a components::Transform.
Definition clip.hpp:59
float height
Height, in dp.
Definition clip.hpp:63
float width
Width, in dp.
Definition clip.hpp:62
float y
Top edge, in dp.
Definition clip.hpp:61
float x
Left edge, in dp.
Definition clip.hpp:60