Added generic button

This commit is contained in:
2022-06-21 14:52:36 +02:00
parent a3a1e900b5
commit 2402567330
8 changed files with 100 additions and 4 deletions
+17
View File
@@ -1,4 +1,5 @@
#include "../sdlpp/sdlpp.hpp"
#include "gui/gui.hpp"
#include "sprites.hpp"
#ifdef _WIN32
#include "../sdlpp/SDL2/SDL2_framerate.h"
@@ -56,6 +57,7 @@ struct MouseInfo {
SDLPP::Vec2D<int> edit_box;
SDLPP::Vec2D<int> tool_box;
ToolType::Value tool_type{};
const Button *cur_button{};
};
struct MapInfo {
@@ -491,6 +493,7 @@ void getMousePositionFlags(SDLPP::Scene &scene) {
MouseVisitor visitor;
scene.visitCollisions(*mouse, visitor);
global_vars.mouse.cur_button = visitor.getCurButton();
global_vars.mouse.cur_flags = visitor.getFlags();
// + 1 because the left map arrow is on position 0
global_vars.mouse.edit_box =
@@ -556,6 +559,9 @@ void mouseUpAction(uint64_t flags, SDLPP::Scene &scene) {
updateToolSelection(global_vars.tool.cur_page_characters - 1,
ToolType::CHARACTER);
}
if(MouseVisitor::button(flags)) {
global_vars.mouse.cur_button->performFunction();
}
}
SDLPP::Vec2D<int> getSelectedObjectIndexes() {
@@ -948,12 +954,18 @@ void checkArrowsEnabled(uint64_t cur_page, uint64_t max_page,
}
}
void testButtonFunc(void *input) {
auto actual = static_cast<int*>(input);
std::cout << "NUM: " << *actual << std::endl;
}
#ifdef _WIN32
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PWSTR szCmdLine, int nCmdShow) {
#else
int main() {
#endif
int num = 0;
SDLPP::init();
SDLPP::Window w("Mario editor!");
w.setResizable(true);
@@ -1125,6 +1137,10 @@ int main() {
updateToolSelection(0, ToolType::CHARACTER);
setToolColor();
auto button = createButton(0, 0, 0.2, 0.2, renderer, "CLICK ME", "#FFFFFF", "#000000", "#FF0088", testButtonFunc, &num);
button->setStatic();
scene->addObject(button);
auto base = SDL_GetTicks();
int frames = 0;
std::thread inputThread(doInput, scene);
@@ -1146,6 +1162,7 @@ int main() {
setFlag(UPDATE_FLAG);
while (!getFlag(QUIT_FLAG)) {
num = (num + 1) % 256;
SDL_framerateDelay(&gFPS);
SDL_PumpEvents();
std::lock_guard<std::mutex> lock(destruction_mutex);