Browse Source

Merge branch 'master' of github.com:edubart/otclient

Eduardo Bart 10 years ago
parent
commit
4fa659c26a

+ 4
- 0
src/framework/engine.cpp View File

@@ -23,6 +23,7 @@
23 23
 
24 24
 
25 25
 #include "engine.h"
26
+#include "fonts.h"
26 27
 #include "platform.h"
27 28
 #include "graphics.h"
28 29
 #include "input.h"
@@ -47,6 +48,9 @@ void Engine::init()
47 48
     // initialize graphics stuff
48 49
     g_graphics.init();
49 50
 
51
+    // load fonts
52
+    g_fonts.load();
53
+
50 54
     // finally show the window
51 55
     onResize(Platform::getWindowWidth(), Platform::getWindowHeight());
52 56
 }

+ 22
- 0
src/framework/fonts.cpp View File

@@ -0,0 +1,22 @@
1
+#include "fonts.h"
2
+#include "resourcemanager.h"
3
+
4
+Fonts g_fonts;
5
+
6
+Fonts::Fonts()
7
+{
8
+}
9
+
10
+Fonts::~Fonts()
11
+{
12
+}
13
+
14
+bool Fonts::load()
15
+{
16
+    std::list<std::string> files = g_resources.getDirectoryFiles("fonts");
17
+    for(std::list<std::string>::iterator it = files.begin(), end = files.end(); it != end; ++it) {
18
+        notice("File: %s", (*it).c_str());
19
+    }
20
+
21
+    return true;
22
+}

+ 27
- 0
src/framework/fonts.h View File

@@ -0,0 +1,27 @@
1
+#ifndef FONTS_H
2
+#define FONTS_H
3
+
4
+#include "prerequisites.h"
5
+#include "rect.h"
6
+
7
+struct Font
8
+{
9
+
10
+    Rect textureArea[256];
11
+};
12
+
13
+class Fonts
14
+{
15
+public:
16
+    Fonts();
17
+    ~Fonts();
18
+
19
+    bool load();
20
+
21
+private:
22
+    std::map<int, Font*> mFonts;
23
+};
24
+
25
+extern Fonts g_fonts;
26
+
27
+#endif // FONTS_H

+ 12
- 0
src/framework/resourcemanager.cpp View File

@@ -117,3 +117,15 @@ bool ResourceManager::saveTextFile(const std::string &fileName, std::string text
117 117
 {
118 118
     return saveFile(fileName, (const unsigned char*)text.c_str(), text.size());
119 119
 }
120
+
121
+std::list<std::string> ResourceManager::getDirectoryFiles(const std::string& directory)
122
+{
123
+    std::list<std::string> files;
124
+    char **rc = PHYSFS_enumerateFiles(directory.c_str());
125
+
126
+    for(char **i = rc; *i != NULL; i++)
127
+        files.push_back(*i);
128
+
129
+    PHYSFS_freeList(rc);
130
+    return files;
131
+}

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

@@ -63,6 +63,9 @@ public:
63 63
 
64 64
     /// Save a text file into write directory
65 65
     bool saveTextFile(const std::string &fileName, std::string text);
66
+
67
+    /// Get a list with all files in a directory
68
+    std::list<std::string> getDirectoryFiles(const std::string& directory);
66 69
 };
67 70
 
68 71
 extern ResourceManager g_resources;

+ 30
- 4
src/framework/win32platform.cpp View File

@@ -40,7 +40,7 @@ struct Win32PlatformPrivate {
40 40
     int x, y;
41 41
     int width, height;
42 42
     int minWidth, minHeight;
43
-    bool maximized;
43
+    bool focused, visible, maximized;
44 44
 } win32;
45 45
 
46 46
 void Platform::init(const char *appName)
@@ -302,6 +302,16 @@ void Platform::swapBuffers()
302 302
     SwapBuffers(win32.hdc);
303 303
 }
304 304
 
305
+bool Platform::isWindowFocused()
306
+{
307
+    return win32.focused;
308
+}
309
+
310
+bool Platform::isWindowVisible()
311
+{
312
+    return win32.visible;
313
+}
314
+
305 315
 int Platform::getWindowX()
306 316
 {
307 317
     return win32.x;
@@ -348,8 +358,15 @@ const char *Platform::getAppUserDir()
348 358
 
349 359
 LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
350 360
 {
361
+    static int lastX, lastY;
362
+
351 363
     switch(uMsg)
352 364
     {
365
+    case WM_ACTIVATE:
366
+        {
367
+            win32.focused = !(wParam == WA_INACTIVE);
368
+            break;
369
+        }
353 370
     case WM_CLOSE:
354 371
         {
355 372
             g_engine.onClose();
@@ -364,6 +381,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
364 381
         }
365 382
     case WM_MOVE:
366 383
         {
384
+            lastX = win32.x;
385
+            lastY = win32.y;
367 386
             win32.x = LOWORD(lParam);
368 387
             win32.y = HIWORD(lParam);
369 388
             break;
@@ -373,6 +392,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
373 392
             switch(wParam)
374 393
             {
375 394
             case SIZE_MAXIMIZED:
395
+                win32.x = lastX;
396
+                win32.y = lastY;
376 397
                 win32.maximized = true;
377 398
                 break;
378 399
             case SIZE_RESTORED:
@@ -380,14 +401,19 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
380 401
                 break;
381 402
             }
382 403
 
383
-            win32.width = LOWORD(lParam);
384
-            win32.height = HIWORD(lParam);
404
+            win32.visible = !(wParam == SIZE_MINIMIZED);
405
+
406
+            if(!win32.maximized) {
407
+                win32.width = LOWORD(lParam);
408
+                win32.height = HIWORD(lParam);
409
+            }
410
+
385 411
             g_engine.onResize(LOWORD(lParam), HIWORD(lParam));
386 412
             break;
387 413
         }
388 414
     default:
389 415
         {
390
-            return DefWindowProc(hWnd,uMsg,wParam,lParam);
416
+            return DefWindowProc(hWnd, uMsg, wParam, lParam);
391 417
         }
392 418
     }
393 419
     return 0;

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

@@ -297,20 +297,27 @@ void Platform::poll()
297 297
         switch(event.type) {
298 298
             case ConfigureNotify:
299 299
                 // window resize
300
-                if(x11.width != event.xconfigure.width || x11.height != event.xconfigure.height) {
300
+                static int oldWidth = -1;
301
+                static int oldHeight = -1;
302
+                if(oldWidth != event.xconfigure.width || oldHeight != event.xconfigure.height) {
303
+                    g_engine.onResize(event.xconfigure.width, event.xconfigure.height);
304
+                    oldWidth = event.xconfigure.width;
305
+                    oldHeight = event.xconfigure.height;
306
+                }
307
+
308
+                if(!isWindowMaximized()) {
301 309
                     x11.width = event.xconfigure.width;
302 310
                     x11.height = event.xconfigure.height;
303
-                    g_engine.onResize(x11.width, x11.height);
304
-                }
305 311
 
306
-                // hack to fix x11 windows move gaps
307
-                static int gap_x = -1, gap_y = -1;
308
-                if(gap_x == -1 && gap_y == -1) {
309
-                    gap_x = event.xconfigure.x;
310
-                    gap_y = event.xconfigure.y;
312
+                    // hack to fix x11 windows move gaps
313
+                    static int gap_x = -1, gap_y = -1;
314
+                    if(gap_x == -1 && gap_y == -1) {
315
+                        gap_x = event.xconfigure.x;
316
+                        gap_y = event.xconfigure.y;
317
+                    }
318
+                    x11.x = event.xconfigure.x - gap_x;
319
+                    x11.y = event.xconfigure.y - gap_y;
311 320
                 }
312
-                x11.x = event.xconfigure.x - gap_x;
313
-                x11.y = event.xconfigure.y - gap_y;
314 321
                 break;
315 322
 
316 323
             case KeyPress:

Loading…
Cancel
Save