Gorgon Game Engine
Font.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Base.h"
4 #include "Image.h"
5 #include "../Graphics/Font.h"
6 #include "../Utils/Assert.h"
7 
8 namespace Gorgon { namespace Resource {
9  class File;
10  class Reader;
11 
16  class Font : public Base {
17  public:
18  Font() { }
19 
20  virtual ~Font() {
21  if(isowner)
22  delete data;
23  }
24 
28  Font(Graphics::GlyphRenderer &renderer);
29 
30  Font(const Font &) = delete;
31 
32  //todo duplicate
33 
34  virtual GID::Type GetGID() const override { return GID::Font; }
35 
38  virtual void Prepare() override;
39 
40  virtual void Discard() override;
41 
43  bool HasRenderer() const {
44  return data != nullptr;
45  }
46 
49  ASSERT(data, "Renderer is not set");
50 
51  return *data;
52  }
53 
55  void RemoveRenderer() {
56  if(isowner)
57  delete data;
58 
59  data = nullptr;
60  }
61 
63  void SetRenderer(Graphics::GlyphRenderer &renderer);
64 
67  SetRenderer(renderer);
68  isowner = true;
69  }
70 
76  auto tmp = data;
77  data = nullptr;
78  isowner = false;
79 
80  return *tmp;
81  }
82 
84  static Font *LoadResource(std::weak_ptr<File> file, std::shared_ptr<Reader> reader, unsigned long size);
85 
86  protected:
87  void save(Writer &writer) const override;
88 
90 
92 
93  bool isowner = false;
94  };
95 
96 } }
97 
98 
Gorgon::Resource::GID::File
constexpr Type File
File.
Definition: GID.h:84
Gorgon::Resource::Font::save
void save(Writer &writer) const override
Definition: Font.cpp:41
Base.h
Gorgon::Resource::Font::GetGID
virtual GID::Type GetGID() const override
This function shall return Gorgon ID of this resource.
Definition: Font.h:34
Gorgon::Resource::Font::SetRenderer
void SetRenderer(Graphics::GlyphRenderer &renderer)
Changes the renderer to the given renderer.
Definition: Font.cpp:14
Gorgon::Resource::GID::Font
constexpr Type Font
Definition: GID.h:199
Image.h
Gorgon::Graphics::GlyphRenderer
Should be implemented by the systems aimed to render fonts on the screen.
Definition: Font.h:67
Gorgon::Resource::Font::data
Graphics::GlyphRenderer * data
Definition: Font.h:89
Gorgon::Resource::Font::Release
Graphics::GlyphRenderer & Release()
Releases the renderer.
Definition: Font.h:75
Gorgon::Resource::Font::Discard
virtual void Discard() override
This function shall discard any transitional data which is not vital after Prepare function is issued...
Definition: Font.cpp:252
Gorgon::Resource::Font::Prepare
virtual void Prepare() override
This function will only prepare images loaded from a resource, does not work for images loaded later.
Definition: Font.cpp:245
Gorgon
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
Gorgon::Resource::Font::RemoveRenderer
void RemoveRenderer()
Removes the renderer from this resource.
Definition: Font.h:55
Gorgon::Resource::Font::isowner
bool isowner
Definition: Font.h:93
ASSERT
#define ASSERT(expression, message,...)
Replaces regular assert to allow messages and backtrace.
Definition: Assert.h:161
Gorgon::Containers::Collection
Collection is a container for reference typed objects.
Definition: Collection.h:21
Gorgon::Resource::Font::Font
Font(const Font &)=delete
Gorgon::Resource::Font::LoadResource
static Font * LoadResource(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long size)
This function loads a bitmap font resource from the given file.
Definition: Font.cpp:116
Gorgon::Resource::Base
This class is the base for all Gorgon Resources.
Definition: Base.h:20
Gorgon::Resource::Writer
This class allows resource objects to save their data to a stream.
Definition: Writer.h:59
Gorgon::Resource::Font::tobeprepared
Containers::Collection< Image > tobeprepared
Definition: Font.h:91
Gorgon::Resource::Font::~Font
virtual ~Font()
Definition: Font.h:20
Gorgon::Resource::Font::HasRenderer
bool HasRenderer() const
Returns true if the resource has renderer.
Definition: Font.h:43
Gorgon::Resource::GID::Type
Type to store GID information.
Definition: GID.h:23
Gorgon::Resource::Font::GetRenderer
Graphics::GlyphRenderer & GetRenderer() const
Returns the renderer stored in this resource.
Definition: Font.h:48
Gorgon::Resource::Font
Font resource.
Definition: Font.h:16
Gorgon::Resource::Font::Font
Font()
Definition: Font.h:18
Gorgon::Resource::Font::AssumeRenderer
void AssumeRenderer(Graphics::GlyphRenderer &renderer)
Changes the renderer to the given renderer and assumes ownership.
Definition: Font.h:66