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/ImageButton.cpp
- Revision:
- 2:efae611de184
- Child:
- 3:3fabfe3339b8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Application/ImageButton.cpp Fri Dec 19 07:37:24 2014 +0000 @@ -0,0 +1,60 @@ +/* + * Copyright 2014 Embedded Artists AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ImageButton.h" +#include "mbed.h" +#include "DMBoard.h" + +#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) : + 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() +{ + if (_imgUp.pixels != NULL) { + free(_imgUp.pixels); + _imgUp.pixels = NULL; + } + if (_imgDown.pixels != NULL) { + free(_imgDown.pixels); + _imgDown.pixels = NULL; + } +} + +void ImageButton::draw() +{ + if (_pressed) { + if (_imgDown.pixels != NULL) { + swim_put_image(&_win, _imgDown.pixels, _imgDown.width, _imgDown.height); + } + } else { + swim_put_image(&_win, _imgUp.pixels, _imgUp.width, _imgUp.height); + } +}