Lab4
Dependencies: SeeedStudioTFTv2 TFT_fonts mbed
Fork of Seeed_TFT_Touch_Shield by
Widget.cpp@6:ebffa73d4f95, 2014-09-26 (annotated)
- Committer:
- uswickra
- Date:
- Fri Sep 26 15:33:34 2014 +0000
- Revision:
- 6:ebffa73d4f95
- Parent:
- 4:ebcf8d366b91
fix report
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
uswickra | 4:ebcf8d366b91 | 1 | #include "Widget.h" |
uswickra | 4:ebcf8d366b91 | 2 | |
uswickra | 4:ebcf8d366b91 | 3 | void AbstractWidget::redraw() |
uswickra | 4:ebcf8d366b91 | 4 | { |
uswickra | 4:ebcf8d366b91 | 5 | //if state has changed in this widget |
uswickra | 4:ebcf8d366b91 | 6 | if(state_changed) { |
uswickra | 4:ebcf8d366b91 | 7 | paint(); |
uswickra | 4:ebcf8d366b91 | 8 | pc.printf("starting to paint# \r\n"); |
uswickra | 4:ebcf8d366b91 | 9 | state_changed = false; |
uswickra | 4:ebcf8d366b91 | 10 | } |
uswickra | 4:ebcf8d366b91 | 11 | //redraw action for all children |
uswickra | 4:ebcf8d366b91 | 12 | for(vector<AbstractWidget*>::iterator it = children.begin(); it != children.end(); it++) { |
uswickra | 4:ebcf8d366b91 | 13 | AbstractWidget* w = *it; |
uswickra | 4:ebcf8d366b91 | 14 | w->redraw(); |
uswickra | 4:ebcf8d366b91 | 15 | } |
uswickra | 4:ebcf8d366b91 | 16 | } |
uswickra | 4:ebcf8d366b91 | 17 | |
uswickra | 4:ebcf8d366b91 | 18 | void AbstractWidget::refresh() |
uswickra | 4:ebcf8d366b91 | 19 | { |
uswickra | 4:ebcf8d366b91 | 20 | state_changed = true; |
uswickra | 4:ebcf8d366b91 | 21 | //try to re-adjust cordinates for any children of 'p' |
uswickra | 4:ebcf8d366b91 | 22 | if(children.size() > 0 ) { |
uswickra | 4:ebcf8d366b91 | 23 | curr_row = 0 ; |
uswickra | 4:ebcf8d366b91 | 24 | curr_col = 0 ; |
uswickra | 4:ebcf8d366b91 | 25 | for(vector<AbstractWidget*>::iterator it = children.begin(); it != children.end(); it++) { |
uswickra | 4:ebcf8d366b91 | 26 | AbstractWidget* pnl = (*it); |
uswickra | 4:ebcf8d366b91 | 27 | push_children = false ; |
uswickra | 4:ebcf8d366b91 | 28 | addWidget(pnl); |
uswickra | 4:ebcf8d366b91 | 29 | push_children = true ; |
uswickra | 4:ebcf8d366b91 | 30 | } |
uswickra | 4:ebcf8d366b91 | 31 | } |
uswickra | 4:ebcf8d366b91 | 32 | //refresh action for all children |
uswickra | 4:ebcf8d366b91 | 33 | for(vector<AbstractWidget*>::iterator it = children.begin(); it != children.end(); it++) { |
uswickra | 4:ebcf8d366b91 | 34 | AbstractWidget* w = *it; |
uswickra | 4:ebcf8d366b91 | 35 | w->refresh(); |
uswickra | 4:ebcf8d366b91 | 36 | } |
uswickra | 4:ebcf8d366b91 | 37 | } |
uswickra | 4:ebcf8d366b91 | 38 | |
uswickra | 6:ebffa73d4f95 | 39 | AbstractWidget* AbstractWidget::remove_child() |
uswickra | 6:ebffa73d4f95 | 40 | { |
uswickra | 6:ebffa73d4f95 | 41 | AbstractWidget* w = children.back(); |
uswickra | 6:ebffa73d4f95 | 42 | children.pop_back(); |
uswickra | 6:ebffa73d4f95 | 43 | //refresh state of returned widget |
uswickra | 4:ebcf8d366b91 | 44 | // w->refresh(); |
uswickra | 6:ebffa73d4f95 | 45 | //revert to previous row/col position |
uswickra | 6:ebffa73d4f95 | 46 | curr_row = prev_row; |
uswickra | 6:ebffa73d4f95 | 47 | curr_col = prev_col; |
uswickra | 6:ebffa73d4f95 | 48 | return w; |
uswickra | 6:ebffa73d4f95 | 49 | } |
uswickra | 6:ebffa73d4f95 | 50 | |
uswickra | 6:ebffa73d4f95 | 51 | void AbstractWidget::trigger_action(ActionType type, ActionEvent evnt, void* target) |
uswickra | 6:ebffa73d4f95 | 52 | { |
uswickra | 6:ebffa73d4f95 | 53 | //do nothing |
uswickra | 6:ebffa73d4f95 | 54 | } |
uswickra | 6:ebffa73d4f95 | 55 | |
uswickra | 6:ebffa73d4f95 | 56 | |
uswickra | 6:ebffa73d4f95 | 57 | void AbstractWidget::inject_action(int x, int y) |
uswickra | 6:ebffa73d4f95 | 58 | { |
uswickra | 6:ebffa73d4f95 | 59 | double di_per_pixel = 28.9583; |
uswickra | 6:ebffa73d4f95 | 60 | double dj_per_pixel = 21.25; |
uswickra | 6:ebffa73d4f95 | 61 | |
uswickra | 6:ebffa73d4f95 | 62 | int x_cord = x / di_per_pixel ; |
uswickra | 6:ebffa73d4f95 | 63 | int y_cord = y / dj_per_pixel ; |
uswickra | 6:ebffa73d4f95 | 64 | //do nothing |
uswickra | 6:ebffa73d4f95 | 65 | ActionEvent evnt; |
uswickra | 6:ebffa73d4f95 | 66 | ActionType type; |
uswickra | 6:ebffa73d4f95 | 67 | evnt.x = x_cord; |
uswickra | 6:ebffa73d4f95 | 68 | evnt.y = y_cord ; |
uswickra | 6:ebffa73d4f95 | 69 | type = CORD; |
uswickra | 6:ebffa73d4f95 | 70 | //do this action if registered for events and is inside the input window |
uswickra | 6:ebffa73d4f95 | 71 | if(x_cord > x0 && x_cord < x1 && y_cord > y0 && y_cord < y1 ) { |
uswickra | 6:ebffa73d4f95 | 72 | action(type, evnt); |
uswickra | 4:ebcf8d366b91 | 73 | } |
uswickra | 6:ebffa73d4f95 | 74 | //also inject for children |
uswickra | 6:ebffa73d4f95 | 75 | for(vector<AbstractWidget*>::iterator it = children.begin(); it != children.end(); it++) { |
uswickra | 6:ebffa73d4f95 | 76 | AbstractWidget* w = *it; |
uswickra | 6:ebffa73d4f95 | 77 | w->inject_action(x, y); |
uswickra | 6:ebffa73d4f95 | 78 | } |
uswickra | 4:ebcf8d366b91 | 79 | } |