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
Clickable.h
00001 /* 00002 * Copyright 2014 Embedded Artists AB 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef CLICKABLE_H 00018 #define CLICKABLE_H 00019 00020 #include "lpc_swim.h" 00021 00022 /** 00023 * Clickable is an abstract base class for the Button and ImageButton. 00024 */ 00025 class Clickable { 00026 public: 00027 00028 /** Creates a new clickable 00029 * 00030 * This clickable will use a SWIM window to draw on. That window will use 00031 * part of the full size frame buffer to draw on. 00032 * 00033 * @param fb the frame buffer 00034 * @param x the upper left corner of the button 00035 * @param y the upper left corner of the button 00036 * @param width the width of the button 00037 * @param height the height of the button 00038 */ 00039 Clickable(COLOR_T* fb, uint16_t x, uint16_t y, uint16_t width, uint16_t height); 00040 virtual ~Clickable() {}; 00041 00042 /** Set the function to call when clicked 00043 * 00044 * Note that this function can be called with NULL as func to unregister the 00045 * callback function. 00046 * 00047 * @param func the function to call 00048 * @param arc the argument to pass to the function when calling 00049 */ 00050 void setAction(void (*func)(uint32_t arg), uint32_t arg) { _func = func; _funcArg = arg; } 00051 00052 /** Process the touch event 00053 * 00054 * This function will detect if and how the touch event affects it. 00055 * If the event causes a click then the registered 00056 * callback function is called before handle() returns. 00057 * 00058 * The return value is to let the caller now if the button should be 00059 * redrawn or not. 00060 * 00061 * @param x the touched x coordinate 00062 * @param y the touched y coordinate 00063 * @param pressed true if the user pressed the display 00064 * 00065 * @returns 00066 * true if the button should be redrawn 00067 * false if the event did not affect the button 00068 */ 00069 bool handle(uint16_t x, uint16_t y, bool pressed); 00070 00071 /** Test if the button is held down (usable for repeated presses) 00072 * 00073 * @returns 00074 * true if the button is pressed 00075 * false otherwise 00076 */ 00077 bool pressed() { return _pressed; } 00078 00079 void bounds(int& x0, int& y0, int&x1, int&y1) { 00080 x0 = _win.xpmin; 00081 y0 = _win.ypmin; 00082 x1 = _win.xpmax; 00083 y1 = _win.ypmax; 00084 } 00085 00086 /** Draws the button (on a new framebuffer if one is specified) 00087 * @param fb the frame buffer 00088 */ 00089 virtual void draw(COLOR_T* fb = 0) = 0; 00090 00091 protected: 00092 bool _enabled, _pressed; 00093 SWIM_WINDOW_T _win; 00094 00095 private: 00096 void (*_func)(uint32_t arg); 00097 uint32_t _funcArg; 00098 }; 00099 00100 #endif /* CLICKABLE_H */
Generated on Tue Jul 12 2022 21:27:03 by 1.7.2