Example that shows how to use the ewgui wrapper classes in combination with Segger's emwin library.

Dependencies:   EALib ewgui mbed

Committer:
embeddedartists
Date:
Mon Dec 16 07:09:17 2013 +0000
Revision:
0:6b81fd4666bb
First commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 0:6b81fd4666bb 1 #include "mbed.h"
embeddedartists 0:6b81fd4666bb 2
embeddedartists 0:6b81fd4666bb 3 #include "MyWindow.h"
embeddedartists 0:6b81fd4666bb 4 #include "EwPainter.h"
embeddedartists 0:6b81fd4666bb 5
embeddedartists 0:6b81fd4666bb 6 MyWindow::MyWindow(EwWindow* parent) :
embeddedartists 0:6b81fd4666bb 7 EwWindow(5, 2, 300, 250, parent),
embeddedartists 0:6b81fd4666bb 8 _changeBtn(130, 200, 40, 20, this),
embeddedartists 0:6b81fd4666bb 9 _checkBox(0, 0, 80, 25, this),
embeddedartists 0:6b81fd4666bb 10 _dropDownLst(0, 0, 100, 50, this){
embeddedartists 0:6b81fd4666bb 11
embeddedartists 0:6b81fd4666bb 12 _changeBtn.setText("Click");
embeddedartists 0:6b81fd4666bb 13 _changeBtn.setClickedListener(this, &MyWindow::clickListener);
embeddedartists 0:6b81fd4666bb 14
embeddedartists 0:6b81fd4666bb 15 _checkBox.setText("CheckBox");
embeddedartists 0:6b81fd4666bb 16 _checkBox.setChangedListener(this, &MyWindow::checkedListener);
embeddedartists 0:6b81fd4666bb 17
embeddedartists 0:6b81fd4666bb 18 _dropDownLst.addString("First");
embeddedartists 0:6b81fd4666bb 19 _dropDownLst.addString("Second");
embeddedartists 0:6b81fd4666bb 20 _dropDownLst.addString("Third");
embeddedartists 0:6b81fd4666bb 21
embeddedartists 0:6b81fd4666bb 22 _clickCnt = 0;
embeddedartists 0:6b81fd4666bb 23 _pressed = false;
embeddedartists 0:6b81fd4666bb 24 _pressX = 0;
embeddedartists 0:6b81fd4666bb 25 _pressY = 0;
embeddedartists 0:6b81fd4666bb 26
embeddedartists 0:6b81fd4666bb 27 resizeTo(parent->getWidth()-15, parent->getHeight()-35);
embeddedartists 0:6b81fd4666bb 28 _changeBtn.moveTo(getWidth()/2-_changeBtn.getWidth()/2,
embeddedartists 0:6b81fd4666bb 29 getHeight()-_changeBtn.getHeight()-5);
embeddedartists 0:6b81fd4666bb 30
embeddedartists 0:6b81fd4666bb 31 _checkBox.moveTo(5, 35);
embeddedartists 0:6b81fd4666bb 32
embeddedartists 0:6b81fd4666bb 33 _dropDownLst.move(getWidth()-_dropDownLst.getWidth()-5, 5);
embeddedartists 0:6b81fd4666bb 34 }
embeddedartists 0:6b81fd4666bb 35
embeddedartists 0:6b81fd4666bb 36 bool MyWindow::paintEvent() {
embeddedartists 0:6b81fd4666bb 37 char buf[30];
embeddedartists 0:6b81fd4666bb 38 EwPainter painter;
embeddedartists 0:6b81fd4666bb 39
embeddedartists 0:6b81fd4666bb 40 painter.setBackgroundColor(EW_LIGHTGRAY);
embeddedartists 0:6b81fd4666bb 41 painter.clear();
embeddedartists 0:6b81fd4666bb 42
embeddedartists 0:6b81fd4666bb 43 if (_clickCnt > 0) {
embeddedartists 0:6b81fd4666bb 44 painter.setColor(EW_BLUE);
embeddedartists 0:6b81fd4666bb 45 if (_clickCnt == 1) {
embeddedartists 0:6b81fd4666bb 46 sprintf(buf, "Clicked %d time", _clickCnt);
embeddedartists 0:6b81fd4666bb 47 }
embeddedartists 0:6b81fd4666bb 48 else {
embeddedartists 0:6b81fd4666bb 49 sprintf(buf, "Clicked %d times", _clickCnt);
embeddedartists 0:6b81fd4666bb 50 }
embeddedartists 0:6b81fd4666bb 51 painter.drawStringClearEOL(buf, 5, 5);
embeddedartists 0:6b81fd4666bb 52 }
embeddedartists 0:6b81fd4666bb 53
embeddedartists 0:6b81fd4666bb 54 if (_pressed) {
embeddedartists 0:6b81fd4666bb 55 painter.setColor(GUI_DARKRED);
embeddedartists 0:6b81fd4666bb 56 sprintf(buf, "Touch at %d,%d", _pressX, _pressY);
embeddedartists 0:6b81fd4666bb 57 painter.drawStringClearEOL(buf, 5, 15);
embeddedartists 0:6b81fd4666bb 58 }
embeddedartists 0:6b81fd4666bb 59
embeddedartists 0:6b81fd4666bb 60 return true;
embeddedartists 0:6b81fd4666bb 61 }
embeddedartists 0:6b81fd4666bb 62
embeddedartists 0:6b81fd4666bb 63 bool MyWindow::touchEvent(int x, int y, EwTouchState_t state) {
embeddedartists 0:6b81fd4666bb 64
embeddedartists 0:6b81fd4666bb 65 if (state == TouchStatePressed) {
embeddedartists 0:6b81fd4666bb 66 _pressed = true;
embeddedartists 0:6b81fd4666bb 67 _pressX = x;
embeddedartists 0:6b81fd4666bb 68 _pressY = y;
embeddedartists 0:6b81fd4666bb 69 }
embeddedartists 0:6b81fd4666bb 70 else {
embeddedartists 0:6b81fd4666bb 71 _pressed = false;
embeddedartists 0:6b81fd4666bb 72 }
embeddedartists 0:6b81fd4666bb 73
embeddedartists 0:6b81fd4666bb 74 invalidate();
embeddedartists 0:6b81fd4666bb 75
embeddedartists 0:6b81fd4666bb 76 return true;
embeddedartists 0:6b81fd4666bb 77 }
embeddedartists 0:6b81fd4666bb 78
embeddedartists 0:6b81fd4666bb 79 void MyWindow::clickListener(EwWindow* w) {
embeddedartists 0:6b81fd4666bb 80 _clickCnt++;
embeddedartists 0:6b81fd4666bb 81 invalidate();
embeddedartists 0:6b81fd4666bb 82 }
embeddedartists 0:6b81fd4666bb 83
embeddedartists 0:6b81fd4666bb 84 void MyWindow::checkedListener(EwWindow* w) {
embeddedartists 0:6b81fd4666bb 85 EwCheckBox* b = (EwCheckBox*)w;
embeddedartists 0:6b81fd4666bb 86
embeddedartists 0:6b81fd4666bb 87 ewCheckBoxState_t state = b->getState();
embeddedartists 0:6b81fd4666bb 88
embeddedartists 0:6b81fd4666bb 89 if (state == CheckBoxStateUnchecked) {
embeddedartists 0:6b81fd4666bb 90 b->setText("Unchecked");
embeddedartists 0:6b81fd4666bb 91 }
embeddedartists 0:6b81fd4666bb 92 else {
embeddedartists 0:6b81fd4666bb 93 b->setText("Checked");
embeddedartists 0:6b81fd4666bb 94 }
embeddedartists 0:6b81fd4666bb 95
embeddedartists 0:6b81fd4666bb 96 }