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:
Thu Dec 11 18:15:52 2014 +0000
Revision:
1:46c8df4608c8
Parent:
0:4977187e90c7
Child:
2:efae611de184
Updated documentation

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 1:46c8df4608c8 17 #ifndef BUTTON_H
embeddedartists 1:46c8df4608c8 18 #define BUTTON_H
embeddedartists 0:4977187e90c7 19
embeddedartists 0:4977187e90c7 20 #include "lpc_swim.h"
embeddedartists 0:4977187e90c7 21
embeddedartists 1:46c8df4608c8 22 /**
embeddedartists 1:46c8df4608c8 23 * Button example
embeddedartists 1:46c8df4608c8 24 *
embeddedartists 1:46c8df4608c8 25 * @code
embeddedartists 1:46c8df4608c8 26 * #include "mbed.h"
embeddedartists 1:46c8df4608c8 27 * #include "Button.h"
embeddedartists 1:46c8df4608c8 28 *
embeddedartists 1:46c8df4608c8 29 * SWIM_WINDOW_T win;
embeddedartists 1:46c8df4608c8 30 *
embeddedartists 1:46c8df4608c8 31 * static void buttonClicked(uint32_t x)
embeddedartists 1:46c8df4608c8 32 * {
embeddedartists 1:46c8df4608c8 33 * bool* done = (bool*)x;
embeddedartists 1:46c8df4608c8 34 * *done = true;
embeddedartists 1:46c8df4608c8 35 * }
embeddedartists 1:46c8df4608c8 36 *
embeddedartists 1:46c8df4608c8 37 * int main(void) {
embeddedartists 1:46c8df4608c8 38 * // initialize the display and touch
embeddedartists 1:46c8df4608c8 39 * DMBoard::instance().init();
embeddedartists 1:46c8df4608c8 40 *
embeddedartists 1:46c8df4608c8 41 * // setup the SWIM window to use
embeddedartists 1:46c8df4608c8 42 * swim_window_open(&win, ...);
embeddedartists 1:46c8df4608c8 43 *
embeddedartists 1:46c8df4608c8 44 * // create a 60x30 pixels button labeled "Done" at 100,100
embeddedartists 1:46c8df4608c8 45 * Button btn("Done", win.fb, 100, 100, 60, 30);
embeddedartists 1:46c8df4608c8 46 * btn.draw();
embeddedartists 1:46c8df4608c8 47 *
embeddedartists 1:46c8df4608c8 48 * // register a callback for when the button is pressed and pass the
embeddedartists 1:46c8df4608c8 49 * // done flag for the callback to modify
embeddedartists 1:46c8df4608c8 50 * bool done = false;
embeddedartists 1:46c8df4608c8 51 * btn.setAction(buttonClicked, (uint32_t)&done);
embeddedartists 1:46c8df4608c8 52 *
embeddedartists 1:46c8df4608c8 53 * // keep processing touch events until the button is clicked
embeddedartists 1:46c8df4608c8 54 * TouchPanel* touch = DMBoard::instance().touchPanel();
embeddedartists 1:46c8df4608c8 55 * TouchPanel::touchCoordinate_t coord;
embeddedartists 1:46c8df4608c8 56 * while(!done) {
embeddedartists 1:46c8df4608c8 57 * touch->read(coord);
embeddedartists 1:46c8df4608c8 58 * if (btn.handle(coord.x, coord.y, coord.z > 0)) {
embeddedartists 1:46c8df4608c8 59 * btn.draw();
embeddedartists 1:46c8df4608c8 60 * }
embeddedartists 1:46c8df4608c8 61 * }
embeddedartists 1:46c8df4608c8 62 * }
embeddedartists 1:46c8df4608c8 63 * @endcode
embeddedartists 1:46c8df4608c8 64 */
embeddedartists 0:4977187e90c7 65 class Button {
embeddedartists 0:4977187e90c7 66 public:
embeddedartists 1:46c8df4608c8 67
embeddedartists 1:46c8df4608c8 68 /** Creates a new button
embeddedartists 1:46c8df4608c8 69 *
embeddedartists 1:46c8df4608c8 70 * This button will use a SWIM window to draw on. That window will use
embeddedartists 1:46c8df4608c8 71 * part of the full size frame buffer to draw on.
embeddedartists 1:46c8df4608c8 72 *
embeddedartists 1:46c8df4608c8 73 * @param caption the button text
embeddedartists 1:46c8df4608c8 74 * @param fb the frame buffer
embeddedartists 1:46c8df4608c8 75 * @param x the upper left corner of the button
embeddedartists 1:46c8df4608c8 76 * @param y the upper left corner of the button
embeddedartists 1:46c8df4608c8 77 * @param width the width of the button
embeddedartists 1:46c8df4608c8 78 * @param height the height of the button
embeddedartists 1:46c8df4608c8 79 */
embeddedartists 0:4977187e90c7 80 Button(const char* caption, COLOR_T* fb, uint16_t x, uint16_t y, uint16_t width, uint16_t height);
embeddedartists 1:46c8df4608c8 81
embeddedartists 1:46c8df4608c8 82 /** Set the function to call when the button is clicked
embeddedartists 1:46c8df4608c8 83 *
embeddedartists 1:46c8df4608c8 84 * Note that this function can be called with NULL as func to unregister the
embeddedartists 1:46c8df4608c8 85 * callback function.
embeddedartists 1:46c8df4608c8 86 *
embeddedartists 1:46c8df4608c8 87 * @param func the function to call
embeddedartists 1:46c8df4608c8 88 * @param arc the argument to pass to the function when calling
embeddedartists 1:46c8df4608c8 89 */
embeddedartists 0:4977187e90c7 90 void setAction(void (*func)(uint32_t arg), uint32_t arg) { _func = func; _funcArg = arg; }
embeddedartists 1:46c8df4608c8 91
embeddedartists 1:46c8df4608c8 92 /** Changes the caption
embeddedartists 1:46c8df4608c8 93 *
embeddedartists 1:46c8df4608c8 94 * @param caption the new text on the button
embeddedartists 1:46c8df4608c8 95 */
embeddedartists 0:4977187e90c7 96 void setCaption(const char* caption);
embeddedartists 1:46c8df4608c8 97
embeddedartists 1:46c8df4608c8 98 /** Changes the colors
embeddedartists 1:46c8df4608c8 99 *
embeddedartists 1:46c8df4608c8 100 * @param bg background color when not pressed
embeddedartists 1:46c8df4608c8 101 * @param fg text color when pressed
embeddedartists 1:46c8df4608c8 102 * @param bgPressed background color when pressed
embeddedartists 1:46c8df4608c8 103 * @param fgPressed text color when pressed
embeddedartists 1:46c8df4608c8 104 */
embeddedartists 0:4977187e90c7 105 void setColors(COLOR_T bg, COLOR_T fg, COLOR_T bgPressed, COLOR_T fgPressed);
embeddedartists 1:46c8df4608c8 106
embeddedartists 1:46c8df4608c8 107 /** Process the touch event
embeddedartists 1:46c8df4608c8 108 *
embeddedartists 1:46c8df4608c8 109 * This function will detect if and how the touch event affects it.
embeddedartists 1:46c8df4608c8 110 * If the event causes the button to be clicked then the registered
embeddedartists 1:46c8df4608c8 111 * callback function is called before handle() returns.
embeddedartists 1:46c8df4608c8 112 *
embeddedartists 1:46c8df4608c8 113 * The return value is to let the caller now if the button should be
embeddedartists 1:46c8df4608c8 114 * redrawn or not.
embeddedartists 1:46c8df4608c8 115 *
embeddedartists 1:46c8df4608c8 116 * @param x the touched x coordinate
embeddedartists 1:46c8df4608c8 117 * @param y the touched y coordinate
embeddedartists 1:46c8df4608c8 118 * @param pressed true if the user pressed the display
embeddedartists 1:46c8df4608c8 119 *
embeddedartists 1:46c8df4608c8 120 * @returns
embeddedartists 1:46c8df4608c8 121 * true if the button should be redrawn
embeddedartists 1:46c8df4608c8 122 * false if the event did not affect the button
embeddedartists 1:46c8df4608c8 123 */
embeddedartists 0:4977187e90c7 124 bool handle(uint16_t x, uint16_t y, bool pressed);
embeddedartists 1:46c8df4608c8 125
embeddedartists 1:46c8df4608c8 126 /** Draws the button
embeddedartists 1:46c8df4608c8 127 */
embeddedartists 0:4977187e90c7 128 void draw();
embeddedartists 0:4977187e90c7 129
embeddedartists 0:4977187e90c7 130 private:
embeddedartists 0:4977187e90c7 131 const char* _caption;
embeddedartists 0:4977187e90c7 132 int _capx, _capy;
embeddedartists 0:4977187e90c7 133 COLOR_T _bgCol, _fgCol, _bgColPressed, _fgColPressed;
embeddedartists 0:4977187e90c7 134 bool _enabled, _pressed;
embeddedartists 0:4977187e90c7 135 void (*_func)(uint32_t arg);
embeddedartists 0:4977187e90c7 136 uint32_t _funcArg;
embeddedartists 0:4977187e90c7 137 SWIM_WINDOW_T _win;
embeddedartists 0:4977187e90c7 138 };
embeddedartists 0:4977187e90c7 139
embeddedartists 1:46c8df4608c8 140 #endif /* BUTTON_H */