-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClipComponent.h
More file actions
75 lines (65 loc) · 2.34 KB
/
Copy pathClipComponent.h
File metadata and controls
75 lines (65 loc) · 2.34 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#pragma once
#include <cstdint>
#include "DekiComponent.h"
#include "reflection/DekiProperty.h"
#include "IClipProvider.h"
#include "ISortableProvider.h"
/**
* @brief Component that clips children to a rectangular region
*
* Add this component to any object to clip its children's rendering
* to the specified width/height bounds. The clip region is centered
* on the object's position.
*
* Usage:
* @code
* auto* clip = entity->AddComponent<ClipComponent>();
* clip->width = 100;
* clip->height = 50;
* // All children will be clipped to this 100x50 region
* @endcode
*
* ClipComponents can be nested - child clips are intersected with parent clips.
*/
class ClipComponent : public DekiComponent, public IClipProvider, public ISortableProvider
{
public:
DEKI_COMPONENT(ClipComponent, DekiComponent, "Core", "063a42d4-bfe1-49b9-b620-0cbf87ad720f", "DEKI_FEATURE_CLIP")
DEKI_DESCRIPTION("Clips its children's rendering to a rectangle.")
/** @brief Width of clip region in meters */
DEKI_EXPORT
DEKI_UNIT(Distance)
float width = 6.25f;
/** @brief Height of clip region in meters */
DEKI_EXPORT
DEKI_UNIT(Distance)
float height = 6.25f;
/** @brief Sorting order for this clip region (lower = behind) */
DEKI_EXPORT
int32_t sortingOrder = 0;
ClipComponent() = default;
virtual ~ClipComponent() = default;
// ISortableProvider
int32_t GetSortingOrder() const override { return sortingOrder; }
// IClipProvider
float GetClipWidth() const override { return width; }
float GetClipHeight() const override { return height; }
/**
* @brief Get clip bounds in screen coordinates (pixels)
*
* Caller is responsible for converting meters to screen pixels and
* passing screenX/screenY accordingly; this helper just centers a
* pixel-sized rectangle on the given screen point.
*/
void GetClipBounds(int32_t screenX, int32_t screenY, int32_t pixelW, int32_t pixelH,
int32_t& outLeft, int32_t& outTop,
int32_t& outRight, int32_t& outBottom) const
{
outLeft = screenX - pixelW / 2;
outTop = screenY - pixelH / 2;
outRight = outLeft + pixelW;
outBottom = outTop + pixelH;
}
};
// Generated property metadata (after class definition for offsetof)
#include "generated/ClipComponent.gen.h"