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:
Mon Nov 04 14:31:50 2019 +0000
Revision:
22:f0d00f29bfeb
Parent:
10:651861441108
More updates related to mbed OS 5

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 2:efae611de184 1 /*
embeddedartists 2:efae611de184 2 * Copyright 2014 Embedded Artists AB
embeddedartists 2:efae611de184 3 *
embeddedartists 2:efae611de184 4 * Licensed under the Apache License, Version 2.0 (the "License");
embeddedartists 2:efae611de184 5 * you may not use this file except in compliance with the License.
embeddedartists 2:efae611de184 6 * You may obtain a copy of the License at
embeddedartists 2:efae611de184 7 *
embeddedartists 2:efae611de184 8 * http://www.apache.org/licenses/LICENSE-2.0
embeddedartists 2:efae611de184 9 *
embeddedartists 2:efae611de184 10 * Unless required by applicable law or agreed to in writing, software
embeddedartists 2:efae611de184 11 * distributed under the License is distributed on an "AS IS" BASIS,
embeddedartists 2:efae611de184 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
embeddedartists 2:efae611de184 13 * See the License for the specific language governing permissions and
embeddedartists 2:efae611de184 14 * limitations under the License.
embeddedartists 2:efae611de184 15 */
embeddedartists 2:efae611de184 16
embeddedartists 2:efae611de184 17 #ifndef CLICKABLE_H
embeddedartists 2:efae611de184 18 #define CLICKABLE_H
embeddedartists 2:efae611de184 19
embeddedartists 2:efae611de184 20 #include "lpc_swim.h"
embeddedartists 2:efae611de184 21
embeddedartists 2:efae611de184 22 /**
embeddedartists 2:efae611de184 23 * Clickable is an abstract base class for the Button and ImageButton.
embeddedartists 2:efae611de184 24 */
embeddedartists 2:efae611de184 25 class Clickable {
embeddedartists 2:efae611de184 26 public:
embeddedartists 2:efae611de184 27
embeddedartists 2:efae611de184 28 /** Creates a new clickable
embeddedartists 2:efae611de184 29 *
embeddedartists 2:efae611de184 30 * This clickable will use a SWIM window to draw on. That window will use
embeddedartists 2:efae611de184 31 * part of the full size frame buffer to draw on.
embeddedartists 2:efae611de184 32 *
embeddedartists 2:efae611de184 33 * @param fb the frame buffer
embeddedartists 2:efae611de184 34 * @param x the upper left corner of the button
embeddedartists 2:efae611de184 35 * @param y the upper left corner of the button
embeddedartists 2:efae611de184 36 * @param width the width of the button
embeddedartists 2:efae611de184 37 * @param height the height of the button
embeddedartists 2:efae611de184 38 */
embeddedartists 2:efae611de184 39 Clickable(COLOR_T* fb, uint16_t x, uint16_t y, uint16_t width, uint16_t height);
embeddedartists 10:651861441108 40 virtual ~Clickable() {};
embeddedartists 2:efae611de184 41
embeddedartists 2:efae611de184 42 /** Set the function to call when clicked
embeddedartists 2:efae611de184 43 *
embeddedartists 2:efae611de184 44 * Note that this function can be called with NULL as func to unregister the
embeddedartists 2:efae611de184 45 * callback function.
embeddedartists 2:efae611de184 46 *
embeddedartists 2:efae611de184 47 * @param func the function to call
embeddedartists 2:efae611de184 48 * @param arc the argument to pass to the function when calling
embeddedartists 2:efae611de184 49 */
embeddedartists 2:efae611de184 50 void setAction(void (*func)(uint32_t arg), uint32_t arg) { _func = func; _funcArg = arg; }
embeddedartists 2:efae611de184 51
embeddedartists 2:efae611de184 52 /** Process the touch event
embeddedartists 2:efae611de184 53 *
embeddedartists 2:efae611de184 54 * This function will detect if and how the touch event affects it.
embeddedartists 2:efae611de184 55 * If the event causes a click then the registered
embeddedartists 2:efae611de184 56 * callback function is called before handle() returns.
embeddedartists 2:efae611de184 57 *
embeddedartists 2:efae611de184 58 * The return value is to let the caller now if the button should be
embeddedartists 2:efae611de184 59 * redrawn or not.
embeddedartists 2:efae611de184 60 *
embeddedartists 2:efae611de184 61 * @param x the touched x coordinate
embeddedartists 2:efae611de184 62 * @param y the touched y coordinate
embeddedartists 2:efae611de184 63 * @param pressed true if the user pressed the display
embeddedartists 2:efae611de184 64 *
embeddedartists 2:efae611de184 65 * @returns
embeddedartists 2:efae611de184 66 * true if the button should be redrawn
embeddedartists 2:efae611de184 67 * false if the event did not affect the button
embeddedartists 2:efae611de184 68 */
embeddedartists 2:efae611de184 69 bool handle(uint16_t x, uint16_t y, bool pressed);
embeddedartists 2:efae611de184 70
embeddedartists 7:4ba7bd9d32ef 71 /** Test if the button is held down (usable for repeated presses)
embeddedartists 7:4ba7bd9d32ef 72 *
embeddedartists 7:4ba7bd9d32ef 73 * @returns
embeddedartists 7:4ba7bd9d32ef 74 * true if the button is pressed
embeddedartists 7:4ba7bd9d32ef 75 * false otherwise
embeddedartists 7:4ba7bd9d32ef 76 */
embeddedartists 7:4ba7bd9d32ef 77 bool pressed() { return _pressed; }
embeddedartists 7:4ba7bd9d32ef 78
embeddedartists 7:4ba7bd9d32ef 79 void bounds(int& x0, int& y0, int&x1, int&y1) {
embeddedartists 7:4ba7bd9d32ef 80 x0 = _win.xpmin;
embeddedartists 7:4ba7bd9d32ef 81 y0 = _win.ypmin;
embeddedartists 7:4ba7bd9d32ef 82 x1 = _win.xpmax;
embeddedartists 7:4ba7bd9d32ef 83 y1 = _win.ypmax;
embeddedartists 7:4ba7bd9d32ef 84 }
embeddedartists 7:4ba7bd9d32ef 85
embeddedartists 6:7917b0894655 86 /** Draws the button (on a new framebuffer if one is specified)
embeddedartists 6:7917b0894655 87 * @param fb the frame buffer
embeddedartists 2:efae611de184 88 */
embeddedartists 6:7917b0894655 89 virtual void draw(COLOR_T* fb = 0) = 0;
embeddedartists 7:4ba7bd9d32ef 90
embeddedartists 2:efae611de184 91 protected:
embeddedartists 2:efae611de184 92 bool _enabled, _pressed;
embeddedartists 2:efae611de184 93 SWIM_WINDOW_T _win;
embeddedartists 2:efae611de184 94
embeddedartists 2:efae611de184 95 private:
embeddedartists 2:efae611de184 96 void (*_func)(uint32_t arg);
embeddedartists 2:efae611de184 97 uint32_t _funcArg;
embeddedartists 2:efae611de184 98 };
embeddedartists 2:efae611de184 99
embeddedartists 2:efae611de184 100 #endif /* CLICKABLE_H */