git repos / blockattack-game

commit 636cde3b

Poul Sander · 2025-05-15 21:40
636cde3b74db2247764f772ba4102fd6105b2b1f patch · browse files
parent 1fcc88813f344d779187a40793380b7186a5c0c7

Add resize to the board area

Changed files

M source/code/puzzle_editor/PuzzleEditorState.cpp before
M source/code/puzzle_editor/PuzzleEditorState.hpp before
diff --git a/source/code/puzzle_editor/PuzzleEditorState.cpp b/source/code/puzzle_editor/PuzzleEditorState.cpp index ca205f5..91e60f8 100644 --- a/source/code/puzzle_editor/PuzzleEditorState.cpp +++ b/source/code/puzzle_editor/PuzzleEditorState.cpp
@@ -29,6 +29,10 @@ https://blockattack.net
#include "../puzzlehandler.hpp"
+PuzzleEditorState::PuzzleEditorState() {
+ this->window_resize = sago::SagoLogicalResize(BOARD_WIDTH+5, BOARD_HEIGHT+5);
+}
+
bool PuzzleEditorState::IsActive() {
return isActive;
}
@@ -48,21 +52,51 @@ void PuzzleEditorState::SelectFile(const std::string& file) {
LoadPuzzleStages();
}
+static void LogicalToPhysical(const sago::SagoLogicalResize& resize, ImVec2& inout) {
+ int inx = inout.x;
+ int iny = inout.y;
+ int outx = inout.x;
+ int outy = inout.y;
+ resize.LogicalToPhysical(inx, iny, outx, outy);
+ inout.x = outx;
+ inout.y = outy;
+}
+
void PuzzleEditorState::Draw(SDL_Renderer* target) {
DrawBackground(target);
ImGui::Begin("Board area");
ImGui::BeginChild("Test");
ImVec2 p = ImGui::GetCursorScreenPos();
- float xoffset = p.x;
- float yoffset = p.y;
- float height = BOARD_HEIGHT;
- float width = BOARD_WIDTH;
+ ImVec2 size = ImGui::GetContentRegionAvail();
+ int xoffset = p.x;
+ int yoffset = p.y;
+ int height = BOARD_HEIGHT;
+ int width = BOARD_WIDTH;
+ window_resize.SetPhysicalSize(size.x, size.y);
+
+
for (int i=0; i <= 6;++i) {
- ImGui::GetWindowDrawList()->AddLine(ImVec2(i*50.0f+xoffset, yoffset), ImVec2(i*50.0f+xoffset, height+yoffset), IM_COL32(255, 0, 0, 100));
+ ImVec2 p1(i*50.0f, 0);
+ ImVec2 p2(i*50.0f, height);
+ LogicalToPhysical(window_resize, p1);
+ LogicalToPhysical(window_resize, p2);
+ p1.x += xoffset;
+ p1.y += yoffset;
+ p2.x += xoffset;
+ p2.y += yoffset;
+ ImGui::GetWindowDrawList()->AddLine(p1, p2, IM_COL32(255, 0, 0, 100));
}
for (int i=0; i <= 12;++i) {
- ImGui::GetWindowDrawList()->AddLine(ImVec2(xoffset,yoffset+i*50.0f), ImVec2(xoffset+width, yoffset+i*50.0f), IM_COL32(255, 0, 0, 100));
+ ImVec2 p1(0,i*50.0f);
+ ImVec2 p2(width, i*50.0f);
+ LogicalToPhysical(window_resize, p1);
+ LogicalToPhysical(window_resize, p2);
+ p1.x += xoffset;
+ p1.y += yoffset;
+ p2.x += xoffset;
+ p2.y += yoffset;
+ ImGui::GetWindowDrawList()->AddLine(p1, p2, IM_COL32(255, 0, 0, 100));
}
ImGui::EndChild();
ImGui::End();
diff --git a/source/code/puzzle_editor/PuzzleEditorState.hpp b/source/code/puzzle_editor/PuzzleEditorState.hpp index 596c9cf..967350d 100644 --- a/source/code/puzzle_editor/PuzzleEditorState.hpp +++ b/source/code/puzzle_editor/PuzzleEditorState.hpp
@@ -33,7 +33,7 @@ https://blockattack.net
class PuzzleEditorState : public sago::GameStateInterface {
public:
- PuzzleEditorState() = default;
+ PuzzleEditorState();
PuzzleEditorState(const PuzzleEditorState& orig) = delete;
virtual ~PuzzleEditorState() = default;
@@ -51,4 +51,5 @@ private:
int selected_puzzle = -1;
std::string selected_file;
std::vector<std::string> puzzle_files;
+ sago::SagoLogicalResize window_resize;
};