Skip to content

Commit 636cde3

Browse files
committed
Add resize to the board area
1 parent 1fcc888 commit 636cde3

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

source/code/puzzle_editor/PuzzleEditorState.cpp

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ Source information and contacts persons can be found at
2929
#include "../puzzlehandler.hpp"
3030

3131

32+
PuzzleEditorState::PuzzleEditorState() {
33+
this->window_resize = sago::SagoLogicalResize(BOARD_WIDTH+5, BOARD_HEIGHT+5);
34+
}
35+
3236
bool PuzzleEditorState::IsActive() {
3337
return isActive;
3438
}
@@ -48,21 +52,51 @@ void PuzzleEditorState::SelectFile(const std::string& file) {
4852
LoadPuzzleStages();
4953
}
5054

55+
static void LogicalToPhysical(const sago::SagoLogicalResize& resize, ImVec2& inout) {
56+
int inx = inout.x;
57+
int iny = inout.y;
58+
int outx = inout.x;
59+
int outy = inout.y;
60+
resize.LogicalToPhysical(inx, iny, outx, outy);
61+
inout.x = outx;
62+
inout.y = outy;
63+
}
64+
5165
void PuzzleEditorState::Draw(SDL_Renderer* target) {
5266
DrawBackground(target);
5367

5468
ImGui::Begin("Board area");
5569
ImGui::BeginChild("Test");
5670
ImVec2 p = ImGui::GetCursorScreenPos();
57-
float xoffset = p.x;
58-
float yoffset = p.y;
59-
float height = BOARD_HEIGHT;
60-
float width = BOARD_WIDTH;
71+
ImVec2 size = ImGui::GetContentRegionAvail();
72+
int xoffset = p.x;
73+
int yoffset = p.y;
74+
int height = BOARD_HEIGHT;
75+
int width = BOARD_WIDTH;
76+
window_resize.SetPhysicalSize(size.x, size.y);
77+
78+
6179
for (int i=0; i <= 6;++i) {
62-
ImGui::GetWindowDrawList()->AddLine(ImVec2(i*50.0f+xoffset, yoffset), ImVec2(i*50.0f+xoffset, height+yoffset), IM_COL32(255, 0, 0, 100));
80+
ImVec2 p1(i*50.0f, 0);
81+
ImVec2 p2(i*50.0f, height);
82+
LogicalToPhysical(window_resize, p1);
83+
LogicalToPhysical(window_resize, p2);
84+
p1.x += xoffset;
85+
p1.y += yoffset;
86+
p2.x += xoffset;
87+
p2.y += yoffset;
88+
ImGui::GetWindowDrawList()->AddLine(p1, p2, IM_COL32(255, 0, 0, 100));
6389
}
6490
for (int i=0; i <= 12;++i) {
65-
ImGui::GetWindowDrawList()->AddLine(ImVec2(xoffset,yoffset+i*50.0f), ImVec2(xoffset+width, yoffset+i*50.0f), IM_COL32(255, 0, 0, 100));
91+
ImVec2 p1(0,i*50.0f);
92+
ImVec2 p2(width, i*50.0f);
93+
LogicalToPhysical(window_resize, p1);
94+
LogicalToPhysical(window_resize, p2);
95+
p1.x += xoffset;
96+
p1.y += yoffset;
97+
p2.x += xoffset;
98+
p2.y += yoffset;
99+
ImGui::GetWindowDrawList()->AddLine(p1, p2, IM_COL32(255, 0, 0, 100));
66100
}
67101
ImGui::EndChild();
68102
ImGui::End();

source/code/puzzle_editor/PuzzleEditorState.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Source information and contacts persons can be found at
3333

3434
class PuzzleEditorState : public sago::GameStateInterface {
3535
public:
36-
PuzzleEditorState() = default;
36+
PuzzleEditorState();
3737
PuzzleEditorState(const PuzzleEditorState& orig) = delete;
3838
virtual ~PuzzleEditorState() = default;
3939

@@ -51,4 +51,5 @@ class PuzzleEditorState : public sago::GameStateInterface {
5151
int selected_puzzle = -1;
5252
std::string selected_file;
5353
std::vector<std::string> puzzle_files;
54+
sago::SagoLogicalResize window_resize;
5455
};

0 commit comments

Comments
 (0)