blob: 60b1cb956411a048734dcd9fc1217ad71b70df78 [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 {
thatf6ed8fc2015-02-14 20:23:16 +010043 mImage = LoadAttrImage(child, "resource");
44 mHighlightImage = LoadAttrImage(child, "highlightresource");
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020045 }
Dees_Troy51a0e822012-09-05 15:24:24 -040046
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020047 // Load the placement
48 LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, NULL, NULL, &mPlacement);
Dees_Troy51a0e822012-09-05 15:24:24 -040049
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020050 if (mImage && mImage->GetResource())
51 {
thatf6ed8fc2015-02-14 20:23:16 +010052 mRenderW = mImage->GetWidth();
53 mRenderH = mImage->GetHeight();
Dees_Troy51a0e822012-09-05 15:24:24 -040054
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020055 // 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 }
Dees_Troy51a0e822012-09-05 15:24:24 -040072}
73
74int GUIImage::Render(void)
75{
Vojtech Bocek6041a782013-10-11 14:40:01 +020076 if (!isConditionTrue())
77 return 0;
78
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020079 if (isHighlighted && mHighlightImage && mHighlightImage->GetResource()) {
Dees_Troy4d12f962012-10-19 13:13:15 -040080 gr_blit(mHighlightImage->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
81 return 0;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020082 }
83 else if (!mImage || !mImage->GetResource())
84 return -1;
85
86 gr_blit(mImage->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
87 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -040088}
89
90int GUIImage::SetRenderPos(int x, int y, int w, int h)
91{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020092 if (w || h)
93 return -1;
94
95 mRenderX = x;
96 mRenderY = y;
97 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -040098}
99