blob: 45d863673996457868f74657c55c6573c8f2b336 [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{
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 Bocekfafb0c52013-07-25 22:53:02 +020082 if (isHighlighted && mHighlightImage && mHighlightImage->GetResource()) {
Dees_Troy4d12f962012-10-19 13:13:15 -040083 gr_blit(mHighlightImage->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
84 return 0;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020085 }
86 else if (!mImage || !mImage->GetResource())
87 return -1;
88
89 gr_blit(mImage->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
90 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -040091}
92
93int GUIImage::SetRenderPos(int x, int y, int w, int h)
94{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020095 if (w || h)
96 return -1;
97
98 mRenderX = x;
99 mRenderY = y;
100 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400101}
102