neoGFX
C++ GPU-oriented GUI library and app/game creation framework.
i_shape.hpp
Go to the documentation of this file.
1 // i_shape.hpp
2 /*
3  neogfx C++ GUI Library
4  Copyright (c) 2015 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>
22 #include <chrono>
23 #include <boost/optional.hpp>
26 #include <neogfx/core/colour.hpp>
27 #include <neogfx/gfx/texture.hpp>
29 #include <neogfx/game/i_mesh.hpp>
30 
31 namespace neogfx
32 {
33  class graphics_context;
34 
36  {
37  public:
38  virtual bool has_extents() const = 0;
39  virtual size extents() const = 0;
40  virtual const optional_colour_or_gradient& colour() const = 0;
41  virtual void set_colour(const optional_colour_or_gradient& aColour) = 0;
42  virtual texture_list_pointer textures() const = 0;
43  virtual void set_textures(texture_list_pointer aTextures) = 0;
44  virtual const optional_mat33& transformation() const = 0;
45  virtual void set_transformation(const optional_mat33& aTransformation) = 0;
46  };
47 
48  class i_widget;
49  class i_shape;
50 
52  {
53  public:
54  virtual const i_widget& as_widget() const = 0;
55  virtual i_widget& as_widget() = 0;
56  };
57 
58  class i_shape : public virtual i_game_object, public virtual i_mesh
59  {
60  // types
61  public:
62  typedef std::size_t frame_index;
64  typedef std::pair<frame_index, time_interval> animation_frame;
65  typedef std::vector<animation_frame> animation_frames;
66  typedef boost::optional<time_interval> optional_time_interval;
67  // exceptions
68  public:
69  struct no_shape_container : std::logic_error { no_shape_container() : std::logic_error("neogfx::i_shape::no_shape_container") {} };
70  struct not_a_tag : std::logic_error { not_a_tag() : std::logic_error("neogfx::i_shape::not_a_tag") {} };
71  struct bad_frame_index : std::logic_error { bad_frame_index() : std::logic_error("neogfx::i_shape::bad_frame_index") {} };
72  // construction
73  public:
74  virtual ~i_shape() {}
75  // container
76  public:
77  virtual const i_shape_container& container() const = 0;
78  virtual i_shape_container& container() = 0;
79  // tag
80  public:
81  virtual bool is_tag() const = 0;
82  virtual i_shape& tag_of() const = 0;
83  virtual void set_tag_of(i_shape& aTagOf, const vec3& aOffset = vec3{}) = 0;
84  virtual const vec3& tag_offset() const = 0;
85  virtual void set_tag_offset(const vec3& aOffset) = 0;
86  virtual void unset_tag_of() = 0;
87  // animation
88  public:
89  virtual frame_index frame_count() const = 0;
90  virtual const i_shape_frame& shape_frame(frame_index aFrameIndex) const = 0;
91  virtual i_shape_frame& shape_frame(frame_index aFrameIndex) = 0;
92  virtual void add_frame(i_shape_frame& aFrame) = 0;
93  virtual void add_frame(std::shared_ptr<i_shape_frame> aFrame) = 0;
94  virtual void replace_frame(frame_index aFrameIndex, i_shape_frame& aFrame) = 0;
95  virtual void replace_frame(frame_index aFrameIndex, std::shared_ptr<i_shape_frame> aFrame) = 0;
96  virtual void remove_frame(frame_index aFrameIndex) = 0;
97  // geometry
98  public:
99  virtual const animation_frames& animation() const = 0;
100  virtual bool repeat_animation() const = 0;
101  virtual const animation_frame& current_animation_frame() const = 0;
102  virtual bool has_animation_finished() const = 0;
103  virtual void animation_finished() = 0;
104  virtual frame_index current_frame_index() const = 0;
105  virtual const i_shape_frame& current_frame() const = 0;
106  virtual i_shape_frame& current_frame() = 0;
107  virtual vec3 origin() const = 0;
108  virtual vec3 position() const = 0;
109  virtual vec3 extents() const = 0;
110  virtual rect bounding_box_2d(bool aWithPosition = true) const = 0;
111  virtual void set_animation(const animation_frames& aAnimation) = 0;
112  virtual void set_current_frame(frame_index aFrameIndex) = 0;
113  virtual void set_origin(const vec3& aOrigin) = 0;
114  virtual void set_position(const vec3& aPosition) = 0;
115  virtual void clear_extents() = 0;
116  virtual void set_extents(const vec3& aExtents) = 0;
117  virtual bool has_transformation_matrix() const = 0;
118  virtual void clear_transformation_matrix() = 0;
119  virtual void set_transformation_matrix(const mat33& aTransformationMatrix) = 0;
120  virtual void set_transformation_matrix(const mat44& aTransformationMatrix) = 0;
121  // rendering
122  public:
123  virtual bool update(time_interval aNow) = 0;
124  virtual void paint(graphics_context& aGraphicsContext) const = 0;
125  // helpers
126  public:
127  void set_origin(const vec2& aOrigin)
128  {
129  set_origin(vec3{ aOrigin.x, aOrigin.y, 0.0 });
130  }
131  void set_origin(const point& aOrigin)
132  {
133  set_origin(vec3{ aOrigin.x, aOrigin.y, 0.0 });
134  }
135  void set_position(const vec2& aPosition)
136  {
137  set_position(vec3{ aPosition.x, aPosition.y, 0.0 });
138  }
139  void set_position(const point& aPosition)
140  {
141  set_position(vec3{ aPosition.x, aPosition.y, 0.0 });
142  }
143  void set_extents(const vec2& aExtents)
144  {
145  set_extents(vec3{ aExtents.x, aExtents.y, 0.0 });
146  }
147  void set_extents(const size& aExtents)
148  {
149  set_extents(vec3{ aExtents.cx, aExtents.cy, 0.0 });
150  }
151  };
152 }
virtual texture_list_pointer textures() const =0
std::size_t frame_index
Definition: i_shape.hpp:62
virtual const optional_mat33 & transformation() const =0
boost::optional< mat33 > optional_mat33
Definition: numerical.hpp:638
coordinate_type x
double scalar
Definition: numerical.hpp:34
boost::optional< colour_or_gradient > optional_colour_or_gradient
Definition: colour.hpp:929
void set_extents(const size &aExtents)
Definition: i_shape.hpp:147
virtual ~i_shape()
Definition: i_shape.hpp:74
scalar time_interval
Definition: i_shape.hpp:63
void set_origin(const vec2 &aOrigin)
Definition: i_shape.hpp:127
void set_position(const point &aPosition)
Definition: i_shape.hpp:139
dimension_type cx
std::vector< animation_frame > animation_frames
Definition: i_shape.hpp:65
void set_extents(const vec2 &aExtents)
Definition: i_shape.hpp:143
virtual void set_textures(texture_list_pointer aTextures)=0
virtual void set_transformation(const optional_mat33 &aTransformation)=0
virtual void set_colour(const optional_colour_or_gradient &aColour)=0
dimension_type cy
std::shared_ptr< texture_list > texture_list_pointer
Definition: texture.hpp:69
void set_origin(const point &aOrigin)
Definition: i_shape.hpp:131
std::pair< frame_index, time_interval > animation_frame
Definition: i_shape.hpp:64
virtual const optional_colour_or_gradient & colour() const =0
coordinate_type y
virtual bool has_extents() const =0
void set_position(const vec2 &aPosition)
Definition: i_shape.hpp:135
boost::optional< time_interval > optional_time_interval
Definition: i_shape.hpp:66
virtual size extents() const =0