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:
11:265884fa7fdd
Parent:
9:ce69a7adfe9c
Child:
17:6e2abf107800
--- a/Application/ImageButton.cpp	Mon Jan 26 10:06:58 2015 +0100
+++ b/Application/ImageButton.cpp	Tue Feb 17 10:34:13 2015 +0100
@@ -19,14 +19,27 @@
 #include "DMBoard.h"
 
 #include "lpc_swim_image.h"
+#include "lpc_swim_font.h"
+#include "lpc_colors.h"
 
-ImageButton::ImageButton(COLOR_T* fb, uint16_t x, uint16_t y, uint16_t width, uint16_t height) :
-  Clickable(fb, x, y, width, height)
+ImageButton::ImageButton(COLOR_T* fb, uint16_t x, uint16_t y, uint16_t width, uint16_t height,
+                         const char* caption, COLOR_T color) :
+  Clickable(fb, x, y, width, height+(caption==NULL?0:20))
 {
   _imgUp.pointerToFree = NULL;
   _imgUp.pixels = NULL;
   _imgDown.pointerToFree = NULL;
   _imgDown.pixels = NULL;
+  _caption = NULL;
+  _transparent = false;
+    
+  if (caption != NULL) {
+    _caption = (char*)malloc(strlen(caption)+1);
+    if (_caption != NULL) {
+      strcpy(_caption, caption);
+    }
+    _captionColor = color;
+  }
 }
 
 ImageButton::~ImageButton()
@@ -39,6 +52,10 @@
     free(_imgDown.pointerToFree);
     _imgDown.pointerToFree = NULL;
   }
+  if (_caption != NULL) {
+    free(_caption);
+    _caption = NULL;
+  }
 }
 
 bool ImageButton::loadImages(const char* imgUp, const char* imgDown)
@@ -88,19 +105,36 @@
   return true;
 }
 
+void ImageButton::setTransparency(COLOR_T tColor)
+{
+  _transparent = true;
+  _transparentColor = tColor;
+}
 
 void ImageButton::draw(COLOR_T* fb)
 {
   if (fb != NULL) {
     _win.fb = fb;
   }
+  if (_caption != NULL) {
+    _win.pen = _captionColor;
+    swim_put_text_centered_win(&_win, _caption, _imgUp.height+2);
+  }
   if (_pressed) {
     if (_imgDown.pixels != NULL) {
-      swim_put_image(&_win, _imgDown.pixels, _imgDown.width, _imgDown.height);
+      if (_transparent) {
+        swim_put_transparent_image_xy(&_win, _imgDown.pixels, _imgDown.width, _imgDown.height, 0, 0, _transparentColor);
+      } else {
+        swim_put_image(&_win, _imgDown.pixels, _imgDown.width, _imgDown.height);
+      }
     }
   } else {
     if (_imgUp.pixels != NULL) {
-      swim_put_image(&_win, _imgUp.pixels, _imgUp.width, _imgUp.height);
+      if (_transparent) {
+        swim_put_transparent_image_xy(&_win, _imgUp.pixels, _imgUp.width, _imgUp.height, 0, 0, _transparentColor);
+      } else {
+        swim_put_image(&_win, _imgUp.pixels, _imgUp.width, _imgUp.height);
+      }
     }
   }
 }