blob: 8b43aaa343cfda55163a16c6f859b2ca30c536ad [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 mImage = NULL;
Dees_Troy4d12f962012-10-19 13:13:15 -040031 mHighlightImage = NULL;
32 isHighlighted = false;
Dees_Troy51a0e822012-09-05 15:24:24 -040033
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020034 if (!node)
35 return;
Dees_Troy51a0e822012-09-05 15:24:24 -040036
Ethan Yonker21ff02a2015-02-18 14:35:00 -060037 mImage = LoadAttrImage(FindNode(node, "image"), "resource");
38 mHighlightImage = LoadAttrImage(FindNode(node, "image"), "highlightresource");
Dees_Troy51a0e822012-09-05 15:24:24 -040039
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020040 // Load the placement
Ethan Yonker21ff02a2015-02-18 14:35:00 -060041 LoadPlacement(FindNode(node, "placement"), &mRenderX, &mRenderY, NULL, NULL, &mPlacement);
Dees_Troy51a0e822012-09-05 15:24:24 -040042
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020043 if (mImage && mImage->GetResource())
44 {
thatf6ed8fc2015-02-14 20:23:16 +010045 mRenderW = mImage->GetWidth();
46 mRenderH = mImage->GetHeight();
Dees_Troy51a0e822012-09-05 15:24:24 -040047
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020048 // Adjust for placement
49 if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT)
50 {
51 if (mPlacement == CENTER)
52 mRenderX -= (mRenderW / 2);
53 else
54 mRenderX -= mRenderW;
55 }
56 if (mPlacement != TOP_LEFT && mPlacement != TOP_RIGHT)
57 {
58 if (mPlacement == CENTER)
59 mRenderY -= (mRenderH / 2);
60 else
61 mRenderY -= mRenderH;
62 }
63 SetPlacement(TOP_LEFT);
64 }
Dees_Troy51a0e822012-09-05 15:24:24 -040065}
66
67int GUIImage::Render(void)
68{
Vojtech Bocek6041a782013-10-11 14:40:01 +020069 if (!isConditionTrue())
70 return 0;
71
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020072 if (isHighlighted && mHighlightImage && mHighlightImage->GetResource()) {
Dees_Troy4d12f962012-10-19 13:13:15 -040073 gr_blit(mHighlightImage->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
74 return 0;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020075 }
76 else if (!mImage || !mImage->GetResource())
77 return -1;
78
79 gr_blit(mImage->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
80 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -040081}
82
83int GUIImage::SetRenderPos(int x, int y, int w, int h)
84{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020085 if (w || h)
86 return -1;
87
88 mRenderX = x;
89 mRenderY = y;
90 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -040091}
92