summaryrefslogtreecommitdiffstats
path: root/gui/mousecursor.cpp
diff options
context:
space:
mode:
authorVojtech Bocek <vbocek@gmail.com>2014-01-29 18:37:19 +0100
committerEthan Yonker <dees_troy@teamw.in>2014-02-07 19:37:13 +0100
commit1fc30fc77b5588c4b651085c21003aceb4ec5083 (patch)
treee8f522b1aa1150095bc0e440039c1a5b8205ab0c /gui/mousecursor.cpp
parentExpansion of vibrate options (diff)
downloadandroid_bootable_recovery-1fc30fc77b5588c4b651085c21003aceb4ec5083.tar
android_bootable_recovery-1fc30fc77b5588c4b651085c21003aceb4ec5083.tar.gz
android_bootable_recovery-1fc30fc77b5588c4b651085c21003aceb4ec5083.tar.bz2
android_bootable_recovery-1fc30fc77b5588c4b651085c21003aceb4ec5083.tar.lz
android_bootable_recovery-1fc30fc77b5588c4b651085c21003aceb4ec5083.tar.xz
android_bootable_recovery-1fc30fc77b5588c4b651085c21003aceb4ec5083.tar.zst
android_bootable_recovery-1fc30fc77b5588c4b651085c21003aceb4ec5083.zip
Diffstat (limited to 'gui/mousecursor.cpp')
-rw-r--r--gui/mousecursor.cpp154
1 files changed, 154 insertions, 0 deletions
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;
+}