blob: 05e5178678ddd027ae5af369c2caf319526f010d [file] [log] [blame]
Dees_Troy51a0e822012-09-05 15:24:24 -04001// image.cpp - GUIImage object
2
3#include <stdarg.h>
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7#include <fcntl.h>
8#include <sys/reboot.h>
9#include <sys/stat.h>
10#include <sys/time.h>
11#include <sys/mman.h>
12#include <sys/types.h>
13#include <sys/ioctl.h>
14#include <time.h>
15#include <unistd.h>
16#include <stdlib.h>
17
18#include <string>
19
20extern "C" {
21#include "../common.h"
22#include "../minuitwrp/minui.h"
23#include "../recovery_ui.h"
24}
25
26#include "rapidxml.hpp"
27#include "objects.hpp"
28
29GUIImage::GUIImage(xml_node<>* node)
30{
31 xml_attribute<>* attr;
32 xml_node<>* child;
33
34 mImage = NULL;
Dees_Troy4d12f962012-10-19 13:13:15 -040035 mHighlightImage = NULL;
36 isHighlighted = false;
Dees_Troy51a0e822012-09-05 15:24:24 -040037
38 if (!node)
39 return;
40
41 child = node->first_node("image");
42 if (child)
43 {
44 attr = child->first_attribute("resource");
45 if (attr)
46 mImage = PageManager::FindResource(attr->value());
Dees_Troy4d12f962012-10-19 13:13:15 -040047 attr = child->first_attribute("highlightresource");
48 if (attr)
49 mHighlightImage = PageManager::FindResource(attr->value());
Dees_Troy51a0e822012-09-05 15:24:24 -040050 }
51
52 // Load the placement
53 LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, NULL, NULL, &mPlacement);
54
55 if (mImage && mImage->GetResource())
56 {
57 mRenderW = gr_get_width(mImage->GetResource());
58 mRenderH = gr_get_height(mImage->GetResource());
59
60 // Adjust for placement
61 if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT)
62 {
63 if (mPlacement == CENTER)
64 mRenderX -= (mRenderW / 2);
65 else
66 mRenderX -= mRenderW;
67 }
68 if (mPlacement != TOP_LEFT && mPlacement != TOP_RIGHT)
69 {
70 if (mPlacement == CENTER)
71 mRenderY -= (mRenderH / 2);
72 else
73 mRenderY -= mRenderH;
74 }
75 SetPlacement(TOP_LEFT);
76 }
77
78 return;
79}
80
81int GUIImage::Render(void)
82{
Dees_Troy4d12f962012-10-19 13:13:15 -040083 if (isHighlighted && mHighlightImage && mHighlightImage->GetResource()) {
84 gr_blit(mHighlightImage->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
85 return 0;
86 } else if (!mImage || !mImage->GetResource()) return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -040087 gr_blit(mImage->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
88 return 0;
89}
90
91int GUIImage::SetRenderPos(int x, int y, int w, int h)
92{
93 if (w || h) return -1;
94 mRenderX = x;
95 mRenderY = y;
96 return 0;
97}
98