neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
rectangle.hpp
Go to the documentation of this file.
1// rectangle.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2018, 2020 Leigh Johnston. All Rights Reserved.
5
6 This program is free software: you can redistribute it and / or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19#pragma once
20
21#include <neogfx/neogfx.hpp>
24#include <neogfx/gfx/color.hpp>
31#include <neogfx/gfx/shapes.hpp>
32
33namespace neogfx::game
34{
35 struct rectangle
36 {
40
42 {
43 static const neolib::uuid& id()
44 {
45 static const neolib::uuid sId = { 0x6f45d8be, 0xba9c, 0x4a32, 0xa99e, { 0x37, 0xd3, 0xf2, 0xb4, 0xe7, 0x53 } };
46 return sId;
47 }
48 static const i_string& name()
49 {
50 static const string sName = "Rectangle";
51 return sName;
52 }
53 static uint32_t field_count()
54 {
55 return 3;
56 }
57 static component_data_field_type field_type(uint32_t aFieldIndex)
58 {
59 switch (aFieldIndex)
60 {
61 case 0:
62 return component_data_field_type::Vec3;
63 case 1:
64 return component_data_field_type::Vec2;
65 case 2:
66 return component_data_field_type::ComponentData | component_data_field_type::Optional;
67 default:
68 throw invalid_field_index();
69 }
70 }
71 static const i_string& field_name(uint32_t aFieldIndex)
72 {
73 static const string sFieldNames[] =
74 {
75 "Position",
76 "Extents",
77 "Material"
78 };
79 return sFieldNames[aFieldIndex];
80 }
81 static constexpr bool has_updater = true;
82 static void update(const rectangle& aData, i_ecs& aEcs, entity_id aEntity)
83 {
85 thread_local game::mesh rectMesh;
86 aEcs.component<mesh>().populate(aEntity, to_ecs_component(rectMesh, rect{ point{ ~aData.position.xy - aData.extents / 2.0 }, size{aData.extents} }));
87 aEcs.component<material>().populate(aEntity, aData.material);
88 }
89 };
90 };
91
92 namespace shape
93 {
94 class rectangle : public entity
95 {
96 public:
97 static const entity_archetype& archetype(i_ecs& aEcs)
98 {
100 static const renderable_entity_archetype sArchetype
101 {
102 { 0xce3d930, 0x6b18, 0x403b, 0x9680, { 0x89, 0xed, 0x54, 0x83, 0xd5, 0x72 } },
103 "Rectangle",
105 };
106 if (!aEcs.archetype_registered(sArchetype))
107 aEcs.register_archetype(sArchetype);
108 return sArchetype;
109 }
110 public:
111 rectangle(i_ecs& aEcs, const vec3& aPosition, const vec2& aExtents);
112 rectangle(i_ecs& aEcs, const vec3& aPosition, const vec2& aExtents, const neogfx::color& aColor);
113 rectangle(i_ecs& aEcs, const vec3& aPosition, const vec2& aExtents, const i_texture& aTexture);
114 rectangle(i_ecs& aEcs, const vec3& aPosition, const vec2& aExtents, const i_image& aImage);
115 rectangle(i_ecs& aEcs, const vec3& aPosition, const vec2& aExtents, const i_texture& aTexture, const rect& aTextureRect);
116 rectangle(i_ecs& aEcs, const vec3& aPosition, const vec2& aExtents, const i_image& aImage, const rect& aTextureRect);
117 rectangle(const rectangle& aOther);
118 };
119 }
120}
rectangle(i_ecs &aEcs, const vec3 &aPosition, const vec2 &aExtents, const i_texture &aTexture)
rectangle(const rectangle &aOther)
static const entity_archetype & archetype(i_ecs &aEcs)
Definition rectangle.hpp:97
rectangle(i_ecs &aEcs, const vec3 &aPosition, const vec2 &aExtents, const i_image &aImage, const rect &aTextureRect)
rectangle(i_ecs &aEcs, const vec3 &aPosition, const vec2 &aExtents)
rectangle(i_ecs &aEcs, const vec3 &aPosition, const vec2 &aExtents, const i_texture &aTexture, const rect &aTextureRect)
rectangle(i_ecs &aEcs, const vec3 &aPosition, const vec2 &aExtents, const i_image &aImage)
rectangle(i_ecs &aEcs, const vec3 &aPosition, const vec2 &aExtents, const neogfx::color &aColor)
virtual const i_component & component(component_id aComponentId) const =0
virtual void register_archetype(const i_entity_archetype &aArchetype)=0
virtual bool archetype_registered(const i_entity_archetype &aArchetype) const =0
game::mesh const & to_ecs_component(game::mesh &aResult, const basic_rect< CoordinateType, CoordinateSystem > &aRect, mesh_type aMeshType=mesh_type::Triangles, optional_mat44 const &aTransformation={}, uint32_t aOffset=0)
id_t entity_id
Definition ecs_ids.hpp:51
static const neolib::uuid & id()
static const neolib::uuid & id()
static void update(const rectangle &aData, i_ecs &aEcs, entity_id aEntity)
Definition rectangle.hpp:82
static constexpr bool has_updater
Definition rectangle.hpp:81
static component_data_field_type field_type(uint32_t aFieldIndex)
Definition rectangle.hpp:57
static const i_string & name()
Definition rectangle.hpp:48
static uint32_t field_count()
Definition rectangle.hpp:53
static const i_string & field_name(uint32_t aFieldIndex)
Definition rectangle.hpp:71
static const neolib::uuid & id()
Definition rectangle.hpp:43