From 152580faf7e7665a04be69b4a0e0538cf39c975c Mon Sep 17 00:00:00 2001 From: rtk0c Date: Sat, 17 May 2025 17:35:11 -0700 Subject: Interactive buttons --- src/sandbox.cpp | 5 ----- src/ui.cpp | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/sandbox.cpp b/src/sandbox.cpp index 85a4850..d0d918c 100644 --- a/src/sandbox.cpp +++ b/src/sandbox.cpp @@ -35,11 +35,6 @@ Sandbox::Sandbox(int w, int h) , height{ h } // { memset(_bitmap.data(), 0xff, _bitmap.size() * sizeof(_bitmap[0])); - for (int y = 80; y <= 90; ++y) { - for (int x = 10; x <= 13; ++x) { - set_sand(x, y, Tile{ .so = Tile::SAND }); - } - } } static void simulate_sand_tile(Sandbox& self, int x, int y) { diff --git a/src/ui.cpp b/src/ui.cpp index fdb9eee..f356afa 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -4,6 +4,14 @@ #include +static void AddSand(Sandbox& sb) { + for (int y = 80; y <= 90; ++y) { + for (int x = 10; x <= 13; ++x) { + sb.set_sand(x, y, Tile{ .so = Tile::SAND }); + } + } +} + void ShowEverything() { ImGui::Begin("Sandbox"); constexpr int kWidth = 40; @@ -13,6 +21,14 @@ void ShowEverything() { static OglImage gl; sandbox.simulate_step(); gl.upload(reinterpret_cast(sandbox._bitmap.data()), kWidth, kHeight); + + if (ImGui::Button("Reset sandbox")) { + sandbox = Sandbox(40, 100); + } + if (ImGui::Button("Add sand")) { + AddSand(sandbox); + } + constexpr float kScale = 4.0f; constexpr ImVec2 kSize(kWidth * kScale, kHeight * kScale); ImGui::Image(gl.as_imgui(), kSize, ImVec2(0, 1), ImVec2(1, 0)); -- cgit v1.2.3-70-g09d2