blob: c684d1b5389f1f28dbb0c309a7cdab66da828c13 [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" {
Dees_Troy2673cec2013-04-02 20:22:16 +000021#include "../twcommon.h"
Dees_Troy51a0e822012-09-05 15:24:24 -040022#include "../minuitwrp/minui.h"
Dees_Troy51a0e822012-09-05 15:24:24 -040023}
24
25#include "rapidxml.hpp"
26#include "objects.hpp"
27
28GUIImage::GUIImage(xml_node<>* node)
29{
30 xml_attribute<>* attr;
31 xml_node<>* child;
32
33 mImage = NULL;
Dees_Troy4d12f962012-10-19 13:13:15 -040034 mHighlightImage = NULL;
35 isHighlighted = false;
Dees_Troy51a0e822012-09-05 15:24:24 -040036
37 if (!node)
38 return;
39
40 child = node->first_node("image");
41 if (child)
42 {
43 attr = child->first_attribute("resource");
44 if (attr)
45 mImage = PageManager::FindResource(attr->value());
Dees_Troy4d12f962012-10-19 13:13:15 -040046 attr = child->first_attribute("highlightresource");
47 if (attr)
48 mHighlightImage = PageManager::FindResource(attr->value());
Dees_Troy51a0e822012-09-05 15:24:24 -040049 }
50
51 // Load the placement
52 LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, NULL, NULL, &mPlacement);
53
54 if (mImage && mImage->GetResource())
55 {
56 mRenderW = gr_get_width(mImage->GetResource());
57 mRenderH = gr_get_height(mImage->GetResource());
58
59 // Adjust for placement
60 if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT)
61 {
62 if (mPlacement == CENTER)
63 mRenderX -= (mRenderW / 2);
64 else
65 mRenderX -= mRenderW;
66 }
67 if (mPlacement != TOP_LEFT && mPlacement != TOP_RIGHT)
68 {
69 if (mPlacement == CENTER)
70 mRenderY -= (mRenderH / 2);
71 else
72 mRenderY -= mRenderH;
73 }
74 SetPlacement(TOP_LEFT);
75 }
76
77 return;
78}
79
80int GUIImage::Render(void)
81{
Dees_Troy4d12f962012-10-19 13:13:15 -040082 if (isHighlighted && mHighlightImage && mHighlightImage->GetResource()) {
83 gr_blit(mHighlightImage->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
84 return 0;
85 } else if (!mImage || !mImage->GetResource()) return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -040086 gr_blit(mImage->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
87 return 0;
88}
89
90int GUIImage::SetRenderPos(int x, int y, int w, int h)
91{
92 if (w || h) return -1;
93 mRenderX = x;
94 mRenderY = y;
95 return 0;
96}
97