Duncan McIntyre / Mbed 2 deprecated TouchScreenGUIDemo

Dependencies:   SimpleGUI SimpleGUITouchScreen TouchScreen UniGraphic mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
duncanFrance
Date:
Sun May 08 14:43:42 2016 +0000
Parent:
2:fe93c85e8f0b
Commit message:
Work with new event-handling mechanism and Window->attach()

Changed in this revision

SimpleGUI.lib Show annotated file Show diff for this revision Revisions of this file
SimpleGUITouchScreen.lib Show annotated file Show diff for this revision Revisions of this file
TouchScreen.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r fe93c85e8f0b -r ca2285e07824 SimpleGUI.lib
--- a/SimpleGUI.lib	Mon Apr 11 16:54:57 2016 +0000
+++ b/SimpleGUI.lib	Sun May 08 14:43:42 2016 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/users/duncanFrance/code/SimpleGUI/#a460cabc85ac
+https://developer.mbed.org/users/duncanFrance/code/SimpleGUI/#63db16fea709
diff -r fe93c85e8f0b -r ca2285e07824 SimpleGUITouchScreen.lib
--- a/SimpleGUITouchScreen.lib	Mon Apr 11 16:54:57 2016 +0000
+++ b/SimpleGUITouchScreen.lib	Sun May 08 14:43:42 2016 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/users/duncanFrance/code/SimpleGUITouchScreen/#0c8196ec23e4
+https://developer.mbed.org/users/duncanFrance/code/SimpleGUITouchScreen/#45777fe81448
diff -r fe93c85e8f0b -r ca2285e07824 TouchScreen.lib
--- a/TouchScreen.lib	Mon Apr 11 16:54:57 2016 +0000
+++ b/TouchScreen.lib	Sun May 08 14:43:42 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/duncanFrance/code/TouchScreen/#9bd85d0331a8
+http://mbed.org/users/duncanFrance/code/TouchScreen/#e5ea47fb1ede
diff -r fe93c85e8f0b -r ca2285e07824 main.cpp
--- a/main.cpp	Mon Apr 11 16:54:57 2016 +0000
+++ b/main.cpp	Sun May 08 14:43:42 2016 +0000
@@ -18,9 +18,12 @@
 BitmapWidget* bm1;
 ContainerWidget* cw1;
 GUI* gui;
+GraphicsContext* context;
 FastFontRenderer* fontRenderer;
 FastFont* defaultFont;
 
+Window* rootWindow;
+Window* win1;
 ILI932x* tft;
 
 Serial *pc;
@@ -45,32 +48,32 @@
    eventSource->touchEndHandler(p);
 }
 
-void tapHandler1(Event e, EventListener* target) {
-    TextWidget* w = (TextWidget*) target;
+void tapHandler1(Event e) {
+    TextWidget* w = (TextWidget*) e.target;
     if(done) {
         w->setBackground(Green);
     } else {
         w->setBackground(Blue);
     }
     done = !done;
-    w->draw();    
+  //  w->draw();    
 }
-void tapHandler2(Event e, EventListener* target) {
-    TextWidget* w = (TextWidget*) target;
+void tapHandler2(Event e) {
+    TextWidget* w = (TextWidget*) e.target;
     if(done) {
         w->setBackground(Green);
     } else {
         w->setBackground(Red);
     }
     done = !done;
-    w->draw();    
+   // w->draw();    
 }
 
-void dragHandler(Event e, EventListener* target) {
-    Widget* w = (Widget*) target;
+void dragHandler(Event e) {
+    Widget* w = (Widget*) e.target;
     w->clear();
     w->setLocation(w->x(), e.screenY - w->height()/2);
-    w->draw();    
+   // w->draw();    
 }
 
 void initSerial() {
@@ -91,7 +94,9 @@
     eventDispatcher = new EventDispatcher();
     fontRenderer = new FastFontRenderer();
     defaultFont = new FastFont((uint8_t*)FFArial24x23);
-    gui = new GUI(tft, eventDispatcher, fontRenderer, defaultFont);
+    context = new GraphicsContext(tft, eventDispatcher, fontRenderer, defaultFont);
+    gui = new GUI(context);
+    rootWindow = gui->rootWindow();
 }
 
 void initTouchScreen() {
@@ -101,7 +106,7 @@
     touchScreen->setTouchEndHandler(&touchEnd);
     touchScreen->setLCDGeometry(LCD_X_RES, LCD_Y_RES, TOUCHSCREEN_ORIENTATION_PORTRAIT | TOUCHSCREEN_ORIENTATION_ROTATED);
     touchScreen->setCalibration(TOUCH_X_MIN, TOUCH_X_MAX, TOUCH_Y_MIN, TOUCH_Y_MAX);
-    eventSource = new TouchScreenEventSource(touchScreen, eventDispatcher);
+    eventSource = new TouchScreenEventSource(touchScreen, gui);
 }
 
 int main()
@@ -110,45 +115,64 @@
     initSerial();
     initGui();
     initTouchScreen();
-    
-    
-    
-    widget1 = new TextWidget(gui);
-    widget1->setLocation(10,10);
-    widget1->setSize(100,60);
-    widget1->setText("This widget will change\ncolour when tapped");
-    widget1->draw();
-    widget1->setEventHandler(touchTapEvent, &tapHandler1);
+ 
     
-    widget2 = new TextWidget(gui);
-    widget2->setLocation(10,100);
-    widget2->setSize(200,60);
-    widget2->setText("A double-tap will make this\nwidget change colour");
-    widget2->draw();
-    widget2->setEventHandler(touchDoubleTapEvent, &tapHandler2);
-    
-    widget3 = new TextWidget(gui);
-    widget3->setLocation(10,10);
-    widget3->setSize(200,60);
-    widget3->setText("ABCDEF\nGHIJKL\nMNOPQRS\nTUVWXYZ");
-    widget3->draw();    
-    widget3->setEventHandler(touchMoveEvent, &dragHandler);
-    
-    bm1 = new BitmapWidget(gui);
-    bm1->setLocation(10,200);
-    bm1->setSize(64,64);
-    bm1->setBitmap(radiator_64x64_on_bmp);
-    
-    cw1 = new ContainerWidget(gui);
+    cw1 = new ContainerWidget(context);
     cw1->setLocation(50,150);
     cw1->setSize(20,20);
     cw1->setBorder(4, Green);
-    cw1->append(widget1);
-    cw1->append(bm1);
-    cw1->draw();
-    
-    
+    rootWindow->attach(cw1);
+    {
+     
+        widget1 = new TextWidget(context);
+        widget1->setSize(100,60);
+        widget1->setText("This widget will change\ncolour when tapped");
+        widget1->setBorder(1,White);
+        cw1->attach(widget1);
+        widget1->setEventHandler(new EventHandler(TOUCH_TAP, &tapHandler1));
+        
+        
+        bm1 = new BitmapWidget(context);
+        bm1->setBitmap(radiator_64x64_on_bmp, 64, 64);
+        cw1->attach(bm1);
+    }
+
+    Widget *w = new Widget(context);
+    w->setSize(60,60);
+    w->setLocation(100,100);
+    w->setBorder(2, Red);
+    rootWindow->attach(w);
+
+    widget2 = new TextWidget(context);
+    widget2->setLocation(10,80);
+    widget2->setSize(200,60);
+    widget2->setText("A double-tap will make this\nwidget change colour");
+    rootWindow->attach(widget2);
+    widget2->setEventHandler(new EventHandler(TOUCH_DOUBLE_TAP, &tapHandler2));
+ 
+    char *moveme = "ABCDEF\nGHIJKL\nMNOPQRS\nTUVWXYZ";
+    widget3 = new TextWidget(context);
+    widget3->setLocation(10,10);
+    widget3->setSize(200,60);
+    widget3->setText(moveme);
+    rootWindow->attach(widget3);
+    widget3->setEventHandler(new EventHandler(TOUCH_MOVE, &dragHandler));
+
+ 
+    SpinnerWidget *sw = new SpinnerWidget(context);
+    sw->setLocation(50,250);
+    sw->setSize(128,96);
+    sw->setIncrement(0.5);
+    sw->setMax(20);
+    sw->setMin(10);
+    char *format = "%2.1f C";
+    sw->setFormat(format);
+    sw->setValue(9.5);
+    rootWindow->attach(sw);
+
     while (1) {
-        Thread::wait(1000);
+        gui->updateWindow();
+        gui->pumpEvents();
+        Thread::wait(1);
     }
 }
diff -r fe93c85e8f0b -r ca2285e07824 mbed.bld
--- a/mbed.bld	Mon Apr 11 16:54:57 2016 +0000
+++ b/mbed.bld	Sun May 08 14:43:42 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/c0f6e94411f5
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/aae6fcc7d9bb
\ No newline at end of file