-
Notifications
You must be signed in to change notification settings - Fork 11
/
GoF.h
135 lines (112 loc) · 2.93 KB
/
GoF.h
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#pragma once
namespace BridgePattern::GoF
{
class View {};
class Coord {
public:
Coord(double) {}
};
class Point {
private:
Coord x, y;
public:
const Coord& X() const { return x; }
const Coord& Y() const { return y; }
};
class WindowImp;
class Window {
public:
Window(View* contents)
: _contents(contents)
{}
// requests handled by window
virtual void DrawContents() {}
virtual void Open() {}
virtual void Close() {}
virtual void Iconify() {}
virtual void Deiconify() {}
// requests forwarded to implementation
virtual void SetOrigin(const Point& at) {}
virtual void SetExtent(const Point& extent) {}
virtual void Raise() {}
virtual void Lower() {}
virtual void DrawLine(const Point&, const Point&) {}
virtual void DrawRect(const Point&, const Point&);
virtual void DrawPolygon(const Point[], int n) {}
virtual void DrawText(const char*, const Point&) {}
protected:
WindowImp* GetWindowImp();
View* GetView() { return nullptr; }
private:
WindowImp* _imp;
View* _contents; // the window's contents
};
class WindowImp {
public:
virtual void ImpTop() = 0;
virtual void ImpBottom() = 0;
virtual void ImpSetExtent(const Point&) = 0;
virtual void ImpSetOrigin(const Point&) = 0;
virtual void DeviceRect(const Coord&, const Coord&, const Coord&, const Coord&) = 0;
virtual void DeviceText(const char*, Coord, Coord) = 0;
virtual void DeviceBitmap(const char*, Coord, Coord) = 0;
// lots more functions for drawing on windows...
protected:
WindowImp() {}
};
class ApplicationWindow : public Window {
public:
// ...
virtual void DrawContents();
};
void ApplicationWindow::DrawContents() {
// GetView()->DrawOn(this);
}
class IconWindow : public Window {
public:
// ...
virtual void DrawContents();
private:
const char* _bitmapName;
};
void IconWindow::DrawContents() {
WindowImp* imp = GetWindowImp();
if (imp != 0) {
imp->DeviceBitmap(_bitmapName, 0.0, 0.0);
}
}
void Window::DrawRect(const Point& p1, const Point& p2) {
WindowImp* imp = GetWindowImp();
imp->DeviceRect(p1.X(), p1.Y(), p2.X(), p2.Y());
}
class Display {};
class Drawable {};
class GC {};
class XWindowImp : public WindowImp {
public:
XWindowImp() {}
virtual void DeviceRect(const Coord&, const Coord&, const Coord&, const Coord&) {}
// remainder of public interface...
private:
// lots of X window system-specific state, including:
Display* _dpy;
Drawable _winid; // window id
GC _gc; // window graphic context
};
class HPS {};
class PMWindowImp : public WindowImp {
public:
PMWindowImp() {}
virtual void DeviceRect(const Coord&, const Coord&, const Coord&, const Coord&) {}
// remainder of public interface...
private:
// lots of PM window system-specific state, including:
HPS _hps;
};
WindowImp* Window::GetWindowImp() {
//if (_imp == 0) {
// _imp = WindowSystemFactory::Instance()->MakeWindowImp();
//}
return _imp;
}
}