Lab4

Dependencies:   SeeedStudioTFTv2 TFT_fonts mbed

Fork of Seeed_TFT_Touch_Shield by Shields

Revision:
6:ebffa73d4f95
Parent:
4:ebcf8d366b91
--- a/Widget.cpp	Fri Sep 26 12:42:10 2014 +0000
+++ b/Widget.cpp	Fri Sep 26 15:33:34 2014 +0000
@@ -36,17 +36,44 @@
     }
 }
 
-AbstractWidget* AbstractWidget::remove_child() {
-        AbstractWidget* w = children.back();
-        children.pop_back();
-        //refresh state of returned widget
+AbstractWidget* AbstractWidget::remove_child()
+{
+    AbstractWidget* w = children.back();
+    children.pop_back();
+    //refresh state of returned widget
 //        w->refresh();
-        //revert to previous row/col position
-        curr_row = prev_row;
-        curr_col = prev_col;
-        return w;
+    //revert to previous row/col position
+    curr_row = prev_row;
+    curr_col = prev_col;
+    return w;
+}
+
+void AbstractWidget::trigger_action(ActionType type, ActionEvent evnt, void* target)
+{
+    //do nothing
+}
+
+
+void AbstractWidget::inject_action(int x, int y)
+{
+    double di_per_pixel = 28.9583;
+    double dj_per_pixel = 21.25;
+
+    int x_cord = x / di_per_pixel ;
+    int y_cord = y / dj_per_pixel ;
+    //do nothing
+    ActionEvent evnt;
+    ActionType type;
+    evnt.x = x_cord;
+    evnt.y = y_cord ;
+    type = CORD;
+    //do this action if registered for events and is inside the input window
+    if(x_cord > x0 && x_cord < x1 && y_cord > y0 && y_cord < y1 ) {
+        action(type, evnt);
     }
-    
-void AbstractWidget::trigger_action(ActionType type, ActionEvent evnt){
-        //do nothing
+    //also inject for children
+    for(vector<AbstractWidget*>::iterator it = children.begin(); it != children.end(); it++) {
+        AbstractWidget* w = *it;
+        w->inject_action(x, y);
+    }
 }