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
embeddedartists 0:316c181e9b65 2 #ifndef EWBUTTON_H
embeddedartists 0:316c181e9b65 3 #define EWBUTTON_H
embeddedartists 0:316c181e9b65 4
embeddedartists 0:316c181e9b65 5 #include "EwPainter.h"
embeddedartists 0:316c181e9b65 6 #include "EwWindow.h"
embeddedartists 0:316c181e9b65 7 #include "EwFunctionPointer.h"
embeddedartists 0:316c181e9b65 8
embeddedartists 0:316c181e9b65 9 #include "BUTTON.h"
embeddedartists 0:316c181e9b65 10
embeddedartists 0:316c181e9b65 11 enum ewButtonColorIndex_t {
embeddedartists 0:316c181e9b65 12 ButtonColorIndexDisabled = BUTTON_CI_DISABLED,
embeddedartists 0:316c181e9b65 13 ButtonColorIndexPressed = BUTTON_CI_PRESSED,
embeddedartists 0:316c181e9b65 14 ButtonColorIndexUnpressed = BUTTON_CI_UNPRESSED,
embeddedartists 0:316c181e9b65 15 };
embeddedartists 0:316c181e9b65 16
embeddedartists 0:316c181e9b65 17 /**
embeddedartists 0:316c181e9b65 18 * This is a wrapper class for the emwin BUTTON interface.
embeddedartists 0:316c181e9b65 19 */
embeddedartists 0:316c181e9b65 20 class EwButton : public EwWindow {
embeddedartists 0:316c181e9b65 21 public:
embeddedartists 0:316c181e9b65 22
embeddedartists 0:316c181e9b65 23 EwButton(EwWindow* parent = 0);
embeddedartists 0:316c181e9b65 24 EwButton(int x, int y, int width, int height, EwWindow* parent = 0);
embeddedartists 0:316c181e9b65 25
embeddedartists 0:316c181e9b65 26
embeddedartists 0:316c181e9b65 27 void setText(const char* text);
embeddedartists 0:316c181e9b65 28 void getText(char* pBuf, int bufSz);
embeddedartists 0:316c181e9b65 29
embeddedartists 0:316c181e9b65 30 ewColor_t getBackgroundColor(ewButtonColorIndex_t idx);
embeddedartists 0:316c181e9b65 31 void setBackgroundColor(ewButtonColorIndex_t idx, ewColor_t c);
embeddedartists 0:316c181e9b65 32 const ewFont_t* getFont();
embeddedartists 0:316c181e9b65 33 void setFont(const ewFont_t* pFont);
embeddedartists 0:316c181e9b65 34
embeddedartists 0:316c181e9b65 35 ewTextAlign_t getTextAlign();
embeddedartists 0:316c181e9b65 36 void setTextAlign(ewTextAlign_t align);
embeddedartists 0:316c181e9b65 37 ewColor_t getTextColor(ewButtonColorIndex_t idx);
embeddedartists 0:316c181e9b65 38 void setTextColor(ewButtonColorIndex_t idx, ewColor_t c);
embeddedartists 0:316c181e9b65 39
embeddedartists 0:316c181e9b65 40 void setFocusColor(ewColor_t c);
embeddedartists 0:316c181e9b65 41 void setFocussable(bool focussable);
embeddedartists 0:316c181e9b65 42 void setPressed(bool pressed);
embeddedartists 0:316c181e9b65 43 bool isPressed();
embeddedartists 0:316c181e9b65 44
embeddedartists 0:316c181e9b65 45 void setTextOffset(int32_t xPos, int32_t yPos);
embeddedartists 0:316c181e9b65 46
embeddedartists 0:316c181e9b65 47 const ewBitmap_t* getBitmap(ewButtonColorIndex_t idx);
embeddedartists 0:316c181e9b65 48 void setBitmap(ewButtonColorIndex_t idx, const ewBitmap_t* pBitmap);
embeddedartists 0:316c181e9b65 49 void setBitmap(ewButtonColorIndex_t idx, const ewBitmap_t* pBitmap, int32_t x, int32_t y);
embeddedartists 0:316c181e9b65 50
embeddedartists 0:316c181e9b65 51 /**
embeddedartists 0:316c181e9b65 52 * Register a member function that will called when the button
embeddedartists 0:316c181e9b65 53 * is pressed.
embeddedartists 0:316c181e9b65 54 *
embeddedartists 0:316c181e9b65 55 * @param tptr pointer to the object to call the member function on
embeddedartists 0:316c181e9b65 56 * @param mptr pointer to the member function to be called
embeddedartists 0:316c181e9b65 57 */
embeddedartists 0:316c181e9b65 58 template<typename T>
embeddedartists 0:316c181e9b65 59 void setPressedListener(T* tptr, void (T::*mptr)(EwWindow* w)) {
embeddedartists 0:316c181e9b65 60 if((mptr != NULL) && (tptr != NULL)) {
embeddedartists 0:316c181e9b65 61 _pressedListener.attach(tptr, mptr);
embeddedartists 0:316c181e9b65 62 }
embeddedartists 0:316c181e9b65 63 }
embeddedartists 0:316c181e9b65 64
embeddedartists 0:316c181e9b65 65 /**
embeddedartists 0:316c181e9b65 66 * Register a function that will called when the button
embeddedartists 0:316c181e9b65 67 * is pressed.
embeddedartists 0:316c181e9b65 68 *
embeddedartists 0:316c181e9b65 69 * @param fptr A pointer to a void function that will be called
embeddedartists 0:316c181e9b65 70 * when the button is pressed
embeddedartists 0:316c181e9b65 71 */
embeddedartists 0:316c181e9b65 72 void setPressedListener(void (*fptr)(EwWindow* w));
embeddedartists 0:316c181e9b65 73
embeddedartists 0:316c181e9b65 74 /**
embeddedartists 0:316c181e9b65 75 * Register a member function that will called when the button
embeddedartists 0:316c181e9b65 76 * is released.
embeddedartists 0:316c181e9b65 77 *
embeddedartists 0:316c181e9b65 78 * @param tptr pointer to the object to call the member function on
embeddedartists 0:316c181e9b65 79 * @param mptr pointer to the member function to be called
embeddedartists 0:316c181e9b65 80 */
embeddedartists 0:316c181e9b65 81 template<typename T>
embeddedartists 0:316c181e9b65 82 void setReleasedListener(T* tptr, void (T::*mptr)(EwWindow* w)) {
embeddedartists 0:316c181e9b65 83 if((mptr != NULL) && (tptr != NULL)) {
embeddedartists 0:316c181e9b65 84 _releasedListener.attach(tptr, mptr);
embeddedartists 0:316c181e9b65 85 }
embeddedartists 0:316c181e9b65 86 }
embeddedartists 0:316c181e9b65 87
embeddedartists 0:316c181e9b65 88 /**
embeddedartists 0:316c181e9b65 89 * Register a function that will called when the button
embeddedartists 0:316c181e9b65 90 * is released.
embeddedartists 0:316c181e9b65 91 *
embeddedartists 0:316c181e9b65 92 * @param fptr A pointer to a void function that will be called
embeddedartists 0:316c181e9b65 93 * when the button is released
embeddedartists 0:316c181e9b65 94 */
embeddedartists 0:316c181e9b65 95 void setReleasedListener(void (*fptr)(EwWindow* w));
embeddedartists 0:316c181e9b65 96
embeddedartists 0:316c181e9b65 97 /**
embeddedartists 0:316c181e9b65 98 * Register a member function that will called when the button
embeddedartists 0:316c181e9b65 99 * is clicked.
embeddedartists 0:316c181e9b65 100 *
embeddedartists 0:316c181e9b65 101 * @param tptr pointer to the object to call the member function on
embeddedartists 0:316c181e9b65 102 * @param mptr pointer to the member function to be called
embeddedartists 0:316c181e9b65 103 */
embeddedartists 0:316c181e9b65 104 template<typename T>
embeddedartists 0:316c181e9b65 105 void setClickedListener(T* tptr, void (T::*mptr)(EwWindow* w)) {
embeddedartists 0:316c181e9b65 106 if((mptr != NULL) && (tptr != NULL)) {
embeddedartists 0:316c181e9b65 107 _clickedListener.attach(tptr, mptr);
embeddedartists 0:316c181e9b65 108 }
embeddedartists 0:316c181e9b65 109 }
embeddedartists 0:316c181e9b65 110
embeddedartists 0:316c181e9b65 111 /**
embeddedartists 0:316c181e9b65 112 * Register a function that will called when the button
embeddedartists 0:316c181e9b65 113 * is clicked.
embeddedartists 0:316c181e9b65 114 *
embeddedartists 0:316c181e9b65 115 * @param fptr A pointer to a void function that will be called
embeddedartists 0:316c181e9b65 116 * when the button is clicked
embeddedartists 0:316c181e9b65 117 */
embeddedartists 0:316c181e9b65 118 void setClickedListener(void (*fptr)(EwWindow* w));
embeddedartists 0:316c181e9b65 119
embeddedartists 0:316c181e9b65 120 static ewColor_t getDefaultBackgroundColor(ewButtonColorIndex_t idx);
embeddedartists 0:316c181e9b65 121 static void setDefaultBackgroundColor(ewButtonColorIndex_t idx, ewColor_t c);
embeddedartists 0:316c181e9b65 122 static const ewFont_t* getDefaultFont();
embeddedartists 0:316c181e9b65 123 static void setDefaultFont(const ewFont_t* pFont);
embeddedartists 0:316c181e9b65 124 static ewTextAlign_t getDefaultTextAlign();
embeddedartists 0:316c181e9b65 125 static void setDefaultTextAlign(ewTextAlign_t align);
embeddedartists 0:316c181e9b65 126 static ewColor_t getDefaultTextColor(ewButtonColorIndex_t idx);
embeddedartists 0:316c181e9b65 127 static void setDefaultTextColor(ewButtonColorIndex_t idx, ewColor_t c);
embeddedartists 0:316c181e9b65 128
embeddedartists 0:316c181e9b65 129 static void setDefaultFocusColor(ewColor_t c);
embeddedartists 0:316c181e9b65 130
embeddedartists 0:316c181e9b65 131
embeddedartists 0:316c181e9b65 132
embeddedartists 0:316c181e9b65 133
embeddedartists 0:316c181e9b65 134 private:
embeddedartists 0:316c181e9b65 135
embeddedartists 0:316c181e9b65 136 bool _inputStatePressed;
embeddedartists 0:316c181e9b65 137 EwFunctionPointer _pressedListener;
embeddedartists 0:316c181e9b65 138 EwFunctionPointer _releasedListener;
embeddedartists 0:316c181e9b65 139 EwFunctionPointer _clickedListener;
embeddedartists 0:316c181e9b65 140
embeddedartists 0:316c181e9b65 141 void init(int x, int y, int width, int height, EwWindow* parent);
embeddedartists 0:316c181e9b65 142 void handleInput(bool pressed, bool onWidget);
embeddedartists 0:316c181e9b65 143
embeddedartists 0:316c181e9b65 144 static void _callback(WM_MESSAGE* pMsg, EwWindow* w);
embeddedartists 0:316c181e9b65 145
embeddedartists 0:316c181e9b65 146
embeddedartists 0:316c181e9b65 147 };
embeddedartists 0:316c181e9b65 148
embeddedartists 0:316c181e9b65 149 #endif