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 | |
| 28 | GUIImage::GUIImage(xml_node<>* node) |
| 29 | { |
| 30 | xml_attribute<>* attr; |
| 31 | xml_node<>* child; |
| 32 | |
| 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 | |
| 37 | if (!node) |
| 38 | return; |
| 39 | |
| 40 | 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_Troy | 4d12f96 | 2012-10-19 13:13:15 -0400 | [diff] [blame] | 46 | attr = child->first_attribute("highlightresource"); |
| 47 | if (attr) |
| 48 | mHighlightImage = PageManager::FindResource(attr->value()); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | // Load the placement |
| 52 | LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, NULL, NULL, &mPlacement); |
| 53 | |
| 54 | if (mImage && mImage->GetResource()) |
| 55 | { |
| 56 | mRenderW = gr_get_width(mImage->GetResource()); |
| 57 | mRenderH = gr_get_height(mImage->GetResource()); |
| 58 | |
| 59 | // 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 | } |
| 76 | |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | int GUIImage::Render(void) |
| 81 | { |
Dees_Troy | 4d12f96 | 2012-10-19 13:13:15 -0400 | [diff] [blame] | 82 | if (isHighlighted && mHighlightImage && mHighlightImage->GetResource()) { |
| 83 | gr_blit(mHighlightImage->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY); |
| 84 | return 0; |
| 85 | } else if (!mImage || !mImage->GetResource()) return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 86 | gr_blit(mImage->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY); |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | int GUIImage::SetRenderPos(int x, int y, int w, int h) |
| 91 | { |
| 92 | if (w || h) return -1; |
| 93 | mRenderX = x; |
| 94 | mRenderY = y; |
| 95 | return 0; |
| 96 | } |
| 97 | |