summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/eglfs
diff options
context:
space:
mode:
authorGirish Ramakrishnan <girish.1.ramakrishnan@nokia.com>2012-05-17 15:53:14 -0700
committerQt by Nokia <qt-info@nokia.com>2012-05-18 15:28:09 +0200
commit5672cbf1317bc266ac12c224b148d6d213c91779 (patch)
tree0e07269388b0da2b16b48b4fca21f2a83b0ee3ae /src/plugins/platforms/eglfs
parentf3a0422acb6d92be26e30c604b7092a8bfd52b7b (diff)
eglfs: Add support for cursor hotspots
Cursor information is now loaded from cursor.json. Done-with: Johannes Zellner Change-Id: I093cf8e944d495269973e777d0b444ae4ececee1 Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
Diffstat (limited to 'src/plugins/platforms/eglfs')
-rw-r--r--src/plugins/platforms/eglfs/cursor.json28
-rw-r--r--src/plugins/platforms/eglfs/cursor.qrc1
-rw-r--r--src/plugins/platforms/eglfs/qeglfscursor.cpp47
-rw-r--r--src/plugins/platforms/eglfs/qeglfscursor.h7
4 files changed, 69 insertions, 14 deletions
diff --git a/src/plugins/platforms/eglfs/cursor.json b/src/plugins/platforms/eglfs/cursor.json
new file mode 100644
index 0000000000..7b6b6d95fa
--- /dev/null
+++ b/src/plugins/platforms/eglfs/cursor.json
@@ -0,0 +1,28 @@
+{
+ "image": ":/cursor-atlas.png",
+ "cursorsPerRow": 8,
+ "hotSpots": [
+ [7, 2],
+ [13, 3],
+ [13, 13],
+ [13, 13],
+ [14, 15],
+ [13, 13],
+ [13, 13],
+ [13, 13],
+ [13, 13],
+ [13, 13],
+ [13, 13],
+ [13, 13],
+ [13, 13],
+ [13, 13],
+ [13, 13],
+ [10, 1],
+ [13, 13],
+ [0, 0],
+ [0, 0],
+ [13, 13],
+ [13, 13]
+ ]
+}
+
diff --git a/src/plugins/platforms/eglfs/cursor.qrc b/src/plugins/platforms/eglfs/cursor.qrc
index 64d9b2b478..8ea6e86587 100644
--- a/src/plugins/platforms/eglfs/cursor.qrc
+++ b/src/plugins/platforms/eglfs/cursor.qrc
@@ -1,6 +1,7 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>cursor-atlas.png</file>
+ <file>cursor.json</file>
</qresource>
</RCC>
diff --git a/src/plugins/platforms/eglfs/qeglfscursor.cpp b/src/plugins/platforms/eglfs/qeglfscursor.cpp
index 20cd7b978b..0d068f38c0 100644
--- a/src/plugins/platforms/eglfs/qeglfscursor.cpp
+++ b/src/plugins/platforms/eglfs/qeglfscursor.cpp
@@ -43,12 +43,13 @@
#include <QtGui/qwindowsysteminterface_qpa.h>
#include <QtGui/QOpenGLShaderProgram>
#include <QtGui/QOpenGLContext>
+#include <QtCore/QJsonDocument>
+#include <QtCore/QJsonArray>
+#include <QtCore/QJsonObject>
#include <QtDebug>
QT_BEGIN_NAMESPACE
-#define CURSORS_PER_ROW 8
-
QEglFSCursor::QEglFSCursor(QEglFSScreen *screen)
: m_screen(screen), m_pos(0, 0), m_program(0), m_vertexCoordEntry(0), m_textureCoordEntry(0), m_textureEntry(0)
{
@@ -114,13 +115,32 @@ void QEglFSCursor::createCursorTexture(uint *texture, const QImage &image)
void QEglFSCursor::initCursorAtlas()
{
- static QByteArray atlas = qgetenv("QT_QPA_EGLFS_CURSORATLAS");
- if (atlas.isEmpty())
- atlas = ":/cursor-atlas.png";
+ static QByteArray json = qgetenv("QT_QPA_EGLFS_CURSOR");
+ if (json.isEmpty())
+ json = ":/cursor.json";
+
+ QFile file(json);
+ file.open(QFile::ReadOnly);
+ QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
+ QJsonObject object = doc.object();
+
+ QString atlas = object.value("image").toString();
+ Q_ASSERT(!atlas.isEmpty());
+
+ const int cursorsPerRow = object.value("cursorsPerRow").toDouble();
+ Q_ASSERT(cursorsPerRow);
+ m_cursorAtlas.cursorsPerRow = cursorsPerRow;
+
+ const QJsonArray hotSpots = object.value("hotSpots").toArray();
+ Q_ASSERT(hotSpots.count() == Qt::LastCursor);
+ for (int i = 0; i < hotSpots.count(); i++) {
+ QPoint hotSpot(hotSpots[i].toArray()[0].toDouble(), hotSpots[i].toArray()[1].toDouble());
+ m_cursorAtlas.hotSpots << hotSpot;
+ }
+
QImage image = QImage(atlas).convertToFormat(QImage::Format_ARGB32_Premultiplied);
- m_cursorAtlas.cursorWidth = image.width() / CURSORS_PER_ROW;
- m_cursorAtlas.cursorHeight = image.height() / ((Qt::LastCursor + CURSORS_PER_ROW - 1) / CURSORS_PER_ROW);
- m_cursorAtlas.hotSpot = QPoint(m_cursorAtlas.cursorWidth/2, m_cursorAtlas.cursorHeight/2); // ## be smarter
+ m_cursorAtlas.cursorWidth = image.width() / m_cursorAtlas.cursorsPerRow;
+ m_cursorAtlas.cursorHeight = image.height() / ((Qt::LastCursor + cursorsPerRow - 1) / cursorsPerRow);
m_cursorAtlas.width = image.width();
m_cursorAtlas.height = image.height();
createCursorTexture(&m_cursorAtlas.texture, image);
@@ -137,10 +157,10 @@ void QEglFSCursor::changeCursor(QCursor *cursor, QWindow *window)
if (cursor->shape() != Qt::BitmapCursor) { // standard cursor
const float ws = (float)m_cursorAtlas.cursorWidth / m_cursorAtlas.width,
hs = (float)m_cursorAtlas.cursorHeight / m_cursorAtlas.height;
- m_cursor.textureRect = QRectF(ws * (m_cursor.shape % CURSORS_PER_ROW),
- hs * (m_cursor.shape / CURSORS_PER_ROW),
+ m_cursor.textureRect = QRectF(ws * (m_cursor.shape % m_cursorAtlas.cursorsPerRow),
+ hs * (m_cursor.shape / m_cursorAtlas.cursorsPerRow),
ws, hs);
- m_cursor.hotSpot = m_cursorAtlas.hotSpot;
+ m_cursor.hotSpot = m_cursorAtlas.hotSpots[m_cursor.shape];
m_cursor.texture = m_cursorAtlas.texture;
m_cursor.size = QSize(m_cursorAtlas.cursorWidth, m_cursorAtlas.cursorHeight);
} else {
@@ -155,6 +175,11 @@ void QEglFSCursor::changeCursor(QCursor *cursor, QWindow *window)
QWindowSystemInterface::handleSynchronousExposeEvent(window, rgn);
}
+QRect QEglFSCursor::cursorRect() const
+{
+ return QRect(m_pos - m_cursor.hotSpot, m_cursor.size);
+}
+
QPoint QEglFSCursor::pos() const
{
return m_pos;
diff --git a/src/plugins/platforms/eglfs/qeglfscursor.h b/src/plugins/platforms/eglfs/qeglfscursor.h
index a580404ab8..43f6b681a8 100644
--- a/src/plugins/platforms/eglfs/qeglfscursor.h
+++ b/src/plugins/platforms/eglfs/qeglfscursor.h
@@ -61,7 +61,7 @@ public:
QPoint pos() const;
void setPos(const QPoint &pos);
- QRect cursorRect() const { return QRect(m_pos, m_cursor.size); }
+ QRect cursorRect() const;
void render();
@@ -74,11 +74,12 @@ private:
// cursor atlas information
struct CursorAtlas {
- CursorAtlas() : texture(0), cursorWidth(0), cursorHeight(0) { }
+ CursorAtlas() : cursorsPerRow(0), texture(0), cursorWidth(0), cursorHeight(0) { }
+ int cursorsPerRow;
uint texture;
int width, height; // width and height of the the atlas
int cursorWidth, cursorHeight; // width and height of cursors inside the atlas
- QPoint hotSpot;
+ QList<QPoint> hotSpots;
} m_cursorAtlas;
// current cursor information