-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRaylibAdditions.hpp
executable file
·121 lines (107 loc) · 5.5 KB
/
RaylibAdditions.hpp
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#pragma once
#include <raylib.h>
#include <string>
#include <unordered_map>
#include <vector>
#include <variant>
#include "DrawClasses.hpp"
namespace RaylibAdditions { // Define classes here
// Window class, construct using title, width, heigth. All args can be changed and then run updateWindow to resize and rename window
class WindowClass {
public:
std::string title;
int width;
int height;
WindowClass(std::string windowTitle, int windowWidth, int windowHeight, int monitor = 0)
: title(windowTitle), width(windowWidth), height(windowHeight) {
InitWindow(width, height, title.c_str());
SetWindowMonitor(monitor);
};
~WindowClass() {
CloseWindow();
}
void updateWindow() {
SetWindowTitle(title.c_str());
SetWindowSize(width, height);
}
};
// Button class, consturct using all args (some are optional)
class ButtonClass {
public:
Rectangle rect;
std::string text;
int textSize;
Color color;
Color outlineColor;
Color textColor;
int outlineThickness;
float scale;
// state, 0 = off, 1 = hover, 2 = pressed, 3 = released (only one cycle)
int state;
//optional sound
Sound pressedSound;
Sound releasedSound;
ButtonClass(Rectangle buttonRect, std::string buttonText, int buttonTextSize, Color buttonColor, Color buttonOutlineColor, Color buttonTextColor, int buttonOutlineThickness, float buttonScale, Sound buttonPressedSound = Sound(), Sound buttonReleasedSound = Sound(), int buttonState = 0)
: rect(buttonRect), text(buttonText), textSize(buttonTextSize), color(buttonColor), outlineColor(buttonOutlineColor), textColor(buttonTextColor), outlineThickness(buttonOutlineThickness), scale(buttonScale), state(buttonState), pressedSound(buttonPressedSound), releasedSound(buttonReleasedSound) {}
};
class LoadedButtonClass {
public:
Texture2D texture;
Vector2 pos;
float scale;
// state, 0 = off, 1 = hover, 2 = pressed, 3 = released (only one cycle)
int state;
//optional sound
Sound pressedSound;
Sound releasedSound;
LoadedButtonClass(Texture2D buttonTexture, Vector2 buttonPos, float buttonScale, Sound buttonPressedSound = Sound(), Sound buttonReleasedSound = Sound(), int buttonState = 0)
: texture(buttonTexture), pos(buttonPos), scale(buttonScale), state(buttonState), pressedSound(buttonPressedSound), releasedSound(buttonReleasedSound) {}
};
class DrawClass { // Experimental use only for testing, more a preformance lost than boost
std::vector<std::variant<
Rectangle,
DrawStructs::DrawTextCenterRectStruct,
DrawStructs::DrawRectRectStruct,
DrawStructs::DrawTextureStruct
>> list;
public:
void pushList(std::variant<Rectangle, DrawStructs::DrawTextCenterRectStruct, DrawStructs::DrawRectRectStruct, DrawStructs::DrawTextureStruct> item);
std::variant<Rectangle, DrawStructs::DrawTextCenterRectStruct, DrawStructs::DrawRectRectStruct, DrawStructs::DrawTextureStruct> popList();
void clearList();
void drawList();
};
}
namespace RaylibAdditions { // Define functions here
// Draws text in the Y center of a Rectangle and to the X left in the Rectangle
void drawTextLeftCenterRect(Rectangle& rect, std::string& text, int fontSize, Color color);
void drawTextLeftCenterRect(Rectangle &rect, std::string &text, int fontSize, Color color, float xOffset);
// Draws text in the X center of a Rectangle and to the Y top in the Rectangle
void drawTextCenterTopRect(Rectangle& rect, std::string& text, int fontSize, Color color);
void drawTextCenterTopRect(Rectangle& rect, std::string& text, int fontSize, Color color, int topOffset);
// Draws text in the center of a Rectangle
void drawTextCenterRect(Rectangle& rect, std::string& text, int fontSize, Color color);
// Draws text in the center of Rectangle custom text args
void drawTextCenterRect(Rectangle& rect, std::string& text, int fontsize, float spacing, Color tint, Font font = GetFontDefault());
// Draws a Rectangle with an outline
void drawRectWOutline(Rectangle& rect, float lineThick, Color color, Color outlineColor);
// Draws a Rectangle with an outline and text
void drawRectWOutlineWText(Rectangle& rect, float lineThick, Color rectColor, Color outlineColor, std::string& text, int fontSize, Color textColor);
// Draws a Rectangle with an outline and text but top center
void drawRectWOutlineWTextCenterTop(Rectangle& rect, float lineThick, Color rectColor, Color outlineColor, std::string& text, int fontSize, Color textColor);
// Draws a Rectangle with an outline and text using custom text args
void drawRectWOutlineWText(Rectangle& rect, float lineThick, Color rectColor, Color outlineColor, std::string& text, int fontSize, Color textColor, float textSpacing, Font font = GetFontDefault());
// Draws a button using the ButtonClass
void drawButton(RaylibAdditions::ButtonClass* button);
// Draws all the buttons in a std::unordererd_map
void drawButtons(std::unordered_map<std::string, ButtonClass>* buttons);
// Updates the state of all buttons in a std::unordererd_map
void updateButtonstates(std::unordered_map<std::string, ButtonClass>* buttons);
// updates the state of all buttons in a std::unordered_map but using a camera and does getScreenToWorld
void updateButtonstates(std::unordered_map<std::string, ButtonClass>* buttons, Camera2D* camera);
// Creates a normal Camera2D
Camera2D createCamera();
// Creates camera zooming into game area using getScreenHeight()
Camera2D createCamera(int gameHeight);
// Draws an FPS counter at the position supplied 1 = top left, 2 = top middle, 3 = top right, 4 = middle left and so on
void drawFPSCounter(int position, int fontSize, Color color);
}