-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.h
More file actions
53 lines (38 loc) · 1.08 KB
/
Copy pathButton.h
File metadata and controls
53 lines (38 loc) · 1.08 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
47
48
49
50
51
52
53
/* Copyright (c) 2024 Lilian Buzer - All rights reserved - */
#pragma once
#include <string>
#include "V2.h"
#include "Graphics.h"
#include "Event.h"
#include "Model.h"
#include <functional>
using namespace std;
// button component in the GUI
class Button
{
string imageFile_;
string myName_;
V2 pos_;
V2 size_;
function<void(Model&)> storedFunction_; // when the button is clicked, call this function
public:
V2 getPos() { return pos_; }
V2 getSize() { return size_; }
Button(string myName, V2 pos, V2 size, string imageFile, function<void(Model&)> callBack) :
myName_(myName), pos_(pos), size_(size), imageFile_(imageFile), storedFunction_(callBack) { }
void manageEvent(const Event& Ev, Model& Ap)
{
if (Ev.Type == EventType::MouseDown)
{
cout << ">> Clic sur le bouton " << myName_ << endl;
// muda o nome no mouse (?)
storedFunction_(Ap);
}
}
void draw(Graphics & G)
{
G.drawRectWithTexture(imageFile_, pos_, size_);
G.drawRectangle(pos_, size_, Color::Gray, false,2);
G.drawRectangle(pos_ + V2(2,2), size_-V2(4,4), Color::Black, false,2);
}
};