win32 preferences, bug fixes

This commit is contained in:
Henrique Santiago 2011-03-20 16:55:12 -03:00
parent 7ab8b17bf6
commit e0cfab3dd2
4 changed files with 67 additions and 23 deletions

View File

@ -46,8 +46,11 @@ namespace Platform
void setWindowTitle(const char *title); void setWindowTitle(const char *title);
bool isWindowFocused(); bool isWindowFocused();
bool isWindowVisible(); bool isWindowVisible();
int getWindowX();
int getWindowY();
int getWindowWidth(); int getWindowWidth();
int getWindowHeight(); int getWindowHeight();
bool isWindowMaximized();
/// Get GL extension function address /// Get GL extension function address
void *getExtensionProcAddress(const char *ext); void *getExtensionProcAddress(const char *ext);

View File

@ -24,6 +24,8 @@
#include "platform.h" #include "platform.h"
#include "engine.h" #include "engine.h"
#include <dir.h>
#include <physfs.h>
#include <windows.h> #include <windows.h>
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
@ -231,20 +233,23 @@ void *Platform::getExtensionProcAddress(const char *ext)
bool Platform::isExtensionSupported(const char *ext) bool Platform::isExtensionSupported(const char *ext)
{ {
const char *exts = NULL;//glXQueryExtensionsString(x11.display, DefaultScreen(x11.display)); typedef const char* _wglGetExtensionsStringARB(HDC hdc);
_wglGetExtensionsStringARB *wglGetExtensionsStringARB = (_wglGetExtensionsStringARB*)getExtensionProcAddress("wglGetExtensionsStringARB");
const char *exts = wglGetExtensionsStringARB(win32.hdc);
if(strstr(exts, ext)) if(strstr(exts, ext))
return true; return true;
return true; return false;
}
void Platform::hideMouseCursor()
{
ShowCursor(false);
} }
void Platform::showMouseCursor() void Platform::showMouseCursor()
{ {
ShowCursor(false); ShowCursor(true);
/*XUndefineCursor(x11.display, x11.window);
if(x11.cursor != None) {
XFreeCursor(x11.display, x11.cursor);
x11.cursor = None;
}*/
} }
void Platform::setVsync(bool enable) void Platform::setVsync(bool enable)
@ -252,10 +257,8 @@ void Platform::setVsync(bool enable)
typedef GLint (*glSwapIntervalProc)(GLint); typedef GLint (*glSwapIntervalProc)(GLint);
glSwapIntervalProc glSwapInterval = NULL; glSwapIntervalProc glSwapInterval = NULL;
if(isExtensionSupported("GLX_MESA_swap_control")) if(isExtensionSupported("WGL_EXT_swap_control"))
glSwapInterval = (glSwapIntervalProc)getExtensionProcAddress("glXSwapIntervalMESA"); glSwapInterval = (glSwapIntervalProc)getExtensionProcAddress("wglSwapIntervalEXT");
else if(isExtensionSupported("GLX_SGI_swap_control"))
glSwapInterval = (glSwapIntervalProc)getExtensionProcAddress("glXSwapIntervalSGI");
if(glSwapInterval) if(glSwapInterval)
glSwapInterval(enable ? 1 : 0); glSwapInterval(enable ? 1 : 0);
@ -266,6 +269,16 @@ void Platform::swapBuffers()
SwapBuffers(win32.hdc); SwapBuffers(win32.hdc);
} }
int Platform::getWindowX()
{
return win32.x;
}
int Platform::getWindowY()
{
return win32.y;
}
int Platform::getWindowWidth() int Platform::getWindowWidth()
{ {
return win32.width; return win32.width;
@ -276,14 +289,18 @@ int Platform::getWindowHeight()
return win32.height; return win32.height;
} }
bool Platform::isWindowMaximized()
{
return win32.maximized;
}
const char *Platform::getAppUserDir(const char *appName) const char *Platform::getAppUserDir(const char *appName)
{ {
/*std::stringstream sdir; std::stringstream sdir;
sdir << PHYSFS_getUserDir() << "/." << APP_NAME << "/"; sdir << PHYSFS_getUserDir() << "/." << appName << "/";
if((mkdir(sdir.str().c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) && (errno != EEXIST)) if((mkdir(sdir.str().c_str()) != 0) && (errno != EEXIST))
error("Couldn't create directory for saving configuration file. (%s)", sdir.str().c_str()); error("Couldn't create directory for saving configuration file. (%s)", sdir.str().c_str());
return sdir.str().c_str();*/ return sdir.str().c_str();
return "lol";
} }
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)

View File

@ -596,7 +596,7 @@ bool Platform::isExtensionSupported(const char *ext)
const char *exts = glXQueryExtensionsString(x11.display, DefaultScreen(x11.display)); const char *exts = glXQueryExtensionsString(x11.display, DefaultScreen(x11.display));
if(strstr(exts, ext)) if(strstr(exts, ext))
return true; return true;
return true; return false;
} }
const char *Platform::getTextFromClipboard() const char *Platform::getTextFromClipboard()
@ -707,6 +707,16 @@ bool Platform::isWindowVisible()
return x11.visible; return x11.visible;
} }
int Platform::getWindowX()
{
return 0;
}
int Platform::getWindowY()
{
return 0;
}
int Platform::getWindowWidth() int Platform::getWindowWidth()
{ {
return x11.width; return x11.width;
@ -717,6 +727,11 @@ int Platform::getWindowHeight()
return x11.height; return x11.height;
} }
bool Platform::isWindowMaximized()
{
return false;
}
const char *Platform::getAppUserDir(const char *appName) const char *Platform::getAppUserDir(const char *appName)
{ {
std::stringstream sdir; std::stringstream sdir;

View File

@ -48,14 +48,20 @@ void signal_handler(int sig)
/// Default configurations /// Default configurations
void setDefaultConfigs() void setDefaultConfigs()
{ {
g_config.setValue("width", 640); g_config.setValue("window x", 0);
g_config.setValue("height", 480); g_config.setValue("window y", 0);
g_config.setValue("window width", 640);
g_config.setValue("window height", 480);
g_config.setValue("window maximized", false);
} }
void saveConfigs() void saveConfigs()
{ {
g_config.setValue("width", Platform::getWindowWidth()); g_config.setValue("window x", Platform::getWindowX());
g_config.setValue("height", Platform::getWindowHeight()); g_config.setValue("window y", Platform::getWindowY());
g_config.setValue("window width", Platform::getWindowWidth());
g_config.setValue("window height", Platform::getWindowHeight());
g_config.setValue("window maximized", Platform::isWindowMaximized());
g_config.save(); g_config.save();
} }
@ -84,7 +90,10 @@ int main(int argc, const char *argv[])
Platform::init(); Platform::init();
// create the window // create the window
Platform::createWindow(0, 0, g_config.getInteger("width"), g_config.getInteger("height"), 640, 480, false); Platform::createWindow(g_config.getInteger("window x"), g_config.getInteger("window y"),
g_config.getInteger("window width"), g_config.getInteger("window height"),
640, 480,
g_config.getBoolean("window maximized"));
Platform::setWindowTitle("OTClient"); Platform::setWindowTitle("OTClient");
Platform::setVsync(); Platform::setVsync();