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 EmbeddedArtists AB

Committer:
embeddedartists
Date:
Fri Dec 19 07:37:24 2014 +0000
Revision:
2:efae611de184
Parent:
1:46c8df4608c8
Child:
3:3fabfe3339b8
Added ImageButton and Clickable

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 1:46c8df4608c8 1 /*
embeddedartists 1:46c8df4608c8 2 * Copyright 2014 Embedded Artists AB
embeddedartists 1:46c8df4608c8 3 *
embeddedartists 1:46c8df4608c8 4 * Licensed under the Apache License, Version 2.0 (the "License");
embeddedartists 1:46c8df4608c8 5 * you may not use this file except in compliance with the License.
embeddedartists 1:46c8df4608c8 6 * You may obtain a copy of the License at
embeddedartists 1:46c8df4608c8 7 *
embeddedartists 1:46c8df4608c8 8 * http://www.apache.org/licenses/LICENSE-2.0
embeddedartists 1:46c8df4608c8 9 *
embeddedartists 1:46c8df4608c8 10 * Unless required by applicable law or agreed to in writing, software
embeddedartists 1:46c8df4608c8 11 * distributed under the License is distributed on an "AS IS" BASIS,
embeddedartists 1:46c8df4608c8 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
embeddedartists 1:46c8df4608c8 13 * See the License for the specific language governing permissions and
embeddedartists 1:46c8df4608c8 14 * limitations under the License.
embeddedartists 1:46c8df4608c8 15 */
embeddedartists 1:46c8df4608c8 16
embeddedartists 0:4977187e90c7 17 #include "Button.h"
embeddedartists 0:4977187e90c7 18 #include "mbed.h"
embeddedartists 0:4977187e90c7 19 #include "DMBoard.h"
embeddedartists 0:4977187e90c7 20
embeddedartists 0:4977187e90c7 21 #include "lpc_swim_font.h"
embeddedartists 0:4977187e90c7 22
embeddedartists 0:4977187e90c7 23 Button::Button(const char* caption, COLOR_T* fb, uint16_t x, uint16_t y, uint16_t width, uint16_t height) :
embeddedartists 2:efae611de184 24 Clickable(fb, x, y, width, height),
embeddedartists 0:4977187e90c7 25 _caption(caption), _capx(0), _capy(0),
embeddedartists 0:4977187e90c7 26 _bgCol(GREEN), _fgCol(BLACK),
embeddedartists 0:4977187e90c7 27 _bgColPressed(BLACK), _fgColPressed(GREEN)
embeddedartists 0:4977187e90c7 28 {
embeddedartists 2:efae611de184 29 _win.pen = _fgCol;
embeddedartists 2:efae611de184 30 _win.bkg = _bgCol;
embeddedartists 2:efae611de184 31 _win.fill = _fgCol;
embeddedartists 0:4977187e90c7 32
embeddedartists 0:4977187e90c7 33 swim_set_font_transparency(&_win, 1);
embeddedartists 0:4977187e90c7 34 setCaption(caption);
embeddedartists 0:4977187e90c7 35 }
embeddedartists 0:4977187e90c7 36
embeddedartists 0:4977187e90c7 37 void Button::setCaption(const char* caption)
embeddedartists 0:4977187e90c7 38 {
embeddedartists 0:4977187e90c7 39 int w, h;
embeddedartists 0:4977187e90c7 40 _caption = caption;
embeddedartists 0:4977187e90c7 41 swim_get_string_bounds(&_win, _caption, &w, &h);
embeddedartists 0:4977187e90c7 42 _capx = (_win.xpmax-_win.xpmin-w)/2;
embeddedartists 0:4977187e90c7 43 _capy = (_win.ypmax-_win.ypmin-h)/2;
embeddedartists 0:4977187e90c7 44 }
embeddedartists 0:4977187e90c7 45
embeddedartists 0:4977187e90c7 46 void Button::setColors(COLOR_T bg, COLOR_T fg, COLOR_T bgPressed, COLOR_T fgPressed)
embeddedartists 0:4977187e90c7 47 {
embeddedartists 0:4977187e90c7 48 _bgCol = bg;
embeddedartists 0:4977187e90c7 49 _fgCol = fg;
embeddedartists 0:4977187e90c7 50 _bgColPressed = bgPressed;
embeddedartists 0:4977187e90c7 51 _fgColPressed = fgPressed;
embeddedartists 0:4977187e90c7 52 }
embeddedartists 0:4977187e90c7 53
embeddedartists 0:4977187e90c7 54 void Button::draw()
embeddedartists 0:4977187e90c7 55 {
embeddedartists 0:4977187e90c7 56 if (_pressed) {
embeddedartists 0:4977187e90c7 57 swim_set_pen_color(&_win, _fgColPressed);
embeddedartists 0:4977187e90c7 58 swim_set_bkg_color(&_win, _bgColPressed);
embeddedartists 0:4977187e90c7 59 swim_set_fill_color(&_win, _fgColPressed);
embeddedartists 0:4977187e90c7 60 swim_clear_screen(&_win, _bgColPressed);
embeddedartists 0:4977187e90c7 61 } else {
embeddedartists 0:4977187e90c7 62 swim_set_pen_color(&_win, _fgCol);
embeddedartists 0:4977187e90c7 63 swim_set_bkg_color(&_win, _bgCol);
embeddedartists 0:4977187e90c7 64 swim_set_fill_color(&_win, _fgCol);
embeddedartists 0:4977187e90c7 65 swim_clear_screen(&_win, _bgCol);
embeddedartists 0:4977187e90c7 66 }
embeddedartists 0:4977187e90c7 67 swim_put_text_xy(&_win, _caption, _capx, _capy);
embeddedartists 0:4977187e90c7 68 }