Wrapper classes for the emwin library

Dependents:   app_emwin1 app_emwin2_pos lpc4088_ebb_gui_emwin

Committer:
embeddedartists
Date:
Mon Dec 16 07:03:22 2013 +0000
Revision:
0:316c181e9b65
First commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 0:316c181e9b65 1 #include "mbed.h"
embeddedartists 0:316c181e9b65 2
embeddedartists 0:316c181e9b65 3 #include "EwButton.h"
embeddedartists 0:316c181e9b65 4
embeddedartists 0:316c181e9b65 5
embeddedartists 0:316c181e9b65 6 EwButton::EwButton(EwWindow* parent) : EwWindow(parent) {
embeddedartists 0:316c181e9b65 7 init(0, 0, 0, 0, parent);
embeddedartists 0:316c181e9b65 8 }
embeddedartists 0:316c181e9b65 9
embeddedartists 0:316c181e9b65 10 EwButton::EwButton(int x, int y, int width, int height, EwWindow* parent) :
embeddedartists 0:316c181e9b65 11 EwWindow(x, y, width, height, parent) {
embeddedartists 0:316c181e9b65 12
embeddedartists 0:316c181e9b65 13 init(x, y, width, height, parent);
embeddedartists 0:316c181e9b65 14 }
embeddedartists 0:316c181e9b65 15
embeddedartists 0:316c181e9b65 16 void EwButton::setText(const char* text) {
embeddedartists 0:316c181e9b65 17 BUTTON_SetText(_hWnd, text);
embeddedartists 0:316c181e9b65 18 }
embeddedartists 0:316c181e9b65 19
embeddedartists 0:316c181e9b65 20 void EwButton::getText(char* pBuf, int bufSz) {
embeddedartists 0:316c181e9b65 21 BUTTON_GetText(_hWnd, pBuf, bufSz);
embeddedartists 0:316c181e9b65 22 }
embeddedartists 0:316c181e9b65 23
embeddedartists 0:316c181e9b65 24 ewColor_t EwButton::getBackgroundColor(ewButtonColorIndex_t idx) {
embeddedartists 0:316c181e9b65 25 return BUTTON_GetBkColor(_hWnd, idx);
embeddedartists 0:316c181e9b65 26 }
embeddedartists 0:316c181e9b65 27
embeddedartists 0:316c181e9b65 28 void EwButton::setBackgroundColor(ewButtonColorIndex_t idx, ewColor_t c) {
embeddedartists 0:316c181e9b65 29 BUTTON_SetBkColor(_hWnd, idx, c);
embeddedartists 0:316c181e9b65 30 }
embeddedartists 0:316c181e9b65 31
embeddedartists 0:316c181e9b65 32 const ewFont_t* EwButton::getFont() {
embeddedartists 0:316c181e9b65 33 return BUTTON_GetFont(_hWnd);
embeddedartists 0:316c181e9b65 34 }
embeddedartists 0:316c181e9b65 35
embeddedartists 0:316c181e9b65 36 void EwButton::setFont(const ewFont_t* pFont) {
embeddedartists 0:316c181e9b65 37 BUTTON_SetFont(_hWnd, pFont);
embeddedartists 0:316c181e9b65 38 }
embeddedartists 0:316c181e9b65 39
embeddedartists 0:316c181e9b65 40 ewTextAlign_t EwButton::getTextAlign() {
embeddedartists 0:316c181e9b65 41 return (ewTextAlign_t)BUTTON_GetTextAlign(_hWnd);
embeddedartists 0:316c181e9b65 42 }
embeddedartists 0:316c181e9b65 43
embeddedartists 0:316c181e9b65 44 void EwButton::setTextAlign(ewTextAlign_t align) {
embeddedartists 0:316c181e9b65 45 BUTTON_SetTextAlign(_hWnd, align);
embeddedartists 0:316c181e9b65 46 }
embeddedartists 0:316c181e9b65 47
embeddedartists 0:316c181e9b65 48 ewColor_t EwButton::getTextColor(ewButtonColorIndex_t idx) {
embeddedartists 0:316c181e9b65 49 return BUTTON_GetTextColor(_hWnd, idx);
embeddedartists 0:316c181e9b65 50 }
embeddedartists 0:316c181e9b65 51
embeddedartists 0:316c181e9b65 52 void EwButton::setTextColor(ewButtonColorIndex_t idx, ewColor_t c) {
embeddedartists 0:316c181e9b65 53 BUTTON_SetTextColor(_hWnd, idx, c);
embeddedartists 0:316c181e9b65 54 }
embeddedartists 0:316c181e9b65 55
embeddedartists 0:316c181e9b65 56 void EwButton::setFocusColor(ewColor_t c) {
embeddedartists 0:316c181e9b65 57 BUTTON_SetFocusColor(_hWnd, c);
embeddedartists 0:316c181e9b65 58 }
embeddedartists 0:316c181e9b65 59
embeddedartists 0:316c181e9b65 60 void EwButton::setFocussable(bool focussable) {
embeddedartists 0:316c181e9b65 61 BUTTON_SetFocussable(_hWnd, (focussable ? 1 : 0));
embeddedartists 0:316c181e9b65 62 }
embeddedartists 0:316c181e9b65 63
embeddedartists 0:316c181e9b65 64 void EwButton::setPressed(bool pressed) {
embeddedartists 0:316c181e9b65 65 BUTTON_SetPressed(_hWnd, (pressed ? 1 : 0));
embeddedartists 0:316c181e9b65 66 }
embeddedartists 0:316c181e9b65 67
embeddedartists 0:316c181e9b65 68 bool EwButton::isPressed() {
embeddedartists 0:316c181e9b65 69 return (BUTTON_IsPressed(_hWnd) == 1);
embeddedartists 0:316c181e9b65 70 }
embeddedartists 0:316c181e9b65 71
embeddedartists 0:316c181e9b65 72
embeddedartists 0:316c181e9b65 73 void EwButton::setTextOffset(int32_t xPos, int32_t yPos) {
embeddedartists 0:316c181e9b65 74 BUTTON_SetTextOffset(_hWnd, xPos, yPos);
embeddedartists 0:316c181e9b65 75 }
embeddedartists 0:316c181e9b65 76
embeddedartists 0:316c181e9b65 77 const ewBitmap_t* EwButton::getBitmap(ewButtonColorIndex_t idx) {
embeddedartists 0:316c181e9b65 78 return BUTTON_GetBitmap(_hWnd, idx);
embeddedartists 0:316c181e9b65 79 }
embeddedartists 0:316c181e9b65 80
embeddedartists 0:316c181e9b65 81 void EwButton::setBitmap(ewButtonColorIndex_t idx, const ewBitmap_t* pBitmap) {
embeddedartists 0:316c181e9b65 82 BUTTON_SetBitmap(_hWnd, idx, pBitmap);
embeddedartists 0:316c181e9b65 83 }
embeddedartists 0:316c181e9b65 84
embeddedartists 0:316c181e9b65 85 void EwButton::setBitmap(ewButtonColorIndex_t idx, const ewBitmap_t* pBitmap, int32_t x, int32_t y) {
embeddedartists 0:316c181e9b65 86 BUTTON_SetBitmapEx(_hWnd, idx, pBitmap, x, y);
embeddedartists 0:316c181e9b65 87 }
embeddedartists 0:316c181e9b65 88
embeddedartists 0:316c181e9b65 89 void EwButton::setPressedListener(void (*fptr)(EwWindow* w)) {
embeddedartists 0:316c181e9b65 90 _pressedListener.attach(fptr);
embeddedartists 0:316c181e9b65 91 }
embeddedartists 0:316c181e9b65 92
embeddedartists 0:316c181e9b65 93 void EwButton::setReleasedListener(void (*fptr)(EwWindow* w)) {
embeddedartists 0:316c181e9b65 94 _releasedListener.attach(fptr);
embeddedartists 0:316c181e9b65 95 }
embeddedartists 0:316c181e9b65 96
embeddedartists 0:316c181e9b65 97 void EwButton::setClickedListener(void (*fptr)(EwWindow* w)) {
embeddedartists 0:316c181e9b65 98 _clickedListener.attach(fptr);
embeddedartists 0:316c181e9b65 99 }
embeddedartists 0:316c181e9b65 100
embeddedartists 0:316c181e9b65 101 ewColor_t EwButton::getDefaultBackgroundColor(ewButtonColorIndex_t idx) {
embeddedartists 0:316c181e9b65 102 return BUTTON_GetDefaultBkColor(idx);
embeddedartists 0:316c181e9b65 103 }
embeddedartists 0:316c181e9b65 104
embeddedartists 0:316c181e9b65 105 void EwButton::setDefaultBackgroundColor(ewButtonColorIndex_t idx, ewColor_t c) {
embeddedartists 0:316c181e9b65 106 BUTTON_SetDefaultBkColor(c, idx);
embeddedartists 0:316c181e9b65 107 }
embeddedartists 0:316c181e9b65 108
embeddedartists 0:316c181e9b65 109 void EwButton::setDefaultFont(const ewFont_t* pFont) {
embeddedartists 0:316c181e9b65 110 BUTTON_SetDefaultFont(pFont);
embeddedartists 0:316c181e9b65 111 }
embeddedartists 0:316c181e9b65 112
embeddedartists 0:316c181e9b65 113 const ewFont_t* EwButton::getDefaultFont() {
embeddedartists 0:316c181e9b65 114 return BUTTON_GetDefaultFont();
embeddedartists 0:316c181e9b65 115 }
embeddedartists 0:316c181e9b65 116
embeddedartists 0:316c181e9b65 117 ewTextAlign_t EwButton::getDefaultTextAlign() {
embeddedartists 0:316c181e9b65 118 return (ewTextAlign_t) BUTTON_GetDefaultTextAlign();
embeddedartists 0:316c181e9b65 119 }
embeddedartists 0:316c181e9b65 120
embeddedartists 0:316c181e9b65 121 void EwButton::setDefaultTextAlign(ewTextAlign_t align) {
embeddedartists 0:316c181e9b65 122 BUTTON_SetDefaultTextAlign(align);
embeddedartists 0:316c181e9b65 123 }
embeddedartists 0:316c181e9b65 124
embeddedartists 0:316c181e9b65 125 ewColor_t EwButton::getDefaultTextColor(ewButtonColorIndex_t idx) {
embeddedartists 0:316c181e9b65 126 return BUTTON_GetDefaultTextColor(idx);
embeddedartists 0:316c181e9b65 127 }
embeddedartists 0:316c181e9b65 128
embeddedartists 0:316c181e9b65 129 void EwButton::setDefaultTextColor(ewButtonColorIndex_t idx, ewColor_t c) {
embeddedartists 0:316c181e9b65 130 BUTTON_SetDefaultTextColor(c, idx);
embeddedartists 0:316c181e9b65 131 }
embeddedartists 0:316c181e9b65 132
embeddedartists 0:316c181e9b65 133 void EwButton::setDefaultFocusColor(ewColor_t c) {
embeddedartists 0:316c181e9b65 134 BUTTON_SetDefaultFocusColor(c);
embeddedartists 0:316c181e9b65 135 }
embeddedartists 0:316c181e9b65 136
embeddedartists 0:316c181e9b65 137
embeddedartists 0:316c181e9b65 138 void EwButton::init(int x, int y, int width, int height, EwWindow* parent) {
embeddedartists 0:316c181e9b65 139 BUTTON_Handle h;
embeddedartists 0:316c181e9b65 140 GUI_HWIN hWin = 0;
embeddedartists 0:316c181e9b65 141
embeddedartists 0:316c181e9b65 142 _inputStatePressed = false;
embeddedartists 0:316c181e9b65 143
embeddedartists 0:316c181e9b65 144 if (parent) {
embeddedartists 0:316c181e9b65 145 hWin = _getHandle(parent);
embeddedartists 0:316c181e9b65 146 }
embeddedartists 0:316c181e9b65 147
embeddedartists 0:316c181e9b65 148 h = BUTTON_CreateEx(x, y, width, height, hWin, (WM_CF_SHOW| WM_CF_MEMDEV),
embeddedartists 0:316c181e9b65 149 0, _guiWidgetId++);
embeddedartists 0:316c181e9b65 150 _setNewHandle(h, _callback);
embeddedartists 0:316c181e9b65 151 }
embeddedartists 0:316c181e9b65 152
embeddedartists 0:316c181e9b65 153 void EwButton::handleInput(bool pressed, bool onWidget) {
embeddedartists 0:316c181e9b65 154
embeddedartists 0:316c181e9b65 155 // pressed will always be on top of widget
embeddedartists 0:316c181e9b65 156 if (pressed && !_inputStatePressed) {
embeddedartists 0:316c181e9b65 157 _pressedListener.call(this);
embeddedartists 0:316c181e9b65 158 }
embeddedartists 0:316c181e9b65 159
embeddedartists 0:316c181e9b65 160 // always generate a released event (even if not released on top of widget)
embeddedartists 0:316c181e9b65 161 if (!pressed && _inputStatePressed) {
embeddedartists 0:316c181e9b65 162 _releasedListener.call(this);
embeddedartists 0:316c181e9b65 163 }
embeddedartists 0:316c181e9b65 164
embeddedartists 0:316c181e9b65 165 if (!pressed && _inputStatePressed && onWidget) {
embeddedartists 0:316c181e9b65 166 _clickedListener.call(this);
embeddedartists 0:316c181e9b65 167 }
embeddedartists 0:316c181e9b65 168
embeddedartists 0:316c181e9b65 169 _inputStatePressed = pressed;
embeddedartists 0:316c181e9b65 170 }
embeddedartists 0:316c181e9b65 171
embeddedartists 0:316c181e9b65 172 void EwButton::_callback(WM_MESSAGE* pMsg, EwWindow* w) {
embeddedartists 0:316c181e9b65 173 GUI_PID_STATE* pidState;
embeddedartists 0:316c181e9b65 174
embeddedartists 0:316c181e9b65 175 // always let button widget process the event first
embeddedartists 0:316c181e9b65 176 BUTTON_Callback(pMsg);
embeddedartists 0:316c181e9b65 177
embeddedartists 0:316c181e9b65 178 switch(pMsg->MsgId) {
embeddedartists 0:316c181e9b65 179 case WM_TOUCH:
embeddedartists 0:316c181e9b65 180 pidState = (GUI_PID_STATE*)pMsg->Data.p;
embeddedartists 0:316c181e9b65 181
embeddedartists 0:316c181e9b65 182 EwButton* b = (EwButton*)w;
embeddedartists 0:316c181e9b65 183 b->handleInput((pidState->Pressed == 1),
embeddedartists 0:316c181e9b65 184 (pidState->Pressed == 1 || pidState->Pressed == 0));
embeddedartists 0:316c181e9b65 185
embeddedartists 0:316c181e9b65 186
embeddedartists 0:316c181e9b65 187 break;
embeddedartists 0:316c181e9b65 188 }
embeddedartists 0:316c181e9b65 189
embeddedartists 0:316c181e9b65 190 }
embeddedartists 0:316c181e9b65 191