blob: cb5e11b754d42c6576ebb53d5231520b6e9db00b [file] [log] [blame]
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +01001#include <stdarg.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include <fcntl.h>
6#include <sys/reboot.h>
7#include <sys/stat.h>
8#include <sys/time.h>
9#include <sys/mman.h>
10#include <sys/types.h>
11#include <sys/ioctl.h>
12#include <time.h>
13#include <unistd.h>
14#include <stdlib.h>
15
16#include <string>
17
18extern "C" {
19#include "../twcommon.h"
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010020}
Ethan Yonkerfbb43532015-12-28 21:54:50 +010021#include "../minuitwrp/minui.h"
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010022
23#include "rapidxml.hpp"
24#include "objects.hpp"
25
26MouseCursor::MouseCursor(int resX, int resY)
27{
28 ResetData(resX, resY);
29}
30
31MouseCursor::~MouseCursor()
32{
33}
34
35void MouseCursor::ResetData(int resX, int resY)
36{
37 m_resX = resX;
38 m_resY = resY;
39 m_moved = false;
40 m_speedMultiplier = 2.5f;
41 m_image = NULL;
42 m_present = false;
43
44 ConvertStrToColor("red", &m_color);
45
46 SetRenderPos(resX/2, resY/2, 10, 10);
47}
48
49void MouseCursor::LoadData(xml_node<>* node)
50{
51 xml_attribute<>* attr;
52 xml_node<>* child;
53
Ethan Yonker21ff02a2015-02-18 14:35:00 -060054 child = FindNode(node, "placement");
Matt Mowera8a89d12016-12-30 18:10:37 -060055 if (child)
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010056 LoadPlacement(child, &mRenderX, &mRenderY, &mRenderW, &mRenderH);
57
Ethan Yonker21ff02a2015-02-18 14:35:00 -060058 child = FindNode(node, "background");
Matt Mowera8a89d12016-12-30 18:10:37 -060059 if (child)
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010060 {
thatf6ed8fc2015-02-14 20:23:16 +010061 m_color = LoadAttrColor(child, "color", m_color);
62 m_image = LoadAttrImage(child, "resource");
Matt Mowera8a89d12016-12-30 18:10:37 -060063 if (m_image)
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010064 {
thatf6ed8fc2015-02-14 20:23:16 +010065 mRenderW = m_image->GetWidth();
66 mRenderH = m_image->GetHeight();
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010067 }
68 }
69
Ethan Yonker21ff02a2015-02-18 14:35:00 -060070 child = FindNode(node, "speed");
Matt Mowera8a89d12016-12-30 18:10:37 -060071 if (child)
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010072 {
73 attr = child->first_attribute("multiplier");
Matt Mowera8a89d12016-12-30 18:10:37 -060074 if (attr)
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010075 m_speedMultiplier = atof(attr->value());
76 }
77}
78
79int MouseCursor::Render(void)
80{
Matt Mowera8a89d12016-12-30 18:10:37 -060081 if (!m_present)
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010082 return 0;
83
Matt Mowera8a89d12016-12-30 18:10:37 -060084 if (m_image)
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010085 {
86 gr_blit(m_image->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
87 }
88 else
89 {
90 gr_color(m_color.red, m_color.green, m_color.blue, m_color.alpha);
91 gr_fill(mRenderX, mRenderY, mRenderW, mRenderH);
92 }
93 return 0;
94}
95
96int MouseCursor::Update(void)
97{
Matt Mowera8a89d12016-12-30 18:10:37 -060098 if (m_present != ev_has_mouse())
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010099 {
100 m_present = ev_has_mouse();
Matt Mowera8a89d12016-12-30 18:10:37 -0600101 if (m_present)
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100102 SetRenderPos(m_resX/2, m_resY/2);
103 return 2;
104 }
105
Matt Mowera8a89d12016-12-30 18:10:37 -0600106 if (m_present && m_moved)
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100107 {
108 m_moved = false;
109 return 2;
110 }
111 return 0;
112}
113
114int MouseCursor::SetRenderPos(int x, int y, int w, int h)
115{
Matt Mowera8a89d12016-12-30 18:10:37 -0600116 if (x == mRenderX && y == mRenderY)
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100117 m_moved = true;
118
119 return RenderObject::SetRenderPos(x, y, w, h);
120}
121
122void MouseCursor::Move(int deltaX, int deltaY)
123{
Matt Mowera8a89d12016-12-30 18:10:37 -0600124 if (deltaX != 0)
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100125 {
126 mRenderX += deltaX*m_speedMultiplier;
127 mRenderX = (std::min)(mRenderX, m_resX);
128 mRenderX = (std::max)(mRenderX, 0);
129
130 m_moved = true;
131 }
132
Matt Mowera8a89d12016-12-30 18:10:37 -0600133 if (deltaY != 0)
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100134 {
135 mRenderY += deltaY*m_speedMultiplier;
136 mRenderY = (std::min)(mRenderY, m_resY);
137 mRenderY = (std::max)(mRenderY, 0);
138
139 m_moved = true;
140 }
141}
142
143void MouseCursor::GetPos(int& x, int& y)
144{
145 x = mRenderX;
146 y = mRenderY;
147}