Finalized SDL2 migration

dev-time-step
krzys-h 2015-09-25 21:26:49 +02:00
parent e965414d34
commit a0034f8000
11 changed files with 62 additions and 95 deletions

View File

@ -579,8 +579,6 @@ bool CApplication::Create()
}
}
//SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); //TODO: ?
// Don't generate joystick events
SDL_JoystickEventState(SDL_IGNORE);
@ -1002,30 +1000,34 @@ Event CApplication::ProcessSystemEvent()
}
else if (m_private->currentEvent.type == SDL_WINDOWEVENT)
{
if (m_private->currentEvent.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
if (m_private->currentEvent.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
{
Gfx::DeviceConfig newConfig = m_deviceConfig;
newConfig.size.x = m_private->currentEvent.window.data1;
newConfig.size.y = m_private->currentEvent.window.data2;
if (newConfig.size != m_deviceConfig.size)
ChangeVideoConfig(newConfig);
}
// TODO: EVENT_ACTIVE
/*{
event.type = EVENT_ACTIVE;
auto data = MakeUnique<ActiveEventData>();
if (m_private->currentEvent.window.event == SDL_WINDOWEVENT_ENTER)
{
event.type = EVENT_MOUSE_ENTER;
}
if (m_private->currentEvent.active.type & SDL_APPINPUTFOCUS)
data->flags |= ACTIVE_INPUT;
if (m_private->currentEvent.active.type & SDL_APPMOUSEFOCUS)
data->flags |= ACTIVE_MOUSE;
if (m_private->currentEvent.active.type & SDL_APPACTIVE)
data->flags |= ACTIVE_APP;
if (m_private->currentEvent.window.event == SDL_WINDOWEVENT_LEAVE)
{
event.type = EVENT_MOUSE_LEAVE;
}
data->gain = m_private->currentEvent.active.gain == 1;
if (m_private->currentEvent.window.event == SDL_WINDOWEVENT_FOCUS_GAINED)
{
event.type = EVENT_FOCUS_GAINED;
}
event.data = std::move(data);
}*/
if (m_private->currentEvent.window.event == SDL_WINDOWEVENT_FOCUS_LOST)
{
event.type = EVENT_FOCUS_LOST;
}
}
else if ( (m_private->currentEvent.type == SDL_KEYDOWN) ||
(m_private->currentEvent.type == SDL_KEYUP) )
@ -1190,13 +1192,6 @@ void CApplication::LogEvent(const Event &event)
l->Trace(" button = %d\n", data->button);
break;
}
case EVENT_ACTIVE:
{
auto data = event.GetData<ActiveEventData>();
l->Trace(" flags = 0x%x\n", data->flags);
l->Trace(" gain = %s\n", data->gain ? "true" : "false");
break;
}
default:
break;
}

View File

@ -330,6 +330,7 @@ InputSlot CInput::FindBinding(unsigned int key)
void CInput::SaveKeyBindings()
{
std::stringstream key;
CConfigFile::GetInstancePointer()->SetStringProperty("Keybindings", "_Version", "SDL2");
for (int i = 0; i < INPUT_SLOT_MAX; i++)
{
InputBinding b = GetInputBinding(static_cast<InputSlot>(i));
@ -355,19 +356,22 @@ void CInput::LoadKeyBindings()
{
std::stringstream skey;
std::string keys;
for (int i = 0; i < INPUT_SLOT_MAX; i++)
if (CConfigFile::GetInstancePointer()->GetStringProperty("Keybindings", "_Version", keys) && keys == "SDL2") // Keybindings from SDL1.2 are incompatible with SDL2 !!
{
InputBinding b;
for (int i = 0; i < INPUT_SLOT_MAX; i++)
{
InputBinding b;
if (!CConfigFile::GetInstancePointer()->GetStringProperty("Keybindings", m_keyTable[static_cast<InputSlot>(i)], keys))
continue;
skey.clear();
skey.str(keys);
if (!CConfigFile::GetInstancePointer()->GetStringProperty("Keybindings", m_keyTable[static_cast<InputSlot>(i)], keys))
continue;
skey.clear();
skey.str(keys);
skey >> b.primary;
skey >> b.secondary;
skey >> b.primary;
skey >> b.secondary;
SetInputBinding(static_cast<InputSlot>(i), b);
SetInputBinding(static_cast<InputSlot>(i), b);
}
}
for (int i = 0; i < JOY_AXIS_SLOT_MAX; i++)

View File

@ -52,17 +52,20 @@ void InitializeEventTypeTexts()
EVENT_TYPE_TEXT[EVENT_MOUSE_BUTTON_UP] = "EVENT_MOUSE_BUTTON_UP";
EVENT_TYPE_TEXT[EVENT_MOUSE_WHEEL] = "EVENT_MOUSE_WHEEL";
EVENT_TYPE_TEXT[EVENT_MOUSE_MOVE] = "EVENT_MOUSE_MOVE";
EVENT_TYPE_TEXT[EVENT_MOUSE_MOVE] = "EVENT_MOUSE_ENTER";
EVENT_TYPE_TEXT[EVENT_MOUSE_MOVE] = "EVENT_MOUSE_LEAVE";
EVENT_TYPE_TEXT[EVENT_KEY_DOWN] = "EVENT_KEY_DOWN";
EVENT_TYPE_TEXT[EVENT_KEY_UP] = "EVENT_KEY_UP";
EVENT_TYPE_TEXT[EVENT_ACTIVE] = "EVENT_ACTIVE";
EVENT_TYPE_TEXT[EVENT_TEXT_INPUT] = "EVENT_TEXT_INPUT";
EVENT_TYPE_TEXT[EVENT_JOY_AXIS] = "EVENT_JOY_AXIS";
EVENT_TYPE_TEXT[EVENT_JOY_BUTTON_DOWN] = "EVENT_JOY_BUTTON_DOWN";
EVENT_TYPE_TEXT[EVENT_JOY_BUTTON_UP] = "EVENT_JOY_BUTTON_UP";
EVENT_TYPE_TEXT[EVENT_FOCUS_GAINED] = "EVENT_FOCUS_GAINED";
EVENT_TYPE_TEXT[EVENT_FOCUS_LOST] = "EVENT_FOCUS_LOST";
EVENT_TYPE_TEXT[EVENT_UPDINTERFACE] = "EVENT_UPDINTERFACE";
EVENT_TYPE_TEXT[EVENT_WIN] = "EVENT_WIN";

View File

@ -62,23 +62,29 @@ enum EventType
EVENT_MOUSE_WHEEL = 5,
//! Event sent after moving the mouse
EVENT_MOUSE_MOVE = 7,
//! Event sent when mouse enters the window
EVENT_MOUSE_ENTER = 8,
//! Event sent when mouse leaves the window
EVENT_MOUSE_LEAVE = 9,
//! Event sent after pressing a key
EVENT_KEY_DOWN = 8,
EVENT_KEY_DOWN = 10,
//! Event sent after releasing a key
EVENT_KEY_UP = 9,
//! Event sent when application window loses/gains focus
EVENT_ACTIVE = 10,
EVENT_KEY_UP = 11,
//! Event sent when user inputs some character
EVENT_TEXT_INPUT = 11,
EVENT_TEXT_INPUT = 12,
//! Event sent after moving joystick axes
EVENT_JOY_AXIS = 12,
EVENT_JOY_AXIS = 13,
//! Event sent after pressing a joystick button
EVENT_JOY_BUTTON_DOWN = 13,
EVENT_JOY_BUTTON_DOWN = 14,
//! Event sent after releasing a joystick button
EVENT_JOY_BUTTON_UP = 14,
EVENT_JOY_BUTTON_UP = 15,
//! Event sent when the app winddow gains focus
EVENT_FOCUS_GAINED = 16,
//! Event sent when the app winddow loses focus
EVENT_FOCUS_LOST = 17,
//!< Maximum value of system events
EVENT_SYS_MAX,
@ -678,38 +684,6 @@ struct JoyButtonEventData : public EventData
unsigned char button = 0;
};
/**
* \enum ActiveEventFlags
* \brief Type of focus gained/lost
*/
enum ActiveEventFlags
{
//! Application window focus
ACTIVE_APP = 0x01,
//! Input focus
ACTIVE_INPUT = 0x02,
//! Mouse focus
ACTIVE_MOUSE = 0x04
};
/**
* \struct ActiveEventData
* \brief Additional data for active event
*/
struct ActiveEventData : public EventData
{
std::unique_ptr<EventData> Clone() const override
{
return MakeUnique<ActiveEventData>(*this);
}
//! Flags (bitmask of enum values ActiveEventFlags)
unsigned char flags = 0;
//! True if the focus was gained; false otherwise
bool gain = false;
};
/**
* \struct Event
* \brief Event sent by system, interface or game

View File

@ -238,7 +238,6 @@ void CImage::ConvertToRGBA()
void CImage::BlitToNewRGBASurface(int width, int height)
{
//m_data->surface->flags &= (~SDL_SRCALPHA); //TODO: ?
SDL_Surface* convertedSurface = SDL_CreateRGBSurface(0, width, height, 32, 0x00FF0000, 0x0000FF00,
0x000000FF, 0xFF000000);
assert(convertedSurface != nullptr);

View File

@ -26,7 +26,9 @@
#include <SDL_keycode.h>
#define SDLK_LAST (SDLK_SCANCODE_MASK << 1) //TODO
// TODO: This is a bit ugly hack
#define SDLK_LAST (SDLK_SCANCODE_MASK << 1)
/* Key definitions are specially defined here so that it is clear in other parts of the code
that these are used. It is to avoid having SDL-related enum values or #defines lying around

View File

@ -866,18 +866,17 @@ bool GetResource(ResType type, unsigned int num, std::string& text)
}
else
{
// TODO: fix signed/unsigned comparations
if (num == KEY_INVALID)
if (num == static_cast<unsigned int>(KEY_INVALID))
text.clear();
else if (num == VIRTUAL_KMOD_CTRL)
else if (num == static_cast<unsigned int>(VIRTUAL_KMOD(CTRL)))
text = "Ctrl";
else if (num == VIRTUAL_KMOD_SHIFT)
else if (num == static_cast<unsigned int>(VIRTUAL_KMOD(SHIFT)))
text = "Shift";
else if (num == VIRTUAL_KMOD_ALT)
else if (num == static_cast<unsigned int>(VIRTUAL_KMOD(ALT)))
text = "Alt";
else if (num == VIRTUAL_KMOD_GUI)
else if (num == static_cast<unsigned int>(VIRTUAL_KMOD(GUI)))
text = "Win"; // TODO: Better description of this key?
else if (num > VIRTUAL_JOY(0))
else if (num > static_cast<unsigned int>(VIRTUAL_JOY(0)))
{
text = gettext("Button %1");
text = StrUtils::Replace(text, "%1", StrUtils::ToString<int>(1 + num - VIRTUAL_JOY(0)));
@ -885,8 +884,6 @@ bool GetResource(ResType type, unsigned int num, std::string& text)
else
{
text = SDL_GetKeyName(static_cast<SDL_Keycode>(num));
text = boost::regex_replace(text, boost::regex("\\[(.*)\\]"), "\\1");
text[0] = toupper(text[0]);
}
return true;
}

View File

@ -1017,7 +1017,6 @@ CharTexture CText::CreateCharTexture(UTF8Char ch, CachedFont* font)
int w = Math::NextPowerOfTwo(textSurface->w);
int h = Math::NextPowerOfTwo(textSurface->h);
//textSurface->flags = textSurface->flags & (~SDL_SRCALPHA); //TODO: ?
SDL_Surface* textureSurface = SDL_CreateRGBSurface(0, w, h, 32, 0x00ff0000, 0x0000ff00,
0x000000ff, 0xff000000);
SDL_BlitSurface(textSurface, nullptr, textureSurface, nullptr);

View File

@ -727,8 +727,6 @@ Texture CGL21Device::CreateTexture(ImageData *data, const TextureCreateParams &p
SDL_PixelFormat format;
format.BytesPerPixel = 4;
format.BitsPerPixel = 32;
//format.alpha = 0; //TODO: ?
//format.colorkey = 0; //TODO: ?
format.Aloss = format.Bloss = format.Gloss = format.Rloss = 0;
format.Amask = 0xFF000000;
format.Ashift = 24;

View File

@ -754,8 +754,6 @@ Texture CGL33Device::CreateTexture(ImageData *data, const TextureCreateParams &p
SDL_PixelFormat format;
format.BytesPerPixel = 4;
format.BitsPerPixel = 32;
//format.alpha = 0; //TODO: ?
//format.colorkey = 0; //TODO: ?
format.Aloss = format.Bloss = format.Gloss = format.Rloss = 0;
format.Amask = 0xFF000000;
format.Ashift = 24;

View File

@ -696,8 +696,6 @@ Texture CGLDevice::CreateTexture(ImageData *data, const TextureCreateParams &par
SDL_PixelFormat format;
format.BytesPerPixel = 4;
format.BitsPerPixel = 32;
//format.alpha = 0; //TODO: ?
//format.colorkey = 0; //TODO: ?
format.Aloss = format.Bloss = format.Gloss = format.Rloss = 0;
format.Amask = 0xFF000000;
format.Ashift = 24;