neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
canvas.hpp
Go to the documentation of this file.
1// canvas.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2015, 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>
23#include <neogfx/game/ecs.hpp>
24
25namespace neogfx::game
26{
27 class canvas : public widget<>
28 {
29 public:
30 define_event(RenderingEntities, rendering_entities, i_graphics_context&, int32_t)
32 define_event(EntityClicked, entity_clicked, entity_id)
34 public:
35 struct no_ecs : std::logic_error { no_ecs() : std::logic_error{ "neogfx::game::canvas::no_ecs" } {} };
36 struct invalid_layer : std::logic_error { invalid_layer() : std::logic_error{ "neogfx::game::canvas::invalid_layer" } {} };
37 public:
40 canvas(std::shared_ptr<game::i_ecs> aEcs);
41 canvas(i_widget& aParent);
42 canvas(i_widget& aParent, game::i_ecs& aEcs);
43 canvas(i_widget& aParent, std::shared_ptr<game::i_ecs> aEcs);
44 canvas(i_layout& aLayout);
45 canvas(i_layout& aLayout, game::i_ecs& aEcs);
46 canvas(i_layout& aLayout, std::shared_ptr<game::i_ecs> aEcs);
48 public:
49 bool have_ecs() const;
50 game::i_ecs& ecs() const;
51 void set_ecs(game::i_ecs& aEcs);
52 void set_ecs(const std::shared_ptr<game::i_ecs>& aEcs);
53 int32_t layers();
54 void set_layers(int32_t aLayers);
55 bool layer_visible(int32_t aLayer) const;
56 void show_layer(int32_t aLayer);
57 void hide_layer(int32_t aLayer);
58 public:
60 public:
61 void mouse_button_pressed(mouse_button aButton, const point& aPosition, key_modifiers_e aKeyModifiers) override;
62 void mouse_button_double_clicked(mouse_button aButton, const point& aPosition, key_modifiers_e aKeyModifiers) override;
63 private:
64 void init();
65 private:
66 std::shared_ptr<game::i_ecs> iEcs;
67 std::vector<bool> iLayers;
68 sink iSink;
69 std::optional<widget_timer> iUpdater;
70 bool iEcsPaused;
71 };
72}
73
74namespace neogfx
75{
76 using game::canvas;
77}
canvas(i_widget &aParent)
canvas(i_layout &aLayout, std::shared_ptr< game::i_ecs > aEcs)
void hide_layer(int32_t aLayer)
game::i_ecs & ecs() const
neogfx::logical_coordinate_system logical_coordinate_system() const override
void mouse_button_pressed(mouse_button aButton, const point &aPosition, key_modifiers_e aKeyModifiers) override
canvas(i_widget &aParent, game::i_ecs &aEcs)
define_event(RenderingEntities, rendering_entities, i_graphics_context &, int32_t) define_event(EntitiesRendered
canvas(i_layout &aLayout, game::i_ecs &aEcs)
bool have_ecs() const
bool layer_visible(int32_t aLayer) const
void set_ecs(game::i_ecs &aEcs)
void show_layer(int32_t aLayer)
canvas(i_layout &aLayout)
i_graphics_context int32_t entity_double_clicked
Definition canvas.hpp:33
canvas(game::i_ecs &aEcs)
canvas(i_widget &aParent, std::shared_ptr< game::i_ecs > aEcs)
canvas(std::shared_ptr< game::i_ecs > aEcs)
void set_layers(int32_t aLayers)
void mouse_button_double_clicked(mouse_button aButton, const point &aPosition, key_modifiers_e aKeyModifiers) override
void set_ecs(const std::shared_ptr< game::i_ecs > &aEcs)
logical_coordinate_system
mouse_button
Definition i_mouse.hpp:31
id_t entity_id
Definition ecs_ids.hpp:51
Definition plf_hive.h:79
#define define_event(name, declName,...)
Definition event.hpp:200