blob: 2cf3b68af081d5f7b031d1772394d39792589260 [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
Vojtech Bocekede51c52014-02-07 23:58:09 +010028GUIImage::GUIImage(xml_node<>* node) : GUIObject(node)
Dees_Troy51a0e822012-09-05 15:24:24 -040029{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020030 xml_attribute<>* attr;
31 xml_node<>* child;
Dees_Troy51a0e822012-09-05 15:24:24 -040032
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020033 mImage = NULL;
Dees_Troy4d12f962012-10-19 13:13:15 -040034 mHighlightImage = NULL;
35 isHighlighted = false;
Dees_Troy51a0e822012-09-05 15:24:24 -040036
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020037 if (!node)
38 return;
Dees_Troy51a0e822012-09-05 15:24:24 -040039
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020040 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");
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020047 if (attr)
48 mHighlightImage = PageManager::FindResource(attr->value());
49 }
Dees_Troy51a0e822012-09-05 15:24:24 -040050
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020051 // Load the placement
52 LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, NULL, NULL, &mPlacement);
Dees_Troy51a0e822012-09-05 15:24:24 -040053
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020054 if (mImage && mImage->GetResource())
55 {
56 mRenderW = gr_get_width(mImage->GetResource());
57 mRenderH = gr_get_height(mImage->GetResource());
Dees_Troy51a0e822012-09-05 15:24:24 -040058
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020059 // 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 }
Dees_Troy51a0e822012-09-05 15:24:24 -040076
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020077 return;
Dees_Troy51a0e822012-09-05 15:24:24 -040078}
79
80int GUIImage::Render(void)
81{
Vojtech Bocek6041a782013-10-11 14:40:01 +020082 if (!isConditionTrue())
83 return 0;
84
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020085 if (isHighlighted && mHighlightImage && mHighlightImage->GetResource()) {
Dees_Troy4d12f962012-10-19 13:13:15 -040086 gr_blit(mHighlightImage->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
87 return 0;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020088 }
89 else if (!mImage || !mImage->GetResource())
90 return -1;
91
92 gr_blit(mImage->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
93 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -040094}
95
96int GUIImage::SetRenderPos(int x, int y, int w, int h)
97{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020098 if (w || h)
99 return -1;
100
101 mRenderX = x;
102 mRenderY = y;
103 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400104}
105