[nostalgia/core/studio] Add scrolling support to TileSheetEditor
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
|
||||
#include <nostalgia/core/consts.hpp>
|
||||
#include "ptidxconv.hpp"
|
||||
#include <nostalgia/core/ptidxconv.hpp>
|
||||
#include "tilesheetpixels.hpp"
|
||||
|
||||
namespace nostalgia::core {
|
||||
@@ -18,12 +18,14 @@ ox::Error TileSheetPixels::buildShader() noexcept {
|
||||
return glutils::buildShaderProgram(Vshad, Fshad).moveTo(&m_shader);
|
||||
}
|
||||
|
||||
void TileSheetPixels::draw(bool update) noexcept {
|
||||
void TileSheetPixels::draw(bool update, const ImVec2 &scroll) noexcept {
|
||||
glUseProgram(m_shader);
|
||||
glBindVertexArray(m_bufferSet.vao);
|
||||
if (update) {
|
||||
glutils::sendVbo(m_bufferSet);
|
||||
}
|
||||
const auto uniformScroll = static_cast<GLint>(glGetUniformLocation(m_shader, "vScroll"));
|
||||
glUniform2f(uniformScroll, scroll.x, scroll.y);
|
||||
glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(m_bufferSet.elements.size()), GL_UNSIGNED_INT, nullptr);
|
||||
}
|
||||
|
||||
@@ -47,6 +49,13 @@ void TileSheetPixels::initBufferSet(const NostalgiaGraphic &img, const Nostalgia
|
||||
reinterpret_cast<void*>(2 * sizeof(float)));
|
||||
}
|
||||
|
||||
ImVec2 TileSheetPixels::pixelSize(const ImVec2 &paneSize) const noexcept {
|
||||
const auto [sw, sh] = paneSize;
|
||||
constexpr float ymod = 0.35f / 10.0f;
|
||||
const auto xmod = ymod * sh / sw;
|
||||
return {xmod * m_pixelSizeMod, ymod * m_pixelSizeMod};
|
||||
}
|
||||
|
||||
void TileSheetPixels::setPixelBufferObject(unsigned vertexRow, float x, float y, Color16 color, float *vbo, GLuint *ebo) noexcept {
|
||||
const auto [xmod, ymod] = pixelSize();
|
||||
x *= xmod;
|
||||
@@ -102,11 +111,4 @@ void TileSheetPixels::setBufferObjects(const NostalgiaGraphic &img, const Nostal
|
||||
}
|
||||
}
|
||||
|
||||
ImVec2 TileSheetPixels::pixelSize() const noexcept {
|
||||
const auto [sw, sh] = ImGui::GetContentRegionAvail();
|
||||
constexpr float ymod = 0.35f / 10.0f;
|
||||
const auto xmod = ymod * sh / sw;
|
||||
return {xmod * m_pixelSizeMod, ymod * m_pixelSizeMod};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user