[nostalgia/core/studio] Add zoom support to TileSheetEditor

This commit is contained in:
2022-02-03 00:24:40 -06:00
parent 78942ce21d
commit d4e198ecc3
6 changed files with 49 additions and 12 deletions
+24 -2
View File
@@ -2,6 +2,8 @@
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <iostream>
#include <imgui.h>
#include <nostalgia/common/point.hpp>
@@ -47,8 +49,10 @@ void TileSheetEditor::paste() {
void TileSheetEditor::draw(core::Context*) noexcept {
const auto size = ImGui::GetContentRegionAvail();
const auto sizei = common::Size(static_cast<int>(size.x), static_cast<int>(size.y));
if (m_framebuffer.width != sizei.width || m_framebuffer.height != sizei.height) {
m_framebuffer = glutils::generateFrameBuffer(sizei.width, sizei.height);
if (m_updated || m_framebuffer.width != sizei.width || m_framebuffer.height != sizei.height) {
if (!m_framebuffer) {
m_framebuffer = glutils::generateFrameBuffer(sizei.width, sizei.height);
}
m_pixels.initBufferSet(m_img, *m_pal);
m_pixelGrid.initBufferSet(m_img);
}
@@ -57,6 +61,24 @@ void TileSheetEditor::draw(core::Context*) noexcept {
glDraw();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
ImGui::Image(reinterpret_cast<void*>(m_framebuffer.color.id), size, ImVec2(0, 1), ImVec2(1, 0));
if (ImGui::IsItemHovered()) {
const auto &io = ImGui::GetIO();
const auto wheel = io.MouseWheel * 0.01f;
const auto zoomMod = ox::defines::OS == ox::defines::OS::Darwin ? io.KeySuper : io.KeyCtrl;
if (zoomMod && wheel != 0) {
m_pixelSizeMod = ox::clamp(m_pixelSizeMod + wheel, 0.55f, 2.f);
m_pixels.setPixelSizeMod(m_pixelSizeMod);
m_pixelGrid.setPixelSizeMod(m_pixelSizeMod);
m_updated = true;
}
if (io.MouseClicked[0]) {
auto clickPos = io.MouseClickedPos[0];
const auto &winPos = ImGui::GetWindowPos();
clickPos.x -= winPos.x;
clickPos.y -= winPos.y;
std::cout << clickPos.x - 8 << ", " << clickPos.y - 31 << '\n';
}
}
}
void TileSheetEditor::glDraw() noexcept {