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 | xml_attribute<>* attr; |
| 31 | xml_node<>* child; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 32 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 33 | mImage = NULL; |
Dees_Troy | 4d12f96 | 2012-10-19 13:13:15 -0400 | [diff] [blame] | 34 | mHighlightImage = NULL; |
| 35 | isHighlighted = false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 36 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 37 | if (!node) |
| 38 | return; |
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 | child = node->first_node("image"); |
| 41 | if (child) |
| 42 | { |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 43 | mImage = LoadAttrImage(child, "resource"); |
| 44 | mHighlightImage = LoadAttrImage(child, "highlightresource"); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 45 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 46 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 47 | // Load the placement |
| 48 | LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, NULL, NULL, &mPlacement); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 49 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 50 | if (mImage && mImage->GetResource()) |
| 51 | { |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 52 | mRenderW = mImage->GetWidth(); |
| 53 | mRenderH = mImage->GetHeight(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 54 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 55 | // 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | int GUIImage::Render(void) |
| 75 | { |
Vojtech Bocek | 6041a78 | 2013-10-11 14:40:01 +0200 | [diff] [blame] | 76 | if (!isConditionTrue()) |
| 77 | return 0; |
| 78 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 79 | if (isHighlighted && mHighlightImage && mHighlightImage->GetResource()) { |
Dees_Troy | 4d12f96 | 2012-10-19 13:13:15 -0400 | [diff] [blame] | 80 | gr_blit(mHighlightImage->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY); |
| 81 | return 0; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 82 | } |
| 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | int GUIImage::SetRenderPos(int x, int y, int w, int h) |
| 91 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 92 | if (w || h) |
| 93 | return -1; |
| 94 | |
| 95 | mRenderX = x; |
| 96 | mRenderY = y; |
| 97 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 98 | } |
| 99 | |