Playing around with buttons
This commit is contained in:
+33
-8
@@ -57,7 +57,7 @@ struct MouseInfo {
|
||||
SDLPP::Vec2D<int> edit_box;
|
||||
SDLPP::Vec2D<int> tool_box;
|
||||
ToolType::Value tool_type{};
|
||||
const Button *cur_button{};
|
||||
uint64_t cur_button_index{};
|
||||
};
|
||||
|
||||
struct MapInfo {
|
||||
@@ -89,6 +89,7 @@ struct GlobalVars {
|
||||
std::vector<std::shared_ptr<SDLPP::RenderObject>> tool_boxes;
|
||||
std::vector<std::shared_ptr<SDLPP::RenderObject>> mod_boxes;
|
||||
std::vector<std::shared_ptr<SDLPP::RenderObject>> character_boxes;
|
||||
std::vector<std::shared_ptr<Button>> buttons;
|
||||
enum LandType::Value current_world_type{};
|
||||
std::shared_ptr<MarioBlock> coin_tool;
|
||||
std::shared_ptr<MarioBlock> generic_tool;
|
||||
@@ -103,6 +104,7 @@ struct GlobalVars {
|
||||
|
||||
GlobalVars global_vars;
|
||||
std::mutex destruction_mutex;
|
||||
std::mutex render_mutex;
|
||||
|
||||
void updateTool() {
|
||||
auto tool_index = global_vars.tool.index;
|
||||
@@ -493,7 +495,15 @@ void getMousePositionFlags(SDLPP::Scene &scene) {
|
||||
|
||||
MouseVisitor visitor;
|
||||
scene.visitCollisions(*mouse, visitor);
|
||||
global_vars.mouse.cur_button = visitor.getCurButton();
|
||||
if(visitor.getCurButton() != global_vars.mouse.cur_button_index) {
|
||||
if(global_vars.mouse.cur_button_index != (uint64_t)-1) {
|
||||
global_vars.buttons[global_vars.mouse.cur_button_index]->unsetHighlight(render_mutex);
|
||||
}
|
||||
if(visitor.getCurButton() != (uint64_t)-1) {
|
||||
global_vars.buttons[visitor.getCurButton()]->setHighlight(render_mutex);
|
||||
}
|
||||
}
|
||||
global_vars.mouse.cur_button_index = visitor.getCurButton();
|
||||
global_vars.mouse.cur_flags = visitor.getFlags();
|
||||
// + 1 because the left map arrow is on position 0
|
||||
global_vars.mouse.edit_box =
|
||||
@@ -560,7 +570,7 @@ void mouseUpAction(uint64_t flags, SDLPP::Scene &scene) {
|
||||
ToolType::CHARACTER);
|
||||
}
|
||||
if(MouseVisitor::button(flags)) {
|
||||
global_vars.mouse.cur_button->performFunction();
|
||||
global_vars.buttons[global_vars.mouse.cur_button_index]->performFunction();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -957,6 +967,7 @@ 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;
|
||||
global_vars.buttons[0]->disable(render_mutex);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
@@ -1137,9 +1148,20 @@ 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);
|
||||
ButtonColors default_button_theme{};
|
||||
default_button_theme.bg_color = "#FF0088";
|
||||
default_button_theme.bg_color_highlight = "#FF00FF";
|
||||
default_button_theme.bg_color_disabled = "#FFAAFF";
|
||||
default_button_theme.font_color = "#FFFFFF";
|
||||
default_button_theme.font_color_highlight = "#FFFFFF";
|
||||
default_button_theme.font_color_disabled = "#BBBBBB";
|
||||
default_button_theme.font_outline_color = "#000000";
|
||||
default_button_theme.font_outline_color_highlight = "#444444";
|
||||
default_button_theme.font_outline_color_disabled = "#888888";
|
||||
global_vars.buttons.emplace_back(std::make_shared<Button>(0, 0, 0.2, 0.2, renderer, "CLICK ME", default_button_theme, testButtonFunc, &num));
|
||||
global_vars.buttons.back()->setStatic();
|
||||
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
|
||||
scene->addObject(global_vars.buttons.back());
|
||||
|
||||
auto base = SDL_GetTicks();
|
||||
int frames = 0;
|
||||
@@ -1166,8 +1188,11 @@ int main() {
|
||||
SDL_framerateDelay(&gFPS);
|
||||
SDL_PumpEvents();
|
||||
std::lock_guard<std::mutex> lock(destruction_mutex);
|
||||
scene->renderScene();
|
||||
renderer->presentRenderer();
|
||||
{
|
||||
std::lock_guard<std::mutex> render(render_mutex);
|
||||
scene->renderScene();
|
||||
renderer->presentRenderer();
|
||||
}
|
||||
frames++;
|
||||
if (SDL_GetTicks() - base >= 1000) {
|
||||
std::cout << "FPS: " << frames << std::endl;
|
||||
|
||||
Reference in New Issue
Block a user