Eduardo Bart 10 years ago
parent
commit
2339e05b34
4 changed files with 54 additions and 27 deletions
  1. 4
    4
      src/framework/platform.h
  2. 38
    13
      src/framework/win32platform.cpp
  3. 7
    5
      src/framework/x11platform.cpp
  4. 5
    5
      src/main.cpp

+ 4
- 4
src/framework/platform.h View File

@@ -29,7 +29,7 @@
29 29
 
30 30
 namespace Platform
31 31
 {
32
-    void init();
32
+    void init(const char *appName);
33 33
     void terminate();
34 34
 
35 35
     /// Poll platform input/window events
@@ -57,8 +57,8 @@ namespace Platform
57 57
     /// Check if GL extension is supported
58 58
     bool isExtensionSupported(const char *ext);
59 59
 
60
-    const char *getTextFromClipboard();
61
-    void copyToClipboard(const char *text);
60
+    const char *getClipboardText();
61
+    void setClipboardText(const char *text);
62 62
 
63 63
     void hideMouseCursor();
64 64
     void showMouseCursor();
@@ -69,7 +69,7 @@ namespace Platform
69 69
     void swapBuffers();
70 70
 
71 71
     /// Get the app user directory, the place to save files configurations files
72
-    const char *getAppUserDir(const char *appName);
72
+    const char *getAppUserDir();
73 73
 }
74 74
 
75 75
 #endif // PLATFORM_H

+ 38
- 13
src/framework/win32platform.cpp View File

@@ -36,14 +36,16 @@ struct Win32PlatformPrivate {
36 36
     HDC hdc;
37 37
     HGLRC hrc;
38 38
 
39
+    std::string appName;
39 40
     int x, y;
40 41
     int width, height;
41 42
     int minWidth, minHeight;
42 43
     bool maximized;
43 44
 } win32;
44 45
 
45
-void Platform::init()
46
+void Platform::init(const char *appName)
46 47
 {
48
+    win32.appName = appName;
47 49
     win32.instance = GetModuleHandle(NULL);
48 50
 
49 51
     WNDCLASSA wc;
@@ -56,7 +58,7 @@ void Platform::init()
56 58
     wc.hCursor			= LoadCursor(NULL, IDC_ARROW);		// Load The Arrow Pointer
57 59
     wc.hbrBackground            = NULL;					// No Background Required For GL
58 60
     wc.lpszMenuName		= NULL;					// We Don't Want A Menu
59
-    wc.lpszClassName            = "OTClient";		// Set The Class Name
61
+    wc.lpszClassName            = win32.appName.c_str();                        // Set The Class Name
60 62
 
61 63
     if(!RegisterClassA(&wc))
62 64
         fatal("Failed to register the window class.");
@@ -70,7 +72,7 @@ void Platform::terminate()
70 72
     }
71 73
 
72 74
     if(win32.instance) {
73
-        if(!UnregisterClassA("OTClient", win32.instance))
75
+        if(!UnregisterClassA(win32.appName.c_str(), win32.instance))
74 76
             error("Unregister class failed.");
75 77
 
76 78
         win32.instance = NULL;
@@ -112,15 +114,15 @@ bool Platform::createWindow(int x, int y, int width, int height, int minWidth, i
112 114
     //AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle);
113 115
 
114 116
     win32.window = CreateWindowExA(dwExStyle,		// Extended Style For The Window
115
-                                   "OTClient",		// Class Name
116
-                                   "OTClient",          // Window Title
117
+                                   win32.appName.c_str(),       // Class Name
118
+                                   win32.appName.c_str(),       // Window Title
117 119
                                    dwStyle,		// Required Window Style
118
-                                   x,                    // Window X Position
119
-                                   y,                    // Window Y Position
120
-                                   width,                // Calculate Window Width
121
-                                   height,               // Calculate Window Height
122
-                                   NULL,			// No Parent Window
123
-                                   NULL,			// No Menu
120
+                                   x,                   // Window X Position
121
+                                   y,                   // Window Y Position
122
+                                   width,               // Calculate Window Width
123
+                                   height,              // Calculate Window Height
124
+                                   NULL,		// No Parent Window
125
+                                   NULL,		// No Menu
124 126
                                    win32.instance,	// Instance
125 127
                                    NULL);
126 128
 
@@ -242,6 +244,29 @@ bool Platform::isExtensionSupported(const char *ext)
242 244
     return false;
243 245
 }
244 246
 
247
+const char *Platform::getClipboardText()
248
+{
249
+    const char *text = "";
250
+    if(OpenClipboard(NULL)) {
251
+        text = (const char*)GetClipboardData(CF_TEXT);
252
+        CloseClipboard();
253
+    }
254
+    return text;
255
+}
256
+
257
+void Platform::setClipboardText(const char *text)
258
+{
259
+    int textLenght = strlen(text);
260
+    HANDLE hData = new HANDLE[textLenght + 1];
261
+    memcpy(hData, text, textLenght + 1);
262
+
263
+    if(OpenClipboard(NULL)) {
264
+        EmptyClipboard();
265
+        SetClipboardData(CF_TEXT, hData);
266
+        CloseClipboard();
267
+    }
268
+}
269
+
245 270
 void Platform::hideMouseCursor()
246 271
 {
247 272
     ShowCursor(false);
@@ -294,10 +319,10 @@ bool Platform::isWindowMaximized()
294 319
     return win32.maximized;
295 320
 }
296 321
 
297
-const char *Platform::getAppUserDir(const char *appName)
322
+const char *Platform::getAppUserDir()
298 323
 {
299 324
     std::stringstream sdir;
300
-    sdir << PHYSFS_getUserDir() << "/." << appName << "/";
325
+    sdir << PHYSFS_getUserDir() << "/." << win32.appName << "/";
301 326
     if((mkdir(sdir.str().c_str()) != 0) && (errno != EEXIST))
302 327
         error("Couldn't create directory for saving configuration file. (%s)", sdir.str().c_str());
303 328
     return sdir.str().c_str();

+ 7
- 5
src/framework/x11platform.cpp View File

@@ -57,6 +57,7 @@ struct X11PlatformPrivate {
57 57
     bool visible;
58 58
     bool focused;
59 59
     bool maximizeOnFirstShow;
60
+    std::string appName;
60 61
     int width;
61 62
     int height;
62 63
     int x;
@@ -65,8 +66,9 @@ struct X11PlatformPrivate {
65 66
     std::map<int, unsigned char> keyMap;
66 67
 } x11;
67 68
 
68
-void Platform::init()
69
+void Platform::init(const char *appName)
69 70
 {
71
+    x11.appName = appName;
70 72
     x11.display = NULL;
71 73
     x11.visual = NULL;
72 74
     x11.glxContext = NULL;
@@ -642,7 +644,7 @@ bool Platform::isExtensionSupported(const char *ext)
642 644
     return false;
643 645
 }
644 646
 
645
-const char *Platform::getTextFromClipboard()
647
+const char *Platform::getClipboardText()
646 648
 {
647 649
     Window ownerWindow = XGetSelectionOwner(x11.display, x11.atomClipboard);
648 650
     if(ownerWindow ==  x11.window)
@@ -691,7 +693,7 @@ const char *Platform::getTextFromClipboard()
691 693
     return clipboard.c_str();
692 694
 }
693 695
 
694
-void Platform::copyToClipboard(const char *text)
696
+void Platform::setClipboardText(const char *text)
695 697
 {
696 698
     x11.clipboardText = text;
697 699
     XSetSelectionOwner(x11.display, x11.atomClipboard, x11.window, CurrentTime);
@@ -799,10 +801,10 @@ bool Platform::isWindowMaximized()
799 801
     return ret;
800 802
 }
801 803
 
802
-const char *Platform::getAppUserDir(const char *appName)
804
+const char *Platform::getAppUserDir()
803 805
 {
804 806
     std::stringstream sdir;
805
-    sdir << PHYSFS_getUserDir() << "/." << appName << "/";
807
+    sdir << PHYSFS_getUserDir() << "/." << x11.appName << "/";
806 808
     if((mkdir(sdir.str().c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) && (errno != EEXIST))
807 809
         error("Couldn't create directory for saving configuration file. (%s)", sdir.str().c_str());
808 810
     return sdir.str().c_str();

+ 5
- 5
src/main.cpp View File

@@ -71,10 +71,13 @@ int main(int argc, const char *argv[])
71 71
     signal(SIGTERM, signal_handler);
72 72
     signal(SIGINT, signal_handler);
73 73
 
74
+    // init platform stuff
75
+    Platform::init("OTClient");
76
+
74 77
     // init resources
75 78
     g_resources.init(argv[0]);
76
-    if(g_resources.setWriteDir(Platform::getAppUserDir("OTClient")))
77
-        g_resources.addToSearchPath(Platform::getAppUserDir("OTClient"));
79
+    if(g_resources.setWriteDir(Platform::getAppUserDir()))
80
+        g_resources.addToSearchPath(Platform::getAppUserDir());
78 81
     g_resources.addToSearchPath("data");
79 82
 
80 83
     // before loading configurations set the default ones
@@ -86,9 +89,6 @@ int main(int argc, const char *argv[])
86 89
 
87 90
     notice("OTClient 0.1.0");
88 91
 
89
-    // init platform stuff
90
-    Platform::init();
91
-
92 92
     // create the window
93 93
     Platform::createWindow(g_config.getInteger("window x"), g_config.getInteger("window y"),
94 94
                            g_config.getInteger("window width"), g_config.getInteger("window height"),

Loading…
Cancel
Save