Gorgon Game Engine
Rectangle.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "AnimationStorage.h"
4 #include "../Graphics/Rectangle.h"
5 
6 
7 namespace Gorgon { namespace Resource {
8  class File;
9  class Reader;
10 
12  public:
15 
18 
20  explicit Rectangle(Graphics::RectangleProvider &prov);
21 
24  own = true;
25  }
26 
29  own = true;
30  }
32  explicit Rectangle(Graphics::RectangleProvider &&prov) : Rectangle(*new Graphics::RectangleProvider(std::move(prov))) {
33  own = true;
34  }
35 
37  Rectangle() = default;
38 
40 
41  GID::Type GetGID() const override {
42  return GID::Rectangle;
43  }
44 
48  prov = &value;
49  }
50 
54  prov = &value;
55  }
56 
60  prov = &value;
61  }
62 
66  prov = &value;
67  own = true;
68  }
69 
73  prov = &value;
74  own = true;
75  }
76 
80  prov = &value;
81  own = true;
82  }
83 
85  void RemoveProvider() {
86  if(own)
87  delete prov;
88 
89  own = false;
90 
91  prov = nullptr;
92  }
93 
94  virtual Graphics::RectangularAnimation &CreateTL() const override {
95  if(!prov)
96  throw std::runtime_error("Provider is not set.");
97 
98  return prov->CreateTL();
99  }
100 
101  virtual Graphics::RectangularAnimation &CreateTM() const override {
102  if(!prov)
103  throw std::runtime_error("Provider is not set.");
104 
105  return prov->CreateTM();
106  }
107 
108  virtual Graphics::RectangularAnimation &CreateTR() const override {
109  if(!prov)
110  throw std::runtime_error("Provider is not set.");
111 
112  return prov->CreateTR();
113  }
114 
115  virtual Graphics::RectangularAnimation &CreateML() const override {
116  if(!prov)
117  throw std::runtime_error("Provider is not set.");
118 
119  return prov->CreateML();
120  }
121 
122  virtual Graphics::RectangularAnimation &CreateMM() const override {
123  if(!prov)
124  throw std::runtime_error("Provider is not set.");
125 
126  return prov->CreateMM();
127  }
128 
129  virtual Graphics::RectangularAnimation &CreateMR() const override {
130  if(!prov)
131  throw std::runtime_error("Provider is not set.");
132 
133  return prov->CreateMR();
134  }
135 
136  virtual Graphics::RectangularAnimation &CreateBL() const override {
137  if(!prov)
138  throw std::runtime_error("Provider is not set.");
139 
140  return prov->CreateBL();
141  }
142 
143  virtual Graphics::RectangularAnimation &CreateBM() const override {
144  if(!prov)
145  throw std::runtime_error("Provider is not set.");
146 
147  return prov->CreateBM();
148  }
149 
150  virtual Graphics::RectangularAnimation &CreateBR() const override {
151  if(!prov)
152  throw std::runtime_error("Provider is not set.");
153 
154  return prov->CreateBR();
155  }
156 
157  virtual void SetCenterTiling(bool value) override {
158  if(!prov)
159  throw std::runtime_error("Provider is not set.");
160 
161  prov->SetCenterTiling(value);
162  }
163 
164  virtual bool GetCenterTiling() const override {
165  if(!prov)
166  throw std::runtime_error("Provider is not set.");
167 
168  return prov->GetCenterTiling();
169  }
170 
171  virtual void SetSideTiling(bool value) override {
172  if(!prov)
173  throw std::runtime_error("Provider is not set.");
174 
175  prov->SetSideTiling(value);
176  }
177 
178  virtual bool GetSideTiling() const override {
179  if(!prov)
180  throw std::runtime_error("Provider is not set.");
181 
182  return prov->GetSideTiling();
183  }
184 
186  if(!prov)
187  throw std::runtime_error("Provider is not set.");
188 
189  return dynamic_cast<Gorgon::Graphics::Rectangle &>(prov->CreateAnimation(timer));
190  }
191 
192  virtual Gorgon::Graphics::Rectangle &CreateAnimation(bool create=true) const override {
193  if(!prov)
194  throw std::runtime_error("Provider is not set.");
195 
196  return dynamic_cast<Gorgon::Graphics::Rectangle &>(prov->CreateAnimation(create));
197  }
198 
199  virtual Geometry::Size GetSize() const override {
200  if(!prov)
201  throw std::runtime_error("Provider is not set.");
202 
203  return prov->GetSize();
204  }
205 
207  static Rectangle *LoadResource(std::weak_ptr<File> file, std::shared_ptr<Reader> reader, unsigned long size);
208 
209  static void SaveThis(Writer &writer, const Graphics::IRectangleProvider &provider);
210 
211 
212  protected:
213  void save(Writer &writer) const override;
214 
216 
217  private:
218  virtual ~Rectangle() {
219  if(own)
220  delete prov;
221  }
222 
223  IRectangleProvider *prov = nullptr;
224 
225  bool own = false;
226  };
227 
228 } }
Gorgon::Graphics::basic_RectangleProvider::CreateMM
virtual RectangularAnimation & CreateMM() const override
Creates an animation without controller. This function should always return an animation.
Definition: Rectangle.h:360
Gorgon::Animation::basic_Storage
This class stores animations as a part of itself so that it can be moved around as a value rather tha...
Definition: Storage.h:21
Gorgon::Resource::Rectangle::Rectangle
Rectangle(Graphics::AnimatedBitmapRectangleProvider &&prov)
Creates a new rectangle using another rectangle provider.
Definition: Rectangle.h:28
Gorgon::Resource::Rectangle::Rectangle
Rectangle(Graphics::RectangleProvider &&prov)
Creates a new rectangle using another rectangle provider.
Definition: Rectangle.h:32
Gorgon::Resource::GID::File
constexpr Type File
File.
Definition: GID.h:84
Gorgon::Graphics::basic_RectangleProvider::CreateML
virtual RectangularAnimation & CreateML() const override
Creates an animation without controller. This function should always return an animation.
Definition: Rectangle.h:352
Gorgon::Resource::Rectangle::Rectangle
Rectangle(Graphics::BitmapRectangleProvider &&prov)
Creates a new rectangle using another rectangle provider.
Definition: Rectangle.h:23
Gorgon::Graphics::IRectangleProvider::GetSideTiling
virtual bool GetSideTiling() const
Returns if the middle part will be tiled.
Definition: Rectangle.h:65
Gorgon::Resource::Rectangle::SetSideTiling
virtual void SetSideTiling(bool value) override
Sets whether the side parts (tm, ml, mr, bm) would be tiled.
Definition: Rectangle.h:171
Gorgon::Resource::Rectangle::CreateML
virtual Graphics::RectangularAnimation & CreateML() const override
Creates an animation without controller. This function should always return an animation.
Definition: Rectangle.h:115
Gorgon::Resource::Rectangle::CreateAnimation
virtual Gorgon::Graphics::Rectangle & CreateAnimation(bool create=true) const override
This function should create and animation and depending on the create parameter, it should create its...
Definition: Rectangle.h:192
Gorgon::Resource::Rectangle::GetSideTiling
virtual bool GetSideTiling() const override
Returns if the middle part will be tiled.
Definition: Rectangle.h:178
Gorgon::Animation::ControllerBase
Controllers are required to progress animations.
Definition: Animation.h:65
Gorgon::Graphics::IRectangleProvider::GetCenterTiling
virtual bool GetCenterTiling() const
Returns if the middle part will be tiled.
Definition: Rectangle.h:53
Gorgon::Resource::Rectangle::CreateBL
virtual Graphics::RectangularAnimation & CreateBL() const override
Creates an animation without controller. This function should always return an animation.
Definition: Rectangle.h:136
Gorgon::Resource::Rectangle::Rectangle
Rectangle()=default
Creates an empty rectangle.
Gorgon::Resource::Rectangle::CreateTM
virtual Graphics::RectangularAnimation & CreateTM() const override
Creates an animation without controller. This function should always return an animation.
Definition: Rectangle.h:101
Gorgon::Graphics::IRectangleProvider
Interface for RectangleProviders.
Definition: Rectangle.h:12
Gorgon::Resource::Rectangle::SetProvider
void SetProvider(Graphics::AnimatedBitmapRectangleProvider &value)
Changes provider to the given provider, ownership will not be transferred.
Definition: Rectangle.h:52
Gorgon::Resource::Rectangle::AssumeProvider
void AssumeProvider(Graphics::RectangleProvider &value)
Changes the provider stored in this line, ownership will be transferred.
Definition: Rectangle.h:78
Gorgon::Resource::Rectangle::AssumeProvider
void AssumeProvider(Graphics::BitmapRectangleProvider &value)
Changes the provider stored in this line, ownership will be transferred.
Definition: Rectangle.h:64
Gorgon::Resource::Rectangle::LoadResource
static Rectangle * LoadResource(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long size)
This function loads a rectangle resource from the file.
Definition: Rectangle.cpp:83
Gorgon::Graphics::basic_RectangleProvider::GetSize
Geometry::Size GetSize() const override
Definition: Rectangle.h:545
Gorgon
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
Gorgon::Geometry::basic_Size
This class represents a 2D geometric size.
Definition: Size.h:23
Gorgon::Resource::Rectangle::GetGID
GID::Type GetGID() const override
This function shall return Gorgon ID of this resource.
Definition: Rectangle.h:41
Gorgon::Graphics::basic_RectangleProvider::CreateBR
virtual RectangularAnimation & CreateBR() const override
Creates an animation without controller. This function should always return an animation.
Definition: Rectangle.h:392
Gorgon::Resource::AnimationStorage
This class denotes the resource is an image animation storage.
Definition: AnimationStorage.h:12
Gorgon::Graphics::RectangularAnimation
Rectangular drawable animation.
Definition: Animations.h:19
Gorgon::Resource::Rectangle::CreateBM
virtual Graphics::RectangularAnimation & CreateBM() const override
Creates an animation without controller. This function should always return an animation.
Definition: Rectangle.h:143
AnimationStorage.h
Gorgon::Graphics::AnimatedBitmapRectangleProvider
basic_RectangleProvider< BitmapAnimationProvider > AnimatedBitmapRectangleProvider
Definition: Rectangle.h:591
Gorgon::Resource::Rectangle::CreateBR
virtual Graphics::RectangularAnimation & CreateBR() const override
Creates an animation without controller. This function should always return an animation.
Definition: Rectangle.h:150
Gorgon::Resource::Rectangle::CreateMR
virtual Graphics::RectangularAnimation & CreateMR() const override
Creates an animation without controller. This function should always return an animation.
Definition: Rectangle.h:129
Gorgon::Graphics::IRectangleProvider::SetSideTiling
virtual void SetSideTiling(bool value)
Sets whether the side parts (tm, ml, mr, bm) would be tiled.
Definition: Rectangle.h:60
Gorgon::Resource::Rectangle::SetProvider
void SetProvider(Graphics::BitmapRectangleProvider &value)
Changes provider to the given provider, ownership will not be transferred.
Definition: Rectangle.h:46
Gorgon::Resource::Rectangle::RemoveProvider
void RemoveProvider()
Removes the provider, if it is own by this resource it will be deleted.
Definition: Rectangle.h:85
Gorgon::Resource::Rectangle::CreateTR
virtual Graphics::RectangularAnimation & CreateTR() const override
Creates an animation without controller. This function should always return an animation.
Definition: Rectangle.h:108
Gorgon::Graphics::basic_RectangleProvider::CreateTR
virtual RectangularAnimation & CreateTR() const override
Creates an animation without controller. This function should always return an animation.
Definition: Rectangle.h:344
Gorgon::Resource::Rectangle::CreateMM
virtual Graphics::RectangularAnimation & CreateMM() const override
Creates an animation without controller. This function should always return an animation.
Definition: Rectangle.h:122
Gorgon::Resource::Writer
This class allows resource objects to save their data to a stream.
Definition: Writer.h:59
Gorgon::Graphics::basic_RectangleProvider::CreateAnimation
Rectangle & CreateAnimation(Gorgon::Animation::ControllerBase &timer) const override
This function should create a new animation with the given controller and if owner parameter is set t...
Definition: Rectangle.h:320
Gorgon::Resource::Rectangle::MoveOutProvider
Graphics::IRectangleProvider & MoveOutProvider() override
This function moves this animation provider into a new provider.
Definition: Rectangle.cpp:324
Gorgon::Graphics::RectangleProvider
basic_RectangleProvider< RectangularAnimationProvider > RectangleProvider
Definition: Rectangle.h:588
Gorgon::Resource::Rectangle
Definition: Rectangle.h:11
Gorgon::Resource::Rectangle::animmoveout
virtual Graphics::RectangularAnimationStorage animmoveout() override
Definition: Rectangle.cpp:320
Gorgon::Graphics::basic_RectangleProvider
This class allows instancing of a rectangle like image that is made out of three parts.
Definition: Rectangle.h:185
Gorgon::UI::Graphics
@ Graphics
Definition: Template.h:164
Gorgon::Resource::GID::Rectangle
constexpr Type Rectangle
Definition: GID.h:238
Gorgon::Resource::Rectangle::SetCenterTiling
virtual void SetCenterTiling(bool value) override
Sets whether the middle part would be tiled.
Definition: Rectangle.h:157
Gorgon::Resource::Rectangle::SetProvider
void SetProvider(Graphics::RectangleProvider &value)
Changes provider to the given provider, ownership will not be transferred.
Definition: Rectangle.h:58
Gorgon::Resource::Rectangle::CreateAnimation
virtual Gorgon::Graphics::Rectangle & CreateAnimation(Gorgon::Animation::ControllerBase &timer) const override
This function should create a new animation with the given controller and if owner parameter is set t...
Definition: Rectangle.h:185
Gorgon::Graphics::BitmapRectangleProvider
basic_RectangleProvider< Bitmap > BitmapRectangleProvider
Definition: Rectangle.h:590
Gorgon::Graphics::IRectangleProvider::IRectangleProvider
IRectangleProvider()
Definition: Rectangle.h:14
Gorgon::Graphics::basic_RectangleProvider::CreateBM
virtual RectangularAnimation & CreateBM() const override
Creates an animation without controller. This function should always return an animation.
Definition: Rectangle.h:384
Gorgon::Resource::GID::Type
Type to store GID information.
Definition: GID.h:23
Gorgon::Graphics::basic_RectangleProvider::CreateTM
virtual RectangularAnimation & CreateTM() const override
Creates an animation without controller. This function should always return an animation.
Definition: Rectangle.h:336
Gorgon::Graphics::basic_RectangleProvider::CreateTL
virtual RectangularAnimation & CreateTL() const override
Creates an animation without controller. This function should always return an animation.
Definition: Rectangle.h:328
Gorgon::Resource::Rectangle::SaveThis
static void SaveThis(Writer &writer, const Graphics::IRectangleProvider &provider)
Definition: Rectangle.cpp:250
Gorgon::Graphics::basic_RectangleProvider::CreateMR
virtual RectangularAnimation & CreateMR() const override
Creates an animation without controller. This function should always return an animation.
Definition: Rectangle.h:368
Gorgon::Graphics::basic_RectangleProvider::CreateBL
virtual RectangularAnimation & CreateBL() const override
Creates an animation without controller. This function should always return an animation.
Definition: Rectangle.h:376
Gorgon::Resource::Rectangle::CreateTL
virtual Graphics::RectangularAnimation & CreateTL() const override
Creates an animation without controller. This function should always return an animation.
Definition: Rectangle.h:94
Gorgon::Graphics::Rectangle
This class allows drawing a rectangle like image that is made out of nine parts.
Definition: Rectangle.h:79
Gorgon::Resource::Rectangle::GetCenterTiling
virtual bool GetCenterTiling() const override
Returns if the middle part will be tiled.
Definition: Rectangle.h:164
Gorgon::Resource::Rectangle::AssumeProvider
void AssumeProvider(Graphics::AnimatedBitmapRectangleProvider &value)
Changes the provider stored in this line, ownership will be transferred.
Definition: Rectangle.h:71
Gorgon::Graphics::IRectangleProvider::SetCenterTiling
virtual void SetCenterTiling(bool value)
Sets whether the middle part would be tiled.
Definition: Rectangle.h:48
Gorgon::Resource::Rectangle::save
void save(Writer &writer) const override
Definition: Rectangle.cpp:231
Gorgon::Resource::Rectangle::GetSize
virtual Geometry::Size GetSize() const override
Definition: Rectangle.h:199