From 0893c0857bb073f2ef6cb6514f46390f89cf62c4 Mon Sep 17 00:00:00 2001 From: dborth Date: Wed, 19 May 2010 21:52:59 +0000 Subject: [PATCH] finalize 2.1.6 --- hbc/meta.xml | 4 +- readme.txt | 10 ++- source/gui/gui.h | 7 ++ source/gui/gui_text.cpp | 133 ++++++++++++++++++++++++++++++------ source/utils/FreeTypeGX.cpp | 15 ++-- source/utils/FreeTypeGX.h | 4 +- source/vbagx.h | 2 +- update.xml | 4 +- 8 files changed, 149 insertions(+), 30 deletions(-) diff --git a/hbc/meta.xml b/hbc/meta.xml index 64498cb..caad30d 100644 --- a/hbc/meta.xml +++ b/hbc/meta.xml @@ -2,8 +2,8 @@ Visual Boy Advance GX Tantric - 2.1.5 - 20100409 + 2.1.6 + 20100519 GBA/GBC/GB Emulator A port of Visual Boy Advance - M to the Wii. diff --git a/readme.txt b/readme.txt index 8039d42..2b74837 100644 --- a/readme.txt +++ b/readme.txt @@ -1,7 +1,7 @@ ¸,ø¤°`°¤ø,¸¸,ø¤°`°¤ø,¸,ø¤°`°¤ø,¸¸,ø¤°`°¤ø,¸,ø¤°`°¤ø,¸¸,ø¤°`°¤ø,¸,ø¤°`°¤ø,¸¸,ø¤ - Visual Boy Advance GX - - Version 2.1.5 + Version 2.1.6 http://code.google.com/p/vba-wii (Under GPL License) @@ -28,6 +28,14 @@ With it you can play GBA/Game Boy Color/Game Boy games on your Wii/GameCube. |0O×øo· UPDATE HISTORY ·oø×O0| `¨•¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨' +[2.1.6 - May 19, 2010] + +* DVD support fixed +* Fixed some potential hangs when returning to menu +* Video/audio code changes +* Fixed scrolling text bug +* Other minor changes + [2.1.5 - April 9, 2010] * Fix auto-save bug diff --git a/source/gui/gui.h b/source/gui/gui.h index 61c5888..1b25522 100644 --- a/source/gui/gui.h +++ b/source/gui/gui.h @@ -641,6 +641,11 @@ class GuiText : public GuiElement //!Sets the text of the GuiText element //!\param t Text void SetText(const char * t); + //!Sets the text of the GuiText element + //!\param t UTF-8 Text + void SetWText(wchar_t * t); + //!Gets the translated text length of the GuiText element + int GetLength(); //!Sets up preset values to be used by GuiText(t) //!Useful when printing multiple text elements, all with the same attributes set //!\param sz Font size @@ -656,6 +661,8 @@ class GuiText : public GuiElement //!Sets the maximum width of the drawn texture image //!\param w Maximum width void SetMaxWidth(int w); + //!Gets the width of the text when rendered + int GetTextWidth(); //!Enables/disables text scrolling //!\param s Scrolling on/off void SetScroll(int s); diff --git a/source/gui/gui_text.cpp b/source/gui/gui_text.cpp index c96afbf..c2d3a09 100644 --- a/source/gui/gui_text.cpp +++ b/source/gui/gui_text.cpp @@ -49,6 +49,9 @@ GuiText::GuiText(const char * t, int s, GXColor c) origText = strdup(t); text = charToWideChar(gettext(t)); } + + for(int i=0; i < 20; i++) + textDyn[i] = NULL; } /** @@ -78,6 +81,9 @@ GuiText::GuiText(const char * t) origText = strdup(t); text = charToWideChar(gettext(t)); } + + for(int i=0; i < 20; i++) + textDyn[i] = NULL; } /** @@ -93,7 +99,8 @@ GuiText::~GuiText() if(textDynNum > 0) { for(int i=0; i < textDynNum; i++) - delete[] textDyn[i]; + if(textDyn[i]) + delete[] textDyn[i]; } } @@ -107,7 +114,8 @@ void GuiText::SetText(const char * t) if(textDynNum > 0) { for(int i=0; i < textDynNum; i++) - delete[] textDyn[i]; + if(textDyn[i]) + delete[] textDyn[i]; } origText = NULL; @@ -123,6 +131,38 @@ void GuiText::SetText(const char * t) } } +void GuiText::SetWText(wchar_t * t) +{ + if(origText) + free(origText); + if(text) + delete[] text; + + if(textDynNum > 0) + { + for(int i=0; i < textDynNum; i++) + if(textDyn[i]) + delete[] textDyn[i]; + } + + origText = NULL; + text = NULL; + textDynNum = 0; + textScrollPos = 0; + textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY; + + if(t) + text = wcsdup(t); +} + +int GuiText::GetLength() +{ + if(!text) + return 0; + + return wcslen(text); +} + void GuiText::SetPresets(int sz, GXColor c, int w, u16 s, int h, int v) { presetSize = sz; @@ -142,24 +182,49 @@ void GuiText::SetMaxWidth(int width) { maxWidth = width; - if(textDynNum > 0) + for(int i=0; i < textDynNum; i++) { - for(int i=0; i < textDynNum; i++) + if(textDyn[i]) + { delete[] textDyn[i]; + textDyn[i] = NULL; + } } + textDynNum = 0; } +int GuiText::GetTextWidth() +{ + if(!text) + return 0; + + if(currentSize != size) + { + ChangeFontSize(size); + + if(!fontSystem[size]) + fontSystem[size] = new FreeTypeGX(size); + + currentSize = size; + } + return fontSystem[size]->getWidth(text); +} + void GuiText::SetWrap(bool w, int width) { wrap = w; maxWidth = width; - if(textDynNum > 0) + for(int i=0; i < textDynNum; i++) { - for(int i=0; i < textDynNum; i++) + if(textDyn[i]) + { delete[] textDyn[i]; + textDyn[i] = NULL; + } } + textDynNum = 0; } @@ -168,11 +233,15 @@ void GuiText::SetScroll(int s) if(textScroll == s) return; - if(textDynNum > 0) + for(int i=0; i < textDynNum; i++) { - for(int i=0; i < textDynNum; i++) + if(textDyn[i]) + { delete[] textDyn[i]; + textDyn[i] = NULL; + } } + textDynNum = 0; textScroll = s; @@ -234,12 +303,17 @@ void GuiText::ResetText() text = charToWideChar(gettext(origText)); - if(textDynNum > 0) + for(int i=0; i < textDynNum; i++) { - for(int i=0; i < textDynNum; i++) + if(textDyn[i]) + { delete[] textDyn[i]; + textDyn[i] = NULL; + } } + textDynNum = 0; + currentSize = 0; } /** @@ -276,7 +350,6 @@ void GuiText::Draw() return; } - u32 maxChar = maxWidth*2.5 / (float)newSize; // approximate u32 textlen = wcslen(text); if(wrap) @@ -298,7 +371,7 @@ void GuiText::Draw() if(text[ch] == ' ' || ch == textlen-1) { - if(wcslen(textDyn[linenum]) >= maxChar) + if(fontSystem[currentSize]->getWidth(textDyn[linenum]) > maxWidth) { if(lastSpace >= 0) { @@ -344,14 +417,15 @@ void GuiText::Draw() { textDynNum = 1; textDyn[0] = wcsdup(text); + int len = wcslen(textDyn[0]); - if(textlen > maxChar) - textDyn[0][maxChar] = 0; + while(fontSystem[currentSize]->getWidth(textDyn[0]) > maxWidth) + textDyn[0][--len] = 0; } if(textScroll == SCROLL_HORIZONTAL) { - if(textlen > maxChar && (FrameTimer % textScrollDelay == 0)) + if(fontSystem[currentSize]->getWidth(text) > maxWidth && (FrameTimer % textScrollDelay == 0)) { if(textScrollInitialDelay) { @@ -366,15 +440,36 @@ void GuiText::Draw() textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY; } - wcsncpy(textDyn[0], &text[textScrollPos], maxChar-1); - + wcscpy(textDyn[0], &text[textScrollPos]); u32 dynlen = wcslen(textDyn[0]); - if(dynlen+2 < maxChar) + if(dynlen+2 < textlen) { textDyn[0][dynlen] = ' '; textDyn[0][dynlen+1] = ' '; - wcsncat(&textDyn[0][dynlen+2], text, maxChar - dynlen - 2); + textDyn[0][dynlen+2] = 0; + dynlen += 2; + } + + if(fontSystem[currentSize]->getWidth(textDyn[0]) > maxWidth) + { + while(fontSystem[currentSize]->getWidth(textDyn[0]) > maxWidth) + textDyn[0][--dynlen] = 0; + } + else + { + int i = 0; + + while(fontSystem[currentSize]->getWidth(textDyn[0]) < maxWidth && dynlen+1 < textlen) + { + textDyn[0][dynlen] = text[i++]; + textDyn[0][++dynlen] = 0; + } + + if(fontSystem[currentSize]->getWidth(textDyn[0]) > maxWidth) + textDyn[0][dynlen-2] = 0; + else + textDyn[0][dynlen-1] = 0; } } } diff --git a/source/utils/FreeTypeGX.cpp b/source/utils/FreeTypeGX.cpp index dffbf36..f7a4c53 100644 --- a/source/utils/FreeTypeGX.cpp +++ b/source/utils/FreeTypeGX.cpp @@ -38,6 +38,13 @@ void InitFreeType(uint8_t* fontBuffer, FT_Long bufferSize) fontSystem[i] = NULL; } +void DeinitFreeType() +{ + ClearFontData(); + FT_Done_FreeType(ftLibrary); + ftLibrary = NULL; +} + void ChangeFontSize(FT_UInt pixelSize) { FT_Set_Pixel_Sizes(ftFace, 0, pixelSize); @@ -544,10 +551,10 @@ uint16_t FreeTypeGX::getWidth(wchar_t *text) std::map::iterator thisEnd =this->fontData.end(); - for (uint32_t i = 0; i < strLength; ++i){ - + for (uint32_t i = 0; i < strLength; ++i) + { ftgxCharData* glyphData = NULL; - if( this->fontData.find(text[i]) != thisEnd) + if(this->fontData.find(text[i]) != thisEnd) { glyphData = &this->fontData[text[i]]; } @@ -560,7 +567,7 @@ uint16_t FreeTypeGX::getWidth(wchar_t *text) { if(this->ftKerningEnabled && (i > 0)) { - FT_Get_Kerning( ftFace, this->fontData[text[i - 1]].glyphIndex, glyphData->glyphIndex, FT_KERNING_DEFAULT, &pairDelta ); + FT_Get_Kerning(ftFace, this->fontData[text[i - 1]].glyphIndex, glyphData->glyphIndex, FT_KERNING_DEFAULT, &pairDelta); strWidth += pairDelta.x >> 6; } strWidth += glyphData->glyphAdvanceX; diff --git a/source/utils/FreeTypeGX.h b/source/utils/FreeTypeGX.h index 2b428fc..6a9d599 100644 --- a/source/utils/FreeTypeGX.h +++ b/source/utils/FreeTypeGX.h @@ -155,13 +155,14 @@ #include #include FT_FREETYPE_H #include FT_BITMAP_H -#include "Metaphrasis.h" #include #include #include #include +#include "Metaphrasis.h" + #define MAX_FONT_SIZE 100 /*! \struct ftgxCharData_ @@ -236,6 +237,7 @@ typedef struct ftgxDataOffset_ ftgxDataOffset; const GXColor ftgxWhite = (GXColor){0xff, 0xff, 0xff, 0xff}; /**< Constant color value used only to sanitize Doxygen documentation. */ void InitFreeType(uint8_t* fontBuffer, FT_Long bufferSize); +void DeinitFreeType(); void ChangeFontSize(FT_UInt pixelSize); wchar_t* charToWideChar(const char* p); void ClearFontData(); diff --git a/source/vbagx.h b/source/vbagx.h index 75ddb61..ce27d44 100644 --- a/source/vbagx.h +++ b/source/vbagx.h @@ -16,7 +16,7 @@ #include "utils/FreeTypeGX.h" #define APPNAME "Visual Boy Advance GX" -#define APPVERSION "2.1.5" +#define APPVERSION "2.1.6" #define APPFOLDER "vbagx" #define PREF_FILE_NAME "settings.xml" #define PAL_FILE_NAME "palettes.xml" diff --git a/update.xml b/update.xml index 5e8ca07..f5e7ecf 100644 --- a/update.xml +++ b/update.xml @@ -1,4 +1,4 @@ - - + +