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
Diff: Application/AppLauncher.cpp
- Revision:
- 5:f4de114c31c3
- Parent:
- 3:3fabfe3339b8
- Child:
- 8:19a6b70d42b1
--- a/Application/AppLauncher.cpp Fri Dec 19 16:40:30 2014 +0100 +++ b/Application/AppLauncher.cpp Sun Dec 21 13:53:07 2014 +0100 @@ -17,10 +17,6 @@ #include "mbed.h" #include "AppLauncher.h" -#include "AppSettings.h" -#include "AppTouchCalibration.h" -#include "AppColorPicker.h" -#include "AppImageViewer.h" #include "lpc_swim_font.h" #include "Button.h" #include "ImageButton.h" @@ -31,25 +27,27 @@ #define APP_PREFIX "[Launcher] " +#define NO_APPLICATION (-1) -typedef enum { - NoApplication = -1, - SettingsApp = 0, - ColorPicker, - TouchTestApp, - ImageViewerApp, - //SlideshowApp, - //TouchGFXApp, - //EmWinApp, - Placeholder = 99, - CalibrationApp = 100, -} AppID_t; + +//typedef enum { +// NoApplication = -1, +// SettingsApp = 0, +// ColorPicker, +// TouchTestApp, +// ImageViewerApp, +// SlideshowApp, +// //TouchGFXApp, +// //EmWinApp, +// Placeholder = 99, +// CalibrationApp = 100, +//} AppID_t; /****************************************************************************** * Private variables *****************************************************************************/ -static AppID_t appToLaunch = NoApplication; +static int appToLaunch = NO_APPLICATION; /****************************************************************************** * Private functions @@ -57,43 +55,11 @@ static void buttonClicked(uint32_t x) { - if (appToLaunch == NoApplication) { - appToLaunch = (AppID_t)x; + if (appToLaunch == NO_APPLICATION) { + appToLaunch = (int)x; } } -void AppLauncher::addButton(uint32_t buttonID, const char* caption) -{ - int idx = _usedButtons++; - int xspace = ((_disp->width() - ButtonColumns * ButtonWidth) / (ButtonColumns + 1)); - int yspace = ((_disp->height() - TitleHeight - ButtonRows * ButtonHeight) / (ButtonRows + 1)); - - _buttons[idx] = new Button(caption, (COLOR_T*)_fb, - xspace + (ButtonWidth + xspace)*(idx%ButtonColumns), - TitleHeight + yspace + (ButtonHeight + yspace)*(idx/ButtonColumns), - ButtonWidth, ButtonHeight); - _buttons[idx]->setAction(buttonClicked, buttonID); - _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 @@ -105,41 +71,14 @@ 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"); - //addButton(TouchGFXApp, "TouchGFX"); - //addButton(EmWinApp, "emWin"); - addButton(ColorPicker, "Color Picker"); - addButton(ImageViewerApp, "Image Viewer"); - //addButton(5, "Button 5"); - //addButton(6, "Button 6"); - //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); swim_put_text_xy(_win, msg, (_disp->width()-w)/2, _disp->height()-h*4); + + for (int i = 0; i < _usedButtons; i++) { + _buttons[i]->draw(); + } } /****************************************************************************** @@ -208,7 +147,7 @@ } // Check if the physical USER button on the board has been pressed - if (appToLaunch == NoApplication) { + if (appToLaunch == NO_APPLICATION) { if (board->buttonPressed()) { if (buttonPressed) { if (buttonTimer.read_ms() > 2000) { @@ -234,23 +173,10 @@ buttonPressed = false; } - if (appToLaunch != NoApplication) { + if (appToLaunch != NO_APPLICATION) { App* a = NULL; - switch (appToLaunch) { - case SettingsApp: - a = new AppSettings(); - break; - case CalibrationApp: - a = new AppTouchCalibration(); - break; - case ColorPicker: - a = new AppColorPicker(); - break; - case ImageViewerApp: - a = new AppImageViewer(); - break; - default: - break; + if (_callback != NULL) { + a = _callback(appToLaunch); } if (a != NULL) { if (a->setup()) { @@ -259,8 +185,8 @@ } delete a; } - appToLaunch = NoApplication; - } + appToLaunch = NO_APPLICATION; + } } } @@ -284,4 +210,64 @@ return true; } +void AppLauncher::setAppCreatorFunc(App*(*callback)(uint32_t buttonID)) +{ + _callback = callback; +} +bool AppLauncher::addButton(uint32_t buttonID, const char* caption) +{ + int idx = _usedButtons++; + int xspace = ((_disp->width() - ButtonColumns * ButtonWidth) / (ButtonColumns + 1)); + int yspace = ((_disp->height() - TitleHeight - ButtonRows * ButtonHeight) / (ButtonRows + 1)); + + _buttons[idx] = new Button(caption, (COLOR_T*)_fb, + xspace + (ButtonWidth + xspace)*(idx%ButtonColumns), + TitleHeight + yspace + (ButtonHeight + yspace)*(idx/ButtonColumns), + ButtonWidth, ButtonHeight); + _buttons[idx]->setAction(buttonClicked, buttonID); + //_buttons[idx]->draw(); + return true; +} + +bool 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)) { + _buttons[idx] = img; + _buttons[idx]->setAction(buttonClicked, buttonID); + //_buttons[idx]->draw(); + return true; + } else { + //DMBoard::instance().logger()->printf("Failed to load image for buttonID %u, %s[%s]\n", buttonID, imgUp, imgDown==NULL?"":imgDown); + return false; + } +} + +bool AppLauncher::addImageButton(uint32_t buttonID, const unsigned char* imgUp, unsigned int imgUpSize, const unsigned char* imgDown, unsigned int imgDownSize) +{ + 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, imgUpSize, imgDown, imgDownSize)) { + _buttons[idx] = img; + _buttons[idx]->setAction(buttonClicked, buttonID); + //_buttons[idx]->draw(); + return true; + } else { + //DMBoard::instance().logger()->printf("Failed to load image for buttonID %u, %s[%s]\n", buttonID, imgUp, imgDown==NULL?"":imgDown); + return false; + } +}