R-Type
R-Type project
GraphicalLib.hpp
1
/*
2
** EPITECH PROJECT, 2022
3
** gameEngine2
4
** File description:
5
** GraphicalLib
6
*/
7
8
#ifndef GRAPHICALLIB_HPP_
9
#define GRAPHICALLIB_HPP_
10
11
#include "Engine.hpp"
12
#include "
Input.hpp
"
13
#include "Vectors.hpp"
14
#include "Entity.hpp"
15
#include "Colors.hpp"
16
#include "Rectangle.hpp"
17
18
#include <functional>
19
20
namespace
KapEngine
{
21
class
KEngine;
22
class
Entity;
23
24
namespace
Events {
25
class
Key;
26
class
Input;
27
}
28
29
namespace
Graphical {
30
class
GraphicalLibManager;
31
}
32
33
namespace
Tools {
34
class
Color;
35
class
Vector2;
36
class
Rectangle;
37
}
38
39
namespace
UI {
40
class
Image
;
41
class
Text
;
42
}
43
44
}
45
46
namespace
KapEngine
{
47
48
namespace
Graphical {
49
50
class
GraphicalLib
:
public
Entity
{
51
public
:
52
GraphicalLib
(std::string
const
& name,
GraphicalLibManager
&manager);
53
~
GraphicalLib
();
54
55
//updates things
56
virtual
void
clear();
57
virtual
void
display();
58
virtual
void
getEvents();
59
60
//back system call
61
std::string getName()
const
{
62
PROFILER_FUNC_START();
63
PROFILER_FUNC_END();
64
return
_name;
65
}
66
67
//inputs
68
virtual
float
getJoystikValue(
int
gamepadId,
int
joystickId) {
69
PROFILER_FUNC_START();
70
PROFILER_FUNC_END();
71
return
0.0f;
72
}
73
74
std::vector<Events::Key> getNewKeys()
const
{
75
PROFILER_FUNC_START();
76
PROFILER_FUNC_END();
77
return
_newPressedInputs;
78
}
79
std::vector<Events::Key> getKeysPressed()
const
{
80
PROFILER_FUNC_START();
81
PROFILER_FUNC_END();
82
return
_pressedInputs;
83
}
84
std::vector<Events::Key> getKeysReleased()
const
{
85
PROFILER_FUNC_START();
86
PROFILER_FUNC_END();
87
return
_releasedInputs;
88
}
89
90
virtual
Tools::Vector2
getMousePosition()
const
{
91
PROFILER_FUNC_START();
92
PROFILER_FUNC_END();
93
Tools::Vector2
res;
94
95
return
res;
96
}
97
98
virtual
void
clearCache() {}
99
100
virtual
void
stopDisplay() {}
101
102
virtual
void
startDisplay() {}
103
104
virtual
Tools::Vector2
getScreenSize();
105
106
virtual
void
playMusic(std::string
const
& musicPath,
float
volume = 1.0f) {}
107
virtual
void
stopMusic() {}
108
virtual
void
pauseMusic() {}
109
virtual
void
resumMusic() {}
110
virtual
void
restartMusic() {}
111
virtual
void
setMusicVolume(
float
volume) {}
112
113
virtual
void
playSound(std::string
const
& soundPath) {}
114
void
setSoundVolume(
float
volume) {
115
PROFILER_FUNC_START();
116
_soundVolume = volume;
117
PROFILER_FUNC_END();
118
}
119
120
virtual
void
drawRectangle(
Tools::Vector2
const
& position,
Tools::Vector2
const
& size,
Tools::Color
const
& color) {}
121
virtual
void
drawRectangle(
Tools::Rectangle
rectangle,
Tools::Color
const
& color,
float
rotation) {}
122
123
//graphical call
124
125
void
setDrawText(std::function<
void
(
UI::Text
&)> f) {
126
PROFILER_FUNC_START();
127
_drawText = f;
128
PROFILER_FUNC_END();
129
}
130
void
setDrawImage(std::function<
void
(
UI::Image
&)> f) {
131
PROFILER_FUNC_START();
132
_drawImage = f;
133
PROFILER_FUNC_END();
134
}
135
136
void
drawText(
UI::Text
&txt) {
137
PROFILER_FUNC_START();
138
_drawText(txt);
139
PROFILER_FUNC_END();
140
}
141
void
drawImage(
UI::Image
&img) {
142
PROFILER_FUNC_START();
143
_drawImage(img);
144
PROFILER_FUNC_END();
145
}
146
147
protected
:
148
std::vector<Events::Key> _newPressedInputs;
149
std::vector<Events::Key> _pressedInputs;
150
std::vector<Events::Key> _releasedInputs;
151
std::string _name;
152
GraphicalLibManager
&manager;
153
154
std::function<void(
UI::Text
&)> _drawText;
155
std::function<void(
UI::Image
&)> _drawImage;
156
157
float
_soundVolume = 1.f;
158
159
};
160
161
}
162
}
163
164
#endif
/* !GRAPHICALLIB_HPP_ */
KapEngine::UI::Text
Definition:
UiText.hpp:30
Input.hpp
KapEngine::UI::Image
Definition:
UiImage.hpp:35
KapEngine::Tools::Vector2
Definition:
Vectors.hpp:25
KapEngine::Graphical::GraphicalLibManager
Definition:
GraphicalLibManager.hpp:31
KapEngine::Tools::Color
Definition:
Colors.hpp:22
KapEngine
main namespace
Definition:
Component.hpp:17
KapEngine::Tools::Rectangle
Definition:
Rectangle.hpp:23
KapEngine::Graphical::GraphicalLib
Definition:
GraphicalLib.hpp:50
KapEngine::Entity
Definition:
Entity.hpp:15
Library
KapEngine
KapEngine
GraphicalLib
GraphicalLib.hpp
Generated by
1.8.17