Matt Mower | e04eee7 | 2016-12-31 00:38:57 -0600 | [diff] [blame] | 1 | /* |
| 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 Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 19 | #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 | |
| 36 | extern "C" { |
| 37 | #include "../twcommon.h" |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 38 | } |
bigbiff | d81833a | 2021-01-17 11:06:57 -0500 | [diff] [blame] | 39 | #include "minuitwrp/minui.h" |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 40 | |
| 41 | #include "rapidxml.hpp" |
| 42 | #include "objects.hpp" |
| 43 | |
| 44 | MouseCursor::MouseCursor(int resX, int resY) |
| 45 | { |
| 46 | ResetData(resX, resY); |
| 47 | } |
| 48 | |
| 49 | MouseCursor::~MouseCursor() |
| 50 | { |
| 51 | } |
| 52 | |
| 53 | void 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 | |
| 67 | void MouseCursor::LoadData(xml_node<>* node) |
| 68 | { |
| 69 | xml_attribute<>* attr; |
| 70 | xml_node<>* child; |
| 71 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 72 | child = FindNode(node, "placement"); |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 73 | if (child) |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 74 | LoadPlacement(child, &mRenderX, &mRenderY, &mRenderW, &mRenderH); |
| 75 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 76 | child = FindNode(node, "background"); |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 77 | if (child) |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 78 | { |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 79 | m_color = LoadAttrColor(child, "color", m_color); |
| 80 | m_image = LoadAttrImage(child, "resource"); |
Ethan Yonker | 58f2132 | 2018-08-24 11:17:36 -0500 | [diff] [blame] | 81 | if (m_image && m_image->GetResource()) |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 82 | { |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 83 | mRenderW = m_image->GetWidth(); |
| 84 | mRenderH = m_image->GetHeight(); |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 88 | child = FindNode(node, "speed"); |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 89 | if (child) |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 90 | { |
| 91 | attr = child->first_attribute("multiplier"); |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 92 | if (attr) |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 93 | m_speedMultiplier = atof(attr->value()); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | int MouseCursor::Render(void) |
| 98 | { |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 99 | if (!m_present) |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 100 | return 0; |
| 101 | |
Ethan Yonker | 58f2132 | 2018-08-24 11:17:36 -0500 | [diff] [blame] | 102 | if (m_image && m_image->GetResource()) |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 103 | { |
| 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 | |
| 114 | int MouseCursor::Update(void) |
| 115 | { |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 116 | if (m_present != ev_has_mouse()) |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 117 | { |
| 118 | m_present = ev_has_mouse(); |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 119 | if (m_present) |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 120 | SetRenderPos(m_resX/2, m_resY/2); |
| 121 | return 2; |
| 122 | } |
| 123 | |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 124 | if (m_present && m_moved) |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 125 | { |
| 126 | m_moved = false; |
| 127 | return 2; |
| 128 | } |
| 129 | return 0; |
| 130 | } |
| 131 | |
| 132 | int MouseCursor::SetRenderPos(int x, int y, int w, int h) |
| 133 | { |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 134 | if (x == mRenderX && y == mRenderY) |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 135 | m_moved = true; |
| 136 | |
| 137 | return RenderObject::SetRenderPos(x, y, w, h); |
| 138 | } |
| 139 | |
| 140 | void MouseCursor::Move(int deltaX, int deltaY) |
| 141 | { |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 142 | if (deltaX != 0) |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 143 | { |
| 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 Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 151 | if (deltaY != 0) |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 152 | { |
| 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 | |
| 161 | void MouseCursor::GetPos(int& x, int& y) |
| 162 | { |
| 163 | x = mRenderX; |
| 164 | y = mRenderY; |
| 165 | } |