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/DigitButton.cpp
- Revision:
- 9:ce69a7adfe9c
- Parent:
- 7:4ba7bd9d32ef
- Child:
- 10:651861441108
--- a/Application/DigitButton.cpp Sat Jan 17 14:07:25 2015 +0100
+++ b/Application/DigitButton.cpp Tue Jan 20 09:05:30 2015 +0100
@@ -24,7 +24,9 @@
Clickable(fb, x, y, width, height), _value(0), _digits(1), _img_y_offset(0),
_img_digit_height(0), _img_digit_width(0), _img_digit_size(0)
{
+ _imgUp.pointerToFree = NULL;
_imgUp.pixels = NULL;
+ _imgDown.pointerToFree = NULL;
_imgDown.pixels = NULL;
_win.fill = WHITE;
swim_clear_screen(&_win, _win.fill);
@@ -32,25 +34,25 @@
DigitButton::~DigitButton()
{
- if (_imgUp.pixels != NULL) {
- free(_imgUp.pixels);
- _imgUp.pixels = NULL;
+ if (_imgUp.pointerToFree != NULL) {
+ free(_imgUp.pointerToFree);
+ _imgUp.pointerToFree = NULL;
}
- if (_imgDown.pixels != NULL) {
- free(_imgDown.pixels);
- _imgDown.pixels = NULL;
+ if (_imgDown.pointerToFree != NULL) {
+ free(_imgDown.pointerToFree);
+ _imgDown.pointerToFree = NULL;
}
}
bool DigitButton::loadImages(const char* imgUp, const char* imgDown)
{
- if (_imgUp.pixels != NULL) {
- free(_imgUp.pixels);
- _imgUp.pixels = NULL;
+ if (_imgUp.pointerToFree != NULL) {
+ free(_imgUp.pointerToFree);
+ _imgUp.pointerToFree = NULL;
}
- if (_imgDown.pixels != NULL) {
- free(_imgDown.pixels);
- _imgDown.pixels = NULL;
+ if (_imgDown.pointerToFree != NULL) {
+ free(_imgDown.pointerToFree);
+ _imgDown.pointerToFree = NULL;
}
if (Image::decode(imgUp, Image::RES_16BIT, &_imgUp) != 0) {
DMBoard::instance().logger()->printf("Failed to load %s\n", imgUp);
@@ -69,16 +71,37 @@
return true;
}
+bool DigitButton::loadImages(const Image::ImageData_t* imgUp, const Image::ImageData_t* imgDown)
+{
+ if (_imgUp.pointerToFree != NULL) {
+ free(_imgUp.pointerToFree);
+ _imgUp.pointerToFree = NULL;
+ }
+ if (_imgDown.pointerToFree != NULL) {
+ free(_imgDown.pointerToFree);
+ _imgDown.pointerToFree = NULL;
+ }
+ memcpy(&_imgUp, imgUp, sizeof(Image::ImageData_t));
+ if (imgDown != NULL) {
+ memcpy(&_imgDown, imgDown, sizeof(Image::ImageData_t));
+ }
+ _img_digit_width = _imgUp.width;
+ _img_digit_height = _imgUp.height/10;
+ _img_y_offset = _imgUp.height - 10*_img_digit_height;
+ _img_digit_size = ((_imgUp.res == Image::RES_16BIT)?1:2) * _img_digit_height * _img_digit_width;
+ return true;
+}
+
bool DigitButton::loadImages(const unsigned char* imgUp, unsigned int imgUpSize,
const unsigned char* imgDown, unsigned int imgDownSize)
{
- if (_imgUp.pixels != NULL) {
- free(_imgUp.pixels);
- _imgUp.pixels = NULL;
+ if (_imgUp.pointerToFree != NULL) {
+ free(_imgUp.pointerToFree);
+ _imgUp.pointerToFree = NULL;
}
- if (_imgDown.pixels != NULL) {
- free(_imgDown.pixels);
- _imgDown.pixels = NULL;
+ if (_imgDown.pointerToFree != NULL) {
+ free(_imgDown.pointerToFree);
+ _imgDown.pointerToFree = NULL;
}
if (Image::decode(imgUp, imgUpSize, Image::RES_16BIT, &_imgUp) != 0) {
DMBoard::instance().logger()->printf("Failed to load %s\n", imgUp);
