diff options
Diffstat (limited to 'src/irrlicht_changes')
-rw-r--r-- | src/irrlicht_changes/CGUITTFont.cpp | 60 | ||||
-rw-r--r-- | src/irrlicht_changes/CGUITTFont.h | 43 | ||||
-rw-r--r-- | src/irrlicht_changes/static_text.cpp | 2 | ||||
-rw-r--r-- | src/irrlicht_changes/static_text.h | 2 |
4 files changed, 57 insertions, 50 deletions
diff --git a/src/irrlicht_changes/CGUITTFont.cpp b/src/irrlicht_changes/CGUITTFont.cpp index e785ea837..53be27319 100644 --- a/src/irrlicht_changes/CGUITTFont.cpp +++ b/src/irrlicht_changes/CGUITTFont.cpp @@ -1,7 +1,7 @@ /* CGUITTFont FreeType class for Irrlicht Copyright (c) 2009-2010 John Norman - Copyright (c) 2016 Nathanaël Courant + Copyright (c) 2016 Nathanaëlle Courant This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -59,7 +59,7 @@ struct SGUITTFace : public virtual irr::IReferenceCounted // Static variables. FT_Library CGUITTFont::c_library; -core::map<io::path, SGUITTFace*> CGUITTFont::c_faces; +std::map<io::path, SGUITTFace*> CGUITTFont::c_faces; bool CGUITTFont::c_libraryLoaded = false; scene::IMesh* CGUITTFont::shared_plane_ptr_ = 0; scene::SMesh CGUITTFont::shared_plane_; @@ -292,9 +292,6 @@ shadow_offset(0), shadow_alpha(0), fallback(0) Driver->grab(); setInvisibleCharacters(L" "); - - // Glyphs aren't reference counted, so don't try to delete them when we free the array. - Glyphs.set_free_when_destroyed(false); } bool CGUITTFont::load(const io::path& filename, const u32 size, const bool antialias, const bool transparency) @@ -320,11 +317,11 @@ bool CGUITTFont::load(const io::path& filename, const u32 size, const bool antia // Grab the face. SGUITTFace* face = 0; - core::map<io::path, SGUITTFace*>::Node* node = c_faces.find(filename); - if (node == 0) + auto node = c_faces.find(filename); + if (node == c_faces.end()) { face = new SGUITTFace(); - c_faces.set(filename, face); + c_faces.emplace(filename, face); if (filesystem) { @@ -334,7 +331,7 @@ bool CGUITTFont::load(const io::path& filename, const u32 size, const bool antia { if (logger) logger->log(L"CGUITTFont", L"Failed to open the file.", irr::ELL_INFORMATION); - c_faces.remove(filename); + c_faces.erase(filename); delete face; face = 0; return false; @@ -349,7 +346,7 @@ bool CGUITTFont::load(const io::path& filename, const u32 size, const bool antia { if (logger) logger->log(L"CGUITTFont", L"FT_New_Memory_Face failed.", irr::ELL_INFORMATION); - c_faces.remove(filename); + c_faces.erase(filename); delete face; face = 0; return false; @@ -362,7 +359,7 @@ bool CGUITTFont::load(const io::path& filename, const u32 size, const bool antia { if (logger) logger->log(L"CGUITTFont", L"FT_New_Face failed.", irr::ELL_INFORMATION); - c_faces.remove(filename); + c_faces.erase(filename); delete face; face = 0; return false; @@ -372,7 +369,7 @@ bool CGUITTFont::load(const io::path& filename, const u32 size, const bool antia else { // Using another instance of this face. - face = node->getValue(); + face = node->second; face->grab(); } @@ -411,21 +408,20 @@ CGUITTFont::~CGUITTFont() { // Delete the glyphs and glyph pages. reset_images(); - CGUITTAssistDelete::Delete(Glyphs); - //Glyphs.clear(); + Glyphs.clear(); // We aren't using this face anymore. - core::map<io::path, SGUITTFace*>::Node* n = c_faces.find(filename); - if (n) + auto n = c_faces.find(filename); + if (n != c_faces.end()) { - SGUITTFace* f = n->getValue(); + SGUITTFace* f = n->second; // Drop our face. If this was the last face, the destructor will clean up. if (f->drop()) - c_faces.remove(filename); + c_faces.erase(filename); // If there are no more faces referenced by FreeType, clean up. - if (c_faces.size() == 0) + if (c_faces.empty()) { FT_Done_FreeType(c_library); c_libraryLoaded = false; @@ -478,7 +474,7 @@ CGUITTGlyphPage* CGUITTFont::getLastGlyphPage() const CGUITTGlyphPage* CGUITTFont::createGlyphPage(const u8& pixel_mode) { CGUITTGlyphPage* page = 0; - + // Name of our page. io::path name("TTFontGlyphPage_"); name += tt_face->family_name; @@ -585,7 +581,7 @@ void CGUITTFont::draw(const EnrichedString &text, const core::rect<s32>& positio core::ustring utext = text.getString(); // Set up our render map. - core::map<u32, CGUITTGlyphPage*> Render_Map; + std::map<u32, CGUITTGlyphPage*> Render_Map; // Start parsing characters. u32 n; @@ -640,7 +636,7 @@ void CGUITTFont::draw(const EnrichedString &text, const core::rect<s32>& positio page->render_colors.push_back(colors[iter.getPos()]); else page->render_colors.push_back(video::SColor(255,255,255,255)); - Render_Map.set(glyph.glyph_page, page); + Render_Map[glyph.glyph_page] = page; } if (n > 0) { @@ -673,14 +669,14 @@ void CGUITTFont::draw(const EnrichedString &text, const core::rect<s32>& positio // Draw now. update_glyph_pages(); - core::map<u32, CGUITTGlyphPage*>::Iterator j = Render_Map.getIterator(); - while (!j.atEnd()) + auto it = Render_Map.begin(); + auto ie = Render_Map.end(); + core::array<core::vector2di> tmp_positions; + core::array<core::recti> tmp_source_rects; + while (it != ie) { - core::map<u32, CGUITTGlyphPage*>::Node* n = j.getNode(); - j++; - if (n == 0) continue; - - CGUITTGlyphPage* page = n->getValue(); + CGUITTGlyphPage* page = it->second; + ++it; if (shadow_offset) { for (size_t i = 0; i < page->render_positions.size(); ++i) @@ -698,10 +694,8 @@ void CGUITTFont::draw(const EnrichedString &text, const core::rect<s32>& positio do ++i; while (i < page->render_positions.size() && page->render_colors[i] == colprev); - core::array<core::vector2di> tmp_positions; - core::array<core::recti> tmp_source_rects; - tmp_positions.set_pointer(&page->render_positions[ibegin], i - ibegin, false, false); // no copy - tmp_source_rects.set_pointer(&page->render_source_rects[ibegin], i - ibegin, false, false); + tmp_positions.set_data(&page->render_positions[ibegin], i - ibegin); + tmp_source_rects.set_data(&page->render_source_rects[ibegin], i - ibegin); --i; if (!use_transparency) diff --git a/src/irrlicht_changes/CGUITTFont.h b/src/irrlicht_changes/CGUITTFont.h index 7b04ae828..2721364f5 100644 --- a/src/irrlicht_changes/CGUITTFont.h +++ b/src/irrlicht_changes/CGUITTFont.h @@ -1,7 +1,7 @@ /* CGUITTFont FreeType class for Irrlicht Copyright (c) 2009-2010 John Norman - Copyright (c) 2016 Nathanaël Courant + Copyright (c) 2016 Nathanaëlle Courant This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -34,8 +34,10 @@ #include <irrlicht.h> #include <ft2build.h> #include <vector> +#include <map> #include <irrUString.h> #include "util/enriched_string.h" +#include "util/basic_macros.h" #include FT_FREETYPE_H namespace irr @@ -45,23 +47,34 @@ namespace gui struct SGUITTFace; class CGUITTFont; - //! Class to assist in deleting glyphs. - class CGUITTAssistDelete - { - public: - template <class T, typename TAlloc> - static void Delete(core::array<T, TAlloc>& a) - { - TAlloc allocator; - allocator.deallocate(a.pointer()); - } - }; - //! Structure representing a single TrueType glyph. struct SGUITTGlyph { //! Constructor. - SGUITTGlyph() : isLoaded(false), glyph_page(0), surface(0), parent(0) {} + SGUITTGlyph() : + isLoaded(false), + glyph_page(0), + source_rect(), + offset(), + advance(), + surface(0), + parent(0) + {} + + DISABLE_CLASS_COPY(SGUITTGlyph); + + //! This class would be trivially copyable except for the reference count on `surface`. + SGUITTGlyph(SGUITTGlyph &&other) : + isLoaded(other.isLoaded), + glyph_page(other.glyph_page), + source_rect(other.source_rect), + offset(other.offset), + advance(other.advance), + surface(other.surface), + parent(other.parent) + { + other.surface = 0; + } //! Destructor. ~SGUITTGlyph() { unload(); } @@ -345,7 +358,7 @@ namespace gui private: // Manages the FreeType library. static FT_Library c_library; - static core::map<io::path, SGUITTFace*> c_faces; + static std::map<io::path, SGUITTFace*> c_faces; static bool c_libraryLoaded; static scene::IMesh* shared_plane_ptr_; static scene::SMesh shared_plane_; diff --git a/src/irrlicht_changes/static_text.cpp b/src/irrlicht_changes/static_text.cpp index baf0ea626..a4749bab1 100644 --- a/src/irrlicht_changes/static_text.cpp +++ b/src/irrlicht_changes/static_text.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2002-2012 Nikolaus Gebhardt -// Copyright (C) 2016 Nathanaël Courant: +// Copyright (C) 2016 Nathanaëlle Courant: // Modified the functions to use EnrichedText instead of string. // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in irrlicht.h diff --git a/src/irrlicht_changes/static_text.h b/src/irrlicht_changes/static_text.h index 74ef62008..fc58e3e90 100644 --- a/src/irrlicht_changes/static_text.h +++ b/src/irrlicht_changes/static_text.h @@ -1,5 +1,5 @@ // Copyright (C) 2002-2012 Nikolaus Gebhardt -// Copyright (C) 2016 Nathanaël Courant +// Copyright (C) 2016 Nathanaëlle Courant // Modified this class to work with EnrichedStrings too // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in irrlicht.h |