From 7f3fb10f2accca7eda6e3877dce8889747a668e9 Mon Sep 17 00:00:00 2001 From: Jeremie Roy Date: Tue, 23 Apr 2013 17:18:54 +0200 Subject: [PATCH] Remove namespace from font utility classes --- examples/10-font/font.cpp | 29 ++++++++++---------- examples/11-fontdfs/fontdfs.cpp | 14 +++++----- examples/common/cube_atlas.cpp | 5 ---- examples/common/cube_atlas.h | 5 +--- examples/common/font/font_manager.cpp | 18 ++---------- examples/common/font/font_manager.h | 14 +++------- examples/common/font/text_buffer_manager.cpp | 5 ---- examples/common/font/text_buffer_manager.h | 5 ---- 8 files changed, 29 insertions(+), 66 deletions(-) diff --git a/examples/10-font/font.cpp b/examples/10-font/font.cpp index ffe8f37e..715dea2d 100644 --- a/examples/10-font/font.cpp +++ b/examples/10-font/font.cpp @@ -61,17 +61,16 @@ int _main_(int /*_argc*/, char** /*_argv*/) } //init the text rendering system - bgfx_font::FontManager* fontManager = new bgfx_font::FontManager(512); - bgfx_font::TextBufferManager* textBufferManager = new bgfx_font::TextBufferManager(fontManager); + FontManager* fontManager = new FontManager(512); + TextBufferManager* textBufferManager = new TextBufferManager(fontManager); textBufferManager->init(s_shaderPath); - - + //load some truetype files - bgfx_font::TrueTypeHandle times_tt = fontManager->loadTrueTypeFromFile("c:/windows/fonts/times.ttf"); - bgfx_font::TrueTypeHandle consola_tt = fontManager->loadTrueTypeFromFile("c:/windows/fonts/consola.ttf"); + TrueTypeHandle times_tt = fontManager->loadTrueTypeFromFile("c:/windows/fonts/times.ttf"); + TrueTypeHandle consola_tt = fontManager->loadTrueTypeFromFile("c:/windows/fonts/consola.ttf"); //create some usable font with of a specific size - bgfx_font::FontHandle times_24 = fontManager->createFontByPixelSize(times_tt, 0, 24); + FontHandle times_24 = fontManager->createFontByPixelSize(times_tt, 0, 24); //preload glyphs and blit them to atlas fontManager->preloadGlyph(times_24, L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ. \n"); @@ -81,11 +80,11 @@ int _main_(int /*_argc*/, char** /*_argv*/) //this font doesn't have any preloaded glyph's but the truetype file is loaded //so glyph will be generated as needed - bgfx_font::FontHandle consola_16 = fontManager->createFontByPixelSize(consola_tt, 0, 16); + FontHandle consola_16 = fontManager->createFontByPixelSize(consola_tt, 0, 16); //create a static text buffer compatible with alpha font //a static text buffer content cannot be modified after its first submit. - bgfx_font::TextBufferHandle staticText = textBufferManager->createTextBuffer(bgfx_font::FONT_TYPE_ALPHA, bgfx_font::STATIC); + TextBufferHandle staticText = textBufferManager->createTextBuffer(FONT_TYPE_ALPHA, STATIC); //the pen position represent the top left of the box of the first line of text textBufferManager->setPenPosition(staticText, 20.0f, 100.0f); @@ -102,28 +101,28 @@ int _main_(int /*_argc*/, char** /*_argv*/) //text + bkg - textBufferManager->setStyle(staticText, bgfx_font::STYLE_BACKGROUND); + textBufferManager->setStyle(staticText, STYLE_BACKGROUND); textBufferManager->appendText(staticText, times_24, L"The quick brown fox jumps over the lazy dog\n"); //text + strike-through - textBufferManager->setStyle(staticText, bgfx_font::STYLE_STRIKE_THROUGH); + textBufferManager->setStyle(staticText, STYLE_STRIKE_THROUGH); textBufferManager->appendText(staticText, times_24, L"The quick brown fox jumps over the lazy dog\n"); //text + overline - textBufferManager->setStyle(staticText, bgfx_font::STYLE_OVERLINE); + textBufferManager->setStyle(staticText, STYLE_OVERLINE); textBufferManager->appendText(staticText, times_24, L"The quick brown fox jumps over the lazy dog\n"); //text + underline - textBufferManager->setStyle(staticText, bgfx_font::STYLE_UNDERLINE); + textBufferManager->setStyle(staticText, STYLE_UNDERLINE); textBufferManager->appendText(staticText, times_24, L"The quick brown fox jumps over the lazy dog\n"); //text + bkg + strike-through - textBufferManager->setStyle(staticText, bgfx_font::STYLE_BACKGROUND|bgfx_font::STYLE_STRIKE_THROUGH); + textBufferManager->setStyle(staticText, STYLE_BACKGROUND|STYLE_STRIKE_THROUGH); textBufferManager->appendText(staticText, times_24, L"The quick brown fox jumps over the lazy dog\n"); //create a transient buffer for realtime data - bgfx_font::TextBufferHandle transientText = textBufferManager->createTextBuffer(bgfx_font::FONT_TYPE_ALPHA, bgfx_font::TRANSIENT); + TextBufferHandle transientText = textBufferManager->createTextBuffer(FONT_TYPE_ALPHA, TRANSIENT); uint32_t w = 0,h = 0; diff --git a/examples/11-fontdfs/fontdfs.cpp b/examples/11-fontdfs/fontdfs.cpp index 1d5b607f..d7fc7d9c 100644 --- a/examples/11-fontdfs/fontdfs.cpp +++ b/examples/11-fontdfs/fontdfs.cpp @@ -62,18 +62,18 @@ int _main_(int /*_argc*/, char** /*_argv*/) } //init the text rendering system - bgfx_font::FontManager* fontManager = new bgfx_font::FontManager(512); - bgfx_font::TextBufferManager* textBufferManager = new bgfx_font::TextBufferManager(fontManager); + FontManager* fontManager = new FontManager(512); + TextBufferManager* textBufferManager = new TextBufferManager(fontManager); textBufferManager->init(s_shaderPath); //load a truetype files - bgfx_font::TrueTypeHandle times_tt = fontManager->loadTrueTypeFromFile("c:/windows/fonts/times.ttf"); - bgfx_font::FontHandle distance_font = fontManager->createFontByPixelSize(times_tt, 0, 48, bgfx_font::FONT_TYPE_DISTANCE); + TrueTypeHandle times_tt = fontManager->loadTrueTypeFromFile("c:/windows/fonts/times.ttf"); + FontHandle distance_font = fontManager->createFontByPixelSize(times_tt, 0, 48, FONT_TYPE_DISTANCE); //preload glyph and generate (generate bitmap's) fontManager->preloadGlyph(distance_font, L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ. \n"); uint32_t fontsCount = 0; - bgfx_font::FontHandle fonts[64]; + FontHandle fonts[64]; fonts[fontsCount++] = distance_font; //generate various sub distance field fonts at various size int step=4; @@ -81,13 +81,13 @@ int _main_(int /*_argc*/, char** /*_argv*/) { if(i<32) step = 2; //instantiate a usable font - bgfx_font::FontHandle font = fontManager->createScaledFontToPixelSize(distance_font, i); + FontHandle font = fontManager->createScaledFontToPixelSize(distance_font, i); fonts[fontsCount++] = font; } //You can unload the truetype files at this stage, but in that case, the set of glyph's will be limited to the set of preloaded glyph fontManager->unloadTrueType(times_tt); - bgfx_font::TextBufferHandle staticText = textBufferManager->createTextBuffer(bgfx_font::FONT_TYPE_DISTANCE, bgfx_font::STATIC); + TextBufferHandle staticText = textBufferManager->createTextBuffer(FONT_TYPE_DISTANCE, STATIC); textBufferManager->setPenPosition(staticText, 10.0f, 70.0f); textBufferManager->setTextColor(staticText, 0xFFFFFFFF); diff --git a/examples/common/cube_atlas.cpp b/examples/common/cube_atlas.cpp index 3f705807..baa95c53 100644 --- a/examples/common/cube_atlas.cpp +++ b/examples/common/cube_atlas.cpp @@ -7,9 +7,6 @@ #include #include "cube_atlas.h" -namespace bgfx -{ - //********** Rectangle packer implementation ************ class RectanglePacker { @@ -479,5 +476,3 @@ void Atlas::packUV( const AtlasRegion& region, uint8_t* vertexBuffer, uint32_t o break; } } - -} \ No newline at end of file diff --git a/examples/common/cube_atlas.h b/examples/common/cube_atlas.h index 70b10eaf..7f8ca118 100644 --- a/examples/common/cube_atlas.h +++ b/examples/common/cube_atlas.h @@ -14,9 +14,6 @@ #include -namespace bgfx -{ - struct AtlasRegion { enum Type @@ -133,4 +130,4 @@ private: AtlasRegion* m_regions; uint8_t* m_textureBuffer; -};} \ No newline at end of file +}; \ No newline at end of file diff --git a/examples/common/font/font_manager.cpp b/examples/common/font/font_manager.cpp index d12d96e2..4c607e3f 100644 --- a/examples/common/font/font_manager.cpp +++ b/examples/common/font/font_manager.cpp @@ -40,12 +40,6 @@ namespace stl { } #endif // BGFX_CONFIG_USE_TINYSTL - -#define BGFX_FONT_ASSERT(cond, message) assert((cond) && (message)); - -namespace bgfx_font -{ - class FontManager::TrueTypeFont { public: @@ -445,7 +439,7 @@ const uint16_t MAX_OPENED_FILES = 64; const uint16_t MAX_OPENED_FONT = 64; const uint32_t MAX_FONT_BUFFER_SIZE = 512*512*4; -FontManager::FontManager(bgfx::Atlas* atlas):m_filesHandles(MAX_OPENED_FILES), m_fontHandles(MAX_OPENED_FONT) +FontManager::FontManager(Atlas* atlas):m_filesHandles(MAX_OPENED_FILES), m_fontHandles(MAX_OPENED_FONT) { m_atlas = atlas; m_ownAtlas = false; @@ -454,7 +448,7 @@ FontManager::FontManager(bgfx::Atlas* atlas):m_filesHandles(MAX_OPENED_FILES), m FontManager::FontManager(uint32_t textureSideWidth):m_filesHandles(MAX_OPENED_FILES), m_fontHandles(MAX_OPENED_FONT) { - m_atlas = new bgfx::Atlas(textureSideWidth); + m_atlas = new Atlas(textureSideWidth); m_ownAtlas = true; init(); } @@ -781,12 +775,6 @@ bool FontManager::getGlyphInfo(FontHandle fontHandle, CodePoint_t codePoint, Gly bool FontManager::addBitmap(GlyphInfo& glyphInfo, const uint8_t* data) { - glyphInfo.regionIndex = m_atlas->addRegion((uint16_t) ceil(glyphInfo.width),(uint16_t) ceil(glyphInfo.height), data, bgfx::AtlasRegion::TYPE_GRAY); + glyphInfo.regionIndex = m_atlas->addRegion((uint16_t) ceil(glyphInfo.width),(uint16_t) ceil(glyphInfo.height), data, AtlasRegion::TYPE_GRAY); return true; } - - - - - -} diff --git a/examples/common/font/font_manager.h b/examples/common/font/font_manager.h index 65c86e89..07a40870 100644 --- a/examples/common/font/font_manager.h +++ b/examples/common/font/font_manager.h @@ -5,11 +5,7 @@ #include #include -namespace bgfx{ class Atlas; } - -namespace bgfx_font -{ - +class Atlas; enum FontType { FONT_TYPE_ALPHA = 0x00000100 , // L8 @@ -116,14 +112,14 @@ class FontManager { public: /// create the font manager using an external cube atlas (doesn't take ownership of the atlas) - FontManager(bgfx::Atlas* atlas); + FontManager(Atlas* atlas); /// create the font manager and create the texture cube as BGRA8 with linear filtering FontManager(uint32_t textureSideWidth = 512); ~FontManager(); /// retrieve the atlas used by the font manager (e.g. to add stuff to it) - bgfx::Atlas* getAtlas() { return m_atlas; } + Atlas* getAtlas() { return m_atlas; } /// load a TrueType font from a file path /// @return invalid handle if the loading fail @@ -191,7 +187,7 @@ private: bool addBitmap(GlyphInfo& glyphInfo, const uint8_t* data); bool m_ownAtlas; - (bgfx::Atlas* m_atlas; + (Atlas* m_atlas; bx::HandleAlloc m_fontHandles; CachedFont* m_cachedFonts; @@ -204,5 +200,3 @@ private: //temporary buffer to raster glyph uint8_t* m_buffer; }; - -} diff --git a/examples/common/font/text_buffer_manager.cpp b/examples/common/font/text_buffer_manager.cpp index 5d3399f9..b7b325b9 100644 --- a/examples/common/font/text_buffer_manager.cpp +++ b/examples/common/font/text_buffer_manager.cpp @@ -10,9 +10,6 @@ #include #include /* offsetof */ -namespace bgfx_font -{ - const uint16_t MAX_TEXT_BUFFER_COUNT = 64; long int fsize(FILE* _file) @@ -808,5 +805,3 @@ void TextBufferManager::clearTextBuffer(TextBufferHandle _handle) BufferCache& bc = m_textBuffers[_handle.idx]; bc.textBuffer->clearTextBuffer(); } - -} diff --git a/examples/common/font/text_buffer_manager.h b/examples/common/font/text_buffer_manager.h index 2a386c71..57720fbd 100644 --- a/examples/common/font/text_buffer_manager.h +++ b/examples/common/font/text_buffer_manager.h @@ -4,9 +4,6 @@ #pragma once #include "font_manager.h" -namespace bgfx_font -{ - BGFX_HANDLE(TextBufferHandle); /// type of vertex and index buffer to use with a TextBuffer @@ -86,5 +83,3 @@ private: bgfx::ProgramHandle m_distanceProgram; bgfx::ProgramHandle m_distanceSubpixelProgram; }; - -}