user32 hurts

This commit is contained in:
ArsenArsen 2017-05-13 11:03:46 +02:00
parent c2f35e9189
commit 1961a67653
9 changed files with 129 additions and 1 deletions

View File

@ -70,7 +70,25 @@ HEADERS += mainwindow.hpp \
cropeditor/settings/blurdialog.hpp \
cropeditor/drawing/pathitem.hpp \
cropeditor/drawing/lineitem.hpp \
cropeditor/drawing/textitem.hpp
cropeditor/drawing/textitem.hpp \
platformbackend.hpp
mac {
SOURCES += $$PWD/platformspecifics/mac/macbackend.cpp
HEADERS += $$PWD/platformspecifics/mac/macbackend.hpp
LIBS += -framework Carbon
} else:win32 {
SOURCES += $$PWD/platformspecifics/u32/u32backend.cpp
HEADERS += $$PWD/platformspecifics/u32/u32backend.hpp
LIBS += -luser32
QT += winextras
} else:unix {
SOURCES += $$PWD/platformspecifics/x11/x11backend.cpp
HEADERS += $$PWD/platformspecifics/x11/x11backend.hpp
QT += x11extras
LIBS += -lxcb-cursor -lxcb-xfixes
} else {
error(Unsupported platform);
}
FORMS += mainwindow.ui \
cropeditor/settings/brushpenselection.ui \

View File

@ -3,6 +3,7 @@
#include <QCommandLineParser>
#include <QTimer>
#include <QtGlobal>
#include <platformbackend.hpp>
#include <stdio.h>
bool verbose = false;
@ -44,6 +45,7 @@ int main(int argc, char *argv[]) {
parser.addOption(v);
parser.process(a);
verbose = parser.isSet(v);
PlatformBackend::inst().getCursor().save("test.png", "PNG");
MainWindow w;
w.show();

14
platformbackend.hpp Normal file
View File

@ -0,0 +1,14 @@
#ifndef PLATFORMBACKEND_HPP
#define PLATFORMBACKEND_HPP
#ifdef __APPLE__
#include <platformspecifics/mac/macbackend.hpp>
#endif
#ifdef _WIN32
#include <platformspecifics/u32/u32backend.hpp>
#endif
#ifdef __unix__
#include <platformspecifics/x11/x11backend.hpp>
#endif
#endif // PLATFORMBACKEND_HPP

View File

@ -0,0 +1,6 @@
#include "macbackend.hpp"
QPixmap PlatformBackend::getCursor() {
#warning "TODO: Mac backend"
return QPixmap();
}

View File

@ -0,0 +1,15 @@
#ifndef MACBACKEND_HPP
#define MACBACKEND_HPP
#include <QPixmap>
class PlatformBackend {
public:
QPixmap getCursor();
static PlatformBackend &inst() {
static PlatformBackend inst;
return inst;
}
};
#endif // MACBACKEND_HPP

View File

@ -0,0 +1,21 @@
#include "u32backend.hpp"
#include <QCursor>
#include <QtWin>
#include <windows.h>
QPixmap PlatformBackend::getCursor() {
CURSORINFO cursorInfo;
cursorInfo.cbSize = sizeof(cursorInfo);
if (GetCursorInfo(&cursorInfo)) {
if (cursorInfo.flags == CURSOR_SHOWING) {
ICONINFO info; // It took me 5 hours to get to here
if (GetIconInfo(cursorInfo.hCursor, &info)) {
return QtWin::fromHBITMAP(info.hbmColor);
} else
return QPixmap();
} else
return QPixmap();
} else
return QPixmap();
}

View File

@ -0,0 +1,15 @@
#ifndef U32BACKEND_HPP
#define U32BACKEND_HPP
#include <QPixmap>
class PlatformBackend {
public:
QPixmap getCursor();
static PlatformBackend &inst() {
static PlatformBackend inst;
return inst;
}
};
#endif // U32BACKEND_HPP

View File

@ -0,0 +1,22 @@
#include "x11backend.hpp"
#include <QPixmap>
#include <QX11Info>
#include <xcb/xcb_cursor.h>
#include <xcb/xcb_util.h>
#include <xcb/xfixes.h>
QPixmap PlatformBackend::getCursor() {
xcb_connection_t *connection = QX11Info::connection();
xcb_xfixes_get_cursor_image_cookie_t cursorCookie = xcb_xfixes_get_cursor_image_unchecked(connection);
QScopedPointer<xcb_xfixes_get_cursor_image_reply_t> cursorReply(xcb_xfixes_get_cursor_image_reply(connection, cursorCookie, NULL));
if (cursorReply.isNull()) {
return QPixmap();
}
quint32 *pixels = xcb_xfixes_get_cursor_image_cursor_image(cursorReply.data());
if (!pixels) {
return QPixmap();
}
return QPixmap::fromImage(QImage((quint8 *)pixels, cursorReply->width, cursorReply->height, QImage::Format_ARGB32_Premultiplied));
}

View File

@ -0,0 +1,15 @@
#ifndef X11BACKEND_HPP
#define X11BACKEND_HPP
#include <QPixmap>
class PlatformBackend {
public:
QPixmap getCursor();
static PlatformBackend &inst() {
static PlatformBackend inst;
return inst;
}
};
#endif // X11BACKEND_HPP