From 8a1351771492b35d08881fbab428d137721f29d3 Mon Sep 17 00:00:00 2001 From: Henrique Santiago Date: Mon, 21 Mar 2011 17:03:45 -0300 Subject: [PATCH 1/3] win32 visible, focused, size fix --- src/framework/win32platform.cpp | 34 +++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/framework/win32platform.cpp b/src/framework/win32platform.cpp index 408ab1cb..b0a2383b 100644 --- a/src/framework/win32platform.cpp +++ b/src/framework/win32platform.cpp @@ -40,7 +40,7 @@ struct Win32PlatformPrivate { int x, y; int width, height; int minWidth, minHeight; - bool maximized; + bool focused, visible, maximized; } win32; void Platform::init(const char *appName) @@ -299,6 +299,16 @@ void Platform::swapBuffers() SwapBuffers(win32.hdc); } +bool Platform::isWindowFocused() +{ + return win32.focused; +} + +bool Platform::isWindowVisible() +{ + return win32.visible; +} + int Platform::getWindowX() { return win32.x; @@ -345,8 +355,15 @@ const char *Platform::getAppUserDir() LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { + static int lastX, lastY; + switch(uMsg) { + case WM_ACTIVATE: + { + win32.focused = !(wParam == WA_INACTIVE); + break; + } case WM_CLOSE: { g_engine.onClose(); @@ -361,6 +378,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) } case WM_MOVE: { + lastX = win32.x; + lastY = win32.y; win32.x = LOWORD(lParam); win32.y = HIWORD(lParam); break; @@ -370,6 +389,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) switch(wParam) { case SIZE_MAXIMIZED: + win32.x = lastX; + win32.y = lastY; win32.maximized = true; break; case SIZE_RESTORED: @@ -377,14 +398,19 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) break; } - win32.width = LOWORD(lParam); - win32.height = HIWORD(lParam); + win32.visible = !(wParam == SIZE_MINIMIZED); + + if(!win32.maximized) { + win32.width = LOWORD(lParam); + win32.height = HIWORD(lParam); + } + g_engine.onResize(LOWORD(lParam), HIWORD(lParam)); break; } default: { - return DefWindowProc(hWnd,uMsg,wParam,lParam); + return DefWindowProc(hWnd, uMsg, wParam, lParam); } } return 0; From 33a2b885b525c12281bac279410c610f08123bf6 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Fri, 25 Mar 2011 16:57:11 -0300 Subject: [PATCH 2/3] useless feature --- src/framework/x11platform.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/framework/x11platform.cpp b/src/framework/x11platform.cpp index 5b90b569..f0ad5dde 100644 --- a/src/framework/x11platform.cpp +++ b/src/framework/x11platform.cpp @@ -297,20 +297,27 @@ void Platform::poll() switch(event.type) { case ConfigureNotify: // window resize - if(x11.width != event.xconfigure.width || x11.height != event.xconfigure.height) { + static int oldWidth = -1; + static int oldHeight = -1; + if(oldWidth != event.xconfigure.width || oldHeight != event.xconfigure.height) { + g_engine.onResize(event.xconfigure.width, event.xconfigure.height); + oldWidth = event.xconfigure.width; + oldHeight = event.xconfigure.height; + } + + if(!isWindowMaximized()) { x11.width = event.xconfigure.width; x11.height = event.xconfigure.height; - g_engine.onResize(x11.width, x11.height); - } - // hack to fix x11 windows move gaps - static int gap_x = -1, gap_y = -1; - if(gap_x == -1 && gap_y == -1) { - gap_x = event.xconfigure.x; - gap_y = event.xconfigure.y; + // hack to fix x11 windows move gaps + static int gap_x = -1, gap_y = -1; + if(gap_x == -1 && gap_y == -1) { + gap_x = event.xconfigure.x; + gap_y = event.xconfigure.y; + } + x11.x = event.xconfigure.x - gap_x; + x11.y = event.xconfigure.y - gap_y; } - x11.x = event.xconfigure.x - gap_x; - x11.y = event.xconfigure.y - gap_y; break; case KeyPress: From 884de984f36b63e50066554884865d426c2e2e32 Mon Sep 17 00:00:00 2001 From: Henrique Santiago Date: Sat, 26 Mar 2011 17:53:08 -0300 Subject: [PATCH 3/3] resource ls, init fonts --- src/framework/engine.cpp | 4 ++++ src/framework/fonts.cpp | 22 ++++++++++++++++++++++ src/framework/fonts.h | 27 +++++++++++++++++++++++++++ src/framework/resourcemanager.cpp | 12 ++++++++++++ src/framework/resourcemanager.h | 3 +++ 5 files changed, 68 insertions(+) create mode 100644 src/framework/fonts.cpp create mode 100644 src/framework/fonts.h diff --git a/src/framework/engine.cpp b/src/framework/engine.cpp index d7516a2b..1993d324 100644 --- a/src/framework/engine.cpp +++ b/src/framework/engine.cpp @@ -23,6 +23,7 @@ #include "engine.h" +#include "fonts.h" #include "platform.h" #include "graphics.h" #include "input.h" @@ -47,6 +48,9 @@ void Engine::init() // initialize graphics stuff g_graphics.init(); + // load fonts + g_fonts.load(); + // finally show the window onResize(Platform::getWindowWidth(), Platform::getWindowHeight()); } diff --git a/src/framework/fonts.cpp b/src/framework/fonts.cpp new file mode 100644 index 00000000..19f66633 --- /dev/null +++ b/src/framework/fonts.cpp @@ -0,0 +1,22 @@ +#include "fonts.h" +#include "resourcemanager.h" + +Fonts g_fonts; + +Fonts::Fonts() +{ +} + +Fonts::~Fonts() +{ +} + +bool Fonts::load() +{ + std::list files = g_resources.getDirectoryFiles("fonts"); + for(std::list::iterator it = files.begin(), end = files.end(); it != end; ++it) { + notice("File: %s", (*it).c_str()); + } + + return true; +} diff --git a/src/framework/fonts.h b/src/framework/fonts.h new file mode 100644 index 00000000..f68cd1c4 --- /dev/null +++ b/src/framework/fonts.h @@ -0,0 +1,27 @@ +#ifndef FONTS_H +#define FONTS_H + +#include "prerequisites.h" +#include "rect.h" + +struct Font +{ + + Rect textureArea[256]; +}; + +class Fonts +{ +public: + Fonts(); + ~Fonts(); + + bool load(); + +private: + std::map mFonts; +}; + +extern Fonts g_fonts; + +#endif // FONTS_H diff --git a/src/framework/resourcemanager.cpp b/src/framework/resourcemanager.cpp index 574c9b1a..011abd6e 100644 --- a/src/framework/resourcemanager.cpp +++ b/src/framework/resourcemanager.cpp @@ -117,3 +117,15 @@ bool ResourceManager::saveTextFile(const std::string &fileName, std::string text { return saveFile(fileName, (const unsigned char*)text.c_str(), text.size()); } + +std::list ResourceManager::getDirectoryFiles(const std::string& directory) +{ + std::list files; + char **rc = PHYSFS_enumerateFiles(directory.c_str()); + + for(char **i = rc; *i != NULL; i++) + files.push_back(*i); + + PHYSFS_freeList(rc); + return files; +} diff --git a/src/framework/resourcemanager.h b/src/framework/resourcemanager.h index 9333653c..66f43a17 100644 --- a/src/framework/resourcemanager.h +++ b/src/framework/resourcemanager.h @@ -63,6 +63,9 @@ public: /// Save a text file into write directory bool saveTextFile(const std::string &fileName, std::string text); + + /// Get a list with all files in a directory + std::list getDirectoryFiles(const std::string& directory); }; extern ResourceManager g_resources;