From 1ac23d2750bd4057eac7d65471b41412a7cd4c99 Mon Sep 17 00:00:00 2001 From: J-D-K Date: Sun, 4 Jun 2023 20:15:27 -0400 Subject: [PATCH] Fixes + Revisions to last commit --- inc/gfx/textureMgr.h | 1 + inc/ui/sldpanel.h | 1 - src/data.cpp | 4 +--- src/gfx.cpp | 8 +++++++- src/gfx/textureMgr.cpp | 18 +++++++++++++++++- src/ui/fld.cpp | 1 - src/ui/miscui.cpp | 4 +--- src/ui/sldpanel.cpp | 12 ++---------- src/ui/usr.cpp | 3 --- src/util.cpp | 2 +- 10 files changed, 30 insertions(+), 24 deletions(-) diff --git a/inc/gfx/textureMgr.h b/inc/gfx/textureMgr.h index 08820dc..62002b7 100644 --- a/inc/gfx/textureMgr.h +++ b/inc/gfx/textureMgr.h @@ -25,6 +25,7 @@ namespace gfx SDL_Texture *textureCreate(int _w, int _h); SDL_Texture *textureLoadFromFile(const char *_path); SDL_Texture *textureLoadFromMem(imgTypes _type, const void *_dat, size_t _datSize); + void textureResize(SDL_Texture **_tex, int _w, int _h); private: std::vector textures; diff --git a/inc/ui/sldpanel.h b/inc/ui/sldpanel.h index 26e1bb1..3476722 100644 --- a/inc/ui/sldpanel.h +++ b/inc/ui/sldpanel.h @@ -14,7 +14,6 @@ namespace ui { public: slideOutPanel(int _w, int _h, int _y, slidePanelOrientation _side, funcPtr _draw); - ~slideOutPanel(); void resizePanel(int _w, int _h, int _y); void update(); diff --git a/src/data.cpp b/src/data.cpp index 7bab6de..821fbd8 100644 --- a/src/data.cpp +++ b/src/data.cpp @@ -360,9 +360,7 @@ void data::init() void data::exit() { - for(data::user& u : data::users) u.delIcon(); - for(auto& tinfo : titles) - SDL_DestroyTexture(tinfo.second.icon); + /*Still needed for planned future revisions*/ } void data::setUserIndex(unsigned _sUser) diff --git a/src/gfx.cpp b/src/gfx.cpp index 330fb42..2a529a2 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -106,14 +106,20 @@ void gfx::init() gfx::texMgr = new gfx::textureMgr; loadSystemFont(); + + //This is to avoid blank, black glyphs + for(unsigned i = 0x20; i < 0x7E; i++) + gfx::drawTextf(NULL, 18, 32, 32, &ui::txtCont, "%c", i); } void gfx::exit() { + delete gfx::texMgr; + SDL_DestroyRenderer(gfx::render); + SDL_DestroyWindow(wind); IMG_Quit(); SDL_Quit(); freeSystemFont(); - delete gfx::texMgr; } void gfx::present() diff --git a/src/gfx/textureMgr.cpp b/src/gfx/textureMgr.cpp index fcb975c..1e74c3a 100644 --- a/src/gfx/textureMgr.cpp +++ b/src/gfx/textureMgr.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -18,9 +19,12 @@ void gfx::textureMgr::textureAdd(SDL_Texture *_tex) SDL_Texture *gfx::textureMgr::textureCreate(int _w, int _h) { SDL_Texture *ret = NULL; - ret = SDL_CreateTexture(gfx::render, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STATIC, _w, _h); + ret = SDL_CreateTexture(gfx::render, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STATIC | SDL_TEXTUREACCESS_TARGET, _w, _h); if(ret) + { + SDL_SetTextureBlendMode(ret, SDL_BLENDMODE_BLEND); textures.push_back(ret); + } return ret; } @@ -105,4 +109,16 @@ SDL_Texture *gfx::textureMgr::textureLoadFromMem(imgTypes _type, const void *_da textures.push_back(ret); return ret; +} + +void gfx::textureMgr::textureResize(SDL_Texture **_tex, int _w, int _h) +{ + auto texIt = std::find(textures.begin(), textures.end(), *_tex); + if(texIt != textures.end()) + { + SDL_DestroyTexture(*texIt); + *_tex = SDL_CreateTexture(gfx::render, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STATIC | SDL_TEXTUREACCESS_TARGET, _w, _h); + SDL_SetTextureBlendMode(*_tex, SDL_BLENDMODE_BLEND); + *texIt = *_tex; + } } \ No newline at end of file diff --git a/src/ui/fld.cpp b/src/ui/fld.cpp index 2751486..7c1dd26 100644 --- a/src/ui/fld.cpp +++ b/src/ui/fld.cpp @@ -290,7 +290,6 @@ void ui::fldExit() delete ui::fldPanel; delete fldMenu; delete fldList; - SDL_DestroyTexture(fldBuffer); } void ui::fldUpdate() diff --git a/src/ui/miscui.cpp b/src/ui/miscui.cpp index 7e843e4..32320e6 100644 --- a/src/ui/miscui.cpp +++ b/src/ui/miscui.cpp @@ -32,8 +32,7 @@ ui::menu::menu(const int& _x, const int& _y, const int& _rW, const int& _fS, con rH = _fS + 30; spcWidth = gfx::getTextWidth(" ", _fS) * 3; - optTex = SDL_CreateTexture(gfx::render, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STATIC | SDL_TEXTUREACCESS_TARGET, rW - 24, rH - 8); - SDL_SetTextureBlendMode(optTex, SDL_BLENDMODE_BLEND); + optTex = gfx::texMgr->textureCreate(rW - 24, rH - 8); } void ui::menu::editParam(int _param, int newVal) @@ -110,7 +109,6 @@ int ui::menu::getOptPos(const std::string& txt) ui::menu::~menu() { - SDL_DestroyTexture(optTex); opt.clear(); } diff --git a/src/ui/sldpanel.cpp b/src/ui/sldpanel.cpp index 33faaa0..b9abab0 100644 --- a/src/ui/sldpanel.cpp +++ b/src/ui/sldpanel.cpp @@ -15,13 +15,7 @@ ui::slideOutPanel::slideOutPanel(int _w, int _h, int _y, ui::slidePanelOrientati x = 1280; drawFunc = _draw; - panel = SDL_CreateTexture(gfx::render, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STATIC | SDL_TEXTUREACCESS_TARGET, w, h); - SDL_SetTextureBlendMode(panel, SDL_BLENDMODE_BLEND); -} - -ui::slideOutPanel::~slideOutPanel() -{ - SDL_DestroyTexture(panel); + panel = gfx::texMgr->textureCreate(w, h); } void ui::slideOutPanel::resizePanel(int _w, int _h, int _y) @@ -32,9 +26,7 @@ void ui::slideOutPanel::resizePanel(int _w, int _h, int _y) if(sldSide == ui::SLD_LEFT) x = -w; - SDL_DestroyTexture(panel); - panel = SDL_CreateTexture(gfx::render, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STATIC | SDL_TEXTUREACCESS_TARGET, w, h); - SDL_SetTextureBlendMode(panel, SDL_BLENDMODE_BLEND); + gfx::texMgr->textureResize(&panel, w, h); } void ui::slideOutPanel::update() diff --git a/src/ui/usr.cpp b/src/ui/usr.cpp index a7aa9a2..345d90b 100644 --- a/src/ui/usr.cpp +++ b/src/ui/usr.cpp @@ -444,9 +444,6 @@ void ui::usrExit() delete deviceSaveMenu; delete bcatSaveMenu; delete cacheSaveMenu; - - SDL_DestroyTexture(sett); - SDL_DestroyTexture(ext); } void ui::usrRefresh() diff --git a/src/util.cpp b/src/util.cpp index 2092b91..faaefd0 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -290,7 +290,7 @@ void util::replaceButtonsInString(std::string& rep) SDL_Texture *util::createIconGeneric(const char *txt, int fontSize, bool clearBack) { - SDL_Texture *ret = SDL_CreateTexture(gfx::render, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STATIC | SDL_TEXTUREACCESS_TARGET, 256, 256); + SDL_Texture *ret = gfx::texMgr->textureCreate(256, 256); SDL_SetRenderTarget(gfx::render, ret); if(clearBack) {