Merged default into minor

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2014-09-20 00:34:34 -03:00
20 changed files with 311 additions and 119 deletions
+2
View File
@@ -83,6 +83,8 @@ StringMap<Window::Setting, Window::SETTING_MAX_ENUM>::Entry Window::settingEntri
{"highdpi", SETTING_HIGHDPI},
{"srgb", SETTING_SRGB},
{"refreshrate", SETTING_REFRESHRATE},
{"x", SETTING_X},
{"y", SETTING_Y},
};
StringMap<Window::Setting, Window::SETTING_MAX_ENUM> Window::settings(Window::settingEntries, sizeof(Window::settingEntries));
+8
View File
@@ -59,6 +59,8 @@ public:
SETTING_HIGHDPI,
SETTING_SRGB,
SETTING_REFRESHRATE,
SETTING_X,
SETTING_Y,
SETTING_MAX_ENUM
};
@@ -118,6 +120,9 @@ public:
virtual void getDesktopDimensions(int displayindex, int &width, int &height) const = 0;
virtual void setPosition(int x, int y, int displayindex) = 0;
virtual void getPosition(int &x, int &y, int &displayindex) = 0;
virtual bool isCreated() const = 0;
virtual void setWindowTitle(const std::string &title) = 0;
@@ -199,6 +204,9 @@ struct WindowSettings
bool highdpi = false;
bool sRGB = false;
double refreshrate = 0.0;
bool useposition = false;
int x = 0;
int y = 0;
};
} // window
+69 -9
View File
@@ -116,6 +116,25 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
sdlflags |= SDL_WINDOW_ALLOW_HIGHDPI;
#endif
int x = f.x;
int y = f.y;
if (f.useposition && !f.fullscreen)
{
// The position needs to be in the global coordinate space.
SDL_Rect displaybounds = {};
SDL_GetDisplayBounds(f.display, &displaybounds);
x += displaybounds.x;
y += displaybounds.y;
}
else
{
if (f.centered)
x = y = SDL_WINDOWPOS_CENTERED_DISPLAY(f.display);
else
x = y = SDL_WINDOWPOS_UNDEFINED_DISPLAY(f.display);
}
graphics::Graphics *gfx = Module::getInstance<graphics::Graphics>(Module::M_GRAPHICS);
if (gfx != nullptr)
gfx->unSetMode();
@@ -148,9 +167,6 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
}
}
int centeredpos = SDL_WINDOWPOS_CENTERED_DISPLAY(f.display);
int uncenteredpos = SDL_WINDOWPOS_UNDEFINED_DISPLAY(f.display);
if (!window)
{
created = false;
@@ -159,9 +175,8 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
setWindowGLAttributes(f.msaa, f.sRGB);
const char *title = windowTitle.c_str();
int pos = f.centered ? centeredpos : uncenteredpos;
window = SDL_CreateWindow(title, pos, pos, width, height, sdlflags);
window = SDL_CreateWindow(title, x, y, width, height, sdlflags);
if (!window && f.msaa > 0)
{
@@ -169,7 +184,7 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
window = SDL_CreateWindow(title, pos, pos, width, height, sdlflags);
window = SDL_CreateWindow(title, x, y, width, height, sdlflags);
f.msaa = 0;
}
@@ -187,8 +202,8 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
// Enforce minimum window dimensions.
SDL_SetWindowMinimumSize(window, f.minwidth, f.minheight);
if (f.centered && !f.fullscreen)
SDL_SetWindowPosition(window, centeredpos, centeredpos);
if ((f.useposition || f.centered) && !f.fullscreen)
SDL_SetWindowPosition(window, x, y);
SDL_RaiseWindow(window);
@@ -366,7 +381,8 @@ void Window::updateSettings(const WindowSettings &newsettings)
curMode.settings.resizable = (wflags & SDL_WINDOW_RESIZABLE) != 0;
curMode.settings.borderless = (wflags & SDL_WINDOW_BORDERLESS) != 0;
curMode.settings.centered = newsettings.centered;
curMode.settings.display = std::max(SDL_GetWindowDisplayIndex(window), 0);
getPosition(curMode.settings.x, curMode.settings.y, curMode.settings.display);
#if SDL_VERSION_ATLEAST(2,0,1)
curMode.settings.highdpi = (wflags & SDL_WINDOW_ALLOW_HIGHDPI) != 0;
@@ -525,6 +541,50 @@ void Window::getDesktopDimensions(int displayindex, int &width, int &height) con
}
}
void Window::setPosition(int x, int y, int displayindex)
{
if (!window)
return;
displayindex = std::min(std::max(displayindex, 0), getDisplayCount() - 1);
SDL_Rect displaybounds = {};
SDL_GetDisplayBounds(displayindex, &displaybounds);
// The position needs to be in the global coordinate space.
x += displaybounds.x;
y += displaybounds.y;
SDL_SetWindowPosition(window, x, y);
curMode.settings.useposition = true;
}
void Window::getPosition(int &x, int &y, int &displayindex)
{
if (!window)
{
x = y = 0;
displayindex = 0;
return;
}
displayindex = std::max(SDL_GetWindowDisplayIndex(window), 0);
SDL_GetWindowPosition(window, &x, &y);
// SDL always reports 0, 0 for fullscreen windows.
if (!(SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN))
{
SDL_Rect displaybounds = {};
SDL_GetDisplayBounds(displayindex, &displaybounds);
// The position needs to be in the monitor's coordinate space.
x -= displaybounds.x;
y -= displaybounds.y;
}
}
bool Window::isCreated() const
{
return created;
+3
View File
@@ -57,6 +57,9 @@ public:
void getDesktopDimensions(int displayindex, int &width, int &height) const;
void setPosition(int x, int y, int displayindex);
void getPosition(int &x, int &y, int &displayindex);
bool isCreated() const;
void setWindowTitle(const std::string &title);
+39
View File
@@ -109,6 +109,16 @@ int w_setMode(lua_State *L)
settings.highdpi = luax_boolflag(L, 3, settingName(Window::SETTING_HIGHDPI), false);
settings.sRGB = luax_boolflag(L, 3, settingName(Window::SETTING_SRGB), false);
lua_getfield(L, 3, settingName(Window::SETTING_X));
lua_getfield(L, 3, settingName(Window::SETTING_Y));
settings.useposition = !(lua_isnoneornil(L, -2) && lua_isnoneornil(L, -1));
if (settings.useposition)
{
settings.x = luaL_optint(L, -2, 0);
settings.y = luaL_optint(L, -1, 0);
}
lua_pop(L, 2);
// We don't explicitly set the refresh rate, it's "read-only".
luax_catchexcept(L,
@@ -171,6 +181,12 @@ int w_getMode(lua_State *L)
lua_pushnumber(L, settings.refreshrate);
lua_setfield(L, -2, settingName(Window::SETTING_REFRESHRATE));
lua_pushinteger(L, settings.x);
lua_setfield(L, -2, settingName(Window::SETTING_X));
lua_pushinteger(L, settings.y);
lua_setfield(L, -2, settingName(Window::SETTING_Y));
return 3;
}
@@ -253,6 +269,27 @@ int w_getDesktopDimensions(lua_State *L)
return 2;
}
int w_setPosition(lua_State *L)
{
int x = luaL_checkint(L, 1);
int y = luaL_checkint(L, 2);
int displayindex = luaL_optint(L, 3, 1) - 1;
instance()->setPosition(x, y, displayindex);
return 0;
}
int w_getPosition(lua_State *L)
{
int x = 0;
int y = 0;
int displayindex = 0;
instance()->getPosition(x, y, displayindex);
lua_pushinteger(L, x);
lua_pushinteger(L, y);
lua_pushinteger(L, displayindex + 1);
return 3;
}
int w_setIcon(lua_State *L)
{
image::ImageData *i = luax_checktype<image::ImageData>(L, 1, "ImageData", IMAGE_IMAGE_DATA_T);
@@ -426,6 +463,8 @@ static const luaL_Reg functions[] =
{ "getFullscreen", w_getFullscreen },
{ "isCreated", w_isCreated },
{ "getDesktopDimensions", w_getDesktopDimensions },
{ "setPosition", w_setPosition },
{ "getPosition", w_getPosition },
{ "setIcon", w_setIcon },
{ "getIcon", w_getIcon },
{ "setTitle", w_setTitle },
+2
View File
@@ -38,6 +38,8 @@ int w_setFullscreen(lua_State *L);
int w_getFullscreen(lua_State *L);
int w_isCreated(lua_State *L);
int w_getDesktopDimensions(lua_State *L);
int w_setPosition(lua_State *L);
int w_getPosition(lua_State *L);
int w_setIcon(lua_State *L);
int w_getIcon(lua_State *L);
int w_setTitle(lua_State *L);