Wrapper classes for the emwin library

Dependents:   app_emwin1 app_emwin2_pos lpc4088_ebb_gui_emwin

Committer:
embeddedartists
Date:
Mon Apr 14 08:38:33 2014 +0000
Revision:
1:0b16165ada7c
Parent:
0:316c181e9b65
Initialize uninitialized touchState in EwGui

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 0:316c181e9b65 1 /* mbed Microcontroller Library
embeddedartists 0:316c181e9b65 2 * Copyright (c) 2006-2013 ARM Limited
embeddedartists 0:316c181e9b65 3 *
embeddedartists 0:316c181e9b65 4 * Licensed under the Apache License, Version 2.0 (the "License");
embeddedartists 0:316c181e9b65 5 * you may not use this file except in compliance with the License.
embeddedartists 0:316c181e9b65 6 * You may obtain a copy of the License at
embeddedartists 0:316c181e9b65 7 *
embeddedartists 0:316c181e9b65 8 * http://www.apache.org/licenses/LICENSE-2.0
embeddedartists 0:316c181e9b65 9 *
embeddedartists 0:316c181e9b65 10 * Unless required by applicable law or agreed to in writing, software
embeddedartists 0:316c181e9b65 11 * distributed under the License is distributed on an "AS IS" BASIS,
embeddedartists 0:316c181e9b65 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
embeddedartists 0:316c181e9b65 13 * See the License for the specific language governing permissions and
embeddedartists 0:316c181e9b65 14 * limitations under the License.
embeddedartists 0:316c181e9b65 15 */
embeddedartists 0:316c181e9b65 16 #ifndef EWFUNCTIONPOINTER_H
embeddedartists 0:316c181e9b65 17 #define EWFUNCTIONPOINTER_H
embeddedartists 0:316c181e9b65 18
embeddedartists 0:316c181e9b65 19 #include <string.h>
embeddedartists 0:316c181e9b65 20 #include <stdint.h>
embeddedartists 0:316c181e9b65 21 #include "EwWindow.h"
embeddedartists 0:316c181e9b65 22
embeddedartists 0:316c181e9b65 23
embeddedartists 0:316c181e9b65 24
embeddedartists 0:316c181e9b65 25
embeddedartists 0:316c181e9b65 26 /** A class for storing and calling a pointer to a static or member void function
embeddedartists 0:316c181e9b65 27 */
embeddedartists 0:316c181e9b65 28 class EwFunctionPointer {
embeddedartists 0:316c181e9b65 29 public:
embeddedartists 0:316c181e9b65 30
embeddedartists 0:316c181e9b65 31 /** Create a FunctionPointer, attaching a static function
embeddedartists 0:316c181e9b65 32 *
embeddedartists 0:316c181e9b65 33 * @param function The void static function to attach (default is none)
embeddedartists 0:316c181e9b65 34 */
embeddedartists 0:316c181e9b65 35 EwFunctionPointer(void (*function)(EwWindow* w) = 0);
embeddedartists 0:316c181e9b65 36
embeddedartists 0:316c181e9b65 37 /** Create a FunctionPointer, attaching a member function
embeddedartists 0:316c181e9b65 38 *
embeddedartists 0:316c181e9b65 39 * @param object The object pointer to invoke the member function on (i.e. the this pointer)
embeddedartists 0:316c181e9b65 40 * @param function The address of the void member function to attach
embeddedartists 0:316c181e9b65 41 */
embeddedartists 0:316c181e9b65 42 template<typename T>
embeddedartists 0:316c181e9b65 43 EwFunctionPointer(T *object, void (T::*member)(EwWindow* w)) {
embeddedartists 0:316c181e9b65 44 attach(object, member);
embeddedartists 0:316c181e9b65 45 }
embeddedartists 0:316c181e9b65 46
embeddedartists 0:316c181e9b65 47 /** Attach a static function
embeddedartists 0:316c181e9b65 48 *
embeddedartists 0:316c181e9b65 49 * @param function The void static function to attach (default is none)
embeddedartists 0:316c181e9b65 50 */
embeddedartists 0:316c181e9b65 51 void attach(void (*function)(EwWindow* w) = 0);
embeddedartists 0:316c181e9b65 52
embeddedartists 0:316c181e9b65 53 /** Attach a member function
embeddedartists 0:316c181e9b65 54 *
embeddedartists 0:316c181e9b65 55 * @param object The object pointer to invoke the member function on (i.e. the this pointer)
embeddedartists 0:316c181e9b65 56 * @param function The address of the void member function to attach
embeddedartists 0:316c181e9b65 57 */
embeddedartists 0:316c181e9b65 58 template<typename T>
embeddedartists 0:316c181e9b65 59 void attach(T *object, void (T::*member)(EwWindow* w)) {
embeddedartists 0:316c181e9b65 60 _object = static_cast<void*>(object);
embeddedartists 0:316c181e9b65 61 memcpy(_member, (char*)&member, sizeof(member));
embeddedartists 0:316c181e9b65 62 _membercaller = &EwFunctionPointer::membercaller<T>;
embeddedartists 0:316c181e9b65 63 _function = 0;
embeddedartists 0:316c181e9b65 64 }
embeddedartists 0:316c181e9b65 65
embeddedartists 0:316c181e9b65 66 /** Call the attached static or member function
embeddedartists 0:316c181e9b65 67 */
embeddedartists 0:316c181e9b65 68 void call(EwWindow* w);
embeddedartists 0:316c181e9b65 69
embeddedartists 0:316c181e9b65 70
embeddedartists 0:316c181e9b65 71
embeddedartists 0:316c181e9b65 72
embeddedartists 0:316c181e9b65 73 private:
embeddedartists 0:316c181e9b65 74 template<typename T>
embeddedartists 0:316c181e9b65 75 static void membercaller(void *object, char *member, EwWindow* w) {
embeddedartists 0:316c181e9b65 76 T* o = static_cast<T*>(object);
embeddedartists 0:316c181e9b65 77 void (T::*m)(EwWindow* w);
embeddedartists 0:316c181e9b65 78 memcpy((char*)&m, member, sizeof(m));
embeddedartists 0:316c181e9b65 79 (o->*m)(w);
embeddedartists 0:316c181e9b65 80 }
embeddedartists 0:316c181e9b65 81
embeddedartists 0:316c181e9b65 82 void (*_function)(EwWindow* w); // static function pointer - 0 if none attached
embeddedartists 0:316c181e9b65 83 void *_object; // object this pointer - 0 if none attached
embeddedartists 0:316c181e9b65 84 char _member[16]; // raw member function pointer storage - converted back by registered _membercaller
embeddedartists 0:316c181e9b65 85 void (*_membercaller)(void*, char*, EwWindow* w); // registered membercaller function to convert back and call _member on _object
embeddedartists 0:316c181e9b65 86 };
embeddedartists 0:316c181e9b65 87
embeddedartists 0:316c181e9b65 88
embeddedartists 0:316c181e9b65 89
embeddedartists 0:316c181e9b65 90 #endif