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
Application/Button.cpp@22:f0d00f29bfeb, 2019-11-04 (annotated)
- Committer:
- embeddedartists
- Date:
- Mon Nov 04 14:31:50 2019 +0000
- Revision:
- 22:f0d00f29bfeb
- Parent:
- 6:7917b0894655
More updates related to mbed OS 5
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:4977187e90c7 | 29 | swim_set_font_transparency(&_win, 1); |
embeddedartists | 0:4977187e90c7 | 30 | setCaption(caption); |
embeddedartists | 0:4977187e90c7 | 31 | } |
embeddedartists | 0:4977187e90c7 | 32 | |
embeddedartists | 0:4977187e90c7 | 33 | void Button::setCaption(const char* caption) |
embeddedartists | 0:4977187e90c7 | 34 | { |
embeddedartists | 0:4977187e90c7 | 35 | int w, h; |
embeddedartists | 0:4977187e90c7 | 36 | _caption = caption; |
embeddedartists | 0:4977187e90c7 | 37 | swim_get_string_bounds(&_win, _caption, &w, &h); |
embeddedartists | 0:4977187e90c7 | 38 | _capx = (_win.xpmax-_win.xpmin-w)/2; |
embeddedartists | 0:4977187e90c7 | 39 | _capy = (_win.ypmax-_win.ypmin-h)/2; |
embeddedartists | 0:4977187e90c7 | 40 | } |
embeddedartists | 0:4977187e90c7 | 41 | |
embeddedartists | 0:4977187e90c7 | 42 | void Button::setColors(COLOR_T bg, COLOR_T fg, COLOR_T bgPressed, COLOR_T fgPressed) |
embeddedartists | 0:4977187e90c7 | 43 | { |
embeddedartists | 0:4977187e90c7 | 44 | _bgCol = bg; |
embeddedartists | 0:4977187e90c7 | 45 | _fgCol = fg; |
embeddedartists | 0:4977187e90c7 | 46 | _bgColPressed = bgPressed; |
embeddedartists | 0:4977187e90c7 | 47 | _fgColPressed = fgPressed; |
embeddedartists | 0:4977187e90c7 | 48 | } |
embeddedartists | 0:4977187e90c7 | 49 | |
embeddedartists | 6:7917b0894655 | 50 | void Button::draw(COLOR_T* fb) |
embeddedartists | 0:4977187e90c7 | 51 | { |
embeddedartists | 6:7917b0894655 | 52 | if (fb != NULL) { |
embeddedartists | 6:7917b0894655 | 53 | _win.fb = fb; |
embeddedartists | 6:7917b0894655 | 54 | } |
embeddedartists | 0:4977187e90c7 | 55 | if (_pressed) { |
embeddedartists | 0:4977187e90c7 | 56 | swim_set_pen_color(&_win, _fgColPressed); |
embeddedartists | 0:4977187e90c7 | 57 | swim_set_bkg_color(&_win, _bgColPressed); |
embeddedartists | 0:4977187e90c7 | 58 | swim_set_fill_color(&_win, _fgColPressed); |
embeddedartists | 0:4977187e90c7 | 59 | swim_clear_screen(&_win, _bgColPressed); |
embeddedartists | 0:4977187e90c7 | 60 | } else { |
embeddedartists | 0:4977187e90c7 | 61 | swim_set_pen_color(&_win, _fgCol); |
embeddedartists | 0:4977187e90c7 | 62 | swim_set_bkg_color(&_win, _bgCol); |
embeddedartists | 0:4977187e90c7 | 63 | swim_set_fill_color(&_win, _fgCol); |
embeddedartists | 0:4977187e90c7 | 64 | swim_clear_screen(&_win, _bgCol); |
embeddedartists | 0:4977187e90c7 | 65 | } |
embeddedartists | 0:4977187e90c7 | 66 | swim_put_text_xy(&_win, _caption, _capx, _capy); |
embeddedartists | 0:4977187e90c7 | 67 | } |