Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1 | // 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 | |
| 20 | extern "C" { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 21 | #include "../twcommon.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 22 | #include "../minuitwrp/minui.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | #include "rapidxml.hpp" |
| 26 | #include "objects.hpp" |
| 27 | |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 28 | GUIImage::GUIImage(xml_node<>* node) : GUIObject(node) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 29 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 30 | mImage = NULL; |
Dees_Troy | 4d12f96 | 2012-10-19 13:13:15 -0400 | [diff] [blame] | 31 | mHighlightImage = NULL; |
| 32 | isHighlighted = false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 33 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 34 | if (!node) |
| 35 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 36 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 37 | mImage = LoadAttrImage(FindNode(node, "image"), "resource"); |
| 38 | mHighlightImage = LoadAttrImage(FindNode(node, "image"), "highlightresource"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 39 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 40 | // Load the placement |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 41 | LoadPlacement(FindNode(node, "placement"), &mRenderX, &mRenderY, NULL, NULL, &mPlacement); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 42 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 43 | if (mImage && mImage->GetResource()) |
| 44 | { |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 45 | mRenderW = mImage->GetWidth(); |
| 46 | mRenderH = mImage->GetHeight(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 47 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 48 | // 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | int GUIImage::Render(void) |
| 68 | { |
Vojtech Bocek | 6041a78 | 2013-10-11 14:40:01 +0200 | [diff] [blame] | 69 | if (!isConditionTrue()) |
| 70 | return 0; |
| 71 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 72 | if (isHighlighted && mHighlightImage && mHighlightImage->GetResource()) { |
Dees_Troy | 4d12f96 | 2012-10-19 13:13:15 -0400 | [diff] [blame] | 73 | gr_blit(mHighlightImage->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY); |
| 74 | return 0; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 75 | } |
| 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | int GUIImage::SetRenderPos(int x, int y, int w, int h) |
| 84 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 85 | if (w || h) |
| 86 | return -1; |
| 87 | |
| 88 | mRenderX = x; |
| 89 | mRenderY = y; |
| 90 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 91 | } |
| 92 | |