Browse Source

win32 preferences, bug fixes

Henrique Santiago 10 years ago
parent
commit
e0cfab3dd2
4 changed files with 67 additions and 23 deletions
  1. 3
    0
      src/framework/platform.h
  2. 34
    17
      src/framework/win32platform.cpp
  3. 16
    1
      src/framework/x11platform.cpp
  4. 14
    5
      src/main.cpp

+ 3
- 0
src/framework/platform.h View File

@@ -46,8 +46,11 @@ namespace Platform
46 46
     void setWindowTitle(const char *title);
47 47
     bool isWindowFocused();
48 48
     bool isWindowVisible();
49
+    int getWindowX();
50
+    int getWindowY();
49 51
     int getWindowWidth();
50 52
     int getWindowHeight();
53
+    bool isWindowMaximized();
51 54
 
52 55
     /// Get GL extension function address
53 56
     void *getExtensionProcAddress(const char *ext);

+ 34
- 17
src/framework/win32platform.cpp View File

@@ -24,6 +24,8 @@
24 24
 #include "platform.h"
25 25
 #include "engine.h"
26 26
 
27
+#include <dir.h>
28
+#include <physfs.h>
27 29
 #include <windows.h>
28 30
 
29 31
 LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
@@ -231,20 +233,23 @@ void *Platform::getExtensionProcAddress(const char *ext)
231 233
 
232 234
 bool Platform::isExtensionSupported(const char *ext)
233 235
 {
234
-    const char *exts = NULL;//glXQueryExtensionsString(x11.display, DefaultScreen(x11.display));
236
+    typedef const char* _wglGetExtensionsStringARB(HDC hdc);
237
+    _wglGetExtensionsStringARB *wglGetExtensionsStringARB = (_wglGetExtensionsStringARB*)getExtensionProcAddress("wglGetExtensionsStringARB");
238
+
239
+    const char *exts = wglGetExtensionsStringARB(win32.hdc);
235 240
     if(strstr(exts, ext))
236 241
         return true;
237
-    return true;
242
+    return false;
238 243
 }
239 244
 
240
-void Platform::showMouseCursor()
245
+void Platform::hideMouseCursor()
241 246
 {
242 247
     ShowCursor(false);
243
-    /*XUndefineCursor(x11.display, x11.window);
244
-    if(x11.cursor != None) {
245
-        XFreeCursor(x11.display, x11.cursor);
246
-        x11.cursor = None;
247
-    }*/
248
+}
249
+
250
+void Platform::showMouseCursor()
251
+{
252
+    ShowCursor(true);
248 253
 }
249 254
 
250 255
 void Platform::setVsync(bool enable)
@@ -252,10 +257,8 @@ void Platform::setVsync(bool enable)
252 257
     typedef GLint (*glSwapIntervalProc)(GLint);
253 258
     glSwapIntervalProc glSwapInterval = NULL;
254 259
 
255
-    if(isExtensionSupported("GLX_MESA_swap_control"))
256
-        glSwapInterval = (glSwapIntervalProc)getExtensionProcAddress("glXSwapIntervalMESA");
257
-    else if(isExtensionSupported("GLX_SGI_swap_control"))
258
-        glSwapInterval = (glSwapIntervalProc)getExtensionProcAddress("glXSwapIntervalSGI");
260
+    if(isExtensionSupported("WGL_EXT_swap_control"))
261
+        glSwapInterval = (glSwapIntervalProc)getExtensionProcAddress("wglSwapIntervalEXT");
259 262
 
260 263
     if(glSwapInterval)
261 264
         glSwapInterval(enable ? 1 : 0);
@@ -266,6 +269,16 @@ void Platform::swapBuffers()
266 269
     SwapBuffers(win32.hdc);
267 270
 }
268 271
 
272
+int Platform::getWindowX()
273
+{
274
+    return win32.x;
275
+}
276
+
277
+int Platform::getWindowY()
278
+{
279
+    return win32.y;
280
+}
281
+
269 282
 int Platform::getWindowWidth()
270 283
 {
271 284
     return win32.width;
@@ -276,14 +289,18 @@ int Platform::getWindowHeight()
276 289
     return win32.height;
277 290
 }
278 291
 
292
+bool Platform::isWindowMaximized()
293
+{
294
+    return win32.maximized;
295
+}
296
+
279 297
 const char *Platform::getAppUserDir(const char *appName)
280 298
 {
281
-    /*std::stringstream sdir;
282
-    sdir << PHYSFS_getUserDir() << "/." << APP_NAME << "/";
283
-    if((mkdir(sdir.str().c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) && (errno != EEXIST))
299
+    std::stringstream sdir;
300
+    sdir << PHYSFS_getUserDir() << "/." << appName << "/";
301
+    if((mkdir(sdir.str().c_str()) != 0) && (errno != EEXIST))
284 302
         error("Couldn't create directory for saving configuration file. (%s)", sdir.str().c_str());
285
-    return sdir.str().c_str();*/
286
-    return "lol";
303
+    return sdir.str().c_str();
287 304
 }
288 305
 
289 306
 LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)

+ 16
- 1
src/framework/x11platform.cpp View File

@@ -596,7 +596,7 @@ bool Platform::isExtensionSupported(const char *ext)
596 596
     const char *exts = glXQueryExtensionsString(x11.display, DefaultScreen(x11.display));
597 597
     if(strstr(exts, ext))
598 598
         return true;
599
-    return true;
599
+    return false;
600 600
 }
601 601
 
602 602
 const char *Platform::getTextFromClipboard()
@@ -707,6 +707,16 @@ bool Platform::isWindowVisible()
707 707
     return x11.visible;
708 708
 }
709 709
 
710
+int Platform::getWindowX()
711
+{
712
+    return 0;
713
+}
714
+
715
+int Platform::getWindowY()
716
+{
717
+    return 0;
718
+}
719
+
710 720
 int Platform::getWindowWidth()
711 721
 {
712 722
     return x11.width;
@@ -717,6 +727,11 @@ int Platform::getWindowHeight()
717 727
     return x11.height;
718 728
 }
719 729
 
730
+bool Platform::isWindowMaximized()
731
+{
732
+    return false;
733
+}
734
+
720 735
 const char *Platform::getAppUserDir(const char *appName)
721 736
 {
722 737
     std::stringstream sdir;

+ 14
- 5
src/main.cpp View File

@@ -48,14 +48,20 @@ void signal_handler(int sig)
48 48
 /// Default configurations
49 49
 void setDefaultConfigs()
50 50
 {
51
-    g_config.setValue("width", 640);
52
-    g_config.setValue("height", 480);
51
+    g_config.setValue("window x", 0);
52
+    g_config.setValue("window y", 0);
53
+    g_config.setValue("window width", 640);
54
+    g_config.setValue("window height", 480);
55
+    g_config.setValue("window maximized", false);
53 56
 }
54 57
 
55 58
 void saveConfigs()
56 59
 {
57
-    g_config.setValue("width", Platform::getWindowWidth());
58
-    g_config.setValue("height", Platform::getWindowHeight());
60
+    g_config.setValue("window x", Platform::getWindowX());
61
+    g_config.setValue("window y", Platform::getWindowY());
62
+    g_config.setValue("window width", Platform::getWindowWidth());
63
+    g_config.setValue("window height", Platform::getWindowHeight());
64
+    g_config.setValue("window maximized", Platform::isWindowMaximized());
59 65
     g_config.save();
60 66
 }
61 67
 
@@ -84,7 +90,10 @@ int main(int argc, const char *argv[])
84 90
     Platform::init();
85 91
 
86 92
     // create the window
87
-    Platform::createWindow(0, 0, g_config.getInteger("width"), g_config.getInteger("height"), 640, 480, false);
93
+    Platform::createWindow(g_config.getInteger("window x"), g_config.getInteger("window y"),
94
+                           g_config.getInteger("window width"), g_config.getInteger("window height"),
95
+                           640, 480,
96
+                           g_config.getBoolean("window maximized"));
88 97
     Platform::setWindowTitle("OTClient");
89 98
     Platform::setVsync();
90 99
 

Loading…
Cancel
Save