-
Notifications
You must be signed in to change notification settings - Fork 126
/
Copy pathGui.h
115 lines (94 loc) · 2.74 KB
/
Gui.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
#ifndef GUI_GUARD
#define GUI_GUARD
#include "Point.h"
#include "fltk.h"
#include "Window.h"
#include "Graph.h"
//#include<vector>
//#include<string>
namespace Graph_lib {
typedef void* Address;
typedef void (*Callback)(Address,Address); // FLTK's required function type for all callbacks
template<class W> W& reference_to(Address pw)
// treat an address as a reference to a W
{
return *static_cast<W*>(pw);
}
class Widget {
// Widget is a handle to a Fl_widget - it is *not* a Fl_widget
// We try to keep our interface classes at arm's length from FLTK
public:
Widget(Point xy, int w, int h, const string& s, Callback cb)
:loc(xy), width(w), height(h), label(s), do_it(cb)
{ }
virtual void move(int dx,int dy) { hide(); pw->position(loc.x+=dx, loc.y+=dy); show(); }
virtual void hide() { pw->hide(); }
virtual void show() { pw->show(); }
virtual void attach(Window&) = 0; // each Widgit define at least one action for a window
Point loc;
int width;
int height;
string label;
Callback do_it;
virtual ~Widget() { }
/*
Widget(const Widget& a) :loc(a.loc) { error("attempt to copy Widget by constructor"); }
Widget& operator=(const Widget& a)
{
error("attempt to copy Widget by cassignment");
return *this;
}
*/
protected:
Window* own; // every Widget belongs to a Window
Fl_Widget* pw;
private:
Widget& operator=(const Widget&); // don't copy Widgets
Widget(const Widget&);
};
class Button : public Widget {
public:
Button(Point xy, int ww, int hh, const string& s, Callback cb)
:Widget(xy,ww,hh,s,cb)
{
}
void attach(Window& win);
};
struct In_box : Widget {
In_box(Point xy, int w, int h, const string& s)
:Widget(xy,w,h,s,0)
{
}
int get_int();
string get_string();
void attach(Window& win);
};
struct Out_box : Widget {
Out_box(Point xy, int w, int h, const string& s/*, Window& win*/)
:Widget(xy,w,h,s,0)
{
}
void put(int);
void put(const string&);
void attach(Window& win);
};
struct Menu : Widget {
enum Kind { horizontal, vertical };
Menu(Point xy, int w, int h, Kind kk, const string& s);
Vector_ref<Button> selection;
Kind k;
int offset;
int attach(Button& b); // attach button; Menu does not delete &b
int attach(Button* p); // attach new button; Menu deletes p
void show() { for (int i = 0; i<selection.size(); ++i) selection[i].show(); }
void hide() { for (int i = 0; i<selection.size(); ++i) selection[i].hide(); }
void move(int dx, int dy)
{ for (int i = 0; i<selection.size(); ++i) selection[i].move(dx,dy); }
// int insert(int i, const Button& b); // not implemented
void attach(Window& win)
{
for (int i=0; i<selection.size(); ++i) win.attach(selection[i]);
}
};
}
#endif