1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

SDL1 wipe, part 1. Untested.

This commit is contained in:
AlexVinS 2015-06-21 01:13:45 +03:00
parent 728dac3b47
commit dca1e28bc1
17 changed files with 9 additions and 422 deletions

View File

@ -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;
}

View File

@ -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<bool> inGuiThread;
@ -264,11 +262,6 @@ int main(int argc, char** argv)
gNoGUI = true;
vm.insert(std::pair<std::string, po::variable_value>("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();

View File

@ -1,6 +1,5 @@
#pragma once
#ifndef VCMI_SDL1
#include <SDL_render.h>
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

View File

@ -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()

View File

@ -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
}
}

View File

@ -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();

View File

@ -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

View File

@ -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<SDL_Color, 8> 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<bpp, 0>::PutColor(dest, pal.r, pal.g, pal.b, pal.unused);
#else
ColorPutter<bpp, 0>::PutColor(dest, pal.r, pal.g, pal.b, pal.a);
#endif // 0
}
else
{

View File

@ -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<size; i++)
{
SDL_Color col = palette[*(data++)];
#ifdef VCMI_SDL1
col.unused = (ui32)col.unused*alpha/255;
#else
col.a = (ui32)col.a*alpha/255;
#endif // 0
ColorPutter<bpp, 1>::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<size; i++)
@ -842,19 +819,6 @@ void CompImage::BlitBlock(ui8 type, ui8 size, ui8 *&data, ui8 *&dest, ui8 alpha)
//RLE-d sequence
else
{
#ifdef VCMI_SDL1
if (alpha != 255 && palette[type].unused !=0)//Per-surface alpha is set
{
SDL_Color col = palette[type];
col.unused = (int)col.unused*(255-alpha)/255;
for (size_t i=0; i<size; i++)
ColorPutter<bpp, 1>::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:
{

View File

@ -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<CIntObject*> 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 )

View File

@ -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<bpp, +1>::PutColorAlphaSwitch(p, tbc.r, tbc.g, tbc.b, tbc.unused);
#else
ColorPutter<bpp, +1>::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)

View File

@ -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;

View File

@ -135,11 +135,7 @@ struct ColorPutter<2, incrementPtr>
template<int bpp, int incrementPtr>
STRONG_INLINE void ColorPutter<bpp, 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<int bpp, int incrementPtr>
@ -268,11 +264,7 @@ STRONG_INLINE void ColorPutter<2, incrementPtr>::PutColor(Uint8 *&ptr, const Uin
template <int incrementPtr>
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 <int incrementPtr>

View File

@ -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)

View File

@ -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<std::string, std::string> CButton::tooltip()

View File

@ -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

View File

@ -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;