100 glClear(GL_COLOR_BUFFER_BIT);
101 gl2d::enableNecessaryGLFeatures();
102 renderer.updateWindowMetrics(windowState.
w, windowState.
h);
106 float wheel = ImGui::GetIO().MouseWheel;
110 if ((ImGui::GetIO().KeysData[ImGuiKey_LeftCtrl].Down || ImGui::GetIO().KeysData[ImGuiKey_RightCtrl].Down) && input.
hasFocus)
112 renderer.currentCamera.zoom += wheel * 3;
118 glm::vec2 delta = {};
148 renderer.currentCamera.follow(
pos, input.
deltaTime * speed * 0.9f, 0.0001, 0.2, windowState.
w, windowState.
h);
151 auto viewRect =
renderer.getViewRect();
158 minV = {viewRect.x-1, viewRect.y-1};
159 maxV = minV + glm::ivec2{viewRect.z+2, viewRect.w+2};
160 minV = glm::max(minV, {0,0});
161 maxV = glm::min(maxV,
mapSize);
164 for (
int j = minV.y; j < maxV.y; j++)
165 for (
int i = minV.x; i < maxV.x; i++)
176 glm::ivec2 blockPosition;
180 auto lerp = [](
auto a,
auto b,
auto c)
182 return a * (1.f - c) + b * c;
185 blockPosition = lerp(glm::vec2(viewRect.x, viewRect.y),
186 glm::vec2(viewRect.x + viewRect.z, viewRect.y + viewRect.w), glm::vec2(mousePos) / glm::vec2(windowState.
w, windowState.
h));
188 if (blockPosition.x >= maxV.x || blockPosition.y >= maxV.y || blockPosition.x < minV.x || blockPosition.y < minV.y)
190 blockPosition = {-1,-1};
194 renderer.renderRectangle({blockPosition, 1, 1}, {0.9,0.9,0.9,0.9}, {}, {},
tiles,
201 ImGui::Begin(
"Block picker");
205 ImGui::Checkbox(
"Show Collidable Blocks", &
collidable);
206 ImGui::Checkbox(
"Show Non-Collidable Blocks", &
nonCollidable);
207 ImGui::Checkbox(
"Flip", &
flip);
208 ImGui::Text(
"MousePos: %d, %d", blockPosition.x, blockPosition.y);
210 ImGui::InputText(
"Save file",
path,
sizeof(
path));
212 if (ImGui::Button(
"save"))
221 unsigned short mCount = 0;
222 ImGui::BeginChild(
"Block Selector");
223 bool inImgui = ImGui::IsWindowHovered();
227 unsigned short localCount = 0;
228 while (mCount < 8*10)
232 ImGui::PushID(mCount);
233 if (ImGui::ImageButton((
void *)(intptr_t)
tiles.id,
234 {35,35}, {uv.x, uv.y}, {uv.z, uv.w}))
241 if (localCount % 10 != 0)
254 unsigned short localCount = 0;
255 while (mCount < 8 * 10)
261 ImGui::PushID(mCount);
262 if (ImGui::ImageButton((
void *)(intptr_t)
tiles.id,
263 {35,35}, {uv.x, uv.y}, {uv.z, uv.w}));
269 if (localCount % 10 != 0)
281 unsigned short localCount = 0;
282 while (mCount < 8*10)
288 ImGui::PushID(mCount);
289 if (ImGui::ImageButton((
void *)(intptr_t)
tiles.id,
290 {35,35}, {uv.x, uv.y}, {uv.z, uv.w}));
296 if (localCount % 10 != 0)
316 if (input.
hasFocus && input.
lMouse.held() && blockPosition.x >= 0)