Browse Source

init on screen center on first startup

Eduardo Bart 10 years ago
parent
commit
caded3285c
4 changed files with 25 additions and 6 deletions
  1. 3
    0
      src/framework/platform.h
  2. 2
    2
      src/framework/win32platform.cpp
  3. 10
    0
      src/framework/x11platform.cpp
  4. 10
    4
      src/main.cpp

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

@@ -52,6 +52,9 @@ namespace Platform
52 52
     int getWindowHeight();
53 53
     bool isWindowMaximized();
54 54
 
55
+    int getDisplayHeight();
56
+    int getDisplayWidth();
57
+
55 58
     /// Get GL extension function address
56 59
     void *getExtensionProcAddress(const char *ext);
57 60
     /// Check if GL extension is supported

+ 2
- 2
src/framework/win32platform.cpp View File

@@ -350,8 +350,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
350 350
             RECT *rect = (RECT*)lParam;
351 351
             win32.x = rect->left;
352 352
             win32.y = rect->top;
353
-            win32.width = rect->right - rect->left;
354
-            win32.height = rect->bottom - rect->top;
355 353
             break;
356 354
         }
357 355
     case WM_SIZE:
@@ -366,6 +364,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
366 364
                 break;
367 365
             }
368 366
 
367
+            win32.width = LOWORD(lParam);
368
+            win32.height = HIWORD(lParam);
369 369
             g_engine.onResize(LOWORD(lParam), HIWORD(lParam));
370 370
             break;
371 371
         }

+ 10
- 0
src/framework/x11platform.cpp View File

@@ -772,6 +772,16 @@ int Platform::getWindowHeight()
772 772
     return x11.height;
773 773
 }
774 774
 
775
+int Platform::getDisplayWidth()
776
+{
777
+    return XDisplayWidth(x11.display, DefaultScreen(x11.display));
778
+}
779
+
780
+int Platform::getDisplayHeight()
781
+{
782
+    return XDisplayHeight(x11.display, DefaultScreen(x11.display));
783
+}
784
+
775 785
 bool Platform::isWindowMaximized()
776 786
 {
777 787
     bool ret = false;

+ 10
- 4
src/main.cpp View File

@@ -48,10 +48,16 @@ void signal_handler(int sig)
48 48
 /// Default configurations
49 49
 void setDefaultConfigs()
50 50
 {
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);
51
+    // default size
52
+    int defWidth = 640;
53
+    int defHeight = 480;
54
+
55
+    // init on screen center
56
+    g_config.setValue("window x", (Platform::getDisplayWidth() - defWidth)/2);
57
+    g_config.setValue("window y", (Platform::getDisplayHeight() - defHeight)/2);
58
+
59
+    g_config.setValue("window width", defWidth);
60
+    g_config.setValue("window height", defHeight);
55 61
     g_config.setValue("window maximized", false);
56 62
 }
57 63
 

Loading…
Cancel
Save