merging
This commit is contained in:
commit
2339e05b34
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
namespace Platform
|
namespace Platform
|
||||||
{
|
{
|
||||||
void init();
|
void init(const char *appName);
|
||||||
void terminate();
|
void terminate();
|
||||||
|
|
||||||
/// Poll platform input/window events
|
/// Poll platform input/window events
|
||||||
|
@ -57,8 +57,8 @@ namespace Platform
|
||||||
/// Check if GL extension is supported
|
/// Check if GL extension is supported
|
||||||
bool isExtensionSupported(const char *ext);
|
bool isExtensionSupported(const char *ext);
|
||||||
|
|
||||||
const char *getTextFromClipboard();
|
const char *getClipboardText();
|
||||||
void copyToClipboard(const char *text);
|
void setClipboardText(const char *text);
|
||||||
|
|
||||||
void hideMouseCursor();
|
void hideMouseCursor();
|
||||||
void showMouseCursor();
|
void showMouseCursor();
|
||||||
|
@ -69,7 +69,7 @@ namespace Platform
|
||||||
void swapBuffers();
|
void swapBuffers();
|
||||||
|
|
||||||
/// Get the app user directory, the place to save files configurations files
|
/// Get the app user directory, the place to save files configurations files
|
||||||
const char *getAppUserDir(const char *appName);
|
const char *getAppUserDir();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // PLATFORM_H
|
#endif // PLATFORM_H
|
||||||
|
|
|
@ -36,14 +36,16 @@ struct Win32PlatformPrivate {
|
||||||
HDC hdc;
|
HDC hdc;
|
||||||
HGLRC hrc;
|
HGLRC hrc;
|
||||||
|
|
||||||
|
std::string appName;
|
||||||
int x, y;
|
int x, y;
|
||||||
int width, height;
|
int width, height;
|
||||||
int minWidth, minHeight;
|
int minWidth, minHeight;
|
||||||
bool maximized;
|
bool maximized;
|
||||||
} win32;
|
} win32;
|
||||||
|
|
||||||
void Platform::init()
|
void Platform::init(const char *appName)
|
||||||
{
|
{
|
||||||
|
win32.appName = appName;
|
||||||
win32.instance = GetModuleHandle(NULL);
|
win32.instance = GetModuleHandle(NULL);
|
||||||
|
|
||||||
WNDCLASSA wc;
|
WNDCLASSA wc;
|
||||||
|
@ -56,7 +58,7 @@ void Platform::init()
|
||||||
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer
|
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer
|
||||||
wc.hbrBackground = NULL; // No Background Required For GL
|
wc.hbrBackground = NULL; // No Background Required For GL
|
||||||
wc.lpszMenuName = NULL; // We Don't Want A Menu
|
wc.lpszMenuName = NULL; // We Don't Want A Menu
|
||||||
wc.lpszClassName = "OTClient"; // Set The Class Name
|
wc.lpszClassName = win32.appName.c_str(); // Set The Class Name
|
||||||
|
|
||||||
if(!RegisterClassA(&wc))
|
if(!RegisterClassA(&wc))
|
||||||
fatal("Failed to register the window class.");
|
fatal("Failed to register the window class.");
|
||||||
|
@ -70,7 +72,7 @@ void Platform::terminate()
|
||||||
}
|
}
|
||||||
|
|
||||||
if(win32.instance) {
|
if(win32.instance) {
|
||||||
if(!UnregisterClassA("OTClient", win32.instance))
|
if(!UnregisterClassA(win32.appName.c_str(), win32.instance))
|
||||||
error("Unregister class failed.");
|
error("Unregister class failed.");
|
||||||
|
|
||||||
win32.instance = NULL;
|
win32.instance = NULL;
|
||||||
|
@ -112,15 +114,15 @@ bool Platform::createWindow(int x, int y, int width, int height, int minWidth, i
|
||||||
//AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle);
|
//AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle);
|
||||||
|
|
||||||
win32.window = CreateWindowExA(dwExStyle, // Extended Style For The Window
|
win32.window = CreateWindowExA(dwExStyle, // Extended Style For The Window
|
||||||
"OTClient", // Class Name
|
win32.appName.c_str(), // Class Name
|
||||||
"OTClient", // Window Title
|
win32.appName.c_str(), // Window Title
|
||||||
dwStyle, // Required Window Style
|
dwStyle, // Required Window Style
|
||||||
x, // Window X Position
|
x, // Window X Position
|
||||||
y, // Window Y Position
|
y, // Window Y Position
|
||||||
width, // Calculate Window Width
|
width, // Calculate Window Width
|
||||||
height, // Calculate Window Height
|
height, // Calculate Window Height
|
||||||
NULL, // No Parent Window
|
NULL, // No Parent Window
|
||||||
NULL, // No Menu
|
NULL, // No Menu
|
||||||
win32.instance, // Instance
|
win32.instance, // Instance
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
|
@ -242,6 +244,29 @@ bool Platform::isExtensionSupported(const char *ext)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *Platform::getClipboardText()
|
||||||
|
{
|
||||||
|
const char *text = "";
|
||||||
|
if(OpenClipboard(NULL)) {
|
||||||
|
text = (const char*)GetClipboardData(CF_TEXT);
|
||||||
|
CloseClipboard();
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Platform::setClipboardText(const char *text)
|
||||||
|
{
|
||||||
|
int textLenght = strlen(text);
|
||||||
|
HANDLE hData = new HANDLE[textLenght + 1];
|
||||||
|
memcpy(hData, text, textLenght + 1);
|
||||||
|
|
||||||
|
if(OpenClipboard(NULL)) {
|
||||||
|
EmptyClipboard();
|
||||||
|
SetClipboardData(CF_TEXT, hData);
|
||||||
|
CloseClipboard();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Platform::hideMouseCursor()
|
void Platform::hideMouseCursor()
|
||||||
{
|
{
|
||||||
ShowCursor(false);
|
ShowCursor(false);
|
||||||
|
@ -294,10 +319,10 @@ bool Platform::isWindowMaximized()
|
||||||
return win32.maximized;
|
return win32.maximized;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *Platform::getAppUserDir(const char *appName)
|
const char *Platform::getAppUserDir()
|
||||||
{
|
{
|
||||||
std::stringstream sdir;
|
std::stringstream sdir;
|
||||||
sdir << PHYSFS_getUserDir() << "/." << appName << "/";
|
sdir << PHYSFS_getUserDir() << "/." << win32.appName << "/";
|
||||||
if((mkdir(sdir.str().c_str()) != 0) && (errno != EEXIST))
|
if((mkdir(sdir.str().c_str()) != 0) && (errno != EEXIST))
|
||||||
error("Couldn't create directory for saving configuration file. (%s)", sdir.str().c_str());
|
error("Couldn't create directory for saving configuration file. (%s)", sdir.str().c_str());
|
||||||
return sdir.str().c_str();
|
return sdir.str().c_str();
|
||||||
|
|
|
@ -57,6 +57,7 @@ struct X11PlatformPrivate {
|
||||||
bool visible;
|
bool visible;
|
||||||
bool focused;
|
bool focused;
|
||||||
bool maximizeOnFirstShow;
|
bool maximizeOnFirstShow;
|
||||||
|
std::string appName;
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
int x;
|
int x;
|
||||||
|
@ -65,8 +66,9 @@ struct X11PlatformPrivate {
|
||||||
std::map<int, unsigned char> keyMap;
|
std::map<int, unsigned char> keyMap;
|
||||||
} x11;
|
} x11;
|
||||||
|
|
||||||
void Platform::init()
|
void Platform::init(const char *appName)
|
||||||
{
|
{
|
||||||
|
x11.appName = appName;
|
||||||
x11.display = NULL;
|
x11.display = NULL;
|
||||||
x11.visual = NULL;
|
x11.visual = NULL;
|
||||||
x11.glxContext = NULL;
|
x11.glxContext = NULL;
|
||||||
|
@ -642,7 +644,7 @@ bool Platform::isExtensionSupported(const char *ext)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *Platform::getTextFromClipboard()
|
const char *Platform::getClipboardText()
|
||||||
{
|
{
|
||||||
Window ownerWindow = XGetSelectionOwner(x11.display, x11.atomClipboard);
|
Window ownerWindow = XGetSelectionOwner(x11.display, x11.atomClipboard);
|
||||||
if(ownerWindow == x11.window)
|
if(ownerWindow == x11.window)
|
||||||
|
@ -691,7 +693,7 @@ const char *Platform::getTextFromClipboard()
|
||||||
return clipboard.c_str();
|
return clipboard.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform::copyToClipboard(const char *text)
|
void Platform::setClipboardText(const char *text)
|
||||||
{
|
{
|
||||||
x11.clipboardText = text;
|
x11.clipboardText = text;
|
||||||
XSetSelectionOwner(x11.display, x11.atomClipboard, x11.window, CurrentTime);
|
XSetSelectionOwner(x11.display, x11.atomClipboard, x11.window, CurrentTime);
|
||||||
|
@ -799,10 +801,10 @@ bool Platform::isWindowMaximized()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *Platform::getAppUserDir(const char *appName)
|
const char *Platform::getAppUserDir()
|
||||||
{
|
{
|
||||||
std::stringstream sdir;
|
std::stringstream sdir;
|
||||||
sdir << PHYSFS_getUserDir() << "/." << appName << "/";
|
sdir << PHYSFS_getUserDir() << "/." << x11.appName << "/";
|
||||||
if((mkdir(sdir.str().c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) && (errno != EEXIST))
|
if((mkdir(sdir.str().c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) && (errno != EEXIST))
|
||||||
error("Couldn't create directory for saving configuration file. (%s)", sdir.str().c_str());
|
error("Couldn't create directory for saving configuration file. (%s)", sdir.str().c_str());
|
||||||
return sdir.str().c_str();
|
return sdir.str().c_str();
|
||||||
|
|
10
src/main.cpp
10
src/main.cpp
|
@ -71,10 +71,13 @@ int main(int argc, const char *argv[])
|
||||||
signal(SIGTERM, signal_handler);
|
signal(SIGTERM, signal_handler);
|
||||||
signal(SIGINT, signal_handler);
|
signal(SIGINT, signal_handler);
|
||||||
|
|
||||||
|
// init platform stuff
|
||||||
|
Platform::init("OTClient");
|
||||||
|
|
||||||
// init resources
|
// init resources
|
||||||
g_resources.init(argv[0]);
|
g_resources.init(argv[0]);
|
||||||
if(g_resources.setWriteDir(Platform::getAppUserDir("OTClient")))
|
if(g_resources.setWriteDir(Platform::getAppUserDir()))
|
||||||
g_resources.addToSearchPath(Platform::getAppUserDir("OTClient"));
|
g_resources.addToSearchPath(Platform::getAppUserDir());
|
||||||
g_resources.addToSearchPath("data");
|
g_resources.addToSearchPath("data");
|
||||||
|
|
||||||
// before loading configurations set the default ones
|
// before loading configurations set the default ones
|
||||||
|
@ -86,9 +89,6 @@ int main(int argc, const char *argv[])
|
||||||
|
|
||||||
notice("OTClient 0.1.0");
|
notice("OTClient 0.1.0");
|
||||||
|
|
||||||
// init platform stuff
|
|
||||||
Platform::init();
|
|
||||||
|
|
||||||
// create the window
|
// create the window
|
||||||
Platform::createWindow(g_config.getInteger("window x"), g_config.getInteger("window y"),
|
Platform::createWindow(g_config.getInteger("window x"), g_config.getInteger("window y"),
|
||||||
g_config.getInteger("window width"), g_config.getInteger("window height"),
|
g_config.getInteger("window width"), g_config.getInteger("window height"),
|
||||||
|
|
Loading…
Reference in New Issue