Gorgon Game Engine
Line.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "AnimationStorage.h"
4 #include "../Graphics/Line.h"
5 
6 
7 namespace Gorgon { namespace Resource {
8  class File;
9  class Reader;
10 
17  public:
19  explicit Line(Graphics::BitmapLineProvider &prov);
20 
23 
25  explicit Line(Graphics::LineProvider &prov);
26 
28  explicit Line(Graphics::BitmapLineProvider &&prov) : Line(*new Graphics::BitmapLineProvider(std::move(prov))) {
29  own = true;
30  }
31 
34  own = true;
35  }
36 
38  explicit Line(Graphics::LineProvider &&prov) : Line(*new Graphics::LineProvider(std::move(prov))) {
39  own = true;
40  }
41 
44 
45  ILineProvider &MoveOutProvider() override;
46 
47  GID::Type GetGID() const override {
48  return GID::Line;
49  }
50 
54  prov = &value;
55  }
56 
60  prov = &value;
61  }
62 
66  prov = &value;
67  }
68 
72  prov = &value;
73  own = true;
74  }
75 
79  prov = &value;
80  own = true;
81  }
82 
86  prov = &value;
87  own = true;
88  }
89 
91  void RemoveProvider() {
92  if(own)
93  delete prov;
94 
95  own = false;
96 
97  prov = nullptr;
98  }
99 
100  virtual Graphics::RectangularAnimation &CreateStart() const override {
101  if(!prov)
102  throw std::runtime_error("Provider is not set.");
103 
104  return prov->CreateStart();
105  }
106 
107  virtual Graphics::RectangularAnimation &CreateMiddle() const override {
108  if(!prov)
109  throw std::runtime_error("Provider is not set.");
110 
111  return prov->CreateMiddle();
112  }
113 
114  virtual Graphics::RectangularAnimation &CreateEnd() const override {
115  if(!prov)
116  throw std::runtime_error("Provider is not set.");
117 
118  return prov->CreateEnd();
119  }
120 
121  virtual void SetOrientation(Graphics::Orientation value) override {
122  if(!prov)
123  throw std::runtime_error("Provider is not set.");
124 
125  prov->SetOrientation(value);
126  }
127 
128  virtual Graphics::Orientation GetOrientation() const override {
129  if(!prov)
130  throw std::runtime_error("Provider is not set.");
131 
132  return prov->GetOrientation();
133  }
134 
135  virtual void SetTiling(bool value) override {
136  if(!prov)
137  throw std::runtime_error("Provider is not set.");
138 
139  prov->SetTiling(value);
140  }
141 
142  virtual bool GetTiling() const override {
143  if(!prov)
144  throw std::runtime_error("Provider is not set.");
145 
146  return prov->GetTiling();
147  }
148 
150  if(!prov)
151  throw std::runtime_error("Provider is not set.");
152 
153  return dynamic_cast<Gorgon::Graphics::Line &>(prov->CreateAnimation(timer));
154  }
155 
156  virtual Gorgon::Graphics::Line &CreateAnimation(bool create=true) const override {
157  if(!prov)
158  throw std::runtime_error("Provider is not set.");
159 
160  return dynamic_cast<Gorgon::Graphics::Line &>(prov->CreateAnimation(create));
161  }
162 
163  virtual Geometry::Size GetSize() const override {
164  if(!prov)
165  throw std::runtime_error("Provider is not set.");
166 
167  return prov->GetSize();
168  }
169 
171  static Line *LoadResource(std::weak_ptr<File> file, std::shared_ptr<Reader> reader, unsigned long size);
172 
173  static void SaveThis(Writer &writer, const Graphics::ILineProvider &provider);
174 
175  protected:
176  void save(Writer &writer) const override;
177 
179 
180  private:
181  virtual ~Line() {
182  if(own)
183  delete prov;
184  }
185 
186  ILineProvider *prov = nullptr;
187 
188  bool own = false;
189  };
190 
191 } }
Gorgon::Resource::Line::AssumeProvider
void AssumeProvider(Graphics::BitmapLineProvider &value)
Changes the provider stored in this line, ownership will be transferred.
Definition: Line.h:70
Gorgon::Graphics::Orientation
Orientation
2D orientation constants
Definition: Graphics.h:39
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::Line::Line
Line(Graphics::AnimatedBitmapLineProvider &&prov)
Creates a new line using another line provider.
Definition: Line.h:33
Gorgon::Resource::Line::CreateAnimation
virtual Gorgon::Graphics::Line & CreateAnimation(bool create=true) const override
This function should create and animation and depending on the create parameter, it should create its...
Definition: Line.h:156
Gorgon::Resource::GID::File
constexpr Type File
File.
Definition: GID.h:84
Gorgon::Resource::Line::RemoveProvider
void RemoveProvider()
Removes the provider, if it is owned by this resource it will be deleted.
Definition: Line.h:91
Gorgon::Resource::Line::GetTiling
virtual bool GetTiling() const override
Returns if the middle part will be tiled.
Definition: Line.h:142
Gorgon::Resource::Line::Line
Line(Graphics::BitmapLineProvider &&prov)
Creates a new line using another line provider.
Definition: Line.h:28
Gorgon::Resource::Line::CreateAnimation
virtual Gorgon::Graphics::Line & 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: Line.h:149
Gorgon::Graphics::LineProvider
basic_LineProvider< RectangularAnimationProvider > LineProvider
Definition: Line.h:362
Gorgon::Resource::Line::SetOrientation
virtual void SetOrientation(Graphics::Orientation value) override
Changes the orientation of the provider.
Definition: Line.h:121
Gorgon::Animation::ControllerBase
Controllers are required to progress animations.
Definition: Animation.h:65
Gorgon::Resource::Line::SaveThis
static void SaveThis(Writer &writer, const Graphics::ILineProvider &provider)
Definition: Line.cpp:175
Gorgon::Resource::Line
This is a line resource, it stores a Graphics::LineProvider.
Definition: Line.h:16
Gorgon::Resource::Line::AssumeProvider
void AssumeProvider(Graphics::LineProvider &value)
Changes the provider stored in this line, ownership will be transferred.
Definition: Line.h:84
Gorgon::Resource::Line::CreateMiddle
virtual Graphics::RectangularAnimation & CreateMiddle() const override
Creates a start animation without controller. This function should always return an animation.
Definition: Line.h:107
Gorgon::Resource::Line::SetProvider
void SetProvider(Graphics::BitmapLineProvider &value)
Changes the provider stored in this line, ownership will not be transferred.
Definition: Line.h:52
Gorgon::Resource::Line::Line
Line(Graphics::LineProvider &&prov)
Creates a new line using another line provider.
Definition: Line.h:38
Gorgon::Resource::Line::SetTiling
virtual void SetTiling(bool value) override
Sets whether the middle part would be tiled.
Definition: Line.h:135
Gorgon::Resource::Line::AssumeProvider
void AssumeProvider(Graphics::AnimatedBitmapLineProvider &value)
Changes the provider stored in this line, ownership will be transferred.
Definition: Line.h:77
Gorgon::Resource::GID::Line
constexpr Type Line
Definition: GID.h:234
Gorgon::Resource::Line::SetProvider
void SetProvider(Graphics::AnimatedBitmapLineProvider &value)
Changes the provider stored in this line, ownership will not be transferred.
Definition: Line.h:58
Gorgon::Resource::Line::GetSize
virtual Geometry::Size GetSize() const override
Definition: Line.h:163
Gorgon::Resource::Line::save
void save(Writer &writer) const override
Definition: Line.cpp:156
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::Line::MoveOutProvider
ILineProvider & MoveOutProvider() override
This function moves this animation provider into a new provider.
Definition: Line.cpp:236
Gorgon::Resource::Line::CreateEnd
virtual Graphics::RectangularAnimation & CreateEnd() const override
Creates a start animation without controller. This function should always return an animation.
Definition: Line.h:114
Gorgon::Graphics::Line
This class allows drawing a line like image that is made out of three parts.
Definition: Line.h:61
Gorgon::Resource::Line::GetGID
GID::Type GetGID() const override
This function shall return Gorgon ID of this resource.
Definition: Line.h:47
Gorgon::Graphics::basic_LineProvider::CreateEnd
virtual RectangularAnimation & CreateEnd() const override
Creates a start animation without controller. This function should always return an animation.
Definition: Line.h:235
Gorgon::Resource::Line::Line
Line()
Creates a new empty line.
Definition: Line.h:43
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::Graphics::BitmapLineProvider
basic_LineProvider< Bitmap > BitmapLineProvider
Definition: Line.h:363
AnimationStorage.h
Gorgon::Graphics::ILineProvider
Interface for LineProviders.
Definition: Line.h:12
Gorgon::Graphics::basic_LineProvider
This class allows instancing of a line like image that is made out of three parts.
Definition: Line.h:162
Gorgon::Graphics::basic_LineProvider::CreateAnimation
Line & 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: Line.h:213
Gorgon::Graphics::ILineProvider::GetTiling
virtual bool GetTiling() const
Returns if the middle part will be tiled.
Definition: Line.h:47
Gorgon::Resource::Line::LoadResource
static Line * LoadResource(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long size)
This function loads a line resource from the file.
Definition: Line.cpp:44
Gorgon::Resource::Writer
This class allows resource objects to save their data to a stream.
Definition: Writer.h:59
Gorgon::Graphics::AnimatedBitmapLineProvider
basic_LineProvider< BitmapAnimationProvider > AnimatedBitmapLineProvider
Definition: Line.h:364
Gorgon::Resource::Line::SetProvider
void SetProvider(Graphics::LineProvider &value)
Changes the provider stored in this line, ownership will not be transferred.
Definition: Line.h:64
Gorgon::Graphics::ILineProvider::SetOrientation
virtual void SetOrientation(Orientation value)
Changes the orientation of the provider.
Definition: Line.h:30
Gorgon::Resource::Line::GetOrientation
virtual Graphics::Orientation GetOrientation() const override
Returns the orientation of the line provider.
Definition: Line.h:128
Gorgon::UI::Graphics
@ Graphics
Definition: Template.h:164
Gorgon::Graphics::ILineProvider::GetOrientation
virtual Orientation GetOrientation() const
Returns the orientation of the line provider.
Definition: Line.h:35
Gorgon::Graphics::basic_LineProvider::GetSize
Geometry::Size GetSize() const override
Definition: Line.h:306
Gorgon::Graphics::ILineProvider::SetTiling
virtual void SetTiling(bool value)
Sets whether the middle part would be tiled.
Definition: Line.h:42
Gorgon::Graphics::basic_LineProvider::CreateStart
virtual RectangularAnimation & CreateStart() const override
Creates a start animation without controller. This function should always return an animation.
Definition: Line.h:221
Gorgon::Resource::GID::Type
Type to store GID information.
Definition: GID.h:23
Gorgon::Resource::Line::animmoveout
virtual Graphics::RectangularAnimationStorage animmoveout() override
Definition: Line.cpp:232
Gorgon::Input::Mouse::Horizontal
@ Horizontal
Definition: Mouse.h:76
Gorgon::Graphics::basic_LineProvider::CreateMiddle
virtual RectangularAnimation & CreateMiddle() const override
Creates a start animation without controller. This function should always return an animation.
Definition: Line.h:228
Gorgon::Graphics::ILineProvider::ILineProvider
ILineProvider(Orientation orientation)
Definition: Line.h:14
Gorgon::Resource::Line::CreateStart
virtual Graphics::RectangularAnimation & CreateStart() const override
Creates a start animation without controller. This function should always return an animation.
Definition: Line.h:100