Gorgon Game Engine
ScalableObject.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "AnimationStorage.h"
4 #include "../Graphics/ScalableObject.h"
5 
6 
7 namespace Gorgon {
8  namespace Resource {
9  class File;
10  class Reader;
11 
17  public:
20 
23 
26 
29  own = true;
30  }
31 
34  own = true;
35  }
36 
39  own = true;
40  }
41 
44 
45  IScalableObjectProvider &MoveOutProvider() override;
46 
47  GID::Type GetGID() const override {
48  return GID::ScalableObject;
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 &CreateBase() const override {
101  if(!prov)
102  throw std::runtime_error("Provider is not set.");
103 
104  return prov->CreateBase();
105  }
106 
107  virtual Graphics::SizeController GetController() const override {
108  if(!prov)
109  throw std::runtime_error("Provider is not set.");
110 
111  return prov->GetController();
112  }
113  virtual void SetController(const Graphics::SizeController &value) override {
114  if(!prov)
115  throw std::runtime_error("Provider is not set.");
116 
117  return prov->SetController(value);
118  }
119 
121  if(!prov)
122  throw std::runtime_error("Provider is not set.");
123 
124  return dynamic_cast<Gorgon::Graphics::ScalableObject &>(prov->CreateAnimation(timer));
125  }
126 
127  virtual Graphics::ScalableObject &CreateAnimation(bool create=true) const override {
128  if(!prov)
129  throw std::runtime_error("Provider is not set.");
130 
131  return dynamic_cast<Gorgon::Graphics::ScalableObject &>(prov->CreateAnimation(create));
132  }
133 
134  virtual Geometry::Size GetSize() const override {
135  if(!prov)
136  throw std::runtime_error("Provider is not set.");
137 
138  return prov->GetSize();
139  }
140 
142  static ScalableObject *LoadResource(std::weak_ptr<File> file, std::shared_ptr<Reader> reader, unsigned long size);
143 
144  static void SaveThis(Writer &writer, const Graphics::IScalableObjectProvider &provider);
145 
146  protected:
147  void save(Writer &writer) const override;
148 
150 
151  private:
152  virtual ~ScalableObject() {
153  if(own)
154  delete prov;
155  }
156 
157  IScalableObjectProvider *prov = nullptr;
158 
159  bool own = false;
160  };
161  }
162 }
Gorgon::Graphics::basic_ScalableObjectProvider::CreateAnimation
basic_ScalableObject< A_ > & CreateAnimation(bool create=true) const override
Definition: ScalableObject.h:157
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::Graphics::basic_ScalableObjectProvider::GetController
SizeController GetController() const override
Returns the size controller.
Definition: ScalableObject.h:181
Gorgon::Graphics::SizeController
This class allows control over a sizable object.
Definition: Graphics.h:161
Gorgon::Resource::GID::File
constexpr Type File
File.
Definition: GID.h:84
Gorgon::Resource::ScalableObject::ScalableObject
ScalableObject(Graphics::ScalableObjectProvider &&prov)
Creates a new tinted object using another tinted object provider.
Definition: ScalableObject.h:38
Gorgon::Resource::ScalableObject::MoveOutProvider
IScalableObjectProvider & MoveOutProvider() override
This function moves this animation provider into a new provider.
Definition: ScalableObject.cpp:209
Gorgon::Animation::ControllerBase
Controllers are required to progress animations.
Definition: Animation.h:65
Gorgon::Resource::ScalableObject::LoadResource
static ScalableObject * LoadResource(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long size)
This function loads a tinted object resource from the file.
Definition: ScalableObject.cpp:34
Gorgon::Resource::ScalableObject::CreateAnimation
virtual Graphics::ScalableObject & 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: ScalableObject.h:120
Gorgon::Resource::ScalableObject::CreateAnimation
virtual Graphics::ScalableObject & CreateAnimation(bool create=true) const override
This function should create and animation and depending on the create parameter, it should create its...
Definition: ScalableObject.h:127
Gorgon::Graphics::IScalableObjectProvider
For ease of use in resource system.
Definition: ScalableObject.h:11
Gorgon::Graphics::basic_ScalableObjectProvider::CreateBase
RectangularAnimation & CreateBase() const override
Creates a base animation without controller.
Definition: ScalableObject.h:166
Gorgon::Resource::ScalableObject::SetProvider
void SetProvider(Graphics::ScalableBitmapAnimationProvider &value)
Changes the provider stored in this tinted object, ownership will not be transferred.
Definition: ScalableObject.h:58
Gorgon::Resource::ScalableObject::SetProvider
void SetProvider(Graphics::ScalableObjectProvider &value)
Changes the provider stored in this tinted object, ownership will not be transferred.
Definition: ScalableObject.h:64
Gorgon::Resource::ScalableObject::save
void save(Writer &writer) const override
Definition: ScalableObject.cpp:133
Gorgon::Graphics::basic_ScalableObject
Definition: ScalableObject.h:26
Gorgon::Graphics::basic_ScalableObjectProvider
This object creates a scalable object from a graphic object.
Definition: ScalableObject.h:122
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::ScalableObject::GetGID
GID::Type GetGID() const override
This function shall return Gorgon ID of this resource.
Definition: ScalableObject.h:47
Gorgon::Resource::ScalableObject::animmoveout
virtual Graphics::RectangularAnimationStorage animmoveout() override
Definition: ScalableObject.cpp:205
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::ScalableObject::AssumeProvider
void AssumeProvider(Graphics::ScalableBitmapAnimationProvider &value)
Changes the provider stored in this tinted object, ownership will be transferred.
Definition: ScalableObject.h:77
AnimationStorage.h
Gorgon::Graphics::basic_ScalableObjectProvider::SetController
void SetController(const SizeController &value) override
Sets the controller.
Definition: ScalableObject.h:186
Gorgon::Graphics::ScalableObjectProvider
basic_ScalableObjectProvider< RectangularAnimationProvider > ScalableObjectProvider
Definition: ScalableObject.h:275
Gorgon::Resource::Writer
This class allows resource objects to save their data to a stream.
Definition: Writer.h:59
Gorgon::Resource::ScalableObject::AssumeProvider
void AssumeProvider(Graphics::ScalableBitmapProvider &value)
Changes the provider stored in this tinted object, ownership will be transferred.
Definition: ScalableObject.h:70
Gorgon::Resource::ScalableObject
This is a tinted object resource.
Definition: ScalableObject.h:16
Gorgon::Resource::ScalableObject::SaveThis
static void SaveThis(Writer &writer, const Graphics::IScalableObjectProvider &provider)
Definition: ScalableObject.cpp:152
Gorgon::UI::Graphics
@ Graphics
Definition: Template.h:164
Gorgon::Graphics::ScalableBitmapProvider
basic_ScalableObjectProvider< Bitmap > ScalableBitmapProvider
Definition: ScalableObject.h:281
Gorgon::Graphics::basic_ScalableObjectProvider::GetSize
Geometry::Size GetSize() const override
Definition: ScalableObject.h:209
Gorgon::Resource::ScalableObject::RemoveProvider
void RemoveProvider()
Removes the provider, if it is own by this resource it will be deleted.
Definition: ScalableObject.h:91
Gorgon::Graphics::ScalableBitmapAnimationProvider
basic_ScalableObjectProvider< BitmapAnimationProvider > ScalableBitmapAnimationProvider
Definition: ScalableObject.h:278
Gorgon::Resource::ScalableObject::ScalableObject
ScalableObject(Graphics::ScalableBitmapAnimationProvider &&prov)
Creates a new tinted object using another tinted object provider.
Definition: ScalableObject.h:33
Gorgon::Resource::ScalableObject::SetController
virtual void SetController(const Graphics::SizeController &value) override
Definition: ScalableObject.h:113
Gorgon::Resource::GID::Type
Type to store GID information.
Definition: GID.h:23
Gorgon::Resource::ScalableObject::SetProvider
void SetProvider(Graphics::ScalableBitmapProvider &value)
Changes the provider stored in this tinted object, ownership will not be transferred.
Definition: ScalableObject.h:52
Gorgon::Resource::ScalableObject::AssumeProvider
void AssumeProvider(Graphics::ScalableObjectProvider &value)
Changes the provider stored in this tinted object, ownership will be transferred.
Definition: ScalableObject.h:84
Gorgon::Resource::ScalableObject::GetSize
virtual Geometry::Size GetSize() const override
Definition: ScalableObject.h:134
Gorgon::Resource::ScalableObject::ScalableObject
ScalableObject(Graphics::ScalableBitmapProvider &&prov)
Creates a new tinted object using another tinted object provider.
Definition: ScalableObject.h:28
Gorgon::Resource::ScalableObject::CreateBase
virtual Graphics::RectangularAnimation & CreateBase() const override
Definition: ScalableObject.h:100
Gorgon::Resource::ScalableObject::GetController
virtual Graphics::SizeController GetController() const override
Definition: ScalableObject.h:107
Gorgon::Resource::ScalableObject::ScalableObject
ScalableObject()
Creates a new empty tinted object.
Definition: ScalableObject.h:43
Gorgon::Resource::GID::ScalableObject
constexpr Type ScalableObject
Definition: GID.h:247