-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbutton.cpp
More file actions
46 lines (34 loc) · 1.28 KB
/
Copy pathbutton.cpp
File metadata and controls
46 lines (34 loc) · 1.28 KB
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
#include "field.h"
const std::string up = "↑";
const std::string left = "←";
const std::string down = "↓";
const std::string right = "→";
const std::string& get_str(DIRECT d){
if (d == DIRECT::UP)
return up;
if (d == DIRECT::LEFT)
return left;
if (d == DIRECT::DOWN)
return down;
if (d == DIRECT::RIGHT)
return right;
}
ArrowButton::ArrowButton(Graph_lib::Point xy, int but_s, Graph_lib::Callback cb, DIRECT d)
: Button{xy, but_s, but_s, get_str(d), cb}, dir{d} {
}
void ArrowButton::attach(Graph_lib::Window& win){
Button::attach(win);
}
ButtonControl::ButtonControl(Field* f, Graph_lib::Point c, Graph_lib::Callback cb)
: center{c}, field{f}{
but.push_back(new ArrowButton{Graph_lib::Point{c.x, c.y-shift}, button_size, cb, DIRECT::UP});
but.push_back(new ArrowButton{Graph_lib::Point{c.x-shift, c.y}, button_size, cb, DIRECT::LEFT});
but.push_back(new ArrowButton{Graph_lib::Point{c.x, c.y+shift}, button_size, cb, DIRECT::DOWN});
but.push_back(new ArrowButton{Graph_lib::Point{c.x+shift, c.y}, button_size, cb, DIRECT::RIGHT});
for (int i=0; i<but.size(); ++i)
field->attach(but[i]);
}
void ButtonControl::clicked(const ArrowButton& but){
field->move( but.get_dir() );
Fl::redraw();
}