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

Files at this revision

API Documentation at this revision

Comitter:
embeddedartists
Date:
Fri Dec 19 09:12:51 2014 +0100
Parent:
2:efae611de184
Child:
4:a73760d09423
Commit message:
- Fixed bug in Clickable
- Fixed missing include in Image
- Updated to match the new TouchPanel interface

Changed in this revision

Application/AppColorPicker.cpp Show annotated file Show diff for this revision Revisions of this file
Application/AppImageViewer.cpp Show annotated file Show diff for this revision Revisions of this file
Application/AppLauncher.cpp Show annotated file Show diff for this revision Revisions of this file
Application/AppLauncher.h Show annotated file Show diff for this revision Revisions of this file
Application/AppSettings.cpp Show annotated file Show diff for this revision Revisions of this file
Application/AppTouchCalibration.cpp Show annotated file Show diff for this revision Revisions of this file
Application/Button.cpp Show annotated file Show diff for this revision Revisions of this file
Application/Button.h Show annotated file Show diff for this revision Revisions of this file
Application/Clickable.cpp Show annotated file Show diff for this revision Revisions of this file
Application/Image.h Show annotated file Show diff for this revision Revisions of this file
Application/ImageButton.cpp Show annotated file Show diff for this revision Revisions of this file
Application/ImageButton.h Show annotated file Show diff for this revision Revisions of this file
--- a/Application/AppColorPicker.cpp	Fri Dec 19 07:37:24 2014 +0000
+++ b/Application/AppColorPicker.cpp	Fri Dec 19 09:12:51 2014 +0100
@@ -123,20 +123,21 @@
     char buf[10];
     swim_set_pen_color(_win, BLACK);
     while(!done) {
-      touch->read(coord);
-      if (coord.z > 0 &&
-          coord.x >= _colorwin->xpmin && coord.x <= _colorwin->xpmax && 
-          coord.y >= _colorwin->ypmin && coord.y <= _colorwin->ypmax) {
-          int x = coord.x - _colorwin->xpmin;
-          int y = coord.y - _colorwin->ypmin;
-          COLOR_T c = ((x/(BOX_SIDE/32))<<11) | ((y/(BOX_SIDE/64))<<5) | ((0x1f-(x/(BOX_SIDE/32)))<<0);
-          swim_set_fill_color(_win, c);
-          swim_put_box(_win, 350, 70, 430, 150);
-          sprintf(buf, "0x%04x  ", c);
-          swim_put_text_xy(_win, buf, 350, 160);
-      }
-      if (_btn->handle(coord.x, coord.y, coord.z > 0)) {
-          _btn->draw();
+      if (touch->read(coord) == TouchPanel::TouchError_Ok) {
+        if (coord.z > 0 &&
+            coord.x >= _colorwin->xpmin && coord.x <= _colorwin->xpmax && 
+            coord.y >= _colorwin->ypmin && coord.y <= _colorwin->ypmax) {
+            int x = coord.x - _colorwin->xpmin;
+            int y = coord.y - _colorwin->ypmin;
+            COLOR_T c = ((x/(BOX_SIDE/32))<<11) | ((y/(BOX_SIDE/64))<<5) | ((0x1f-(x/(BOX_SIDE/32)))<<0);
+            swim_set_fill_color(_win, c);
+            swim_put_box(_win, 350, 70, 430, 150);
+            sprintf(buf, "0x%04x  ", c);
+            swim_put_text_xy(_win, buf, 350, 160);
+        }
+        if (_btn->handle(coord.x, coord.y, coord.z > 0)) {
+            _btn->draw();
+        }
       }
     }
     
--- a/Application/AppImageViewer.cpp	Fri Dec 19 07:37:24 2014 +0000
+++ b/Application/AppImageViewer.cpp	Fri Dec 19 09:12:51 2014 +0100
@@ -271,9 +271,10 @@
     TouchPanel* touch = DMBoard::instance().touchPanel();
     TouchPanel::touchCoordinate_t coord;
     while(!done) {
-      touch->read(coord);
-      if (_btn->handle(coord.x, coord.y, coord.z > 0)) {
-          _btn->draw();
+      if (touch->read(coord) == TouchPanel::TouchError_Ok) {
+        if (_btn->handle(coord.x, coord.y, coord.z > 0)) {
+            _btn->draw();
+        }
       }
     }
     
--- a/Application/AppLauncher.cpp	Fri Dec 19 07:37:24 2014 +0000
+++ b/Application/AppLauncher.cpp	Fri Dec 19 09:12:51 2014 +0100
@@ -23,6 +23,7 @@
 #include "AppImageViewer.h"
 #include "lpc_swim_font.h"
 #include "Button.h"
+#include "ImageButton.h"
 
 /******************************************************************************
  * Defines and typedefs
@@ -40,6 +41,7 @@
     //SlideshowApp,
     //TouchGFXApp,
     //EmWinApp,
+    Placeholder    =  99,
     CalibrationApp = 100,
 } AppID_t;
 
@@ -74,6 +76,24 @@
     _buttons[idx]->draw();
 }
 
+void AppLauncher::addImageButton(uint32_t buttonID, const char* imgUp, const char* imgDown)
+{
+    int idx = _usedButtons++;
+    int xspace = ((_disp->width() - ButtonColumns * 64) / (ButtonColumns + 1));
+    int yspace = ((_disp->height() - TitleHeight - ButtonRows * 64) / (ButtonRows + 1));
+    
+    ImageButton* img =  new ImageButton((COLOR_T*)_fb, 
+                              xspace + (64 + xspace)*(idx%ButtonColumns), 
+                              TitleHeight + yspace + (64 + yspace)*(idx/ButtonColumns), 
+                              64, 64);
+    if (!img->loadImages(imgUp, imgDown)) {
+      DMBoard::instance().logger()->printf("Failed to load image for buttonID %u, %s[%s]\n", buttonID, imgUp, imgDown==NULL?"":imgDown);
+    }
+    _buttons[idx] = img;
+    _buttons[idx]->setAction(buttonClicked, buttonID);
+    _buttons[idx]->draw();
+}
+
 void AppLauncher::draw()
 {
     // Prepare fullscreen
@@ -82,10 +102,11 @@
                      (COLOR_T*)_fb,
                      0,0,_disp->width()-1, _disp->height()-1, // window position and size
                      1,                                     // border
-                     WHITE, RED, BLACK);                    // colors: pen, backgr, forgr
+                     WHITE, BLACK, BLACK);                    // colors: pen, backgr, forgr
     swim_set_title(_win, "Demo Program", BLACK);
 
     // Add many buttons
+#if 0    
     addButton(SettingsApp,  "Settings");
     addButton(TouchTestApp, "Test Touch");
     //addButton(SlideshowApp, "Slideshow");
@@ -98,7 +119,23 @@
     //addButton(7, "Button 7");
     //addButton(8, "Button 8");
     //addButton(9, "Button 9");
-    
+#else
+    addImageButton(SettingsApp,  "/usb/preferences-desktop-applications.png");
+    addImageButton(TouchTestApp, "/usb/bijiben.png");
+    //addImageButton(SlideshowApp, "Slideshow");
+    //addImageButton(TouchGFXApp,  "TouchGFX");
+    //addImageButton(EmWinApp,     "emWin");
+    addImageButton(ColorPicker,  "/usb/preferences-color.png");
+    addImageButton(ImageViewerApp,  "/usb/multimedia-photo-manager.png");
+    addImageButton(Placeholder,  "/usb/help-info.png");
+    addImageButton(Placeholder,  "/usb/unetbootin.png");
+    //addImageButton(5, "Button 5");
+    //addImageButton(6, "Button 6");
+    //addImageButton(7, "Button 7");
+    //addImageButton(8, "Button 8");
+    //addImageButton(9, "Button 9");
+#endif
+
     const char* msg = "(Press physical UserButton >2s to calibrate touch)";
     int w, h;
     swim_get_string_bounds(_win, msg, &w, &h);
@@ -147,7 +184,7 @@
     
     // Start display in default mode (16-bit)
     Display::DisplayError disperr = _disp->powerUp(_fb);
-    if (disperr != Display::Ok) {
+    if (disperr != Display::DisplayError_Ok) {
         log->printf(APP_PREFIX"Failed to initialize the display, got error %d\r\n", disperr);
         return;
     }
@@ -159,7 +196,7 @@
     // Wait for touches
     TouchPanel* touch = board->touchPanel();
     TouchPanel::touchCoordinate_t coord;
-    while(touch->read(coord)) {
+    while(touch->read(coord) == TouchPanel::TouchError_Ok) {
         
         // Process the touch coordinate for each button
         for (int i = 0; i < NumberOfButtons; i++) {
--- a/Application/AppLauncher.h	Fri Dec 19 07:37:24 2014 +0000
+++ b/Application/AppLauncher.h	Fri Dec 19 09:12:51 2014 +0100
@@ -20,7 +20,7 @@
 #include "App.h"
 #include "DMBoard.h"
 #include "lpc_swim.h"
-#include "Button.h"
+#include "Clickable.h"
 
 /**
  * An App example. This uses a number of buttons to launch different Apps.
@@ -53,11 +53,12 @@
     Display* _disp;
     SWIM_WINDOW_T* _win;
     void* _fb;
-    Button* _buttons[NumberOfButtons];
+    Clickable* _buttons[NumberOfButtons];
     int _usedButtons;
 
     void draw();
     void addButton(uint32_t buttonID, const char* caption);
+    void addImageButton(uint32_t buttonID, const char* imgUp, const char* imgDown = 0);
 };
 
 #endif
--- a/Application/AppSettings.cpp	Fri Dec 19 07:37:24 2014 +0000
+++ b/Application/AppSettings.cpp	Fri Dec 19 09:12:51 2014 +0100
@@ -102,13 +102,13 @@
     sprintf(buff, "%d x %d pixels", _disp->width(), _disp->height());
     swim_put_text_xy(_win, buff, COL3_OFF+ITEM_VALUE_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 1);
     
-    sprintf(buff, "%s %s", _disp->isSupported(Display::Resolution_16bit_rgb565)?"Supported":"N/A", _disp->bpp()==Display::Resolution_16bit_rgb565?"  (Active)":"");
+    sprintf(buff, "%s %s", _disp->isSupported(Display::Resolution_16bit_rgb565)?"Supported":"N/A", _disp->currentResolution()==Display::Resolution_16bit_rgb565?"  (Active)":"");
     swim_put_text_xy(_win, buff, COL3_OFF+ITEM_VALUE_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 3);
     
-    sprintf(buff, "%s %s", _disp->isSupported(Display::Resolution_18bit_rgb666)?"Supported":"N/A", _disp->bpp()==Display::Resolution_18bit_rgb666?"  (Active)":"");
+    sprintf(buff, "%s %s", _disp->isSupported(Display::Resolution_18bit_rgb666)?"Supported":"N/A", _disp->currentResolution()==Display::Resolution_18bit_rgb666?"  (Active)":"");
     swim_put_text_xy(_win, buff, COL3_OFF+ITEM_VALUE_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 4);
     
-    sprintf(buff, "%s %s", _disp->isSupported(Display::Resolution_24bit_rgb888)?"Supported":"N/A", _disp->bpp()==Display::Resolution_24bit_rgb888?"  (Active)":"");
+    sprintf(buff, "%s %s", _disp->isSupported(Display::Resolution_24bit_rgb888)?"Supported":"N/A", _disp->currentResolution()==Display::Resolution_24bit_rgb888?"  (Active)":"");
     swim_put_text_xy(_win, buff, COL3_OFF+ITEM_VALUE_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 5);
     
     sprintf(buff, "%s", _disp->landscape()?"YES":"NO");
@@ -152,9 +152,10 @@
     TouchPanel* touch = DMBoard::instance().touchPanel();
     TouchPanel::touchCoordinate_t coord;
     while(!done) {
-      touch->read(coord);
-      if (_btn->handle(coord.x, coord.y, coord.z > 0)) {
-          _btn->draw();
+      if (touch->read(coord) == TouchPanel::TouchError_Ok) {
+        if (_btn->handle(coord.x, coord.y, coord.z > 0)) {
+            _btn->draw();
+        }
       }
     }
     
--- a/Application/AppTouchCalibration.cpp	Fri Dec 19 07:37:24 2014 +0000
+++ b/Application/AppTouchCalibration.cpp	Fri Dec 19 09:12:51 2014 +0100
@@ -187,13 +187,14 @@
     swim_set_pen_color(_win, BLACK);
     TouchPanel::touchCoordinate_t coord;
     while(!done) {
-      _touch->read(coord);
-      if (coord.z > 0) {
-          //swim_put_pixel(_win, coord.x, coord.y);
-          swim_put_box(_win, coord.x-1, coord.y-1, coord.x+1, coord.y+1);
-      }
-      if (_btn->handle(coord.x, coord.y, coord.z > 0)) {
-          _btn->draw();
+      if (_touch->read(coord) == TouchPanel::TouchError_Ok) {
+        if (coord.z > 0) {
+            //swim_put_pixel(_win, coord.x, coord.y);
+            swim_put_box(_win, coord.x-1, coord.y-1, coord.x+1, coord.y+1);
+        }
+        if (_btn->handle(coord.x, coord.y, coord.z > 0)) {
+            _btn->draw();
+        }
       }
     }
     
--- a/Application/Button.cpp	Fri Dec 19 07:37:24 2014 +0000
+++ b/Application/Button.cpp	Fri Dec 19 09:12:51 2014 +0100
@@ -26,10 +26,6 @@
   _bgCol(GREEN), _fgCol(BLACK), 
   _bgColPressed(BLACK), _fgColPressed(GREEN)
 {
-  _win.pen = _fgCol;
-  _win.bkg = _bgCol;
-  _win.fill = _fgCol;
-    
   swim_set_font_transparency(&_win, 1);
   setCaption(caption);
 }
--- a/Application/Button.h	Fri Dec 19 07:37:24 2014 +0000
+++ b/Application/Button.h	Fri Dec 19 09:12:51 2014 +0100
@@ -54,9 +54,10 @@
  *    TouchPanel* touch = DMBoard::instance().touchPanel();
  *    TouchPanel::touchCoordinate_t coord;
  *    while(!done) {
- *      touch->read(coord);
- *      if (btn.handle(coord.x, coord.y, coord.z > 0)) {
- *        btn.draw();
+ *      if (touch->read(coord) == TouchPanel::TouchError_Ok) {
+ *        if (btn.handle(coord.x, coord.y, coord.z > 0)) {
+ *          btn.draw();
+ *        }
  *      }
  *    }
  * }
--- a/Application/Clickable.cpp	Fri Dec 19 07:37:24 2014 +0000
+++ b/Application/Clickable.cpp	Fri Dec 19 09:12:51 2014 +0100
@@ -59,6 +59,7 @@
     else if (_pressed) {
       // pressed but moved outside of the button area
       needsRepaint = true;
+      _pressed = false;
     }
   }
   return needsRepaint;
--- a/Application/Image.h	Fri Dec 19 07:37:24 2014 +0000
+++ b/Application/Image.h	Fri Dec 19 09:12:51 2014 +0100
@@ -17,6 +17,8 @@
 #ifndef IMAGE_H
 #define IMAGE_H
 
+#include "mbed.h"
+
 /**
  * Image example
  *
--- 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);
+    }
   }
 }
--- a/Application/ImageButton.h	Fri Dec 19 07:37:24 2014 +0000
+++ b/Application/ImageButton.h	Fri Dec 19 09:12:51 2014 +0100
@@ -14,8 +14,8 @@
  *  limitations under the License.
  */
  
-#ifndef BUTTON_H
-#define BUTTON_H
+#ifndef IMAGEBUTTON_H
+#define IMAGEBUTTON_H
 
 #include "Clickable.h"
 #include "Image.h"
@@ -36,12 +36,21 @@
      *  @param y       the upper left corner of the button
      *  @param width   the width of the button
      *  @param height  the height of the button
+     */
+  ImageButton(COLOR_T* fb, uint16_t x, uint16_t y, uint16_t width, uint16_t height);
+  ~ImageButton();
+
+    /** Loads the mandatory "normal" state image and the optional "pressed" state image
+     *
      *  @param imgUp   the image for the normal state
      *  @param imgDown the image for the pressed state (or NULL to use the same)
+     *
+     *  @returns
+     *       true on success
+     *       false on failure
      */
-  ImageButton(COLOR_T* fb, uint16_t x, uint16_t y, uint16_t width, uint16_t height, const char* imgUp, const char* imgDown = 0);
-  ~ImageButton();
-  
+  bool loadImages(const char* imgUp, const char* imgDown = 0);
+
     /** Draws the button
      */
   virtual void draw();
@@ -51,4 +60,4 @@
   Image::ImageData_t _imgDown;
 };
 
-#endif /* BUTTON_H */
+#endif /* IMAGEBUTTON_H */