-
Notifications
You must be signed in to change notification settings - Fork 0
/
Field.cpp
88 lines (69 loc) · 2.89 KB
/
Field.cpp
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
#include "Field.hpp"
Field::Field(bool visible, POINT pos, POINT size) :
visible_ (visible),
pos_ (pos),
size_ (size),
canvas_size_ (size),
button_count_ (0),
textbox_count_(0),
buttons_ (std::vector<AbstractButton*>()),
textboxes_ (std::vector<Textbox>()),
canvas_ (NULL),
scroll_ (false)
{}
Field::Field(const Field& field) :
visible_ (field.visible_),
pos_ (field.pos_),
size_ (field.size_),
canvas_size_ (field.canvas_size_),
button_count_ (field.button_count_),
textbox_count_ (field.textbox_count_),
buttons_ (field.buttons_),
textboxes_ (field.textboxes_),
canvas_ (NULL),
scroll_ (field.scroll_)
{}
Field::~Field() {
txDeleteDC(canvas_);
}
void Field::addButton(AbstractButton* button) {
button_count_++;
buttons_.push_back(button);
buttons_.back()->wndPos_.x += pos_.x;
buttons_.back()->wndPos_.y += pos_.y;
if (!scroll_ && (button->fieldPos_.y + button->size_.y > size_.y)) { //
scroll_ = true; // скорее всего это уже не понадобится
size_.x -= 20; //
} //
if (button->fieldPos_.y + button->size_.y > canvas_size_.y) {
canvas_size_.y = button->fieldPos_.y + button->size_.y;
}
}
void Field::addTextbox(const Textbox& textbox) {
textbox_count_++;
textboxes_.push_back(textbox);
textboxes_.back().wndPos_.x += pos_.x;
textboxes_.back().wndPos_.y += pos_.y;
if (!scroll_ && (textbox.fieldPos_.y + textbox.size_.y > size_.y)) { //
scroll_ = true; // скорее всего это уже не понадобится
size_.x -= 20; //
} //
if (textbox.fieldPos_.y + textbox.size_.y > canvas_size_.y) {
canvas_size_.y = textbox.fieldPos_.y + textbox.size_.y;
}
}
void Field::draw() {
txSetColor (VEC2RGB((prop.INTERFACECOLOR * 0.9)), 1, canvas_);
txSetFillColor(VEC2RGB(prop.INTERFACECOLOR), canvas_);
txRectangle(0, 0, canvas_size_.x, canvas_size_.y, canvas_);
for (int button = 0; button < button_count_; ++button) {
buttons_[button]->draw(canvas_, false);
}
for (int textbox = 0; textbox < textbox_count_; ++textbox) {
textboxes_[textbox].draw(canvas_);
}
}
bool Field::mouse_on_field() {
POINT mouse = mousePos();
return (mouse.x > pos_.x && mouse.x < pos_.x + size_.x && mouse.y > pos_.y && mouse.y < pos_.y + size_.y) ? true : false;
}