port to sdl2 x2 patch by galtgendo
This commit is contained in:
parent
56ad4c7eda
commit
6b970f12d0
20 changed files with 397 additions and 374 deletions
|
@ -161,7 +161,7 @@ set(guichan_SRCS
|
|||
src/guichan/rectangle.cpp
|
||||
src/guichan/sdl/gsdl.cpp
|
||||
src/guichan/sdl/sdlgraphics.cpp
|
||||
src/guichan/sdl/sdlimageloader.cpp
|
||||
# src/guichan/sdl/sdlimageloader.cpp
|
||||
src/guichan/sdl/sdlinput.cpp
|
||||
src/guichan/widget.cpp
|
||||
src/guichan/widgets/button.cpp
|
||||
|
@ -631,7 +631,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_P
|
|||
|
||||
find_package(Lua51 REQUIRED)
|
||||
find_package(PNG REQUIRED)
|
||||
find_package(SDL REQUIRED)
|
||||
find_package(SDL2 REQUIRED)
|
||||
find_package(Tolua++ REQUIRED)
|
||||
find_package(ZLIB REQUIRED)
|
||||
|
||||
|
@ -699,7 +699,7 @@ option(ENABLE_USEGAMEDIR "Place all files created by Stratagus(logs, savegames)
|
|||
option(ENABLE_MULTIBUILD "Compile Stratagus on all CPU cores simltaneously in MSVC" ON)
|
||||
|
||||
if(NOT WITH_RENDERER)
|
||||
if(OPENGL_FOUND)
|
||||
if(OPENGL_FOUND AND FALSE)
|
||||
set(WITH_RENDERER "OpenGL")
|
||||
elseif(OPENGLES_FOUND AND SDLGLES_FOUND)
|
||||
set(WITH_RENDERER "OpenGLES")
|
||||
|
@ -726,8 +726,8 @@ endif()
|
|||
# Stratagus definitions
|
||||
|
||||
add_definitions(${PNG_DEFINITIONS} -DUSE_ZLIB -DPIXMAPS=\"${PIXMAPSDIRABS}\")
|
||||
include_directories(${LUA_INCLUDE_DIR} ${PNG_INCLUDE_DIR} ${SDL_INCLUDE_DIR} ${TOLUA++_INCLUDE_DIR} ${ZLIB_INCLUDE_DIRS})
|
||||
set(stratagus_LIBS ${stratagus_LIBS} ${LUA_LIBRARIES} ${PNG_LIBRARIES} ${SDL_LIBRARY} ${TOLUA++_LIBRARY} ${ZLIB_LIBRARIES})
|
||||
include_directories(${LUA_INCLUDE_DIR} ${PNG_INCLUDE_DIR} ${SDL2_INCLUDE_DIR} ${TOLUA++_INCLUDE_DIR} ${ZLIB_INCLUDE_DIRS})
|
||||
set(stratagus_LIBS ${stratagus_LIBS} ${LUA_LIBRARIES} ${PNG_LIBRARIES} ${SDL2_LIBRARY} ${TOLUA++_LIBRARY} ${ZLIB_LIBRARIES})
|
||||
|
||||
if(WIN32 AND NOT ENABLE_STDIO_REDIRECT)
|
||||
add_definitions(-DNO_STDIO_REDIRECT)
|
||||
|
@ -825,7 +825,7 @@ endif()
|
|||
|
||||
if(APPLE)
|
||||
add_definitions(-DUSE_MAC)
|
||||
set(SDL_LIBRARY ${SDL_LIBRARY} SDLmain)
|
||||
set(SDL_LIBRARY ${SDL_LIBRARY} SDLmain)
|
||||
endif()
|
||||
|
||||
if(BSD)
|
||||
|
@ -1115,7 +1115,7 @@ source_group(metaserver FILES ${metaserver_SRCS} ${metaserver_HDRS})
|
|||
|
||||
if(SQLITE_FOUND)
|
||||
add_executable(metaserver ${metaserver_SRCS} ${metaserver_HDRS})
|
||||
target_link_libraries(metaserver ${SDL_LIBRARY} ${SQLITE_LIBRARIES})
|
||||
target_link_libraries(metaserver ${SDL2_LIBRARY} ${SQLITE_LIBRARIES})
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(metaserver winmm ws2_32)
|
||||
|
|
|
@ -1374,19 +1374,19 @@ static void EditorCallbackKeyDown(unsigned key, unsigned keychar)
|
|||
break;
|
||||
|
||||
case SDLK_UP: // Keyboard scrolling
|
||||
case SDLK_KP8:
|
||||
case SDLK_KP_8:
|
||||
KeyScrollState |= ScrollUp;
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
case SDLK_KP2:
|
||||
case SDLK_KP_2:
|
||||
KeyScrollState |= ScrollDown;
|
||||
break;
|
||||
case SDLK_LEFT:
|
||||
case SDLK_KP4:
|
||||
case SDLK_KP_4:
|
||||
KeyScrollState |= ScrollLeft;
|
||||
break;
|
||||
case SDLK_RIGHT:
|
||||
case SDLK_KP6:
|
||||
case SDLK_KP_6:
|
||||
KeyScrollState |= ScrollRight;
|
||||
break;
|
||||
case '0':
|
||||
|
@ -1426,19 +1426,19 @@ static void EditorCallbackKeyUp(unsigned key, unsigned keychar)
|
|||
|
||||
switch (key) {
|
||||
case SDLK_UP: // Keyboard scrolling
|
||||
case SDLK_KP8:
|
||||
case SDLK_KP_8:
|
||||
KeyScrollState &= ~ScrollUp;
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
case SDLK_KP2:
|
||||
case SDLK_KP_2:
|
||||
KeyScrollState &= ~ScrollDown;
|
||||
break;
|
||||
case SDLK_LEFT:
|
||||
case SDLK_KP4:
|
||||
case SDLK_KP_4:
|
||||
KeyScrollState &= ~ScrollLeft;
|
||||
break;
|
||||
case SDLK_RIGHT:
|
||||
case SDLK_KP6:
|
||||
case SDLK_KP_6:
|
||||
KeyScrollState &= ~ScrollRight;
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -90,6 +90,7 @@ namespace gcn
|
|||
* @param target the target to draw to.
|
||||
*/
|
||||
virtual void setTarget(SDL_Surface* target);
|
||||
//virtual void setTarget(SDL_Renderer* renderer);
|
||||
|
||||
/**
|
||||
* Gets the target SDL_Surface.
|
||||
|
@ -155,6 +156,8 @@ namespace gcn
|
|||
virtual void drawVLine(int x, int y1, int y2);
|
||||
|
||||
SDL_Surface* mTarget;
|
||||
SDL_Renderer* mRenderer;
|
||||
SDL_Texture* mTargetTexture;
|
||||
Color mColor;
|
||||
bool mAlpha;
|
||||
};
|
||||
|
|
|
@ -113,7 +113,7 @@ namespace gcn
|
|||
* @param key an SDL keysym
|
||||
* @return a Key object.
|
||||
*/
|
||||
static Key convertKeyCharacter(SDL_keysym key);
|
||||
static Key convertKeyCharacter(SDL_Keysym key);
|
||||
|
||||
protected:
|
||||
/**
|
||||
|
|
|
@ -76,6 +76,7 @@ namespace gcn
|
|||
SDLGraphics::SDLGraphics()
|
||||
{
|
||||
mAlpha = false;
|
||||
mTarget = NULL;
|
||||
}
|
||||
|
||||
void SDLGraphics::_beginDraw()
|
||||
|
@ -86,13 +87,38 @@ namespace gcn
|
|||
area.width = mTarget->w;
|
||||
area.height = mTarget->h;
|
||||
pushClipArea(area);
|
||||
|
||||
//SDL_FillRect(mTarget, NULL, SDL_MapRGBA(mTarget->format, 0, 0, 0, 0));
|
||||
}
|
||||
|
||||
void SDLGraphics::_endDraw()
|
||||
{
|
||||
//SDL_UpdateTexture(mTargetTexture, NULL, mTarget->pixels, mTarget->w * sizeof(Uint32));
|
||||
//SDL_RenderCopy(mRenderer, mTargetTexture, NULL, NULL);
|
||||
//SDL_RenderPresent(mRenderer);
|
||||
|
||||
popClipArea();
|
||||
}
|
||||
|
||||
#if 0
|
||||
void SDLGraphics::setTarget(SDL_Renderer* renderer)
|
||||
{
|
||||
if(mTarget)
|
||||
{
|
||||
SDL_FreeSurface(mTarget);
|
||||
SDL_DestroyTexture(mTargetTexture);
|
||||
}
|
||||
|
||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||
mTarget = SDL_CreateRGBSurface(0, 640, 480, 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
|
||||
#else
|
||||
mTarget = SDL_CreateRGBSurface(0, 640, 480, 32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
|
||||
#endif
|
||||
SDL_FillRect(mTarget, NULL, SDL_MapRGBA(mTarget->format, 0, 0, 0, 0));
|
||||
mTargetTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 640, 480);
|
||||
mRenderer = renderer;
|
||||
}
|
||||
#endif
|
||||
void SDLGraphics::setTarget(SDL_Surface* target)
|
||||
{
|
||||
mTarget = target;
|
||||
|
@ -176,10 +202,20 @@ namespace gcn
|
|||
int y1 = std::max<int>(area.y, top.y);
|
||||
int x2 = std::min<int>(area.x + area.width, top.x + top.width);
|
||||
int y2 = std::min<int>(area.y + area.height, top.y + top.height);
|
||||
int x, y;
|
||||
|
||||
Video.FillTransRectangle(SDL_MapRGB(TheScreen->format, mColor.r, mColor.g, mColor.b),
|
||||
x1, y1, x2 - x1, y2 - y1, mColor.a);
|
||||
}
|
||||
//Video.FillTransRectangle(SDL_MapRGB(mTarget->format, mColor.r, mColor.g, mColor.b),
|
||||
// x1, y1, x2 - x1, y2 - y1, mColor.a);
|
||||
// SDL_LockSurface(mTarget);
|
||||
for (y = y1; y < y2; y++)
|
||||
{
|
||||
for (x = x1; x < x2; x++)
|
||||
{
|
||||
SDLputPixelAlpha(mTarget, x, y, mColor);
|
||||
}
|
||||
}
|
||||
SDL_UnlockSurface(mTarget);
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_Rect rect;
|
||||
|
@ -247,7 +283,7 @@ namespace gcn
|
|||
x2 = top.x + top.width -1;
|
||||
}
|
||||
Uint32 color =
|
||||
SDL_MapRGB(TheScreen->format, mColor.r, mColor.g, mColor.b);
|
||||
SDL_MapRGB(mTarget->format, mColor.r, mColor.g, mColor.b);
|
||||
if (mAlpha) {
|
||||
Video.DrawTransHLine(color, x1, y, x2 - x1, mColor.a);
|
||||
} else {
|
||||
|
@ -290,7 +326,7 @@ namespace gcn
|
|||
y2 = top.y + top.height - 1;
|
||||
}
|
||||
Uint32 color =
|
||||
SDL_MapRGB(TheScreen->format, mColor.r, mColor.g, mColor.b);
|
||||
SDL_MapRGB(mTarget->format, mColor.r, mColor.g, mColor.b);
|
||||
if (mAlpha) {
|
||||
Video.DrawTransVLine(color, x, y1,y2 - y1, mColor.a);
|
||||
} else {
|
||||
|
|
|
@ -168,12 +168,12 @@ namespace gcn
|
|||
|
||||
if (hasPink)
|
||||
{
|
||||
SDL_SetColorKey(temp, SDL_SRCCOLORKEY,
|
||||
SDL_SetColorKey(temp, SDL_TRUE,
|
||||
SDL_MapRGB(temp->format,255,0,255));
|
||||
}
|
||||
if (hasAlpha)
|
||||
{
|
||||
SDL_SetAlpha(temp, SDL_SRCALPHA, 255);
|
||||
SDL_SetSurfaceAlphaMod(temp, 255);
|
||||
}
|
||||
|
||||
return temp;
|
||||
|
|
|
@ -129,15 +129,15 @@ namespace gcn
|
|||
switch (event.type)
|
||||
{
|
||||
case SDL_KEYDOWN:
|
||||
mLastKey = convertKeyCharacter(event.key.keysym);
|
||||
mIsRepeating = true;
|
||||
mLastKey = convertKeyCharacter(event.key.keysym);
|
||||
mIsRepeating = true;
|
||||
keyInput.setKey(mLastKey);
|
||||
keyInput.setType(KeyInput::PRESS);
|
||||
mKeyInputQueue.push(keyInput);
|
||||
break;
|
||||
|
||||
case SDL_KEYUP:
|
||||
mIsRepeating = false;
|
||||
mIsRepeating = false;
|
||||
keyInput.setKey(convertKeyCharacter(event.key.keysym));
|
||||
keyInput.setType(KeyInput::RELEASE);
|
||||
mKeyInputQueue.push(keyInput);
|
||||
|
@ -163,6 +163,23 @@ namespace gcn
|
|||
mMouseInputQueue.push(mouseInput);
|
||||
break;
|
||||
|
||||
case SDL_MOUSEWHEEL:
|
||||
if (event.wheel.y != 0) {
|
||||
mouseInput.x = event.wheel.x;
|
||||
mouseInput.y = event.wheel.y;
|
||||
mouseInput.setButton(event.wheel.y > 0 ? MouseInput::WHEEL_UP : MouseInput::WHEEL_DOWN);
|
||||
mouseInput.setType(MouseInput::PRESS);
|
||||
mouseInput.setTimeStamp(SDL_GetTicks());
|
||||
mMouseInputQueue.push(mouseInput);
|
||||
mouseInput.x = event.wheel.x;
|
||||
mouseInput.y = event.wheel.y;
|
||||
mouseInput.setButton(event.wheel.y > 0 ? MouseInput::WHEEL_UP : MouseInput::WHEEL_DOWN);
|
||||
mouseInput.setType(MouseInput::RELEASE);
|
||||
mouseInput.setTimeStamp(SDL_GetTicks()+1);
|
||||
mMouseInputQueue.push(mouseInput);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_MOUSEMOTION:
|
||||
mouseInput.x = event.button.x;
|
||||
mouseInput.y = event.button.y;
|
||||
|
@ -172,30 +189,31 @@ namespace gcn
|
|||
mMouseInputQueue.push(mouseInput);
|
||||
break;
|
||||
|
||||
case SDL_ACTIVEEVENT:
|
||||
case SDL_WINDOWEVENT:
|
||||
/*
|
||||
* This occurs when the mouse leaves the window and the Gui-chan
|
||||
* application loses its mousefocus.
|
||||
*/
|
||||
if ((event.active.state & SDL_APPMOUSEFOCUS)
|
||||
&& !event.active.gain)
|
||||
switch (event.window.event)
|
||||
{
|
||||
mMouseInWindow = false;
|
||||
case SDL_WINDOWEVENT_LEAVE:
|
||||
{
|
||||
mMouseInWindow = false;
|
||||
|
||||
if (!mMouseDown)
|
||||
{
|
||||
mouseInput.x = -1;
|
||||
mouseInput.y = -1;
|
||||
mouseInput.setButton(MouseInput::EMPTY);
|
||||
mouseInput.setType(MouseInput::MOTION);
|
||||
mMouseInputQueue.push(mouseInput);
|
||||
}
|
||||
}
|
||||
if (!mMouseDown)
|
||||
{
|
||||
mouseInput.x = -1;
|
||||
mouseInput.y = -1;
|
||||
mouseInput.setButton(MouseInput::EMPTY);
|
||||
mouseInput.setType(MouseInput::MOTION);
|
||||
mMouseInputQueue.push(mouseInput);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
if ((event.active.state & SDL_APPMOUSEFOCUS)
|
||||
&& event.active.gain)
|
||||
{
|
||||
mMouseInWindow = true;
|
||||
case SDL_WINDOWEVENT_ENTER:
|
||||
mMouseInWindow = true;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -215,12 +233,6 @@ namespace gcn
|
|||
case SDL_BUTTON_MIDDLE:
|
||||
return MouseInput::MIDDLE;
|
||||
break;
|
||||
case SDL_BUTTON_WHEELUP:
|
||||
return MouseInput::WHEEL_UP;
|
||||
break;
|
||||
case SDL_BUTTON_WHEELDOWN:
|
||||
return MouseInput::WHEEL_DOWN;
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
|
@ -230,23 +242,11 @@ namespace gcn
|
|||
return 0;
|
||||
}
|
||||
|
||||
Key SDLInput::convertKeyCharacter(SDL_keysym keysym)
|
||||
Key SDLInput::convertKeyCharacter(SDL_Keysym keysym)
|
||||
{
|
||||
int value = 0;
|
||||
Key key;
|
||||
|
||||
if (keysym.unicode < 255)
|
||||
{
|
||||
if (keysym.unicode == 0)
|
||||
{
|
||||
value = keysym.sym;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = (int)keysym.unicode;
|
||||
}
|
||||
}
|
||||
|
||||
switch (keysym.sym)
|
||||
{
|
||||
case SDLK_TAB:
|
||||
|
@ -297,7 +297,7 @@ namespace gcn
|
|||
case SDLK_PAGEUP:
|
||||
value = Key::K_PAGE_UP;
|
||||
break;
|
||||
case SDLK_PRINT:
|
||||
case SDLK_PRINTSCREEN:
|
||||
value = Key::K_PRINT_SCREEN;
|
||||
break;
|
||||
case SDLK_PAGEDOWN:
|
||||
|
@ -348,25 +348,27 @@ namespace gcn
|
|||
case SDLK_F15:
|
||||
value = Key::K_F15;
|
||||
break;
|
||||
case SDLK_NUMLOCK:
|
||||
case SDLK_NUMLOCKCLEAR:
|
||||
value = Key::K_NUM_LOCK;
|
||||
break;
|
||||
case SDLK_CAPSLOCK:
|
||||
value = Key::K_CAPS_LOCK;
|
||||
break;
|
||||
case SDLK_SCROLLOCK:
|
||||
case SDLK_SCROLLLOCK:
|
||||
value = Key::K_SCROLL_LOCK;
|
||||
break;
|
||||
#if 0
|
||||
case SDLK_RMETA:
|
||||
value = Key::K_RIGHT_META;
|
||||
break;
|
||||
case SDLK_LMETA:
|
||||
value = Key::K_LEFT_META;
|
||||
break;
|
||||
case SDLK_LSUPER:
|
||||
#endif
|
||||
case SDLK_LGUI:
|
||||
value = Key::K_LEFT_SUPER;
|
||||
break;
|
||||
case SDLK_RSUPER:
|
||||
case SDLK_RGUI:
|
||||
value = Key::K_RIGHT_SUPER;
|
||||
break;
|
||||
case SDLK_MODE:
|
||||
|
@ -392,6 +394,7 @@ namespace gcn
|
|||
break;
|
||||
|
||||
default:
|
||||
value = keysym.sym;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -399,34 +402,34 @@ namespace gcn
|
|||
{
|
||||
switch (keysym.sym)
|
||||
{
|
||||
case SDLK_KP0:
|
||||
case SDLK_KP_0:
|
||||
value = Key::K_INSERT;
|
||||
break;
|
||||
case SDLK_KP1:
|
||||
case SDLK_KP_1:
|
||||
value = Key::K_END;
|
||||
break;
|
||||
case SDLK_KP2:
|
||||
case SDLK_KP_2:
|
||||
value = Key::K_DOWN;
|
||||
break;
|
||||
case SDLK_KP3:
|
||||
case SDLK_KP_3:
|
||||
value = Key::K_PAGE_DOWN;
|
||||
break;
|
||||
case SDLK_KP4:
|
||||
case SDLK_KP_4:
|
||||
value = Key::K_LEFT;
|
||||
break;
|
||||
case SDLK_KP5:
|
||||
case SDLK_KP_5:
|
||||
value = 0;
|
||||
break;
|
||||
case SDLK_KP6:
|
||||
case SDLK_KP_6:
|
||||
value = Key::K_RIGHT;
|
||||
break;
|
||||
case SDLK_KP7:
|
||||
case SDLK_KP_7:
|
||||
value = Key::K_HOME;
|
||||
break;
|
||||
case SDLK_KP8:
|
||||
case SDLK_KP_8:
|
||||
value = Key::K_UP;
|
||||
break;
|
||||
case SDLK_KP9:
|
||||
case SDLK_KP_9:
|
||||
value = Key::K_PAGE_UP;
|
||||
break;
|
||||
default:
|
||||
|
@ -438,9 +441,9 @@ namespace gcn
|
|||
key.setShiftPressed((keysym.mod & KMOD_SHIFT) != 0);
|
||||
key.setControlPressed((keysym.mod & KMOD_CTRL) != 0);
|
||||
key.setAltPressed((keysym.mod & KMOD_ALT) != 0);
|
||||
key.setMetaPressed((keysym.mod & KMOD_META) != 0);
|
||||
//key.setMetaPressed((keysym.mod & KMOD_META) != 0);
|
||||
|
||||
if (keysym.sym >= SDLK_KP0 && keysym.sym <= SDLK_KP_EQUALS)
|
||||
if (keysym.sym >= SDLK_KP_0 && keysym.sym <= SDLK_KP_EQUALS)
|
||||
{
|
||||
key.setNumericPad(true);
|
||||
}
|
||||
|
|
|
@ -70,9 +70,9 @@ extern int Str2SdlKey(const char *str);
|
|||
|
||||
int convertKey(const char *key)
|
||||
{
|
||||
SDL_keysym keysym;
|
||||
SDL_Keysym keysym;
|
||||
memset(&keysym, 0, sizeof(keysym));
|
||||
keysym.sym = (SDLKey)Str2SdlKey(key);
|
||||
keysym.sym = (SDL_Keycode)Str2SdlKey(key);
|
||||
gcn::Key k = gcn::SDLInput::convertKeyCharacter(keysym);
|
||||
return k.getValue();
|
||||
}
|
||||
|
@ -411,7 +411,8 @@ namespace gcn
|
|||
if (hasMouse())
|
||||
{
|
||||
requestFocus();
|
||||
mFocusHandler->requestDrag(this);
|
||||
if (b != MouseInput::WHEEL_UP && b != MouseInput::WHEEL_DOWN)
|
||||
mFocusHandler->requestDrag(this);
|
||||
}
|
||||
|
||||
if (b != MouseInput::WHEEL_UP && b != MouseInput::WHEEL_DOWN)
|
||||
|
|
|
@ -408,6 +408,8 @@ extern unsigned long SlowFrameCounter;
|
|||
extern void SetPlayersPalette();
|
||||
|
||||
/// The SDL screen
|
||||
extern SDL_Window *TheWindow;
|
||||
extern SDL_Renderer *TheRenderer;
|
||||
extern SDL_Surface *TheScreen;
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
|
|
|
@ -682,24 +682,22 @@ void CMap::InitFogOfWar()
|
|||
//
|
||||
// Generate Only Fog surface.
|
||||
//
|
||||
s = SDL_CreateRGBSurface(SDL_SWSURFACE, PixelTileSize.x, PixelTileSize.y,
|
||||
OnlyFogSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, PixelTileSize.x, PixelTileSize.y,
|
||||
32, RMASK, GMASK, BMASK, AMASK);
|
||||
|
||||
SDL_GetRGB(FogOfWarColorSDL, TheScreen->format, &r, &g, &b);
|
||||
Uint32 color = Video.MapRGB(s->format, r, g, b);
|
||||
Uint32 color = Video.MapRGBA(OnlyFogSurface->format, r, g, b, FogOfWarOpacity);
|
||||
|
||||
SDL_FillRect(s, NULL, color);
|
||||
OnlyFogSurface = SDL_DisplayFormat(s);
|
||||
SDL_SetAlpha(OnlyFogSurface, SDL_SRCALPHA | SDL_RLEACCEL, FogOfWarOpacity);
|
||||
VideoPaletteListRemove(s);
|
||||
SDL_FreeSurface(s);
|
||||
SDL_FillRect(OnlyFogSurface, NULL, color);
|
||||
//SDL_SetSurfaceAlphaMod(OnlyFogSurface, FogOfWarOpacity);
|
||||
//VideoPaletteListRemove(OnlyFogSurface);
|
||||
|
||||
//
|
||||
// Generate Alpha Fog surface.
|
||||
//
|
||||
if (FogGraphic->Surface->format->BytesPerPixel == 1) {
|
||||
s = SDL_DisplayFormat(FogGraphic->Surface);
|
||||
SDL_SetAlpha(s, SDL_SRCALPHA | SDL_RLEACCEL, FogOfWarOpacity);
|
||||
s = FogGraphic->Surface;
|
||||
SDL_SetSurfaceAlphaMod(FogGraphic->Surface, FogOfWarOpacity);
|
||||
} else {
|
||||
// Copy the top row to a new surface
|
||||
SDL_PixelFormat *f = FogGraphic->Surface->format;
|
||||
|
|
|
@ -238,7 +238,7 @@ void CMinimap::UpdateTerrain()
|
|||
#endif
|
||||
{
|
||||
if (bpp == 1) {
|
||||
SDL_SetPalette(MinimapTerrainSurface, SDL_LOGPAL,
|
||||
SDL_SetPaletteColors(MinimapTerrainSurface->format->palette,
|
||||
Map.TileGraphic->Surface->format->palette->colors, 0, 256);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1209,9 +1209,9 @@ void GraphicPlayerPixels(CPlayer &player, const CGraphic &sprite)
|
|||
|
||||
SDL_LockSurface(sprite.Surface);
|
||||
std::vector<SDL_Color> sdlColors(player.UnitColors.Colors.begin(), player.UnitColors.Colors.end());
|
||||
SDL_SetColors(sprite.Surface, &sdlColors[0], PlayerColorIndexStart, PlayerColorIndexCount);
|
||||
SDL_SetPaletteColors(sprite.Surface->format->palette, &sdlColors[0], PlayerColorIndexStart, PlayerColorIndexCount);
|
||||
if (sprite.SurfaceFlip) {
|
||||
SDL_SetColors(sprite.SurfaceFlip, &sdlColors[0], PlayerColorIndexStart, PlayerColorIndexCount);
|
||||
SDL_SetPaletteColors(sprite.SurfaceFlip->format->palette, &sdlColors[0], PlayerColorIndexStart, PlayerColorIndexCount);
|
||||
}
|
||||
SDL_UnlockSurface(sprite.Surface);
|
||||
}
|
||||
|
|
|
@ -1407,9 +1407,9 @@ void CButtonPanel::DoClicked(int button)
|
|||
*/
|
||||
int CButtonPanel::DoKey(int key)
|
||||
{
|
||||
SDL_keysym keysym;
|
||||
SDL_Keysym keysym;
|
||||
memset(&keysym, 0, sizeof(keysym));
|
||||
keysym.sym = (SDLKey)key;
|
||||
keysym.sym = (SDL_Keycode)key;
|
||||
gcn::Key k = gcn::SDLInput::convertKeyCharacter(keysym);
|
||||
key = k.getValue();
|
||||
|
||||
|
|
|
@ -714,19 +714,19 @@ static bool CommandKey(int key)
|
|||
break;
|
||||
|
||||
case SDLK_UP:
|
||||
case SDLK_KP8:
|
||||
case SDLK_KP_8:
|
||||
KeyScrollState |= ScrollUp;
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
case SDLK_KP2:
|
||||
case SDLK_KP_2:
|
||||
KeyScrollState |= ScrollDown;
|
||||
break;
|
||||
case SDLK_LEFT:
|
||||
case SDLK_KP4:
|
||||
case SDLK_KP_4:
|
||||
KeyScrollState |= ScrollLeft;
|
||||
break;
|
||||
case SDLK_RIGHT:
|
||||
case SDLK_KP6:
|
||||
case SDLK_KP_6:
|
||||
KeyScrollState |= ScrollRight;
|
||||
break;
|
||||
|
||||
|
@ -979,20 +979,20 @@ int HandleKeyModifiersDown(unsigned key, unsigned)
|
|||
return 1;
|
||||
case SDLK_LALT:
|
||||
case SDLK_RALT:
|
||||
case SDLK_LMETA:
|
||||
case SDLK_RMETA:
|
||||
//case SDLK_LMETA:
|
||||
//case SDLK_RMETA:
|
||||
KeyModifiers |= ModifierAlt;
|
||||
// maxy: disabled
|
||||
if (InterfaceState == IfaceStateNormal) {
|
||||
SelectedUnitChanged(); // VLADI: to allow alt-buttons
|
||||
}
|
||||
return 1;
|
||||
case SDLK_LSUPER:
|
||||
case SDLK_RSUPER:
|
||||
case SDLK_LGUI:
|
||||
case SDLK_RGUI:
|
||||
KeyModifiers |= ModifierSuper;
|
||||
return 1;
|
||||
case SDLK_SYSREQ:
|
||||
case SDLK_PRINT:
|
||||
case SDLK_PRINTSCREEN:
|
||||
Screenshot();
|
||||
if (GameRunning) {
|
||||
SetMessage("%s", _("Screenshot made."));
|
||||
|
@ -1025,16 +1025,16 @@ int HandleKeyModifiersUp(unsigned key, unsigned)
|
|||
return 1;
|
||||
case SDLK_LALT:
|
||||
case SDLK_RALT:
|
||||
case SDLK_LMETA:
|
||||
case SDLK_RMETA:
|
||||
//case SDLK_LMETA:
|
||||
//case SDLK_RMETA:
|
||||
KeyModifiers &= ~ModifierAlt;
|
||||
// maxy: disabled
|
||||
if (InterfaceState == IfaceStateNormal) {
|
||||
SelectedUnitChanged(); // VLADI: to allow alt-buttons
|
||||
}
|
||||
return 1;
|
||||
case SDLK_LSUPER:
|
||||
case SDLK_RSUPER:
|
||||
case SDLK_LGUI:
|
||||
case SDLK_RGUI:
|
||||
KeyModifiers &= ~ModifierSuper;
|
||||
return 1;
|
||||
}
|
||||
|
@ -1046,8 +1046,8 @@ int HandleKeyModifiersUp(unsigned key, unsigned)
|
|||
*/
|
||||
static bool IsKeyPad(unsigned key, unsigned *kp)
|
||||
{
|
||||
if (key >= SDLK_KP0 && key <= SDLK_KP9) {
|
||||
*kp = SDLK_0 + (key - SDLK_KP0);
|
||||
if (key >= SDLK_KP_0 && key <= SDLK_KP_9) {
|
||||
*kp = SDLK_0 + (key - SDLK_KP_0);
|
||||
} else if (key == SDLK_KP_PERIOD) {
|
||||
*kp = SDLK_PERIOD;
|
||||
} else if (key == SDLK_KP_DIVIDE) {
|
||||
|
@ -1114,19 +1114,19 @@ void HandleKeyUp(unsigned key, unsigned keychar)
|
|||
|
||||
switch (key) {
|
||||
case SDLK_UP:
|
||||
case SDLK_KP8:
|
||||
case SDLK_KP_8:
|
||||
KeyScrollState &= ~ScrollUp;
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
case SDLK_KP2:
|
||||
case SDLK_KP_2:
|
||||
KeyScrollState &= ~ScrollDown;
|
||||
break;
|
||||
case SDLK_LEFT:
|
||||
case SDLK_KP4:
|
||||
case SDLK_KP_4:
|
||||
KeyScrollState &= ~ScrollLeft;
|
||||
break;
|
||||
case SDLK_RIGHT:
|
||||
case SDLK_KP6:
|
||||
case SDLK_KP_6:
|
||||
KeyScrollState &= ~ScrollRight;
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -147,7 +147,7 @@ static void VideoDrawChar(const CGraphic &g,
|
|||
SDL_Rect srect = {Sint16(gx), Sint16(gy), Uint16(w), Uint16(h)};
|
||||
SDL_Rect drect = {Sint16(x), Sint16(y), 0, 0};
|
||||
std::vector<SDL_Color> sdlColors(fc.Colors, fc.Colors + MaxFontColors);
|
||||
SDL_SetColors(g.Surface, &sdlColors[0], 0, MaxFontColors);
|
||||
SDL_SetPaletteColors(g.Surface->format->palette, &sdlColors[0], 0, MaxFontColors);
|
||||
SDL_BlitSurface(g.Surface, &srect, TheScreen, &drect);
|
||||
}
|
||||
}
|
||||
|
@ -795,10 +795,11 @@ void CFont::MeasureWidths()
|
|||
CharWidth = new char[maxy];
|
||||
memset(CharWidth, 0, maxy);
|
||||
CharWidth[0] = G->Width / 2; // a reasonable value for SPACE
|
||||
const Uint32 ckey = G->Surface->format->colorkey;
|
||||
Uint32 ckey = 0;
|
||||
const int ipr = G->Surface->w / G->Width; // images per row
|
||||
|
||||
SDL_LockSurface(G->Surface);
|
||||
SDL_GetColorKey(G->Surface, &ckey);
|
||||
for (int y = 1; y < maxy; ++y) {
|
||||
const unsigned char *sp = (const unsigned char *)G->Surface->pixels +
|
||||
(y / ipr) * G->Surface->pitch * G->Height +
|
||||
|
|
|
@ -140,10 +140,11 @@ void CGraphic::DrawSubTrans(int gx, int gy, int w, int h, int x, int y,
|
|||
} else
|
||||
#endif
|
||||
{
|
||||
int oldalpha = Surface->format->alpha;
|
||||
SDL_SetAlpha(Surface, SDL_SRCALPHA, alpha);
|
||||
Uint8 oldalpha;
|
||||
SDL_GetSurfaceAlphaMod(Surface, &oldalpha);
|
||||
SDL_SetSurfaceAlphaMod(Surface, alpha);
|
||||
DrawSub(gx, gy, w, h, x, y);
|
||||
SDL_SetAlpha(Surface, SDL_SRCALPHA, oldalpha);
|
||||
SDL_SetSurfaceAlphaMod(Surface, oldalpha);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -376,11 +377,12 @@ void CGraphic::DrawFrameTransX(unsigned frame, int x, int y, int alpha) const
|
|||
{
|
||||
SDL_Rect srect = {frameFlip_map[frame].x, frameFlip_map[frame].y, Uint16(Width), Uint16(Height)};
|
||||
SDL_Rect drect = {Sint16(x), Sint16(y), 0, 0};
|
||||
const int oldalpha = Surface->format->alpha;
|
||||
Uint8 oldalpha;
|
||||
SDL_GetSurfaceAlphaMod(Surface, &oldalpha);
|
||||
|
||||
SDL_SetAlpha(Surface, SDL_SRCALPHA, alpha);
|
||||
SDL_SetSurfaceAlphaMod(Surface, alpha);
|
||||
SDL_BlitSurface(SurfaceFlip, &srect, TheScreen, &drect);
|
||||
SDL_SetAlpha(Surface, SDL_SRCALPHA, oldalpha);
|
||||
SDL_SetSurfaceAlphaMod(Surface, oldalpha);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -404,11 +406,12 @@ void CGraphic::DrawFrameClipTransX(unsigned frame, int x, int y, int alpha) cons
|
|||
srect.y += y - oldy;
|
||||
|
||||
SDL_Rect drect = {Sint16(x), Sint16(y), 0, 0};
|
||||
const int oldalpha = SurfaceFlip->format->alpha;
|
||||
Uint8 oldalpha;
|
||||
SDL_GetSurfaceAlphaMod(SurfaceFlip, &oldalpha);
|
||||
|
||||
SDL_SetAlpha(SurfaceFlip, SDL_SRCALPHA, alpha);
|
||||
SDL_SetSurfaceAlphaMod(SurfaceFlip, alpha);
|
||||
SDL_BlitSurface(SurfaceFlip, &srect, TheScreen, &drect);
|
||||
SDL_SetAlpha(SurfaceFlip, SDL_SRCALPHA, oldalpha);
|
||||
SDL_SetSurfaceAlphaMod(SurfaceFlip, oldalpha);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -676,7 +679,7 @@ static void ApplyGrayScale(SDL_Surface *Surface, int Width, int Height)
|
|||
const int gray = redGray * pal.colors[i].r + greenGray * pal.colors[i].g + blueGray * pal.colors[i].b;
|
||||
colors[i].r = colors[i].g = colors[i].b = gray;
|
||||
}
|
||||
SDL_SetColors(Surface, &colors[0], 0, 256);
|
||||
SDL_SetPaletteColors(&pal, &colors[0], 0, 256);
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
|
@ -893,14 +896,16 @@ void CGraphic::Flip()
|
|||
}
|
||||
|
||||
SDL_Surface *s = SurfaceFlip = SDL_ConvertSurface(Surface, Surface->format, SDL_SWSURFACE);
|
||||
if (Surface->flags & SDL_SRCCOLORKEY) {
|
||||
SDL_SetColorKey(SurfaceFlip, SDL_SRCCOLORKEY | SDL_RLEACCEL, Surface->format->colorkey);
|
||||
Uint32 ckey;
|
||||
if (!SDL_GetColorKey(Surface, &ckey)) {
|
||||
SDL_SetColorKey(SurfaceFlip, SDL_TRUE, ckey);
|
||||
}
|
||||
if (SurfaceFlip->format->BytesPerPixel == 1) {
|
||||
VideoPaletteListAdd(SurfaceFlip);
|
||||
}
|
||||
SDL_LockSurface(Surface);
|
||||
SDL_LockSurface(s);
|
||||
//fprintf(stderr, "flipping sprite %s (%dbpp)\n", File.c_str(), 8*s->format->BytesPerPixel);
|
||||
switch (s->format->BytesPerPixel) {
|
||||
case 1:
|
||||
for (int i = 0; i < s->h; ++i) {
|
||||
|
@ -919,6 +924,13 @@ void CGraphic::Flip()
|
|||
}
|
||||
break;
|
||||
case 4: {
|
||||
for (int i = 0; i < s->h; ++i) {
|
||||
for (int j = 0; j < s->w; ++j) {
|
||||
memcpy(&((char *)s->pixels)[j + i * s->pitch],
|
||||
&((char *)Surface->pixels)[(s->w - j - 1) * 4 + i * Surface->pitch], 4);
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
unsigned int p0 = s->pitch;
|
||||
unsigned int p1 = Surface->pitch;
|
||||
const int width = s->w;
|
||||
|
@ -970,6 +982,7 @@ void CGraphic::Flip()
|
|||
p0 += s->pitch;
|
||||
p1 += Surface->pitch;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -996,6 +1009,7 @@ void CGraphic::UseDisplayFormat()
|
|||
if (UseOpenGL) { return; }
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
SDL_Surface *s = Surface;
|
||||
|
||||
if (s->format->Amask != 0) {
|
||||
|
@ -1016,6 +1030,12 @@ void CGraphic::UseDisplayFormat()
|
|||
VideoPaletteListRemove(s);
|
||||
SDL_FreeSurface(s);
|
||||
}
|
||||
VideoPaletteListRemove(Surface);
|
||||
if (SurfaceFlip) {
|
||||
VideoPaletteListRemove(SurfaceFlip);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
|
@ -1042,10 +1062,10 @@ static int PowerOf2(int x)
|
|||
static void MakeTextures2(CGraphic *g, GLuint texture, CUnitColors *colors,
|
||||
int ow, int oh)
|
||||
{
|
||||
int useckey = g->Surface->flags & SDL_SRCCOLORKEY;
|
||||
Uint32 ckey;
|
||||
int useckey = !SDL_GetColorKey(g->Surface, &ckey);
|
||||
SDL_PixelFormat *f = g->Surface->format;
|
||||
int bpp = f->BytesPerPixel;
|
||||
Uint32 ckey = f->colorkey;
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
int maxw = std::min<int>(g->GraphicWidth - ow, GLMaxTextureSize);
|
||||
|
@ -1055,9 +1075,7 @@ static void MakeTextures2(CGraphic *g, GLuint texture, CUnitColors *colors,
|
|||
unsigned char *tex = new unsigned char[w * h * 4];
|
||||
memset(tex, 0, w * h * 4);
|
||||
unsigned char alpha;
|
||||
if (g->Surface->flags & SDL_SRCALPHA) {
|
||||
alpha = f->alpha;
|
||||
} else {
|
||||
if (!!SDL_GetSurfaceAlphaMod(g->Surface, &alpha) {
|
||||
alpha = 0xff;
|
||||
}
|
||||
|
||||
|
@ -1251,8 +1269,8 @@ void CGraphic::Resize(int w, int h)
|
|||
}
|
||||
|
||||
Resized = true;
|
||||
Uint32 ckey = Surface->format->colorkey;
|
||||
int useckey = Surface->flags & SDL_SRCCOLORKEY;
|
||||
Uint32 ckey;
|
||||
bool useckey = !SDL_GetColorKey(Surface, &ckey);
|
||||
|
||||
int bpp = Surface->format->BytesPerPixel;
|
||||
if (bpp == 1) {
|
||||
|
@ -1281,7 +1299,7 @@ void CGraphic::Resize(int w, int h)
|
|||
if (Surface->format->BytesPerPixel == 1) {
|
||||
VideoPaletteListAdd(Surface);
|
||||
}
|
||||
SDL_SetPalette(Surface, SDL_LOGPAL | SDL_PHYSPAL, pal, 0, 256);
|
||||
SDL_SetPaletteColors(Surface->format->palette, pal, 0, 256);
|
||||
} else {
|
||||
SDL_LockSurface(Surface);
|
||||
|
||||
|
@ -1345,7 +1363,7 @@ void CGraphic::Resize(int w, int h)
|
|||
Rmask, Gmask, Bmask, Amask);
|
||||
}
|
||||
if (useckey) {
|
||||
SDL_SetColorKey(Surface, SDL_SRCCOLORKEY | SDL_RLEACCEL, ckey);
|
||||
SDL_SetColorKey(Surface, SDL_TRUE, ckey);
|
||||
}
|
||||
Width = GraphicWidth = w;
|
||||
Height = GraphicHeight = h;
|
||||
|
@ -1418,7 +1436,9 @@ void CGraphic::SetOriginalSize()
|
|||
bool CGraphic::TransparentPixel(int x, int y)
|
||||
{
|
||||
int bpp = Surface->format->BytesPerPixel;
|
||||
if ((bpp == 1 && !(Surface->flags & SDL_SRCCOLORKEY)) || bpp == 3) {
|
||||
Uint32 colorkey;
|
||||
bool has_colorkey = !SDL_GetColorKey(Surface, &colorkey);
|
||||
if ((bpp == 1 && !has_colorkey) || bpp == 3) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1426,12 +1446,12 @@ bool CGraphic::TransparentPixel(int x, int y)
|
|||
SDL_LockSurface(Surface);
|
||||
unsigned char *p = (unsigned char *)Surface->pixels + y * Surface->pitch + x * bpp;
|
||||
if (bpp == 1) {
|
||||
if (*p == Surface->format->colorkey) {
|
||||
if (*p == colorkey) {
|
||||
ret = true;
|
||||
}
|
||||
} else {
|
||||
bool ckey = (Surface->flags & SDL_SRCCOLORKEY) > 0;
|
||||
if (ckey && *p == Surface->format->colorkey) {
|
||||
bool ckey = has_colorkey;
|
||||
if (ckey && *p == colorkey) {
|
||||
ret = true;
|
||||
} else if (p[Surface->format->Ashift >> 3] == 255) {
|
||||
ret = true;
|
||||
|
@ -1454,8 +1474,8 @@ void CGraphic::MakeShadow()
|
|||
// Set all colors in the palette to black and use 50% alpha
|
||||
memset(colors, 0, sizeof(colors));
|
||||
|
||||
SDL_SetPalette(Surface, SDL_LOGPAL | SDL_PHYSPAL, colors, 0, 256);
|
||||
SDL_SetAlpha(Surface, SDL_SRCALPHA | SDL_RLEACCEL, 128);
|
||||
SDL_SetPaletteColors(Surface->format->palette, colors, 0, 256);
|
||||
SDL_SetSurfaceAlphaMod(Surface, 128);
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
|
@ -1469,8 +1489,8 @@ void CGraphic::MakeShadow()
|
|||
#endif
|
||||
{
|
||||
if (SurfaceFlip) {
|
||||
SDL_SetPalette(SurfaceFlip, SDL_LOGPAL | SDL_PHYSPAL, colors, 0, 256);
|
||||
SDL_SetAlpha(SurfaceFlip, SDL_SRCALPHA | SDL_RLEACCEL, 128);
|
||||
SDL_SetPaletteColors(SurfaceFlip->format->palette, colors, 0, 256);
|
||||
SDL_SetSurfaceAlphaMod(SurfaceFlip, 128);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1500,6 +1520,7 @@ void CFiller::bits_map::Init(CGraphic *g)
|
|||
{
|
||||
SDL_Surface *s = g->Surface;
|
||||
int bpp = s->format->BytesPerPixel;
|
||||
unsigned int ckey;
|
||||
|
||||
if (bstore) {
|
||||
free(bstore);
|
||||
|
@ -1508,7 +1529,7 @@ void CFiller::bits_map::Init(CGraphic *g)
|
|||
Height = 0;
|
||||
}
|
||||
|
||||
if ((bpp == 1 && !(s->flags & SDL_SRCCOLORKEY)) || bpp == 3) {
|
||||
if ((bpp == 1 && SDL_GetColorKey(s, &ckey) != 0) || bpp == 3) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1524,7 +1545,6 @@ void CFiller::bits_map::Init(CGraphic *g)
|
|||
|
||||
switch (s->format->BytesPerPixel) {
|
||||
case 1: {
|
||||
int ckey = s->format->colorkey;
|
||||
unsigned char *ptr = (unsigned char *)s->pixels;
|
||||
|
||||
for (int i = 0; i < Height; ++i) {
|
||||
|
@ -1546,8 +1566,8 @@ void CFiller::bits_map::Init(CGraphic *g)
|
|||
case 3:
|
||||
break;
|
||||
case 4:
|
||||
if ((s->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
|
||||
unsigned int ckey = s->format->colorkey;
|
||||
{
|
||||
if (!SDL_GetColorKey(s, &ckey)) {
|
||||
unsigned int *ptr = (unsigned int *)s->pixels;
|
||||
|
||||
for (int i = 0; i < Height; ++i) {
|
||||
|
@ -1581,6 +1601,7 @@ void CFiller::bits_map::Init(CGraphic *g)
|
|||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -101,12 +101,13 @@ static void MovieCallbackMouseExit()
|
|||
/**
|
||||
** Draw Ogg data to the overlay
|
||||
*/
|
||||
static int OutputTheora(OggData *data, SDL_Overlay *yuv_overlay, SDL_Rect *rect)
|
||||
static int OutputTheora(OggData *data, SDL_Texture *yuv_overlay, SDL_Rect *rect)
|
||||
{
|
||||
yuv_buffer yuv;
|
||||
|
||||
theora_decode_YUVout(&data->tstate, &yuv);
|
||||
|
||||
#if 0
|
||||
if (SDL_MUSTLOCK(TheScreen)) {
|
||||
if (SDL_LockSurface(TheScreen) < 0) {
|
||||
return - 1;
|
||||
|
@ -136,8 +137,11 @@ static int OutputTheora(OggData *data, SDL_Overlay *yuv_overlay, SDL_Rect *rect)
|
|||
SDL_UnlockSurface(TheScreen);
|
||||
}
|
||||
SDL_UnlockYUVOverlay(yuv_overlay);
|
||||
#endif
|
||||
|
||||
SDL_DisplayYUVOverlay(yuv_overlay, rect);
|
||||
SDL_UpdateYUVTexture(yuv_overlay, NULL, yuv.y, yuv.y_stride, yuv.u, yuv.uv_stride, yuv.v, yuv.uv_stride);
|
||||
SDL_RenderCopy(TheRenderer, yuv_overlay, NULL, NULL);
|
||||
SDL_RenderPresent(TheRenderer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -217,16 +221,21 @@ int PlayMovie(const std::string &name)
|
|||
// When SDL_OPENGL is used, it is not possible to call SDL_CreateYUVOverlay, so turn temporary OpenGL off
|
||||
// With GLES is all ok
|
||||
if (UseOpenGL) {
|
||||
SDL_SetVideoMode(Video.ViewportWidth, Video.ViewportHeight, Video.Depth, SDL_GetVideoSurface()->flags & ~SDL_OPENGL);
|
||||
//SDL_SetVideoMode(Video.ViewportWidth, Video.ViewportHeight, Video.Depth, SDL_GetVideoSurface()->flags & ~SDL_OPENGL);
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_FillRect(SDL_GetVideoSurface(), NULL, 0);
|
||||
SDL_RenderClear(TheRenderer);
|
||||
Video.ClearScreen();
|
||||
SDL_Overlay *yuv_overlay = SDL_CreateYUVOverlay(data.tinfo.frame_width, data.tinfo.frame_height, SDL_YV12_OVERLAY, TheScreen);
|
||||
SDL_Texture *yuv_overlay = SDL_CreateTexture(TheRenderer,
|
||||
SDL_PIXELFORMAT_YV12,
|
||||
SDL_TEXTUREACCESS_STREAMING,
|
||||
data.tinfo.frame_width,
|
||||
data.tinfo.frame_height);
|
||||
|
||||
if (yuv_overlay == NULL) {
|
||||
fprintf(stderr, "SDL_CreateYUVOverlay: %s\n", SDL_GetError());
|
||||
fprintf(stderr, "SDL_CreateYUVOverlay: %dx%d\n", data.tinfo.frame_width, data.tinfo.frame_height);
|
||||
OggFree(&data);
|
||||
f.close();
|
||||
return 0;
|
||||
|
@ -238,7 +247,7 @@ int PlayMovie(const std::string &name)
|
|||
if ((sample->Channels != 1 && sample->Channels != 2) || sample->SampleSize != 16) {
|
||||
fprintf(stderr, "Unsupported sound format in movie\n");
|
||||
delete sample;
|
||||
SDL_FreeYUVOverlay(yuv_overlay);
|
||||
SDL_DestroyTexture(yuv_overlay);
|
||||
OggFree(&data);
|
||||
f.close();
|
||||
return 0;
|
||||
|
@ -291,14 +300,14 @@ int PlayMovie(const std::string &name)
|
|||
}
|
||||
|
||||
StopMusic();
|
||||
SDL_FreeYUVOverlay(yuv_overlay);
|
||||
SDL_DestroyTexture(yuv_overlay);
|
||||
|
||||
OggFree(&data);
|
||||
f.close();
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
if (UseOpenGL) {
|
||||
SDL_SetVideoMode(Video.ViewportWidth, Video.ViewportHeight, Video.Depth, SDL_GetVideoSurface()->flags | SDL_OPENGL);
|
||||
//SDL_SetVideoMode(Video.ViewportWidth, Video.ViewportHeight, Video.Depth, SDL_GetVideoSurface()->flags | SDL_OPENGL);
|
||||
ReloadOpenGL();
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -221,7 +221,7 @@ int LoadGraphicPNG(CGraphic *g)
|
|||
}
|
||||
}
|
||||
SDL_Surface *surface =
|
||||
SDL_AllocSurface(SDL_SWSURFACE, width, height,
|
||||
SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
|
||||
bit_depth * png_get_channels(png_ptr, info_ptr), Rmask, Gmask, Bmask, Amask);
|
||||
if (surface == NULL) {
|
||||
fprintf(stderr, "Out of memory");
|
||||
|
@ -233,7 +233,7 @@ int LoadGraphicPNG(CGraphic *g)
|
|||
/* FIXME: Should these be truncated or shifted down? */
|
||||
ckey = SDL_MapRGB(surface->format, (Uint8)transv->red, (Uint8)transv->green, (Uint8)transv->blue);
|
||||
}
|
||||
SDL_SetColorKey(surface, SDL_SRCCOLORKEY, ckey);
|
||||
SDL_SetColorKey(surface, SDL_TRUE, ckey);
|
||||
}
|
||||
|
||||
/* Create the array of pointers to image data */
|
||||
|
@ -259,6 +259,7 @@ int LoadGraphicPNG(CGraphic *g)
|
|||
palette->colors[i].r = i;
|
||||
palette->colors[i].g = i;
|
||||
palette->colors[i].b = i;
|
||||
palette->colors[i].a = 0xff;
|
||||
}
|
||||
} else {
|
||||
png_colorp pngpalette;
|
||||
|
@ -270,6 +271,7 @@ int LoadGraphicPNG(CGraphic *g)
|
|||
palette->colors[i].b = pngpalette[i].blue;
|
||||
palette->colors[i].g = pngpalette[i].green;
|
||||
palette->colors[i].r = pngpalette[i].red;
|
||||
palette->colors[i].a = 0xff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,6 +105,9 @@ static EGLDisplay eglDisplay;
|
|||
static EGLSurface eglSurface;
|
||||
#endif
|
||||
|
||||
SDL_Window *TheWindow; /// Internal screen
|
||||
SDL_Renderer *TheRenderer = NULL; /// Internal screen
|
||||
SDL_Texture *TheTexture; /// Internal screen
|
||||
SDL_Surface *TheScreen; /// Internal screen
|
||||
|
||||
static SDL_Rect Rects[100];
|
||||
|
@ -416,8 +419,8 @@ static void InitKey2Str()
|
|||
|
||||
Key2Str[SDLK_DELETE] = "delete";
|
||||
|
||||
for (i = SDLK_KP0; i <= SDLK_KP9; ++i) {
|
||||
snprintf(str, sizeof(str), "kp_%d", i - SDLK_KP0);
|
||||
for (i = SDLK_KP_0; i <= SDLK_KP_9; ++i) {
|
||||
snprintf(str, sizeof(str), "kp_%d", i - SDLK_KP_0);
|
||||
Key2Str[i] = str;
|
||||
}
|
||||
|
||||
|
@ -446,12 +449,12 @@ static void InitKey2Str()
|
|||
}
|
||||
|
||||
Key2Str[SDLK_HELP] = "help";
|
||||
Key2Str[SDLK_PRINT] = "print";
|
||||
Key2Str[SDLK_PRINTSCREEN] = "print";
|
||||
Key2Str[SDLK_SYSREQ] = "sysreq";
|
||||
Key2Str[SDLK_BREAK] = "break";
|
||||
Key2Str[SDLK_PAUSE] = "break";
|
||||
Key2Str[SDLK_MENU] = "menu";
|
||||
Key2Str[SDLK_POWER] = "power";
|
||||
Key2Str[SDLK_EURO] = "euro";
|
||||
//Key2Str[SDLK_EURO] = "euro";
|
||||
Key2Str[SDLK_UNDO] = "undo";
|
||||
}
|
||||
|
||||
|
@ -465,12 +468,9 @@ void InitVideoSdl()
|
|||
if (SDL_WasInit(SDL_INIT_VIDEO) == 0) {
|
||||
#ifndef USE_WIN32
|
||||
// Fix tablet input in full-screen mode
|
||||
SDL_putenv(strdup("SDL_MOUSE_RELATIVE=0"));
|
||||
SDL_setenv("SDL_MOUSE_RELATIVE", "0", 1);
|
||||
#endif
|
||||
int res = SDL_Init(
|
||||
#ifdef DEBUG
|
||||
SDL_INIT_NOPARACHUTE |
|
||||
#endif
|
||||
SDL_INIT_AUDIO | SDL_INIT_VIDEO |
|
||||
SDL_INIT_TIMER);
|
||||
if (res < 0) {
|
||||
|
@ -487,16 +487,97 @@ void InitVideoSdl()
|
|||
signal(SIGSEGV, CleanExit);
|
||||
signal(SIGABRT, CleanExit);
|
||||
#endif
|
||||
// Set WindowManager Title
|
||||
if (!FullGameName.empty()) {
|
||||
SDL_WM_SetCaption(FullGameName.c_str(), FullGameName.c_str());
|
||||
} else if (!Parameters::Instance.applicationName.empty()) {
|
||||
SDL_WM_SetCaption(Parameters::Instance.applicationName.c_str(), Parameters::Instance.applicationName.c_str());
|
||||
} else {
|
||||
SDL_WM_SetCaption("Stratagus", "Stratagus");
|
||||
#ifdef USE_WIN32
|
||||
HWND hwnd = NULL;
|
||||
HICON hicon = NULL;
|
||||
SDL_SysWMinfo info;
|
||||
SDL_VERSION(&info.version);
|
||||
|
||||
if (SDL_GetWMInfo(&info)) {
|
||||
hwnd = info.window;
|
||||
}
|
||||
|
||||
#if ! defined(USE_WIN32)
|
||||
if (hwnd) {
|
||||
hicon = ExtractIcon(GetModuleHandle(NULL), Parameters::Instance.applicationName.c_str(), 0);
|
||||
}
|
||||
|
||||
if (hicon) {
|
||||
SendMessage(hwnd, (UINT)WM_SETICON, ICON_SMALL, (LPARAM)hicon);
|
||||
SendMessage(hwnd, (UINT)WM_SETICON, ICON_BIG, (LPARAM)hicon);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Initialize the display
|
||||
|
||||
#if !defined(USE_OPENGL) && !defined(USE_GLES)
|
||||
flags = 0;
|
||||
#endif
|
||||
|
||||
// Sam said: better for windows.
|
||||
/* SDL_HWSURFACE|SDL_HWPALETTE | */
|
||||
if (Video.FullScreen) {
|
||||
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
}
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
#ifdef USE_GLES_NATIVE
|
||||
flags |= SDL_OPENGLES;
|
||||
#endif
|
||||
#ifdef USE_OPENGL
|
||||
flags |= SDL_OPENGL | SDL_GL_DOUBLEBUFFER;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!Video.Width || !Video.Height) {
|
||||
Video.Width = 640;
|
||||
Video.Height = 480;
|
||||
}
|
||||
|
||||
if (!Video.Depth) {
|
||||
Video.Depth = 32;
|
||||
}
|
||||
|
||||
const char *win_title = "Stratagus";
|
||||
// Set WindowManager Title
|
||||
if (!FullGameName.empty()) {
|
||||
win_title = FullGameName.c_str();
|
||||
} else if (!Parameters::Instance.applicationName.empty()) {
|
||||
win_title = Parameters::Instance.applicationName.c_str();
|
||||
}
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (!Video.ViewportWidth || !Video.ViewportHeight) {
|
||||
Video.ViewportWidth = Video.Width;
|
||||
Video.ViewportHeight = Video.Height;
|
||||
}
|
||||
TheWindow = SDL_CreateWindow(win_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||
Video.ViewportWidth, Video.ViewportHeight, flags);
|
||||
#else
|
||||
TheWindow = SDL_CreateWindow(win_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||
Video.Width, Video.Height, flags);
|
||||
#endif
|
||||
if (TheWindow == NULL) {
|
||||
fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n",
|
||||
Video.Width, Video.Height, Video.Depth, SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
if (!TheRenderer) TheRenderer = SDL_CreateRenderer(TheWindow, -1, 0);
|
||||
SDL_RenderSetLogicalSize(TheRenderer, 640, 480);
|
||||
SDL_SetRenderDrawColor(TheRenderer, 0, 0, 0, 255);
|
||||
TheScreen = SDL_CreateRGBSurface(0, Video.Width, Video.Height, 32,
|
||||
0x00FF0000,
|
||||
0x0000FF00,
|
||||
0x000000FF,
|
||||
0xFF000000);
|
||||
TheTexture = SDL_CreateTexture(TheRenderer,
|
||||
SDL_PIXELFORMAT_ARGB8888,
|
||||
SDL_TEXTUREACCESS_STREAMING,
|
||||
Video.Width, Video.Height);
|
||||
|
||||
#if ! defined(USE_WIN32) && ! defined(USE_MAEMO)
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
// Make sure, that we not create OpenGL textures (and do not call OpenGL functions), when creating icon surface
|
||||
|
@ -544,7 +625,7 @@ void InitVideoSdl()
|
|||
}
|
||||
|
||||
if (icon) {
|
||||
SDL_WM_SetIcon(icon, 0);
|
||||
SDL_SetWindowIcon(TheWindow, icon);
|
||||
}
|
||||
|
||||
if (g) {
|
||||
|
@ -556,84 +637,7 @@ void InitVideoSdl()
|
|||
#endif
|
||||
|
||||
#endif
|
||||
#ifdef USE_WIN32
|
||||
HWND hwnd = NULL;
|
||||
HICON hicon = NULL;
|
||||
SDL_SysWMinfo info;
|
||||
SDL_VERSION(&info.version);
|
||||
|
||||
if (SDL_GetWMInfo(&info)) {
|
||||
hwnd = info.window;
|
||||
}
|
||||
|
||||
if (hwnd) {
|
||||
hicon = ExtractIcon(GetModuleHandle(NULL), Parameters::Instance.applicationName.c_str(), 0);
|
||||
}
|
||||
|
||||
if (hicon) {
|
||||
SendMessage(hwnd, (UINT)WM_SETICON, ICON_SMALL, (LPARAM)hicon);
|
||||
SendMessage(hwnd, (UINT)WM_SETICON, ICON_BIG, (LPARAM)hicon);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Initialize the display
|
||||
|
||||
#if !defined(USE_OPENGL) && !defined(USE_GLES)
|
||||
flags = SDL_HWSURFACE | SDL_HWPALETTE;
|
||||
#endif
|
||||
|
||||
// Sam said: better for windows.
|
||||
/* SDL_HWSURFACE|SDL_HWPALETTE | */
|
||||
if (Video.FullScreen) {
|
||||
flags |= SDL_FULLSCREEN;
|
||||
}
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
#ifdef USE_GLES_NATIVE
|
||||
flags |= SDL_OPENGLES;
|
||||
#endif
|
||||
#ifdef USE_OPENGL
|
||||
flags |= SDL_OPENGL | SDL_GL_DOUBLEBUFFER;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!Video.Width || !Video.Height) {
|
||||
Video.Width = 640;
|
||||
Video.Height = 480;
|
||||
}
|
||||
|
||||
if (!Video.Depth) {
|
||||
Video.Depth = 32;
|
||||
}
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (!Video.ViewportWidth || !Video.ViewportHeight) {
|
||||
Video.ViewportWidth = Video.Width;
|
||||
Video.ViewportHeight = Video.Height;
|
||||
}
|
||||
TheScreen = SDL_SetVideoMode(Video.ViewportWidth, Video.ViewportHeight, Video.Depth, flags);
|
||||
#else
|
||||
TheScreen = SDL_SetVideoMode(Video.Width, Video.Height, Video.Depth, flags);
|
||||
#endif
|
||||
if (TheScreen && (TheScreen->format->BitsPerPixel != 16
|
||||
&& TheScreen->format->BitsPerPixel != 32)) {
|
||||
// Only support 16 and 32 bpp, default to 16
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
TheScreen = SDL_SetVideoMode(Video.ViewportWidth, Video.ViewportHeight, 16, flags);
|
||||
#else
|
||||
TheScreen = SDL_SetVideoMode(Video.Width, Video.Height, 16, flags);
|
||||
#endif
|
||||
}
|
||||
if (TheScreen == NULL) {
|
||||
fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n",
|
||||
Video.Width, Video.Height, Video.Depth, SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
Video.FullScreen = (TheScreen->flags & SDL_FULLSCREEN) ? 1 : 0;
|
||||
Video.FullScreen = (SDL_GetWindowFlags(TheWindow) & SDL_WINDOW_FULLSCREEN_DESKTOP) ? 1 : 0;
|
||||
Video.Depth = TheScreen->format->BitsPerPixel;
|
||||
|
||||
#if defined(USE_TOUCHSCREEN) && defined(USE_WIN32)
|
||||
|
@ -648,9 +652,6 @@ void InitVideoSdl()
|
|||
SDL_ShowCursor(SDL_DISABLE);
|
||||
#endif
|
||||
|
||||
// Make default character translation easier
|
||||
SDL_EnableUNICODE(1);
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
#ifdef USE_GLES_EGL
|
||||
|
@ -732,7 +733,8 @@ void InitVideoSdl()
|
|||
*/
|
||||
int VideoValidResolution(int w, int h)
|
||||
{
|
||||
return SDL_VideoModeOK(w, h, TheScreen->format->BitsPerPixel, TheScreen->flags);
|
||||
//return SDL_VideoModeOK(w, h, TheScreen->format->BitsPerPixel, TheScreen->flags);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -811,35 +813,46 @@ static void SdlDoEvent(const EventCallback &callbacks, SDL_Event &event)
|
|||
int yw = UI.MouseWarpPos.y;
|
||||
UI.MouseWarpPos.x = -1;
|
||||
UI.MouseWarpPos.y = -1;
|
||||
SDL_WarpMouse(xw, yw);
|
||||
SDL_WarpMouseInWindow(TheWindow, xw, yw);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_ACTIVEEVENT:
|
||||
if (event.active.state & SDL_APPMOUSEFOCUS) {
|
||||
static bool InMainWindow = true;
|
||||
case SDL_WINDOWEVENT:
|
||||
switch (event.window.event) {
|
||||
case SDL_WINDOWEVENT_ENTER:
|
||||
case SDL_WINDOWEVENT_LEAVE:
|
||||
{
|
||||
static bool InMainWindow = true;
|
||||
|
||||
if (InMainWindow && !event.active.gain) {
|
||||
InputMouseExit(callbacks, SDL_GetTicks());
|
||||
}
|
||||
InMainWindow = (event.active.gain != 0);
|
||||
}
|
||||
if (!IsNetworkGame() && Preference.PauseOnLeave && (event.active.state & SDL_APPACTIVE || SDL_GetAppState() & SDL_APPACTIVE)) {
|
||||
static bool DoTogglePause = false;
|
||||
|
||||
if (IsSDLWindowVisible && !event.active.gain) {
|
||||
IsSDLWindowVisible = false;
|
||||
if (!GamePaused) {
|
||||
DoTogglePause = true;
|
||||
UiTogglePause();
|
||||
if (InMainWindow && (event.window.event & SDL_WINDOWEVENT_LEAVE)) {
|
||||
InputMouseExit(callbacks, SDL_GetTicks());
|
||||
}
|
||||
} else if (!IsSDLWindowVisible && event.active.gain) {
|
||||
IsSDLWindowVisible = true;
|
||||
if (GamePaused && DoTogglePause) {
|
||||
DoTogglePause = false;
|
||||
UiTogglePause();
|
||||
InMainWindow = !!(event.window.event & SDL_WINDOWEVENT_ENTER);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
||||
case SDL_WINDOWEVENT_FOCUS_LOST:
|
||||
{
|
||||
if (!IsNetworkGame() && Preference.PauseOnLeave /*SDL_GetAppState() & SDL_APPACTIVE*/) {
|
||||
static bool DoTogglePause = false;
|
||||
|
||||
if (IsSDLWindowVisible && (event.window.event & SDL_WINDOWEVENT_FOCUS_LOST)) {
|
||||
IsSDLWindowVisible = false;
|
||||
if (!GamePaused) {
|
||||
DoTogglePause = true;
|
||||
UiTogglePause();
|
||||
}
|
||||
} else if (!IsSDLWindowVisible && (event.window.event & SDL_WINDOWEVENT_FOCUS_GAINED)) {
|
||||
IsSDLWindowVisible = true;
|
||||
if (GamePaused && DoTogglePause) {
|
||||
DoTogglePause = false;
|
||||
UiTogglePause();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -852,12 +865,12 @@ static void SdlDoEvent(const EventCallback &callbacks, SDL_Event &event)
|
|||
break;
|
||||
}
|
||||
InputKeyButtonPress(callbacks, SDL_GetTicks(),
|
||||
event.key.keysym.sym, event.key.keysym.unicode);
|
||||
event.key.keysym.sym, event.key.keysym.sym < 128 ? event.key.keysym.sym : 0);
|
||||
break;
|
||||
|
||||
case SDL_KEYUP:
|
||||
InputKeyButtonRelease(callbacks, SDL_GetTicks(),
|
||||
event.key.keysym.sym, event.key.keysym.unicode);
|
||||
event.key.keysym.sym, event.key.keysym.sym < 128 ? event.key.keysym.sym : 0);
|
||||
break;
|
||||
|
||||
case SDL_QUIT:
|
||||
|
@ -971,7 +984,7 @@ void RealizeVideoMemory()
|
|||
if (GLShaderPipelineSupported) {
|
||||
RenderFramebufferToScreen();
|
||||
} else {
|
||||
SDL_GL_SwapBuffers();
|
||||
SDL_GL_SwapWindow(TheWindow);
|
||||
}
|
||||
#endif
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
@ -979,7 +992,13 @@ void RealizeVideoMemory()
|
|||
#endif
|
||||
{
|
||||
if (NumRects) {
|
||||
SDL_UpdateRects(TheScreen, NumRects, Rects);
|
||||
//SDL_UpdateWindowSurfaceRects(TheWindow, Rects, NumRects);
|
||||
//SDL_UpdateTexture(TheTexture, NULL, TheScreen->pixels, TheScreen->pitch);
|
||||
//SDL_RenderClear(TheRenderer);
|
||||
for (int i = 0; i < NumRects; i++)
|
||||
SDL_UpdateTexture(TheTexture, &Rects[i], TheScreen->pixels, TheScreen->pitch);
|
||||
SDL_RenderCopy(TheRenderer, TheTexture, NULL, NULL);
|
||||
SDL_RenderPresent(TheRenderer);
|
||||
NumRects = 0;
|
||||
}
|
||||
}
|
||||
|
@ -1051,7 +1070,7 @@ int Str2SdlKey(const char *str)
|
|||
*/
|
||||
bool SdlGetGrabMouse()
|
||||
{
|
||||
return SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON;
|
||||
return SDL_GetRelativeMouseMode();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1064,9 +1083,9 @@ void ToggleGrabMouse(int mode)
|
|||
bool grabbed = SdlGetGrabMouse();
|
||||
|
||||
if (mode <= 0 && grabbed) {
|
||||
SDL_WM_GrabInput(SDL_GRAB_OFF);
|
||||
SDL_SetRelativeMouseMode(SDL_FALSE);
|
||||
} else if (mode >= 0 && !grabbed) {
|
||||
SDL_WM_GrabInput(SDL_GRAB_ON);
|
||||
SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1075,72 +1094,14 @@ void ToggleGrabMouse(int mode)
|
|||
*/
|
||||
void ToggleFullScreen()
|
||||
{
|
||||
#ifdef USE_WIN32
|
||||
long framesize;
|
||||
SDL_Rect clip;
|
||||
Uint32 flags;
|
||||
int w;
|
||||
int h;
|
||||
int bpp;
|
||||
unsigned char *pixels = NULL;
|
||||
SDL_Color *palette = NULL;
|
||||
int ncolors = 0;
|
||||
|
||||
if (!TheScreen) { // don't bother if there's no surface.
|
||||
flags = SDL_GetWindowFlags(TheWindow) & SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
#ifdef USE_WIN32
|
||||
|
||||
if (!TheWindow) { // don't bother if there's no surface.
|
||||
return;
|
||||
}
|
||||
|
||||
flags = TheScreen->flags;
|
||||
w = TheScreen->w;
|
||||
h = TheScreen->h;
|
||||
bpp = TheScreen->format->BitsPerPixel;
|
||||
|
||||
if (!SDL_VideoModeOK(w, h, bpp, flags ^ SDL_FULLSCREEN)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_GetClipRect(TheScreen, &clip);
|
||||
|
||||
// save the contents of the screen.
|
||||
framesize = w * h * TheScreen->format->BytesPerPixel;
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (!UseOpenGL)
|
||||
#endif
|
||||
{
|
||||
if (!(pixels = new unsigned char[framesize])) { // out of memory
|
||||
return;
|
||||
}
|
||||
SDL_LockSurface(TheScreen);
|
||||
memcpy(pixels, TheScreen->pixels, framesize);
|
||||
|
||||
if (TheScreen->format->palette) {
|
||||
ncolors = TheScreen->format->palette->ncolors;
|
||||
if (!(palette = new SDL_Color[ncolors])) {
|
||||
delete[] pixels;
|
||||
return;
|
||||
}
|
||||
memcpy(palette, TheScreen->format->palette->colors,
|
||||
ncolors * sizeof(SDL_Color));
|
||||
}
|
||||
SDL_UnlockSurface(TheScreen);
|
||||
}
|
||||
|
||||
TheScreen = SDL_SetVideoMode(w, h, bpp, flags ^ SDL_FULLSCREEN);
|
||||
if (!TheScreen) {
|
||||
TheScreen = SDL_SetVideoMode(w, h, bpp, flags);
|
||||
if (!TheScreen) { // completely screwed.
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (!UseOpenGL)
|
||||
#endif
|
||||
{
|
||||
delete[] pixels;
|
||||
delete[] palette;
|
||||
}
|
||||
fprintf(stderr, "Toggle to fullscreen, crashed all\n");
|
||||
Exit(-1);
|
||||
}
|
||||
}
|
||||
SDL_SetWindowFullscreen(TheWindow, flags ^ SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||
|
||||
#ifndef USE_TOUCHSCREEN
|
||||
// Cannot hide cursor on Windows with touchscreen, as it switches
|
||||
|
@ -1149,36 +1110,22 @@ void ToggleFullScreen()
|
|||
//
|
||||
// Windows shows the SDL cursor when starting in fullscreen mode
|
||||
// then switching to window mode. This hides the cursor again.
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
//SDL_ShowCursor(SDL_ENABLE);
|
||||
//SDL_ShowCursor(SDL_DISABLE);
|
||||
#endif
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
ReloadOpenGL();
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
SDL_LockSurface(TheScreen);
|
||||
memcpy(TheScreen->pixels, pixels, framesize);
|
||||
delete[] pixels;
|
||||
|
||||
if (TheScreen->format->palette) {
|
||||
// !!! FIXME : No idea if that flags param is right.
|
||||
SDL_SetPalette(TheScreen, SDL_LOGPAL, palette, 0, ncolors);
|
||||
delete[] palette;
|
||||
}
|
||||
SDL_UnlockSurface(TheScreen);
|
||||
}
|
||||
|
||||
SDL_SetClipRect(TheScreen, &clip);
|
||||
#endif
|
||||
|
||||
Invalidate(); // Update display
|
||||
#else // !USE_WIN32
|
||||
SDL_WM_ToggleFullScreen(TheScreen);
|
||||
SDL_SetWindowFullscreen(TheWindow, flags ^ SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||
#endif
|
||||
|
||||
Video.FullScreen = (TheScreen->flags & SDL_FULLSCREEN) ? 1 : 0;
|
||||
Video.FullScreen = (flags & SDL_WINDOW_FULLSCREEN_DESKTOP) ? 1 : 0;
|
||||
}
|
||||
|
||||
//@}
|
||||
|
|
|
@ -292,7 +292,7 @@ bool CVideo::ResizeScreen(int w, int h)
|
|||
UI.Minimap.FreeOpenGL();
|
||||
}
|
||||
#endif
|
||||
TheScreen = SDL_SetVideoMode(w, h, TheScreen->format->BitsPerPixel, TheScreen->flags);
|
||||
SDL_SetWindowSize(TheWindow, w, h);
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
ViewportWidth = w;
|
||||
ViewportHeight = h;
|
||||
|
@ -424,7 +424,7 @@ static void ColorCycleSurface(SDL_Surface &surface)
|
|||
memcpy(colors + range.begin, palcolors + range.begin + 1, (range.end - range.begin) * sizeof(SDL_Color));
|
||||
colors[range.end] = palcolors[range.begin];
|
||||
}
|
||||
SDL_SetPalette(&surface, SDL_LOGPAL | SDL_PHYSPAL, colors, 0, 256);
|
||||
SDL_SetPaletteColors(surface.format->palette, colors, 0, 256);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -445,7 +445,7 @@ static void ColorCycleSurface_Reverse(SDL_Surface &surface, unsigned int count)
|
|||
memcpy(colors + range.begin + 1, palcolors + range.begin, (range.end - range.begin) * sizeof(SDL_Color));
|
||||
colors[range.begin] = palcolors[range.end];
|
||||
}
|
||||
SDL_SetPalette(&surface, SDL_LOGPAL | SDL_PHYSPAL, colors, 0, 256);
|
||||
SDL_SetPaletteColors(surface.format->palette, colors, 0, 256);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue