1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| #pragma once
#include <string>
using namespace std;
class Screen { friend class Window_Mgr;
public: Screen() : contents("hello class"), cursor(0), width(5) {} explicit Screen(string text, int cur = 0, int w = 5) : contents(text), cursor(cur), width(w) {}
typedef std::string::size_type index; char get() const { return contents[cursor]; } inline char get(index x, index y) const; index get_cursor() const;
Screen& move(index row, index offset);
Screen& set(char);
Screen& display(std::ostream &os) { do_display(os); return *this; } const Screen& display(std::ostream &os) const { do_display(os); return *this; }
private: string contents; index cursor; index width; void do_display(std::ostream &os)const { os << contents << endl; } };
inline char Screen::get(index x, index y) const { index row = x * width; return contents[row + y]; }
inline Screen::index Screen::get_cursor() const { return cursor; }
|