1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

fix compilation

* may not even run
* text input disabled
This commit is contained in:
AlexVinS 2014-05-21 20:04:34 +04:00 committed by AlexVinS
parent 796905ec42
commit 62d42465de
18 changed files with 469 additions and 82 deletions

View File

@ -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<ui16>(move->pos.h + 1, mana->pos.h + 1), img->pos.h);
pos.h = std::max(std::max<SDLX_Size>(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<ui16>(movement->pos.h + 1, mana->pos.h + 1), portrait->pos.h);
pos.h = std::max(std::max<SDLX_Size>(movement->pos.h + 1, mana->pos.h + 1), portrait->pos.h);
update();
}

View File

@ -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);
@ -922,7 +931,11 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
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;

View File

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

View File

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

View File

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

View File

@ -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<SDL_Event> 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)
{
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);
// 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)
int suggestedBpp = bpp;
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");
}
//For some reason changing fullscreen via config window checkbox result in SDL_Quit event
if (resetVideo)
//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);
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");
}
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");
}
SDL_RenderSetLogicalSize(mainRenderer, w, h);
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);
#ifdef _WIN32
SDL_SysWMinfo wm;
SDL_VERSION(&wm.version);
int getwm = SDL_GetWMInfo(&wm);
if(getwm == 1)
//logGlobal->infoStream() << "New screen flags: " << screen->flags;
SDL_FreeSurface(screen);
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);
throw std::runtime_error("Unable to create surface\n");
}
else
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");
}
#endif
//TODO: centering game window on other platforms (or does the environment do their job correctly there?)
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;
}
#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?)
//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;
auto bitsPerPixel = screen->format->BitsPerPixel;
auto w = screen->w;
auto h = screen->h;
bitsPerPixel = SDL_VideoModeOK(screen->w, screen->h, bitsPerPixel, SDL_SWSURFACE|(toFullscreen?SDL_FULLSCREEN:0));
if(bitsPerPixel == 0)
if(!recreateWindow(w,h,bitsPerPixel,(toFullscreen?SDL_FULLSCREEN:0)))
{
logGlobal->errorStream() << "Error: SDL says that " << screen->w << "x" << screen->h << " resolution is not available!";
//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();
}

View File

@ -1,9 +1,16 @@
#pragma once
#include <SDL_render.h>
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();

View File

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

View File

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

View File

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

View File

@ -365,7 +365,11 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe
idToObstacle[ID] = CDefHandler::giveDef(elem->getInfo().defName);
for(auto & _n : idToObstacle[ID]->ourImages)
{
#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)

View File

@ -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<totalBlocks; i++)
@ -267,7 +271,11 @@ static SDL_Color genShadow(ui8 alpha)
static SDL_Color genBorderColor(ui8 alpha, const SDL_Color & base)
{
#if 0
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)
@ -277,12 +285,22 @@ static ui8 mixChannels(ui8 c1, ui8 c2, ui8 a1, ui8 a2)
static SDL_Color addColors(const SDL_Color & base, const SDL_Color & over)
{
#if 0
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 // 0
}
std::array<SDL_Color, 8> 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<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

@ -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<CIntObject*> 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<CIntObject*> 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<CIntObject*> hlp = lclickable;
@ -387,6 +401,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:
@ -445,13 +465,33 @@ SDLKey CGuiHandler::arrowToNum( SDLKey key )
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 )

View File

@ -2,6 +2,7 @@
#include "../../lib/CStopWatch.h"
#include "Geometries.h"
#include "SDL_Extensions.h"
class CFramerateManager;
class CGStatusBar;

View File

@ -134,7 +134,11 @@ void CPicture::convertToScreenBPP()
void CPicture::setAlpha(int 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<void()> &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;
@ -453,8 +465,13 @@ 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));
#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 )
@ -1631,11 +1653,15 @@ 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 &)

View File

@ -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<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);
@ -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)
{
@ -602,13 +615,21 @@ bool CSDL_Ext::isTransparent( SDL_Surface * srf, int x, int y )
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);
}

View File

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

View File

@ -133,7 +133,11 @@ struct ColorPutter<2, incrementPtr>
template<int bpp, int incrementPtr>
STRONG_INLINE void ColorPutter<bpp, 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<int bpp, int incrementPtr>
@ -262,7 +266,11 @@ 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)
{
#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 <int incrementPtr>