From 0a4a254245762a2dc8cf0f42000f623a7bde2c5c Mon Sep 17 00:00:00 2001 From: Relintai Date: Wed, 14 Apr 2021 18:24:43 +0200 Subject: [PATCH] Renamed Font to TrueTypeFont. --- 03_sdl_basics/16_sdl_ttf/compile.bat | 4 +- 03_sdl_basics/16_sdl_ttf/compile.sh | 4 +- 03_sdl_basics/16_sdl_ttf/main_scene.cpp | 2 +- 03_sdl_basics/16_sdl_ttf/main_scene.h | 4 +- .../{font.cpp => true_type_font.cpp} | 78 ++++++++++--------- .../16_sdl_ttf/{font.h => true_type_font.h} | 14 ++-- 6 files changed, 54 insertions(+), 52 deletions(-) rename 03_sdl_basics/16_sdl_ttf/{font.cpp => true_type_font.cpp} (54%) rename 03_sdl_basics/16_sdl_ttf/{font.h => true_type_font.h} (89%) diff --git a/03_sdl_basics/16_sdl_ttf/compile.bat b/03_sdl_basics/16_sdl_ttf/compile.bat index d010553..ae76063 100755 --- a/03_sdl_basics/16_sdl_ttf/compile.bat +++ b/03_sdl_basics/16_sdl_ttf/compile.bat @@ -40,7 +40,7 @@ XCOPY ..\..\lib\SDL2\bin\*.dll bin /D /Y %GPP% -Wall %VER% %SDL2_CFLAGS% -c texture.cpp -o obj/texture.o %GPP% -Wall %VER% %SDL2_CFLAGS% -c sprite.cpp -o obj/sprite.o %GPP% -Wall %VER% %SDL2_CFLAGS% -c camera.cpp -o obj/camera.o -%GPP% -Wall %VER% %SDL2_CFLAGS% -c font.cpp -o obj/font.o +%GPP% -Wall %VER% %SDL2_CFLAGS% -c true_type_font.cpp -o obj/true_type_font.o %GPP% -Wall %VER% %SDL2_CFLAGS% -c button.cpp -o obj/button.o @@ -50,4 +50,4 @@ XCOPY ..\..\lib\SDL2\bin\*.dll bin /D /Y %GPP% -Wall %VER% %SDL2_CFLAGS% -c main.cpp -o obj/main.o -%GPP% -o bin/program obj/math.o obj/rect2.o obj/color.o obj/vector2.o obj/vector3.o obj/string.o obj/renderer.o obj/image.o obj/texture.o obj/sprite.o obj/font.o obj/camera.o obj/button.o obj/scene.o obj/application.o obj/main_scene.o obj/main.o %SDL2_LIBS% +%GPP% -o bin/program obj/math.o obj/rect2.o obj/color.o obj/vector2.o obj/vector3.o obj/string.o obj/renderer.o obj/image.o obj/texture.o obj/sprite.o obj/true_type_font.o obj/camera.o obj/button.o obj/scene.o obj/application.o obj/main_scene.o obj/main.o %SDL2_LIBS% diff --git a/03_sdl_basics/16_sdl_ttf/compile.sh b/03_sdl_basics/16_sdl_ttf/compile.sh index 2e07c48..fc4b54c 100755 --- a/03_sdl_basics/16_sdl_ttf/compile.sh +++ b/03_sdl_basics/16_sdl_ttf/compile.sh @@ -26,7 +26,7 @@ g++ -Wall -g $(sdl2-config --cflags) -c texture.cpp -o obj/texture.o g++ -Wall -g $(sdl2-config --cflags) -c sprite.cpp -o obj/sprite.o g++ -Wall -g $(sdl2-config --cflags) -c camera.cpp -o obj/camera.o -g++ -Wall -g $(sdl2-config --cflags) -c font.cpp -o obj/font.o +g++ -Wall -g $(sdl2-config --cflags) -c true_type_font.cpp -o obj/true_type_font.o g++ -Wall -g $(sdl2-config --cflags) -c button.cpp -o obj/button.o @@ -36,5 +36,5 @@ g++ -Wall -g $(sdl2-config --cflags) -c main_scene.cpp -o obj/main_scene.o g++ -Wall -g $(sdl2-config --cflags) -c main.cpp -o obj/main.o -g++ -o bin/program obj/math.o obj/rect2.o obj/color.o obj/vector2.o obj/vector3.o obj/string.o obj/renderer.o obj/image.o obj/texture.o obj/sprite.o obj/camera.o obj/font.o obj/button.o obj/scene.o obj/application.o obj/main_scene.o obj/main.o $(sdl2-config --libs) -lSDL2_ttf +g++ -o bin/program obj/math.o obj/rect2.o obj/color.o obj/vector2.o obj/vector3.o obj/string.o obj/renderer.o obj/image.o obj/texture.o obj/sprite.o obj/camera.o obj/true_type_font.o obj/button.o obj/scene.o obj/application.o obj/main_scene.o obj/main.o $(sdl2-config --libs) -lSDL2_ttf diff --git a/03_sdl_basics/16_sdl_ttf/main_scene.cpp b/03_sdl_basics/16_sdl_ttf/main_scene.cpp index 222a3b4..3e19246 100644 --- a/03_sdl_basics/16_sdl_ttf/main_scene.cpp +++ b/03_sdl_basics/16_sdl_ttf/main_scene.cpp @@ -45,7 +45,7 @@ MainScene::MainScene() { _camera = new Camera(); _image = new Image("ti.bmp"); _texture = new Texture(_image); - _font = new Font("./DejaVuSans.ttf", 16); + _font = new TrueTypeFont("./DejaVuSans.ttf", 16); _ii = _font->render_text_blended("Adsdsda", Color(255, 0, 0, 255)); _iit = new Texture(_ii); _s = new Sprite(_iit); diff --git a/03_sdl_basics/16_sdl_ttf/main_scene.h b/03_sdl_basics/16_sdl_ttf/main_scene.h index 405d059..3399149 100644 --- a/03_sdl_basics/16_sdl_ttf/main_scene.h +++ b/03_sdl_basics/16_sdl_ttf/main_scene.h @@ -8,7 +8,7 @@ #include "sprite.h" #include "camera.h" #include "button.h" -#include "font.h" +#include "true_type_font.h" class MainScene : public Scene { public: @@ -29,7 +29,7 @@ public: Camera *_camera; Image *_image; Texture *_texture; - Font *_font; + TrueTypeFont *_font; Image *_ii; Texture *_iit; Sprite *_s; diff --git a/03_sdl_basics/16_sdl_ttf/font.cpp b/03_sdl_basics/16_sdl_ttf/true_type_font.cpp similarity index 54% rename from 03_sdl_basics/16_sdl_ttf/font.cpp rename to 03_sdl_basics/16_sdl_ttf/true_type_font.cpp index 3bc8902..a012dcb 100644 --- a/03_sdl_basics/16_sdl_ttf/font.cpp +++ b/03_sdl_basics/16_sdl_ttf/true_type_font.cpp @@ -1,73 +1,75 @@ -#include "font.h" +#include "true_type_font.h" -int Font::get_style() { +int TrueTypeFont::get_style() { return TTF_GetFontStyle(_font); } -void Font::set_style(const int style) { +void TrueTypeFont::set_style(const int style) { TTF_SetFontStyle(_font, style); } -int Font::get_outline() { +int TrueTypeFont::get_outline() { return TTF_GetFontOutline(_font); } -void Font::set_outline(const int outline) { +void TrueTypeFont::set_outline(const int outline) { TTF_SetFontOutline(_font, outline); } -int Font::get_hinting() { +int TrueTypeFont::get_hinting() { return TTF_GetFontHinting(_font); } -void Font::set_hinting(const int hinting) { +void TrueTypeFont::set_hinting(const int hinting) { TTF_SetFontHinting(_font, hinting); } -int Font::get_height() { +int TrueTypeFont::get_height() { return TTF_FontHeight(_font); } -int Font::get_ascent() { +int TrueTypeFont::get_ascent() { return TTF_FontAscent(_font); } -int Font::get_descent() { +int TrueTypeFont::get_descent() { return TTF_FontDescent(_font); } -int Font::get_line_skip() { +int TrueTypeFont::get_line_skip() { return TTF_FontLineSkip(_font); } -int Font::get_kerning() { +int TrueTypeFont::get_kerning() { return TTF_GetFontKerning(_font); } -void Font::set_kerning(const int allowed) { +void TrueTypeFont::set_kerning(const int allowed) { TTF_SetFontKerning(_font, allowed); } -long Font::get_faces() { +long TrueTypeFont::get_faces() { return TTF_FontFaces(_font); } -int Font::get_face_is_fixed_width() { +int TrueTypeFont::get_face_is_fixed_width() { return TTF_FontFaceIsFixedWidth(_font); } -char *Font::get_face_family_name() { + +char *TrueTypeFont::get_face_family_name() { return TTF_FontFaceFamilyName(_font); } -char *Font::get_font_face_style_name() { + +char *TrueTypeFont::get_face_style_name() { return TTF_FontFaceStyleName(_font); } -bool Font::is_glyph_provided(Uint16 ch) { +bool TrueTypeFont::is_glyph_provided(Uint16 ch) { return TTF_GlyphIsProvided(_font, ch); } -Font::GlyphMetric Font::glyph_metrics(Uint16 ch) { - Font::GlyphMetric g; +TrueTypeFont::GlyphMetric TrueTypeFont::glyph_metrics(Uint16 ch) { + TrueTypeFont::GlyphMetric g; TTF_GlyphMetrics(_font, ch, &g.minx, &g.maxx, &g.miny, &g.maxy, &g.advance); return g; } -Vector2 Font::get_size_text(const String &text) { +Vector2 TrueTypeFont::get_size_text(const String &text) { int w; int h; @@ -76,7 +78,7 @@ Vector2 Font::get_size_text(const String &text) { return Vector2(w, h); } -Vector2 Font::get_size_utf8(const String &text) { +Vector2 TrueTypeFont::get_size_utf8(const String &text) { int w; int h; @@ -85,7 +87,7 @@ Vector2 Font::get_size_utf8(const String &text) { return Vector2(w, h); } -Image *Font::render_text_solid(const String &text, const Color &fg) { +Image *TrueTypeFont::render_text_solid(const String &text, const Color &fg) { if (!_font) { return nullptr; } @@ -93,7 +95,7 @@ Image *Font::render_text_solid(const String &text, const Color &fg) { return new Image(TTF_RenderText_Solid(_font, text.c_str(), fg.to_sdl_color())); } -Image *Font::render_utf8_solid(const String &text, const Color &fg) { +Image *TrueTypeFont::render_utf8_solid(const String &text, const Color &fg) { if (!_font) { return nullptr; } @@ -101,7 +103,7 @@ Image *Font::render_utf8_solid(const String &text, const Color &fg) { return new Image(TTF_RenderUTF8_Solid(_font, text.c_str(), fg.to_sdl_color())); } -Image *Font::render_glyph_solid(const Uint16 ch, const Color &fg) { +Image *TrueTypeFont::render_glyph_solid(const Uint16 ch, const Color &fg) { if (!_font) { return nullptr; } @@ -109,7 +111,7 @@ Image *Font::render_glyph_solid(const Uint16 ch, const Color &fg) { return new Image(TTF_RenderGlyph_Solid(_font, ch, fg.to_sdl_color())); } -Image *Font::render_text_shaded(const String &text, const Color &fg, const Color &bg) { +Image *TrueTypeFont::render_text_shaded(const String &text, const Color &fg, const Color &bg) { if (!_font) { return nullptr; } @@ -117,7 +119,7 @@ Image *Font::render_text_shaded(const String &text, const Color &fg, const Color return new Image(TTF_RenderText_Shaded(_font, text.c_str(), fg.to_sdl_color(), bg.to_sdl_color())); } -Image *Font::render_utf8_shaded(const String &text, const Color &fg, const Color &bg) { +Image *TrueTypeFont::render_utf8_shaded(const String &text, const Color &fg, const Color &bg) { if (!_font) { return nullptr; } @@ -125,7 +127,7 @@ Image *Font::render_utf8_shaded(const String &text, const Color &fg, const Color return new Image(TTF_RenderUTF8_Shaded(_font, text.c_str(), fg.to_sdl_color(), bg.to_sdl_color())); } -Image *Font::render_glyph_shaded(const Uint16 ch, const Color &fg, const Color &bg) { +Image *TrueTypeFont::render_glyph_shaded(const Uint16 ch, const Color &fg, const Color &bg) { if (!_font) { return nullptr; } @@ -133,7 +135,7 @@ Image *Font::render_glyph_shaded(const Uint16 ch, const Color &fg, const Color & return new Image(TTF_RenderGlyph_Shaded(_font, ch, fg.to_sdl_color(), bg.to_sdl_color())); } -Image *Font::render_text_blended(const String &text, const Color &fg) { +Image *TrueTypeFont::render_text_blended(const String &text, const Color &fg) { if (!_font) { return nullptr; } @@ -141,7 +143,7 @@ Image *Font::render_text_blended(const String &text, const Color &fg) { return new Image(TTF_RenderText_Blended(_font, text.c_str(), fg.to_sdl_color())); } -Image *Font::render_utf8_blended(const String &text, const Color &fg) { +Image *TrueTypeFont::render_utf8_blended(const String &text, const Color &fg) { if (!_font) { return nullptr; } @@ -149,7 +151,7 @@ Image *Font::render_utf8_blended(const String &text, const Color &fg) { return new Image(TTF_RenderUTF8_Blended(_font, text.c_str(), fg.to_sdl_color())); } -Image *Font::render_text_blended_wrapped(const String &text, const Color &fg, Uint32 wrap_length) { +Image *TrueTypeFont::render_text_blended_wrapped(const String &text, const Color &fg, Uint32 wrap_length) { if (!_font) { return nullptr; } @@ -157,7 +159,7 @@ Image *Font::render_text_blended_wrapped(const String &text, const Color &fg, Ui return new Image(TTF_RenderText_Blended_Wrapped(_font, text.c_str(), fg.to_sdl_color(), wrap_length)); } -Image *Font::render_utf8_blended_wrapped(const String &text, const Color &fg, Uint32 wrap_length) { +Image *TrueTypeFont::render_utf8_blended_wrapped(const String &text, const Color &fg, Uint32 wrap_length) { if (!_font) { return nullptr; } @@ -165,7 +167,7 @@ Image *Font::render_utf8_blended_wrapped(const String &text, const Color &fg, Ui return new Image(TTF_RenderUTF8_Blended_Wrapped(_font, text.c_str(), fg.to_sdl_color(), wrap_length)); } -Image *Font::render_glyph_blended(const Uint16 ch, const Color &fg) { +Image *TrueTypeFont::render_glyph_blended(const Uint16 ch, const Color &fg) { if (!_font) { return nullptr; } @@ -173,7 +175,7 @@ Image *Font::render_glyph_blended(const Uint16 ch, const Color &fg) { return new Image(TTF_RenderGlyph_Blended(_font, ch, fg.to_sdl_color())); } -void Font::load(const String &file_name, const int ptsize, const int index) { +void TrueTypeFont::load(const String &file_name, const int ptsize, const int index) { if (index == -1) { _font = TTF_OpenFont(file_name.c_str(), ptsize); } else { @@ -181,7 +183,7 @@ void Font::load(const String &file_name, const int ptsize, const int index) { } } -void Font::free() { +void TrueTypeFont::free() { if (_font) { TTF_CloseFont(_font); @@ -189,16 +191,16 @@ void Font::free() { } } -Font::Font() { +TrueTypeFont::TrueTypeFont() { _font = nullptr; } -Font::Font(const String &file_name, const int ptsize, const int index) { +TrueTypeFont::TrueTypeFont(const String &file_name, const int ptsize, const int index) { _font = nullptr; load(file_name, ptsize, index); } -Font::~Font() { +TrueTypeFont::~TrueTypeFont() { free(); } \ No newline at end of file diff --git a/03_sdl_basics/16_sdl_ttf/font.h b/03_sdl_basics/16_sdl_ttf/true_type_font.h similarity index 89% rename from 03_sdl_basics/16_sdl_ttf/font.h rename to 03_sdl_basics/16_sdl_ttf/true_type_font.h index acd4504..62cf8d5 100644 --- a/03_sdl_basics/16_sdl_ttf/font.h +++ b/03_sdl_basics/16_sdl_ttf/true_type_font.h @@ -1,5 +1,5 @@ -#ifndef FONT_H -#define FONT_H +#ifndef TURE_TYPE_FONT_H +#define TURE_TYPE_FONT_H #include #include @@ -9,7 +9,7 @@ #include "vector2.h" #include "image.h" -class Font { +class TrueTypeFont { public: struct GlyphMetric { int minx; @@ -40,7 +40,7 @@ public: int get_face_is_fixed_width(); char *get_face_family_name(); - char *get_font_face_style_name(); + char *get_face_style_name(); bool is_glyph_provided(Uint16 ch); @@ -69,9 +69,9 @@ public: void load(const String &file_name, const int ptsize, const int index = -1); void free(); - Font(); - Font(const String &file_name, const int ptsize, const int index = -1); - ~Font(); + TrueTypeFont(); + TrueTypeFont(const String &file_name, const int ptsize, const int index = -1); + ~TrueTypeFont(); private: TTF_Font *_font;