From 71bc9818548897a91f03e724014466c3fc744e96 Mon Sep 17 00:00:00 2001 From: chaoskagami Date: Mon, 25 Aug 2014 01:28:01 -0400 Subject: [PATCH] As it turns out, setimg is actually based on NDS adapted coordinates by this formula: x = x * (width / 256) y = y * (height / 192). It appears that he was lazy when the Android port was made, and adapted coordinates got used rather than native in conversions. --- external/include/zero/TextManager.hpp | 4 ++-- external/include/zero/UDisplayable.hpp | 3 +++ external/src/zero/TextManager.cpp | 11 ++++++++--- external/src/zero/UDisplayable.cpp | 16 ++++++++++++++++ vndc/src/Loop.cpp | 6 +++++- vndc/src/op_setimg.cpp | 10 ++++++++-- 6 files changed, 42 insertions(+), 8 deletions(-) diff --git a/external/include/zero/TextManager.hpp b/external/include/zero/TextManager.hpp index 7e97530..574b20e 100644 --- a/external/include/zero/TextManager.hpp +++ b/external/include/zero/TextManager.hpp @@ -6,7 +6,7 @@ class TextManager { ~TextManager(); // Base font functions. - int LoadFont(char* fname); + int LoadFont(char* fname, int size); void Render(char* text); void Render(char* text, int x, int y); @@ -15,7 +15,7 @@ class TextManager { // Property functions. // void SetStyle(int style); - // void SetFontUsed(int font); + void SetFontUsed(int font); void SetColor(int r, int g, int b, int a); // Complex functions. diff --git a/external/include/zero/UDisplayable.hpp b/external/include/zero/UDisplayable.hpp index 076bdd8..eb8f004 100644 --- a/external/include/zero/UDisplayable.hpp +++ b/external/include/zero/UDisplayable.hpp @@ -28,6 +28,9 @@ typedef enum { int GetXI(); int GetYI(); + int GetW(); + int GetH(); + void Blit(); int* GetHitbox(); diff --git a/external/src/zero/TextManager.cpp b/external/src/zero/TextManager.cpp index 4109597..d741dd4 100644 --- a/external/src/zero/TextManager.cpp +++ b/external/src/zero/TextManager.cpp @@ -8,7 +8,7 @@ TextManager::TextManager(ContextManager* ct) { exit(-8); } - LoadFont((char*)"default.ttf"); + LoadFont((char*)"default.ttf", 20); color.r = 255; color.g = 255; @@ -28,13 +28,13 @@ TextManager::~TextManager() { TTF_Quit(); } -int TextManager::LoadFont(char* fname) { +int TextManager::LoadFont(char* fname, int size) { ++fonts_loaded; fonts = (TTF_Font**)realloc(fonts, sizeof(TTF_Font*) * fonts_loaded); - if ( !(fonts[fonts_loaded - 1] = TTF_OpenFont(fname, 20) ) ) { + if ( !(fonts[fonts_loaded - 1] = TTF_OpenFont(fname, size) ) ) { printf("Font Open Failed. Load attempt: %s. Msg: %s\n", fname, TTF_GetError()); } @@ -128,3 +128,8 @@ void TextManager::SetColor(int r, int g, int b, int a) color.b = b; color.a = a; } + +void TextManager::SetFontUsed(int index) +{ + current_font = index; +} diff --git a/external/src/zero/UDisplayable.cpp b/external/src/zero/UDisplayable.cpp index c85c925..80742b7 100644 --- a/external/src/zero/UDisplayable.cpp +++ b/external/src/zero/UDisplayable.cpp @@ -225,6 +225,22 @@ return this->loc.y; } + // Get Width + + int UDisplayable::GetW() { + if (Error) + return 0; + return this->bmp_w; + } + + // Get Height + + int UDisplayable::GetH() { + if (Error) + return 0; + return this->bmp_h; + } + // Blit to an associated context. void UDisplayable::Blit() { diff --git a/vndc/src/Loop.cpp b/vndc/src/Loop.cpp index aa7c8a6..fa7107c 100644 --- a/vndc/src/Loop.cpp +++ b/vndc/src/Loop.cpp @@ -55,7 +55,11 @@ void Setup() { GetData()->s_flags = new std::map(); GetData()->g_flags = new std::map(); - GetData()->ctx->Text()->Outline(2); + // Font + GetData()->ctx->Text()->LoadFont((char*)"default.ttf", 24); + GetData()->ctx->Text()->SetFontUsed(1); + + GetData()->ctx->Text()->Outline(1); GetData()->ctx->Text()->SetColor(255,255,255,255); op_cleartext(); diff --git a/vndc/src/op_setimg.cpp b/vndc/src/op_setimg.cpp index 88f708d..d1e66eb 100644 --- a/vndc/src/op_setimg.cpp +++ b/vndc/src/op_setimg.cpp @@ -4,7 +4,7 @@ /* * Implements setimg vnds function. - * bgload file x y + * setimg file x y */ void op_setimg(char* file, int* x, int* y) { @@ -21,7 +21,13 @@ void op_setimg(char* file, int* x, int* y) { // Load displayable. UDisplayable* fg_add = new UDisplayable(GetData()->ctx, Normal, path); - fg_add->SetXY(*x, *y); + // Centered NDS adapted + double adp_x = ((double)x[0]) * (GetData()->screen_w / 256); + double adp_y = ((double)y[0]) * (GetData()->screen_h / 192); + fg_add->SetXY((int)adp_x, (int)adp_y); + + // Raw + // fg_add->SetXY(x[0], y[0]); fg_add->Blit(); -- 2.39.5