FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_objectAnchor.hpp
1/*
2 * Copyright 2024 Guillaume Guillet
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _FGE_C_OBJECTANCHOR_HPP_INCLUDED
18#define _FGE_C_OBJECTANCHOR_HPP_INCLUDED
19
20#include "FastEngine/fge_extern.hpp"
21#include "FastEngine/C_vector.hpp"
22#include <cstdint>
23#include <limits>
24#include <memory>
25
26#define FGE_SCENE_BAD_SID std::numeric_limits<fge::ObjectSid>::max()
27
28namespace fge
29{
30
31using ObjectSid = uint32_t;
32
33class ObjectData;
34using ObjectDataShared = std::shared_ptr<fge::ObjectData>;
35using ObjectDataWeak = std::weak_ptr<fge::ObjectData>;
36
37class Object;
38
39class FGE_API Anchor
40{
41public:
42 enum class Types : uint8_t
43 {
44 ANCHOR_NONE,
45 ANCHOR_UPLEFT_CORNER,
46 ANCHOR_UPRIGHT_CORNER,
47 ANCHOR_DOWNLEFT_CORNER,
48 ANCHOR_DOWNRIGHT_CORNER
49 };
50
51 enum class Shifts : uint8_t
52 {
53 SHIFT_NONE,
54 SHIFT_POSITIVE_BOUNDS,
55 SHIFT_NEGATIVE_BOUNDS
56 };
57
58 explicit Anchor(fge::Object* owner);
59 Anchor(fge::Object* owner, Anchor const& anchor);
60 Anchor(Anchor const& r) = delete;
61 Anchor(Anchor&& r) noexcept = delete;
62 virtual ~Anchor();
63
64 Anchor& operator=(Anchor const& r);
65 Anchor& operator=(Anchor&& r) noexcept = delete;
66
67 void updateAnchor(fge::Vector2f const& customTargetSize = {0.0f, 0.0f});
68
69 void setAnchor(Types type, fge::Vector2<Shifts> const& shift, fge::ObjectSid target = FGE_SCENE_BAD_SID);
70
71 void setAnchorType(Types type);
72 void setAnchorShift(fge::Vector2<Shifts> const& shift);
73 void setAnchorTarget(fge::ObjectSid target);
74
75 [[nodiscard]] Types getAnchorType() const;
76 [[nodiscard]] fge::Vector2<Shifts> const& getAnchorShift() const;
77 [[nodiscard]] fge::ObjectSid getAnchorTarget() const;
78 [[nodiscard]] fge::Object* getAnchorOwner() const;
79
80 void setAnchorSuccessor(fge::ObjectDataWeak successor);
81 [[nodiscard]] fge::ObjectDataWeak getAnchorSuccessor() const;
82
83 void needAnchorUpdate(bool flag);
84 [[nodiscard]] bool isNeedingAnchorUpdate() const;
85
86private:
87 Types g_anchorType{Types::ANCHOR_NONE};
88 fge::Vector2<Shifts> g_anchorShift{Shifts::SHIFT_NONE, Shifts::SHIFT_NONE};
89 fge::ObjectSid g_anchorTarget{FGE_SCENE_BAD_SID};
90 bool g_anchorNeedUpdate{true};
91 fge::ObjectDataWeak g_anchorSuccessor;
92 fge::Object* g_anchorOwner;
93};
94
95} // namespace fge
96
97#endif // _FGE_C_OBJECTANCHOR_HPP_INCLUDED
Definition C_objectAnchor.hpp:40
The Object class is the base class for all objects in the engine.
Definition C_object.hpp:102