Finalized SDL2 migration
parent
e965414d34
commit
a0034f8000
|
@ -579,8 +579,6 @@ bool CApplication::Create()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); //TODO: ?
|
|
||||||
|
|
||||||
// Don't generate joystick events
|
// Don't generate joystick events
|
||||||
SDL_JoystickEventState(SDL_IGNORE);
|
SDL_JoystickEventState(SDL_IGNORE);
|
||||||
|
|
||||||
|
@ -1002,30 +1000,34 @@ Event CApplication::ProcessSystemEvent()
|
||||||
}
|
}
|
||||||
else if (m_private->currentEvent.type == SDL_WINDOWEVENT)
|
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;
|
Gfx::DeviceConfig newConfig = m_deviceConfig;
|
||||||
newConfig.size.x = m_private->currentEvent.window.data1;
|
newConfig.size.x = m_private->currentEvent.window.data1;
|
||||||
newConfig.size.y = m_private->currentEvent.window.data2;
|
newConfig.size.y = m_private->currentEvent.window.data2;
|
||||||
if (newConfig.size != m_deviceConfig.size)
|
if (newConfig.size != m_deviceConfig.size)
|
||||||
ChangeVideoConfig(newConfig);
|
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)
|
if (m_private->currentEvent.window.event == SDL_WINDOWEVENT_LEAVE)
|
||||||
data->flags |= ACTIVE_INPUT;
|
{
|
||||||
if (m_private->currentEvent.active.type & SDL_APPMOUSEFOCUS)
|
event.type = EVENT_MOUSE_LEAVE;
|
||||||
data->flags |= ACTIVE_MOUSE;
|
}
|
||||||
if (m_private->currentEvent.active.type & SDL_APPACTIVE)
|
|
||||||
data->flags |= ACTIVE_APP;
|
|
||||||
|
|
||||||
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) ||
|
else if ( (m_private->currentEvent.type == SDL_KEYDOWN) ||
|
||||||
(m_private->currentEvent.type == SDL_KEYUP) )
|
(m_private->currentEvent.type == SDL_KEYUP) )
|
||||||
|
@ -1190,13 +1192,6 @@ void CApplication::LogEvent(const Event &event)
|
||||||
l->Trace(" button = %d\n", data->button);
|
l->Trace(" button = %d\n", data->button);
|
||||||
break;
|
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:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -330,6 +330,7 @@ InputSlot CInput::FindBinding(unsigned int key)
|
||||||
void CInput::SaveKeyBindings()
|
void CInput::SaveKeyBindings()
|
||||||
{
|
{
|
||||||
std::stringstream key;
|
std::stringstream key;
|
||||||
|
CConfigFile::GetInstancePointer()->SetStringProperty("Keybindings", "_Version", "SDL2");
|
||||||
for (int i = 0; i < INPUT_SLOT_MAX; i++)
|
for (int i = 0; i < INPUT_SLOT_MAX; i++)
|
||||||
{
|
{
|
||||||
InputBinding b = GetInputBinding(static_cast<InputSlot>(i));
|
InputBinding b = GetInputBinding(static_cast<InputSlot>(i));
|
||||||
|
@ -355,19 +356,22 @@ void CInput::LoadKeyBindings()
|
||||||
{
|
{
|
||||||
std::stringstream skey;
|
std::stringstream skey;
|
||||||
std::string keys;
|
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))
|
if (!CConfigFile::GetInstancePointer()->GetStringProperty("Keybindings", m_keyTable[static_cast<InputSlot>(i)], keys))
|
||||||
continue;
|
continue;
|
||||||
skey.clear();
|
skey.clear();
|
||||||
skey.str(keys);
|
skey.str(keys);
|
||||||
|
|
||||||
skey >> b.primary;
|
skey >> b.primary;
|
||||||
skey >> b.secondary;
|
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++)
|
for (int i = 0; i < JOY_AXIS_SLOT_MAX; i++)
|
||||||
|
|
|
@ -52,17 +52,20 @@ void InitializeEventTypeTexts()
|
||||||
EVENT_TYPE_TEXT[EVENT_MOUSE_BUTTON_UP] = "EVENT_MOUSE_BUTTON_UP";
|
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_WHEEL] = "EVENT_MOUSE_WHEEL";
|
||||||
EVENT_TYPE_TEXT[EVENT_MOUSE_MOVE] = "EVENT_MOUSE_MOVE";
|
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_DOWN] = "EVENT_KEY_DOWN";
|
||||||
EVENT_TYPE_TEXT[EVENT_KEY_UP] = "EVENT_KEY_UP";
|
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_TEXT_INPUT] = "EVENT_TEXT_INPUT";
|
||||||
|
|
||||||
EVENT_TYPE_TEXT[EVENT_JOY_AXIS] = "EVENT_JOY_AXIS";
|
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_DOWN] = "EVENT_JOY_BUTTON_DOWN";
|
||||||
EVENT_TYPE_TEXT[EVENT_JOY_BUTTON_UP] = "EVENT_JOY_BUTTON_UP";
|
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_UPDINTERFACE] = "EVENT_UPDINTERFACE";
|
||||||
EVENT_TYPE_TEXT[EVENT_WIN] = "EVENT_WIN";
|
EVENT_TYPE_TEXT[EVENT_WIN] = "EVENT_WIN";
|
||||||
|
|
|
@ -62,23 +62,29 @@ enum EventType
|
||||||
EVENT_MOUSE_WHEEL = 5,
|
EVENT_MOUSE_WHEEL = 5,
|
||||||
//! Event sent after moving the mouse
|
//! Event sent after moving the mouse
|
||||||
EVENT_MOUSE_MOVE = 7,
|
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 sent after pressing a key
|
||||||
EVENT_KEY_DOWN = 8,
|
EVENT_KEY_DOWN = 10,
|
||||||
//! Event sent after releasing a key
|
//! Event sent after releasing a key
|
||||||
EVENT_KEY_UP = 9,
|
EVENT_KEY_UP = 11,
|
||||||
|
|
||||||
//! Event sent when application window loses/gains focus
|
|
||||||
EVENT_ACTIVE = 10,
|
|
||||||
|
|
||||||
//! Event sent when user inputs some character
|
//! Event sent when user inputs some character
|
||||||
EVENT_TEXT_INPUT = 11,
|
EVENT_TEXT_INPUT = 12,
|
||||||
|
|
||||||
//! Event sent after moving joystick axes
|
//! Event sent after moving joystick axes
|
||||||
EVENT_JOY_AXIS = 12,
|
EVENT_JOY_AXIS = 13,
|
||||||
//! Event sent after pressing a joystick button
|
//! 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 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
|
//!< Maximum value of system events
|
||||||
EVENT_SYS_MAX,
|
EVENT_SYS_MAX,
|
||||||
|
@ -678,38 +684,6 @@ struct JoyButtonEventData : public EventData
|
||||||
unsigned char button = 0;
|
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
|
* \struct Event
|
||||||
* \brief Event sent by system, interface or game
|
* \brief Event sent by system, interface or game
|
||||||
|
|
|
@ -238,7 +238,6 @@ void CImage::ConvertToRGBA()
|
||||||
|
|
||||||
void CImage::BlitToNewRGBASurface(int width, int height)
|
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,
|
SDL_Surface* convertedSurface = SDL_CreateRGBSurface(0, width, height, 32, 0x00FF0000, 0x0000FF00,
|
||||||
0x000000FF, 0xFF000000);
|
0x000000FF, 0xFF000000);
|
||||||
assert(convertedSurface != nullptr);
|
assert(convertedSurface != nullptr);
|
||||||
|
|
|
@ -26,7 +26,9 @@
|
||||||
|
|
||||||
|
|
||||||
#include <SDL_keycode.h>
|
#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
|
/* 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
|
that these are used. It is to avoid having SDL-related enum values or #defines lying around
|
||||||
|
|
|
@ -866,18 +866,17 @@ bool GetResource(ResType type, unsigned int num, std::string& text)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// TODO: fix signed/unsigned comparations
|
if (num == static_cast<unsigned int>(KEY_INVALID))
|
||||||
if (num == KEY_INVALID)
|
|
||||||
text.clear();
|
text.clear();
|
||||||
else if (num == VIRTUAL_KMOD_CTRL)
|
else if (num == static_cast<unsigned int>(VIRTUAL_KMOD(CTRL)))
|
||||||
text = "Ctrl";
|
text = "Ctrl";
|
||||||
else if (num == VIRTUAL_KMOD_SHIFT)
|
else if (num == static_cast<unsigned int>(VIRTUAL_KMOD(SHIFT)))
|
||||||
text = "Shift";
|
text = "Shift";
|
||||||
else if (num == VIRTUAL_KMOD_ALT)
|
else if (num == static_cast<unsigned int>(VIRTUAL_KMOD(ALT)))
|
||||||
text = "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?
|
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 = gettext("Button %1");
|
||||||
text = StrUtils::Replace(text, "%1", StrUtils::ToString<int>(1 + num - VIRTUAL_JOY(0)));
|
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
|
else
|
||||||
{
|
{
|
||||||
text = SDL_GetKeyName(static_cast<SDL_Keycode>(num));
|
text = SDL_GetKeyName(static_cast<SDL_Keycode>(num));
|
||||||
text = boost::regex_replace(text, boost::regex("\\[(.*)\\]"), "\\1");
|
|
||||||
text[0] = toupper(text[0]);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1017,7 +1017,6 @@ CharTexture CText::CreateCharTexture(UTF8Char ch, CachedFont* font)
|
||||||
int w = Math::NextPowerOfTwo(textSurface->w);
|
int w = Math::NextPowerOfTwo(textSurface->w);
|
||||||
int h = Math::NextPowerOfTwo(textSurface->h);
|
int h = Math::NextPowerOfTwo(textSurface->h);
|
||||||
|
|
||||||
//textSurface->flags = textSurface->flags & (~SDL_SRCALPHA); //TODO: ?
|
|
||||||
SDL_Surface* textureSurface = SDL_CreateRGBSurface(0, w, h, 32, 0x00ff0000, 0x0000ff00,
|
SDL_Surface* textureSurface = SDL_CreateRGBSurface(0, w, h, 32, 0x00ff0000, 0x0000ff00,
|
||||||
0x000000ff, 0xff000000);
|
0x000000ff, 0xff000000);
|
||||||
SDL_BlitSurface(textSurface, nullptr, textureSurface, nullptr);
|
SDL_BlitSurface(textSurface, nullptr, textureSurface, nullptr);
|
||||||
|
|
|
@ -727,8 +727,6 @@ Texture CGL21Device::CreateTexture(ImageData *data, const TextureCreateParams &p
|
||||||
SDL_PixelFormat format;
|
SDL_PixelFormat format;
|
||||||
format.BytesPerPixel = 4;
|
format.BytesPerPixel = 4;
|
||||||
format.BitsPerPixel = 32;
|
format.BitsPerPixel = 32;
|
||||||
//format.alpha = 0; //TODO: ?
|
|
||||||
//format.colorkey = 0; //TODO: ?
|
|
||||||
format.Aloss = format.Bloss = format.Gloss = format.Rloss = 0;
|
format.Aloss = format.Bloss = format.Gloss = format.Rloss = 0;
|
||||||
format.Amask = 0xFF000000;
|
format.Amask = 0xFF000000;
|
||||||
format.Ashift = 24;
|
format.Ashift = 24;
|
||||||
|
|
|
@ -754,8 +754,6 @@ Texture CGL33Device::CreateTexture(ImageData *data, const TextureCreateParams &p
|
||||||
SDL_PixelFormat format;
|
SDL_PixelFormat format;
|
||||||
format.BytesPerPixel = 4;
|
format.BytesPerPixel = 4;
|
||||||
format.BitsPerPixel = 32;
|
format.BitsPerPixel = 32;
|
||||||
//format.alpha = 0; //TODO: ?
|
|
||||||
//format.colorkey = 0; //TODO: ?
|
|
||||||
format.Aloss = format.Bloss = format.Gloss = format.Rloss = 0;
|
format.Aloss = format.Bloss = format.Gloss = format.Rloss = 0;
|
||||||
format.Amask = 0xFF000000;
|
format.Amask = 0xFF000000;
|
||||||
format.Ashift = 24;
|
format.Ashift = 24;
|
||||||
|
|
|
@ -696,8 +696,6 @@ Texture CGLDevice::CreateTexture(ImageData *data, const TextureCreateParams &par
|
||||||
SDL_PixelFormat format;
|
SDL_PixelFormat format;
|
||||||
format.BytesPerPixel = 4;
|
format.BytesPerPixel = 4;
|
||||||
format.BitsPerPixel = 32;
|
format.BitsPerPixel = 32;
|
||||||
//format.alpha = 0; //TODO: ?
|
|
||||||
//format.colorkey = 0; //TODO: ?
|
|
||||||
format.Aloss = format.Bloss = format.Gloss = format.Rloss = 0;
|
format.Aloss = format.Bloss = format.Gloss = format.Rloss = 0;
|
||||||
format.Amask = 0xFF000000;
|
format.Amask = 0xFF000000;
|
||||||
format.Ashift = 24;
|
format.Ashift = 24;
|
||||||
|
|
Loading…
Reference in New Issue