Otclient  14/8/2020
win32window.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 #ifndef WIN32WINDOW_H
24 #define WIN32WINDOW_H
25 
26 #include "platformwindow.h"
27 
28 #include <winsock2.h>
29 #include <windows.h>
30 
31 #ifdef OPENGL_ES
32 #include <EGL/egl.h>
33 #endif
34 
35 #ifdef DIRECTX
36 #include <d3d9.h>
37 #endif
38 
39 struct WindowProcProxy;
40 
42 {
43  void internalCreateWindow();
44  void internalCreateGLContext();
45  void internalDestroyGLContext();
46  void internalRestoreGLContext();
47 
48  void *getExtensionProcAddress(const char *ext);
49  bool isExtensionSupported(const char *ext);
50 
51  LRESULT windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
52  friend struct WindowProcProxy;
53 
54  Fw::Key retranslateVirtualKey(WPARAM wParam, LPARAM lParam);
55 
56 public:
57  WIN32Window();
58 
59  void init();
60  void terminate();
61 
62  void move(const Point& pos);
63  void resize(const Size& size);
64  void show();
65  void hide();
66  void maximize();
67  void poll();
68  void swapBuffers();
69  void showMouse();
70  void hideMouse();
71  void displayFatalError(const std::string& message);
72 
73  void setMouseCursor(int cursorId);
74  void restoreMouseCursor();
75 
76  void setTitle(const std::string& title);
77  void setMinimumSize(const Size& minimumSize);
78  void setFullscreen(bool fullscreen);
79  void setVerticalSync(bool enable);
80  void setIcon(const std::string& file);
81  void setClipboardText(const std::string& text);
82 
84  std::string getClipboardText();
85  std::string getPlatformType();
86 
87 protected:
88  int internalLoadMouseCursor(const ImagePtr& image, const Point& hotSpot);
89 
90 private:
91  Rect getClientRect();
92  Rect getWindowRect();
93  Rect adjustWindowRect(const Rect& rect);
94 
95  std::vector<HCURSOR> m_cursors;
96  HWND m_window;
97  HINSTANCE m_instance;
98  HDC m_deviceContext;
99  HCURSOR m_cursor;
100  HCURSOR m_defaultCursor;
101  bool m_hidden;
102 
103 #ifdef DIRECTX
104  LPDIRECT3D9 m_d3d; // the pointer to our Direct3D interface
105  LPDIRECT3DDEVICE9 m_d3ddev; // the pointer to the device class
106 #endif
107 
108 #ifdef OPENGL_ES
109  EGLConfig m_eglConfig;
110  EGLContext m_eglContext;
111  EGLDisplay m_eglDisplay;
112  EGLSurface m_eglSurface;
113 #else
114  HGLRC m_wglContext;
115 #endif
116 };
117 
118 #endif
WIN32Window::setMinimumSize
void setMinimumSize(const Size &minimumSize)
WIN32Window::terminate
void terminate()
platformwindow.h
WIN32Window::swapBuffers
void swapBuffers()
WIN32Window::setIcon
void setIcon(const std::string &file)
TRect< int >
WIN32Window::WIN32Window
WIN32Window()
WIN32Window::resize
void resize(const Size &size)
PlatformWindow
Definition: platformwindow.h:32
Fw::Key
Key
Definition: const.h:57
WIN32Window::move
void move(const Point &pos)
WIN32Window::restoreMouseCursor
void restoreMouseCursor()
WIN32Window::setMouseCursor
void setMouseCursor(int cursorId)
WIN32Window::setClipboardText
void setClipboardText(const std::string &text)
WIN32Window::show
void show()
WIN32Window::setVerticalSync
void setVerticalSync(bool enable)
WIN32Window::hideMouse
void hideMouse()
WIN32Window::init
void init()
WIN32Window::setFullscreen
void setFullscreen(bool fullscreen)
WIN32Window::getDisplaySize
Size getDisplaySize()
WIN32Window::showMouse
void showMouse()
WIN32Window::getPlatformType
std::string getPlatformType()
WIN32Window
Definition: win32window.h:41
WIN32Window::maximize
void maximize()
WIN32Window::displayFatalError
void displayFatalError(const std::string &message)
WIN32Window::internalLoadMouseCursor
int internalLoadMouseCursor(const ImagePtr &image, const Point &hotSpot)
stdext::shared_object_ptr
Definition: shared_object.h:39
WIN32Window::hide
void hide()
TPoint< int >
WIN32Window::poll
void poll()
WIN32Window::getClipboardText
std::string getClipboardText()
TSize< int >
WIN32Window::setTitle
void setTitle(const std::string &title)
WIN32Window::WindowProcProxy
friend struct WindowProcProxy
Definition: win32window.h:52