[nostalgia/core/studio] Add ability to select pixels for copy/paste

This commit is contained in:
2022-03-10 02:39:22 -06:00
parent 3486734b50
commit b502b8cc30
9 changed files with 147 additions and 33 deletions
+20 -8
View File
@@ -4,10 +4,14 @@
#include <nostalgia/core/consts.hpp>
#include <nostalgia/core/ptidxconv.hpp>
#include "tilesheeteditormodel.hpp"
#include "tilesheetpixels.hpp"
namespace nostalgia::core {
TileSheetPixels::TileSheetPixels(TileSheetEditorModel *model) noexcept: m_model(model) {
}
void TileSheetPixels::setPixelSizeMod(float sm) noexcept {
m_pixelSizeMod = sm;
}
@@ -29,14 +33,14 @@ void TileSheetPixels::draw(bool update, const geo::Vec2 &scroll) noexcept {
glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(m_bufferSet.elements.size()), GL_UNSIGNED_INT, nullptr);
}
void TileSheetPixels::initBufferSet(const geo::Vec2 &paneSize, const TileSheet &img, const TileSheet::SubSheet &subSheet, const Palette &pal) noexcept {
void TileSheetPixels::initBufferSet(const geo::Vec2 &paneSize) noexcept {
// vao
m_bufferSet.vao = glutils::generateVertexArrayObject();
glBindVertexArray(m_bufferSet.vao);
// vbo & ebo
m_bufferSet.vbo = glutils::generateBuffer();
m_bufferSet.ebo = glutils::generateBuffer();
setBufferObjects(paneSize, img, subSheet, pal);
setBufferObjects(paneSize);
glutils::sendVbo(m_bufferSet);
glutils::sendEbo(m_bufferSet);
// vbo layout
@@ -78,21 +82,29 @@ void TileSheetPixels::setPixelBufferObject(const geo::Vec2 &paneSize, unsigned v
memcpy(ebo, elms, sizeof(elms));
}
void TileSheetPixels::setBufferObjects(const geo::Vec2 &paneSize, const TileSheet &img, const TileSheet::SubSheet &subSheet, const Palette &pal) noexcept {
void TileSheetPixels::setBufferObjects(const geo::Vec2 &paneSize) noexcept {
// set buffer lengths
const auto width = subSheet.columns * TileWidth;
const auto height = subSheet.rows * TileHeight;
const auto subSheet = m_model->activeSubSheet();
const auto &pal = m_model->pal();
const auto width = subSheet->columns * TileWidth;
const auto height = subSheet->rows * TileHeight;
const auto pixels = static_cast<unsigned>(width * height);
m_bufferSet.vertices.resize(pixels * VertexVboLength);
m_bufferSet.elements.resize(pixels * VertexEboLength);
// set pixels
subSheet.walkPixels(img.bpp, [&](std::size_t i, uint8_t p) {
const auto color = pal.colors[p];
const auto pt = idxToPt(static_cast<int>(i), subSheet.columns);
subSheet->walkPixels(m_model->img().bpp, [&](std::size_t i, uint8_t p) {
auto color = pal.colors[p];
const auto pt = idxToPt(static_cast<int>(i), subSheet->columns);
const auto fx = static_cast<float>(pt.x);
const auto fy = static_cast<float>(pt.y);
const auto vbo = &m_bufferSet.vertices[i * VertexVboLength];
const auto ebo = &m_bufferSet.elements[i * VertexEboLength];
if (m_model->pixelSelected(i)) {
const auto r = red16(color) / 2;
const auto g = (green16(color) + 20) / 2;
const auto b = (blue16(color) + 31) / 2;
color = color16(r, g, b);
}
setPixelBufferObject(paneSize, i * VertexVboRows, fx, fy, color, vbo, ebo);
});
}