blob: 8c0d438b4f699f188a5f4048fc9f5630458b24a4 [file] [log] [blame]
Matt Mowere04eee72016-12-31 00:38:57 -06001/*
2 Copyright 2017 TeamWin
3 This file is part of TWRP/TeamWin Recovery Project.
4
5 TWRP is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 TWRP is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with TWRP. If not, see <http://www.gnu.org/licenses/>.
17*/
18
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010019#include <stdarg.h>
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
23#include <fcntl.h>
24#include <sys/reboot.h>
25#include <sys/stat.h>
26#include <sys/time.h>
27#include <sys/mman.h>
28#include <sys/types.h>
29#include <sys/ioctl.h>
30#include <time.h>
31#include <unistd.h>
32#include <stdlib.h>
33
34#include <string>
35
36extern "C" {
37#include "../twcommon.h"
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010038}
bigbiffd81833a2021-01-17 11:06:57 -050039#include "minuitwrp/minui.h"
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010040
41#include "rapidxml.hpp"
42#include "objects.hpp"
43
44MouseCursor::MouseCursor(int resX, int resY)
45{
46 ResetData(resX, resY);
47}
48
49MouseCursor::~MouseCursor()
50{
51}
52
53void MouseCursor::ResetData(int resX, int resY)
54{
55 m_resX = resX;
56 m_resY = resY;
57 m_moved = false;
58 m_speedMultiplier = 2.5f;
59 m_image = NULL;
60 m_present = false;
61
62 ConvertStrToColor("red", &m_color);
63
64 SetRenderPos(resX/2, resY/2, 10, 10);
65}
66
67void MouseCursor::LoadData(xml_node<>* node)
68{
69 xml_attribute<>* attr;
70 xml_node<>* child;
71
Ethan Yonker21ff02a2015-02-18 14:35:00 -060072 child = FindNode(node, "placement");
Matt Mowera8a89d12016-12-30 18:10:37 -060073 if (child)
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010074 LoadPlacement(child, &mRenderX, &mRenderY, &mRenderW, &mRenderH);
75
Ethan Yonker21ff02a2015-02-18 14:35:00 -060076 child = FindNode(node, "background");
Matt Mowera8a89d12016-12-30 18:10:37 -060077 if (child)
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010078 {
thatf6ed8fc2015-02-14 20:23:16 +010079 m_color = LoadAttrColor(child, "color", m_color);
80 m_image = LoadAttrImage(child, "resource");
Ethan Yonker58f21322018-08-24 11:17:36 -050081 if (m_image && m_image->GetResource())
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010082 {
thatf6ed8fc2015-02-14 20:23:16 +010083 mRenderW = m_image->GetWidth();
84 mRenderH = m_image->GetHeight();
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010085 }
86 }
87
Ethan Yonker21ff02a2015-02-18 14:35:00 -060088 child = FindNode(node, "speed");
Matt Mowera8a89d12016-12-30 18:10:37 -060089 if (child)
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010090 {
91 attr = child->first_attribute("multiplier");
Matt Mowera8a89d12016-12-30 18:10:37 -060092 if (attr)
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010093 m_speedMultiplier = atof(attr->value());
94 }
95}
96
97int MouseCursor::Render(void)
98{
Matt Mowera8a89d12016-12-30 18:10:37 -060099 if (!m_present)
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100100 return 0;
101
Ethan Yonker58f21322018-08-24 11:17:36 -0500102 if (m_image && m_image->GetResource())
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100103 {
104 gr_blit(m_image->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
105 }
106 else
107 {
108 gr_color(m_color.red, m_color.green, m_color.blue, m_color.alpha);
109 gr_fill(mRenderX, mRenderY, mRenderW, mRenderH);
110 }
111 return 0;
112}
113
114int MouseCursor::Update(void)
115{
Matt Mowera8a89d12016-12-30 18:10:37 -0600116 if (m_present != ev_has_mouse())
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100117 {
118 m_present = ev_has_mouse();
Matt Mowera8a89d12016-12-30 18:10:37 -0600119 if (m_present)
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100120 SetRenderPos(m_resX/2, m_resY/2);
121 return 2;
122 }
123
Matt Mowera8a89d12016-12-30 18:10:37 -0600124 if (m_present && m_moved)
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100125 {
126 m_moved = false;
127 return 2;
128 }
129 return 0;
130}
131
132int MouseCursor::SetRenderPos(int x, int y, int w, int h)
133{
Matt Mowera8a89d12016-12-30 18:10:37 -0600134 if (x == mRenderX && y == mRenderY)
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100135 m_moved = true;
136
137 return RenderObject::SetRenderPos(x, y, w, h);
138}
139
140void MouseCursor::Move(int deltaX, int deltaY)
141{
Matt Mowera8a89d12016-12-30 18:10:37 -0600142 if (deltaX != 0)
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100143 {
144 mRenderX += deltaX*m_speedMultiplier;
145 mRenderX = (std::min)(mRenderX, m_resX);
146 mRenderX = (std::max)(mRenderX, 0);
147
148 m_moved = true;
149 }
150
Matt Mowera8a89d12016-12-30 18:10:37 -0600151 if (deltaY != 0)
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100152 {
153 mRenderY += deltaY*m_speedMultiplier;
154 mRenderY = (std::min)(mRenderY, m_resY);
155 mRenderY = (std::max)(mRenderY, 0);
156
157 m_moved = true;
158 }
159}
160
161void MouseCursor::GetPos(int& x, int& y)
162{
163 x = mRenderX;
164 y = mRenderY;
165}