Chris Womack / DMBasicGUI

Fork of DMBasicGUI by Embedded Artists

Revision:
2:efae611de184
Child:
6:7917b0894655
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Application/Clickable.h	Fri Dec 19 07:37:24 2014 +0000
@@ -0,0 +1,83 @@
+/*
+ *  Copyright 2014 Embedded Artists AB
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+ 
+#ifndef CLICKABLE_H
+#define CLICKABLE_H
+
+#include "lpc_swim.h"
+
+/**
+ * Clickable is an abstract base class for the Button and ImageButton.
+ */
+class Clickable {
+public:
+
+    /** Creates a new clickable
+     *
+     *  This clickable will use a SWIM window to draw on. That window will use
+     *  part of the full size frame buffer to draw on.
+     *
+     *  @param fb      the frame buffer
+     *  @param x       the upper left corner of the button
+     *  @param y       the upper left corner of the button
+     *  @param width   the width of the button
+     *  @param height  the height of the button
+     */
+  Clickable(COLOR_T* fb, uint16_t x, uint16_t y, uint16_t width, uint16_t height);
+  
+    /** Set the function to call when  clicked
+     *
+     *  Note that this function can be called with NULL as func to unregister the
+     *  callback function.
+     *
+     *  @param func the function to call
+     *  @param arc the argument to pass to the function when calling
+     */
+  void setAction(void (*func)(uint32_t arg), uint32_t arg) { _func = func; _funcArg = arg; }
+  
+    /** Process the touch event
+     *
+     *  This function will detect if and how the touch event affects it.
+     *  If the event causes a click then the registered
+     *  callback function is called before handle() returns.
+     *
+     *  The return value is to let the caller now if the button should be
+     *  redrawn or not.
+     *
+     *  @param x       the touched x coordinate
+     *  @param y       the touched y coordinate
+     *  @param pressed true if the user pressed the display
+     *
+     *  @returns
+     *       true if the button should be redrawn
+     *       false if the event did not affect the button
+     */
+  bool handle(uint16_t x, uint16_t y, bool pressed);
+
+    /** Draws the button
+     */
+  virtual void draw() = 0;
+
+protected:
+  bool _enabled, _pressed;
+  SWIM_WINDOW_T _win;
+
+private:
+  void (*_func)(uint32_t arg);
+  uint32_t _funcArg;
+};
+
+#endif /* CLICKABLE_H */