A basic graphics package for the LPC4088 Display Module.

Dependents:   lpc4088_displaymodule_demo_sphere sampleGUI sampleEmptyGUI lpc4088_displaymodule_fs_aid ... more

Fork of DMBasicGUI by EmbeddedArtists AB

Revision:
3:3fabfe3339b8
Parent:
2:efae611de184
Child:
4:a73760d09423
--- a/Application/ImageButton.cpp	Fri Dec 19 07:37:24 2014 +0000
+++ b/Application/ImageButton.cpp	Fri Dec 19 09:12:51 2014 +0100
@@ -20,20 +20,11 @@
 
 #include "lpc_swim_image.h"
 
-ImageButton::ImageButton(COLOR_T* fb, uint16_t x, uint16_t y, uint16_t width, uint16_t height, const char* imgUp, const char* imgDown) :
+ImageButton::ImageButton(COLOR_T* fb, uint16_t x, uint16_t y, uint16_t width, uint16_t height) :
   Clickable(fb, x, y, width, height)
 {
   _imgUp.pixels = NULL;
   _imgDown.pixels = NULL;
-  
-  if (Image::decode(imgUp, Image::RES_16BIT, &_imgUp) != 0) {
-    DMBoard::instance().logger()->printf("Failed to load %s\n", imgUp);
-  }
-  if (imgDown != NULL) {
-    if (Image::decode(imgDown, Image::RES_16BIT, &_imgDown) == 0) {
-      DMBoard::instance().logger()->printf("Failed to load %s\n", imgDown);
-    }
-  }
 }
 
 ImageButton::~ImageButton()
@@ -48,6 +39,29 @@
   }
 }
 
+bool ImageButton::loadImages(const char* imgUp, const char* imgDown)
+{
+  if (_imgUp.pixels != NULL) {
+    free(_imgUp.pixels);
+    _imgUp.pixels = NULL;
+  }
+  if (_imgDown.pixels != NULL) {
+    free(_imgDown.pixels);
+    _imgDown.pixels = NULL;
+  }
+  if (Image::decode(imgUp, Image::RES_16BIT, &_imgUp) != 0) {
+    DMBoard::instance().logger()->printf("Failed to load %s\n", imgUp);
+    return false;
+  }
+  if (imgDown != NULL) {
+    if (Image::decode(imgDown, Image::RES_16BIT, &_imgDown) == 0) {
+      DMBoard::instance().logger()->printf("Failed to load %s\n", imgDown);
+      return false;
+    }
+  }
+  return true;
+}
+
 void ImageButton::draw()
 {
   if (_pressed) {
@@ -55,6 +69,8 @@
       swim_put_image(&_win, _imgDown.pixels, _imgDown.width, _imgDown.height);
     }
   } else {
-    swim_put_image(&_win, _imgUp.pixels, _imgUp.width, _imgUp.height);
+    if (_imgUp.pixels != NULL) {
+      swim_put_image(&_win, _imgUp.pixels, _imgUp.width, _imgUp.height);
+    }
   }
 }