From 62d42465de494ef11affe8b95e11e80585d64b39 Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Wed, 21 May 2014 20:04:34 +0400 Subject: [PATCH] fix compilation * may not even run * text input disabled --- client/AdventureMapClasses.cpp | 4 +- client/CAdvmapInterface.cpp | 15 ++- client/CAnimation.cpp | 45 ++++++- client/CBitmapHandler.cpp | 20 +++ client/CDefHandler.cpp | 18 ++- client/CMT.cpp | 195 +++++++++++++++++++-------- client/CMT.h | 9 +- client/CMusicHandler.cpp | 14 ++ client/GUIClasses.cpp | 2 + client/Graphics.cpp | 20 +++ client/battle/CBattleInterface.cpp | 6 +- client/battle/CCreatureAnimation.cpp | 32 ++++- client/gui/CGuiHandler.cpp | 51 ++++++- client/gui/CGuiHandler.h | 1 + client/gui/CIntObjectClasses.cpp | 38 +++++- client/gui/SDL_Extensions.cpp | 23 +++- client/gui/SDL_Extensions.h | 48 +++++++ client/gui/SDL_Pixels.h | 10 +- 18 files changed, 469 insertions(+), 82 deletions(-) diff --git a/client/AdventureMapClasses.cpp b/client/AdventureMapClasses.cpp index c1c5ae64b..e8774e695 100644 --- a/client/AdventureMapClasses.cpp +++ b/client/AdventureMapClasses.cpp @@ -177,7 +177,7 @@ CHeroList::CEmptyHeroItem::CEmptyHeroItem() auto mana = new CAnimImage("IMANA", 0, 0, move->pos.w + img->pos.w + 2, 1 ); pos.w = mana->pos.w + mana->pos.x - pos.x; - pos.h = std::max(std::max(move->pos.h + 1, mana->pos.h + 1), img->pos.h); + pos.h = std::max(std::max(move->pos.h + 1, mana->pos.h + 1), img->pos.h); } CHeroList::CHeroItem::CHeroItem(CHeroList *parent, const CGHeroInstance * Hero): @@ -190,7 +190,7 @@ CHeroList::CHeroItem::CHeroItem(CHeroList *parent, const CGHeroInstance * Hero): mana = new CAnimImage("IMANA", 0, 0, movement->pos.w + portrait->pos.w + 2, 1 ); pos.w = mana->pos.w + mana->pos.x - pos.x; - pos.h = std::max(std::max(movement->pos.h + 1, mana->pos.h + 1), portrait->pos.h); + pos.h = std::max(std::max(movement->pos.h + 1, mana->pos.h + 1), portrait->pos.h); update(); } diff --git a/client/CAdvmapInterface.cpp b/client/CAdvmapInterface.cpp index eab31d8e1..a2a6f9d53 100644 --- a/client/CAdvmapInterface.cpp +++ b/client/CAdvmapInterface.cpp @@ -294,7 +294,12 @@ void CResDataBar::clickRight(tribool down, bool previousState) CResDataBar::CResDataBar(const std::string &defname, int x, int y, int offx, int offy, int resdist, int datedist) { bg = BitmapHandler::loadBitmap(defname); + #if 0 SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255)); + #else + SDL_SetColorKey(bg,SDL_TRUE,SDL_MapRGB(bg->format,0,255,255)); + #endif + graphics->blueToPlayersAdv(bg,LOCPLINT->playerID); pos = genRect(bg->h, bg->w, pos.x+x, pos.y+y); @@ -313,7 +318,11 @@ CResDataBar::CResDataBar(const std::string &defname, int x, int y, int offx, int CResDataBar::CResDataBar() { bg = BitmapHandler::loadBitmap(ADVOPT.resdatabarG); + #if 0 SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255)); + #else + SDL_SetColorKey(bg,SDL_TRUE,SDL_MapRGB(bg->format,0,255,255)); + #endif graphics->blueToPlayersAdv(bg,LOCPLINT->playerID); pos = genRect(bg->h,bg->w,ADVOPT.resdatabarX,ADVOPT.resdatabarY); @@ -921,8 +930,12 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key) //numpad arrow if(CGuiHandler::isArrowKey(SDLKey(k))) k = CGuiHandler::arrowToNum(SDLKey(k)); - + + #if 0 k -= SDLK_KP0 + 1; + #else + k -= SDL_SCANCODE_KP_0 + 1; + #endif // 0 if(k < 0 || k > 8) return; diff --git a/client/CAnimation.cpp b/client/CAnimation.cpp index 3dcf75b71..6bcf203a6 100644 --- a/client/CAnimation.cpp +++ b/client/CAnimation.cpp @@ -157,7 +157,11 @@ CDefFile::CDefFile(std::string Name): palette[i].r = data[it++]; palette[i].g = data[it++]; palette[i].b = data[it++]; + #if 0 palette[i].unused = 255; + #else + palette[i].a = 255; + #endif // 0 } if (type == 71 || type == 64)//Buttons/buildings don't have shadows\semi-transparency memset(palette, 0, sizeof(SDL_Color)*2); @@ -356,7 +360,6 @@ void SDLImageLoader::init(Point SpriteSize, Point Margins, Point FullSize, SDL_C //Prepare surface SDL_SetColors(image->surf, pal, 0, 256); SDL_LockSurface(image->surf); - lineStart = position = (ui8*)image->surf->pixels; } @@ -387,7 +390,11 @@ inline void SDLImageLoader::EndLine() SDLImageLoader::~SDLImageLoader() { SDL_UnlockSurface(image->surf); + #if 0 SDL_SetColorKey(image->surf, SDL_SRCCOLORKEY, 0); + #else + SDL_SetColorKey(image->surf, SDL_TRUE, 0); + #endif // 0 //TODO: RLE if compressed and bpp>1 } @@ -444,8 +451,14 @@ inline ui8 CompImageLoader::typeOf(ui8 color) { if (color == 0) return 0; + #if 0 if (image->palette[color].unused != 255) return 1; + #else + if (image->palette[color].a != 255) + return 1; + #endif // 0 + return 2; } @@ -797,13 +810,21 @@ void CompImage::BlitBlock(ui8 type, ui8 size, ui8 *&data, ui8 *&dest, ui8 alpha) for (size_t i=0; i::PutColorAlpha(dest, col); } return; } - + + #if 0 if (palette[color].unused == 255) + #else + if (palette[color].a == 255) + #endif // 0 { //Put row of RGB data for (size_t i=0; i::PutColorAlpha(dest, col); return; - } + } switch (palette[type].unused) + + #else + if (alpha != 255 && palette[type].a !=0)//Per-surface alpha is set + { + SDL_Color col = palette[type]; + col.a = (int)col.a*(255-alpha)/255; + for (size_t i=0; i::PutColorAlpha(dest, col); + return; + } + + switch (palette[type].a) + #endif // 0 { case 0: { @@ -873,7 +908,11 @@ void CompImage::playerColored(PlayerColor player) palette[224+i].r = pal[i].r; palette[224+i].g = pal[i].g; palette[224+i].b = pal[i].b; + #if 0 palette[224+i].unused = pal[i].unused; + #else + palette[224+i].a = pal[i].a; + #endif // 0 } } diff --git a/client/CBitmapHandler.cpp b/client/CBitmapHandler.cpp index 7ac2f53a4..de18df324 100644 --- a/client/CBitmapHandler.cpp +++ b/client/CBitmapHandler.cpp @@ -70,7 +70,11 @@ SDL_Surface * BitmapHandler::loadH3PCX(ui8 * pcx, size_t size) tp.r = pcx[it++]; tp.g = pcx[it++]; tp.b = pcx[it++]; + #if 0 tp.unused = SDL_ALPHA_OPAQUE; + #else + tp.a = SDL_ALPHA_OPAQUE; + #endif // 0 ret->format->palette->colors[i] = tp; } } @@ -122,7 +126,11 @@ SDL_Surface * BitmapHandler::loadBitmapFromDir(std::string path, std::string fna if(ret->format->BytesPerPixel == 1 && setKey) { const SDL_Color &c = ret->format->palette->colors[0]; + #if 0 SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format, c.r, c.g, c.b)); + #else + SDL_SetColorKey(ret,SDL_TRUE,SDL_MapRGB(ret->format, c.r, c.g, c.b)); + #endif // 0 } } else @@ -143,7 +151,11 @@ SDL_Surface * BitmapHandler::loadBitmapFromDir(std::string path, std::string fna { //set correct value for alpha\unused channel for (int i=0; i< ret->format->palette->ncolors; i++) + #if 0 ret->format->palette->colors[i].unused = 255; + #else + ret->format->palette->colors[i].a = 255; + #endif // 0 } } else @@ -166,11 +178,19 @@ SDL_Surface * BitmapHandler::loadBitmapFromDir(std::string path, std::string fna // set color key only if exactly such color was found if (color.r == 0 && color.g == 255 && color.b == 255) + #if 0 SDL_SetColorKey(ret, SDL_SRCCOLORKEY, colorID); + #else + SDL_SetColorKey(ret, SDL_TRUE, colorID); + #endif // 0 } else // always set { + #if 0 SDL_SetColorKey(ret, SDL_SRCCOLORKEY, colorID); + #else + SDL_SetColorKey(ret, SDL_TRUE, colorID); + #endif // 0 } return ret; } diff --git a/client/CDefHandler.cpp b/client/CDefHandler.cpp index 0d88266ad..68f13a6e3 100644 --- a/client/CDefHandler.cpp +++ b/client/CDefHandler.cpp @@ -67,7 +67,11 @@ void CDefHandler::openFromMemory(ui8 *table, const std::string & name) palette[it].r = de.palette[it].R; palette[it].g = de.palette[it].G; palette[it].b = de.palette[it].B; + #if 0 palette[it].unused = 255; + #else + palette[it].a = 255; + #endif // 0 } // The SDefEntryBlock starts just after the SDefEntry @@ -179,7 +183,11 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const ui8 * FDef, const SDL_Co pr.r = palette[i].r; pr.g = palette[i].g; pr.b = palette[i].b; + #if 0 pr.unused = palette[i].unused; + #else + pr.a = palette[i].a; + #endif // 0 (*(ret->format->palette->colors+i))=pr; } @@ -347,8 +355,14 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const ui8 * FDef, const SDL_Co } SDL_Color ttcol = ret->format->palette->colors[0]; - Uint32 keycol = SDL_MapRGBA(ret->format, ttcol.r, ttcol.b, ttcol.g, ttcol.unused); - SDL_SetColorKey(ret, SDL_SRCCOLORKEY, keycol); + #if 0 + Uint32 keycol = SDL_MapRGBA(ret->format, ttcol.r, ttcol.b, ttcol.g, ttcol.unused); + SDL_SetColorKey(ret, SDL_SRCCOLORKEY, keycol); + #else + Uint32 keycol = SDL_MapRGBA(ret->format, ttcol.r, ttcol.b, ttcol.g, ttcol.a); + SDL_SetColorKey(ret, SDL_TRUE, keycol); + #endif // 0 + return ret; } diff --git a/client/CMT.cpp b/client/CMT.cpp index 6c99a2d7c..d3a027486 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -68,9 +68,16 @@ std::string NAME_AFFIX = "client"; std::string NAME = GameConstants::VCMI_VERSION + std::string(" (") + NAME_AFFIX + ')'; //application name CGuiHandler GH; static CClient *client=nullptr; + +SDL_Window * mainWindow = nullptr; +SDL_Renderer * mainRenderer = nullptr; + SDL_Surface *screen = nullptr, //main screen surface *screen2 = nullptr,//and hlp surface (used to store not-active interfaces layer) *screenBuf = screen; //points to screen (if only advmapint is present) or screen2 (else) - should be used when updating controls which are not regularly redrawed + +SDL_Texture * screenTexture = nullptr; + static boost::thread *mainGUIThread; std::queue events; @@ -763,76 +770,153 @@ void dispose() CMessage::dispose(); } -//used only once during initialization -static void setScreenRes(int w, int h, int bpp, bool fullscreen, bool resetVideo) +static bool checkVideoMode(int monitorIndex, int w, int h, int& bpp, bool fullscreen) { - // VCMI will only work with 2, 3 or 4 bytes per pixel + SDL_DisplayMode mode; + const int modeCount = SDL_GetNumDisplayModes(monitorIndex); + for (int i = 0; i < modeCount; i++) { + SDL_GetDisplayMode(0, i, &mode); + if (!mode.w || !mode.h || (w >= mode.w && h >= mode.h)) { + return true; + } + } + return false; + + // bpp = SDL_VideoModeOK(w, h, bpp, SDL_SWSURFACE|(fullscreen?SDL_FULLSCREEN:0)); + //return !(bpp==0) +} + + +static bool recreateWindow(int w, int h, int bpp, bool fullscreen) +{ + // VCMI will only work with 2, 3 or 4 bytes per pixel vstd::amax(bpp, 16); vstd::amin(bpp, 32); + + int suggestedBpp = bpp; - // Try to use the best screen depth for the display - int suggestedBpp = SDL_VideoModeOK(w, h, bpp, SDL_SWSURFACE|(fullscreen?SDL_FULLSCREEN:0)); - if(suggestedBpp == 0) + if(!checkVideoMode(0,w,h,suggestedBpp,fullscreen)) { logGlobal->errorStream() << "Error: SDL says that " << w << "x" << h << " resolution is not available!"; - return; + return false; + } + + if(nullptr != mainRenderer) + { + SDL_DestroyRenderer(mainRenderer); + mainRenderer = nullptr; } - + + if(nullptr != mainWindow) + { + SDL_DestroyWindow(mainWindow); + mainWindow = nullptr; + } + bool bufOnScreen = (screenBuf == screen); - - if(suggestedBpp != bpp) + + mainWindow = SDL_CreateWindow(NAME.c_str(), SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED, w, h, (fullscreen?SDL_FULLSCREEN:0)); + + if(nullptr == mainWindow) { - logGlobal->infoStream() << boost::format("Using %s bpp (bits per pixel) for the video mode. Default or overridden setting was %s bpp.") % suggestedBpp % bpp; + throw std::runtime_error("Unable to create window\n"); } + + + //create first available renderer. Use no flags, so HW accelerated will be preferred but SW renderer also will possible + mainRenderer = SDL_CreateRenderer(mainWindow,-1,0); - //For some reason changing fullscreen via config window checkbox result in SDL_Quit event - if (resetVideo) + if(nullptr == mainRenderer) { - if(screen) //screen has been already initialized - SDL_QuitSubSystem(SDL_INIT_VIDEO); - SDL_InitSubSystem(SDL_INIT_VIDEO); - } + throw std::runtime_error("Unable to create renderer\n"); + } + + SDL_RenderSetLogicalSize(mainRenderer, w, h); - if((screen = SDL_SetVideoMode(w, h, suggestedBpp, SDL_SWSURFACE|(fullscreen?SDL_FULLSCREEN:0))) == nullptr) - { - logGlobal->errorStream() << "Requested screen resolution is not available (" << w << "x" << h << "x" << suggestedBpp << "bpp)"; - throw std::runtime_error("Requested screen resolution is not available\n"); - } - logGlobal->infoStream() << "New screen flags: " << screen->flags; + screenBuf = nullptr; //it`s a link - just nullify if(screen2) SDL_FreeSurface(screen2); - screen2 = CSDL_Ext::copySurface(screen); - SDL_EnableUNICODE(1); - SDL_WM_SetCaption(NAME.c_str(),""); //set window title - SDL_ShowCursor(SDL_DISABLE); - SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); + + //logGlobal->infoStream() << "New screen flags: " << screen->flags; + SDL_FreeSurface(screen); -#ifdef _WIN32 - SDL_SysWMinfo wm; - SDL_VERSION(&wm.version); - int getwm = SDL_GetWMInfo(&wm); - if(getwm == 1) + screen = SDL_CreateRGBSurface(0,w,h,bpp,0x00FF000, + 0x0000FF00, + 0x000000FF, + 0xFF000000); + if(nullptr == screen) { - int sw = GetSystemMetrics(SM_CXSCREEN), - sh = GetSystemMetrics(SM_CYSCREEN); - RECT curpos; - GetWindowRect(wm.window,&curpos); - int ourw = curpos.right - curpos.left, - ourh = curpos.bottom - curpos.top; - SetWindowPos(wm.window, 0, (sw - ourw)/2, (sh - ourh)/2, 0, 0, SWP_NOZORDER|SWP_NOSIZE); - } - else + throw std::runtime_error("Unable to create surface\n"); + } + + screenTexture = SDL_CreateTexture(mainRenderer, + SDL_PIXELFORMAT_ARGB8888, + SDL_TEXTUREACCESS_STREAMING, + w, h); + + if(nullptr == screenTexture) { - logGlobal->warnStream() << "Something went wrong, getwm=" << getwm; - logGlobal->warnStream() << "SDL says: " << SDL_GetError(); - logGlobal->warnStream() << "Window won't be centered."; + throw std::runtime_error("Unable to create screen texture\n"); + } + + screen2 = CSDL_Ext::copySurface(screen); + + + if(nullptr == screen2) + { + throw std::runtime_error("Unable to copy surface\n"); + } + + screenBuf = bufOnScreen ? screen : screen2; + + return true; +} + + + +//used only once during initialization +static void setScreenRes(int w, int h, int bpp, bool fullscreen, bool resetVideo) +{ + + if(!recreateWindow(w,h,bpp,fullscreen)) + { + return; } -#endif + + #if 0 + SDL_EnableUNICODE(1); + #endif // 0 + + SDL_ShowCursor(SDL_DISABLE); + //TODO: this shall be handled manually in SDL2 + //SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); + +//#ifdef _WIN32 +// SDL_SysWMinfo wm; +// SDL_VERSION(&wm.version); +// int getwm = SDL_GetWMInfo(&wm); +// if(getwm == 1) +// { +// int sw = GetSystemMetrics(SM_CXSCREEN), +// sh = GetSystemMetrics(SM_CYSCREEN); +// RECT curpos; +// GetWindowRect(wm.window,&curpos); +// int ourw = curpos.right - curpos.left, +// ourh = curpos.bottom - curpos.top; +// SetWindowPos(wm.window, 0, (sw - ourw)/2, (sh - ourh)/2, 0, 0, SWP_NOZORDER|SWP_NOSIZE); +// } +// else +// { +// logGlobal->warnStream() << "Something went wrong, getwm=" << getwm; +// logGlobal->warnStream() << "SDL says: " << SDL_GetError(); +// logGlobal->warnStream() << "Window won't be centered."; +// } +//#endif //TODO: centering game window on other platforms (or does the environment do their job correctly there?) - screenBuf = bufOnScreen ? screen : screen2; + //setResolution = true; } @@ -843,19 +927,16 @@ static void fullScreenChanged() Settings full = settings.write["video"]["fullscreen"]; const bool toFullscreen = full->Bool(); - int bitsPerPixel = screen->format->BitsPerPixel; - - bitsPerPixel = SDL_VideoModeOK(screen->w, screen->h, bitsPerPixel, SDL_SWSURFACE|(toFullscreen?SDL_FULLSCREEN:0)); - if(bitsPerPixel == 0) + auto bitsPerPixel = screen->format->BitsPerPixel; + auto w = screen->w; + auto h = screen->h; + + if(!recreateWindow(w,h,bitsPerPixel,(toFullscreen?SDL_FULLSCREEN:0))) { - logGlobal->errorStream() << "Error: SDL says that " << screen->w << "x" << screen->h << " resolution is not available!"; - return; + //will return false and report error if video mode is not supported + return; } - bool bufOnScreen = (screenBuf == screen); - screen = SDL_SetVideoMode(screen->w, screen->h, bitsPerPixel, SDL_SWSURFACE|(toFullscreen?SDL_FULLSCREEN:0)); - screenBuf = bufOnScreen ? screen : screen2; - GH.totalRedraw(); } diff --git a/client/CMT.h b/client/CMT.h index 256e8a79b..95c569910 100644 --- a/client/CMT.h +++ b/client/CMT.h @@ -1,9 +1,16 @@ #pragma once +#include + +extern SDL_Window * mainWindow; +extern SDL_Renderer * mainRenderer; + extern SDL_Surface *screen; // main screen surface extern SDL_Surface *screen2; // and hlp surface (used to store not-active interfaces layer) extern SDL_Surface *screenBuf; // points to screen (if only advmapint is present) or screen2 (else) - should be used when updating controls which are not regularly redrawed +extern SDL_Texture * screenTexture; + extern bool gNoGUI; //if true there is no client window and game is silently played between AIs -void handleQuit(); \ No newline at end of file +void handleQuit(); diff --git a/client/CMusicHandler.cpp b/client/CMusicHandler.cpp index 0200cc401..cd3a7e4b4 100644 --- a/client/CMusicHandler.cpp +++ b/client/CMusicHandler.cpp @@ -481,6 +481,7 @@ void MusicEntry::load(std::string musicURI) data = CResourceHandler::get()->load(ResourceID(musicURI, EResType::MUSIC))->readAll(); musicFile = SDL_RWFromConstMem(data.first.get(), data.second); + #if 0 music = Mix_LoadMUS_RW(musicFile); if(!music) @@ -491,6 +492,19 @@ void MusicEntry::load(std::string musicURI) return; } + #else + music = Mix_LoadMUS_RW(musicFile, SDL_FALSE); + + if(!music) + { + SDL_FreeRW(musicFile); + musicFile = nullptr; + logGlobal->warnStream() << "Warning: Cannot open " << currentName << ": " << Mix_GetError(); + return; + } + + #endif // 0 + #ifdef _WIN32 //The assertion will fail if old MSVC libraries pack .dll is used assert(Mix_GetMusicType(music) != MUS_MP3); diff --git a/client/GUIClasses.cpp b/client/GUIClasses.cpp index 924df2be5..13502329b 100644 --- a/client/GUIClasses.cpp +++ b/client/GUIClasses.cpp @@ -3990,6 +3990,7 @@ void CInGameConsole::keyPressed (const SDL_KeyboardEvent & key) } default: { + #if 0 if(enteredText.size() > 0 && enteredText.size() < conf.go()->ac.inputLineLength) { if( key.keysym.unicode < 0x80 && key.keysym.unicode > 0 ) @@ -3999,6 +4000,7 @@ void CInGameConsole::keyPressed (const SDL_KeyboardEvent & key) refreshEnteredText(); } } + #endif // 0 break; } } diff --git a/client/Graphics.cpp b/client/Graphics.cpp index f9bebafb1..9dad7a0df 100644 --- a/client/Graphics.cpp +++ b/client/Graphics.cpp @@ -62,7 +62,11 @@ void Graphics::loadPaletteAndColors() col.r = pals[startPoint++]; col.g = pals[startPoint++]; col.b = pals[startPoint++]; + #if 0 col.unused = 255; + #else + col.a = 255; + #endif // 0 startPoint++; playerColorPalette[i] = col; } @@ -77,12 +81,18 @@ void Graphics::loadPaletteAndColors() neutralColorPalette[i].r = reader.readUInt8(); neutralColorPalette[i].g = reader.readUInt8(); neutralColorPalette[i].b = reader.readUInt8(); + #if 0 neutralColorPalette[i].unused = reader.readUInt8(); neutralColorPalette[i].unused = !neutralColorPalette[i].unused; + #else + neutralColorPalette[i].a = reader.readUInt8(); + neutralColorPalette[i].a = !neutralColorPalette[i].a; + #endif // 0 } //colors initialization int3 kolory[] = {int3(0xff,0,0),int3(0x31,0x52,0xff),int3(0x9c,0x73,0x52),int3(0x42,0x94,0x29), int3(0xff,0x84,0x0),int3(0x8c,0x29,0xa5),int3(0x09,0x9c,0xa5),int3(0xc6,0x7b,0x8c)}; + #if 0 for(int i=0;i<8;i++) { playerColors[i].r = kolory[i].x; @@ -91,6 +101,16 @@ void Graphics::loadPaletteAndColors() playerColors[i].unused = 255; } neutralColor->r = 0x84; neutralColor->g = 0x84; neutralColor->b = 0x84; neutralColor->unused = 255;//gray + #else + for(int i=0;i<8;i++) + { + playerColors[i].r = kolory[i].x; + playerColors[i].g = kolory[i].y; + playerColors[i].b = kolory[i].z; + playerColors[i].a = 255; + } + neutralColor->r = 0x84; neutralColor->g = 0x84; neutralColor->b = 0x84; neutralColor->a = 255;//gray + #endif // 0 } void Graphics::initializeBattleGraphics() diff --git a/client/battle/CBattleInterface.cpp b/client/battle/CBattleInterface.cpp index 54b1375e1..29d0b040b 100644 --- a/client/battle/CBattleInterface.cpp +++ b/client/battle/CBattleInterface.cpp @@ -365,7 +365,11 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe idToObstacle[ID] = CDefHandler::giveDef(elem->getInfo().defName); for(auto & _n : idToObstacle[ID]->ourImages) { - SDL_SetColorKey(_n.bitmap, SDL_SRCCOLORKEY, SDL_MapRGB(_n.bitmap->format,0,255,255)); + #if 0 + SDL_SetColorKey(_n.bitmap, SDL_SRCCOLORKEY, SDL_MapRGB(_n.bitmap->format,0,255,255)); + #else + SDL_SetColorKey(_n.bitmap, SDL_TRUE, SDL_MapRGB(_n.bitmap->format,0,255,255)); + #endif // 0 } } else if(elem->obstacleType == CObstacleInstance::ABSOLUTE_OBSTACLE) diff --git a/client/battle/CCreatureAnimation.cpp b/client/battle/CCreatureAnimation.cpp index 99641253b..0e135b2ea 100644 --- a/client/battle/CCreatureAnimation.cpp +++ b/client/battle/CCreatureAnimation.cpp @@ -178,7 +178,11 @@ CCreatureAnimation::CCreatureAnimation(std::string name, TSpeedController contro elem.r = reader.readUInt8(); elem.g = reader.readUInt8(); elem.b = reader.readUInt8(); + #if 0 elem.unused = 0; + #else + elem.a = 0; + #endif } for (int i=0; i CCreatureAnimation::genSpecialPalette() @@ -413,7 +431,11 @@ inline void CCreatureAnimation::putPixel(ui8 * dest, const SDL_Color & color, si if (index < 8) { const SDL_Color & pal = special[index]; + #if 0 ColorPutter::PutColor(dest, pal.r, pal.g, pal.b, pal.unused); + #else + ColorPutter::PutColor(dest, pal.r, pal.g, pal.b, pal.a); + #endif // 0 } else { diff --git a/client/gui/CGuiHandler.cpp b/client/gui/CGuiHandler.cpp index 1eee3f292..32f29c8ab 100644 --- a/client/gui/CGuiHandler.cpp +++ b/client/gui/CGuiHandler.cpp @@ -1,7 +1,7 @@ #include "StdInc.h" #include "CGuiHandler.h" -#include "SDL_Extensions.h" + #include "CIntObject.h" #include "../CGameInfo.h" #include "CCursorHandler.h" @@ -264,6 +264,7 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent) } } } + #if 0 else if(sEvent->button.button == SDL_BUTTON_WHEELDOWN || sEvent->button.button == SDL_BUTTON_WHEELUP) { std::list hlp = wheelInterested; @@ -273,7 +274,20 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent) (*i)->wheelScrolled(sEvent->button.button == SDL_BUTTON_WHEELDOWN, isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y)); } } + #endif } + #if 0 + #else + else if ((sEvent->type == SDL_MOUSEWHEEL)) + { + std::list hlp = wheelInterested; + for(auto i=hlp.begin(); i != hlp.end() && current; i++) + { + if(!vstd::contains(wheelInterested,*i)) continue; + (*i)->wheelScrolled(sEvent->wheel.y < 0, isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y)); + } + } + #endif // 0 else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT)) { std::list hlp = lclickable; @@ -386,6 +400,11 @@ void CGuiHandler::run() { if(curInt) curInt->update(); // calls a update and drawing process of the loaded game interface object at the moment + + SDL_RenderClear(mainRenderer); + SDL_RenderCopy(mainRenderer, screenTexture, NULL, NULL); + + SDL_RenderPresent(mainRenderer); mainFPSmng->framerateDelay(); // holds a constant FPS } @@ -432,6 +451,7 @@ void CGuiHandler::drawFPSCounter() SDLKey CGuiHandler::arrowToNum( SDLKey key ) { + #if 0 switch(key) { case SDLK_DOWN: @@ -444,14 +464,34 @@ SDLKey CGuiHandler::arrowToNum( SDLKey key ) return SDLK_KP6; default: assert(0); - } + } + #else + switch(key) + { + case SDLK_DOWN: + return SDLK_KP_2; + case SDLK_UP: + return SDLK_KP_8; + case SDLK_LEFT: + return SDLK_KP_4; + case SDLK_RIGHT: + return SDLK_KP_6; + default: + assert(0); + } + #endif // 0 throw std::runtime_error("Wrong key!"); } SDLKey CGuiHandler::numToDigit( SDLKey key ) { +#if 0 if(key >= SDLK_KP0 && key <= SDLK_KP9) return SDLKey(key - SDLK_KP0 + SDLK_0); +#else + if(key >= SDLK_KP_0 && key <= SDLK_KP_9) + return SDLKey(key - SDLK_KP_0 + SDLK_0); +#endif // 0 #define REMOVE_KP(keyName) case SDLK_KP_ ## keyName : return SDLK_ ## keyName; switch(key) @@ -475,10 +515,17 @@ SDLKey CGuiHandler::numToDigit( SDLKey key ) bool CGuiHandler::isNumKey( SDLKey key, bool number ) { + #if 0 if(number) return key >= SDLK_KP0 && key <= SDLK_KP9; else return key >= SDLK_KP0 && key <= SDLK_KP_EQUALS; + #else + if(number) + return key >= SDLK_KP_0 && key <= SDLK_KP_9; + else + return key >= SDLK_KP_0 && key <= SDLK_KP_EQUALS; + #endif // 0 } bool CGuiHandler::isArrowKey( SDLKey key ) diff --git a/client/gui/CGuiHandler.h b/client/gui/CGuiHandler.h index 77775cd07..d2ab716ec 100644 --- a/client/gui/CGuiHandler.h +++ b/client/gui/CGuiHandler.h @@ -2,6 +2,7 @@ #include "../../lib/CStopWatch.h" #include "Geometries.h" +#include "SDL_Extensions.h" class CFramerateManager; class CGStatusBar; diff --git a/client/gui/CIntObjectClasses.cpp b/client/gui/CIntObjectClasses.cpp index c3059e9cc..8b8820b09 100644 --- a/client/gui/CIntObjectClasses.cpp +++ b/client/gui/CIntObjectClasses.cpp @@ -133,8 +133,12 @@ void CPicture::convertToScreenBPP() } void CPicture::setAlpha(int value) -{ - SDL_SetAlpha(bg, SDL_SRCALPHA, value); +{ + #if 0 + SDL_SetAlpha(bg, SDL_SRCALPHA, value); + #else + SDL_SetSurfaceAlphaMod(bg,value); + #endif // 0 } void CPicture::scaleTo(Point size) @@ -285,7 +289,11 @@ void CButtonBase::block(bool on) CAdventureMapButton::CAdventureMapButton () { hoverable = actOnDown = borderEnabled = soundDisabled = false; + #if 0 borderColor.unused = 1; // represents a transparent color, used for HighlightableButton + #else + borderColor.a = 1; // represents a transparent color, used for HighlightableButton + #endif // 0 addUsedEvents(LCLICK | RCLICK | HOVER | KEYBOARD); } @@ -404,7 +412,11 @@ void CAdventureMapButton::init(const CFunctionList &Callback, const std: addUsedEvents(LCLICK | RCLICK | HOVER | KEYBOARD); callback = Callback; hoverable = actOnDown = borderEnabled = soundDisabled = false; + #if 0 borderColor.unused = 1; // represents a transparent color, used for HighlightableButton + #else + borderColor.a = 1; // represents a transparent color, used for HighlightableButton + #endif // 0 hoverTexts = Name; helpBox=HelpBox; @@ -452,9 +464,14 @@ void CAdventureMapButton::setPlayerColor(PlayerColor player) void CAdventureMapButton::showAll(SDL_Surface * to) { CIntObject::showAll(to); - + + #if 0 if (borderEnabled && borderColor.unused == 0) - CSDL_Ext::drawBorder(to, pos.x-1, pos.y-1, pos.w+2, pos.h+2, int3(borderColor.r, borderColor.g, borderColor.b)); + CSDL_Ext::drawBorder(to, pos.x-1, pos.y-1, pos.w+2, pos.h+2, int3(borderColor.r, borderColor.g, borderColor.b)); + #else + if (borderEnabled && borderColor.a == 0) + CSDL_Ext::drawBorder(to, pos.x-1, pos.y-1, pos.w+2, pos.h+2, int3(borderColor.r, borderColor.g, borderColor.b)); + #endif // 0 } void CHighlightableButton::select(bool on) @@ -1604,19 +1621,24 @@ void CTextInput::keyPressed( const SDL_KeyboardEvent & key ) text.resize(text.size()-1); break; default: + #if 0 if (key.keysym.unicode < ' ') return; else text += key.keysym.unicode; //TODO 16-/>8 + #endif // 0 break; } - + #if 0 filters(text, oldText); if (text != oldText) { redraw(); cb(text); } + #endif // 0 + + //todo: handle text input for SDL2 } void CTextInput::setText( const std::string &nText, bool callCb ) @@ -1630,12 +1652,16 @@ bool CTextInput::captureThisEvent(const SDL_KeyboardEvent & key) { if(key.keysym.sym == SDLK_RETURN || key.keysym.sym == SDLK_KP_ENTER) return false; - + + #if 0 //this should allow all non-printable keys to go through (for example arrows) if (key.keysym.unicode < ' ') return false; return true; + #else + return false; //todo:CTextInput::captureThisEvent + #endif } void CTextInput::filenameFilter(std::string & text, const std::string &) diff --git a/client/gui/SDL_Extensions.cpp b/client/gui/SDL_Extensions.cpp index ff5ff202e..491b6183f 100644 --- a/client/gui/SDL_Extensions.cpp +++ b/client/gui/SDL_Extensions.cpp @@ -7,6 +7,7 @@ #include "../CMessage.h" #include "../CDefHandler.h" #include "../Graphics.h" +#include "../CMT.h" const SDL_Color Colors::YELLOW = { 229, 215, 123, 0 }; const SDL_Color Colors::WHITE = { 255, 243, 222, 0 }; @@ -444,7 +445,11 @@ int CSDL_Ext::blit8bppAlphaTo24bppT(const SDL_Surface * src, const SDL_Rect * sr for(int x = w; x; x--) { const SDL_Color &tbc = colors[*color++]; //color to blit + #if 0 ColorPutter::PutColorAlphaSwitch(p, tbc.r, tbc.g, tbc.b, tbc.unused); + #else + ColorPutter::PutColorAlphaSwitch(p, tbc.r, tbc.g, tbc.b, tbc.a); + #endif // 0 } } SDL_UnlockSurface(dst); @@ -469,7 +474,11 @@ int CSDL_Ext::blit8bppAlphaTo24bpp(const SDL_Surface * src, const SDL_Rect * src Uint32 CSDL_Ext::colorToUint32(const SDL_Color * color) { Uint32 ret = 0; + #if 0 ret+=color->unused; + #else + ret+=color->a; + #endif // 0 ret<<=8; //*=256 ret+=color->b; ret<<=8; //*=256 @@ -481,8 +490,12 @@ Uint32 CSDL_Ext::colorToUint32(const SDL_Color * color) void CSDL_Ext::update(SDL_Surface * what) { + #if 0 if(what) SDL_UpdateRect(what, 0, 0, what->w, what->h); + #else + SDL_UpdateTexture(screenTexture, NULL, what->pixels, what->pitch); + #endif } void CSDL_Ext::drawBorder(SDL_Surface * sur, int x, int y, int w, int h, const int3 &color) { @@ -601,14 +614,22 @@ bool CSDL_Ext::isTransparent( SDL_Surface * srf, int x, int y ) return true; SDL_Color color; - + + #if 0 SDL_GetRGBA(SDL_GetPixel(srf, x, y), srf->format, &color.r, &color.g, &color.b, &color.unused); + #else + SDL_GetRGBA(SDL_GetPixel(srf, x, y), srf->format, &color.r, &color.g, &color.b, &color.a); + #endif // 0 // color is considered transparent here if // a) image has aplha: less than 50% transparency // b) no alpha: color is cyan if (srf->format->Amask) + #if 0 return color.unused < 128; // almost transparent + #else + return color.a < 128; // almost transparent + #endif // 0 else return (color.r == 0 && color.g == 255 && color.b == 255); } diff --git a/client/gui/SDL_Extensions.h b/client/gui/SDL_Extensions.h index 0e88302fb..7d32861f4 100644 --- a/client/gui/SDL_Extensions.h +++ b/client/gui/SDL_Extensions.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include "../../lib/int3.h" @@ -29,6 +30,53 @@ #define SDL_GetKeyState SDL_GetKeyboardState #endif +//compatibility stuff +#if 0 + +typedef Sint16 SDLX_Coord; +typedef Uint16 SDLX_Size; + +#else + +extern SDL_Window * mainWindow; +extern SDL_Renderer * mainRenderer; +extern SDL_Texture * screenTexture; + + +typedef int SDLX_Coord; +typedef int SDLX_Size; + +typedef SDL_Keycode SDLKey; + +#define SDL_SRCCOLORKEY SDL_TRUE + +#define SDL_FULLSCREEN SDL_WINDOW_FULLSCREEN + +inline void SDL_SetColors(SDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncolors) +{ + SDL_SetPaletteColors(surface->format->palette,colors,firstcolor,ncolors); +} + +inline void SDL_WarpMouse(int x, int y) +{ + SDL_WarpMouseInWindow(mainWindow,x,y); +} + +inline void SDL_UpdateRect(SDL_Surface *surface, int x, int y, int w, int h) +{ + Rect rect(x,y,w,h); + SDL_UpdateTexture(screenTexture, &rect, surface->pixels, surface->pitch); + + SDL_RenderClear(mainRenderer); + SDL_RenderCopy(mainRenderer, screenTexture, NULL, NULL); + + SDL_RenderPresent(mainRenderer); + +} + + +#endif // 0 + struct Rect; extern SDL_Surface * screen, *screen2, *screenBuf; diff --git a/client/gui/SDL_Pixels.h b/client/gui/SDL_Pixels.h index 2c43a03eb..33383bd39 100644 --- a/client/gui/SDL_Pixels.h +++ b/client/gui/SDL_Pixels.h @@ -133,7 +133,11 @@ struct ColorPutter<2, incrementPtr> template STRONG_INLINE void ColorPutter::PutColorAlpha(Uint8 *&ptr, const SDL_Color & Color) { + #if 0 PutColor(ptr, Color.r, Color.g, Color.b, Color.unused); + #else + PutColor(ptr, Color.r, Color.g, Color.b, Color.a); + #endif } template @@ -262,7 +266,11 @@ STRONG_INLINE void ColorPutter<2, incrementPtr>::PutColor(Uint8 *&ptr, const Uin template STRONG_INLINE void ColorPutter<2, incrementPtr>::PutColorAlpha(Uint8 *&ptr, const SDL_Color & Color) { + #if 0 PutColor(ptr, Color.r, Color.g, Color.b, Color.unused); + #else + PutColor(ptr, Color.r, Color.g, Color.b, Color.a); + #endif } template @@ -285,4 +293,4 @@ STRONG_INLINE void ColorPutter<2, incrementPtr>::PutColorRow(Uint8 *&ptr, const if(incrementPtr == 1) ptr += 2; } -} \ No newline at end of file +}