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

This commit is contained in:
Eduardo Bart 2011-04-02 14:33:41 -03:00
commit 4fa659c26a
7 changed files with 116 additions and 15 deletions

View File

@ -23,6 +23,7 @@
#include "engine.h" #include "engine.h"
#include "fonts.h"
#include "platform.h" #include "platform.h"
#include "graphics.h" #include "graphics.h"
#include "input.h" #include "input.h"
@ -47,6 +48,9 @@ void Engine::init()
// initialize graphics stuff // initialize graphics stuff
g_graphics.init(); g_graphics.init();
// load fonts
g_fonts.load();
// finally show the window // finally show the window
onResize(Platform::getWindowWidth(), Platform::getWindowHeight()); onResize(Platform::getWindowWidth(), Platform::getWindowHeight());
} }

22
src/framework/fonts.cpp Normal file
View File

@ -0,0 +1,22 @@
#include "fonts.h"
#include "resourcemanager.h"
Fonts g_fonts;
Fonts::Fonts()
{
}
Fonts::~Fonts()
{
}
bool Fonts::load()
{
std::list<std::string> files = g_resources.getDirectoryFiles("fonts");
for(std::list<std::string>::iterator it = files.begin(), end = files.end(); it != end; ++it) {
notice("File: %s", (*it).c_str());
}
return true;
}

27
src/framework/fonts.h Normal file
View File

@ -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<int, Font*> mFonts;
};
extern Fonts g_fonts;
#endif // FONTS_H

View File

@ -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()); return saveFile(fileName, (const unsigned char*)text.c_str(), text.size());
} }
std::list<std::string> ResourceManager::getDirectoryFiles(const std::string& directory)
{
std::list<std::string> files;
char **rc = PHYSFS_enumerateFiles(directory.c_str());
for(char **i = rc; *i != NULL; i++)
files.push_back(*i);
PHYSFS_freeList(rc);
return files;
}

View File

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

View File

@ -40,7 +40,7 @@ struct Win32PlatformPrivate {
int x, y; int x, y;
int width, height; int width, height;
int minWidth, minHeight; int minWidth, minHeight;
bool maximized; bool focused, visible, maximized;
} win32; } win32;
void Platform::init(const char *appName) void Platform::init(const char *appName)
@ -302,6 +302,16 @@ void Platform::swapBuffers()
SwapBuffers(win32.hdc); SwapBuffers(win32.hdc);
} }
bool Platform::isWindowFocused()
{
return win32.focused;
}
bool Platform::isWindowVisible()
{
return win32.visible;
}
int Platform::getWindowX() int Platform::getWindowX()
{ {
return win32.x; return win32.x;
@ -348,8 +358,15 @@ const char *Platform::getAppUserDir()
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
static int lastX, lastY;
switch(uMsg) switch(uMsg)
{ {
case WM_ACTIVATE:
{
win32.focused = !(wParam == WA_INACTIVE);
break;
}
case WM_CLOSE: case WM_CLOSE:
{ {
g_engine.onClose(); g_engine.onClose();
@ -364,6 +381,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
} }
case WM_MOVE: case WM_MOVE:
{ {
lastX = win32.x;
lastY = win32.y;
win32.x = LOWORD(lParam); win32.x = LOWORD(lParam);
win32.y = HIWORD(lParam); win32.y = HIWORD(lParam);
break; break;
@ -373,6 +392,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
switch(wParam) switch(wParam)
{ {
case SIZE_MAXIMIZED: case SIZE_MAXIMIZED:
win32.x = lastX;
win32.y = lastY;
win32.maximized = true; win32.maximized = true;
break; break;
case SIZE_RESTORED: case SIZE_RESTORED:
@ -380,8 +401,13 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
break; break;
} }
win32.visible = !(wParam == SIZE_MINIMIZED);
if(!win32.maximized) {
win32.width = LOWORD(lParam); win32.width = LOWORD(lParam);
win32.height = HIWORD(lParam); win32.height = HIWORD(lParam);
}
g_engine.onResize(LOWORD(lParam), HIWORD(lParam)); g_engine.onResize(LOWORD(lParam), HIWORD(lParam));
break; break;
} }

View File

@ -297,11 +297,17 @@ void Platform::poll()
switch(event.type) { switch(event.type) {
case ConfigureNotify: case ConfigureNotify:
// window resize // 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.width = event.xconfigure.width;
x11.height = event.xconfigure.height; x11.height = event.xconfigure.height;
g_engine.onResize(x11.width, x11.height);
}
// hack to fix x11 windows move gaps // hack to fix x11 windows move gaps
static int gap_x = -1, gap_y = -1; static int gap_x = -1, gap_y = -1;
@ -311,6 +317,7 @@ void Platform::poll()
} }
x11.x = event.xconfigure.x - gap_x; x11.x = event.xconfigure.x - gap_x;
x11.y = event.xconfigure.y - gap_y; x11.y = event.xconfigure.y - gap_y;
}
break; break;
case KeyPress: case KeyPress: