Kaynağa Gözat

Removed custom Font support

Thomas Buck 9 yıl önce
ebeveyn
işleme
f8dba33eea

+ 3
- 0
ChangeLog.md Dosyayı Görüntüle

@@ -2,6 +2,9 @@
2 2
 
3 3
 ## OpenRaider (0.1.4) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20150330 ]
6
+    * Removed custom Font support
7
+
5 8
     [ 20150326 ]
6 9
     * No longer including gl.h globally, now only using gl33.h where needed.
7 10
     * No longer including all of glm globally, only the vec2/3/4 and mat4x4.

+ 0
- 2
cmake/setup.sh Dosyayı Görüntüle

@@ -10,7 +10,5 @@ mkdir -p ~/.OpenRaider/sshots
10 10
 
11 11
 cp data/OpenRaider.ini ~/.OpenRaider/
12 12
 cp data/*.tga ~/.OpenRaider/data
13
-cp data/*.ttf ~/.OpenRaider/data
14
-cp data/*.pc ~/.OpenRaider/data
15 13
 
16 14
 echo "DONE"

+ 0
- 2
cmake/setup_mac.sh Dosyayı Görüntüle

@@ -9,8 +9,6 @@ if [ ! -d "${HOME}/.OpenRaider" ]; then
9 9
     mkdir -p ~/.OpenRaider/sshots
10 10
     cp ../Resources/defaults/OpenRaider.ini ~/.OpenRaider/
11 11
     cp ../Resources/defaults/*.tga ~/.OpenRaider/data
12
-    cp ../Resources/defaults/*.ttf ~/.OpenRaider/data
13
-    cp ../Resources/defaults/*.pc ~/.OpenRaider/data
14 12
     echo "DONE"
15 13
     osascript -e 'tell app "System Events" to display alert "Initial Configuration stored in ~/.OpenRaider\n\nView and edit OpenRaider.ini to your needs..."'
16 14
 fi

+ 0
- 2
cmake/setup_win.bat Dosyayı Görüntüle

@@ -9,8 +9,6 @@ if not exist "%UserProfile%\.OpenRaider" (
9 9
 	mkdir %UserProfile%\.OpenRaider\sshots
10 10
 	copy data\OpenRaider.ini %UserProfile%\.OpenRaider
11 11
 	copy data\*.tga %UserProfile%\.OpenRaider\data
12
-	copy data\*.ttf %UserProfile%\.OpenRaider\data
13
-	copy data\*.pc %UserProfile%\.OpenRaider\data
14 12
 	echo Done!
15 13
 ) else (
16 14
 	echo Already done

+ 0
- 2
data/OpenRaider.ini Dosyayı Görüntüle

@@ -5,8 +5,6 @@ set basedir    "~/.OpenRaider"
5 5
 set pakdir     "$(basedir)/paks"
6 6
 set audiodir   "$(basedir)/music"
7 7
 set datadir    "$(basedir)/data"
8
-set font       "$(datadir)/test.ttf"
9
-# set font       "$(datadir)/font.pc"
10 8
 
11 9
 # Windowing
12 10
 set size       1280 720

+ 0
- 2
data/Unix.in Dosyayı Görüntüle

@@ -5,8 +5,6 @@ set basedir    "@CMAKE_INSTALL_PREFIX@"
5 5
 set datadir    "$(basedir)/share/OpenRaider"
6 6
 set pakdir     "$(datadir)"
7 7
 set audiodir   "$(datadir)"
8
-set font       "$(datadir)/test.ttf"
9
-# set font       "$(datadir)/font.pc"
10 8
 
11 9
 # Windowing
12 10
 set size       1280 720

BIN
data/font.pc Dosyayı Görüntüle


BIN
data/test.ttf Dosyayı Görüntüle


+ 0
- 49
include/system/Font.h Dosyayı Görüntüle

@@ -1,49 +0,0 @@
1
-/*!
2
- * \file include/system/Font.h
3
- * \brief Font Interface
4
- *
5
- * \author xythobuz
6
- */
7
-
8
-#ifndef _FONT_H_
9
-#define _FONT_H_
10
-
11
-#include <string>
12
-
13
-/*!
14
- * \brief Font interface
15
- */
16
-class Font {
17
-  public:
18
-    static void shutdown();
19
-
20
-    static int initialize(std::string font = "");
21
-
22
-    static std::string getFontName() { return fontName; }
23
-
24
-    static unsigned int widthText(float scale, std::string s);
25
-
26
-    static unsigned int heightText(float scale, unsigned int maxWidth, std::string s);
27
-
28
-    static void drawText(unsigned int x, unsigned int y, float scale,
29
-                         glm::vec4 color, std::string s);
30
-
31
-    static void drawTextWrapped(unsigned int x, unsigned int y, float scale,
32
-                                glm::vec4 color, unsigned int maxWidth, std::string s);
33
-
34
-    static void drawTextCentered(unsigned int x, unsigned int y, float scale,
35
-                                 glm::vec4 color, unsigned int width, std::string s);
36
-
37
-    static void setShowFontBox(bool s) { showFontBox = s; }
38
-    static bool getShowFontBox() { return showFontBox; }
39
-
40
-  private:
41
-    static void drawFontBox(unsigned int x, unsigned int y, unsigned int w, unsigned int h);
42
-
43
-    static bool isInit;
44
-    static std::string fontName;
45
-    static bool showFontBox;
46
-};
47
-
48
-#endif
49
-

+ 0
- 30
include/system/FontImGui.h Dosyayı Görüntüle

@@ -1,30 +0,0 @@
1
-/*!
2
- * \file include/system/FontImGui.h
3
- * \brief Default Font Implementation
4
- *
5
- * \author xythobuz
6
- */
7
-
8
-#ifndef _FONT_IMGUI_H_
9
-#define _FONT_IMGUI_H_
10
-
11
-#include <string>
12
-
13
-/*!
14
- * \brief Default Font implementation
15
- */
16
-class FontImGui {
17
-  public:
18
-    static unsigned int widthText(float scale, std::string s);
19
-
20
-    static unsigned int heightText(float scale, unsigned int maxWidth, std::string s);
21
-
22
-    static void drawText(unsigned int x, unsigned int y, float scale,
23
-                         glm::vec4 color, std::string s);
24
-
25
-    static void drawTextWrapped(unsigned int x, unsigned int y, float scale,
26
-                                glm::vec4 color, unsigned int maxWidth, std::string s);
27
-};
28
-
29
-#endif
30
-

+ 0
- 52
include/system/FontTRLE.h Dosyayı Görüntüle

@@ -1,52 +0,0 @@
1
-/*!
2
- * \file include/system/FontTRLE.h
3
- * \brief Tomb Raider Level Editor Font loader
4
- *
5
- * \author xythobuz
6
- */
7
-
8
-#ifndef _FONT_TRLE_H_
9
-#define _FONT_TRLE_H_
10
-
11
-#include <vector>
12
-
13
-#include "system/Shader.h"
14
-
15
-/*!
16
- * \brief Tomb Raider Level Editor Font loader
17
- */
18
-class FontTRLE {
19
-  public:
20
-    static void shutdown();
21
-
22
-    static int initialize(std::string font);
23
-
24
-    static unsigned int widthText(float scale, std::string s);
25
-
26
-    static unsigned int heightText(float scale, unsigned int maxWidth, std::string s);
27
-
28
-    static void drawText(unsigned int x, unsigned int y, float scale,
29
-                         glm::vec4 color, std::string s);
30
-
31
-    static void drawTextWrapped(unsigned int x, unsigned int y, float scale,
32
-                                glm::vec4 color, unsigned int maxWidth, std::string s);
33
-
34
-  private:
35
-    static void setDefaultOffsets();
36
-    static void loadLPS(std::string f);
37
-    static void writeChar(unsigned int index, unsigned int xDraw, unsigned int yDraw, float scale,
38
-                          std::vector<glm::vec2>& vertices, std::vector<glm::vec2>& uvs);
39
-
40
-    static bool mFontInit;
41
-    static unsigned int mFontTexture;
42
-
43
-    // 106 entries: (x, y, w, h, offset)
44
-    static int offsets[106][5];
45
-    static int defaultOffsets[106][5];
46
-
47
-    static ShaderBuffer vertexBuffer;
48
-    static ShaderBuffer uvBuffer;
49
-};
50
-
51
-#endif
52
-

+ 0
- 61
include/system/FontTTF.h Dosyayı Görüntüle

@@ -1,61 +0,0 @@
1
-/*!
2
- * \file include/system/FontTTF.h
3
- * \brief TrueType Font Implementation
4
- *
5
- * \author xythobuz
6
- */
7
-
8
-#ifndef _FONT_TTF_H_
9
-#define _FONT_TTF_H_
10
-
11
-#include <string>
12
-#include <vector>
13
-
14
-#include "stb/stb_truetype.h"
15
-#include "system/Shader.h"
16
-
17
-class FontMapTTF {
18
-  public:
19
-    FontMapTTF();
20
-    FontMapTTF(FontMapTTF&& other);
21
-    ~FontMapTTF();
22
-
23
-    int initialize(unsigned char* fontData, int firstChar);
24
-    bool contains(int c);
25
-    int getTexture() { return texture; }
26
-    void getQuad(int c, float* xpos, float* ypos, stbtt_aligned_quad* quad);
27
-
28
-  private:
29
-    int begin;
30
-    int texture;
31
-    stbtt_packedchar* charInfo;
32
-};
33
-
34
-class FontTTF {
35
-  public:
36
-    static int initialize(std::string f);
37
-    static void shutdown();
38
-
39
-    static unsigned int widthText(float scale, std::string s);
40
-    static unsigned int heightText(float scale, unsigned int maxWidth, std::string s);
41
-
42
-    static void drawText(unsigned int x, unsigned int y, float scale,
43
-                         glm::vec4 color, std::string s);
44
-    static void drawTextWrapped(unsigned int x, unsigned int y, float scale,
45
-                                glm::vec4 color, unsigned int maxWidth, std::string s);
46
-
47
-  private:
48
-    static int charIsMapped(int c);
49
-    static int getQuad(int c, float* xpos, float* ypos, stbtt_aligned_quad* quad);
50
-    static void drawTextInternal(unsigned int x, unsigned int y, float scale,
51
-                                 glm::vec4 color, unsigned int maxWidth, std::string s,
52
-                                 bool drawWrapped);
53
-
54
-    static unsigned char* fontData;
55
-    static std::vector<FontMapTTF> maps;
56
-    static ShaderBuffer vertexBuffer;
57
-    static ShaderBuffer uvBuffer;
58
-};
59
-
60
-#endif
61
-

+ 1
- 1
include/system/Shader.h Dosyayı Görüntüle

@@ -76,7 +76,7 @@ class Shader {
76 76
     static void set2DState(bool on, bool depth = true);
77 77
 
78 78
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, glm::vec4 color, unsigned int texture,
79
-                       TextureStorage store = TextureStorage::SYSTEM, gl::GLenum = gl::GL_TRIANGLES,
79
+                       TextureStorage store = TextureStorage::SYSTEM, gl::GLenum mode = gl::GL_TRIANGLES,
80 80
                        ShaderTexture* target = nullptr, Shader& shader = textShader);
81 81
 
82 82
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, unsigned int texture, glm::mat4 MVP,

+ 2
- 4
src/CMakeLists.txt Dosyayı Görüntüle

@@ -152,7 +152,7 @@ if (APPLE)
152 152
     set (RESRCS ${RESRCS} ${MAC_ICON})
153 153
 
154 154
     # Copy Data
155
-    set (MAC_DATA "../data/font.pc" "../data/OpenRaider.ini" "../data/test.ttf" "../data/splash.tga")
155
+    set (MAC_DATA "../data/OpenRaider.ini" "../data/splash.tga")
156 156
     set_source_files_properties (${MAC_DATA} PROPERTIES MACOSX_PACKAGE_LOCATION Resources/defaults)
157 157
     set (RESRCS ${RESRCS} ${MAC_DATA})
158 158
 endif (APPLE)
@@ -238,9 +238,7 @@ elseif (NOT WIN32)
238 238
         RENAME "OpenRaider.ini")
239 239
 
240 240
     # Data files
241
-    install (FILES "${PROJECT_SOURCE_DIR}/data/font.pc"
242
-                    "${PROJECT_SOURCE_DIR}/data/splash.tga"
243
-                    "${PROJECT_SOURCE_DIR}/data/test.ttf"
241
+    install (FILES "${PROJECT_SOURCE_DIR}/data/splash.tga"
244 242
         DESTINATION "share/OpenRaider")
245 243
 endif (APPLE)
246 244
 

+ 0
- 1
src/Menu.cpp Dosyayı Görüntüle

@@ -14,7 +14,6 @@
14 14
 #include "RunTime.h"
15 15
 #include "UI.h"
16 16
 #include "TextureManager.h"
17
-#include "system/Font.h"
18 17
 #include "system/Window.h"
19 18
 #include "utils/random.h"
20 19
 #include "utils/strings.h"

+ 0
- 6
src/Render.cpp Dosyayı Görüntüle

@@ -15,7 +15,6 @@
15 15
 #include "Menu.h"
16 16
 #include "StaticMesh.h"
17 17
 #include "World.h"
18
-#include "system/Font.h"
19 18
 #include "system/Shader.h"
20 19
 #include "system/Window.h"
21 20
 #include "Render.h"
@@ -239,11 +238,6 @@ void Render::displayUI() {
239 238
         if (ImGui::Checkbox("StaticMesh##bbox", &showBoundingBox2)) {
240 239
             StaticMesh::setShowBoundingBox(showBoundingBox2);
241 240
         }
242
-        ImGui::SameLine();
243
-        bool showFontBox = Font::getShowFontBox();
244
-        if (ImGui::Checkbox("Font##bbox", &showFontBox)) {
245
-            Font::setShowFontBox(showFontBox);
246
-        }
247 241
 
248 242
         ImGui::Separator();
249 243
         ImGui::Text("Renderable Objects:");

+ 11
- 1
src/TextureManager.cpp Dosyayı Görüntüle

@@ -285,9 +285,19 @@ int TextureManager::getNextTileAnimation(int index, int tile) {
285 285
 
286 286
 BufferManager* TextureManager::getBufferManager(int tex, TextureStorage store) {
287 287
     auto& v = (store == TextureStorage::GAME) ? gameBuffers : systemBuffers;
288
-    while (v.size() <= (tex + 1)) {
288
+
289
+    /*! \fixme  Strange +2 needed, or else OpenRaider crashes hard.
290
+     * Normally, this should only be (tex). I had to increase it to
291
+     * (tex + 1) some time ago when OpenRaider crashed in relation to
292
+     * non-existing texture IDs. Now, after removing all custom Font
293
+     * support (one texture less loaded at startup), OR crashed again.
294
+     * Increasing this to (tex + 2) "fixed" the problem. Why?
295
+     */
296
+
297
+    while (v.size() <= (tex + 2)) {
289 298
         v.emplace_back(v.size(), store);
290 299
     }
300
+
291 301
     return &(v.at(tex));
292 302
 }
293 303
 

+ 1
- 1
src/UI.cpp Dosyayı Görüntüle

@@ -140,7 +140,7 @@ int UI::initialize() {
140 140
     style.ItemSpacing                           = ImVec2(2, 2);
141 141
     style.ItemInnerSpacing                      = ImVec2(1, 1);
142 142
     style.TouchExtraPadding                     = ImVec2(0, 0);
143
-    style.IndentSpacing                       = 3;
143
+    style.IndentSpacing                         = 3;
144 144
     style.ScrollbarWidth                        = 10;
145 145
 
146 146
     return 0;

+ 0
- 12
src/commands/CommandSet.cpp Dosyayı Görüntüle

@@ -9,7 +9,6 @@
9 9
 #include "Camera.h"
10 10
 #include "Log.h"
11 11
 #include "RunTime.h"
12
-#include "system/Font.h"
13 12
 #include "system/Sound.h"
14 13
 #include "system/Window.h"
15 14
 #include "utils/strings.h"
@@ -31,7 +30,6 @@ void CommandSet::printHelp() {
31 30
     Log::get(LOG_USER) << "  pakdir     STRING" << Log::endl;
32 31
     Log::get(LOG_USER) << "  audiodir   STRING" << Log::endl;
33 32
     Log::get(LOG_USER) << "  datadir    STRING" << Log::endl;
34
-    Log::get(LOG_USER) << "  font       STRING" << Log::endl;
35 33
     Log::get(LOG_USER) << "  size       INT INT" << Log::endl;
36 34
     Log::get(LOG_USER) << "  fullscreen BOOL" << Log::endl;
37 35
     Log::get(LOG_USER) << "  audio      BOOL" << Log::endl;
@@ -132,13 +130,6 @@ int CommandSet::execute(std::istream& args) {
132 130
         std::string temp;
133 131
         args >> temp;
134 132
         RunTime::setDataDir(expandNames(temp));
135
-    } else if (var.compare("font") == 0) {
136
-        std::string temp;
137
-        args >> temp;
138
-        int error = Font::initialize(expandNames(temp));
139
-        if (error != 0)
140
-            Log::get(LOG_USER) << "Error initializing font: " << expandNames(temp) << "(" << error << ")" <<
141
-                               Log::endl;
142 133
     } else {
143 134
         Log::get(LOG_USER) << "set-Error: Unknown variable (" << var.c_str() << ")" << Log::endl;
144 135
         return -1;
@@ -163,7 +154,6 @@ void CommandGet::printHelp() {
163 154
     Log::get(LOG_USER) << "  pakdir" << Log::endl;
164 155
     Log::get(LOG_USER) << "  audiodir" << Log::endl;
165 156
     Log::get(LOG_USER) << "  datadir" << Log::endl;
166
-    Log::get(LOG_USER) << "  font" << Log::endl;
167 157
     Log::get(LOG_USER) << "  size" << Log::endl;
168 158
     Log::get(LOG_USER) << "  fullscreen" << Log::endl;
169 159
     Log::get(LOG_USER) << "  audio" << Log::endl;
@@ -199,8 +189,6 @@ int CommandGet::execute(std::istream& args) {
199 189
         Log::get(LOG_USER) << RunTime::getAudioDir() << Log::endl;
200 190
     } else if (var.compare("datadir") == 0) {
201 191
         Log::get(LOG_USER) << RunTime::getDataDir() << Log::endl;
202
-    } else if (var.compare("font") == 0) {
203
-        Log::get(LOG_USER) << Font::getFontName() << Log::endl;
204 192
     } else {
205 193
         Log::get(LOG_USER) << "get-Error: Unknown variable (" << var << ")" << Log::endl;
206 194
         return -1;

+ 1
- 1
src/deps/CMakeLists.txt Dosyayı Görüntüle

@@ -1,7 +1,7 @@
1 1
 # Source files
2 2
 set (DEPS_SRCS ${DEPS_SRCS} "commander/commander.c" "commander/commander.h")
3 3
 set (DEPS_SRCS ${DEPS_SRCS} "imgui/imgui.cpp" "imgui/imgui.h" "imgui/imconfig.h" "imgui/stb_textedit.h")
4
-set (DEPS_SRCS ${DEPS_SRCS} "stb/stb.cpp" "stb/stb_image.h" "stb/stb_image_write.h" "stb/stb_truetype.h")
4
+set (DEPS_SRCS ${DEPS_SRCS} "stb/stb.cpp" "stb/stb_image.h" "stb/stb_image_write.h")
5 5
 
6 6
 # Add library
7 7
 add_library (OpenRaider_deps OBJECT ${DEPS_SRCS})

+ 6
- 6
src/deps/imgui/imgui.cpp Dosyayı Görüntüle

@@ -6603,7 +6603,7 @@ bool ImGui::Selectable(const char* label, bool selected, const ImVec2& size_arg)
6603 6603
     const ImGuiID id = window->GetID(label);
6604 6604
     const ImVec2 label_size = CalcTextSize(label, NULL, true);
6605 6605
     
6606
-    const float w = ImMax(label_size.x, window->Pos.x + ImGui::GetContentRegionMax().x - window->DC.CursorPos.x);
6606
+    const float w = ImMax(label_size.x, window->Pos.x + ImGui::GetContentRegionMax().x - style.AutoFitPadding.x - window->DC.CursorPos.x);
6607 6607
     const ImVec2 size(size_arg.x != 0.0f ? size_arg.x : w, size_arg.y != 0.0f ? size_arg.y : label_size.y);
6608 6608
     const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size);
6609 6609
     ItemSize(bb);
@@ -7555,10 +7555,10 @@ void ImDrawList::AddVtxUV(const ImVec2& pos, ImU32 col, const ImVec2& uv)
7555 7555
 }
7556 7556
 
7557 7557
 // NB: memory should be reserved for 6 vertices by the caller.
7558
-void ImDrawList::AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col, float half_thickness)
7558
+void ImDrawList::AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness)
7559 7559
 {
7560 7560
     const float inv_length = 1.0f / sqrtf(ImLengthSqr(b - a));
7561
-    const ImVec2 hn = (b - a) * (half_thickness * inv_length);  // half normal
7561
+    const ImVec2 hn = (b - a) * (thickness * 0.5f * inv_length);// half normal
7562 7562
     const ImVec2 hp0 = ImVec2(+hn.y, -hn.x);                    // half perpendiculars + user offset
7563 7563
     const ImVec2 hp1 = ImVec2(-hn.y, +hn.x);
7564 7564
 
@@ -7571,13 +7571,13 @@ void ImDrawList::AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col, float h
7571 7571
     AddVtx(a + hp1, col);
7572 7572
 }
7573 7573
 
7574
-void ImDrawList::AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float half_thickness)
7574
+void ImDrawList::AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness)
7575 7575
 {
7576 7576
     if ((col >> 24) == 0)
7577 7577
         return;
7578 7578
 
7579 7579
     ReserveVertices(6);
7580
-    AddVtxLine(a, b, col, half_thickness);
7580
+    AddVtxLine(a, b, col, thickness);
7581 7581
 }
7582 7582
 
7583 7583
 void ImDrawList::AddArc(const ImVec2& center, float rad, ImU32 col, int a_min, int a_max, bool tris, const ImVec2& third_point_offset)
@@ -9715,7 +9715,7 @@ void ImGui::ShowTestWindow(bool* opened)
9715 9715
                 // Draw a line between the button and the mouse cursor
9716 9716
                 ImDrawList* draw_list = ImGui::GetWindowDrawList();
9717 9717
                 draw_list->PushClipRectFullScreen();
9718
-                draw_list->AddLine(ImGui::CalcItemRectClosestPoint(ImGui::GetIO().MousePos, true, -2.0f), ImGui::GetIO().MousePos, ImColor(ImGui::GetStyle().Colors[ImGuiCol_Button]), 2.0f);
9718
+                draw_list->AddLine(ImGui::CalcItemRectClosestPoint(ImGui::GetIO().MousePos, true, -2.0f), ImGui::GetIO().MousePos, ImColor(ImGui::GetStyle().Colors[ImGuiCol_Button]), 4.0f);
9719 9719
                 draw_list->PopClipRect();
9720 9720
             }
9721 9721
             ImGui::SameLine(); ImGui::Text("Raw (%.1f, %.1f), WithLockThresold (%.1f, %.1f)", value_raw.x, value_raw.y, value_with_lock_threshold.x, value_with_lock_threshold.y);

+ 2
- 2
src/deps/imgui/imgui.h Dosyayı Görüntüle

@@ -895,7 +895,7 @@ struct ImDrawList
895 895
     IMGUI_API void  PopTextureID();
896 896
 
897 897
     // Primitives   
898
-    IMGUI_API void  AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float half_thickness = 0.50f);
898
+    IMGUI_API void  AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness = 1.0f);
899 899
     IMGUI_API void  AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners=0x0F);
900 900
     IMGUI_API void  AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners=0x0F);
901 901
     IMGUI_API void  AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col);
@@ -913,7 +913,7 @@ struct ImDrawList
913 913
     IMGUI_API void  ReserveVertices(unsigned int vtx_count);
914 914
     IMGUI_API void  AddVtx(const ImVec2& pos, ImU32 col);
915 915
     IMGUI_API void  AddVtxUV(const ImVec2& pos, ImU32 col, const ImVec2& uv);
916
-    IMGUI_API void  AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col, float half_thickness = 0.50f);
916
+    IMGUI_API void  AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness = 1.0f);
917 917
     IMGUI_API void  UpdateClipRect();
918 918
     IMGUI_API void  UpdateTextureID();
919 919
 };

+ 0
- 8
src/deps/stb/stb.cpp Dosyayı Görüntüle

@@ -15,11 +15,3 @@
15 15
 #define STB_IMAGE_WRITE_IMPLEMENTATION
16 16
 #include "stb/stb_image_write.h"
17 17
 
18
-#define STB_RECT_PACK_IMPLEMENTATION
19
-#define STBRP_ASSERT orAssert
20
-#include "stb/stb_rect_pack.h"
21
-
22
-#define STB_TRUETYPE_IMPLEMENTATION
23
-#define STBTT_assert(x) orAssert(x)
24
-#include "stb/stb_truetype.h"
25
-

+ 0
- 546
src/deps/stb/stb_rect_pack.h Dosyayı Görüntüle

@@ -1,546 +0,0 @@
1
-// stb_rect_pack.h - v0.05 - public domain - rectangle packing
2
-// Sean Barrett 2014
3
-//
4
-// Useful for e.g. packing rectangular textures into an atlas.
5
-// Does not do rotation.
6
-//
7
-// Not necessarily the awesomest packing method, but better than
8
-// the totally naive one in stb_truetype (which is primarily what
9
-// this is meant to replace).
10
-//
11
-// Has only had a few tests run, may have issues.
12
-//
13
-// More docs to come.
14
-//
15
-// No memory allocations; uses qsort() and assert() from stdlib.
16
-//
17
-// This library currently uses the Skyline Bottom-Left algorithm.
18
-//
19
-// Please note: better rectangle packers are welcome! Please
20
-// implement them to the same API, but with a different init
21
-// function.
22
-//
23
-// Version history:
24
-//
25
-//     0.05:  added STBRP_ASSERT to allow replacing assert
26
-//     0.04:  fixed minor bug in STBRP_LARGE_RECTS support
27
-//     0.01:  initial release
28
-
29
-//////////////////////////////////////////////////////////////////////////////
30
-//
31
-//       INCLUDE SECTION
32
-//
33
-
34
-#ifndef STB_INCLUDE_STB_RECT_PACK_H
35
-#define STB_INCLUDE_STB_RECT_PACK_H
36
-
37
-#define STB_RECT_PACK_VERSION  1
38
-
39
-#ifdef STBRP_STATIC
40
-#define STBRP_DEF static
41
-#else
42
-#define STBRP_DEF extern
43
-#endif
44
-
45
-#ifdef __cplusplus
46
-extern "C" {
47
-#endif
48
-
49
-typedef struct stbrp_context stbrp_context;
50
-typedef struct stbrp_node    stbrp_node;
51
-typedef struct stbrp_rect    stbrp_rect;
52
-
53
-#ifdef STBRP_LARGE_RECTS
54
-typedef int            stbrp_coord;
55
-#else
56
-typedef unsigned short stbrp_coord;
57
-#endif
58
-
59
-STBRP_DEF void stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
60
-// Assign packed locations to rectangles. The rectangles are of type
61
-// 'stbrp_rect' defined below, stored in the array 'rects', and there
62
-// are 'num_rects' many of them.
63
-//
64
-// Rectangles which are successfully packed have the 'was_packed' flag
65
-// set to a non-zero value and 'x' and 'y' store the minimum location
66
-// on each axis (i.e. bottom-left in cartesian coordinates, top-left
67
-// if you imagine y increasing downwards). Rectangles which do not fit
68
-// have the 'was_packed' flag set to 0.
69
-//
70
-// You should not try to access the 'rects' array from another thread
71
-// while this function is running, as the function temporarily reorders
72
-// the array while it executes.
73
-//
74
-// To pack into another rectangle, you need to call stbrp_init_target
75
-// again. To continue packing into the same rectangle, you can call
76
-// this function again. Calling this multiple times with multiple rect
77
-// arrays will probably produce worse packing results than calling it
78
-// a single time with the full rectangle array, but the option is
79
-// available.
80
-
81
-struct stbrp_rect
82
-{
83
-   // reserved for your use:
84
-   int            id;
85
-
86
-   // input:
87
-   stbrp_coord    w, h;
88
-
89
-   // output:
90
-   stbrp_coord    x, y;
91
-   int            was_packed;  // non-zero if valid packing
92
-
93
-}; // 16 bytes, nominally
94
-
95
-
96
-STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes);
97
-// Initialize a rectangle packer to:
98
-//    pack a rectangle that is 'width' by 'height' in dimensions
99
-//    using temporary storage provided by the array 'nodes', which is 'num_nodes' long
100
-//
101
-// You must call this function every time you start packing into a new target.
102
-//
103
-// There is no "shutdown" function. The 'nodes' memory must stay valid for
104
-// the following stbrp_pack_rects() call (or calls), but can be freed after
105
-// the call (or calls) finish.
106
-//
107
-// Note: to guarantee best results, either:
108
-//       1. make sure 'num_nodes' >= 'width'
109
-//   or  2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1'
110
-//
111
-// If you don't do either of the above things, widths will be quantized to multiples
112
-// of small integers to guarantee the algorithm doesn't run out of temporary storage.
113
-//
114
-// If you do #2, then the non-quantized algorithm will be used, but the algorithm
115
-// may run out of temporary storage and be unable to pack some rectangles.
116
-
117
-STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem);
118
-// Optionally call this function after init but before doing any packing to
119
-// change the handling of the out-of-temp-memory scenario, described above.
120
-// If you call init again, this will be reset to the default (false).
121
-
122
-
123
-STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic);
124
-// Optionally select which packing heuristic the library should use. Different
125
-// heuristics will produce better/worse results for different data sets.
126
-// If you call init again, this will be reset to the default.
127
-
128
-enum
129
-{
130
-   STBRP_HEURISTIC_Skyline_default=0,
131
-   STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default,
132
-   STBRP_HEURISTIC_Skyline_BF_sortHeight,
133
-};
134
-
135
-
136
-//////////////////////////////////////////////////////////////////////////////
137
-//
138
-// the details of the following structures don't matter to you, but they must
139
-// be visible so you can handle the memory allocations for them
140
-
141
-struct stbrp_node
142
-{
143
-   stbrp_coord  x,y;
144
-   stbrp_node  *next;
145
-};
146
-
147
-struct stbrp_context
148
-{
149
-   int width;
150
-   int height;
151
-   int align;
152
-   int init_mode;
153
-   int heuristic;
154
-   int num_nodes;
155
-   stbrp_node *active_head;
156
-   stbrp_node *free_head;
157
-   stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2'
158
-};
159
-
160
-#ifdef __cplusplus
161
-}
162
-#endif
163
-
164
-#endif
165
-
166
-//////////////////////////////////////////////////////////////////////////////
167
-//
168
-//     IMPLEMENTATION SECTION
169
-//
170
-
171
-#ifdef STB_RECT_PACK_IMPLEMENTATION
172
-#include <stdlib.h>
173
-
174
-#ifndef STBRP_ASSERT
175
-#include <assert.h>
176
-#define STBRP_ASSERT assert
177
-#endif
178
-
179
-enum
180
-{
181
-   STBRP__INIT_skyline = 1,
182
-};
183
-
184
-STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
185
-{
186
-   switch (context->init_mode) {
187
-      case STBRP__INIT_skyline:
188
-         STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight);
189
-         context->heuristic = heuristic;
190
-         break;
191
-      default:
192
-         STBRP_ASSERT(0);
193
-   }
194
-}
195
-
196
-STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem)
197
-{
198
-   if (allow_out_of_mem)
199
-      // if it's ok to run out of memory, then don't bother aligning them;
200
-      // this gives better packing, but may fail due to OOM (even though
201
-      // the rectangles easily fit). @TODO a smarter approach would be to only
202
-      // quantize once we've hit OOM, then we could get rid of this parameter.
203
-      context->align = 1;
204
-   else {
205
-      // if it's not ok to run out of memory, then quantize the widths
206
-      // so that num_nodes is always enough nodes.
207
-      //
208
-      // I.e. num_nodes * align >= width
209
-      //                  align >= width / num_nodes
210
-      //                  align = ceil(width/num_nodes)
211
-
212
-      context->align = (context->width + context->num_nodes-1) / context->num_nodes;
213
-   }
214
-}
215
-
216
-STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
217
-{
218
-   int i;
219
-#ifndef STBRP_LARGE_RECTS
220
-   STBRP_ASSERT(width <= 0xffff && height <= 0xffff);
221
-#endif
222
-
223
-   for (i=0; i < num_nodes-1; ++i)
224
-      nodes[i].next = &nodes[i+1];
225
-   nodes[i].next = NULL;
226
-   context->init_mode = STBRP__INIT_skyline;
227
-   context->heuristic = STBRP_HEURISTIC_Skyline_default;
228
-   context->free_head = &nodes[0];
229
-   context->active_head = &context->extra[0];
230
-   context->width = width;
231
-   context->height = height;
232
-   context->num_nodes = num_nodes;
233
-   stbrp_setup_allow_out_of_mem(context, 0);
234
-
235
-   // node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly)
236
-   context->extra[0].x = 0;
237
-   context->extra[0].y = 0;
238
-   context->extra[0].next = &context->extra[1];
239
-   context->extra[1].x = (stbrp_coord) width;
240
-#ifdef STBRP_LARGE_RECTS
241
-   context->extra[1].y = (1<<30);
242
-#else
243
-   context->extra[1].y = 65535;
244
-#endif
245
-   context->extra[1].next = NULL;
246
-}
247
-
248
-// find minimum y position if it starts at x1
249
-static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste)
250
-{
251
-   stbrp_node *node = first;
252
-   int x1 = x0 + width;
253
-   int min_y, visited_width, waste_area;
254
-   STBRP_ASSERT(first->x <= x0);
255
-
256
-   #if 0
257
-   // skip in case we're past the node
258
-   while (node->next->x <= x0)
259
-      ++node;
260
-   #else
261
-   STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency
262
-   #endif
263
-
264
-   STBRP_ASSERT(node->x <= x0);
265
-
266
-   min_y = 0;
267
-   waste_area = 0;
268
-   visited_width = 0;
269
-   while (node->x < x1) {
270
-      if (node->y > min_y) {
271
-         // raise min_y higher.
272
-         // we've accounted for all waste up to min_y,
273
-         // but we'll now add more waste for everything we've visted
274
-         waste_area += visited_width * (node->y - min_y);
275
-         min_y = node->y;
276
-         // the first time through, visited_width might be reduced
277
-         if (node->x < x0)
278
-            visited_width += node->next->x - x0;
279
-         else
280
-            visited_width += node->next->x - node->x;
281
-      } else {
282
-         // add waste area
283
-         int under_width = node->next->x - node->x;
284
-         if (under_width + visited_width > width)
285
-            under_width = width - visited_width;
286
-         waste_area += under_width * (min_y - node->y);
287
-         visited_width += under_width;
288
-      }
289
-      node = node->next;
290
-   }
291
-
292
-   *pwaste = waste_area;
293
-   return min_y;
294
-}
295
-
296
-typedef struct
297
-{
298
-   int x,y;
299
-   stbrp_node **prev_link;
300
-} stbrp__findresult;
301
-
302
-static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height)
303
-{
304
-   int best_waste = (1<<30), best_x, best_y = (1 << 30);
305
-   stbrp__findresult fr;
306
-   stbrp_node **prev, *node, *tail, **best = NULL;
307
-
308
-   // align to multiple of c->align
309
-   width = (width + c->align - 1);
310
-   width -= width % c->align;
311
-   STBRP_ASSERT(width % c->align == 0);
312
-
313
-   node = c->active_head;
314
-   prev = &c->active_head;
315
-   while (node->x + width <= c->width) {
316
-      int y,waste;
317
-      y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste);
318
-      if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL
319
-         // bottom left
320
-         if (y < best_y) {
321
-            best_y = y;
322
-            best = prev;
323
-         }
324
-      } else {
325
-         // best-fit
326
-         if (y + height <= c->height) {
327
-            // can only use it if it first vertically
328
-            if (y < best_y || (y == best_y && waste < best_waste)) {
329
-               best_y = y;
330
-               best_waste = waste;
331
-               best = prev;
332
-            }
333
-         }
334
-      }
335
-      prev = &node->next;
336
-      node = node->next;
337
-   }
338
-
339
-   best_x = (best == NULL) ? 0 : (*best)->x;
340
-
341
-   // if doing best-fit (BF), we also have to try aligning right edge to each node position
342
-   //
343
-   // e.g, if fitting
344
-   //
345
-   //     ____________________
346
-   //    |____________________|
347
-   //
348
-   //            into
349
-   //
350
-   //   |                         |
351
-   //   |             ____________|
352
-   //   |____________|
353
-   //
354
-   // then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned
355
-   //
356
-   // This makes BF take about 2x the time
357
-
358
-   if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) {
359
-      tail = c->active_head;
360
-      node = c->active_head;
361
-      prev = &c->active_head;
362
-      // find first node that's admissible
363
-      while (tail->x < width)
364
-         tail = tail->next;
365
-      while (tail) {
366
-         int xpos = tail->x - width;
367
-         int y,waste;
368
-         STBRP_ASSERT(xpos >= 0);
369
-         // find the left position that matches this
370
-         while (node->next->x <= xpos) {
371
-            prev = &node->next;
372
-            node = node->next;
373
-         }
374
-         STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);
375
-         y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
376
-         if (y + height < c->height) {
377
-            if (y <= best_y) {
378
-               if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
379
-                  best_x = xpos;
380
-                  STBRP_ASSERT(y <= best_y);
381
-                  best_y = y;
382
-                  best_waste = waste;
383
-                  best = prev;
384
-               }
385
-            }
386
-         }
387
-         tail = tail->next;
388
-      }
389
-   }
390
-
391
-   fr.prev_link = best;
392
-   fr.x = best_x;
393
-   fr.y = best_y;
394
-   return fr;
395
-}
396
-
397
-static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height)
398
-{
399
-   // find best position according to heuristic
400
-   stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height);
401
-   stbrp_node *node, *cur;
402
-
403
-   // bail if:
404
-   //    1. it failed
405
-   //    2. the best node doesn't fit (we don't always check this)
406
-   //    3. we're out of memory
407
-   if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) {
408
-      res.prev_link = NULL;
409
-      return res;
410
-   }
411
-
412
-   // on success, create new node
413
-   node = context->free_head;
414
-   node->x = (stbrp_coord) res.x;
415
-   node->y = (stbrp_coord) (res.y + height);
416
-
417
-   context->free_head = node->next;
418
-
419
-   // insert the new node into the right starting point, and
420
-   // let 'cur' point to the remaining nodes needing to be
421
-   // stiched back in
422
-
423
-   cur = *res.prev_link;
424
-   if (cur->x < res.x) {
425
-      // preserve the existing one, so start testing with the next one
426
-      stbrp_node *next = cur->next;
427
-      cur->next = node;
428
-      cur = next;
429
-   } else {
430
-      *res.prev_link = node;
431
-   }
432
-
433
-   // from here, traverse cur and free the nodes, until we get to one
434
-   // that shouldn't be freed
435
-   while (cur->next && cur->next->x <= res.x + width) {
436
-      stbrp_node *next = cur->next;
437
-      // move the current node to the free list
438
-      cur->next = context->free_head;
439
-      context->free_head = cur;
440
-      cur = next;
441
-   }
442
-
443
-   // stitch the list back in
444
-   node->next = cur;
445
-
446
-   if (cur->x < res.x + width)
447
-      cur->x = (stbrp_coord) (res.x + width);
448
-
449
-#ifdef _DEBUG
450
-   cur = context->active_head;
451
-   while (cur->x < context->width) {
452
-      STBRP_ASSERT(cur->x < cur->next->x);
453
-      cur = cur->next;
454
-   }
455
-   STBRP_ASSERT(cur->next == NULL);
456
-
457
-   {
458
-      stbrp_node *L1 = NULL, *L2 = NULL;
459
-      int count=0;
460
-      cur = context->active_head;
461
-      while (cur) {
462
-         L1 = cur;
463
-         cur = cur->next;
464
-         ++count;
465
-      }
466
-      cur = context->free_head;
467
-      while (cur) {
468
-         L2 = cur;
469
-         cur = cur->next;
470
-         ++count;
471
-      }
472
-      STBRP_ASSERT(count == context->num_nodes+2);
473
-   }
474
-#endif
475
-
476
-   return res;
477
-}
478
-
479
-static int rect_height_compare(const void *a, const void *b)
480
-{
481
-   stbrp_rect *p = (stbrp_rect *) a;
482
-   stbrp_rect *q = (stbrp_rect *) b;
483
-   if (p->h > q->h)
484
-      return -1;
485
-   if (p->h < q->h)
486
-      return  1;
487
-   return (p->w > q->w) ? -1 : (p->w < q->w);
488
-}
489
-
490
-static int rect_width_compare(const void *a, const void *b)
491
-{
492
-   stbrp_rect *p = (stbrp_rect *) a;
493
-   stbrp_rect *q = (stbrp_rect *) b;
494
-   if (p->w > q->w)
495
-      return -1;
496
-   if (p->w < q->w)
497
-      return  1;
498
-   return (p->h > q->h) ? -1 : (p->h < q->h);
499
-}
500
-
501
-static int rect_original_order(const void *a, const void *b)
502
-{
503
-   stbrp_rect *p = (stbrp_rect *) a;
504
-   stbrp_rect *q = (stbrp_rect *) b;
505
-   return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
506
-}
507
-
508
-#ifdef STBRP_LARGE_RECTS
509
-#define STBRP__MAXVAL  0xffffffff
510
-#else
511
-#define STBRP__MAXVAL  0xffff
512
-#endif
513
-
514
-STBRP_DEF void stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
515
-{
516
-   int i;
517
-
518
-   // we use the 'was_packed' field internally to allow sorting/unsorting
519
-   for (i=0; i < num_rects; ++i) {
520
-      rects[i].was_packed = i;
521
-      #ifndef STBRP_LARGE_RECTS
522
-      STBRP_ASSERT(rects[i].w <= 0xffff && rects[i].h <= 0xffff);
523
-      #endif
524
-   }
525
-
526
-   // sort according to heuristic
527
-   qsort(rects, num_rects, sizeof(rects[0]), rect_height_compare);
528
-
529
-   for (i=0; i < num_rects; ++i) {
530
-      stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
531
-      if (fr.prev_link) {
532
-         rects[i].x = (stbrp_coord) fr.x;
533
-         rects[i].y = (stbrp_coord) fr.y;
534
-      } else {
535
-         rects[i].x = rects[i].y = STBRP__MAXVAL;
536
-      }
537
-   }
538
-
539
-   // unsort
540
-   qsort(rects, num_rects, sizeof(rects[0]), rect_original_order);
541
-
542
-   // set was_packed flags
543
-   for (i=0; i < num_rects; ++i)
544
-      rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL);
545
-}
546
-#endif

+ 0
- 2612
src/deps/stb/stb_truetype.h
Dosya farkı çok büyük olduğundan ihmal edildi
Dosyayı Görüntüle


+ 3
- 5
src/loader/Loader.cpp Dosyayı Görüntüle

@@ -38,12 +38,8 @@ Loader::LoaderVersion Loader::checkFile(std::string f) {
38 38
 
39 39
 std::unique_ptr<Loader> Loader::createLoader(std::string f) {
40 40
     LoaderVersion v = checkFile(f);
41
-    switch (v) {
42
-        case TR_4:
43
-        case TR_5:
44
-        case TR_UNKNOWN:
45
-            return nullptr;
46 41
 
42
+    switch (v) {
47 43
         case TR_1:
48 44
             return std::unique_ptr<Loader>(new LoaderTR1());
49 45
 
@@ -53,6 +49,8 @@ std::unique_ptr<Loader> Loader::createLoader(std::string f) {
53 49
         case TR_3:
54 50
             return std::unique_ptr<Loader>(new LoaderTR3());
55 51
     }
52
+
53
+    return nullptr;
56 54
 }
57 55
 
58 56
 Loader::~Loader() { }

+ 0
- 2
src/main.cpp Dosyayı Görüntüle

@@ -20,7 +20,6 @@
20 20
 #include "World.h"
21 21
 #include "commander/commander.h"
22 22
 #include "commands/Command.h"
23
-#include "system/Font.h"
24 23
 #include "system/Shader.h"
25 24
 #include "system/Sound.h"
26 25
 #include "system/Window.h"
@@ -130,7 +129,6 @@ int main(int argc, char* argv[]) {
130 129
 
131 130
     Menu::shutdown();
132 131
     UI::shutdown();
133
-    Font::shutdown();
134 132
     Sound::shutdown();
135 133
     Shader::shutdown();
136 134
     Window::shutdown();

+ 0
- 4
src/system/CMakeLists.txt Dosyayı Görüntüle

@@ -1,8 +1,4 @@
1 1
 # Source files
2
-set (SYS_SRCS ${SYS_SRCS} "Font.cpp" "../../include/system/Font.h")
3
-set (SYS_SRCS ${SYS_SRCS} "FontImGui.cpp" "../../include/system/FontImGui.h")
4
-set (SYS_SRCS ${SYS_SRCS} "FontTRLE.cpp" "../../include/system/FontTRLE.h")
5
-set (SYS_SRCS ${SYS_SRCS} "FontTTF.cpp" "../../include/system/FontTTF.h")
6 2
 set (SYS_SRCS ${SYS_SRCS} "Shader.cpp" "../../include/system/Shader.h")
7 3
 set (SYS_SRCS ${SYS_SRCS} "Sound.cpp" "../../include/system/Sound.h")
8 4
 set (SYS_SRCS ${SYS_SRCS} "Window.cpp" "../../include/system/Window.h")

+ 0
- 127
src/system/Font.cpp Dosyayı Görüntüle

@@ -1,127 +0,0 @@
1
-/*!
2
- * \file src/system/Font.cpp
3
- * \brief Font Interface
4
- *
5
- * \author xythobuz
6
- */
7
-
8
-#include <vector>
9
-
10
-#include "global.h"
11
-#include "Log.h"
12
-#include "utils/strings.h"
13
-#include "system/FontImGui.h"
14
-#include "system/FontTRLE.h"
15
-#include "system/FontTTF.h"
16
-#include "system/Shader.h"
17
-#include "system/Font.h"
18
-
19
-bool Font::isInit = false;
20
-std::string Font::fontName;
21
-bool Font::showFontBox = false;
22
-
23
-void Font::shutdown() {
24
-    FontTRLE::shutdown();
25
-    FontTTF::shutdown();
26
-}
27
-
28
-int Font::initialize(std::string font) {
29
-    fontName = font;
30
-    if (stringEndsWith(fontName, ".pc")) {
31
-        return FontTRLE::initialize(fontName);
32
-    } else if (stringEndsWith(fontName, ".ttf")) {
33
-        return FontTTF::initialize(fontName);
34
-    }
35
-
36
-    if (font != "") {
37
-        Log::get(LOG_ERROR) << "Unknown font file format: " << font << Log::endl;
38
-        return -1;
39
-    } else {
40
-        return 0;
41
-    }
42
-}
43
-
44
-unsigned int Font::widthText(float scale, std::string s) {
45
-    if (stringEndsWith(fontName, ".pc")) {
46
-        return FontTRLE::widthText(scale, s);
47
-    } else if (stringEndsWith(fontName, ".ttf")) {
48
-        return FontTTF::widthText(scale, s);
49
-    } else {
50
-        return FontImGui::widthText(scale, s);
51
-    }
52
-}
53
-
54
-unsigned int Font::heightText(float scale, unsigned int maxWidth, std::string s) {
55
-    if (stringEndsWith(fontName, ".pc")) {
56
-        return FontTRLE::heightText(scale, maxWidth, s);
57
-    } else if (stringEndsWith(fontName, ".ttf")) {
58
-        return FontTTF::heightText(scale, maxWidth, s);
59
-    } else {
60
-        return FontImGui::heightText(scale, maxWidth, s);
61
-    }
62
-}
63
-
64
-void Font::drawText(unsigned int x, unsigned int y, float scale,
65
-                    glm::vec4 color, std::string s) {
66
-    if (stringEndsWith(fontName, ".pc")) {
67
-        FontTRLE::drawText(x, y, scale, color, s);
68
-    } else if (stringEndsWith(fontName, ".ttf")) {
69
-        FontTTF::drawText(x, y, scale, color, s);
70
-    } else {
71
-        FontImGui::drawText(x, y, scale, color, s);
72
-    }
73
-
74
-    if (showFontBox) {
75
-        unsigned int w = widthText(scale, s);
76
-        unsigned int h = heightText(scale, w + 100, s); // Should always be one line
77
-        drawFontBox(x, y, w, h);
78
-    }
79
-}
80
-
81
-void Font::drawTextWrapped(unsigned int x, unsigned int y, float scale,
82
-                           glm::vec4 color, unsigned int maxWidth, std::string s) {
83
-    if (stringEndsWith(fontName, ".pc")) {
84
-        FontTRLE::drawTextWrapped(x, y, scale, color, maxWidth, s);
85
-    } else if (stringEndsWith(fontName, ".ttf")) {
86
-        FontTTF::drawTextWrapped(x, y, scale, color, maxWidth, s);
87
-    } else {
88
-        FontImGui::drawTextWrapped(x, y, scale, color, maxWidth, s);
89
-    }
90
-
91
-    if (showFontBox) {
92
-        unsigned int w = widthText(scale, s);
93
-        if (w > maxWidth)
94
-            w = maxWidth;
95
-        unsigned int h = heightText(scale, w, s); // Should always be one line
96
-        drawFontBox(x, y, w, h);
97
-    }
98
-}
99
-
100
-void Font::drawTextCentered(unsigned int x, unsigned int y, float scale,
101
-                            glm::vec4 color, unsigned int width, std::string s) {
102
-    drawText(x + ((width / 2) - (widthText(scale, s) / 2)), y, scale, color, s);
103
-}
104
-
105
-void Font::drawFontBox(unsigned int x, unsigned int y, unsigned int w, unsigned int h) {
106
-    static ShaderBuffer vert, uv;
107
-    std::vector<glm::vec2> vertices, uvs;
108
-
109
-    vertices.emplace_back(x, y);
110
-    vertices.emplace_back(x + w, y);
111
-    vertices.emplace_back(x + w, y + h);
112
-    vertices.emplace_back(x, y + h);
113
-    vertices.emplace_back(x, y);
114
-
115
-    uvs.emplace_back(0.0f, 0.0f);
116
-    uvs.emplace_back(1.0f, 0.0f);
117
-    uvs.emplace_back(1.0f, 1.0f);
118
-    uvs.emplace_back(0.0f, 1.0f);
119
-    uvs.emplace_back(0.0f, 0.0f);
120
-
121
-    vert.bufferData(vertices);
122
-    uv.bufferData(uvs);
123
-
124
-    Shader::drawGL(vert, uv, glm::vec4(1.0f, 1.0f, 0.0f, 1.0f), TEXTURE_WHITE,
125
-                   TextureStorage::SYSTEM, gl::GL_LINE_STRIP);
126
-}
127
-

+ 0
- 66
src/system/FontImGui.cpp Dosyayı Görüntüle

@@ -1,66 +0,0 @@
1
-/*!
2
- * \file src/system/FontImGui.cpp
3
- * \brief Default Font Implementation
4
- *
5
- * \author xythobuz
6
- */
7
-
8
-#include "imgui/imgui.h"
9
-
10
-#include "global.h"
11
-#include "UI.h"
12
-#include "system/FontImGui.h"
13
-
14
-#define SCALE_CALC 30.0f
15
-#define SCALE_DRAW SCALE_CALC
16
-
17
-unsigned int FontImGui::widthText(float scale, std::string s) {
18
-    ImGuiIO& io = ImGui::GetIO();
19
-    ImFont* font = io.Fonts->Fonts.at(0);
20
-    ImVec2 size = font->CalcTextSizeA(scale * SCALE_CALC, FLT_MAX, io.DisplaySize.y, s.c_str(),
21
-                                      s.c_str() + s.length());
22
-    return size.x;
23
-}
24
-
25
-void FontImGui::drawText(unsigned int x, unsigned int y, float scale,
26
-                         glm::vec4 color, std::string s) {
27
-    ImGuiIO& io = ImGui::GetIO();
28
-    ImFont* font = io.Fonts->Fonts.at(0);
29
-    ImVec2 pos = ImVec2(x, y);
30
-    ImU32 col = (ImU32(color.r * 255)) | (ImU32(color.g * 255) << 8) | (ImU32(color.b * 255) << 16) |
31
-                (ImU32(color.a * 255) << 24);
32
-
33
-    ImDrawList dl;
34
-    dl.PushTextureID(font->ContainerAtlas->TexID);
35
-    dl.PushClipRect(ImVec4(0.0f, 0.0f, io.DisplaySize.x, io.DisplaySize.y));
36
-    dl.AddText(font, scale * SCALE_DRAW, pos, col, s.c_str(), s.c_str() + s.length());
37
-
38
-    ImDrawList* dlp = &dl;
39
-    UI::renderImGui(&dlp, 1);
40
-}
41
-
42
-unsigned int FontImGui::heightText(float scale, unsigned int maxWidth, std::string s) {
43
-    ImGuiIO& io = ImGui::GetIO();
44
-    ImFont* font = io.Fonts->Fonts.at(0);
45
-    ImVec2 size = font->CalcTextSizeA(scale * SCALE_CALC, FLT_MAX, maxWidth, s.c_str(),
46
-                                      s.c_str() + s.length());
47
-    return size.y;
48
-}
49
-
50
-void FontImGui::drawTextWrapped(unsigned int x, unsigned int y, float scale,
51
-                                glm::vec4 color, unsigned int maxWidth, std::string s) {
52
-    ImGuiIO& io = ImGui::GetIO();
53
-    ImFont* font = io.Fonts->Fonts.at(0);
54
-    ImVec2 pos = ImVec2(x, y);
55
-    ImU32 col = (ImU32(color.r * 255)) | (ImU32(color.g * 255) << 8) | (ImU32(color.b * 255) << 16) |
56
-                (ImU32(color.a * 255) << 24);
57
-
58
-    ImDrawList dl;
59
-    dl.PushTextureID(font->ContainerAtlas->TexID);
60
-    dl.PushClipRect(ImVec4(0.0f, 0.0f, io.DisplaySize.x, io.DisplaySize.y));
61
-    dl.AddText(font, scale * SCALE_DRAW, pos, col, s.c_str(), s.c_str() + s.length(), maxWidth);
62
-
63
-    ImDrawList* dlp = &dl;
64
-    UI::renderImGui(&dlp, 1);
65
-}
66
-

+ 0
- 358
src/system/FontTRLE.cpp Dosyayı Görüntüle

@@ -1,358 +0,0 @@
1
-/*!
2
- * \file src/system/FontTRLE.cpp
3
- * \brief Tomb Raider Level Editor Font loader
4
- *
5
- * \author xythobuz
6
- */
7
-
8
-#include <fstream>
9
-#include <sstream>
10
-
11
-#include "global.h"
12
-#include "TextureManager.h"
13
-#include "utils/strings.h"
14
-#include "system/Shader.h"
15
-#include "system/FontTRLE.h"
16
-
17
-#define SCALING 2.0f
18
-
19
-bool FontTRLE::mFontInit = false;
20
-unsigned int FontTRLE::mFontTexture = 0;
21
-int FontTRLE::offsets[106][5];
22
-ShaderBuffer FontTRLE::vertexBuffer;
23
-ShaderBuffer FontTRLE::uvBuffer;
24
-
25
-void FontTRLE::shutdown() {
26
-}
27
-
28
-int FontTRLE::initialize(std::string font) {
29
-    orAssert(stringEndsWith(font, ".pc") == true);
30
-
31
-    shutdown();
32
-
33
-    // Load .pc file...
34
-    std::ifstream file(font, std::ios::in | std::ios::binary);
35
-    unsigned char* pixels = new unsigned char[256 * 256 * 4];
36
-    if (!file.read((char*)pixels, 256 * 256 * 4)) {
37
-        delete [] pixels;
38
-        return -1;
39
-    }
40
-
41
-    // Fix coloring
42
-    for (unsigned int i = 0; i < (256 * 256 * 4); i += 4) {
43
-        float y = (0.2126f * pixels[i + 2]);
44
-        y += (0.7152f * pixels[i + 1]);
45
-        y += (0.0722f * pixels[i]);
46
-        pixels[i] = pixels[i + 1] = pixels[i + 2] = (unsigned char)y;
47
-    }
48
-
49
-    mFontTexture = TextureManager::loadBufferSlot(pixels, 256, 256,
50
-                   ColorMode::BGRA, 32,
51
-                   TextureStorage::SYSTEM);
52
-    delete [] pixels;
53
-
54
-    // Try to load .lps file or use default glyph positions
55
-    std::string lpsFile = findAndReplace(font, ".pc", ".lps");
56
-    loadLPS(lpsFile);
57
-
58
-    mFontInit = true;
59
-    return 0;
60
-}
61
-
62
-void FontTRLE::loadLPS(std::string f) {
63
-    std::ifstream file(f);
64
-    if (!file) {
65
-        std::copy(&defaultOffsets[0][0], &defaultOffsets[0][0] + (106 * 5), &offsets[0][0]);
66
-        return;
67
-    }
68
-
69
-    for (std::string line; std::getline(file, line);) {
70
-        std::istringstream stream(line);
71
-        int index;
72
-        stream >> index;
73
-        if (stream.get() != '=')
74
-            continue;
75
-        stream >> offsets[index][0];
76
-        if (stream.get() != ',')
77
-            continue;
78
-        stream >> offsets[index][1];
79
-        if (stream.get() != ',')
80
-            continue;
81
-        stream >> offsets[index][2];
82
-        if (stream.get() != ',')
83
-            continue;
84
-        stream >> offsets[index][3];
85
-        if (stream.get() != ',')
86
-            continue;
87
-        stream >> offsets[index][4];
88
-    }
89
-}
90
-
91
-void FontTRLE::writeChar(unsigned int index, unsigned int xDraw, unsigned int yDraw, float scale,
92
-                         std::vector<glm::vec2>& vertices, std::vector<glm::vec2>& uvs) {
93
-    orAssert(mFontInit == true);
94
-
95
-    float width = ((float)offsets[index][2]) * scale * SCALING;
96
-    float height = ((float)offsets[index][3]) * scale * SCALING;
97
-    float offset = ((float)offsets[index][4]) * scale * SCALING;
98
-
99
-    // screen coordinates
100
-    float xMin = xDraw;
101
-    float yMin = yDraw + offset + (10.0f * scale * SCALING);
102
-    float xMax = xMin + width;
103
-    float yMax = yMin + height;
104
-
105
-    // texture part
106
-    float txMin = ((float)offsets[index][0]) / 256.0f;
107
-    float txMax = ((float)(offsets[index][0] + offsets[index][2])) / 256.0f;
108
-    float tyMin = ((float)offsets[index][1]) / 256.0f;
109
-    float tyMax = ((float)(offsets[index][1] + offsets[index][3])) / 256.0f;
110
-
111
-    vertices.push_back(glm::vec2(xMin, yMax));
112
-    vertices.push_back(glm::vec2(xMin, yMin));
113
-    vertices.push_back(glm::vec2(xMax, yMax));
114
-
115
-    vertices.push_back(glm::vec2(xMax, yMin));
116
-    vertices.push_back(glm::vec2(xMax, yMax));
117
-    vertices.push_back(glm::vec2(xMin, yMin));
118
-
119
-    uvs.push_back(glm::vec2(txMin, tyMax));
120
-    uvs.push_back(glm::vec2(txMin, tyMin));
121
-    uvs.push_back(glm::vec2(txMax, tyMax));
122
-
123
-    uvs.push_back(glm::vec2(txMax, tyMin));
124
-    uvs.push_back(glm::vec2(txMax, tyMax));
125
-    uvs.push_back(glm::vec2(txMin, tyMin));
126
-}
127
-
128
-unsigned int FontTRLE::widthText(float scale, std::string s) {
129
-    orAssert(mFontInit == true);
130
-    orAssert(s.length() > 0);
131
-
132
-    unsigned int width = 0;
133
-    for (unsigned int i = 0; i < s.length(); i++) {
134
-        // index into offset table
135
-        int index = s[i] - '!';
136
-
137
-        if (index == -1) // space
138
-            width += (unsigned int)(14.0f * scale * SCALING);
139
-
140
-        if ((index < 0) || (index > 105))
141
-            continue; // skip unprintable chars
142
-
143
-        width += (float)(offsets[index][2] + 1) * scale * SCALING; // glyph width
144
-    }
145
-
146
-    return width;
147
-}
148
-
149
-void FontTRLE::drawText(unsigned int x, unsigned int y, float scale,
150
-                        glm::vec4 color, std::string s) {
151
-    orAssert(mFontInit == true);
152
-    orAssert(s.length() > 0);
153
-
154
-    std::vector<glm::vec2> vertices;
155
-    std::vector<glm::vec2> uvs;
156
-    for (unsigned int i = 0; i < s.length(); i++) {
157
-        // index into offset table
158
-        int index = s[i] - '!';
159
-
160
-        if (index == -1) // space
161
-            x += (unsigned int)(14.0f * scale * SCALING);
162
-
163
-        if ((index < 0) || (index > 105))
164
-            continue; // skip unprintable chars
165
-
166
-        writeChar((unsigned int)index, x, y, scale, vertices, uvs);
167
-        x += (int)((float)(offsets[index][2] + 1) * scale * SCALING); // width
168
-    }
169
-
170
-    vertexBuffer.bufferData(vertices);
171
-    uvBuffer.bufferData(uvs);
172
-    Shader::drawGL(vertexBuffer, uvBuffer, color, mFontTexture);
173
-}
174
-
175
-unsigned int FontTRLE::heightText(float scale, unsigned int maxWidth, std::string s) {
176
-    orAssert(mFontInit == true);
177
-    orAssert(s.length() > 0);
178
-
179
-    unsigned int x = 0;
180
-    unsigned int yMax = 0;
181
-    unsigned int yReturn = 0;
182
-
183
-    for (unsigned int i = 0; i < s.length(); i++) {
184
-        // index into offset table
185
-        int index = s[i] - '!';
186
-
187
-        if (index == -1) // space
188
-            x += (unsigned int)(14.0f * scale * SCALING);
189
-
190
-        if ((index < 0) || (index > 105))
191
-            continue; // skip unprintable chars
192
-
193
-        if (yMax < (unsigned int)(((float)offsets[index][3]) * scale * SCALING))
194
-            yMax = (unsigned int)(((float)offsets[index][3]) * scale * SCALING);
195
-
196
-        x += (int)((float)(offsets[index][2] + 1) * scale * SCALING); // width
197
-        if (x > maxWidth) {
198
-            // go to the next line
199
-            yReturn += yMax + 2;
200
-            yMax = 0;
201
-            x = (int)((float)(offsets[index][2] + 1) * scale * SCALING);
202
-        }
203
-    }
204
-
205
-    return yReturn + yMax + 2;
206
-}
207
-
208
-void FontTRLE::drawTextWrapped(unsigned int x, unsigned int y, float scale,
209
-                               glm::vec4 color, unsigned int maxWidth, std::string s) {
210
-    orAssert(mFontInit == true);
211
-    orAssert(s.length() > 0);
212
-
213
-    unsigned int xStart = x;
214
-    unsigned int yMax = 0;
215
-
216
-    std::vector<glm::vec2> vertices;
217
-    std::vector<glm::vec2> uvs;
218
-    for (unsigned int i = 0; i < s.length(); i++) {
219
-        // index into offset table
220
-        int index = s[i] - '!';
221
-
222
-        if (index == -1) // space
223
-            x += (unsigned int)(14.0f * scale * SCALING);
224
-
225
-        if ((index < 0) || (index > 105))
226
-            continue; // skip unprintable chars
227
-
228
-        if (yMax < (unsigned int)(((float)offsets[index][3]) * scale * SCALING))
229
-            yMax = (unsigned int)(((float)offsets[index][3]) * scale * SCALING);
230
-
231
-        x += (int)((float)(offsets[index][2] + 1) * scale * SCALING); // width
232
-        if ((x - xStart) > maxWidth) {
233
-            // go to the next line
234
-            y += yMax + 2;
235
-            yMax = 0;
236
-            x = xStart;
237
-        } else {
238
-            x -= (int)((float)(offsets[index][2] + 1) * scale * SCALING);
239
-        }
240
-
241
-        writeChar((unsigned int)index, x, y, scale, vertices, uvs);
242
-        x += (int)((float)(offsets[index][2] + 1) * scale * SCALING); // width
243
-    }
244
-
245
-    vertexBuffer.bufferData(vertices);
246
-    uvBuffer.bufferData(uvs);
247
-    Shader::drawGL(vertexBuffer, uvBuffer, color, mFontTexture);
248
-}
249
-
250
-int FontTRLE::defaultOffsets[106][5] = {
251
-    { 174,  52,   3,  12, -11 },
252
-    {  98,  58,   6,   4, -10 },
253
-    {  82,  26,  13,  11, -10 },
254
-    {  78,  38,   9,  13, -10 },
255
-    { 214,  13,  14,  11, -9  },
256
-    {  40,  26,  13,  11, -10 },
257
-    { 157,  57,   5,   6, -11 },
258
-    { 204,  39,   5,  15, -12 },
259
-    {  34,  40,   5,  15, -12 },
260
-    { 184,  59,   4,   4, -11 },
261
-    {  22,  40,  10,  10, -9  },
262
-    { 178,  59,   4,   4, -2  },
263
-    { 106,  60,   7,   2, -4  },
264
-    { 114,  60,   4,   3, -2  },
265
-    { 212,  38,   8,  14, -12 },
266
-    {  88,  49,   9,   9, -8  },
267
-    { 200,  55,   5,   9, -8  },
268
-    {  46,  52,   8,   9, -8  },
269
-    {  88,  38,   7,  10, -8  },
270
-    {  62,  40,  10,  10, -8  },
271
-    { 142,  48,   8,  11, -9  },
272
-    { 232,  50,   8,  10, -9  },
273
-    { 120,  47,   8,  11, -9  },
274
-    {  22,  51,   8,  10, -9  },
275
-    { 110,  49,   8,  10, -8  },
276
-    { 152,  57,   4,   7, -7  },
277
-    { 136,  57,   4,   9, -7  },
278
-    { 178,  40,  11,   9, -8  },
279
-    { 210,  53,  10,   6, -7  },
280
-    { 240,  40,  11,   9, -7  },
281
-    {  12,  39,   9,  12, -11 },
282
-    {  66,  13,  15,  13, -10 },
283
-    { 130,  13,  13,  12, -11 },
284
-    { 214,  25,  12,  12, -11 },
285
-    { 132,  35,  10,  12, -11 },
286
-    {   0,  26,  12,  12, -11 },
287
-    {  14,  26,  12,  12, -11 },
288
-    {  66,  27,  11,  12, -11 },
289
-    { 182,  27,  11,  12, -11 },
290
-    { 200,  13,  13,  12, -11 },
291
-    { 222,  54,   4,  12, -11 },
292
-    {  56,  52,   4,  15, -11 },
293
-    { 230,  15,  12,  12, -11 },
294
-    { 144,  35,  10,  12, -11 },
295
-    {  48,  13,  17,  12, -11 },
296
-    { 144,  13,  13,  12, -11 },
297
-    {  54,  26,  11,  12, -11 },
298
-    { 200,  26,  11,  12, -11 },
299
-    { 240,   0,  13,  14, -11 },
300
-    { 158,  13,  13,  12, -11 },
301
-    { 156,  35,  10,  12, -11 },
302
-    { 172,  13,  13,  12, -11 },
303
-    {  98,  13,  14,  12, -11 },
304
-    {  82,  13,  14,  12, -11 },
305
-    {  24,  13,  22,  12, -11 },
306
-    { 186,  13,  12,  13, -11 },
307
-    { 114,  13,  14,  12, -11 },
308
-    { 228,  28,  11,  12, -11 },
309
-    {  62,  60,   5,   3, -4  },
310
-    { 248,  59,   5,   3, -4  },
311
-    {  88,  59,   7,   3, -4  },
312
-    { 142,  60,   6,   2, -3  },
313
-    { 120,  59,   7,   3, -4  },
314
-    { 242,  59,   4,   4, -11 },
315
-    {  98,  49,  10,   8, -7  },
316
-    {  96,  35,  10,  13, -12 },
317
-    {  72,  52,   8,   8, -7  },
318
-    {   0,  39,  10,  11, -10 },
319
-    { 164,  52,   8,   8, -7  },
320
-    { 168,  38,   9,  13, -12 },
321
-    { 120,  35,  11,  11, -7  },
322
-    { 108,  35,  10,  13, -12 },
323
-    { 194,  27,   5,  11, -10 },
324
-    {  40,  51,   5,  15, -10 },
325
-    {  28,  26,  11,  13, -12 },
326
-    {  82,  52,   5,  12, -11 },
327
-    {  96,  26,  17,   8, -7  },
328
-    { 152,  48,  11,   8, -7  },
329
-    {  62,  51,   9,   8, -7  },
330
-    { 244,  15,  10,  12, -7  },
331
-    {  52,  39,   9,  12, -7  },
332
-    {  10,  52,   9,   8, -7  },
333
-    { 190,  52,   8,   8, -7  },
334
-    {   0,  51,   8,  10, -9  },
335
-    { 178,  50,  10,   8, -7  },
336
-    { 130,  48,  11,   8, -7  },
337
-    { 132,  26,  17,   8, -7  },
338
-    { 242,  50,  10,   8, -7  },
339
-    {  40,  38,  10,  12, -7  },
340
-    { 232,  41,   7,   8, -7  },
341
-    { 222,  41,   8,  12, -7  },
342
-    { 130,  57,   5,   8, -7  },
343
-    { 194,  39,   9,  12, -10 },
344
-    {  32,  56,   4,  11, -10 },
345
-    {   1,  14,  22,  11, -10 },
346
-    { 192,   0,  23,  13, -10 },
347
-    { 168,   0,  23,  12, -10 },
348
-    { 216,   0,  23,  12, -10 },
349
-    { 150,  26,  17,   8, -8  },
350
-    { 168,  26,  11,  11, -9  },
351
-    { 114,  26,  17,   8, -8  },
352
-    { 240,  28,  12,  11, -9  },
353
-    {   0,   0,  40,  12, -10 },
354
-    {  84,   0,  39,  11, -10 },
355
-    {  42,   0,  39,  11, -10 },
356
-    { 126,   0,  39,  11, -10 },
357
-};
358
-

+ 0
- 279
src/system/FontTTF.cpp Dosyayı Görüntüle

@@ -1,279 +0,0 @@
1
-/*!
2
- * \file src/system/FontTTF.cpp
3
- * \brief TrueType Font Implementation
4
- *
5
- * \author xythobuz
6
- */
7
-
8
-#include <fstream>
9
-
10
-#include "global.h"
11
-#include "Log.h"
12
-#include "TextureManager.h"
13
-#include "utils/pixel.h"
14
-#include "system/FontTTF.h"
15
-
16
-#define MAP_WIDTH 512
17
-#define MAP_HEIGHT 512
18
-#define FONT_SIZE 33
19
-#define MAP_NUM_CHARS 100
20
-
21
-FontMapTTF::FontMapTTF() : begin(-1), texture(-1), charInfo(nullptr) { }
22
-
23
-FontMapTTF::FontMapTTF(FontMapTTF&& other) {
24
-    begin = other.begin;
25
-    texture = other.texture;
26
-    other.begin = other.texture = -1;
27
-    charInfo = other.charInfo;
28
-    other.charInfo = nullptr;
29
-}
30
-
31
-FontMapTTF::~FontMapTTF() {
32
-    if (charInfo != nullptr) {
33
-        delete [] charInfo;
34
-    }
35
-
36
-    if (texture > -1) {
37
-        //! \fixme Free the TextureManager buffer slot
38
-    }
39
-}
40
-
41
-int FontMapTTF::initialize(unsigned char* fontData, int firstChar) {
42
-    stbtt_pack_context context;
43
-    unsigned char* pixels = new unsigned char[MAP_WIDTH * MAP_HEIGHT];
44
-    if (!stbtt_PackBegin(&context, pixels, MAP_WIDTH, MAP_HEIGHT, 0, 1, nullptr)) {
45
-        delete [] pixels;
46
-        Log::get(LOG_ERROR) << "Error initializing font map in stbtt_PackBegin!" << Log::endl;
47
-        return -1;
48
-    }
49
-
50
-    stbtt_PackSetOversampling(&context, 2, 2);
51
-
52
-    if (charInfo != nullptr)
53
-        delete [] charInfo;
54
-
55
-    charInfo = new stbtt_packedchar[MAP_NUM_CHARS];
56
-    if (!stbtt_PackFontRange(&context, fontData, 0, FONT_SIZE, firstChar, MAP_NUM_CHARS, charInfo)) {
57
-        stbtt_PackEnd(&context);
58
-        delete [] pixels;
59
-        delete [] charInfo;
60
-        charInfo = nullptr;
61
-        Log::get(LOG_ERROR) << "Error packing font map!" << Log::endl;
62
-        return -2;
63
-    }
64
-
65
-    stbtt_PackEnd(&context);
66
-    unsigned char* rgb = grayscale2rgba(pixels, MAP_WIDTH, MAP_HEIGHT);
67
-    delete [] pixels;
68
-
69
-    texture = TextureManager::loadBufferSlot(rgb, MAP_WIDTH, MAP_HEIGHT, ColorMode::RGBA,
70
-              32, TextureStorage::SYSTEM, texture);
71
-    delete [] rgb;
72
-    if (texture < 0) {
73
-        delete [] charInfo;
74
-        charInfo = nullptr;
75
-        Log::get(LOG_ERROR) << "Error loading new font map texture!" << Log::endl;
76
-        return -3;
77
-    }
78
-
79
-    begin = firstChar;
80
-    return 0;
81
-}
82
-
83
-bool FontMapTTF::contains(int c) {
84
-    orAssert(begin >= 0);
85
-    return (begin >= 0) && (c >= begin) && (c < (begin + MAP_NUM_CHARS));
86
-}
87
-
88
-void FontMapTTF::getQuad(int c, float* xpos, float* ypos, stbtt_aligned_quad* quad) {
89
-    orAssert(contains(c));
90
-    stbtt_GetPackedQuad(charInfo, MAP_WIDTH, MAP_HEIGHT, c - begin, xpos, ypos, quad, 0);
91
-}
92
-
93
-// ----------------------------------------------------------------------------
94
-
95
-unsigned char* FontTTF::fontData = nullptr;
96
-std::vector<FontMapTTF> FontTTF::maps;
97
-ShaderBuffer FontTTF::vertexBuffer;
98
-ShaderBuffer FontTTF::uvBuffer;
99
-
100
-int FontTTF::initialize(std::string f) {
101
-    orAssert(f.length() > 0);
102
-
103
-    std::ifstream file(f, std::ios::binary);
104
-    if (!file) {
105
-        Log::get(LOG_ERROR) << "Couldn't open file \"" << f << "\"!" << Log::endl;
106
-        return -1;
107
-    }
108
-
109
-    file.seekg(0, std::ios::end);
110
-    auto size = file.tellg();
111
-    orAssert(size > 0);
112
-    file.seekg(0);
113
-
114
-    maps.clear();
115
-    if (fontData != nullptr) {
116
-        delete [] fontData;
117
-        fontData = nullptr;
118
-    }
119
-
120
-    fontData = new unsigned char[size];
121
-    if (!file.read(reinterpret_cast<char*>(fontData), size)) {
122
-        Log::get(LOG_ERROR) << "Couldn't read data in \"" << f << "\"" << Log::endl;
123
-        delete [] fontData;
124
-        fontData = nullptr;
125
-        return -2;
126
-    }
127
-
128
-    maps.emplace_back();
129
-    if (maps.at(0).initialize(fontData, ' ') < 0) {
130
-        delete [] fontData;
131
-        fontData = nullptr;
132
-        return -3;
133
-    }
134
-
135
-    return 0;
136
-}
137
-
138
-void FontTTF::shutdown() {
139
-    if (fontData != nullptr) {
140
-        delete [] fontData;
141
-        fontData = nullptr;
142
-    }
143
-
144
-    maps.clear();
145
-}
146
-
147
-unsigned int FontTTF::widthText(float scale, std::string s) {
148
-    float x = 0.0f, y = 0.0f;
149
-    stbtt_aligned_quad q;
150
-    for (int i = 0; i < s.length(); i++) {
151
-        if ((s[i] < 0x20) || (s[i] == 0x7F)) {
152
-            continue;
153
-        }
154
-
155
-        getQuad(s[i], &x, &y, &q);
156
-    }
157
-    return x * scale;
158
-}
159
-
160
-void FontTTF::drawText(unsigned int x, unsigned int y, float scale,
161
-                       glm::vec4 color, std::string s) {
162
-    drawTextInternal(x, y, scale, color, 0, s, false);
163
-}
164
-
165
-unsigned int FontTTF::heightText(float scale, unsigned int maxWidth, std::string s) {
166
-    float x = 0.0f, y = FONT_SIZE;
167
-    stbtt_aligned_quad q;
168
-    for (int i = 0; i < s.length(); i++) {
169
-        if ((s[i] < 0x20) || (s[i] == 0x7F)) {
170
-            continue;
171
-        }
172
-
173
-        getQuad(s[i], &x, &y, &q);
174
-        if (x > maxWidth) {
175
-            x = 0.0f;
176
-            y += FONT_SIZE;
177
-        }
178
-    }
179
-    return y * scale;
180
-}
181
-
182
-void FontTTF::drawTextWrapped(unsigned int x, unsigned int y, float scale,
183
-                              glm::vec4 color, unsigned int maxWidth, std::string s) {
184
-    drawTextInternal(x, y, scale, color, maxWidth, s, true);
185
-}
186
-
187
-void FontTTF::drawTextInternal(unsigned int x, unsigned int y, float scale,
188
-                               glm::vec4 color, unsigned int maxWidth, std::string s,
189
-                               bool drawWrapped) {
190
-    std::vector<glm::vec2> vertices;
191
-    std::vector<glm::vec2> uvs;
192
-    int texture = -1;
193
-    float xpos = x, ypos = y + (FONT_SIZE * scale);
194
-    for (int i = 0; i < s.length(); i++) {
195
-        if ((s[i] < 0x20) || (s[i] == 0x7F)) {
196
-            continue;
197
-        }
198
-
199
-        stbtt_aligned_quad quad;
200
-        int tex = getQuad(s[i], &xpos, &ypos, &quad);
201
-
202
-        if (drawWrapped && (xpos > (x + maxWidth))) {
203
-            xpos = x;
204
-            ypos += FONT_SIZE * scale;
205
-            if (s[i] != ' ')
206
-                i--;
207
-            continue;
208
-        }
209
-
210
-        if ((texture != tex) && (texture != -1)) {
211
-            vertexBuffer.bufferData(vertices);
212
-            uvBuffer.bufferData(uvs);
213
-            Shader::drawGL(vertexBuffer, uvBuffer, color, texture);
214
-            vertices.clear();
215
-            uvs.clear();
216
-        }
217
-
218
-        texture = tex;
219
-
220
-        float xmin = quad.x0;
221
-        float xmax = quad.x0 + ((quad.x1 - quad.x0) * scale);
222
-        float ymin = quad.y1;
223
-        float ymax = quad.y1 + ((quad.y0 - quad.y1) * scale);
224
-
225
-        vertices.emplace_back(xmin, ymin);
226
-        vertices.emplace_back(xmin, ymax);
227
-        vertices.emplace_back(xmax, ymax);
228
-        vertices.emplace_back(xmax, ymin);
229
-        vertices.emplace_back(xmin, ymin);
230
-        vertices.emplace_back(xmax, ymax);
231
-
232
-        uvs.emplace_back(quad.s0, quad.t1);
233
-        uvs.emplace_back(quad.s0, quad.t0);
234
-        uvs.emplace_back(quad.s1, quad.t0);
235
-        uvs.emplace_back(quad.s1, quad.t1);
236
-        uvs.emplace_back(quad.s0, quad.t1);
237
-        uvs.emplace_back(quad.s1, quad.t0);
238
-    }
239
-
240
-    vertexBuffer.bufferData(vertices);
241
-    uvBuffer.bufferData(uvs);
242
-    Shader::drawGL(vertexBuffer, uvBuffer, color, texture);
243
-}
244
-
245
-int FontTTF::charIsMapped(int c) {
246
-    for (int i = 0; i < maps.size(); i++) {
247
-        if (maps.at(i).contains(c)) {
248
-            return i;
249
-        }
250
-    }
251
-
252
-    int begin = c;
253
-    if (c >= (MAP_NUM_CHARS / 2))
254
-        begin -= (MAP_NUM_CHARS / 2);
255
-
256
-    Log::get(LOG_INFO) << "Unmapped character '" << char(c) << "', new map from " << begin << " to "
257
-                       << begin + MAP_NUM_CHARS - 1 << "..." << Log::endl;
258
-
259
-    int p = maps.size();
260
-    maps.emplace_back();
261
-    if (maps.at(p).initialize(fontData, begin) < 0) {
262
-        return -1;
263
-    }
264
-
265
-    return p;
266
-}
267
-
268
-int FontTTF::getQuad(int c, float* xpos, float* ypos, stbtt_aligned_quad* quad) {
269
-    if (c < 0) {
270
-        //! \fixme This has nothing to do with proper UTF8 support...
271
-        c += 128;
272
-    }
273
-
274
-    int map = charIsMapped(c);
275
-    orAssert(map >= 0);
276
-    maps.at(map).getQuad(c, xpos, ypos, quad);
277
-    return maps.at(map).getTexture();
278
-}
279
-

Loading…
İptal
Kaydet