From dca1e28bc122e9fc27354bc45d4e0034c2311c3d Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Sun, 21 Jun 2015 01:13:45 +0300 Subject: [PATCH 1/6] SDL1 wipe, part 1. Untested. --- client/CDefHandler.cpp | 18 ---- client/CMT.cpp | 116 ------------------------- client/CMT.h | 3 - client/CMusicHandler.cpp | 15 ---- client/CPlayerInterface.cpp | 5 -- client/CVideoHandler.cpp | 49 ----------- client/CVideoHandler.h | 6 +- client/battle/CCreatureAnimation.cpp | 18 ---- client/gui/CAnimation.cpp | 41 +-------- client/gui/CGuiHandler.cpp | 45 +--------- client/gui/SDL_Extensions.cpp | 25 ------ client/gui/SDL_Extensions.h | 25 +----- client/gui/SDL_Pixels.h | 8 -- client/widgets/AdventureMapClasses.cpp | 16 ---- client/widgets/Buttons.cpp | 5 -- client/widgets/TextControls.cpp | 29 +------ client/windows/CAdvmapInterface.cpp | 7 +- 17 files changed, 9 insertions(+), 422 deletions(-) diff --git a/client/CDefHandler.cpp b/client/CDefHandler.cpp index 33deb5343..4f5f2ccc0 100644 --- a/client/CDefHandler.cpp +++ b/client/CDefHandler.cpp @@ -181,24 +181,11 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const ui8 * FDef, const SDL_Co BaseOffset += sizeof(SSpriteDef); int BaseOffsetor = BaseOffset; - #ifdef VCMI_SDL1 - for(int i=0; i<256; ++i) - { - SDL_Color pr; - pr.r = palette[i].r; - pr.g = palette[i].g; - pr.b = palette[i].b; - pr.unused = palette[i].unused; - (*(ret->format->palette->colors+i))=pr; - } - #else if(SDL_SetPaletteColors(ret->format->palette,palette,0,256) != 0) { throw std::runtime_error("Unable to set palette"); } - #endif - int ftcp=0; // If there's a margin anywhere, just blank out the whole surface. @@ -363,13 +350,8 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const ui8 * FDef, const SDL_Co } SDL_Color ttcol = ret->format->palette->colors[0]; - #ifdef VCMI_SDL1 - 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 162f95905..ef1dd8e33 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -69,12 +69,10 @@ std::string NAME = GameConstants::VCMI_VERSION + std::string(" (") + NAME_AFFIX CGuiHandler GH; static CClient *client=nullptr; -#ifndef VCMI_SDL1 int preferredDriverIndex = -1; SDL_Window * mainWindow = nullptr; SDL_Renderer * mainRenderer = nullptr; SDL_Texture * screenTexture = nullptr; -#endif // VCMI_SDL1 extern boost::thread_specific_ptr inGuiThread; @@ -264,11 +262,6 @@ int main(int argc, char** argv) gNoGUI = true; vm.insert(std::pair("onlyAI", po::variable_value())); } -#ifdef VCMI_SDL1 - //Set environment vars to make window centered. Sometimes work, sometimes not. :/ - putenv((char*)"SDL_VIDEO_WINDOW_POS"); - putenv((char*)"SDL_VIDEO_CENTERED=1"); -#endif // Have effect on X11 system only (Linux). // For whatever reason in fullscreen mode SDL takes "raw" mouse input from DGA X11 extension @@ -338,11 +331,7 @@ int main(int argc, char** argv) if(!gNoGUI) { - #ifdef VCMI_SDL1 - if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO)) - #else if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO|SDL_INIT_NOPARACHUTE)) - #endif { logGlobal->errorStream()<<"Something was wrong: "<< SDL_GetError(); exit(-1); @@ -350,7 +339,6 @@ int main(int argc, char** argv) GH.mainFPSmng->init(); //(!)init here AFTER SDL_Init() while using SDL for FPS management atexit(SDL_Quit); - #ifndef VCMI_SDL1 int driversCount = SDL_GetNumRenderDrivers(); std::string preferredDriverName = video["driver"].String(); @@ -371,7 +359,6 @@ int main(int argc, char** argv) else logGlobal->infoStream() << "\t" << driverName; } - #endif // VCMI_SDL1 config::CConfigHandler::GuiOptionsMap::key_type resPair(res["width"].Float(), res["height"].Float()); if (conf.guiOptions.count(resPair) == 0) @@ -823,7 +810,6 @@ void dispose() static bool checkVideoMode(int monitorIndex, int w, int h, int& bpp, bool fullscreen) { - #ifndef VCMI_SDL1 SDL_DisplayMode mode; const int modeCount = SDL_GetNumDisplayModes(monitorIndex); for (int i = 0; i < modeCount; i++) { @@ -833,13 +819,8 @@ static bool checkVideoMode(int monitorIndex, int w, int h, int& bpp, bool fullsc } } return false; - #else - bpp = SDL_VideoModeOK(w, h, bpp, SDL_SWSURFACE|(fullscreen?SDL_FULLSCREEN:0)); - return !(bpp==0); - #endif // VCMI_SDL1 } -#ifndef VCMI_SDL1 static bool recreateWindow(int w, int h, int bpp, bool fullscreen) { // VCMI will only work with 2 or 4 bytes per pixel @@ -982,91 +963,14 @@ static bool recreateWindow(int w, int h, int bpp, bool fullscreen) return true; } -#endif - - //used only once during initialization static void setScreenRes(int w, int h, int bpp, bool fullscreen, bool resetVideo) { -#ifdef VCMI_SDL1 - - // VCMI will only work with 2, 3 or 4 bytes per pixel - vstd::amax(bpp, 16); - vstd::amin(bpp, 32); - - // 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) - { - logGlobal->errorStream() << "Error: SDL says that " << w << "x" << h << " resolution is not available!"; - return; - } - - bool bufOnScreen = (screenBuf == screen); - - if(suggestedBpp != bpp) - { - logGlobal->infoStream() << boost::format("Using %s bpp (bits per pixel) for the video mode. Default or overridden setting was %s bpp.") % suggestedBpp % bpp; - } - - //For some reason changing fullscreen via config window checkbox result in SDL_Quit event - if (resetVideo) - { - if(screen) //screen has been already initialized - SDL_QuitSubSystem(SDL_INIT_VIDEO); - SDL_InitSubSystem(SDL_INIT_VIDEO); - } - - 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; - - 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); - -#ifdef VCMI_WINDOWS - 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; - -#else - if(!recreateWindow(w,h,bpp,fullscreen)) { throw std::runtime_error("Requested screen resolution is not available\n"); } -#endif // VCMI_SDL1 } static void fullScreenChanged() @@ -1078,19 +982,6 @@ static void fullScreenChanged() auto bitsPerPixel = screen->format->BitsPerPixel; - #ifdef VCMI_SDL1 - bitsPerPixel = SDL_VideoModeOK(screen->w, screen->h, bitsPerPixel, SDL_SWSURFACE|(toFullscreen?SDL_FULLSCREEN:0)); - if(bitsPerPixel == 0) - { - logGlobal->errorStream() << "Error: SDL says that " << screen->w << "x" << screen->h << " resolution is not available!"; - return; - } - - bool bufOnScreen = (screenBuf == screen); - screen = SDL_SetVideoMode(screen->w, screen->h, bitsPerPixel, SDL_SWSURFACE|(toFullscreen?SDL_FULLSCREEN:0)); - screenBuf = bufOnScreen ? screen : screen2; - - #else auto w = screen->w; auto h = screen->h; @@ -1099,7 +990,6 @@ static void fullScreenChanged() //will return false and report error if video mode is not supported return; } - #endif GH.totalRedraw(); } @@ -1111,13 +1001,7 @@ static void handleEvent(SDL_Event & ev) handleQuit(); return; } - - #ifdef VCMI_SDL1 - //FIXME: this should work even in pregame - else if(LOCPLINT && ev.type == SDL_KEYDOWN && ev.key.keysym.sym==SDLK_F4) - #else else if(ev.type == SDL_KEYDOWN && ev.key.keysym.sym==SDLK_F4) - #endif // VCMI_SDL1 { Settings full = settings.write["video"]["fullscreen"]; full->Bool() = !full->Bool(); diff --git a/client/CMT.h b/client/CMT.h index 5148a01b7..b0a45c7d8 100644 --- a/client/CMT.h +++ b/client/CMT.h @@ -1,6 +1,5 @@ #pragma once -#ifndef VCMI_SDL1 #include extern SDL_Texture * screenTexture; @@ -8,8 +7,6 @@ extern SDL_Texture * screenTexture; extern SDL_Window * mainWindow; extern SDL_Renderer * mainRenderer; -#endif // VCMI_SDL2 - 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 diff --git a/client/CMusicHandler.cpp b/client/CMusicHandler.cpp index d97b5f204..0b800f13e 100644 --- a/client/CMusicHandler.cpp +++ b/client/CMusicHandler.cpp @@ -451,18 +451,6 @@ void MusicEntry::load(std::string musicURI) data = CResourceHandler::get()->load(ResourceID(musicURI, EResType::MUSIC))->readAll(); musicFile = SDL_RWFromConstMem(data.first.get(), data.second); - #ifdef VCMI_SDL1 - music = Mix_LoadMUS_RW(musicFile); - - if(!music) - { - SDL_FreeRW(musicFile); - musicFile = nullptr; - logGlobal->warnStream() << "Warning: Cannot open " << currentName << ": " << Mix_GetError(); - return; - } - - #else music = Mix_LoadMUS_RW(musicFile, SDL_FALSE); if(!music) @@ -472,9 +460,6 @@ void MusicEntry::load(std::string musicURI) logGlobal->warnStream() << "Warning: Cannot open " << currentName << ": " << Mix_GetError(); return; } - - #endif // 0 - } bool MusicEntry::play() diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index cf48e04e2..00d6fc8b9 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -1545,16 +1545,11 @@ void CPlayerInterface::centerView (int3 pos, int focusTime) if(focusTime) { GH.totalRedraw(); - #ifdef VCMI_SDL1 - CSDL_Ext::update(screen); - SDL_Delay(focusTime); - #else { auto unlockPim = vstd::makeUnlockGuard(*pim); IgnoreEvents ignore(*this); SDL_Delay(focusTime); } - #endif } } diff --git a/client/CVideoHandler.cpp b/client/CVideoHandler.cpp index fbdd3badb..c33472517 100644 --- a/client/CVideoHandler.cpp +++ b/client/CVideoHandler.cpp @@ -53,11 +53,7 @@ CVideoPlayer::CVideoPlayer() frame = nullptr; codec = nullptr; sws = nullptr; -#ifdef VCMI_SDL1 - overlay = nullptr; -#else texture = nullptr; -#endif dest = nullptr; context = nullptr; @@ -173,13 +169,7 @@ bool CVideoPlayer::open(std::string fname, bool loop, bool useOverlay, bool scal // Allocate a place to put our YUV image on that screen if (useOverlay) { -#ifdef VCMI_SDL1 - overlay = SDL_CreateYUVOverlay(pos.w, pos.h, - SDL_YV12_OVERLAY, screen); -#else texture = SDL_CreateTexture( mainRenderer, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STATIC, pos.w, pos.h); -#endif - } else { @@ -188,17 +178,11 @@ bool CVideoPlayer::open(std::string fname, bool loop, bool useOverlay, bool scal destRect.w = pos.w; destRect.h = pos.h; } -#ifdef VCMI_SDL1 - if (overlay == nullptr && dest == nullptr) - return false; - if (overlay) -#else if (texture == nullptr && dest == nullptr) return false; if (texture) -#endif { // Convert the image into YUV format that SDL uses sws = sws_getContext(codecContext->width, codecContext->height, codecContext->pix_fmt, pos.w, pos.h, PIX_FMT_YUV420P, @@ -284,23 +268,6 @@ bool CVideoPlayer::nextFrame() { AVPicture pict; -#ifdef VCMI_SDL1 - if (overlay) { - SDL_LockYUVOverlay(overlay); - - pict.data[0] = overlay->pixels[0]; - pict.data[1] = overlay->pixels[2]; - pict.data[2] = overlay->pixels[1]; - - pict.linesize[0] = overlay->pitches[0]; - pict.linesize[1] = overlay->pitches[2]; - pict.linesize[2] = overlay->pitches[1]; - - sws_scale(sws, frame->data, frame->linesize, - 0, codecContext->height, pict.data, pict.linesize); - - SDL_UnlockYUVOverlay(overlay); -#else if (texture) { avpicture_alloc(&pict, AV_PIX_FMT_YUV420P, pos.w, pos.h); @@ -311,7 +278,6 @@ bool CVideoPlayer::nextFrame() pict.data[1], pict.linesize[1], pict.data[2], pict.linesize[2]); avpicture_free(&pict); -#endif } else { @@ -387,22 +353,12 @@ void CVideoPlayer::close() sws = nullptr; } -#ifdef VCMI_SDL1 - if (overlay) - { - SDL_FreeYUVOverlay(overlay); - overlay = nullptr; - } -#else if (texture) { SDL_DestroyTexture(texture); texture = nullptr; } -#endif - - if (dest) { SDL_FreeSurface(dest); @@ -455,13 +411,8 @@ bool CVideoPlayer::playVideo(int x, int y, SDL_Surface *dst, bool stopOnKey) if(stopOnKey && keyDown()) return false; -#ifdef VCMI_SDL1 - SDL_DisplayYUVOverlay(overlay, &pos); -#else SDL_RenderCopy(mainRenderer, texture, NULL, &pos); SDL_RenderPresent(mainRenderer); -#endif - // Wait 3 frames GH.mainFPSmng->framerateDelay(); diff --git a/client/CVideoHandler.h b/client/CVideoHandler.h index 1d5852639..30d2e0d4d 100644 --- a/client/CVideoHandler.h +++ b/client/CVideoHandler.h @@ -80,12 +80,8 @@ class CVideoPlayer : public IMainVideoPlayer AVIOContext * context; // Destination. Either overlay or dest. -#ifdef VCMI_SDL1 - SDL_Overlay * overlay; -#else - SDL_Texture *texture; -#endif + SDL_Texture *texture; SDL_Surface *dest; SDL_Rect destRect; // valid when dest is used SDL_Rect pos; // destination on screen diff --git a/client/battle/CCreatureAnimation.cpp b/client/battle/CCreatureAnimation.cpp index bbca7129f..1544cee75 100644 --- a/client/battle/CCreatureAnimation.cpp +++ b/client/battle/CCreatureAnimation.cpp @@ -267,11 +267,7 @@ static SDL_Color genShadow(ui8 alpha) static SDL_Color genBorderColor(ui8 alpha, const SDL_Color & base) { - #ifdef VCMI_SDL1 - return CSDL_Ext::makeColor(base.r, base.g, base.b, ui8(base.unused * alpha / 256)); - #else return CSDL_Ext::makeColor(base.r, base.g, base.b, ui8(base.a * alpha / 256)); - #endif } static ui8 mixChannels(ui8 c1, ui8 c2, ui8 a1, ui8 a2) @@ -281,22 +277,12 @@ static ui8 mixChannels(ui8 c1, ui8 c2, ui8 a1, ui8 a2) static SDL_Color addColors(const SDL_Color & base, const SDL_Color & over) { - #ifdef VCMI_SDL1 - return CSDL_Ext::makeColor( - mixChannels(over.r, base.r, over.unused, base.unused), - mixChannels(over.g, base.g, over.unused, base.unused), - mixChannels(over.b, base.b, over.unused, base.unused), - ui8(over.unused + base.unused * (255 - over.unused) / 256) - ); - #else return CSDL_Ext::makeColor( mixChannels(over.r, base.r, over.a, base.a), mixChannels(over.g, base.g, over.a, base.a), mixChannels(over.b, base.b, over.a, base.a), ui8(over.a + base.a * (255 - over.a) / 256) ); - - #endif // VCMI_SDL1 } std::array CCreatureAnimation::genSpecialPalette() @@ -427,11 +413,7 @@ inline void CCreatureAnimation::putPixel(ui8 * dest, const SDL_Color & color, si if (index < 8) { const SDL_Color & pal = special[index]; - #ifdef VCMI_SDL1 - 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/CAnimation.cpp b/client/gui/CAnimation.cpp index c76d96245..5bfe2d827 100644 --- a/client/gui/CAnimation.cpp +++ b/client/gui/CAnimation.cpp @@ -444,13 +444,9 @@ inline ui8 CompImageLoader::typeOf(ui8 color) { if (color == 0) return 0; - #ifdef VCMI_SDL1 - if (image->palette[color].unused != 255) - return 1; - #else + if (image->palette[color].a != 255) return 1; - #endif // 0 return 2; } @@ -628,22 +624,11 @@ SDLImage::SDLImage(std::string filename, bool compressed): { SDL_Surface *temp = surf; // add RLE flag - #ifdef VCMI_SDL1 - if (surf->format->palette) - { - const SDL_Color &c = temp->format->palette->colors[0]; - SDL_SetColorKey(temp, (SDL_SRCCOLORKEY | SDL_RLEACCEL), - SDL_MapRGB(temp -> format, c.r, c.g, c.b)); - } - else - SDL_SetColorKey(temp, SDL_RLEACCEL, 0); - #else if (surf->format->palette) { CSDL_Ext::setColorKey(temp,temp->format->palette->colors[0]); } SDL_SetSurfaceRLE(temp, SDL_RLEACCEL); - #endif // convert surface to enable RLE surf = SDL_ConvertSurface(temp, temp->format, temp->flags); @@ -811,21 +796,13 @@ void CompImage::BlitBlock(ui8 type, ui8 size, ui8 *&data, ui8 *&dest, ui8 alpha) for (size_t i=0; i::PutColorAlpha(dest, col); } return; } - - #ifdef VCMI_SDL1 - 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]; @@ -865,7 +829,6 @@ void CompImage::BlitBlock(ui8 type, ui8 size, ui8 *&data, ui8 *&dest, ui8 alpha) } switch (palette[type].a) - #endif // 0 { case 0: { diff --git a/client/gui/CGuiHandler.cpp b/client/gui/CGuiHandler.cpp index a3dbba97a..fabdbc268 100644 --- a/client/gui/CGuiHandler.cpp +++ b/client/gui/CGuiHandler.cpp @@ -270,17 +270,6 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent) } } } - #ifdef VCMI_SDL1 //SDL1x only events - else if(sEvent->button.button == SDL_BUTTON_WHEELDOWN || sEvent->button.button == SDL_BUTTON_WHEELUP) - { - std::list hlp = wheelInterested; - for(auto i=hlp.begin(); i != hlp.end() && current; i++) - { - if(!vstd::contains(wheelInterested,*i)) continue; - (*i)->wheelScrolled(sEvent->button.button == SDL_BUTTON_WHEELDOWN, isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y)); - } - } - #endif } #ifndef VCMI_SDL1 //SDL2x only events else if (sEvent->type == SDL_MOUSEWHEEL) @@ -394,12 +383,9 @@ void CGuiHandler::handleMoveInterested( const SDL_MouseMotionEvent & motion ) void CGuiHandler::fakeMouseMove() { SDL_Event evnt; -#ifdef VCMI_SDL1 - SDL_MouseMotionEvent sme = {SDL_MOUSEMOTION, 0, 0, 0, 0, 0, 0}; -#else SDL_MouseMotionEvent sme = {SDL_MOUSEMOTION, 0, 0, 0, 0, 0, 0, 0, 0}; -#endif int x, y; + sme.state = SDL_GetMouseState(&x, &y); sme.x = x; sme.y = y; @@ -472,21 +458,6 @@ void CGuiHandler::drawFPSCounter() SDLKey CGuiHandler::arrowToNum( SDLKey key ) { - #ifdef VCMI_SDL1 - switch(key) - { - case SDLK_DOWN: - return SDLK_KP2; - case SDLK_UP: - return SDLK_KP8; - case SDLK_LEFT: - return SDLK_KP4; - case SDLK_RIGHT: - return SDLK_KP6; - default: - throw std::runtime_error("Wrong key!");assert(0); - } - #else switch(key) { case SDLK_DOWN: @@ -500,20 +471,14 @@ SDLKey CGuiHandler::arrowToNum( SDLKey key ) default: throw std::runtime_error("Wrong key!"); } - #endif // 0 } SDLKey CGuiHandler::numToDigit( SDLKey key ) { -#ifdef VCMI_SDL1 - if(key >= SDLK_KP0 && key <= SDLK_KP9) - return SDLKey(key - SDLK_KP0 + SDLK_0); -#endif // 0 #define REMOVE_KP(keyName) case SDLK_KP_ ## keyName : return SDLK_ ## keyName; switch(key) { -#ifndef VCMI_SDL1 REMOVE_KP(0) REMOVE_KP(1) REMOVE_KP(2) @@ -524,7 +489,6 @@ SDLKey CGuiHandler::numToDigit( SDLKey key ) REMOVE_KP(7) REMOVE_KP(8) REMOVE_KP(9) -#endif // VCMI_SDL1 REMOVE_KP(PERIOD) REMOVE_KP(MINUS) REMOVE_KP(PLUS) @@ -544,17 +508,10 @@ SDLKey CGuiHandler::numToDigit( SDLKey key ) bool CGuiHandler::isNumKey( SDLKey key, bool number ) { - #ifdef VCMI_SDL1 - 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_1 && key <= SDLK_KP_0; else return (key >= SDLK_KP_1 && key <= SDLK_KP_0) || key == SDLK_KP_MINUS || key == SDLK_KP_PLUS || key == SDLK_KP_EQUALS; - #endif // 0 } bool CGuiHandler::isArrowKey( SDLKey key ) diff --git a/client/gui/SDL_Extensions.cpp b/client/gui/SDL_Extensions.cpp index 1732d449a..c29c4ed6d 100644 --- a/client/gui/SDL_Extensions.cpp +++ b/client/gui/SDL_Extensions.cpp @@ -460,11 +460,7 @@ 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 - #ifdef VCMI_SDL1 - 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); @@ -489,11 +485,7 @@ int CSDL_Ext::blit8bppAlphaTo24bpp(const SDL_Surface * src, const SDL_Rect * src Uint32 CSDL_Ext::colorToUint32(const SDL_Color * color) { Uint32 ret = 0; - #ifdef VCMI_SDL1 - ret+=color->unused; - #else ret+=color->a; - #endif // 0 ret<<=8; //*=256 ret+=color->b; ret<<=8; //*=256 @@ -505,15 +497,10 @@ Uint32 CSDL_Ext::colorToUint32(const SDL_Color * color) void CSDL_Ext::update(SDL_Surface * what) { - #ifdef VCMI_SDL1 - if(what) - SDL_UpdateRect(what, 0, 0, what->w, what->h); - #else if(!what) return; if(0 !=SDL_UpdateTexture(screenTexture, nullptr, what->pixels, what->pitch)) logGlobal->errorStream() << __FUNCTION__ << "SDL_UpdateTexture " << SDL_GetError(); - #endif // VCMI_SDL1 } void CSDL_Ext::drawBorder(SDL_Surface * sur, int x, int y, int w, int h, const int3 &color) { @@ -633,21 +620,13 @@ bool CSDL_Ext::isTransparent( SDL_Surface * srf, int x, int y ) SDL_Color color; - #ifdef VCMI_SDL1 - 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) - #ifdef VCMI_SDL1 - 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); } @@ -1009,11 +988,7 @@ void CSDL_Ext::stopTextInput() STRONG_INLINE static uint32_t mapColor(SDL_Surface * surface, SDL_Color color) { - #ifdef VCMI_SDL1 - return SDL_MapRGB(surface->format, color.r, color.g, color.b); - #else return SDL_MapRGBA(surface->format, color.r, color.g, color.b, color.a); - #endif } void CSDL_Ext::setColorKey(SDL_Surface * surface, SDL_Color color) diff --git a/client/gui/SDL_Extensions.h b/client/gui/SDL_Extensions.h index 9dfcfe48b..0e75478d7 100644 --- a/client/gui/SDL_Extensions.h +++ b/client/gui/SDL_Extensions.h @@ -58,39 +58,24 @@ void SDL_UpdateRect(SDL_Surface *surface, int x, int y, int w, int h); inline bool isCtrlKeyDown() { - #ifdef VCMI_SDL1 - return SDL_GetKeyState(nullptr)[SDLK_LCTRL] || SDL_GetKeyState(nullptr)[SDLK_RCTRL]; - #else return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LCTRL] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RCTRL]; - #endif } inline bool isAltKeyDown() { - #ifdef VCMI_SDL1 - return SDL_GetKeyState(nullptr)[SDLK_LALT] || SDL_GetKeyState(nullptr)[SDLK_RALT]; - #else return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LALT] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RALT]; - #endif } inline bool isShiftKeyDown() { - #ifdef VCMI_SDL1 - return SDL_GetKeyState(nullptr)[SDLK_LSHIFT] || SDL_GetKeyState(nullptr)[SDLK_RSHIFT]; - #else return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LSHIFT] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RSHIFT]; - #endif } namespace CSDL_Ext { + //todo: remove STRONG_INLINE void colorSetAlpha(SDL_Color & color, Uint8 alpha) { -#ifdef VCMI_SDL1 - color.unused = alpha; -#else color.a = alpha; -#endif } //todo: should this better be assignment operator? STRONG_INLINE void colorAssign(SDL_Color & dest, const SDL_Color & source) @@ -98,20 +83,12 @@ namespace CSDL_Ext dest.r = source.r; dest.g = source.g; dest.b = source.b; -#ifdef VCMI_SDL1 - dest.unused = source.unused; -#else dest.a = source.a; -#endif } inline void setAlpha(SDL_Surface * bg, int value) { -#ifdef VCMI_SDL1 - SDL_SetAlpha(bg, SDL_SRCALPHA, value); -#else SDL_SetSurfaceAlphaMod(bg, value); -#endif } } struct Rect; diff --git a/client/gui/SDL_Pixels.h b/client/gui/SDL_Pixels.h index 971054c89..bb2226f55 100644 --- a/client/gui/SDL_Pixels.h +++ b/client/gui/SDL_Pixels.h @@ -135,11 +135,7 @@ struct ColorPutter<2, incrementPtr> template STRONG_INLINE void ColorPutter::PutColorAlpha(Uint8 *&ptr, const SDL_Color & Color) { - #ifdef VCMI_SDL1 - PutColor(ptr, Color.r, Color.g, Color.b, Color.unused); - #else PutColor(ptr, Color.r, Color.g, Color.b, Color.a); - #endif } template @@ -268,11 +264,7 @@ 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) { - #ifdef VCMI_SDL1 - PutColor(ptr, Color.r, Color.g, Color.b, Color.unused); - #else PutColor(ptr, Color.r, Color.g, Color.b, Color.a); - #endif } template diff --git a/client/widgets/AdventureMapClasses.cpp b/client/widgets/AdventureMapClasses.cpp index 7077b71cd..0d31b2ef8 100644 --- a/client/widgets/AdventureMapClasses.cpp +++ b/client/widgets/AdventureMapClasses.cpp @@ -1121,17 +1121,6 @@ void CInGameConsole::keyPressed (const SDL_KeyboardEvent & key) } default: { - #ifdef VCMI_SDL1 - if(enteredText.size() > 0 && enteredText.size() < conf.go()->ac.inputLineLength) - { - if( key.keysym.unicode < 0x80 && key.keysym.unicode > 0 ) - { - enteredText[enteredText.size()-1] = (char)key.keysym.unicode; - enteredText += "_"; - refreshEnteredText(); - } - } - #endif // VCMI_SDL1 break; } } @@ -1219,14 +1208,9 @@ void CInGameConsole::refreshEnteredText() CInGameConsole::CInGameConsole() : prevEntDisp(-1), defaultTimeout(10000), maxDisplayedTexts(10) { - #ifdef VCMI_SDL1 - addUsedEvents(KEYBOARD); - #else addUsedEvents(KEYBOARD | TEXTINPUT); - #endif } - CAdvMapPanel::CAdvMapPanel(SDL_Surface * bg, Point position) : CIntObject(), background(bg) diff --git a/client/widgets/Buttons.cpp b/client/widgets/Buttons.cpp index 9504cfe73..109b7dedb 100644 --- a/client/widgets/Buttons.cpp +++ b/client/widgets/Buttons.cpp @@ -295,13 +295,8 @@ void CButton::showAll(SDL_Surface * to) { CIntObject::showAll(to); - #ifdef VCMI_SDL1 - if (borderColor && 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)); - #else if (borderColor && 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 } std::pair CButton::tooltip() diff --git a/client/widgets/TextControls.cpp b/client/widgets/TextControls.cpp index ca52a274c..9584d39a7 100644 --- a/client/widgets/TextControls.cpp +++ b/client/widgets/TextControls.cpp @@ -461,9 +461,7 @@ void CTextInput::keyPressed( const SDL_KeyboardEvent & key ) } bool redrawNeeded = false; - #ifdef VCMI_SDL1 - std::string oldText = text; - #endif // 0 + switch(key.keysym.sym) { case SDLK_DELETE: // have index > ' ' so it won't be filtered out by default section @@ -481,20 +479,9 @@ void CTextInput::keyPressed( const SDL_KeyboardEvent & key ) } break; default: - #ifdef VCMI_SDL1 - if (key.keysym.unicode < ' ') - return; - else - { - text += key.keysym.unicode; //TODO 16-/>8 - redrawNeeded = true; - } - #endif // 0 break; } - #ifdef VCMI_SDL1 - filters(text, oldText); - #endif // 0 + if (redrawNeeded) { redraw(); @@ -514,18 +501,9 @@ bool CTextInput::captureThisEvent(const SDL_KeyboardEvent & key) if(key.keysym.sym == SDLK_RETURN || key.keysym.sym == SDLK_KP_ENTER) return false; - #ifdef VCMI_SDL1 - //this should allow all non-printable keys to go through (for example arrows) - if (key.keysym.unicode < ' ') - return false; - - return true; - #else return false; - #endif } -#ifndef VCMI_SDL1 void CTextInput::textInputed(const SDL_TextInputEvent & event) { if(!focus) @@ -553,9 +531,6 @@ void CTextInput::textEdited(const SDL_TextEditingEvent & event) cb(text+newText); } -#endif - - void CTextInput::filenameFilter(std::string & text, const std::string &) { static const std::string forbiddenChars = "<>:\"/\\|?*\r\n"; //if we are entering a filename, some special characters won't be allowed diff --git a/client/windows/CAdvmapInterface.cpp b/client/windows/CAdvmapInterface.cpp index b36793979..a18b6fb9a 100644 --- a/client/windows/CAdvmapInterface.cpp +++ b/client/windows/CAdvmapInterface.cpp @@ -1159,14 +1159,11 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key) if(CGuiHandler::isArrowKey(SDLKey(k))) k = CGuiHandler::arrowToNum(SDLKey(k)); - #ifdef VCMI_SDL1 - k -= SDLK_KP0 + 1; - #else k -= SDLK_KP_1; - #endif // VCMI_SDL1 + if(k < 0 || k > 8) return; - + if (!CGI->mh->canStartHeroMovement()) return; From b6a2323e01dfdfdba41452758e6a252fa2acb0af Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Sun, 21 Jun 2015 01:17:44 +0300 Subject: [PATCH 2/6] SDL1 wipe, part 2. Untested. --- client/Graphics.cpp | 2 -- client/gui/CCursorHandler.cpp | 2 -- client/gui/CGuiHandler.cpp | 8 -------- client/gui/CGuiHandler.h | 7 +++---- client/gui/CIntObject.h | 2 -- client/gui/SDL_Extensions.cpp | 4 ---- client/gui/SDL_Extensions.h | 5 ----- client/widgets/AdventureMapClasses.cpp | 4 ---- client/widgets/AdventureMapClasses.h | 2 -- client/widgets/TextControls.h | 4 ---- client/windows/GUIClasses.cpp | 2 -- 11 files changed, 3 insertions(+), 39 deletions(-) diff --git a/client/Graphics.cpp b/client/Graphics.cpp index 9981d400c..4bf27ac63 100644 --- a/client/Graphics.cpp +++ b/client/Graphics.cpp @@ -266,9 +266,7 @@ void Graphics::loadHeroFlagsDetail(std::pair Graphi for(auto & curImg : curImgs) { CSDL_Ext::setDefaultColorKey(curImg.bitmap); - #ifndef VCMI_SDL1 SDL_SetSurfaceBlendMode(curImg.bitmap,SDL_BLENDMODE_NONE); - #endif } } } diff --git a/client/gui/CCursorHandler.cpp b/client/gui/CCursorHandler.cpp index 5b7c27650..326a8a743 100644 --- a/client/gui/CCursorHandler.cpp +++ b/client/gui/CCursorHandler.cpp @@ -27,10 +27,8 @@ void CCursorHandler::initCursor() currentCursor = nullptr; help = CSDL_Ext::newSurface(40,40); - #ifndef VCMI_SDL1 //No blending. Ensure, that we are copying pixels during "screen restore draw" SDL_SetSurfaceBlendMode(help,SDL_BLENDMODE_NONE); - #endif // VCMI_SDL1 SDL_ShowCursor(SDL_DISABLE); changeGraphic(ECursor::ADVENTURE, 0); diff --git a/client/gui/CGuiHandler.cpp b/client/gui/CGuiHandler.cpp index fabdbc268..b1b59e833 100644 --- a/client/gui/CGuiHandler.cpp +++ b/client/gui/CGuiHandler.cpp @@ -63,10 +63,7 @@ void CGuiHandler::processLists(const ui16 activityFlag, std::functiontype == SDL_MOUSEWHEEL) { std::list hlp = wheelInterested; @@ -296,7 +290,6 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent) } } //todo: muiltitouch - #endif // VCMI_SDL1 else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT)) { std::list hlp = lclickable; @@ -330,7 +323,6 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent) } } current = nullptr; - } //event end void CGuiHandler::handleMouseMotion(SDL_Event *sEvent) diff --git a/client/gui/CGuiHandler.h b/client/gui/CGuiHandler.h index 09b3e3b8d..d8f9cfb30 100644 --- a/client/gui/CGuiHandler.h +++ b/client/gui/CGuiHandler.h @@ -58,10 +58,9 @@ private: motioninterested, timeinterested, wheelInterested, - doubleClickInterested; - #ifndef VCMI_SDL1 - CIntObjectList textInterested; - #endif // VCMI_SDL1 + doubleClickInterested, + textInterested; + void processLists(const ui16 activityFlag, std::function *)> cb); public: diff --git a/client/gui/CIntObject.h b/client/gui/CIntObject.h index 751c291bc..fe566c7f0 100644 --- a/client/gui/CIntObject.h +++ b/client/gui/CIntObject.h @@ -133,10 +133,8 @@ public: virtual void keyPressed(const SDL_KeyboardEvent & key){} virtual bool captureThisEvent(const SDL_KeyboardEvent & key); //allows refining captureAllKeys against specific events (eg. don't capture ENTER) -#ifndef VCMI_SDL1 virtual void textInputed(const SDL_TextInputEvent & event){}; virtual void textEdited(const SDL_TextEditingEvent & event){}; -#endif // VCMI_SDL1 //mouse movement handling bool strongInterest; //if true - report all mouse movements, if not - only when hovered diff --git a/client/gui/SDL_Extensions.cpp b/client/gui/SDL_Extensions.cpp index c29c4ed6d..d78c64afc 100644 --- a/client/gui/SDL_Extensions.cpp +++ b/client/gui/SDL_Extensions.cpp @@ -967,23 +967,19 @@ SDL_Color CSDL_Ext::makeColor(ui8 r, ui8 g, ui8 b, ui8 a) void CSDL_Ext::startTextInput(SDL_Rect * where) { - #ifndef VCMI_SDL1 if (SDL_IsTextInputActive() == SDL_FALSE) { SDL_StartTextInput(); } SDL_SetTextInputRect(where); - #endif } void CSDL_Ext::stopTextInput() { - #ifndef VCMI_SDL1 if (SDL_IsTextInputActive() == SDL_TRUE) { SDL_StopTextInput(); } - #endif } STRONG_INLINE static uint32_t mapColor(SDL_Surface * surface, SDL_Color color) diff --git a/client/gui/SDL_Extensions.h b/client/gui/SDL_Extensions.h index 0e75478d7..1e9f06edd 100644 --- a/client/gui/SDL_Extensions.h +++ b/client/gui/SDL_Extensions.h @@ -10,15 +10,10 @@ #pragma once #include - -#ifndef VCMI_SDL1 #include -#endif - #include #include #include "../../lib/int3.h" -//#include "../Graphics.h" #include "Geometries.h" #include "../../lib/GameConstants.h" diff --git a/client/widgets/AdventureMapClasses.cpp b/client/widgets/AdventureMapClasses.cpp index 0d31b2ef8..b7014ee8c 100644 --- a/client/widgets/AdventureMapClasses.cpp +++ b/client/widgets/AdventureMapClasses.cpp @@ -1126,8 +1126,6 @@ void CInGameConsole::keyPressed (const SDL_KeyboardEvent & key) } } -#ifndef VCMI_SDL1 - void CInGameConsole::textInputed(const SDL_TextInputEvent & event) { if(!captureAllKeys || enteredText.size() == 0) @@ -1145,8 +1143,6 @@ void CInGameConsole::textEdited(const SDL_TextEditingEvent & event) //do nothing here } -#endif // VCMI_SDL1 - void CInGameConsole::startEnteringText() { CSDL_Ext::startTextInput(&pos); diff --git a/client/widgets/AdventureMapClasses.h b/client/widgets/AdventureMapClasses.h index c14c88eb0..948bfa2df 100644 --- a/client/widgets/AdventureMapClasses.h +++ b/client/widgets/AdventureMapClasses.h @@ -369,10 +369,8 @@ public: void print(const std::string &txt); void keyPressed (const SDL_KeyboardEvent & key); //call-in -#ifndef VCMI_SDL1 void textInputed(const SDL_TextInputEvent & event) override; void textEdited(const SDL_TextEditingEvent & event) override; -#endif // VCMI_SDL1 void startEnteringText(); void endEnteringText(bool printEnteredText); diff --git a/client/widgets/TextControls.h b/client/widgets/TextControls.h index 0039a0688..9f5491a9b 100644 --- a/client/widgets/TextControls.h +++ b/client/widgets/TextControls.h @@ -174,12 +174,8 @@ public: void keyPressed(const SDL_KeyboardEvent & key) override; bool captureThisEvent(const SDL_KeyboardEvent & key) override; -#ifndef VCMI_SDL1 void textInputed(const SDL_TextInputEvent & event) override; void textEdited(const SDL_TextEditingEvent & event) override; - - -#endif // VCMI_SDL1 //Filter that will block all characters not allowed in filenames static void filenameFilter(std::string &text, const std::string & oldText); diff --git a/client/windows/GUIClasses.cpp b/client/windows/GUIClasses.cpp index d014d0201..95516d507 100644 --- a/client/windows/GUIClasses.cpp +++ b/client/windows/GUIClasses.cpp @@ -1089,9 +1089,7 @@ CPuzzleWindow::CPuzzleWindow(const int3 &GrailPos, double discoveredRatio): piecesToRemove.push_back(piece); piece->needRefresh = true; piece->recActions = piece->recActions & ~SHOWALL; - #ifndef VCMI_SDL1 SDL_SetSurfaceBlendMode(piece->bg,SDL_BLENDMODE_BLEND); - #endif // VCMI_SDL1 } } } From 8c236e30bb66e4039bd1af9adc2caa65ccd890cf Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Sun, 21 Jun 2015 01:24:59 +0300 Subject: [PATCH 3/6] SDL1 wipe, part 3. Untested. --- client/CVideoHandler.h | 3 --- client/gui/CGuiHandler.cpp | 3 --- client/gui/SDL_Compat.h | 6 ------ client/gui/SDL_Extensions.cpp | 2 -- client/gui/SDL_Extensions.h | 8 -------- 5 files changed, 22 deletions(-) diff --git a/client/CVideoHandler.h b/client/CVideoHandler.h index 30d2e0d4d..d7f67394c 100644 --- a/client/CVideoHandler.h +++ b/client/CVideoHandler.h @@ -47,9 +47,6 @@ public: #include #include -#if SDL_VERSION_ATLEAST(1,3,0) && !SDL_VERSION_ATLEAST(2,0,0) -#include -#endif extern "C" { #include diff --git a/client/gui/CGuiHandler.cpp b/client/gui/CGuiHandler.cpp index b1b59e833..1dfb60b09 100644 --- a/client/gui/CGuiHandler.cpp +++ b/client/gui/CGuiHandler.cpp @@ -398,13 +398,10 @@ void CGuiHandler::renderFrame() // draw the mouse cursor and update the screen CCS->curh->render(); - #ifndef VCMI_SDL1 if(0 != SDL_RenderCopy(mainRenderer, screenTexture, nullptr, nullptr)) logGlobal->errorStream() << __FUNCTION__ << " SDL_RenderCopy " << SDL_GetError(); SDL_RenderPresent(mainRenderer); - #endif - }; if(curInt) diff --git a/client/gui/SDL_Compat.h b/client/gui/SDL_Compat.h index ccda77c5d..99dc31f48 100644 --- a/client/gui/SDL_Compat.h +++ b/client/gui/SDL_Compat.h @@ -13,7 +13,6 @@ #include #if (SDL_MAJOR_VERSION == 2) -#define VCMI_SDL2 #include typedef int SDLX_Coord; @@ -25,11 +24,6 @@ typedef SDL_Keycode SDLKey; #define SDL_FULLSCREEN SDL_WINDOW_FULLSCREEN -#elif (SDL_MAJOR_VERSION == 1) -#define VCMI_SDL1 -//SDL 1.x -typedef Sint16 SDLX_Coord; -typedef Uint16 SDLX_Size; #else #error "unknown or unsupported SDL version" #endif diff --git a/client/gui/SDL_Extensions.cpp b/client/gui/SDL_Extensions.cpp index d78c64afc..4a283c9c4 100644 --- a/client/gui/SDL_Extensions.cpp +++ b/client/gui/SDL_Extensions.cpp @@ -14,7 +14,6 @@ const SDL_Color Colors::METALLIC_GOLD = { 173, 142, 66, 0 }; const SDL_Color Colors::GREEN = { 0, 255, 0, 0 }; const SDL_Color Colors::DEFAULT_KEY_COLOR = {0, 255, 255, 0}; -#if (SDL_MAJOR_VERSION == 2) void SDL_UpdateRect(SDL_Surface *surface, int x, int y, int w, int h) { Rect rect(x,y,w,h); @@ -27,7 +26,6 @@ void SDL_UpdateRect(SDL_Surface *surface, int x, int y, int w, int h) SDL_RenderPresent(mainRenderer); } -#endif // VCMI_SDL1 SDL_Surface * CSDL_Ext::newSurface(int w, int h, SDL_Surface * mod) //creates new surface, with flags/format same as in surface given { diff --git a/client/gui/SDL_Extensions.h b/client/gui/SDL_Extensions.h index 1e9f06edd..6ca762818 100644 --- a/client/gui/SDL_Extensions.h +++ b/client/gui/SDL_Extensions.h @@ -27,13 +27,6 @@ #define STRONG_INLINE inline #endif -#if SDL_VERSION_ATLEAST(1,3,0) -#define SDL_GetKeyState SDL_GetKeyboardState -#endif - -//SDL2 support -#if (SDL_MAJOR_VERSION == 2) - extern SDL_Window * mainWindow; extern SDL_Renderer * mainRenderer; extern SDL_Texture * screenTexture; @@ -49,7 +42,6 @@ inline void SDL_WarpMouse(int x, int y) } void SDL_UpdateRect(SDL_Surface *surface, int x, int y, int w, int h); -#endif inline bool isCtrlKeyDown() { From ed281a3cc6c603407edea5dbc942a25728428639 Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Sun, 21 Jun 2015 01:38:05 +0300 Subject: [PATCH 4/6] SDL1 wipe, part 4. Codebase cleanup finished. Untested. --- client/gui/CAnimation.cpp | 2 +- client/gui/CGuiHandler.cpp | 10 +++++----- client/gui/CGuiHandler.h | 8 ++++---- client/gui/SDL_Compat.h | 5 ----- client/gui/SDL_Extensions.cpp | 6 +++--- client/windows/CAdvmapInterface.cpp | 6 +++--- client/windows/CSpellWindow.cpp | 4 ++-- 7 files changed, 18 insertions(+), 23 deletions(-) diff --git a/client/gui/CAnimation.cpp b/client/gui/CAnimation.cpp index 5bfe2d827..0572656c2 100644 --- a/client/gui/CAnimation.cpp +++ b/client/gui/CAnimation.cpp @@ -387,7 +387,7 @@ inline void SDLImageLoader::EndLine() SDLImageLoader::~SDLImageLoader() { SDL_UnlockSurface(image->surf); - SDL_SetColorKey(image->surf, SDL_SRCCOLORKEY, 0); + SDL_SetColorKey(image->surf, SDL_TRUE, 0); //TODO: RLE if compressed and bpp>1 } diff --git a/client/gui/CGuiHandler.cpp b/client/gui/CGuiHandler.cpp index 1dfb60b09..2c1cde092 100644 --- a/client/gui/CGuiHandler.cpp +++ b/client/gui/CGuiHandler.cpp @@ -193,7 +193,7 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent) //translate numpad keys if(key.keysym.sym == SDLK_KP_ENTER) { - key.keysym.sym = (SDLKey)SDLK_RETURN; + key.keysym.sym = SDLK_RETURN; key.keysym.scancode = SDL_SCANCODE_RETURN; } @@ -445,7 +445,7 @@ void CGuiHandler::drawFPSCounter() graphics->fonts[FONT_BIG]->renderTextLeft(screen, fps, yellow, Point(10, 10)); } -SDLKey CGuiHandler::arrowToNum( SDLKey key ) +SDL_Keycode CGuiHandler::arrowToNum(SDL_Keycode key ) { switch(key) { @@ -462,7 +462,7 @@ SDLKey CGuiHandler::arrowToNum( SDLKey key ) } } -SDLKey CGuiHandler::numToDigit( SDLKey key ) +SDL_Keycode CGuiHandler::numToDigit(SDL_Keycode key) { #define REMOVE_KP(keyName) case SDLK_KP_ ## keyName : return SDLK_ ## keyName; @@ -495,7 +495,7 @@ SDLKey CGuiHandler::numToDigit( SDLKey key ) #undef REMOVE_KP } -bool CGuiHandler::isNumKey( SDLKey key, bool number ) +bool CGuiHandler::isNumKey(SDL_Keycode key, bool number) { if(number) return key >= SDLK_KP_1 && key <= SDLK_KP_0; @@ -503,7 +503,7 @@ bool CGuiHandler::isNumKey( SDLKey key, bool number ) return (key >= SDLK_KP_1 && key <= SDLK_KP_0) || key == SDLK_KP_MINUS || key == SDLK_KP_PLUS || key == SDLK_KP_EQUALS; } -bool CGuiHandler::isArrowKey( SDLKey key ) +bool CGuiHandler::isArrowKey(SDL_Keycode key) { return key == SDLK_UP || key == SDLK_DOWN || key == SDLK_LEFT || key == SDLK_RIGHT; } diff --git a/client/gui/CGuiHandler.h b/client/gui/CGuiHandler.h index d8f9cfb30..063fde5fc 100644 --- a/client/gui/CGuiHandler.h +++ b/client/gui/CGuiHandler.h @@ -103,10 +103,10 @@ public: ui8 captureChildren; //all newly created objects will get their parents from stack and will be added to parents children list std::list createdObj; //stack of objs being created - static SDLKey arrowToNum(SDLKey key); //converts arrow key to according numpad key - static SDLKey numToDigit(SDLKey key);//converts numpad digit key to normal digit key - static bool isNumKey(SDLKey key, bool number = true); //checks if key is on numpad (numbers - check only for numpad digits) - static bool isArrowKey(SDLKey key); + static SDL_Keycode arrowToNum(SDL_Keycode key); //converts arrow key to according numpad key + static SDL_Keycode numToDigit(SDL_Keycode key);//converts numpad digit key to normal digit key + static bool isNumKey(SDL_Keycode key, bool number = true); //checks if key is on numpad (numbers - check only for numpad digits) + static bool isArrowKey(SDL_Keycode key); static bool amIGuiThread(); static void pushSDLEvent(int type, int usercode = 0); }; diff --git a/client/gui/SDL_Compat.h b/client/gui/SDL_Compat.h index 99dc31f48..13b428fd4 100644 --- a/client/gui/SDL_Compat.h +++ b/client/gui/SDL_Compat.h @@ -18,11 +18,6 @@ typedef int SDLX_Coord; typedef int SDLX_Size; -typedef SDL_Keycode SDLKey; - -#define SDL_SRCCOLORKEY SDL_TRUE - -#define SDL_FULLSCREEN SDL_WINDOW_FULLSCREEN #else #error "unknown or unsupported SDL version" diff --git a/client/gui/SDL_Extensions.cpp b/client/gui/SDL_Extensions.cpp index 4a283c9c4..a3081da9a 100644 --- a/client/gui/SDL_Extensions.cpp +++ b/client/gui/SDL_Extensions.cpp @@ -169,7 +169,7 @@ void CSDL_Ext::alphaTransform(SDL_Surface *src) SDL_Color & palColor = src->format->palette->colors[i]; palColor = colors[i]; } - SDL_SetColorKey(src, SDL_SRCCOLORKEY, 0); + SDL_SetColorKey(src, SDL_TRUE, 0); } static void prepareOutRect(SDL_Rect *src, SDL_Rect *dst, const SDL_Rect & clip_rect) @@ -988,7 +988,7 @@ STRONG_INLINE static uint32_t mapColor(SDL_Surface * surface, SDL_Color color) void CSDL_Ext::setColorKey(SDL_Surface * surface, SDL_Color color) { uint32_t key = mapColor(surface,color); - SDL_SetColorKey(surface, SDL_SRCCOLORKEY, key); + SDL_SetColorKey(surface, SDL_TRUE, key); } void CSDL_Ext::setDefaultColorKey(SDL_Surface * surface) @@ -1003,7 +1003,7 @@ void CSDL_Ext::setDefaultColorKeyPresize(SDL_Surface * surface) // set color key only if exactly such color was found if (color.r == Colors::DEFAULT_KEY_COLOR.r && color.g == Colors::DEFAULT_KEY_COLOR.g && color.b == Colors::DEFAULT_KEY_COLOR.b) - SDL_SetColorKey(surface, SDL_SRCCOLORKEY, key); + SDL_SetColorKey(surface, SDL_TRUE, key); } diff --git a/client/windows/CAdvmapInterface.cpp b/client/windows/CAdvmapInterface.cpp index a18b6fb9a..e1b96e049 100644 --- a/client/windows/CAdvmapInterface.cpp +++ b/client/windows/CAdvmapInterface.cpp @@ -1029,7 +1029,7 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key) return; ui8 Dir = 0; - int k = key.keysym.sym; + SDL_Keycode k = key.keysym.sym; const CGHeroInstance *h = curHero(); //selected hero const CGTownInstance *t = curTown(); //selected town @@ -1156,8 +1156,8 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key) int3(-1, -1, 0), int3(0, -1, 0), int3(+1, -1, 0) }; //numpad arrow - if(CGuiHandler::isArrowKey(SDLKey(k))) - k = CGuiHandler::arrowToNum(SDLKey(k)); + if(CGuiHandler::isArrowKey(k)) + k = CGuiHandler::arrowToNum(k); k -= SDLK_KP_1; diff --git a/client/windows/CSpellWindow.cpp b/client/windows/CSpellWindow.cpp index 31178d1df..67e9a81f3 100644 --- a/client/windows/CSpellWindow.cpp +++ b/client/windows/CSpellWindow.cpp @@ -571,7 +571,7 @@ void CSpellWindow::keyPressed(const SDL_KeyboardEvent & key) //alt + 1234567890-= casts spell from 1 - 12 slot if(LOCPLINT->altPressed()) { - SDLKey hlpKey = key.keysym.sym; + SDL_Keycode hlpKey = key.keysym.sym; if(CGuiHandler::isNumKey(hlpKey, false)) { if(hlpKey == SDLK_KP_PLUS) @@ -580,7 +580,7 @@ void CSpellWindow::keyPressed(const SDL_KeyboardEvent & key) hlpKey = CGuiHandler::numToDigit(hlpKey); } - static const SDLKey spellSelectors[] = {SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5, SDLK_6, SDLK_7, SDLK_8, SDLK_9, SDLK_0, SDLK_MINUS, SDLK_EQUALS}; + static const SDL_Keycode spellSelectors[] = {SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5, SDLK_6, SDLK_7, SDLK_8, SDLK_9, SDLK_0, SDLK_MINUS, SDLK_EQUALS}; int index = -1; while(++index < ARRAY_COUNT(spellSelectors) && spellSelectors[index] != hlpKey); From 53b85d16be041bb409be31522b3656d9b5404835 Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Sun, 21 Jun 2015 01:48:08 +0300 Subject: [PATCH 5/6] Cleanup C::B projects --- AI/BattleAI/BattleAI.cbp | 23 --------------------- AI/EmptyAI/EmptyAI.cbp | 30 +--------------------------- AI/FuzzyLite/FuzzyLite.cbp | 28 -------------------------- AI/StupidAI/StupidAI.cbp | 24 ---------------------- AI/VCAI/VCAI.cbp | 28 -------------------------- client/VCMI_client.cbp | 41 -------------------------------------- lib/VCMI_lib.cbp | 35 -------------------------------- lib/minizip/minizip.cbp | 29 --------------------------- server/VCMI_server.cbp | 29 --------------------------- test/Test.cbp | 12 ----------- 10 files changed, 1 insertion(+), 278 deletions(-) diff --git a/AI/BattleAI/BattleAI.cbp b/AI/BattleAI/BattleAI.cbp index 990a0d760..148f2d5a3 100644 --- a/AI/BattleAI/BattleAI.cbp +++ b/AI/BattleAI/BattleAI.cbp @@ -29,29 +29,6 @@ - - - - diff --git a/AI/EmptyAI/EmptyAI.cbp b/AI/EmptyAI/EmptyAI.cbp index 17c6e0b38..529526efb 100644 --- a/AI/EmptyAI/EmptyAI.cbp +++ b/AI/EmptyAI/EmptyAI.cbp @@ -23,36 +23,8 @@