Commit f79916092b551a956ad18956f7afbda1f5513afe
1 parent
9be3d764
Updated txtwin
Showing
4 changed files
with
19 additions
and
12 deletions
examples05/02-txtwin/cpoint.h
| 1 | +#ifndef _CPOINT_H_ | ||
| 2 | +#define _CPOINT_H_ | ||
| 3 | + | ||
| 1 | struct CPoint { | 4 | struct CPoint { |
| 2 | int x; | 5 | int x; |
| 3 | int y; | 6 | int y; |
| @@ -15,3 +18,5 @@ struct CRect { | @@ -15,3 +18,5 @@ struct CRect { | ||
| 15 | CPoint size; | 18 | CPoint size; |
| 16 | CRect(CPoint t1 = CPoint(), CPoint s = CPoint()) : topleft(t1), size(s){}; | 19 | CRect(CPoint t1 = CPoint(), CPoint s = CPoint()) : topleft(t1), size(s){}; |
| 17 | }; | 20 | }; |
| 21 | + | ||
| 22 | +#endif /* _CPOINT_H_ */ | ||
| 18 | \ No newline at end of file | 23 | \ No newline at end of file |
examples05/02-txtwin/screen.cpp
examples05/02-txtwin/screen.h
| 1 | -/* screen.h */ | ||
| 2 | -#include <ncurses.h> | 1 | +#ifndef _SCREEN_H_ |
| 2 | +#define _SCREEN_H_ | ||
| 3 | 3 | ||
| 4 | void init_screen(); | 4 | void init_screen(); |
| 5 | void done_screen(); | 5 | void done_screen(); |
| 6 | void gotoyx(int y, int x); | 6 | void gotoyx(int y, int x); |
| 7 | int ngetch(); | 7 | int ngetch(); |
| 8 | void getscreensize(int& y, int& x); | 8 | void getscreensize(int& y, int& x); |
| 9 | + | ||
| 10 | +#endif /* _SCREEN_H_ */ | ||
| 9 | \ No newline at end of file | 11 | \ No newline at end of file |
examples05/02-txtwin/winsys.cpp
| 1 | -#include "cpoint.h" | ||
| 2 | -#include "screen.h" | 1 | +#include <ncurses.h> |
| 3 | #include <ctype.h> | 2 | #include <ctype.h> |
| 4 | #include <list> | 3 | #include <list> |
| 5 | #include <string> | 4 | #include <string> |
| 5 | + | ||
| 6 | +#include "cpoint.h" | ||
| 7 | +#include "screen.h" | ||
| 6 | using namespace std; | 8 | using namespace std; |
| 7 | 9 | ||
| 8 | class CView { | 10 | class CView { |
| @@ -118,9 +120,8 @@ class CGroup : public CView { | @@ -118,9 +120,8 @@ class CGroup : public CView { | ||
| 118 | CGroup(CRect g) : CView(g){}; | 120 | CGroup(CRect g) : CView(g){}; |
| 119 | void paint() | 121 | void paint() |
| 120 | { | 122 | { |
| 121 | - for (list<CView*>::iterator i = children.begin(); i != children.end(); | ||
| 122 | - i++) | ||
| 123 | - (*i)->paint(); | 123 | + for (CView* i : children) |
| 124 | + i->paint(); | ||
| 124 | }; | 125 | }; |
| 125 | bool handleEvent(int key) | 126 | bool handleEvent(int key) |
| 126 | { | 127 | { |
| @@ -141,9 +142,8 @@ class CGroup : public CView { | @@ -141,9 +142,8 @@ class CGroup : public CView { | ||
| 141 | }; | 142 | }; |
| 142 | ~CGroup() | 143 | ~CGroup() |
| 143 | { | 144 | { |
| 144 | - for (list<CView*>::iterator i = children.begin(); i != children.end(); | ||
| 145 | - i++) | ||
| 146 | - delete (*i); | 145 | + for (CView* i : children) |
| 146 | + delete i; | ||
| 147 | }; | 147 | }; |
| 148 | }; | 148 | }; |
| 149 | 149 | ||
| @@ -184,7 +184,7 @@ class CDesktop : public CGroup { | @@ -184,7 +184,7 @@ class CDesktop : public CGroup { | ||
| 184 | refresh(); | 184 | refresh(); |
| 185 | while (1) { | 185 | while (1) { |
| 186 | c = getEvent(); | 186 | c = getEvent(); |
| 187 | - if (c == 27) | 187 | + if (c == 27) // ESC key |
| 188 | break; | 188 | break; |
| 189 | if (handleEvent(c)) { | 189 | if (handleEvent(c)) { |
| 190 | paint(); | 190 | paint(); |