mirror of
https://github.com/edubart/otclient.git
synced 2025-10-20 06:23:26 +02:00
@@ -32,9 +32,32 @@ X11Window window;
|
||||
#endif
|
||||
|
||||
#include <framework/core/clock.h>
|
||||
#include <framework/graphics/image.h>
|
||||
|
||||
PlatformWindow& g_window = window;
|
||||
|
||||
int PlatformWindow::loadMouseCursor(const std::string& file, const Point& hotSpot)
|
||||
{
|
||||
ImagePtr image = Image::load(file);
|
||||
|
||||
if(!image) {
|
||||
g_logger.traceError(stdext::format("unable to load cursor image file %s", file));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(image->getBpp() != 4) {
|
||||
g_logger.error("the cursor image must have 4 channels");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(image->getWidth() != 32 || image->getHeight() != 32) {
|
||||
g_logger.error("the cursor image must have 32x32 dimension");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return internalLoadMouseCursor(image, hotSpot);
|
||||
}
|
||||
|
||||
void PlatformWindow::updateUnmaximizedCoords()
|
||||
{
|
||||
if(!isMaximized() && !isFullscreen()) {
|
||||
|
@@ -26,6 +26,7 @@
|
||||
#include <framework/global.h>
|
||||
#include <framework/core/inputevent.h>
|
||||
#include <framework/core/timer.h>
|
||||
#include <framework/graphics/declarations.h>
|
||||
|
||||
//@bindsingleton g_window
|
||||
class PlatformWindow
|
||||
@@ -48,12 +49,14 @@ public:
|
||||
virtual void maximize() = 0;
|
||||
virtual void poll() = 0;
|
||||
virtual void swapBuffers() = 0;
|
||||
virtual void restoreMouseCursor() = 0;
|
||||
virtual void showMouse() = 0;
|
||||
virtual void hideMouse() = 0;
|
||||
virtual void displayFatalError(const std::string& message) { }
|
||||
|
||||
virtual void setMouseCursor(const std::string& file, const Point& hotSpot) = 0;
|
||||
int loadMouseCursor(const std::string& file, const Point& hotSpot);
|
||||
virtual void setMouseCursor(int cursorId) = 0;
|
||||
virtual void restoreMouseCursor() = 0;
|
||||
|
||||
virtual void setTitle(const std::string& title) = 0;
|
||||
virtual void setMinimumSize(const Size& minimumSize) = 0;
|
||||
virtual void setFullscreen(bool fullscreen) = 0;
|
||||
@@ -92,6 +95,8 @@ public:
|
||||
void setOnInputEvent(const OnInputEventCallback& onInputEvent) { m_onInputEvent = onInputEvent; }
|
||||
|
||||
protected:
|
||||
virtual int internalLoadMouseCursor(const ImagePtr& image, const Point& hotSpot) = 0;
|
||||
|
||||
void updateUnmaximizedCoords();
|
||||
|
||||
void processKeyDown(Fw::Key keyCode);
|
||||
|
@@ -211,6 +211,16 @@ void WIN32Window::init()
|
||||
|
||||
void WIN32Window::terminate()
|
||||
{
|
||||
SetCursor(NULL);
|
||||
if(m_defaultCursor) {
|
||||
DestroyCursor(m_defaultCursor);
|
||||
m_defaultCursor = NULL;
|
||||
}
|
||||
|
||||
for(HCURSOR& cursor : m_cursors)
|
||||
DestroyCursor(cursor);
|
||||
m_cursors.clear();
|
||||
|
||||
internalDestroyGLContext();
|
||||
|
||||
if(m_deviceContext) {
|
||||
@@ -219,11 +229,6 @@ void WIN32Window::terminate()
|
||||
m_deviceContext = NULL;
|
||||
}
|
||||
|
||||
if(m_cursor) {
|
||||
DestroyCursor(m_cursor);
|
||||
m_cursor = NULL;
|
||||
}
|
||||
|
||||
if(m_window) {
|
||||
if(!DestroyWindow(m_window))
|
||||
g_logger.error("ERROR: Destroy window failed.");
|
||||
@@ -744,16 +749,6 @@ void WIN32Window::swapBuffers()
|
||||
#endif
|
||||
}
|
||||
|
||||
void WIN32Window::restoreMouseCursor()
|
||||
{
|
||||
if(m_cursor) {
|
||||
DestroyCursor(m_cursor);
|
||||
m_cursor = NULL;
|
||||
SetCursor(m_defaultCursor);
|
||||
ShowCursor(true);
|
||||
}
|
||||
}
|
||||
|
||||
void WIN32Window::showMouse()
|
||||
{
|
||||
ShowCursor(true);
|
||||
@@ -769,28 +764,8 @@ void WIN32Window::displayFatalError(const std::string& message)
|
||||
MessageBoxW(m_window, stdext::latin1_to_utf16(message).c_str(), L"FATAL ERROR", MB_OK | MB_ICONERROR);
|
||||
}
|
||||
|
||||
void WIN32Window::setMouseCursor(const std::string& file, const Point& hotSpot)
|
||||
int WIN32Window::internalLoadMouseCursor(const ImagePtr& image, const Point& hotSpot)
|
||||
{
|
||||
ImagePtr image = Image::load(file);
|
||||
|
||||
if(!image) {
|
||||
g_logger.traceError(stdext::format("unable to load cursor image file %s", file));
|
||||
return;
|
||||
}
|
||||
|
||||
if(image->getBpp() != 4) {
|
||||
g_logger.error("the cursor image must have 4 channels");
|
||||
return;
|
||||
}
|
||||
|
||||
if(image->getWidth() != 32 || image->getHeight() != 32) {
|
||||
g_logger.error("the cursor image must have 32x32 dimension");
|
||||
return;
|
||||
}
|
||||
|
||||
if(m_cursor != NULL)
|
||||
DestroyCursor(m_cursor);
|
||||
|
||||
int width = image->getWidth();
|
||||
int height = image->getHeight();
|
||||
int numbits = width * height;
|
||||
@@ -808,8 +783,28 @@ void WIN32Window::setMouseCursor(const std::string& file, const Point& hotSpot)
|
||||
} // otherwise 0xff000000 => black
|
||||
}
|
||||
|
||||
m_cursor = CreateCursor(m_instance, hotSpot.x, hotSpot.y, width, height, &andMask[0], &xorMask[0]);
|
||||
HCURSOR cursor = CreateCursor(m_instance, hotSpot.x, hotSpot.y, width, height, &andMask[0], &xorMask[0]);
|
||||
m_cursors.push_back(cursor);
|
||||
return m_cursors.size()-1;
|
||||
}
|
||||
|
||||
void WIN32Window::setMouseCursor(int cursorId)
|
||||
{
|
||||
if(cursorId >= (int)m_cursors.size() || cursorId < 0)
|
||||
return;
|
||||
|
||||
m_cursor = m_cursors[cursorId];
|
||||
SetCursor(m_cursor);
|
||||
ShowCursor(true);
|
||||
}
|
||||
|
||||
void WIN32Window::restoreMouseCursor()
|
||||
{
|
||||
if(m_cursor) {
|
||||
m_cursor = NULL;
|
||||
SetCursor(m_defaultCursor);
|
||||
ShowCursor(true);
|
||||
}
|
||||
}
|
||||
|
||||
void WIN32Window::setTitle(const std::string& title)
|
||||
|
@@ -61,12 +61,13 @@ public:
|
||||
void maximize();
|
||||
void poll();
|
||||
void swapBuffers();
|
||||
void restoreMouseCursor();
|
||||
void showMouse();
|
||||
void hideMouse();
|
||||
void displayFatalError(const std::string& message);
|
||||
|
||||
void setMouseCursor(const std::string& file, const Point& hotSpot);
|
||||
void setMouseCursor(int cursorId);
|
||||
void restoreMouseCursor();
|
||||
|
||||
void setTitle(const std::string& title);
|
||||
void setMinimumSize(const Size& minimumSize);
|
||||
void setFullscreen(bool fullscreen);
|
||||
@@ -78,11 +79,15 @@ public:
|
||||
std::string getClipboardText();
|
||||
std::string getPlatformType();
|
||||
|
||||
protected:
|
||||
int internalLoadMouseCursor(const ImagePtr& image, const Point& hotSpot);
|
||||
|
||||
private:
|
||||
Rect getClientRect();
|
||||
Rect getWindowRect();
|
||||
Rect adjustWindowRect(const Rect& rect);
|
||||
|
||||
std::vector<HCURSOR> m_cursors;
|
||||
HWND m_window;
|
||||
HINSTANCE m_instance;
|
||||
HDC m_deviceContext;
|
||||
|
@@ -37,6 +37,7 @@ X11Window::X11Window()
|
||||
m_rootWindow = 0;
|
||||
m_colormap = 0;
|
||||
m_cursor = 0;
|
||||
m_hiddenCursor = 0;
|
||||
m_xim = 0;
|
||||
m_xic = 0;
|
||||
m_screen = 0;
|
||||
@@ -218,6 +219,20 @@ void X11Window::init()
|
||||
|
||||
void X11Window::terminate()
|
||||
{
|
||||
if(m_cursor != None) {
|
||||
XUndefineCursor(m_display, m_window);
|
||||
m_cursor = None;
|
||||
}
|
||||
|
||||
if(m_hiddenCursor) {
|
||||
XFreeCursor(m_display, m_hiddenCursor);
|
||||
m_hiddenCursor = 0;
|
||||
}
|
||||
|
||||
for(Cursor cursor : m_cursors)
|
||||
XFreeCursor(m_display, cursor);
|
||||
m_cursors.clear();
|
||||
|
||||
if(m_window) {
|
||||
XDestroyWindow(m_display, m_window);
|
||||
m_window = 0;
|
||||
@@ -842,47 +857,40 @@ void X11Window::hideMouse()
|
||||
if(m_cursor != None)
|
||||
restoreMouseCursor();
|
||||
|
||||
char bm[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
Pixmap pix = XCreateBitmapFromData(m_display, m_window, bm, 8, 8);
|
||||
XColor black;
|
||||
memset(&black, 0, sizeof(black));
|
||||
black.flags = DoRed | DoGreen | DoBlue;
|
||||
m_cursor = XCreatePixmapCursor(m_display, pix, pix, &black, &black, 0, 0);
|
||||
XFreePixmap(m_display, pix);
|
||||
if(m_hiddenCursor == None) {
|
||||
char bm[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
Pixmap pix = XCreateBitmapFromData(m_display, m_window, bm, 8, 8);
|
||||
XColor black;
|
||||
memset(&black, 0, sizeof(black));
|
||||
black.flags = DoRed | DoGreen | DoBlue;
|
||||
m_hiddenCursor = XCreatePixmapCursor(m_display, pix, pix, &black, &black, 0, 0);
|
||||
XFreePixmap(m_display, pix);
|
||||
}
|
||||
|
||||
m_cursor = m_hiddenCursor;
|
||||
XDefineCursor(m_display, m_window, m_cursor);
|
||||
}
|
||||
|
||||
void X11Window::setMouseCursor(int cursorId)
|
||||
{
|
||||
if(cursorId >= (int)m_cursors.size() || cursorId < 0)
|
||||
return;
|
||||
|
||||
if(m_cursor != None)
|
||||
restoreMouseCursor();
|
||||
|
||||
m_cursor = m_cursors[cursorId];
|
||||
XDefineCursor(m_display, m_window, m_cursor);
|
||||
}
|
||||
|
||||
void X11Window::restoreMouseCursor()
|
||||
{
|
||||
XUndefineCursor(m_display, m_window);
|
||||
if(m_cursor != None) {
|
||||
XFreeCursor(m_display, m_cursor);
|
||||
m_cursor = None;
|
||||
}
|
||||
m_cursor = None;
|
||||
}
|
||||
|
||||
void X11Window::setMouseCursor(const std::string& file, const Point& hotSpot)
|
||||
int X11Window::internalLoadMouseCursor(const ImagePtr& image, const Point& hotSpot)
|
||||
{
|
||||
ImagePtr image = Image::load(file);
|
||||
|
||||
if(!image) {
|
||||
g_logger.traceError(stdext::format("unable to load image file %s", file));
|
||||
return;
|
||||
}
|
||||
|
||||
if(image->getBpp() != 4) {
|
||||
g_logger.error("the cursor image must have 4 channels");
|
||||
return;
|
||||
}
|
||||
|
||||
if(image->getWidth() != 32 || image->getHeight() != 32) {
|
||||
g_logger.error("the cursor image must have 32x32 dimension");
|
||||
return;
|
||||
}
|
||||
|
||||
if(m_cursor != None)
|
||||
restoreMouseCursor();
|
||||
|
||||
int width = image->getWidth();
|
||||
int height = image->getHeight();
|
||||
int numbits = width * height;
|
||||
@@ -911,10 +919,12 @@ void X11Window::setMouseCursor(const std::string& file, const Point& hotSpot)
|
||||
|
||||
Pixmap cp = XCreateBitmapFromData(m_display, m_window, (char*)&mapBits[0], width, height);
|
||||
Pixmap mp = XCreateBitmapFromData(m_display, m_window, (char*)&maskBits[0], width, height);
|
||||
m_cursor = XCreatePixmapCursor(m_display, cp, mp, &fg, &bg, hotSpot.x, hotSpot.y);
|
||||
XDefineCursor(m_display, m_window, m_cursor);
|
||||
Cursor cursor = XCreatePixmapCursor(m_display, cp, mp, &fg, &bg, hotSpot.x, hotSpot.y);
|
||||
XFreePixmap(m_display, cp);
|
||||
XFreePixmap(m_display, mp);
|
||||
|
||||
m_cursors.push_back(cursor);
|
||||
return m_cursors.size()-1;
|
||||
}
|
||||
|
||||
void X11Window::setTitle(const std::string& title)
|
||||
|
@@ -63,11 +63,12 @@ public:
|
||||
void maximize();
|
||||
void poll();
|
||||
void swapBuffers();
|
||||
void restoreMouseCursor();
|
||||
void showMouse();
|
||||
void hideMouse();
|
||||
|
||||
void setMouseCursor(const std::string& file, const Point& hotSpot);
|
||||
void setMouseCursor(int cursorId);
|
||||
void restoreMouseCursor();
|
||||
|
||||
void setTitle(const std::string& title);
|
||||
void setMinimumSize(const Size& minimumSize);
|
||||
void setFullscreen(bool fullscreen);
|
||||
@@ -79,13 +80,18 @@ public:
|
||||
std::string getClipboardText();
|
||||
std::string getPlatformType();
|
||||
|
||||
protected:
|
||||
int internalLoadMouseCursor(const ImagePtr& image, const Point& hotSpot);
|
||||
|
||||
private:
|
||||
Display *m_display;
|
||||
XVisualInfo *m_visual;
|
||||
Window m_window;
|
||||
Window m_rootWindow;
|
||||
Colormap m_colormap;
|
||||
std::vector<Cursor> m_cursors;
|
||||
Cursor m_cursor;
|
||||
Cursor m_hiddenCursor;
|
||||
XIM m_xim;
|
||||
XIC m_xic;
|
||||
int m_screen;
|
||||
|
Reference in New Issue
Block a user