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
Revision 6:7917b0894655, committed 2015-01-08
- Comitter:
- embeddedartists
- Date:
- Thu Jan 08 11:14:56 2015 +0100
- Parent:
- 5:f4de114c31c3
- Child:
- 7:4ba7bd9d32ef
- Commit message:
- - Fixed bug in Image class
- Added option to draw() in Clickable to change frame buffer
Changed in this revision
--- a/Application/AppImageViewer.cpp Sun Dec 21 13:53:07 2014 +0100 +++ b/Application/AppImageViewer.cpp Thu Jan 08 11:14:56 2015 +0100 @@ -56,87 +56,30 @@ BLACK, BLACK, BLACK); // colors: pen, backgr, forgr _btn = new Button("Done", _win->fb, _win->xpmax - BTN_OFF - BTN_WIDTH, _win->ypmax - BTN_OFF - BTN_HEIGHT, BTN_WIDTH, BTN_HEIGHT); - //_btn->draw(); } void AppImageViewer::load(const char* file) { - // wait for permission to render. According to API documentation alloc() should - // wait forever but it doesn't so we call it with 100ms timeout and try over and - // over until we succeed - while(true) { - Image::ImageData_t* data = _mailbox.alloc(100); - + Image::ImageData_t pre = {0}; + + int res = Image::decode(file, Image::RES_16BIT, &pre); + if (res == 0) { + DMBoard::instance().logger()->printf("[ImageLoader] Preparing %s\n", file); + Image::ImageData_t* data = _mailbox.alloc(osWaitForever); if (data != NULL) { - DMBoard::instance().logger()->printf("[ImageLoader] Preparing %s\n", file); - - if (Image::decode(file, Image::RES_16BIT, data) == 0) { - _mailbox.put(data); - } else { - // could not decode image so no point in sending it - _mailbox.free(data); - } - break; + *data = pre; + _mailbox.put(data); } else { DMBoard::instance().logger()->printf("[ImageLoader] Failed to get memory to prepare %s\n", file); } } } -//static bool recursiveProcessFS(char* buff, const char* name, int maxLen, AppImageViewer* app) -//{ -// uint32_t len = strlen(buff); -// if (len > 0) { -// if (buff[len - 1] != '/') { -// buff[len++] = '/'; -// buff[len] = '\0'; -// } -// } -// if ((strlen(name) + len) >= maxLen) { -// // avoid memory overwrite due to too long file path -// return true; -// } -// strcat(buff, name); -// len += strlen(name); - -// //DIR d = opendir(buff); -// bool result = true; // success -// FRESULT res; -// FATFS_DIR dir; -// FILINFO fno; -// res = f_opendir(&dir, buff); -// if (res == FR_OK) { -// while (result) { -// res = f_readdir(&dir, &fno); -// if (res != FR_OK || fno.fname[0] == 0) { -// break; -// } else if (fno.fname[0] == '.') { -// continue; -// } -// if (fno.fattrib & AM_DIR) { -// // A folder -// result = recursiveProcessFS(buff, fno.fname, maxLen, app); -// buff[len] = '\0'; -// } else { -// // A file -// int tmp = strlen(fno.fname); -// if (tmp > 3) { -// if ((strncasecmp(fno.fname+tmp-4, ".bmp", 4)==0) || -// (strncasecmp(fno.fname+tmp-4, ".png", 4)==0)) { -// snprintf(buff+len, maxLen-len, "/%s", fno.fname); -// app->load(buff); -// buff[len] = '\0'; -// } -// } -// } -// } -// //f_closedir(&dir); -// } -// return result; -//} - -static bool recursiveProcessFS(char* buff, const char* name, int maxLen, AppImageViewer* app) +static bool recursiveProcessFS(char* buff, const char* name, int maxLen, AppImageViewer* app, int depth, int maxDepth) { + if (depth > maxDepth) { + return true; + } uint32_t len = strlen(buff); if (len > 0) { if (buff[len - 1] != '/') { @@ -156,7 +99,7 @@ if (d != NULL) { struct dirent *p; while (result && ((p = readdir(d)) != NULL)) { - result = recursiveProcessFS(buff, p->d_name, maxLen, app); + result = recursiveProcessFS(buff, p->d_name, maxLen, app, depth+1, maxDepth); buff[len] = '\0'; } closedir(d); @@ -164,7 +107,8 @@ // a file if (len > 3) { if ((strncasecmp(buff+len-4, ".bmp", 4)==0) || - (strncasecmp(buff+len-4, ".png", 4)==0)) { + (strncasecmp(buff+len-4, ".png", 4)==0) || + (strncasecmp(buff+len-4, ".raw", 4)==0)) { DMBoard::instance().logger()->printf("[ImageLoader] found %s\n", buff); app->load(buff); } @@ -180,13 +124,13 @@ { DMBoard::instance().logger()->printf("Recursive list of file and folders in /mci/\n"); buff[0] = '\0'; - recursiveProcessFS(buff, "/mci/", 512, (AppImageViewer*)args); + recursiveProcessFS(buff, "/mci/", 512, (AppImageViewer*)args, 0, 2); DMBoard::instance().logger()->printf("Recursive list of file and folders in /usb/\n"); buff[0] = '\0'; - recursiveProcessFS(buff, "/usb/", 512, (AppImageViewer*)args); + recursiveProcessFS(buff, "/usb/", 512, (AppImageViewer*)args, 0, 2); DMBoard::instance().logger()->printf("Recursive list of file and folders in /qspi/\n"); buff[0] = '\0'; - recursiveProcessFS(buff, "/qspi/", 512, (AppImageViewer*)args); + recursiveProcessFS(buff, "/qspi/", 512, (AppImageViewer*)args, 0, 2); free(buff); } DMBoard::instance().logger()->printf("loaderTask done\n"); @@ -230,7 +174,7 @@ bool first = true; Timer t; while(!done) { - osEvent evt = _mailbox.get(100); + osEvent evt = _mailbox.get(1000); if (evt.status == osEventMail) { COLOR_T* fb; if (_active == 1) { @@ -265,7 +209,8 @@ delete tLoader; - _btn->draw(); + // The button must be drawn on the current framebuffer + _btn->draw(_win->fb); // Wait for touches TouchPanel* touch = DMBoard::instance().touchPanel();
--- a/Application/Button.cpp Sun Dec 21 13:53:07 2014 +0100 +++ b/Application/Button.cpp Thu Jan 08 11:14:56 2015 +0100 @@ -47,8 +47,11 @@ _fgColPressed = fgPressed; } -void Button::draw() +void Button::draw(COLOR_T* fb) { + if (fb != NULL) { + _win.fb = fb; + } if (_pressed) { swim_set_pen_color(&_win, _fgColPressed); swim_set_bkg_color(&_win, _bgColPressed);
--- a/Application/Button.h Sun Dec 21 13:53:07 2014 +0100 +++ b/Application/Button.h Thu Jan 08 11:14:56 2015 +0100 @@ -95,9 +95,10 @@ */ void setColors(COLOR_T bg, COLOR_T fg, COLOR_T bgPressed, COLOR_T fgPressed); - /** Draws the button + /** Draws the button (on a new framebuffer if one is specified) + * @param fb the frame buffer */ - virtual void draw(); + virtual void draw(COLOR_T* fb = 0); private: const char* _caption;
--- a/Application/Clickable.h Sun Dec 21 13:53:07 2014 +0100 +++ b/Application/Clickable.h Thu Jan 08 11:14:56 2015 +0100 @@ -67,9 +67,10 @@ */ bool handle(uint16_t x, uint16_t y, bool pressed); - /** Draws the button + /** Draws the button (on a new framebuffer if one is specified) + * @param fb the frame buffer */ - virtual void draw() = 0; + virtual void draw(COLOR_T* fb = 0) = 0; protected: bool _enabled, _pressed;
--- a/Application/Image.cpp Sun Dec 21 13:53:07 2014 +0100 +++ b/Application/Image.cpp Thu Jan 08 11:14:56 2015 +0100 @@ -208,6 +208,7 @@ } else { result = Image::decode(buff, size, res, pDataOut); free(buff); + return result; } // success
--- a/Application/ImageButton.cpp Sun Dec 21 13:53:07 2014 +0100 +++ b/Application/ImageButton.cpp Thu Jan 08 11:14:56 2015 +0100 @@ -87,8 +87,11 @@ } -void ImageButton::draw() +void ImageButton::draw(COLOR_T* fb) { + if (fb != NULL) { + _win.fb = fb; + } if (_pressed) { if (_imgDown.pixels != NULL) { swim_put_image(&_win, _imgDown.pixels, _imgDown.width, _imgDown.height);
--- a/Application/ImageButton.h Sun Dec 21 13:53:07 2014 +0100 +++ b/Application/ImageButton.h Thu Jan 08 11:14:56 2015 +0100 @@ -63,9 +63,10 @@ bool loadImages(const unsigned char* imgUp, unsigned int imgUpSize, const unsigned char* imgDown = 0, unsigned int imgDownSize = 0); - /** Draws the button + /** Draws the button (on a new framebuffer if one is specified) + * @param fb the frame buffer */ - virtual void draw(); + virtual void draw(COLOR_T* fb = 0); private: Image::ImageData_t _imgUp;