Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of DMBasicGUI by
Diff: Application/ImageButton.cpp
- 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); + } } }