Commit 5fde15af authored by edo9300's avatar edo9300

Added nearest-neighbor anti-aliasing scaling for card pictures, from

https://github.com/Fluorohydride/ygopro/pull/2027
fixed for the window resizing
parent c68aad12
...@@ -902,10 +902,10 @@ void Game::DrawSpec() { ...@@ -902,10 +902,10 @@ void Game::DrawSpec() {
switch(showcard) { switch(showcard) {
case 1: { case 1: {
driver->draw2DImage(imageManager.GetTexture(showcardcode), mainGame->Resize(574, 150)); driver->draw2DImage(imageManager.GetTexture(showcardcode), mainGame->Resize(574, 150));
driver->draw2DImage(imageManager.tMask, mainGame->ResizeElem(574, 150, 574 + (showcarddif > 177 ? 177 : showcarddif), 404), driver->draw2DImage(imageManager.tMask, mainGame->ResizeElem(574, 150, 574 + (showcarddif > CARD_IMG_WIDTH ? CARD_IMG_WIDTH : showcarddif), 404),
recti(254 - showcarddif, 0, 254 - (showcarddif > 177 ? showcarddif - 177 : 0), 254), 0, 0, true); recti(CARD_IMG_HEIGHT - showcarddif, 0, CARD_IMG_HEIGHT - (showcarddif > CARD_IMG_WIDTH ? showcarddif - CARD_IMG_WIDTH : 0), CARD_IMG_HEIGHT), 0, 0, true);
showcarddif += 15; showcarddif += 15;
if(showcarddif >= 254) { if(showcarddif >= CARD_IMG_HEIGHT) {
showcard = 2; showcard = 2;
showcarddif = 0; showcarddif = 0;
} }
...@@ -913,9 +913,9 @@ void Game::DrawSpec() { ...@@ -913,9 +913,9 @@ void Game::DrawSpec() {
} }
case 2: { case 2: {
driver->draw2DImage(imageManager.GetTexture(showcardcode), mainGame->Resize(574, 150)); driver->draw2DImage(imageManager.GetTexture(showcardcode), mainGame->Resize(574, 150));
driver->draw2DImage(imageManager.tMask, mainGame->ResizeElem(574 + showcarddif, 150, 761, 404), recti(0, 0, 177 - showcarddif, 254), 0, 0, true); driver->draw2DImage(imageManager.tMask, mainGame->ResizeElem(574 + showcarddif, 150, 761, 404), recti(0, 0, CARD_IMG_WIDTH - showcarddif, 254), 0, 0, true);
showcarddif += 15; showcarddif += 15;
if(showcarddif >= 177) { if(showcarddif >= CARD_IMG_WIDTH) {
showcard = 0; showcard = 0;
} }
break; break;
...@@ -933,7 +933,7 @@ void Game::DrawSpec() { ...@@ -933,7 +933,7 @@ void Game::DrawSpec() {
matManager.c2d[2] = (showcarddif << 24) | 0xffffff; matManager.c2d[2] = (showcarddif << 24) | 0xffffff;
matManager.c2d[3] = (showcarddif << 24) | 0xffffff; matManager.c2d[3] = (showcarddif << 24) | 0xffffff;
driver->draw2DImage(imageManager.GetTexture(showcardcode), mainGame->ResizeElem(574, 154, 751, 404), driver->draw2DImage(imageManager.GetTexture(showcardcode), mainGame->ResizeElem(574, 154, 751, 404),
recti(0, 0, 177, 254), 0, matManager.c2d, true); recti(0, 0, CARD_IMG_WIDTH, CARD_IMG_HEIGHT), 0, matManager.c2d, true);
if(showcarddif < 255) if(showcarddif < 255)
showcarddif += 17; showcarddif += 17;
break; break;
...@@ -944,7 +944,7 @@ void Game::DrawSpec() { ...@@ -944,7 +944,7 @@ void Game::DrawSpec() {
matManager.c2d[2] = (showcarddif << 25) | 0xffffff; matManager.c2d[2] = (showcarddif << 25) | 0xffffff;
matManager.c2d[3] = (showcarddif << 25) | 0xffffff; matManager.c2d[3] = (showcarddif << 25) | 0xffffff;
driver->draw2DImage(imageManager.GetTexture(showcardcode), mainGame->ResizeElem(662 - showcarddif * 0.69685f, 277 - showcarddif, 662 + showcarddif * 0.69685f, 277 + showcarddif), driver->draw2DImage(imageManager.GetTexture(showcardcode), mainGame->ResizeElem(662 - showcarddif * 0.69685f, 277 - showcarddif, 662 + showcarddif * 0.69685f, 277 + showcarddif),
recti(0, 0, 177, 254), 0, matManager.c2d, true); recti(0, 0, CARD_IMG_WIDTH, CARD_IMG_HEIGHT), 0, matManager.c2d, true);
if(showcarddif < 127) if(showcarddif < 127)
showcarddif += 9; showcarddif += 9;
break; break;
...@@ -959,12 +959,12 @@ void Game::DrawSpec() { ...@@ -959,12 +959,12 @@ void Game::DrawSpec() {
} }
case 7: { case 7: {
core::position2d<s32> corner[4]; core::position2d<s32> corner[4];
float y = sin(showcarddif * 3.1415926f / 180.0f) * 254 * window_size.Height / 640; float y = sin(showcarddif * 3.1415926f / 180.0f) * CARD_IMG_HEIGHT * window_size.Height / 640;
corner[0] = core::position2d<s32>(574 * window_size.Width / 1024 - (254 * window_size.Height / 640 - y) * 0.3f, 404 * window_size.Height / 640 - y); corner[0] = core::position2d<s32>(574 * window_size.Width / 1024 - (CARD_IMG_HEIGHT * window_size.Height / 640 - y) * 0.3f, 404 * window_size.Height / 640 - y);
corner[1] = core::position2d<s32>(751 * window_size.Width / 1024 + (254 * window_size.Height / 640 - y) * 0.3f, 404 * window_size.Height / 640 - y); corner[1] = core::position2d<s32>(751 * window_size.Width / 1024 + (CARD_IMG_HEIGHT * window_size.Height / 640 - y) * 0.3f, 404 * window_size.Height / 640 - y);
corner[2] = core::position2d<s32>(574 * window_size.Width / 1024, 404 * window_size.Height / 640); corner[2] = core::position2d<s32>(574 * window_size.Width / 1024, 404 * window_size.Height / 640);
corner[3] = core::position2d<s32>(751 * window_size.Width / 1024, 404 * window_size.Height / 640); corner[3] = core::position2d<s32>(751 * window_size.Width / 1024, 404 * window_size.Height / 640);
irr::gui::Draw2DImageQuad(driver, imageManager.GetTexture(showcardcode), rect<s32>(0, 0, 177, 254), corner); irr::gui::Draw2DImageQuad(driver, imageManager.GetTexture(showcardcode), rect<s32>(0, 0, CARD_IMG_WIDTH, CARD_IMG_HEIGHT), corner);
showcardp++; showcardp++;
showcarddif += 9; showcarddif += 9;
if(showcarddif >= 90) if(showcarddif >= 90)
...@@ -1190,23 +1190,17 @@ void Game::WaitFrameSignal(int frame) { ...@@ -1190,23 +1190,17 @@ void Game::WaitFrameSignal(int frame) {
frameSignal.Wait(); frameSignal.Wait();
} }
void Game::DrawThumb(code_pointer cp, position2di pos, std::unordered_map<int, int>* lflist, bool drag) { void Game::DrawThumb(code_pointer cp, position2di pos, std::unordered_map<int, int>* lflist, bool drag) {
const int width = 44; //standard pic size, maybe it should be defined in game.h
const int height = 64;
int code = cp->first; int code = cp->first;
int lcode = cp->second.alias; int lcode = cp->second.alias;
if(lcode == 0) if(lcode == 0)
lcode = code; lcode = code;
irr::video::ITexture* img; irr::video::ITexture* img = imageManager.GetTextureThumb(code);
if (mainGame->window_size.Width > 1024 || mainGame->window_size.Height > 640)
img = imageManager.GetTexture(code);
else
img = imageManager.GetTextureThumb(code);
if(img == NULL) if(img == NULL)
return; //NULL->getSize() will cause a crash return; //NULL->getSize() will cause a crash
dimension2d<u32> size = img->getOriginalSize(); dimension2d<u32> size = img->getOriginalSize();
if (drag) { if (drag) {
recti dragloc = recti(pos.X, pos.Y, pos.X + width * mainGame->window_size.Width / 1024, pos.Y + height * mainGame->window_size.Height / 640); recti dragloc = recti(pos.X, pos.Y, pos.X + CARD_THUMB_WIDTH * mainGame->window_size.Width / 1024, pos.Y + CARD_THUMB_HEIGHT * mainGame->window_size.Height / 640);
recti limitloc = recti(pos.X, pos.Y, pos.X + 20 * mainGame->window_size.Width / 1024, pos.Y + 20 * mainGame->window_size.Height / 640); recti limitloc = recti(pos.X, pos.Y, pos.X + 20 * mainGame->window_size.Width / 1024, pos.Y + 20 * mainGame->window_size.Height / 640);
driver->draw2DImage(img, dragloc, rect<s32>(0, 0, size.Width, size.Height)); driver->draw2DImage(img, dragloc, rect<s32>(0, 0, size.Width, size.Height));
if (lflist->count(lcode)) { if (lflist->count(lcode)) {
...@@ -1223,7 +1217,7 @@ void Game::DrawThumb(code_pointer cp, position2di pos, std::unordered_map<int, i ...@@ -1223,7 +1217,7 @@ void Game::DrawThumb(code_pointer cp, position2di pos, std::unordered_map<int, i
} }
} }
} else { } else {
driver->draw2DImage(img, mainGame->Resize(pos.X, pos.Y, pos.X + width, pos.Y + height), rect<s32>(0, 0, size.Width, size.Height)); driver->draw2DImage(img, mainGame->Resize(pos.X, pos.Y, pos.X + CARD_THUMB_WIDTH, pos.Y + CARD_THUMB_HEIGHT), rect<s32>(0, 0, size.Width, size.Height));
if(lflist->count(lcode)) { if(lflist->count(lcode)) {
switch((*lflist)[lcode]) { switch((*lflist)[lcode]) {
......
...@@ -226,10 +226,10 @@ bool Game::Initialize() { ...@@ -226,10 +226,10 @@ bool Game::Initialize() {
btnHostPrepStart = env->addButton(rect<s32>(230, 280, 340, 305), wHostPrepare, BUTTON_HP_START, dataManager.GetSysString(1215)); btnHostPrepStart = env->addButton(rect<s32>(230, 280, 340, 305), wHostPrepare, BUTTON_HP_START, dataManager.GetSysString(1215));
btnHostPrepCancel = env->addButton(rect<s32>(350, 280, 460, 305), wHostPrepare, BUTTON_HP_CANCEL, dataManager.GetSysString(1210)); btnHostPrepCancel = env->addButton(rect<s32>(350, 280, 460, 305), wHostPrepare, BUTTON_HP_CANCEL, dataManager.GetSysString(1210));
//img //img
wCardImg = env->addStaticText(L"", rect<s32>(1, 1, 199, 273), true, false, 0, -1, true); wCardImg = env->addStaticText(L"", rect<s32>(1, 1, 1 + CARD_IMG_WIDTH + 20, 1 + CARD_IMG_HEIGHT + 18), true, false, 0, -1, true);
wCardImg->setBackgroundColor(0xc0c0c0c0); wCardImg->setBackgroundColor(0xc0c0c0c0);
wCardImg->setVisible(false); wCardImg->setVisible(false);
imgCard = env->addImage(rect<s32>(10, 9, 187, 263), wCardImg); imgCard = env->addImage(rect<s32>(10, 9, 10 + CARD_IMG_WIDTH, 9 + CARD_IMG_HEIGHT), wCardImg);
imgCard->setImage(imageManager.tCover[0]); imgCard->setImage(imageManager.tCover[0]);
imgCard->setUseAlphaChannel(true); imgCard->setUseAlphaChannel(true);
//phase //phase
...@@ -361,14 +361,14 @@ bool Game::Initialize() { ...@@ -361,14 +361,14 @@ bool Game::Initialize() {
btnPSAU->setImageScale(core::vector2df(0.5, 0.5)); btnPSAU->setImageScale(core::vector2df(0.5, 0.5));
btnPSAD = irr::gui::CGUIImageButton::addImageButton(env, rect<s32>(155, 45, 295, 185), wPosSelect, BUTTON_POS_AD); btnPSAD = irr::gui::CGUIImageButton::addImageButton(env, rect<s32>(155, 45, 295, 185), wPosSelect, BUTTON_POS_AD);
btnPSAD->setImageScale(core::vector2df(0.5, 0.5)); btnPSAD->setImageScale(core::vector2df(0.5, 0.5));
btnPSAD->setImage(imageManager.tCover[0], rect<s32>(0, 0, 177, 254)); btnPSAD->setImage(imageManager.tCover[0], rect<s32>(0, 0, CARD_IMG_WIDTH, CARD_IMG_HEIGHT));
btnPSDU = irr::gui::CGUIImageButton::addImageButton(env, rect<s32>(300, 45, 440, 185), wPosSelect, BUTTON_POS_DU); btnPSDU = irr::gui::CGUIImageButton::addImageButton(env, rect<s32>(300, 45, 440, 185), wPosSelect, BUTTON_POS_DU);
btnPSDU->setImageScale(core::vector2df(0.5, 0.5)); btnPSDU->setImageScale(core::vector2df(0.5, 0.5));
btnPSDU->setImageRotation(270); btnPSDU->setImageRotation(270);
btnPSDD = irr::gui::CGUIImageButton::addImageButton(env, rect<s32>(445, 45, 585, 185), wPosSelect, BUTTON_POS_DD); btnPSDD = irr::gui::CGUIImageButton::addImageButton(env, rect<s32>(445, 45, 585, 185), wPosSelect, BUTTON_POS_DD);
btnPSDD->setImageScale(core::vector2df(0.5, 0.5)); btnPSDD->setImageScale(core::vector2df(0.5, 0.5));
btnPSDD->setImageRotation(270); btnPSDD->setImageRotation(270);
btnPSDD->setImage(imageManager.tCover[0], rect<s32>(0, 0, 177, 254)); btnPSDD->setImage(imageManager.tCover[0], rect<s32>(0, 0, CARD_IMG_WIDTH, CARD_IMG_HEIGHT));
//card select //card select
wCardSelect = env->addWindow(rect<s32>(320, 100, 1000, 400), false, L""); wCardSelect = env->addWindow(rect<s32>(320, 100, 1000, 400), false, L"");
wCardSelect->getCloseButton()->setVisible(false); wCardSelect->getCloseButton()->setVisible(false);
...@@ -1170,7 +1170,7 @@ void Game::ShowCardInfo(int code) { ...@@ -1170,7 +1170,7 @@ void Game::ShowCardInfo(int code) {
wchar_t formatBuffer[256]; wchar_t formatBuffer[256];
if(!dataManager.GetData(code, &cd)) if(!dataManager.GetData(code, &cd))
memset(&cd, 0, sizeof(CardData)); memset(&cd, 0, sizeof(CardData));
imgCard->setImage(imageManager.GetTexture(code)); imgCard->setImage(imageManager.GetTexture(code, true));
imgCard->setScaleImage(true); imgCard->setScaleImage(true);
if(cd.alias != 0 && (cd.alias - code < 10 || code - cd.alias < 10)) if(cd.alias != 0 && (cd.alias - code < 10 || code - cd.alias < 10))
myswprintf(formatBuffer, L"%ls[%08d]", dataManager.GetName(cd.alias), cd.alias); myswprintf(formatBuffer, L"%ls[%08d]", dataManager.GetName(cd.alias), cd.alias);
...@@ -1433,8 +1433,8 @@ void Game::OnResize() ...@@ -1433,8 +1433,8 @@ void Game::OnResize()
wReplaySave->setRelativePosition(ResizeWin(510, 200, 820, 320)); wReplaySave->setRelativePosition(ResizeWin(510, 200, 820, 320));
stHintMsg->setRelativePosition(ResizeWin(500, 60, 820, 90)); stHintMsg->setRelativePosition(ResizeWin(500, 60, 820, 90));
wCardImg->setRelativePosition(Resize(1, 1, 199, 273)); wCardImg->setRelativePosition(Resize(1, 1, 1 + CARD_IMG_WIDTH + 20, 1 + CARD_IMG_HEIGHT + 18));
imgCard->setRelativePosition(Resize(10, 9, 187, 263)); imgCard->setRelativePosition(Resize(10, 9, 10 + CARD_IMG_WIDTH, 9 + CARD_IMG_HEIGHT));
wInfos->setRelativePosition(Resize(1, 275, 301, 639)); wInfos->setRelativePosition(Resize(1, 275, 301, 639));
stName->setRelativePosition(recti(10, 10, 287 * window_size.Width / 1024, 32)); stName->setRelativePosition(recti(10, 10, 287 * window_size.Width / 1024, 32));
stInfo->setRelativePosition(recti(15, 37, 296 * window_size.Width / 1024, 60)); stInfo->setRelativePosition(recti(15, 37, 296 * window_size.Width / 1024, 60));
...@@ -1498,6 +1498,8 @@ void Game::OnResize() ...@@ -1498,6 +1498,8 @@ void Game::OnResize()
btnChainIgnore->setRelativePosition(Resize(205, 100, 295, 135)); btnChainIgnore->setRelativePosition(Resize(205, 100, 295, 135));
btnChainWhenAvail->setRelativePosition(Resize(205, 180, 295, 215)); btnChainWhenAvail->setRelativePosition(Resize(205, 180, 295, 215));
btnCancelOrFinish->setRelativePosition(Resize(205, 230, 295, 265)); btnCancelOrFinish->setRelativePosition(Resize(205, 230, 295, 265));
imageManager.ClearTexture();
} }
recti Game::Resize(s32 x, s32 y, s32 x2, s32 y2) recti Game::Resize(s32 x, s32 y, s32 x2, s32 y2)
{ {
......
...@@ -469,6 +469,11 @@ extern Game* mainGame; ...@@ -469,6 +469,11 @@ extern Game* mainGame;
} }
#define CARD_IMG_WIDTH 177
#define CARD_IMG_HEIGHT 254
#define CARD_THUMB_WIDTH 44
#define CARD_THUMB_HEIGHT 64
#define UEVENT_EXIT 0x1 #define UEVENT_EXIT 0x1
#define UEVENT_TOWINDOW 0x2 #define UEVENT_TOWINDOW 0x2
......
#include "image_manager.h" #include "image_manager.h"
#include "game.h"
namespace ygo { namespace ygo {
...@@ -47,7 +48,11 @@ void ImageManager::SetDevice(irr::IrrlichtDevice* dev) { ...@@ -47,7 +48,11 @@ void ImageManager::SetDevice(irr::IrrlichtDevice* dev) {
driver = dev->getVideoDriver(); driver = dev->getVideoDriver();
} }
void ImageManager::ClearTexture() { void ImageManager::ClearTexture() {
for(auto tit = tMap.begin(); tit != tMap.end(); ++tit) { for(auto tit = tMap[0].begin(); tit != tMap[0].end(); ++tit) {
if(tit->second)
driver->removeTexture(tit->second);
}
for(auto tit = tMap[1].begin(); tit != tMap[1].end(); ++tit) {
if(tit->second) if(tit->second)
driver->removeTexture(tit->second); driver->removeTexture(tit->second);
} }
...@@ -55,40 +60,137 @@ void ImageManager::ClearTexture() { ...@@ -55,40 +60,137 @@ void ImageManager::ClearTexture() {
if(tit->second) if(tit->second)
driver->removeTexture(tit->second); driver->removeTexture(tit->second);
} }
tMap.clear(); tMap[0].clear();
tMap[1].clear();
tThumb.clear(); tThumb.clear();
} }
void ImageManager::RemoveTexture(int code) { void ImageManager::RemoveTexture(int code) {
auto tit = tMap.find(code); auto tit = tMap[0].find(code);
if(tit != tMap.end()) { if(tit != tMap[0].end()) {
if(tit->second)
driver->removeTexture(tit->second);
tMap[0].erase(tit);
}
tit = tMap[1].find(code);
if(tit != tMap[1].end()) {
if(tit->second) if(tit->second)
driver->removeTexture(tit->second); driver->removeTexture(tit->second);
tMap.erase(tit); tMap[1].erase(tit);
} }
} }
irr::video::ITexture* ImageManager::GetTexture(int code) { // function by Warr1024, from https://github.com/minetest/minetest/issues/2419 , modified
void imageScaleNNAA(irr::video::IImage *src, irr::video::IImage *dest) {
double sx, sy, minsx, maxsx, minsy, maxsy, area, ra, ga, ba, aa, pw, ph, pa;
u32 dy, dx;
irr::video::SColor pxl;
// Cache rectsngle boundaries.
double sw = src->getDimension().Width * 1.0;
double sh = src->getDimension().Height * 1.0;
// Walk each destination image pixel.
// Note: loop y around x for better cache locality.
irr::core::dimension2d<u32> dim = dest->getDimension();
for(dy = 0; dy < dim.Height; dy++)
for(dx = 0; dx < dim.Width; dx++) {
// Calculate floating-point source rectangle bounds.
minsx = dx * sw / dim.Width;
maxsx = minsx + sw / dim.Width;
minsy = dy * sh / dim.Height;
maxsy = minsy + sh / dim.Height;
// Total area, and integral of r, g, b values over that area,
// initialized to zero, to be summed up in next loops.
area = 0;
ra = 0;
ga = 0;
ba = 0;
aa = 0;
// Loop over the integral pixel positions described by those bounds.
for(sy = floor(minsy); sy < maxsy; sy++)
for(sx = floor(minsx); sx < maxsx; sx++) {
// Calculate width, height, then area of dest pixel
// that's covered by this source pixel.
pw = 1;
if(minsx > sx)
pw += sx - minsx;
if(maxsx < (sx + 1))
pw += maxsx - sx - 1;
ph = 1;
if(minsy > sy)
ph += sy - minsy;
if(maxsy < (sy + 1))
ph += maxsy - sy - 1;
pa = pw * ph;
// Get source pixel and add it to totals, weighted
// by covered area and alpha.
pxl = src->getPixel((u32)sx, (u32)sy);
area += pa;
ra += pa * pxl.getRed();
ga += pa * pxl.getGreen();
ba += pa * pxl.getBlue();
aa += pa * pxl.getAlpha();
}
// Set the destination image pixel to the average color.
if(area > 0) {
pxl.setRed(ra / area + 0.5);
pxl.setGreen(ga / area + 0.5);
pxl.setBlue(ba / area + 0.5);
pxl.setAlpha(aa / area + 0.5);
} else {
pxl.setRed(0);
pxl.setGreen(0);
pxl.setBlue(0);
pxl.setAlpha(0);
}
dest->setPixel(dx, dy, pxl);
}
}
irr::video::ITexture* ImageManager::GetTextureFromFile(char* file, s32 width, s32 height) {
irr::video::ITexture* texture;
irr::video::IImage* srcimg = driver->createImageFromFile(file);
if(srcimg == NULL)
return NULL;
if(srcimg->getDimension() == irr::core::dimension2d<u32>(width, height)) {
texture = driver->addTexture(file, srcimg);
} else {
video::IImage *destimg = driver->createImage(srcimg->getColorFormat(), irr::core::dimension2d<u32>(width, height));
imageScaleNNAA(srcimg, destimg);
texture = driver->addTexture(file, destimg);
destimg->drop();
}
srcimg->drop();
return texture;
}
irr::video::ITexture* ImageManager::GetTexture(int code, bool fit) {
if(code == 0) if(code == 0)
return tUnknown; return tUnknown;
auto tit = tMap.find(code); int width = CARD_IMG_WIDTH;
if(tit == tMap.end()) { int height = CARD_IMG_HEIGHT;
if(fit) {
width = width * mainGame->window_size.Width / 1024;
height = height * mainGame->window_size.Height / 640;
}
auto tit = tMap[fit ? 1 : 0].find(code);
if(tit == tMap[fit ? 1 : 0].end()) {
char file[256]; char file[256];
sprintf(file, "expansions/pics/%d.jpg", code); sprintf(file, "expansions/pics/%d.jpg", code);
irr::video::ITexture* img = driver->getTexture(file); irr::video::ITexture* img = GetTextureFromFile(file, width, height);
if(img == NULL) { if(img == NULL) {
sprintf(file, "pics/%d.png", code); sprintf(file, "pics/%d.png", code);
img = driver->getTexture(file); img = GetTextureFromFile(file, width, height);
}
if (img == NULL) {
sprintf(file, "pics/%d.jpg", code);
img = driver->getTexture(file);
} }
if(img == NULL) { if(img == NULL) {
tMap[code] = NULL; sprintf(file, "pics/%d.jpg", code);
return GetTextureThumb(code); img = GetTextureFromFile(file, width, height);
} else {
tMap[code] = img;
return img;
} }
tMap[fit ? 1 : 0][code] = img;
return (img == NULL) ? tUnknown : img;
} }
if(tit->second) if(tit->second)
return tit->second; return tit->second;
...@@ -99,26 +201,39 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) { ...@@ -99,26 +201,39 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) {
if(code == 0) if(code == 0)
return tUnknown; return tUnknown;
auto tit = tThumb.find(code); auto tit = tThumb.find(code);
int width = CARD_THUMB_WIDTH * mainGame->window_size.Width / 1024;
int height = CARD_THUMB_HEIGHT * mainGame->window_size.Height / 640;
if(tit == tThumb.end()) { if(tit == tThumb.end()) {
char file[256]; char file[256];
sprintf(file, "expansions/pics/thumbnail/%d.jpg", code); sprintf(file, "expansions/pics/%d.jpg", code);
irr::video::ITexture* img = driver->getTexture(file); irr::video::ITexture* img = GetTextureFromFile(file, width, height);
if(img == NULL) { if(img == NULL) {
sprintf(file, "pics/thumbnail/%d.jpg", code); sprintf(file, "expansions/pics/%d.png", code);
img = driver->getTexture(file); img = GetTextureFromFile(file, width, height);
} }
if(img == NULL) { if(img == NULL) {
tThumb[code] = NULL; sprintf(file, "pics/%d.jpg", code);
return tUnknown; img = GetTextureFromFile(file, width, height);
} else { }
tThumb[code] = img; if(img == NULL) {
return img; sprintf(file, "pics/%d.png", code);
img = GetTextureFromFile(file, width, height);
} }
if(img == NULL) {
sprintf(file, "expansions/pics/thumbnail/%d.jpg", code);
img = GetTextureFromFile(file, width, height);
}
if(img == NULL) {
sprintf(file, "pics/thumbnail/%d.jpg", code);
img = GetTextureFromFile(file, width, height);
}
tThumb[code] = img;
return (img == NULL) ? tUnknown : img;
} }
if(tit->second) if(tit->second)
return tit->second; return tit->second;
else else
return GetTexture(code); return tUnknown;
} }
irr::video::ITexture* ImageManager::GetTextureField(int code) { irr::video::ITexture* ImageManager::GetTextureField(int code) {
if(code == 0) if(code == 0)
......
...@@ -14,10 +14,12 @@ public: ...@@ -14,10 +14,12 @@ public:
void ClearTexture(); void ClearTexture();
void RemoveTexture(int code); void RemoveTexture(int code);
irr::video::ITexture* GetTexture(int code); irr::video::ITexture* GetTexture(int code);
irr::video::ITexture* GetTextureFromFile(char* file, s32 width, s32 height);
irr::video::ITexture* GetTexture(int code, bool fit = false);
irr::video::ITexture* GetTextureThumb(int code); irr::video::ITexture* GetTextureThumb(int code);
irr::video::ITexture* GetTextureField(int code); irr::video::ITexture* GetTextureField(int code);
std::unordered_map<int, irr::video::ITexture*> tMap; std::unordered_map<int, irr::video::ITexture*> tMap[2];
std::unordered_map<int, irr::video::ITexture*> tThumb; std::unordered_map<int, irr::video::ITexture*> tThumb;
std::unordered_map<int, irr::video::ITexture*> tFields; std::unordered_map<int, irr::video::ITexture*> tFields;
irr::IrrlichtDevice* device; irr::IrrlichtDevice* device;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment