 |
Gorgon Game Engine
|
Go to the documentation of this file.
4 #include "../Utils/Assert.h"
5 #include "../Geometry/Point.h"
6 #include "../Containers/Hashmap.h"
39 image(&image), hotspot(hotspot) {}
48 image(&image), hotspot(hotspot) { owner =
true; }
53 image(other.image), hotspot(other.hotspot), owner(other.owner) {
54 other.image =
nullptr;
64 hotspot = other.hotspot;
66 other.image =
nullptr;
81 return image !=
nullptr;
87 ASSERT(image,
"Pointer image is not set");
115 this->hotspot = hotspot;
125 this->hotspot = {x, y};
153 image->
Draw(target, p-hotspot, color);
164 class basic_PointerProvider;
177 other.anim =
nullptr;
182 anim->DeleteAnimation();
186 ASSERT(
anim,
"Trying to use a moved out pointer");
188 anim->SetController(controller);
192 ASSERT(
anim,
"Trying to use a moved out pointer");
194 return anim->HasController();
198 ASSERT(
anim,
"Trying to use a moved out pointer");
200 return anim->GetController();
204 ASSERT(
anim,
"Trying to use a moved out pointer");
206 anim->RemoveController();
213 typename A_::AnimationType *
anim;
319 parent = other.parent;
322 other.parent =
nullptr;
328 parent->
Reset(*
this);
333 parent->
Reset(*
this);
338 tok.parent =
nullptr;
345 bool IsNull()
const {
return parent ==
nullptr; }
348 explicit operator bool()
const {
return !
IsNull(); }
371 swap(lastind, other.lastind);
372 swap(stack, other.stack);
373 swap(pointers, other.pointers);
377 for(
auto &w : pointers) {
410 return pointers[(int)type].ptr !=
nullptr;
425 void Reset(Token &token);
452 ASSERT(anim,
"Try to use a moved out pointer");
454 anim->Draw(target, p-parent.GetHotspot(), color);
void SetImage(const Drawable &value)
Changes the image of this pointer.
Definition: Pointer.h:93
~Token()
Definition: Pointer.h:326
void swap(Event< Source_, Args_... > &l, Event< Source_, Args_... > &r)
Swaps two events.
Definition: Event.h:351
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
void SetController(Gorgon::Animation::ControllerBase &controller) override
Definition: Pointer.h:185
std::enable_if< decltype(gorgon__enum_tr_loc(T_()))::isupgradedenum, std::string >::type From(const T_ &e)
Definition: Enum.h:303
DrawablePointer(const AssumeOwnershipTag &, const Drawable &image, Geometry::Point hotspot)
Initializes a pointer.
Definition: Pointer.h:47
basic_AnimatedPointer< A_ > AnimationType
Definition: Pointer.h:220
const Pointer & Current() const
Returns the pointer on top of the stack, if no pointer is on the stack, first pointer in the order of...
Definition: Pointer.cpp:53
const Drawable & Release()
Releases the ownership of the drawable and removes it from the pointer.
Definition: Pointer.h:139
void Prepare() override
This function shall prepare this resource to be used after resource is loaded.
Definition: Pointer.cpp:63
bool operator!() const
Checks if the token is invalid.
Definition: Pointer.h:351
Definition: TextureAnimation.h:137
DrawablePointer()=default
@ None
No pointer is selected or using default.
E_ ReadEnum32()
Reads an enumeration as 32-bit integer from the stream.
Definition: Reader.h:208
void Assume(PointerType type, const Pointer &pointer)
Adds the given pointer to the stack.
Definition: Pointer.cpp:16
~PointerStack()
Definition: Pointer.h:376
This class is a reference based hashmap.
Definition: Hashmap.h:35
DrawablePointer(const Drawable &image, Geometry::Point hotspot)
Initializes a pointer.
Definition: Pointer.h:38
void Assume(const Drawable &value, Geometry::Point hotspot)
Changes the image of the pointer by assuming the ownership of the given image.
Definition: Pointer.h:110
Controllers are required to progress animations.
Definition: Animation.h:65
basic_AnimatedPointer(const basic_AnimatedPointer &)=delete
void WriteChunkHeader(GID::Type type, unsigned long size)
Writes the header of a chunk.
Definition: Writer.h:364
PointerStack(PointerStack &&other)
Definition: Pointer.h:364
~DrawablePointer()
Definition: Pointer.h:74
static void SaveThis(Writer &writer, const Graphics::BitmapAnimationProvider &anim, GID::Type type=GID::Animation, std::function< void(Writer &writer)> extra={})
Saves the given animation as a resource.
Definition: Animation.cpp:100
basic_PointerProvider(Geometry::Point hotspot={0, 0})
Definition: Pointer.h:222
DrawablePointer & operator=(const DrawablePointer &)=delete
Graphics::PointerType type
Definition: Pointer.h:71
Represents a four channel 32 bit float per channel color information.
Definition: Color.h:373
Marker WriteObjectStart(const Base &base)
Writes the start of an object. Should have a matching WriteEnd with the returned marker.
Definition: File.cpp:211
void Assume(const Drawable &value)
Changes the image of the pointer by assuming the ownership of the given image.
Definition: Pointer.h:101
static Resource::Pointer * LoadResource(std::weak_ptr< Gorgon::Resource::File > file, std::shared_ptr< Gorgon::Resource::Reader > reader, long unsigned int size)
This function loads a bitmap font resource from the given file.
Definition: Pointer.cpp:6
const Drawable & GetImage() const
Returns the image contained in this pointer.
Definition: Pointer.h:86
void ASSERT_FALSE(const std::string &message, int skip=1, int depth=4)
Definition: Assert.h:192
DrawablePointer(DrawablePointer &&other)
Definition: Pointer.h:52
bool IsValid() const
Returns if the stack is valid to be used.
Definition: Pointer.cpp:67
Geometry::Point hotspot
Hotspot will be transferred to newly created pointers.
Definition: Pointer.h:269
Gorgon::Animation::ControllerBase & GetController() const
Definition: Pointer.h:197
PointerType
Pointer types.
Definition: Pointer.h:280
basic_PointerProvider< BitmapAnimationProvider > BitmapPointerProvider
Definition: Pointer.h:276
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
This class turns a drawable into a pointer.
Definition: Pointer.h:28
void Reset(Token &token)
Removes a pointer shape from the stack.
Definition: Pointer.cpp:44
DrawablePointer(const DrawablePointer &other)=delete
virtual Graphics::RectangularAnimationStorage animmoveout() override
Definition: Pointer.cpp:69
void draw(Gorgon::Graphics::TextureTarget &target, const Geometry::Pointf &p, Gorgon::Graphics::RGBAf color) const override
This is the only function that needs to implemented for a drawable.
Definition: Pointer.h:451
Token & operator=(Token &&tok)
Definition: Pointer.h:331
#define ASSERT(expression, message,...)
Replaces regular assert to allow messages and backtrace.
Definition: Assert.h:161
unsigned long ReadChunkSize()
Reads chunk size from a stream.
Definition: Reader.h:381
AnimationType & CreateAnimation(bool create=true) const override
Creates a pointer from this provider.
Definition: Pointer.h:253
Token()
Definition: Pointer.h:316
AnimationType CreatePointer(Gorgon::Animation::Timer &timer) const
Creates a pointer from this provider.
Definition: Pointer.h:238
Pointer resource that can be used to create a new pointer to be displayed.
Definition: Pointer.h:25
Represents a pointer.
Definition: Pointer.h:18
basic_PointerProvider(const basic_PointerProvider &)=delete
bool HasImage() const
Returns if the pointer has an image.
Definition: Pointer.h:80
constexpr Type Animation
Definition: GID.h:187
This class is the base for all Gorgon Resources.
Definition: Base.h:20
AnimationType CreatePointer(bool create=true) const
Creates a pointer from this provider, just a rename for CreateAnimation.
Definition: Pointer.h:243
void draw(Gorgon::Graphics::TextureTarget &target, const Geometry::Pointf &p, Gorgon::Graphics::RGBAf color) const override
This is the only function that needs to implemented for a drawable.
Definition: Pointer.h:150
void SetHotspot(Geometry::Point value)
Sets the hotspot of the pointer.
Definition: Pointer.h:263
void RemoveImage()
Removes the image from the pointer.
Definition: Pointer.h:129
void Draw(TextureTarget &target, int x, int y, RGBAf color=RGBAf(1.f)) const
Draw to the given coordinates.
Definition: Drawables.h:22
Graphics::BitmapPointerProvider MoveOut()
Moves the pointer provider out of resource system.
Definition: Pointer.cpp:47
virtual ~basic_PointerProvider()
Definition: Pointer.h:234
Mark Target(unsigned long delta)
Creates mark to the the target that is delta distance from current point in file.
Definition: Reader.h:193
void EatChunk(long size)
Removes a chunk of data with the given size from the stream.
Definition: Reader.h:389
Geometry::Point GetHotspot() const
Returns the hotspot of the provider.
Definition: Pointer.h:258
A_::AnimationType * anim
Definition: Pointer.h:213
This interface defines a class that can be used as a common target for texture based drawing.
Definition: TextureTargets.h:12
virtual ~Pointer()
Definition: Pointer.h:21
Token(Token &&other)
Definition: Pointer.h:318
This class stores information that allows an animated pointer to be created.
Definition: Pointer.h:218
This class manages a pointer stack that allows multiple pointers to be registered and switched.
Definition: Pointer.h:309
void Assume(const Drawable &value, int x, int y)
Changes the image of the pointer by assuming the ownership of the given image.
Definition: Pointer.h:120
bool IsNull() const
Checks if the token is null.
Definition: Pointer.h:345
This class represents a 2D point.
Definition: Point.h:32
This class allows resource objects to save their data to a stream.
Definition: Writer.h:59
This class is the most basic controller and does not support any operations.
Definition: Animation.h:126
AnimationType & CreateAnimation(Gorgon::Animation::ControllerBase &timer) const override
Creates a pointer from this provider.
Definition: Pointer.h:248
GID::Type ReadGID()
Reads a GID from the given stream.
Definition: Reader.h:341
DrawablePointer(const AssumeOwnershipTag &tag, const Drawable &image, int x, int y)
Initializes a pointer.
Definition: Pointer.h:43
void Swap(PointerStack &other)
Definition: Pointer.h:368
Geometry::Point ReadPoint()
Reads a Point from the given stream.
Definition: Reader.h:357
void WriteEnd(Marker &marker)
This function performs writes necessary to end a chunk that is represented by the marker.
Definition: Writer.h:373
@ Graphics
Definition: Template.h:164
basic_AnimatedPointer(basic_AnimatedPointer &&other)
Definition: Pointer.h:176
bool HasController() const override
Definition: Pointer.h:191
Gorgon::Animation::basic_Storage< RectangularAnimationProvider > RectangularAnimationStorage
Definition: Animations.h:374
PointerStack(const PointerStack &)=delete
Token type, automatically pops pointer stack when goes out of scope.
Definition: Pointer.h:313
void Add(PointerType type, const Pointer &&pointer)
Move variant that maps to assume.
Definition: Pointer.h:389
Pointer(Graphics::Bitmap &bmp, Geometry::Point hotspot, Graphics::PointerType type)
Definition: Pointer.h:27
Represents a drawable object, that can be drawn to the given point.
Definition: Drawables.h:17
basic_PointerProvider(basic_PointerProvider &&other)
Move constructor.
Definition: Pointer.h:227
Containers::Collection< Base > children
Child objects that this resource object have.
Definition: Base.h:162
Token Set(PointerType type)
Set the current pointer to the given type.
Definition: Pointer.cpp:28
void WriteEnum32(E_ value)
Writes an enumeration as 32-bit integer to the stream.
Definition: Writer.h:140
constexpr Type Pointer_Props
Definition: GID.h:197
bool Exists(PointerType type)
Checks if the given pointer exists.
Definition: Pointer.h:407
basic_AnimatedPointer(const basic_PointerProvider< A_ > &parent, typename A_::AnimationType &anim)
Definition: Pointer.h:170
static Animation * LoadResource(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long size)
This function loads an animation resource from the given file.
Definition: Animation.h:51
DrawablePointer(const Drawable &image, int x, int y)
Initializes a pointer.
Definition: Pointer.h:34
bool ReadCommonChunk(Base &self, GID::Type gid, unsigned long size)
Definition: File.cpp:41
~basic_AnimatedPointer()
Definition: Pointer.h:180
Where acceptable, denotes that the object will assume the ownership.
Definition: Types.h:136
This class represents an animation resource.
Definition: Animation.h:19
Represents animated pointer.
Definition: Pointer.h:168
@ Text
Text / Beam pointer.
void RemoveController() const
Definition: Pointer.h:203
bool owned
Whether the animation is owned by this object.
Definition: Pointer.h:272
void WritePoint(Geometry::Point value)
Writes a point to the stream, point takes 2 x 4 bytes.
Definition: Writer.h:244
void Add(PointerType type, const Pointer &pointer)
Adds the given pointer to the stack.
Definition: Pointer.cpp:5
void Add(PointerType type, const Drawable &&image, Geometry::Point hotspot)=delete
void save(Writer &writer) const override
Definition: Pointer.cpp:51
const basic_PointerProvider< A_ > & parent
Definition: Pointer.h:212