-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKey.cpp
More file actions
73 lines (52 loc) · 1.63 KB
/
Copy pathKey.cpp
File metadata and controls
73 lines (52 loc) · 1.63 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "Key.h"
#include "Keyboard.h"
TimestampAndID::TimestampAndID(Uint32 timestamp, size_t ID, KeyEventType keyEventType) {
this->timestamp = timestamp;
this->ID = ID;
this->keyEventType = keyEventType;
}
Button::Button() = default;
Key::Key() : Button() {
initKey();
}
Key::Key(int x, int y, int w, int h) {
initKey();
resizeButton(x, y, w, h);
}
constexpr void Key::initKey() {
this->audioConvert.buf = nullptr;
this->startOfCurrAudio = 0;
}
constexpr void Button::resizeButton(int x, int y, int w, int h) {
this->rectangle.x = x;
this->rectangle.y = y;
this->rectangle.w = w;
this->rectangle.h = h;
}
bool Button::checkMouseClick(const SDL_MouseButtonEvent &event) {
return (event.x >= this->rectangle.x && event.x <= this->rectangle.x + this->rectangle.w &&
event.y >= this->rectangle.y && event.y <= this->rectangle.y + this->rectangle.h);
}
bool Key::setAudioBufferWithFile(char *filename, SDL_AudioSpec *desiredAudioSpec) {
Uint8 *audioBuffer = nullptr;
Uint32 audioBufferLen = 0;
SDL_AudioSpec spec = SDL_AudioSpec();
SDL_AudioSpec *specPtr = &spec;
specPtr = SDL_LoadWAV(filename, specPtr, &audioBuffer, &audioBufferLen);
if (specPtr != nullptr) {
this->isDefaultSound = false;
delete[] this->audioConvert.buf;
this->audioConvert.buf = nullptr;
Keyboard::convert(&this->audioConvert, specPtr, desiredAudioSpec, audioBuffer, audioBufferLen);
SDL_FreeWAV(audioBuffer);
audioBuffer = nullptr;
return true;
}
else {
return false;
}
}
void Key::freeKey() {
delete[] this->audioConvert.buf;
this->audioConvert.buf = nullptr;
}