summaryrefslogtreecommitdiffstats
path: root/gui
diff options
context:
space:
mode:
authorDees Troy <dees_troy@teamw.in>2014-02-07 19:39:53 +0100
committerGerrit Code Review <gerrit2@gerrit>2014-02-07 19:39:53 +0100
commite492e27d77ad0c033fc0f55d7a5ffe18752ac7bd (patch)
treea8f5b7c167c0f365dec2735c11717e09c781a9b7 /gui
parentMerge "Expansion of vibrate options" into android-4.4 (diff)
parentImplement mouse cursor (diff)
downloadandroid_bootable_recovery-e492e27d77ad0c033fc0f55d7a5ffe18752ac7bd.tar
android_bootable_recovery-e492e27d77ad0c033fc0f55d7a5ffe18752ac7bd.tar.gz
android_bootable_recovery-e492e27d77ad0c033fc0f55d7a5ffe18752ac7bd.tar.bz2
android_bootable_recovery-e492e27d77ad0c033fc0f55d7a5ffe18752ac7bd.tar.lz
android_bootable_recovery-e492e27d77ad0c033fc0f55d7a5ffe18752ac7bd.tar.xz
android_bootable_recovery-e492e27d77ad0c033fc0f55d7a5ffe18752ac7bd.tar.zst
android_bootable_recovery-e492e27d77ad0c033fc0f55d7a5ffe18752ac7bd.zip
Diffstat (limited to 'gui')
-rw-r--r--gui/Android.mk3
-rw-r--r--gui/devices/1024x600/res/images/cursor.pngbin0 -> 1452 bytes
-rwxr-xr-xgui/devices/1024x600/res/ui.xml7
-rw-r--r--gui/devices/1024x768/res/images/cursor.pngbin0 -> 1452 bytes
-rw-r--r--gui/devices/1024x768/res/ui.xml7
-rw-r--r--gui/devices/1080x1920/res/images/cursor.pngbin0 -> 1452 bytes
-rw-r--r--gui/devices/1080x1920/res/ui.xml7
-rw-r--r--gui/devices/1200x1920/res/images/cursor.pngbin0 -> 1452 bytes
-rw-r--r--gui/devices/1200x1920/res/ui.xml7
-rw-r--r--gui/devices/1280x800/res/images/cursor.pngbin0 -> 1452 bytes
-rw-r--r--gui/devices/1280x800/res/ui.xml7
-rw-r--r--gui/devices/1920x1200/res/images/cursor.pngbin0 -> 1452 bytes
-rw-r--r--gui/devices/1920x1200/res/ui.xml7
-rw-r--r--gui/devices/2560x1600/res/images/cursor.pngbin0 -> 1452 bytes
-rw-r--r--gui/devices/2560x1600/res/ui.xml7
-rw-r--r--gui/devices/320x480/res/images/cursor.pngbin0 -> 1452 bytes
-rw-r--r--gui/devices/320x480/res/ui.xml7
-rw-r--r--gui/devices/480x800/res/images/cursor.pngbin0 -> 1452 bytes
-rw-r--r--gui/devices/480x800/res/ui.xml7
-rw-r--r--gui/devices/480x854/res/images/cursor.pngbin0 -> 1452 bytes
-rw-r--r--gui/devices/480x854/res/ui.xml7
-rw-r--r--gui/devices/540x960/res/images/cursor.pngbin0 -> 1452 bytes
-rw-r--r--gui/devices/540x960/res/ui.xml7
-rw-r--r--gui/devices/720x1280/res/images/cursor.pngbin0 -> 1452 bytes
-rw-r--r--gui/devices/720x1280/res/ui.xml7
-rw-r--r--gui/devices/800x1280/res/images/cursor.pngbin0 -> 1452 bytes
-rwxr-xr-xgui/devices/800x1280/res/ui.xml7
-rw-r--r--gui/devices/800x480/res/images/cursor.pngbin0 -> 1452 bytes
-rwxr-xr-xgui/devices/800x480/res/ui.xml7
-rw-r--r--gui/gui.cpp63
-rw-r--r--gui/mousecursor.cpp154
-rw-r--r--gui/objects.hpp25
-rw-r--r--gui/pages.cpp40
-rw-r--r--gui/pages.hpp5
34 files changed, 384 insertions, 4 deletions
diff --git a/gui/Android.mk b/gui/Android.mk
index ac0b2037c..29d99f7f8 100644
--- a/gui/Android.mk
+++ b/gui/Android.mk
@@ -22,7 +22,8 @@ LOCAL_SRC_FILES := \
keyboard.cpp \
input.cpp \
blanktimer.cpp \
- partitionlist.cpp
+ partitionlist.cpp \
+ mousecursor.cpp
ifneq ($(TWRP_CUSTOM_KEYBOARD),)
LOCAL_SRC_FILES += $(TWRP_CUSTOM_KEYBOARD)
diff --git a/gui/devices/1024x600/res/images/cursor.png b/gui/devices/1024x600/res/images/cursor.png
new file mode 100644
index 000000000..32c8ae1ca
--- /dev/null
+++ b/gui/devices/1024x600/res/images/cursor.png
Binary files differ
diff --git a/gui/devices/1024x600/res/ui.xml b/gui/devices/1024x600/res/ui.xml
index f1ec1443e..4597fb3a3 100755
--- a/gui/devices/1024x600/res/ui.xml
+++ b/gui/devices/1024x600/res/ui.xml
@@ -38,6 +38,7 @@
<resource name="keyboard2" type="image" filename="keyboard2" />
<resource name="keyboard3" type="image" filename="keyboard3" />
<resource name="keyboard4" type="image" filename="keyboard4" />
+ <resource name="cursor" type="image" filename="cursor" />
</resources>
<variables>
@@ -205,6 +206,12 @@
<variable name="slidervalue_sliderh" value="50" />
</variables>
+ <mousecursor>
+ <placement w="15" h="15" />
+ <background color="#FFFF00FF" resource="cursor" />
+ <speed multiplier="2" />
+ </mousecursor>
+
<templates>
<template name="header">
<background color="#000000FF" />
diff --git a/gui/devices/1024x768/res/images/cursor.png b/gui/devices/1024x768/res/images/cursor.png
new file mode 100644
index 000000000..32c8ae1ca
--- /dev/null
+++ b/gui/devices/1024x768/res/images/cursor.png
Binary files differ
diff --git a/gui/devices/1024x768/res/ui.xml b/gui/devices/1024x768/res/ui.xml
index 73b531b4e..84f470298 100644
--- a/gui/devices/1024x768/res/ui.xml
+++ b/gui/devices/1024x768/res/ui.xml
@@ -38,6 +38,7 @@
<resource name="keyboard2" type="image" filename="keyboard2" />
<resource name="keyboard3" type="image" filename="keyboard3" />
<resource name="keyboard4" type="image" filename="keyboard4" />
+ <resource name="cursor" type="image" filename="cursor" />
</resources>
<variables>
@@ -205,6 +206,12 @@
<variable name="slidervalue_sliderh" value="50" />
</variables>
+ <mousecursor>
+ <placement w="15" h="15" />
+ <background color="#FFFF00FF" resource="cursor" />
+ <speed multiplier="2" />
+ </mousecursor>
+
<templates>
<template name="header">
<background color="#000000FF" />
diff --git a/gui/devices/1080x1920/res/images/cursor.png b/gui/devices/1080x1920/res/images/cursor.png
new file mode 100644
index 000000000..32c8ae1ca
--- /dev/null
+++ b/gui/devices/1080x1920/res/images/cursor.png
Binary files differ
diff --git a/gui/devices/1080x1920/res/ui.xml b/gui/devices/1080x1920/res/ui.xml
index 15b98787b..3ab69a6ed 100644
--- a/gui/devices/1080x1920/res/ui.xml
+++ b/gui/devices/1080x1920/res/ui.xml
@@ -39,6 +39,7 @@
<resource name="keyboard2" type="image" filename="keyboard2" />
<resource name="keyboard3" type="image" filename="keyboard3" />
<resource name="keyboard4" type="image" filename="keyboard4" />
+ <resource name="cursor" type="image" filename="cursor" />
</resources>
<variables>
@@ -191,6 +192,12 @@
<variable name="slidervalue_sliderh" value="90" />
</variables>
+ <mousecursor>
+ <placement w="15" h="15" />
+ <background color="#FFFF00FF" resource="cursor" />
+ <speed multiplier="2.5" />
+ </mousecursor>
+
<templates>
<template name="header">
<background color="#000000FF" />
diff --git a/gui/devices/1200x1920/res/images/cursor.png b/gui/devices/1200x1920/res/images/cursor.png
new file mode 100644
index 000000000..32c8ae1ca
--- /dev/null
+++ b/gui/devices/1200x1920/res/images/cursor.png
Binary files differ
diff --git a/gui/devices/1200x1920/res/ui.xml b/gui/devices/1200x1920/res/ui.xml
index c77c3414d..5aedca8b1 100644
--- a/gui/devices/1200x1920/res/ui.xml
+++ b/gui/devices/1200x1920/res/ui.xml
@@ -39,6 +39,7 @@
<resource name="keyboard2" type="image" filename="keyboard2" />
<resource name="keyboard3" type="image" filename="keyboard3" />
<resource name="keyboard4" type="image" filename="keyboard4" />
+ <resource name="cursor" type="image" filename="cursor" />
</resources>
<variables>
@@ -194,6 +195,12 @@
<variable name="slidervalue_sliderh" value="90" />
</variables>
+ <mousecursor>
+ <placement w="15" h="15" />
+ <background color="#FFFF00FF" resource="cursor" />
+ <speed multiplier="2.5" />
+ </mousecursor>
+
<templates>
<template name="header">
<background color="#000000FF" />
diff --git a/gui/devices/1280x800/res/images/cursor.png b/gui/devices/1280x800/res/images/cursor.png
new file mode 100644
index 000000000..32c8ae1ca
--- /dev/null
+++ b/gui/devices/1280x800/res/images/cursor.png
Binary files differ
diff --git a/gui/devices/1280x800/res/ui.xml b/gui/devices/1280x800/res/ui.xml
index dbfcd60ca..c7d914893 100644
--- a/gui/devices/1280x800/res/ui.xml
+++ b/gui/devices/1280x800/res/ui.xml
@@ -38,6 +38,7 @@
<resource name="keyboard2" type="image" filename="keyboard2" />
<resource name="keyboard3" type="image" filename="keyboard3" />
<resource name="keyboard4" type="image" filename="keyboard4" />
+ <resource name="cursor" type="image" filename="cursor" />
</resources>
<variables>
@@ -205,6 +206,12 @@
<variable name="slidervalue_sliderh" value="60" />
</variables>
+ <mousecursor>
+ <placement w="15" h="15" />
+ <background color="#FFFF00FF" resource="cursor" />
+ <speed multiplier="2" />
+ </mousecursor>
+
<templates>
<template name="header">
<background color="#000000FF" />
diff --git a/gui/devices/1920x1200/res/images/cursor.png b/gui/devices/1920x1200/res/images/cursor.png
new file mode 100644
index 000000000..32c8ae1ca
--- /dev/null
+++ b/gui/devices/1920x1200/res/images/cursor.png
Binary files differ
diff --git a/gui/devices/1920x1200/res/ui.xml b/gui/devices/1920x1200/res/ui.xml
index e4bfd6928..dbd6a0b2d 100644
--- a/gui/devices/1920x1200/res/ui.xml
+++ b/gui/devices/1920x1200/res/ui.xml
@@ -38,6 +38,7 @@
<resource name="keyboard2" type="image" filename="keyboard2" />
<resource name="keyboard3" type="image" filename="keyboard3" />
<resource name="keyboard4" type="image" filename="keyboard4" />
+ <resource name="cursor" type="image" filename="cursor" />
</resources>
<variables>
@@ -205,6 +206,12 @@
<variable name="slidervalue_sliderh" value="80" />
</variables>
+ <mousecursor>
+ <placement w="15" h="15" />
+ <background color="#FFFF00FF" resource="cursor" />
+ <speed multiplier="2.5" />
+ </mousecursor>
+
<templates>
<template name="header">
<background color="#000000FF" />
diff --git a/gui/devices/2560x1600/res/images/cursor.png b/gui/devices/2560x1600/res/images/cursor.png
new file mode 100644
index 000000000..32c8ae1ca
--- /dev/null
+++ b/gui/devices/2560x1600/res/images/cursor.png
Binary files differ
diff --git a/gui/devices/2560x1600/res/ui.xml b/gui/devices/2560x1600/res/ui.xml
index f53f7b412..0a501afc0 100644
--- a/gui/devices/2560x1600/res/ui.xml
+++ b/gui/devices/2560x1600/res/ui.xml
@@ -38,6 +38,7 @@
<resource name="keyboard2" type="image" filename="keyboard2" />
<resource name="keyboard3" type="image" filename="keyboard3" />
<resource name="keyboard4" type="image" filename="keyboard4" />
+ <resource name="cursor" type="image" filename="cursor" />
</resources>
<variables>
@@ -205,6 +206,12 @@
<variable name="slidervalue_sliderh" value="90" />
</variables>
+ <mousecursor>
+ <placement w="15" h="15" />
+ <background color="#FFFF00FF" resource="cursor" />
+ <speed multiplier="2.5" />
+ </mousecursor>
+
<templates>
<template name="header">
<background color="#000000FF" />
diff --git a/gui/devices/320x480/res/images/cursor.png b/gui/devices/320x480/res/images/cursor.png
new file mode 100644
index 000000000..32c8ae1ca
--- /dev/null
+++ b/gui/devices/320x480/res/images/cursor.png
Binary files differ
diff --git a/gui/devices/320x480/res/ui.xml b/gui/devices/320x480/res/ui.xml
index 9f0d5a391..3c3b73d26 100644
--- a/gui/devices/320x480/res/ui.xml
+++ b/gui/devices/320x480/res/ui.xml
@@ -39,6 +39,7 @@
<resource name="keyboard2" type="image" filename="keyboard2" />
<resource name="keyboard3" type="image" filename="keyboard3" />
<resource name="keyboard4" type="image" filename="keyboard4" />
+ <resource name="cursor" type="image" filename="cursor" />
</resources>
<variables>
@@ -186,6 +187,12 @@
<variable name="slidervalue_sliderh" value="20" />
</variables>
+ <mousecursor>
+ <placement w="15" h="15" />
+ <background color="#FFFF00FF" resource="cursor" />
+ <speed multiplier="1" />
+ </mousecursor>
+
<templates>
<template name="header">
<background color="#000000FF" />
diff --git a/gui/devices/480x800/res/images/cursor.png b/gui/devices/480x800/res/images/cursor.png
new file mode 100644
index 000000000..32c8ae1ca
--- /dev/null
+++ b/gui/devices/480x800/res/images/cursor.png
Binary files differ
diff --git a/gui/devices/480x800/res/ui.xml b/gui/devices/480x800/res/ui.xml
index 416f6b941..32c90d936 100644
--- a/gui/devices/480x800/res/ui.xml
+++ b/gui/devices/480x800/res/ui.xml
@@ -39,6 +39,7 @@
<resource name="keyboard2" type="image" filename="keyboard2" />
<resource name="keyboard3" type="image" filename="keyboard3" />
<resource name="keyboard4" type="image" filename="keyboard4" />
+ <resource name="cursor" type="image" filename="cursor" />
</resources>
<variables>
@@ -186,6 +187,12 @@
<variable name="slidervalue_sliderh" value="40" />
</variables>
+ <mousecursor>
+ <placement w="15" h="15" />
+ <background color="#FFFF00FF" resource="cursor" />
+ <speed multiplier="1.5" />
+ </mousecursor>
+
<templates>
<template name="header">
<background color="%backgroundcolor%" />
diff --git a/gui/devices/480x854/res/images/cursor.png b/gui/devices/480x854/res/images/cursor.png
new file mode 100644
index 000000000..32c8ae1ca
--- /dev/null
+++ b/gui/devices/480x854/res/images/cursor.png
Binary files differ
diff --git a/gui/devices/480x854/res/ui.xml b/gui/devices/480x854/res/ui.xml
index 687300ab2..a8357703c 100644
--- a/gui/devices/480x854/res/ui.xml
+++ b/gui/devices/480x854/res/ui.xml
@@ -39,6 +39,7 @@
<resource name="keyboard2" type="image" filename="keyboard2" />
<resource name="keyboard3" type="image" filename="keyboard3" />
<resource name="keyboard4" type="image" filename="keyboard4" />
+ <resource name="cursor" type="image" filename="cursor" />
</resources>
<variables>
@@ -185,6 +186,12 @@
<variable name="slidervalue_sliderh" value="40" />
</variables>
+ <mousecursor>
+ <placement w="15" h="15" />
+ <background color="#FFFF00FF" resource="cursor" />
+ <speed multiplier="1.5" />
+ </mousecursor>
+
<templates>
<template name="header">
<background color="%backgroundcolor%" />
diff --git a/gui/devices/540x960/res/images/cursor.png b/gui/devices/540x960/res/images/cursor.png
new file mode 100644
index 000000000..32c8ae1ca
--- /dev/null
+++ b/gui/devices/540x960/res/images/cursor.png
Binary files differ
diff --git a/gui/devices/540x960/res/ui.xml b/gui/devices/540x960/res/ui.xml
index b11c3dc13..0a43bebc2 100644
--- a/gui/devices/540x960/res/ui.xml
+++ b/gui/devices/540x960/res/ui.xml
@@ -39,6 +39,7 @@
<resource name="keyboard2" type="image" filename="keyboard2" />
<resource name="keyboard3" type="image" filename="keyboard3" />
<resource name="keyboard4" type="image" filename="keyboard4" />
+ <resource name="cursor" type="image" filename="cursor" />
</resources>
<variables>
@@ -186,6 +187,12 @@
<variable name="slidervalue_sliderh" value="45" />
</variables>
+ <mousecursor>
+ <placement w="15" h="15" />
+ <background color="#FFFF00FF" resource="cursor" />
+ <speed multiplier="1.5" />
+ </mousecursor>
+
<templates>
<template name="header">
<background color="#000000FF" />
diff --git a/gui/devices/720x1280/res/images/cursor.png b/gui/devices/720x1280/res/images/cursor.png
new file mode 100644
index 000000000..32c8ae1ca
--- /dev/null
+++ b/gui/devices/720x1280/res/images/cursor.png
Binary files differ
diff --git a/gui/devices/720x1280/res/ui.xml b/gui/devices/720x1280/res/ui.xml
index 573bebde6..37003da45 100644
--- a/gui/devices/720x1280/res/ui.xml
+++ b/gui/devices/720x1280/res/ui.xml
@@ -39,6 +39,7 @@
<resource name="keyboard2" type="image" filename="keyboard2" />
<resource name="keyboard3" type="image" filename="keyboard3" />
<resource name="keyboard4" type="image" filename="keyboard4" />
+ <resource name="cursor" type="image" filename="cursor" />
</resources>
<variables>
@@ -191,6 +192,12 @@
<variable name="slidervalue_sliderh" value="60" />
</variables>
+ <mousecursor>
+ <placement w="15" h="15" />
+ <background color="#FFFF00FF" resource="cursor" />
+ <speed multiplier="2" />
+ </mousecursor>
+
<templates>
<template name="header">
<background color="#000000FF" />
diff --git a/gui/devices/800x1280/res/images/cursor.png b/gui/devices/800x1280/res/images/cursor.png
new file mode 100644
index 000000000..32c8ae1ca
--- /dev/null
+++ b/gui/devices/800x1280/res/images/cursor.png
Binary files differ
diff --git a/gui/devices/800x1280/res/ui.xml b/gui/devices/800x1280/res/ui.xml
index fd63d9015..31006e6fa 100755
--- a/gui/devices/800x1280/res/ui.xml
+++ b/gui/devices/800x1280/res/ui.xml
@@ -39,6 +39,7 @@
<resource name="keyboard2" type="image" filename="keyboard2" />
<resource name="keyboard3" type="image" filename="keyboard3" />
<resource name="keyboard4" type="image" filename="keyboard4" />
+ <resource name="cursor" type="image" filename="cursor" />
</resources>
<variables>
@@ -187,6 +188,12 @@
<variable name="slidervalue_sliderh" value="60" />
</variables>
+ <mousecursor>
+ <placement w="15" h="15" />
+ <background color="#FFFF00FF" resource="cursor" />
+ <speed multiplier="2.5" />
+ </mousecursor>
+
<templates>
<template name="header">
<background color="#000000FF" />
diff --git a/gui/devices/800x480/res/images/cursor.png b/gui/devices/800x480/res/images/cursor.png
new file mode 100644
index 000000000..32c8ae1ca
--- /dev/null
+++ b/gui/devices/800x480/res/images/cursor.png
Binary files differ
diff --git a/gui/devices/800x480/res/ui.xml b/gui/devices/800x480/res/ui.xml
index 87a354389..8f881d779 100755
--- a/gui/devices/800x480/res/ui.xml
+++ b/gui/devices/800x480/res/ui.xml
@@ -38,6 +38,7 @@
<resource name="keyboard2" type="image" filename="keyboard2" />
<resource name="keyboard3" type="image" filename="keyboard3" />
<resource name="keyboard4" type="image" filename="keyboard4" />
+ <resource name="cursor" type="image" filename="cursor" />
</resources>
<variables>
@@ -205,6 +206,12 @@
<variable name="slidervalue_sliderh" value="40" />
</variables>
+ <mousecursor>
+ <placement w="15" h="15" />
+ <background color="#FFFF00FF" resource="cursor" />
+ <speed multiplier="1.5" />
+ </mousecursor>
+
<templates>
<template name="header">
<background color="#000000FF" />
diff --git a/gui/gui.cpp b/gui/gui.cpp
index e9efc1db9..2098342b0 100644
--- a/gui/gui.cpp
+++ b/gui/gui.cpp
@@ -186,6 +186,7 @@ static void * input_thread(void *cookie)
static struct timeval touchStart;
HardwareKeyboard kb;
string seconds;
+ MouseCursor *cursor = PageManager::GetMouseCursor();
#ifndef TW_NO_SCREEN_TIMEOUT
//start screen timeout threads
@@ -329,7 +330,47 @@ static void * input_thread(void *cookie)
#ifdef _EVENT_LOGGING
LOGERR("TOUCH_KEY: %d\n", ev.code);
#endif
- if (ev.value != 0)
+ // Left mouse button
+ if(ev.code == BTN_LEFT)
+ {
+ if(ev.value == 1)
+ {
+ cursor->GetPos(x, y);
+
+ if (PageManager::NotifyTouch(TOUCH_START, x, y) > 0)
+ state = 1;
+ drag = 1;
+ touch_and_hold = 1;
+ dontwait = 1;
+ key_repeat = 0;
+ gettimeofday(&touchStart, NULL);
+ }
+ else if(drag == 1)
+ {
+ if (state == 0)
+ {
+ cursor->GetPos(x, y);
+
+ PageManager::NotifyTouch(TOUCH_RELEASE, x, y);
+
+ touch_and_hold = 0;
+ touch_repeat = 0;
+ if (!key_repeat)
+ dontwait = 0;
+ }
+ state = 0;
+ drag = 0;
+ }
+ }
+ // side mouse button, often used for "back" function
+ else if(ev.code == BTN_SIDE)
+ {
+ if(ev.value == 1)
+ kb.KeyDown(KEY_BACK);
+ else
+ kb.KeyUp(KEY_BACK);
+ }
+ else if (ev.value != 0)
{
// This is a key press
if (kb.KeyDown(ev.code))
@@ -367,6 +408,26 @@ static void * input_thread(void *cookie)
#endif
}
}
+ else if(ev.type == EV_REL)
+ {
+#ifdef _EVENT_LOGGING
+ LOGERR("EV_REL %d %d\n", ev.code, ev.value);
+#endif
+ if(ev.code == REL_X)
+ cursor->Move(ev.value, 0);
+ else if(ev.code == REL_Y)
+ cursor->Move(0, ev.value);
+
+ if(drag == 1) {
+ cursor->GetPos(x, y);
+#ifdef _EVENT_LOGGING
+ LOGERR("TOUCH_DRAG: %d, %d\n", x, y);
+#endif
+ if (PageManager::NotifyTouch(TOUCH_DRAG, x, y) > 0)
+ state = 1;
+ key_repeat = 0;
+ }
+ }
}
return NULL;
}
diff --git a/gui/mousecursor.cpp b/gui/mousecursor.cpp
new file mode 100644
index 000000000..1c22356f9
--- /dev/null
+++ b/gui/mousecursor.cpp
@@ -0,0 +1,154 @@
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sys/reboot.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <time.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include <string>
+
+extern "C" {
+#include "../twcommon.h"
+#include "../minuitwrp/minui.h"
+}
+
+#include "rapidxml.hpp"
+#include "objects.hpp"
+
+MouseCursor::MouseCursor(int resX, int resY)
+{
+ ResetData(resX, resY);
+}
+
+MouseCursor::~MouseCursor()
+{
+}
+
+void MouseCursor::ResetData(int resX, int resY)
+{
+ m_resX = resX;
+ m_resY = resY;
+ m_moved = false;
+ m_speedMultiplier = 2.5f;
+ m_image = NULL;
+ m_present = false;
+
+ ConvertStrToColor("red", &m_color);
+
+ SetRenderPos(resX/2, resY/2, 10, 10);
+}
+
+void MouseCursor::LoadData(xml_node<>* node)
+{
+ xml_attribute<>* attr;
+ xml_node<>* child;
+
+ child = node->first_node("placement");
+ if(child)
+ LoadPlacement(child, &mRenderX, &mRenderY, &mRenderW, &mRenderH);
+
+ child = node->first_node("background");
+ if(child)
+ {
+ attr = child->first_attribute("color");
+ if(attr)
+ ConvertStrToColor(attr->value(), &m_color);
+
+ attr = child->first_attribute("resource");
+ if(attr)
+ {
+ m_image = PageManager::FindResource(attr->value());
+ if(m_image)
+ {
+ mRenderW = gr_get_width(m_image->GetResource());
+ mRenderH = gr_get_height(m_image->GetResource());
+ }
+ }
+ }
+
+ child = node->first_node("speed");
+ if(child)
+ {
+ attr = child->first_attribute("multiplier");
+ if(attr)
+ m_speedMultiplier = atof(attr->value());
+ }
+}
+
+int MouseCursor::Render(void)
+{
+ if(!m_present)
+ return 0;
+
+ if(m_image)
+ {
+ gr_blit(m_image->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
+ }
+ else
+ {
+ gr_color(m_color.red, m_color.green, m_color.blue, m_color.alpha);
+ gr_fill(mRenderX, mRenderY, mRenderW, mRenderH);
+ }
+ return 0;
+}
+
+int MouseCursor::Update(void)
+{
+ if(m_present != ev_has_mouse())
+ {
+ m_present = ev_has_mouse();
+ if(m_present)
+ SetRenderPos(m_resX/2, m_resY/2);
+ return 2;
+ }
+
+ if(m_present && m_moved)
+ {
+ m_moved = false;
+ return 2;
+ }
+ return 0;
+}
+
+int MouseCursor::SetRenderPos(int x, int y, int w, int h)
+{
+ if(x == mRenderX && y == mRenderY)
+ m_moved = true;
+
+ return RenderObject::SetRenderPos(x, y, w, h);
+}
+
+void MouseCursor::Move(int deltaX, int deltaY)
+{
+ if(deltaX != 0)
+ {
+ mRenderX += deltaX*m_speedMultiplier;
+ mRenderX = (std::min)(mRenderX, m_resX);
+ mRenderX = (std::max)(mRenderX, 0);
+
+ m_moved = true;
+ }
+
+ if(deltaY != 0)
+ {
+ mRenderY += deltaY*m_speedMultiplier;
+ mRenderY = (std::min)(mRenderY, m_resY);
+ mRenderY = (std::max)(mRenderY, 0);
+
+ m_moved = true;
+ }
+}
+
+void MouseCursor::GetPos(int& x, int& y)
+{
+ x = mRenderX;
+ y = mRenderY;
+}
diff --git a/gui/objects.hpp b/gui/objects.hpp
index 1053113bd..e8110b016 100644
--- a/gui/objects.hpp
+++ b/gui/objects.hpp
@@ -978,6 +978,31 @@ protected:
int lineW;
};
+class MouseCursor : public RenderObject
+{
+public:
+ MouseCursor(int posX, int posY);
+ virtual ~MouseCursor();
+
+ virtual int Render(void);
+ virtual int Update(void);
+ virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
+
+ void Move(int deltaX, int deltaY);
+ void GetPos(int& x, int& y);
+ void LoadData(xml_node<>* node);
+ void ResetData(int resX, int resY);
+
+private:
+ int m_resX;
+ int m_resY;
+ bool m_moved;
+ float m_speedMultiplier;
+ COLOR m_color;
+ Resource *m_image;
+ bool m_present;
+};
+
// Helper APIs
bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w = NULL, int* h = NULL, RenderObject::Placement* placement = NULL);
diff --git a/gui/pages.cpp b/gui/pages.cpp
index d662f18f8..dc9edc798 100644
--- a/gui/pages.cpp
+++ b/gui/pages.cpp
@@ -54,6 +54,7 @@ extern blanktimer blankTimer;
std::map<std::string, PageSet*> PageManager::mPageSets;
PageSet* PageManager::mCurrentSet;
PageSet* PageManager::mBaseSet = NULL;
+MouseCursor *PageManager::mMouseCursor = NULL;
// Helper routine to convert a string to a color declaration
int ConvertStrToColor(std::string str, COLOR* color)
@@ -550,6 +551,11 @@ int PageSet::Load(ZipArchive* package)
if (child)
LoadVariables(child);
+ LOGINFO("Loading mouse cursor...\n");
+ child = parent->first_node("mousecursor");
+ if(child)
+ PageManager::LoadCursorData(child);
+
LOGINFO("Loading pages...\n");
// This may be NULL if no templates are present
templates = parent->first_node("templates");
@@ -849,6 +855,9 @@ int PageManager::ReloadPackage(std::string name, std::string package)
if (iter == mPageSets.end())
return -1;
+ if(mMouseCursor)
+ mMouseCursor->ResetData(gr_fb_width(), gr_fb_height());
+
PageSet* set = (*iter).second;
mPageSets.erase(iter);
@@ -924,7 +933,25 @@ int PageManager::IsCurrentPage(Page* page)
int PageManager::Render(void)
{
- return (mCurrentSet ? mCurrentSet->Render() : -1);
+ int res = (mCurrentSet ? mCurrentSet->Render() : -1);
+ if(mMouseCursor)
+ mMouseCursor->Render();
+ return res;
+}
+
+MouseCursor *PageManager::GetMouseCursor()
+{
+ if(!mMouseCursor)
+ mMouseCursor = new MouseCursor(gr_fb_width(), gr_fb_height());
+ return mMouseCursor;
+}
+
+void PageManager::LoadCursorData(xml_node<>* node)
+{
+ if(!mMouseCursor)
+ mMouseCursor = new MouseCursor(gr_fb_width(), gr_fb_height());
+
+ mMouseCursor->LoadData(node);
}
int PageManager::Update(void)
@@ -933,7 +960,16 @@ int PageManager::Update(void)
if(blankTimer.IsScreenOff())
return 0;
#endif
- return (mCurrentSet ? mCurrentSet->Update() : -1);
+
+ int res = (mCurrentSet ? mCurrentSet->Update() : -1);
+
+ if(mMouseCursor)
+ {
+ int c_res = mMouseCursor->Update();
+ if(c_res > res)
+ res = c_res;
+ }
+ return res;
}
int PageManager::NotifyTouch(TOUCH_STATE state, int x, int y)
diff --git a/gui/pages.hpp b/gui/pages.hpp
index a37cdb9f2..2a2ef2c32 100644
--- a/gui/pages.hpp
+++ b/gui/pages.hpp
@@ -28,6 +28,7 @@ class ResourceManager;
class RenderObject;
class ActionObject;
class InputObject;
+class MouseCursor;
class Page
{
@@ -130,6 +131,9 @@ public:
static int SetKeyBoardFocus(int inFocus);
static int NotifyVarChange(std::string varName, std::string value);
+ static MouseCursor *GetMouseCursor();
+ static void LoadCursorData(xml_node<>* node);
+
protected:
static PageSet* FindPackage(std::string name);
@@ -137,6 +141,7 @@ protected:
static std::map<std::string, PageSet*> mPageSets;
static PageSet* mCurrentSet;
static PageSet* mBaseSet;
+ static MouseCursor *mMouseCursor;
};
#endif // _PAGES_HEADER_HPP