Skip to content
This repository has been archived by the owner on Nov 7, 2022. It is now read-only.

Commit

Permalink
Move Font and text from engge to ngf
Browse files Browse the repository at this point in the history
  • Loading branch information
scemino committed Feb 23, 2021
1 parent 67567ee commit 0022a4a
Show file tree
Hide file tree
Showing 33 changed files with 111 additions and 855 deletions.
12 changes: 7 additions & 5 deletions include/engge/Entities/TextObject.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#pragma once
#include "Object.hpp"

namespace ngf {
class Font;
}

namespace ng {
enum class TextAlignment : unsigned long {
None = 0x00000000,
Expand All @@ -14,15 +18,13 @@ enum class TextAlignment : unsigned long {
All = Horizontal | Vertical
};

class Font;

class TextObject final : public Object {
public:
TextObject();
~TextObject() final;

const Font *getFont() { return m_font; }
void setFont(const Font *font) { m_font = font; }
const ngf::Font *getFont() { return m_font; }
void setFont(const ngf::Font *font) { m_font = font; }
void setText(const std::string &text);
void setAlignment(TextAlignment alignment) { m_alignment = alignment; }
void setMaxWidth(int maxWidth) { m_maxWidth = maxWidth; }
Expand All @@ -31,7 +33,7 @@ class TextObject final : public Object {
void draw(ngf::RenderTarget &target, ngf::RenderStates states) const final;

private:
mutable const Font *m_font{nullptr};
mutable const ngf::Font *m_font{nullptr};
std::wstring m_text;
TextAlignment m_alignment{TextAlignment::Left};
int m_maxWidth{0};
Expand Down
126 changes: 0 additions & 126 deletions include/engge/Graphics/FntFont.h

This file was deleted.

46 changes: 0 additions & 46 deletions include/engge/Graphics/Font.h

This file was deleted.

8 changes: 4 additions & 4 deletions include/engge/Graphics/GGFont.hpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#pragma once
#include <ngf/IO/GGPackValue.h>
#include <engge/Graphics/ResourceManager.hpp>
#include "Font.h"
#include <ngf/Graphics/Font.h>
#include <memory>

namespace ng {
class GGFont : public Font {
class GGFont : public ngf::Font {
public:
~GGFont() override;
void setTextureManager(ResourceManager *textureManager);

void load(const std::string &path);

[[nodiscard]] const std::shared_ptr<ngf::Texture> &getTexture(unsigned int) const override;
[[nodiscard]] const Glyph &getGlyph(unsigned int codePoint) const override;
[[nodiscard]] const ngf::Glyph &getGlyph(unsigned int codePoint) const override;
[[nodiscard]] float getKerning(unsigned int first, unsigned int second, unsigned int characterSize) const override;

private:
std::map<unsigned int, Glyph> m_glyphs;
std::map<unsigned int, ngf::Glyph> m_glyphs;
ResourceManager *m_resourceManager{nullptr};
std::string m_path;
std::string m_jsonFilename;
Expand Down
21 changes: 12 additions & 9 deletions include/engge/Graphics/ResourceManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
#include <engge/System/NonCopyable.hpp>
#include <ngf/Graphics/Texture.h>

namespace ngf {
class FntFont;
}

namespace ng {
class GGFont;
class FntFont;
class SpriteSheet;

struct TextureResource {
Expand All @@ -15,27 +18,27 @@ struct TextureResource {
};

class ResourceManager : public NonCopyable {
private:
std::map<std::string, TextureResource> _textureMap;
std::map<std::string, std::shared_ptr<GGFont>> _fontMap;
std::map<std::string, std::shared_ptr<FntFont>> _fntFontMap;
std::map<std::string, std::shared_ptr<SpriteSheet>> _spriteSheetMap;

public:
ResourceManager();
~ResourceManager();

std::shared_ptr<ngf::Texture> getTexture(const std::string &id);
GGFont &getFont(const std::string &id);
FntFont &getFntFont(const std::string &id);
ngf::FntFont &getFntFont(const std::string &id);
const SpriteSheet &getSpriteSheet(const std::string &id);

[[nodiscard]] const std::map<std::string, TextureResource> &getTextureMap() const { return _textureMap; }
[[nodiscard]] const std::map<std::string, TextureResource> &getTextureMap() const { return m_textureMap; }

private:
void load(const std::string &id);
void loadFont(const std::string &id);
void loadFntFont(const std::string &id);
void loadSpriteSheet(const std::string &id);

private:
std::map<std::string, TextureResource> m_textureMap;
std::map<std::string, std::shared_ptr<GGFont>> m_fontMap;
std::map<std::string, std::shared_ptr<ngf::FntFont>> m_fntFontMap;
std::map<std::string, std::shared_ptr<SpriteSheet>> m_spriteSheetMap;
};
} // namespace ng
88 changes: 0 additions & 88 deletions include/engge/Graphics/Text.hpp

This file was deleted.

2 changes: 0 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,13 @@ set(SOURCES
Entities/WalkingState.cpp
Graphics/AnimControl.cpp
Graphics/AnimDrawable.cpp
Graphics/FntFont.cpp
Graphics/GGFont.cpp
Graphics/ResourceManager.cpp
Graphics/SpriteSheet.cpp
Graphics/GraphDrawable.cpp
Graphics/LightingShader.cpp
Graphics/WalkboxDrawable.cpp
Graphics/PathDrawable.cpp
Graphics/Text.cpp
Input/CommandManager.cpp
Input/InputMappings.cpp
main.cpp
Expand Down
Loading

0 comments on commit 0022a4a

Please sign in to comment.