blob: 44400e6266d7405e1b982e95f89476df50c69652 [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;
35
36 if (!node)
37 return;
38
39 child = node->first_node("image");
40 if (child)
41 {
42 attr = child->first_attribute("resource");
43 if (attr)
44 mImage = PageManager::FindResource(attr->value());
45 }
46
47 // Load the placement
48 LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, NULL, NULL, &mPlacement);
49
50 if (mImage && mImage->GetResource())
51 {
52 mRenderW = gr_get_width(mImage->GetResource());
53 mRenderH = gr_get_height(mImage->GetResource());
54
55 // Adjust for placement
56 if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT)
57 {
58 if (mPlacement == CENTER)
59 mRenderX -= (mRenderW / 2);
60 else
61 mRenderX -= mRenderW;
62 }
63 if (mPlacement != TOP_LEFT && mPlacement != TOP_RIGHT)
64 {
65 if (mPlacement == CENTER)
66 mRenderY -= (mRenderH / 2);
67 else
68 mRenderY -= mRenderH;
69 }
70 SetPlacement(TOP_LEFT);
71 }
72
73 return;
74}
75
76int GUIImage::Render(void)
77{
78 if (!mImage || !mImage->GetResource()) return -1;
79 gr_blit(mImage->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
80 return 0;
81}
82
83int GUIImage::SetRenderPos(int x, int y, int w, int h)
84{
85 if (w || h) return -1;
86 mRenderX = x;
87 mRenderY = y;
88 return 0;
89}
90