This commit is contained in:
@ -19,10 +19,10 @@ using Color32 = uint32_t;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Color32 toColor32(Color16 nc) noexcept {
|
||||
const auto r = static_cast<Color32>(((nc & 0b0000000000011111) >> 0) * 8);
|
||||
const auto g = static_cast<Color32>(((nc & 0b0000001111100000) >> 5) * 8);
|
||||
const auto b = static_cast<Color32>(((nc & 0b0111110000000000) >> 10) * 8);
|
||||
const auto a = static_cast<Color32>(255);
|
||||
auto const r = static_cast<Color32>(((nc & 0b0000000000011111) >> 0) * 8);
|
||||
auto const g = static_cast<Color32>(((nc & 0b0000001111100000) >> 5) * 8);
|
||||
auto const b = static_cast<Color32>(((nc & 0b0111110000000000) >> 10) * 8);
|
||||
auto const a = static_cast<Color32>(255);
|
||||
return r | (g << 8) | (b << 16) | (a << 24);
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ struct InitParams {
|
||||
uint_t glBlocksPerSprite = 64;
|
||||
};
|
||||
|
||||
ox::Result<ox::UPtr<Context>> init(turbine::Context &tctx, InitParams const¶ms = {}) noexcept;
|
||||
ox::Result<ox::UPtr<Context>> init(turbine::Context &tctx, InitParams const ¶ms = {}) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
int tileColumns(Context&) noexcept;
|
||||
@ -122,12 +122,12 @@ int tileRows(Context&) noexcept;
|
||||
ox::Error loadBgPalette(
|
||||
Context &ctx,
|
||||
size_t palBank,
|
||||
CompactPalette const&palette,
|
||||
CompactPalette const &palette,
|
||||
size_t page = 0) noexcept;
|
||||
|
||||
ox::Error loadSpritePalette(
|
||||
Context &ctx,
|
||||
CompactPalette const&palette,
|
||||
CompactPalette const &palette,
|
||||
size_t page = 0) noexcept;
|
||||
|
||||
ox::Error loadBgPalette(
|
||||
@ -138,7 +138,7 @@ ox::Error loadBgPalette(
|
||||
ox::Error loadBgPalette(
|
||||
Context &ctx,
|
||||
size_t palBank,
|
||||
ox::FileAddress const&paletteAddr) noexcept;
|
||||
ox::FileAddress const &paletteAddr) noexcept;
|
||||
|
||||
ox::Error loadSpritePalette(
|
||||
Context &ctx,
|
||||
@ -146,12 +146,12 @@ ox::Error loadSpritePalette(
|
||||
|
||||
ox::Error loadSpritePalette(
|
||||
Context &ctx,
|
||||
ox::FileAddress const&paletteAddr) noexcept;
|
||||
ox::FileAddress const &paletteAddr) noexcept;
|
||||
|
||||
ox::Error loadBgTileSheet(
|
||||
Context &ctx,
|
||||
unsigned cbb,
|
||||
TileSheetSet const&set) noexcept;
|
||||
TileSheetSet const &set) noexcept;
|
||||
|
||||
void clearCbb(Context &ctx, unsigned cbb) noexcept;
|
||||
|
||||
@ -160,7 +160,7 @@ void clearCbbs(Context &ctx) noexcept;
|
||||
ox::Error loadBgTileSheet(
|
||||
Context &ctx,
|
||||
unsigned cbb,
|
||||
CompactTileSheet const&ts,
|
||||
CompactTileSheet const &ts,
|
||||
size_t dstTileIdx,
|
||||
size_t srcTileIdx,
|
||||
size_t tileCnt) noexcept;
|
||||
@ -176,7 +176,7 @@ ox::Error loadBgTileSheet(
|
||||
ox::Error loadBgTileSheet(
|
||||
Context &ctx,
|
||||
unsigned cbb,
|
||||
ox::FileAddress const&tsAddr,
|
||||
ox::FileAddress const &tsAddr,
|
||||
size_t dstTileIdx,
|
||||
size_t srcTileIdx,
|
||||
size_t tileCnt) noexcept;
|
||||
@ -184,24 +184,24 @@ ox::Error loadBgTileSheet(
|
||||
ox::Error loadBgTileSheet(
|
||||
Context &ctx,
|
||||
unsigned cbb,
|
||||
CompactTileSheet const&ts,
|
||||
ox::Optional<unsigned> const&paletteBank = {}) noexcept;
|
||||
CompactTileSheet const &ts,
|
||||
ox::Optional<unsigned> const &paletteBank = {}) noexcept;
|
||||
|
||||
ox::Error loadBgTileSheet(
|
||||
Context &ctx,
|
||||
unsigned cbb,
|
||||
ox::StringViewCR tilesheetPath,
|
||||
ox::Optional<unsigned> const&paletteBank) noexcept;
|
||||
ox::Optional<unsigned> const &paletteBank) noexcept;
|
||||
|
||||
ox::Error loadBgTileSheet(
|
||||
Context &ctx,
|
||||
unsigned cbb,
|
||||
ox::FileAddress const&tilesheetAddr,
|
||||
ox::Optional<unsigned> const&paletteBank = {}) noexcept;
|
||||
ox::FileAddress const &tilesheetAddr,
|
||||
ox::Optional<unsigned> const &paletteBank = {}) noexcept;
|
||||
|
||||
ox::Error loadSpriteTileSheet(
|
||||
Context &ctx,
|
||||
CompactTileSheet const&ts,
|
||||
CompactTileSheet const &ts,
|
||||
bool loadDefaultPalette) noexcept;
|
||||
|
||||
ox::Error loadSpriteTileSheet(
|
||||
@ -211,16 +211,16 @@ ox::Error loadSpriteTileSheet(
|
||||
|
||||
ox::Error loadSpriteTileSheet(
|
||||
Context &ctx,
|
||||
ox::FileAddress const&tilesheetAddr,
|
||||
ox::FileAddress const &tilesheetAddr,
|
||||
bool loadDefaultPalette = false) noexcept;
|
||||
|
||||
ox::Error loadSpriteTileSheet(
|
||||
Context &ctx,
|
||||
TileSheetSet const&set) noexcept;
|
||||
TileSheetSet const &set) noexcept;
|
||||
|
||||
void setBgTile(Context &ctx, uint_t bgIdx, int column, int row, unsigned tile, unsigned palBank = 0) noexcept;
|
||||
|
||||
void setBgTile(Context &ctx, uint_t bgIdx, int column, int row, BgTile const&tile) noexcept;
|
||||
void setBgTile(Context &ctx, uint_t bgIdx, int column, int row, BgTile const &tile) noexcept;
|
||||
|
||||
void clearBg(Context &ctx, uint_t bgIdx) noexcept;
|
||||
|
||||
@ -242,7 +242,7 @@ void hideSprite(Context &ctx, unsigned) noexcept;
|
||||
|
||||
void showSprite(Context &ctx, unsigned) noexcept;
|
||||
|
||||
void setSprite(Context &ctx, uint_t idx, Sprite const&sprite) noexcept;
|
||||
void setSprite(Context &ctx, uint_t idx, Sprite const &sprite) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
uint_t spriteCount(Context const &ctx) noexcept;
|
||||
@ -260,7 +260,7 @@ constexpr ox::CStringView GlslVersion = "#version 330";
|
||||
[[nodiscard]]
|
||||
ox::Size drawSize(int scale = 5) noexcept;
|
||||
|
||||
void draw(gfx::Context &ctx, ox::Size const&renderSz) noexcept;
|
||||
void draw(gfx::Context &ctx, ox::Size const &renderSz) noexcept;
|
||||
|
||||
void draw(gfx::Context&, int scale = 5) noexcept;
|
||||
|
||||
|
@ -12,15 +12,15 @@ namespace nostalgia::gfx {
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr std::size_t ptToIdx(int x, int y, int c, int scale = 1) noexcept {
|
||||
const auto tileWidth = TileWidth * scale;
|
||||
const auto tileHeight = TileHeight * scale;
|
||||
const auto pixelsPerTile = tileWidth * tileHeight;
|
||||
const auto colLength = static_cast<std::size_t>(pixelsPerTile);
|
||||
const auto rowLength = static_cast<std::size_t>(static_cast<std::size_t>(c / tileWidth) * colLength);
|
||||
const auto colStart = static_cast<std::size_t>(colLength * static_cast<std::size_t>(x / tileWidth));
|
||||
const auto rowStart = static_cast<std::size_t>(rowLength * static_cast<std::size_t>(y / tileHeight));
|
||||
const auto colOffset = static_cast<std::size_t>(x % tileWidth);
|
||||
const auto rowOffset = static_cast<std::size_t>((y % tileHeight) * tileHeight);
|
||||
auto const tileWidth = TileWidth * scale;
|
||||
auto const tileHeight = TileHeight * scale;
|
||||
auto const pixelsPerTile = tileWidth * tileHeight;
|
||||
auto const colLength = static_cast<std::size_t>(pixelsPerTile);
|
||||
auto const rowLength = static_cast<std::size_t>(static_cast<std::size_t>(c / tileWidth) * colLength);
|
||||
auto const colStart = static_cast<std::size_t>(colLength * static_cast<std::size_t>(x / tileWidth));
|
||||
auto const rowStart = static_cast<std::size_t>(rowLength * static_cast<std::size_t>(y / tileHeight));
|
||||
auto const colOffset = static_cast<std::size_t>(x % tileWidth);
|
||||
auto const rowOffset = static_cast<std::size_t>((y % tileHeight) * tileHeight);
|
||||
return static_cast<std::size_t>(colStart + colOffset + rowStart + rowOffset);
|
||||
}
|
||||
|
||||
@ -31,19 +31,19 @@ constexpr std::size_t ptToIdx(const ox::Point &pt, int c, int scale = 1) noexcep
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::Point idxToPt(int i, int c, int scale = 1) noexcept {
|
||||
const auto tileWidth = TileWidth * scale;
|
||||
const auto tileHeight = TileHeight * scale;
|
||||
const auto pixelsPerTile = tileWidth * tileHeight;
|
||||
auto const tileWidth = TileWidth * scale;
|
||||
auto const tileHeight = TileHeight * scale;
|
||||
auto const pixelsPerTile = tileWidth * tileHeight;
|
||||
// prevent divide by zeros
|
||||
if (!c) {
|
||||
++c;
|
||||
}
|
||||
const auto t = i / pixelsPerTile; // tile number
|
||||
const auto iti = i % pixelsPerTile; // in tile index
|
||||
const auto tc = t % c; // tile column
|
||||
const auto tr = t / c; // tile row
|
||||
const auto itx = iti % tileWidth; // in tile x
|
||||
const auto ity = iti / tileHeight; // in tile y
|
||||
auto const t = i / pixelsPerTile; // tile number
|
||||
auto const iti = i % pixelsPerTile; // in tile index
|
||||
auto const tc = t % c; // tile column
|
||||
auto const tr = t / c; // tile row
|
||||
auto const itx = iti % tileWidth; // in tile x
|
||||
auto const ity = iti / tileHeight; // in tile y
|
||||
return {
|
||||
itx + tc * tileWidth,
|
||||
ity + tr * tileHeight,
|
||||
|
@ -246,7 +246,11 @@ ox::Error loadSpriteTileSheet(
|
||||
}
|
||||
|
||||
void setBgTile(
|
||||
Context &ctx, uint_t const bgIdx, int const column, int const row, BgTile const &tile) noexcept {
|
||||
Context &ctx,
|
||||
uint_t const bgIdx,
|
||||
int const column,
|
||||
int const row,
|
||||
BgTile const &tile) noexcept {
|
||||
auto const tileIdx = static_cast<std::size_t>(row * tileColumns(ctx) + column);
|
||||
// see Tonc 9.3
|
||||
MEM_BG_MAP[bgIdx][tileIdx] =
|
||||
@ -286,7 +290,7 @@ void setBgBpp(Context&, unsigned const bgIdx, unsigned const bpp) noexcept {
|
||||
|
||||
void setBgCbb(Context &ctx, unsigned const bgIdx, unsigned const cbbIdx) noexcept {
|
||||
auto &bgCtl = regBgCtl(bgIdx);
|
||||
const auto &cbbData = ctx.cbbData[cbbIdx];
|
||||
auto const &cbbData = ctx.cbbData[cbbIdx];
|
||||
teagba::bgSetBpp(bgCtl, cbbData.bpp);
|
||||
teagba::bgSetCbb(bgCtl, cbbIdx);
|
||||
}
|
||||
@ -341,13 +345,13 @@ uint_t spriteCount(Context const &) noexcept {
|
||||
|
||||
namespace ox {
|
||||
|
||||
void panic(const char *file, int line, const char *panicMsg, ox::Error const &err) noexcept {
|
||||
void panic(char const *file, int line, char const *panicMsg, ox::Error const &err) noexcept {
|
||||
using namespace nostalgia::gfx;
|
||||
// reset heap to make sure we have enough memory to allocate context data
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
const auto heapBegin = reinterpret_cast<char*>(MEM_EWRAM_BEGIN);
|
||||
const auto heapSz = (MEM_EWRAM_END - MEM_EWRAM_BEGIN) / 2;
|
||||
const auto heapEnd = reinterpret_cast<char*>(MEM_EWRAM_BEGIN + heapSz);
|
||||
auto const heapBegin = reinterpret_cast<char*>(MEM_EWRAM_BEGIN);
|
||||
auto const heapSz = (MEM_EWRAM_END - MEM_EWRAM_BEGIN) / 2;
|
||||
auto const heapEnd = reinterpret_cast<char*>(MEM_EWRAM_BEGIN + heapSz);
|
||||
ox::heapmgr::initHeap(heapBegin, heapEnd);
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
auto tctx = turbine::init(keel::loadRomFs("").unwrap(), "Nostalgia").unwrap();
|
||||
|
@ -287,7 +287,7 @@ static void initSpriteBufferObjects(Context const &ctx, glutils::BufferSet &bs)
|
||||
static void initBackgroundBufferObjects(glutils::BufferSet &bs) noexcept {
|
||||
for (auto x = 0u; x < TileColumns; ++x) {
|
||||
for (auto y = 0u; y < TileRows; ++y) {
|
||||
const auto i = bgVertexRow(x, y);
|
||||
auto const i = bgVertexRow(x, y);
|
||||
auto const vbo = ox::Span{bs.vertices}
|
||||
+ i * static_cast<std::size_t>(BgVertexVboLength);
|
||||
auto const ebo = ox::Span{bs.elements}
|
||||
@ -387,7 +387,7 @@ static void initBackgroundBufferset(
|
||||
static glutils::GLTexture createTexture(
|
||||
GLsizei const w,
|
||||
GLsizei const h,
|
||||
void const*pixels) noexcept {
|
||||
void const *pixels) noexcept {
|
||||
GLuint texId = 0;
|
||||
glGenTextures(1, &texId);
|
||||
glutils::GLTexture tex(texId);
|
||||
@ -425,22 +425,22 @@ static void drawBackground(CBB &cbb) noexcept {
|
||||
|
||||
static void drawBackgrounds(
|
||||
Context &ctx,
|
||||
ox::Size const&renderSz) noexcept {
|
||||
ox::Size const &renderSz) noexcept {
|
||||
// load background shader and its uniforms
|
||||
glUseProgram(ctx.bgShader);
|
||||
const auto uniformSrcImgSz = glGetUniformLocation(ctx.bgShader, "fSrcImgSz");
|
||||
const auto uniformXScale = static_cast<GLint>(glGetUniformLocation(ctx.bgShader, "vXScale"));
|
||||
const auto uniformTileHeight = static_cast<GLint>(glGetUniformLocation(ctx.bgShader, "vTileHeight"));
|
||||
const auto uniformBgIdx = static_cast<GLint>(glGetUniformLocation(ctx.bgShader, "vBgIdx"));
|
||||
const auto [wi, hi] = renderSz;
|
||||
const auto wf = static_cast<float>(wi);
|
||||
const auto hf = static_cast<float>(hi);
|
||||
auto const uniformSrcImgSz = glGetUniformLocation(ctx.bgShader, "fSrcImgSz");
|
||||
auto const uniformXScale = static_cast<GLint>(glGetUniformLocation(ctx.bgShader, "vXScale"));
|
||||
auto const uniformTileHeight = static_cast<GLint>(glGetUniformLocation(ctx.bgShader, "vTileHeight"));
|
||||
auto const uniformBgIdx = static_cast<GLint>(glGetUniformLocation(ctx.bgShader, "vBgIdx"));
|
||||
auto const [wi, hi] = renderSz;
|
||||
auto const wf = static_cast<float>(wi);
|
||||
auto const hf = static_cast<float>(hi);
|
||||
glUniform1f(uniformXScale, hf / wf);
|
||||
auto bgIdx = 0.f;
|
||||
for (const auto &bg : ctx.backgrounds) {
|
||||
for (auto const &bg : ctx.backgrounds) {
|
||||
if (bg.enabled) {
|
||||
auto &cbb = ctx.cbbs[bg.cbbIdx];
|
||||
const auto tileRows = cbb.tex.height / (TileHeight * Scale);
|
||||
auto const tileRows = cbb.tex.height / (TileHeight * Scale);
|
||||
glUniform1f(uniformTileHeight, 1.0f / static_cast<float>(tileRows));
|
||||
glUniform2f(
|
||||
uniformSrcImgSz,
|
||||
@ -456,11 +456,11 @@ static void drawBackgrounds(
|
||||
static void drawSprites(Context &ctx, ox::Size const&renderSz) noexcept {
|
||||
glUseProgram(ctx.spriteShader);
|
||||
auto &sb = ctx.spriteBlocks;
|
||||
const auto uniformXScale = glGetUniformLocation(ctx.bgShader, "vXScale");
|
||||
const auto uniformTileHeight = glGetUniformLocation(ctx.spriteShader, "vTileHeight");
|
||||
const auto [wi, hi] = renderSz;
|
||||
const auto wf = static_cast<float>(wi);
|
||||
const auto hf = static_cast<float>(hi);
|
||||
auto const uniformXScale = glGetUniformLocation(ctx.bgShader, "vXScale");
|
||||
auto const uniformTileHeight = glGetUniformLocation(ctx.spriteShader, "vTileHeight");
|
||||
auto const [wi, hi] = renderSz;
|
||||
auto const wf = static_cast<float>(wi);
|
||||
auto const hf = static_cast<float>(hi);
|
||||
glUniform1f(uniformXScale, hf / wf);
|
||||
// update vbo
|
||||
glBindVertexArray(sb.vao);
|
||||
@ -469,7 +469,7 @@ static void drawSprites(Context &ctx, ox::Size const&renderSz) noexcept {
|
||||
glutils::sendVbo(sb);
|
||||
}
|
||||
// set vTileHeight uniform
|
||||
const auto tileRows = sb.tex.height / (TileHeight * Scale);
|
||||
auto const tileRows = sb.tex.height / (TileHeight * Scale);
|
||||
glUniform1f(uniformTileHeight, 1.0f / static_cast<float>(tileRows));
|
||||
// draw
|
||||
glBindTexture(GL_TEXTURE_2D, sb.tex);
|
||||
@ -493,7 +493,7 @@ static void loadPalette(
|
||||
// make first color transparent
|
||||
palette[palOffset + 3] = 0;
|
||||
glUseProgram(shaderPgrm);
|
||||
const auto uniformPalette = static_cast<GLint>(glGetUniformLocation(shaderPgrm, "fPalette"));
|
||||
auto const uniformPalette = static_cast<GLint>(glGetUniformLocation(shaderPgrm, "fPalette"));
|
||||
glUniform4fv(uniformPalette, ColorCnt, palette.data());
|
||||
}
|
||||
|
||||
@ -526,12 +526,12 @@ static void setSprite(
|
||||
auto const uY = static_cast<int>(s.y + 8) % 255 - 8;
|
||||
oxAssert(1 < ctx.spriteBlocks.vertices.size(), "vbo overflow");
|
||||
oxAssert(1 < ctx.spriteBlocks.elements.size(), "ebo overflow");
|
||||
const auto spriteVboSz = ctx.blocksPerSprite * renderer::SpriteVertexVboLength;
|
||||
const auto spriteEboSz = ctx.blocksPerSprite * renderer::SpriteVertexEboLength;
|
||||
auto const spriteVboSz = ctx.blocksPerSprite * renderer::SpriteVertexVboLength;
|
||||
auto const spriteEboSz = ctx.blocksPerSprite * renderer::SpriteVertexEboLength;
|
||||
auto const vboBase = spriteVboSz * idx;
|
||||
auto const eboBase = spriteEboSz * idx;
|
||||
auto i = 0u;
|
||||
const auto set = [&](int xIt, int yIt, bool enabled) {
|
||||
auto const set = [&](int xIt, int yIt, bool enabled) {
|
||||
auto const fX = static_cast<float>(uX + xIt * 8) / 8;
|
||||
auto const fY = static_cast<float>(uY + yIt * 8) / 8;
|
||||
auto const vboIdx = vboBase + renderer::SpriteVertexVboLength * i;
|
||||
@ -576,10 +576,10 @@ static void setSprite(
|
||||
|
||||
ox::Result<ox::UPtr<Context>> init(turbine::Context &tctx, InitParams const¶ms) noexcept {
|
||||
auto ctx = ox::make_unique<Context>(tctx, params);
|
||||
const auto bgVshad = ox::sfmt(renderer::bgvshadTmpl, gl::GlslVersion);
|
||||
const auto bgFshad = ox::sfmt(renderer::bgfshadTmpl, gl::GlslVersion);
|
||||
const auto spriteVshad = ox::sfmt(renderer::spritevshadTmpl, gl::GlslVersion);
|
||||
const auto spriteFshad = ox::sfmt(renderer::spritefshadTmpl, gl::GlslVersion);
|
||||
auto const bgVshad = ox::sfmt(renderer::bgvshadTmpl, gl::GlslVersion);
|
||||
auto const bgFshad = ox::sfmt(renderer::bgfshadTmpl, gl::GlslVersion);
|
||||
auto const spriteVshad = ox::sfmt(renderer::spritevshadTmpl, gl::GlslVersion);
|
||||
auto const spriteFshad = ox::sfmt(renderer::spritefshadTmpl, gl::GlslVersion);
|
||||
OX_RETURN_ERROR(glutils::buildShaderProgram(bgVshad, bgFshad).moveTo(ctx->bgShader));
|
||||
OX_RETURN_ERROR(
|
||||
glutils::buildShaderProgram(spriteVshad, spriteFshad).moveTo(ctx->spriteShader));
|
||||
@ -603,12 +603,12 @@ struct TileSheetData {
|
||||
}
|
||||
};
|
||||
|
||||
static ox::Result<TileSheetData> normalizeTileSheet(
|
||||
CompactTileSheet const&ts) noexcept {
|
||||
static ox::Result<TileSheetData> normalizeTileSheet
|
||||
(CompactTileSheet const&ts) noexcept {
|
||||
const uint_t bytesPerTile = ts.bpp == 8 ? PixelsPerTile : PixelsPerTile / 2;
|
||||
const auto tiles = ts.pixels.size() / bytesPerTile;
|
||||
auto const tiles = ts.pixels.size() / bytesPerTile;
|
||||
constexpr int width = 8;
|
||||
const int height = 8 * static_cast<int>(tiles);
|
||||
int const height = 8 * static_cast<int>(tiles);
|
||||
ox::Vector<uint32_t> pixels;
|
||||
if (bytesPerTile == 64) { // 8 BPP
|
||||
pixels.resize(ts.pixels.size());
|
||||
@ -779,13 +779,13 @@ void setBgTile(
|
||||
"nostalgia.gfx.setBgTile",
|
||||
"bgIdx: {}, column: {}, row: {}, tile: {}, palBank: {}",
|
||||
bgIdx, column, row, tile.tileIdx, tile.palBank);
|
||||
const auto z = static_cast<uint_t>(bgIdx);
|
||||
const auto y = static_cast<uint_t>(row);
|
||||
const auto x = static_cast<uint_t>(column);
|
||||
const auto i = renderer::bgVertexRow(x, y);
|
||||
auto const z = static_cast<uint_t>(bgIdx);
|
||||
auto const y = static_cast<uint_t>(row);
|
||||
auto const x = static_cast<uint_t>(column);
|
||||
auto const i = renderer::bgVertexRow(x, y);
|
||||
auto &cbb = ctx.cbbs[z];
|
||||
const auto vbo = ox::Span{cbb.vertices} + i * renderer::BgVertexVboLength;
|
||||
const auto ebo = ox::Span{cbb.elements} + i * renderer::BgVertexEboLength;
|
||||
auto const vbo = ox::Span{cbb.vertices} + i * renderer::BgVertexVboLength;
|
||||
auto const ebo = ox::Span{cbb.elements} + i * renderer::BgVertexEboLength;
|
||||
auto &bg = ctx.backgrounds[bgIdx];
|
||||
renderer::setTileBufferObject(
|
||||
static_cast<uint_t>(i * renderer::BgVertexVboRows),
|
||||
|
@ -51,7 +51,7 @@ ox::Error loadSpritePalette(
|
||||
ox::Error loadBgTileSheet(
|
||||
Context &ctx,
|
||||
unsigned const cbb,
|
||||
ox::FileAddress const&tsAddr,
|
||||
ox::FileAddress const &tsAddr,
|
||||
size_t const dstTileIdx,
|
||||
size_t const srcTileIdx,
|
||||
size_t const tileCnt) noexcept {
|
||||
@ -74,7 +74,7 @@ ox::Error loadBgTileSheet(
|
||||
Context &ctx,
|
||||
unsigned const cbb,
|
||||
ox::StringViewCR tilesheetPath,
|
||||
ox::Optional<unsigned> const&paletteBank) noexcept {
|
||||
ox::Optional<unsigned> const &paletteBank) noexcept {
|
||||
OX_REQUIRE(ts, keel::readObj<CompactTileSheet>(keelCtx(ctx), tilesheetPath));
|
||||
return loadBgTileSheet(ctx, cbb, *ts, paletteBank);
|
||||
}
|
||||
@ -82,8 +82,8 @@ ox::Error loadBgTileSheet(
|
||||
ox::Error loadBgTileSheet(
|
||||
Context &ctx,
|
||||
unsigned const cbb,
|
||||
ox::FileAddress const&tilesheetAddr,
|
||||
ox::Optional<unsigned> const&paletteBank) noexcept {
|
||||
ox::FileAddress const &tilesheetAddr,
|
||||
ox::Optional<unsigned> const &paletteBank) noexcept {
|
||||
OX_REQUIRE(ts, keel::readObj<CompactTileSheet>(keelCtx(ctx), tilesheetAddr));
|
||||
return loadBgTileSheet(ctx, cbb, *ts, paletteBank);
|
||||
}
|
||||
@ -98,7 +98,7 @@ ox::Error loadSpriteTileSheet(
|
||||
|
||||
ox::Error loadSpriteTileSheet(
|
||||
Context &ctx,
|
||||
ox::FileAddress const&tilesheetAddr,
|
||||
ox::FileAddress const &tilesheetAddr,
|
||||
bool const loadDefaultPalette) noexcept {
|
||||
OX_REQUIRE(ts, readObj<CompactTileSheet>(keelCtx(ctx), tilesheetAddr));
|
||||
return loadSpriteTileSheet(ctx, *ts, loadDefaultPalette);
|
||||
|
@ -89,7 +89,7 @@ static class: public keel::Module {
|
||||
|
||||
} const mod;
|
||||
|
||||
keel::Module const*keelModule() noexcept {
|
||||
keel::Module const *keelModule() noexcept {
|
||||
return &mod;
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ ox::Error convertPaletteV4ToPaletteV5(
|
||||
for (auto &s : src.pages) {
|
||||
ox::Vector<PaletteColorV2> colors;
|
||||
colors.reserve(s.colors.size());
|
||||
for (auto const&c : s.colors) {
|
||||
for (auto const &c : s.colors) {
|
||||
colors.emplace_back(c.r, c.g, c.b, c.a);
|
||||
}
|
||||
dst.pages.emplace_back(PalettePageV2{
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
#include <keel/typeconv.hpp>
|
||||
|
||||
#include <nostalgia/gfx/context.hpp>
|
||||
#include <nostalgia/gfx/palette.hpp>
|
||||
#include <nostalgia/gfx/tilesheet.hpp>
|
||||
|
||||
|
@ -20,7 +20,7 @@ class PaletteEditorImGui: public studio::Editor {
|
||||
bool m_show = false;
|
||||
public:
|
||||
ox::Signal<ox::Error(ox::StringView name)> inputSubmitted;
|
||||
constexpr void show(ox::StringView const&name) noexcept {
|
||||
constexpr void show(ox::StringView const &name) noexcept {
|
||||
m_show = true;
|
||||
m_name = name;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ static class: public studio::Module {
|
||||
}
|
||||
} const mod;
|
||||
|
||||
const studio::Module *studioModule() noexcept {
|
||||
studio::Module const *studioModule() noexcept {
|
||||
return &mod;
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ int AddSubSheetCommand::commandId() const noexcept {
|
||||
return static_cast<int>(CommandId::AddSubSheet);
|
||||
}
|
||||
|
||||
TileSheet::SubSheetIdx const&AddSubSheetCommand::subsheetIdx() const noexcept {
|
||||
TileSheet::SubSheetIdx const &AddSubSheetCommand::subsheetIdx() const noexcept {
|
||||
return m_parentIdx;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ class AddSubSheetCommand: public TileSheetCommand {
|
||||
int commandId() const noexcept final;
|
||||
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheetIdx const&subsheetIdx() const noexcept override;
|
||||
TileSheet::SubSheetIdx const &subsheetIdx() const noexcept override;
|
||||
|
||||
};
|
||||
|
||||
|
@ -37,7 +37,7 @@ constexpr bool operator==(int i, CommandId c) noexcept {
|
||||
class TileSheetCommand: public studio::UndoCommand {
|
||||
public:
|
||||
[[nodiscard]]
|
||||
virtual TileSheet::SubSheetIdx const&subsheetIdx() const noexcept = 0;
|
||||
virtual TileSheet::SubSheetIdx const &subsheetIdx() const noexcept = 0;
|
||||
};
|
||||
|
||||
}
|
@ -48,7 +48,7 @@ CutPasteCommand::CutPasteCommand(
|
||||
|
||||
ox::Error CutPasteCommand::redo() noexcept {
|
||||
auto &subsheet = getSubSheet(m_img, m_subSheetIdx);
|
||||
for (const auto &c : m_changes) {
|
||||
for (auto const &c : m_changes) {
|
||||
subsheet.pixels[c.idx] = static_cast<uint8_t>(c.newPalIdx);
|
||||
}
|
||||
return {};
|
||||
@ -56,7 +56,7 @@ ox::Error CutPasteCommand::redo() noexcept {
|
||||
|
||||
ox::Error CutPasteCommand::undo() noexcept {
|
||||
auto &subsheet = getSubSheet(m_img, m_subSheetIdx);
|
||||
for (const auto &c : m_changes) {
|
||||
for (auto const &c : m_changes) {
|
||||
subsheet.pixels[c.idx] = static_cast<uint8_t>(c.oldPalIdx);
|
||||
}
|
||||
return {};
|
||||
|
@ -30,10 +30,10 @@ class TileSheetClipboard: public turbine::ClipboardObject<TileSheetClipboard> {
|
||||
ox::Vector<Pixel> m_pixels;
|
||||
|
||||
public:
|
||||
void addPixel(ox::Point const&pt, uint16_t colorIdx) noexcept;
|
||||
void addPixel(ox::Point const &pt, uint16_t colorIdx) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
ox::Vector<Pixel> const&pixels() const noexcept;
|
||||
ox::Vector<Pixel> const &pixels() const noexcept;
|
||||
};
|
||||
|
||||
OX_MODEL_BEGIN(TileSheetClipboard::Pixel)
|
||||
@ -67,9 +67,9 @@ class CutPasteCommand: public TileSheetCommand {
|
||||
CommandId commandId,
|
||||
TileSheet &img,
|
||||
TileSheet::SubSheetIdx subSheetIdx,
|
||||
ox::Point const&dstStart,
|
||||
ox::Point const &dstStart,
|
||||
ox::Point dstEnd,
|
||||
TileSheetClipboard const&cb);
|
||||
TileSheetClipboard const &cb);
|
||||
|
||||
ox::Error redo() noexcept final;
|
||||
|
||||
@ -79,7 +79,7 @@ class CutPasteCommand: public TileSheetCommand {
|
||||
int commandId() const noexcept final;
|
||||
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheetIdx const&subsheetIdx() const noexcept override;
|
||||
TileSheet::SubSheetIdx const &subsheetIdx() const noexcept override;
|
||||
|
||||
};
|
||||
|
||||
|
@ -66,7 +66,7 @@ int DeleteTilesCommand::commandId() const noexcept {
|
||||
return static_cast<int>(CommandId::DeleteTile);
|
||||
}
|
||||
|
||||
TileSheet::SubSheetIdx const&DeleteTilesCommand::subsheetIdx() const noexcept {
|
||||
TileSheet::SubSheetIdx const &DeleteTilesCommand::subsheetIdx() const noexcept {
|
||||
return m_idx;
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ class DeleteTilesCommand: public TileSheetCommand {
|
||||
int commandId() const noexcept final;
|
||||
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheetIdx const&subsheetIdx() const noexcept override;
|
||||
TileSheet::SubSheetIdx const &subsheetIdx() const noexcept override;
|
||||
|
||||
};
|
||||
|
||||
|
@ -74,7 +74,7 @@ DrawCommand::DrawCommand(
|
||||
DrawCommand::DrawCommand(
|
||||
TileSheet &img,
|
||||
TileSheet::SubSheetIdx subSheetIdx,
|
||||
ox::SpanView<std::size_t> const&idxList,
|
||||
ox::SpanView<std::size_t> const &idxList,
|
||||
int const palIdx) noexcept:
|
||||
m_img(img),
|
||||
m_subSheetIdx(std::move(subSheetIdx)),
|
||||
@ -90,7 +90,7 @@ bool DrawCommand::append(std::size_t const idx) noexcept {
|
||||
if (m_changes.back().value->idx != idx && getPixel(subsheet, idx) != m_palIdx) {
|
||||
// duplicate entries are bad
|
||||
auto existing = find_if(
|
||||
m_changes.cbegin(), m_changes.cend(), [idx](auto const&c) {
|
||||
m_changes.cbegin(), m_changes.cend(), [idx](auto const &c) {
|
||||
return c.idx == idx;
|
||||
});
|
||||
if (existing == m_changes.cend()) {
|
||||
@ -102,7 +102,7 @@ bool DrawCommand::append(std::size_t const idx) noexcept {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DrawCommand::append(ox::SpanView<std::size_t> const&idxList) noexcept {
|
||||
bool DrawCommand::append(ox::SpanView<std::size_t> const &idxList) noexcept {
|
||||
auto out = false;
|
||||
for (auto idx : idxList) {
|
||||
out = append(idx) || out;
|
||||
@ -134,7 +134,7 @@ void DrawCommand::lineUpdate(ox::Point a, ox::Point b) noexcept {
|
||||
|
||||
ox::Error DrawCommand::redo() noexcept {
|
||||
auto &subsheet = getSubSheet(m_img, m_subSheetIdx);
|
||||
for (auto const&c : m_changes) {
|
||||
for (auto const &c : m_changes) {
|
||||
subsheet.pixels[c.idx] = static_cast<uint8_t>(m_palIdx);
|
||||
}
|
||||
return {};
|
||||
@ -142,7 +142,7 @@ ox::Error DrawCommand::redo() noexcept {
|
||||
|
||||
ox::Error DrawCommand::undo() noexcept {
|
||||
auto &subsheet = getSubSheet(m_img, m_subSheetIdx);
|
||||
for (auto const&c : m_changes) {
|
||||
for (auto const &c : m_changes) {
|
||||
subsheet.pixels[c.idx] = static_cast<uint8_t>(c.oldPalIdx);
|
||||
}
|
||||
return {};
|
||||
@ -152,7 +152,7 @@ int DrawCommand::commandId() const noexcept {
|
||||
return static_cast<int>(CommandId::Draw);
|
||||
}
|
||||
|
||||
TileSheet::SubSheetIdx const&DrawCommand::subsheetIdx() const noexcept {
|
||||
TileSheet::SubSheetIdx const &DrawCommand::subsheetIdx() const noexcept {
|
||||
return m_subSheetIdx;
|
||||
}
|
||||
|
||||
|
@ -33,12 +33,12 @@ class DrawCommand: public TileSheetCommand {
|
||||
DrawCommand(
|
||||
TileSheet &img,
|
||||
TileSheet::SubSheetIdx subSheetIdx,
|
||||
ox::SpanView<std::size_t> const&idxList,
|
||||
ox::SpanView<std::size_t> const &idxList,
|
||||
int palIdx) noexcept;
|
||||
|
||||
bool append(std::size_t idx) noexcept;
|
||||
|
||||
bool append(ox::SpanView<std::size_t> const&idxList) noexcept;
|
||||
bool append(ox::SpanView<std::size_t> const &idxList) noexcept;
|
||||
|
||||
void lineUpdate(ox::Point a, ox::Point b) noexcept;
|
||||
|
||||
@ -50,7 +50,7 @@ class DrawCommand: public TileSheetCommand {
|
||||
int commandId() const noexcept final;
|
||||
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheetIdx const&subsheetIdx() const noexcept override;
|
||||
TileSheet::SubSheetIdx const &subsheetIdx() const noexcept override;
|
||||
|
||||
void finish() noexcept;
|
||||
|
||||
|
@ -30,7 +30,7 @@ class FlipXCommand: public TileSheetCommand {
|
||||
int commandId() const noexcept final;
|
||||
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheetIdx const&subsheetIdx() const noexcept override;
|
||||
TileSheet::SubSheetIdx const &subsheetIdx() const noexcept override;
|
||||
|
||||
};
|
||||
|
||||
@ -56,7 +56,7 @@ class FlipYCommand: public TileSheetCommand {
|
||||
int commandId() const noexcept final;
|
||||
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheetIdx const&subsheetIdx() const noexcept override;
|
||||
TileSheet::SubSheetIdx const &subsheetIdx() const noexcept override;
|
||||
|
||||
};
|
||||
|
||||
|
@ -62,7 +62,7 @@ int InsertTilesCommand::commandId() const noexcept {
|
||||
return static_cast<int>(CommandId::InsertTile);
|
||||
}
|
||||
|
||||
TileSheet::SubSheetIdx const&InsertTilesCommand::subsheetIdx() const noexcept {
|
||||
TileSheet::SubSheetIdx const &InsertTilesCommand::subsheetIdx() const noexcept {
|
||||
return m_idx;
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ class InsertTilesCommand: public TileSheetCommand {
|
||||
int commandId() const noexcept final;
|
||||
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheetIdx const&subsheetIdx() const noexcept override;
|
||||
TileSheet::SubSheetIdx const &subsheetIdx() const noexcept override;
|
||||
|
||||
};
|
||||
|
||||
|
@ -33,7 +33,7 @@ int MoveSubSheetCommand::commandId() const noexcept {
|
||||
return static_cast<int>(CommandId::MoveSubSheet);
|
||||
}
|
||||
|
||||
TileSheet::SubSheetIdx const&MoveSubSheetCommand::subsheetIdx() const noexcept {
|
||||
TileSheet::SubSheetIdx const &MoveSubSheetCommand::subsheetIdx() const noexcept {
|
||||
return *m_active;
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ class MoveSubSheetCommand: public TileSheetCommand {
|
||||
int commandId() const noexcept final;
|
||||
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheetIdx const&subsheetIdx() const noexcept override;
|
||||
TileSheet::SubSheetIdx const &subsheetIdx() const noexcept override;
|
||||
|
||||
};
|
||||
|
||||
|
@ -30,7 +30,7 @@ int PaletteChangeCommand::commandId() const noexcept {
|
||||
return static_cast<int>(CommandId::PaletteChange);
|
||||
}
|
||||
|
||||
TileSheet::SubSheetIdx const&PaletteChangeCommand::subsheetIdx() const noexcept {
|
||||
TileSheet::SubSheetIdx const &PaletteChangeCommand::subsheetIdx() const noexcept {
|
||||
return m_idx;
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ class PaletteChangeCommand: public TileSheetCommand {
|
||||
int commandId() const noexcept final;
|
||||
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheetIdx const&subsheetIdx() const noexcept override;
|
||||
TileSheet::SubSheetIdx const &subsheetIdx() const noexcept override;
|
||||
|
||||
};
|
||||
|
||||
|
@ -31,7 +31,7 @@ int RmSubSheetCommand::commandId() const noexcept {
|
||||
return static_cast<int>(CommandId::RmSubSheet);
|
||||
}
|
||||
|
||||
TileSheet::SubSheetIdx const&RmSubSheetCommand::subsheetIdx() const noexcept {
|
||||
TileSheet::SubSheetIdx const &RmSubSheetCommand::subsheetIdx() const noexcept {
|
||||
return m_idx;
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ class RmSubSheetCommand: public TileSheetCommand {
|
||||
int commandId() const noexcept final;
|
||||
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheetIdx const&subsheetIdx() const noexcept override;
|
||||
TileSheet::SubSheetIdx const &subsheetIdx() const noexcept override;
|
||||
|
||||
};
|
||||
|
||||
|
@ -119,7 +119,7 @@ int RotateCommand::commandId() const noexcept {
|
||||
return static_cast<int>(CommandId::Rotate);
|
||||
}
|
||||
|
||||
TileSheet::SubSheetIdx const&RotateCommand::subsheetIdx() const noexcept {
|
||||
TileSheet::SubSheetIdx const &RotateCommand::subsheetIdx() const noexcept {
|
||||
return m_idx;
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ class RotateCommand: public TileSheetCommand {
|
||||
int commandId() const noexcept final;
|
||||
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheetIdx const&subsheetIdx() const noexcept override;
|
||||
TileSheet::SubSheetIdx const &subsheetIdx() const noexcept override;
|
||||
|
||||
};
|
||||
|
||||
|
@ -33,7 +33,7 @@ int UpdateSubSheetCommand::commandId() const noexcept {
|
||||
return static_cast<int>(CommandId::UpdateSubSheet);
|
||||
}
|
||||
|
||||
TileSheet::SubSheetIdx const&UpdateSubSheetCommand::subsheetIdx() const noexcept {
|
||||
TileSheet::SubSheetIdx const &UpdateSubSheetCommand::subsheetIdx() const noexcept {
|
||||
return m_idx;
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ class UpdateSubSheetCommand: public TileSheetCommand {
|
||||
int commandId() const noexcept final;
|
||||
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheetIdx const&subsheetIdx() const noexcept override;
|
||||
TileSheet::SubSheetIdx const &subsheetIdx() const noexcept override;
|
||||
|
||||
};
|
||||
|
||||
|
@ -66,7 +66,7 @@ void TileSheetEditorModel::cut() {
|
||||
}
|
||||
TileSheetClipboard blankCb;
|
||||
auto cb = ox::make_unique<TileSheetClipboard>();
|
||||
auto const&s = activeSubSheet();
|
||||
auto const &s = activeSubSheet();
|
||||
if (iterateSelectionRows(*m_selection, [&](int const x, int const y) {
|
||||
auto pt = ox::Point{x, y};
|
||||
auto const idx = gfx::idx(s, pt);
|
||||
@ -97,7 +97,7 @@ void TileSheetEditorModel::copy() {
|
||||
auto cb = ox::make_unique<TileSheetClipboard>();
|
||||
if (iterateSelectionRows(*m_selection, [&](int const x, int const y) {
|
||||
auto pt = ox::Point{x, y};
|
||||
auto const&s = activeSubSheet();
|
||||
auto const &s = activeSubSheet();
|
||||
auto const idx = gfx::idx(s, pt);
|
||||
if (idx >= s.pixels.size()) {
|
||||
return ox::Error{1, "invalid idx"};
|
||||
@ -122,7 +122,7 @@ void TileSheetEditorModel::paste() {
|
||||
oxErrf("Could not read clipboard: {}", toStr(err));
|
||||
return;
|
||||
}
|
||||
auto const&s = activeSubSheet();
|
||||
auto const &s = activeSubSheet();
|
||||
auto const pt1 = m_selection->a;
|
||||
auto const pt2 = ox::Point{s.columns * TileWidth, s.rows * TileHeight};
|
||||
if (auto cmd = ox::make_unique_catch<CutPasteCommand>(
|
||||
@ -235,7 +235,7 @@ void TileSheetEditorModel::setActiveSubsheet(TileSheet::SubSheetIdx const &idx)
|
||||
}
|
||||
|
||||
void TileSheetEditorModel::fill(ox::Point const &pt, uint8_t const palIdx) noexcept {
|
||||
auto const&activeSubSheet = getSubSheet(m_img, m_activeSubsSheetIdx);
|
||||
auto const &activeSubSheet = getSubSheet(m_img, m_activeSubsSheetIdx);
|
||||
// build idx list
|
||||
if (pt.x >= activeSubSheet.columns * TileWidth || pt.y >= activeSubSheet.rows * TileHeight) {
|
||||
return;
|
||||
@ -303,7 +303,7 @@ void TileSheetEditorModel::completeSelection() noexcept {
|
||||
m_selTracker.finishSelection();
|
||||
m_selection.emplace(m_selTracker.selection());
|
||||
auto&pt = m_selection->b;
|
||||
auto const&s = activeSubSheet();
|
||||
auto const &s = activeSubSheet();
|
||||
pt.x = ox::min(s.columns * TileWidth - 1, pt.x);
|
||||
pt.y = ox::min(s.rows * TileHeight - 1, pt.y);
|
||||
}
|
||||
@ -356,7 +356,7 @@ ox::Error TileSheetEditorModel::saveFile() noexcept {
|
||||
}
|
||||
|
||||
bool TileSheetEditorModel::pixelSelected(std::size_t const idx) const noexcept {
|
||||
auto const&s = activeSubSheet();
|
||||
auto const &s = activeSubSheet();
|
||||
auto const pt = idxToPt(static_cast<int>(idx), s.columns);
|
||||
return m_selection && m_selection->contains(pt);
|
||||
}
|
||||
@ -398,7 +398,7 @@ ox::Error TileSheetEditorModel::moveSubSheet(TileSheet::SubSheetIdx src, TileShe
|
||||
}
|
||||
|
||||
void TileSheetEditorModel::getFillPixels(
|
||||
TileSheet::SubSheet const&activeSubSheet,
|
||||
TileSheet::SubSheet const &activeSubSheet,
|
||||
ox::Span<bool> const pixels,
|
||||
ox::Point const &pt,
|
||||
uint8_t const oldColor) noexcept {
|
||||
@ -448,7 +448,7 @@ ox::Error TileSheetEditorModel::pushCommand(ox::UPtr<studio::UndoCommand> &&cmd)
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error TileSheetEditorModel::handleFileRename(ox::StringViewCR, ox::StringViewCR newPath, ox::UUID const&id) noexcept {
|
||||
ox::Error TileSheetEditorModel::handleFileRename(ox::StringViewCR, ox::StringViewCR newPath, ox::UUID const &id) noexcept {
|
||||
if ((beginsWith(m_img.defaultPalette, "uuid://") &&
|
||||
substr(m_img.defaultPalette, 7) == id.toString()) ||
|
||||
m_img.defaultPalette == newPath) {
|
||||
|
@ -29,8 +29,8 @@ void TileSheetEditorView::draw() noexcept {
|
||||
m_pixelGridDrawer.draw(updated(), m_scrollOffset);
|
||||
}
|
||||
|
||||
void TileSheetEditorView::scrollV(ox::Vec2 const&paneSz, float wheel, bool zoomMod) noexcept {
|
||||
auto const&s = m_model.activeSubSheet();
|
||||
void TileSheetEditorView::scrollV(ox::Vec2 const &paneSz, float wheel, bool zoomMod) noexcept {
|
||||
auto const &s = m_model.activeSubSheet();
|
||||
auto const pixelSize = m_pixelsDrawer.pixelSize(paneSz);
|
||||
ImVec2 const sheetSize(pixelSize.x * static_cast<float>(s.columns) * TileWidth,
|
||||
pixelSize.y * static_cast<float>(s.rows) * TileHeight);
|
||||
@ -47,8 +47,8 @@ void TileSheetEditorView::scrollV(ox::Vec2 const&paneSz, float wheel, bool zoomM
|
||||
m_scrollOffset.y = ox::clamp(m_scrollOffset.y, 0.f, sheetSize.y / 2);
|
||||
}
|
||||
|
||||
void TileSheetEditorView::scrollH(ox::Vec2 const&paneSz, float wheelh) noexcept {
|
||||
auto const&s = m_model.activeSubSheet();
|
||||
void TileSheetEditorView::scrollH(ox::Vec2 const &paneSz, float wheelh) noexcept {
|
||||
auto const &s = m_model.activeSubSheet();
|
||||
auto const pixelSize = m_pixelsDrawer.pixelSize(paneSz);
|
||||
ImVec2 const sheetSize(pixelSize.x * static_cast<float>(s.columns) * TileWidth,
|
||||
pixelSize.y * static_cast<float>(s.rows) * TileHeight);
|
||||
@ -56,43 +56,43 @@ void TileSheetEditorView::scrollH(ox::Vec2 const&paneSz, float wheelh) noexcept
|
||||
m_scrollOffset.x = ox::clamp(m_scrollOffset.x, -(sheetSize.x / 2), 0.f);
|
||||
}
|
||||
|
||||
void TileSheetEditorView::insertTile(ox::Vec2 const&paneSize, ox::Vec2 const&clickPos) noexcept {
|
||||
void TileSheetEditorView::insertTile(ox::Vec2 const &paneSize, ox::Vec2 const &clickPos) noexcept {
|
||||
auto pt = clickPoint(paneSize, clickPos);
|
||||
auto const&s = m_model.activeSubSheet();
|
||||
auto const &s = m_model.activeSubSheet();
|
||||
pt.x = ox::min(pt.x, s.columns * TileWidth - 1);
|
||||
pt.y = ox::min(pt.y, s.rows * TileHeight - 1);
|
||||
auto const tileIdx = ptToIdx(pt, s.columns) / PixelsPerTile;
|
||||
m_model.insertTiles(m_model.activeSubSheetIdx(), tileIdx, 1);
|
||||
}
|
||||
|
||||
void TileSheetEditorView::deleteTile(ox::Vec2 const&paneSize, ox::Vec2 const&clickPos) noexcept {
|
||||
void TileSheetEditorView::deleteTile(ox::Vec2 const &paneSize, ox::Vec2 const &clickPos) noexcept {
|
||||
auto const pt = clickPoint(paneSize, clickPos);
|
||||
auto const&s = m_model.activeSubSheet();
|
||||
auto const &s = m_model.activeSubSheet();
|
||||
auto const tileIdx = ptToIdx(pt, s.columns) / PixelsPerTile;
|
||||
m_model.deleteTiles(m_model.activeSubSheetIdx(), tileIdx, 1);
|
||||
}
|
||||
|
||||
void TileSheetEditorView::clickDraw(ox::Vec2 const&paneSize, ox::Vec2 const&clickPos) noexcept {
|
||||
void TileSheetEditorView::clickDraw(ox::Vec2 const &paneSize, ox::Vec2 const &clickPos) noexcept {
|
||||
auto const pt = clickPoint(paneSize, clickPos);
|
||||
m_model.drawCommand(pt, m_palIdx);
|
||||
}
|
||||
|
||||
void TileSheetEditorView::clickLine(ox::Vec2 const&paneSize, ox::Vec2 const&clickPos) noexcept {
|
||||
void TileSheetEditorView::clickLine(ox::Vec2 const &paneSize, ox::Vec2 const &clickPos) noexcept {
|
||||
auto const pt = clickPoint(paneSize, clickPos);
|
||||
m_model.drawLineCommand(pt, m_palIdx);
|
||||
}
|
||||
|
||||
void TileSheetEditorView::clickSelect(ox::Vec2 const&paneSize, ox::Vec2 const&clickPos) noexcept {
|
||||
void TileSheetEditorView::clickSelect(ox::Vec2 const &paneSize, ox::Vec2 const &clickPos) noexcept {
|
||||
auto const pt = clickPoint(paneSize, clickPos);
|
||||
m_model.select(pt);
|
||||
}
|
||||
|
||||
void TileSheetEditorView::clickFill(ox::Vec2 const&paneSize, ox::Vec2 const&clickPos) noexcept {
|
||||
void TileSheetEditorView::clickFill(ox::Vec2 const &paneSize, ox::Vec2 const &clickPos) noexcept {
|
||||
auto const pt = clickPoint(paneSize, clickPos);
|
||||
m_model.fill(pt, static_cast<uint8_t>(m_palIdx));
|
||||
}
|
||||
|
||||
void TileSheetEditorView::releaseMouseButton(TileSheetTool tool) noexcept {
|
||||
void TileSheetEditorView::releaseMouseButton(TileSheetTool const tool) noexcept {
|
||||
switch (tool) {
|
||||
case TileSheetTool::Draw:
|
||||
case TileSheetTool::Fill:
|
||||
@ -107,7 +107,7 @@ void TileSheetEditorView::releaseMouseButton(TileSheetTool tool) noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
void TileSheetEditorView::resizeView(ox::Vec2 const&sz) noexcept {
|
||||
void TileSheetEditorView::resizeView(ox::Vec2 const &sz) noexcept {
|
||||
m_viewSize = sz;
|
||||
initView();
|
||||
}
|
||||
@ -133,9 +133,9 @@ void TileSheetEditorView::initView() noexcept {
|
||||
m_pixelGridDrawer.initBufferSet(m_viewSize, m_model.activeSubSheet());
|
||||
}
|
||||
|
||||
ox::Point TileSheetEditorView::clickPoint(ox::Vec2 const&paneSize, ox::Vec2 const&clickPos) const noexcept {
|
||||
ox::Point TileSheetEditorView::clickPoint(ox::Vec2 const &paneSize, ox::Vec2 const &clickPos) const noexcept {
|
||||
auto [x, y] = clickPos;
|
||||
const auto pixDrawSz = m_pixelsDrawer.pixelSize(paneSize);
|
||||
auto const pixDrawSz = m_pixelsDrawer.pixelSize(paneSize);
|
||||
x /= paneSize.x;
|
||||
y /= paneSize.y;
|
||||
x += -m_scrollOffset.x / 2;
|
||||
|
@ -62,28 +62,28 @@ class TileSheetEditorView: public ox::SignalHandler {
|
||||
|
||||
void draw() noexcept;
|
||||
|
||||
void insertTile(ox::Vec2 const&paneSize, ox::Vec2 const&clickPos) noexcept;
|
||||
void insertTile(ox::Vec2 const &paneSize, ox::Vec2 const &clickPos) noexcept;
|
||||
|
||||
void deleteTile(ox::Vec2 const&paneSize, ox::Vec2 const&clickPos) noexcept;
|
||||
void deleteTile(ox::Vec2 const &paneSize, ox::Vec2 const &clickPos) noexcept;
|
||||
|
||||
void clickDraw(ox::Vec2 const&paneSize, ox::Vec2 const&clickPos) noexcept;
|
||||
void clickDraw(ox::Vec2 const &paneSize, ox::Vec2 const &clickPos) noexcept;
|
||||
|
||||
void clickLine(ox::Vec2 const&paneSize, ox::Vec2 const&clickPos) noexcept;
|
||||
void clickLine(ox::Vec2 const &paneSize, ox::Vec2 const &clickPos) noexcept;
|
||||
|
||||
void clickSelect(ox::Vec2 const&paneSize, ox::Vec2 const&clickPos) noexcept;
|
||||
void clickSelect(ox::Vec2 const &paneSize, ox::Vec2 const &clickPos) noexcept;
|
||||
|
||||
void clickFill(ox::Vec2 const&paneSize, ox::Vec2 const&clickPos) noexcept;
|
||||
void clickFill(ox::Vec2 const &paneSize, ox::Vec2 const &clickPos) noexcept;
|
||||
|
||||
void releaseMouseButton(TileSheetTool tool) noexcept;
|
||||
|
||||
void scrollV(ox::Vec2 const&paneSz, float wheel, bool zoomMod) noexcept;
|
||||
void scrollV(ox::Vec2 const &paneSz, float wheel, bool zoomMod) noexcept;
|
||||
|
||||
void scrollH(ox::Vec2 const&paneSz, float wheel) noexcept;
|
||||
void scrollH(ox::Vec2 const &paneSz, float wheel) noexcept;
|
||||
|
||||
void resizeView(ox::Vec2 const&sz) noexcept;
|
||||
void resizeView(ox::Vec2 const &sz) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr TileSheet const&img() const noexcept;
|
||||
constexpr TileSheet const &img() const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr TileSheet &img() noexcept;
|
||||
@ -117,13 +117,13 @@ class TileSheetEditorView: public ox::SignalHandler {
|
||||
private:
|
||||
void initView() noexcept;
|
||||
|
||||
ox::Point clickPoint(ox::Vec2 const&paneSize, ox::Vec2 const&clickPos) const noexcept;
|
||||
ox::Point clickPoint(ox::Vec2 const &paneSize, ox::Vec2 const &clickPos) const noexcept;
|
||||
|
||||
ox::Error setActiveSubsheet(TileSheet::SubSheetIdx const&idx) noexcept;
|
||||
ox::Error setActiveSubsheet(TileSheet::SubSheetIdx const &idx) noexcept;
|
||||
|
||||
};
|
||||
|
||||
constexpr TileSheet const&TileSheetEditorView::img() const noexcept {
|
||||
constexpr TileSheet const &TileSheetEditorView::img() const noexcept {
|
||||
return m_model.img();
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ ox::Error TileSheetGrid::buildShader() noexcept {
|
||||
pixelLineVshad, pixelLineFshad, pixelLineGshad).moveTo(m_shader);
|
||||
}
|
||||
|
||||
void TileSheetGrid::draw(bool const update, ox::Vec2 const&scroll) noexcept {
|
||||
void TileSheetGrid::draw(bool const update, ox::Vec2 const &scroll) noexcept {
|
||||
// the lines just show up bigger on Windows for some reason
|
||||
if constexpr(ox::defines::OS == ox::OS::Windows) {
|
||||
glLineWidth(3 * m_pixelSizeMod * 0.25f);
|
||||
@ -42,7 +42,7 @@ void TileSheetGrid::draw(bool const update, ox::Vec2 const&scroll) noexcept {
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
void TileSheetGrid::initBufferSet(ox::Vec2 const&paneSize, TileSheet::SubSheet const&subsheet) noexcept {
|
||||
void TileSheetGrid::initBufferSet(ox::Vec2 const &paneSize, TileSheet::SubSheet const &subsheet) noexcept {
|
||||
// vao
|
||||
m_bufferSet.vao = glutils::generateVertexArrayObject();
|
||||
glBindVertexArray(m_bufferSet.vao);
|
||||
@ -65,7 +65,7 @@ void TileSheetGrid::initBufferSet(ox::Vec2 const&paneSize, TileSheet::SubSheet c
|
||||
std::bit_cast<void*>(uintptr_t{4 * sizeof(float)}));
|
||||
}
|
||||
|
||||
void TileSheetGrid::update(ox::Vec2 const&paneSize, TileSheet::SubSheet const&subsheet) noexcept {
|
||||
void TileSheetGrid::update(ox::Vec2 const &paneSize, TileSheet::SubSheet const &subsheet) noexcept {
|
||||
glBindVertexArray(m_bufferSet.vao);
|
||||
setBufferObjects(paneSize, subsheet);
|
||||
glutils::sendVbo(m_bufferSet);
|
||||
@ -77,7 +77,7 @@ void TileSheetGrid::setBufferObject(
|
||||
ox::Point const pt2,
|
||||
Color32 const c,
|
||||
ox::Span<float> const vbo,
|
||||
ox::Vec2 const&pixSize) noexcept {
|
||||
ox::Vec2 const &pixSize) noexcept {
|
||||
auto const x1 = static_cast<float>(pt1.x) * pixSize.x - 1.f;
|
||||
auto const y1 = 1.f - static_cast<float>(pt1.y) * pixSize.y;
|
||||
auto const x2 = static_cast<float>(pt2.x) * pixSize.x - 1.f;
|
||||
@ -87,7 +87,7 @@ void TileSheetGrid::setBufferObject(
|
||||
ox::spancpy(vbo, ox::SpanView<float>{vertices});
|
||||
}
|
||||
|
||||
void TileSheetGrid::setBufferObjects(ox::Vec2 const&paneSize, TileSheet::SubSheet const&subsheet) noexcept {
|
||||
void TileSheetGrid::setBufferObjects(ox::Vec2 const &paneSize, TileSheet::SubSheet const &subsheet) noexcept {
|
||||
if (subsheet.columns < 1 || subsheet.rows < 1) {
|
||||
m_bufferSet.elements.clear();
|
||||
m_bufferSet.vertices.clear();
|
||||
@ -129,7 +129,7 @@ void TileSheetGrid::setBufferObjects(ox::Vec2 const&paneSize, TileSheet::SubShee
|
||||
}
|
||||
}
|
||||
|
||||
ox::Vec2 TileSheetGrid::pixelSize(ox::Vec2 const&paneSize) const noexcept {
|
||||
ox::Vec2 TileSheetGrid::pixelSize(ox::Vec2 const &paneSize) const noexcept {
|
||||
auto const [sw, sh] = paneSize;
|
||||
constexpr float ymod = 0.35f / 10.0f;
|
||||
auto const xmod = ymod * sh / sw;
|
||||
|
@ -66,19 +66,20 @@ class TileSheetGrid {
|
||||
|
||||
ox::Error buildShader() noexcept;
|
||||
|
||||
void draw(bool update, ox::Vec2 const&scroll) noexcept;
|
||||
void draw(bool update, ox::Vec2 const &scroll) noexcept;
|
||||
|
||||
void initBufferSet(ox::Vec2 const&paneSize, TileSheet::SubSheet const&subsheet) noexcept;
|
||||
void initBufferSet(ox::Vec2 const &paneSize, TileSheet::SubSheet const &subsheet) noexcept;
|
||||
|
||||
void update(ox::Vec2 const&paneSize, TileSheet::SubSheet const&subsheet) noexcept;
|
||||
void update(ox::Vec2 const &paneSize, TileSheet::SubSheet const &subsheet) noexcept;
|
||||
|
||||
private:
|
||||
static void setBufferObject(ox::Point pt1, ox::Point pt2, Color32 c, ox::Span<float> vbo, ox::Vec2 const&pixSize) noexcept;
|
||||
static void setBufferObject(
|
||||
ox::Point pt1, ox::Point pt2, Color32 c, ox::Span<float> vbo, ox::Vec2 const &pixSize) noexcept;
|
||||
|
||||
void setBufferObjects(ox::Vec2 const&paneSize, TileSheet::SubSheet const&subsheet) noexcept;
|
||||
void setBufferObjects(ox::Vec2 const &paneSize, TileSheet::SubSheet const &subsheet) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
ox::Vec2 pixelSize(ox::Vec2 const&paneSize) const noexcept;
|
||||
ox::Vec2 pixelSize(ox::Vec2 const &paneSize) const noexcept;
|
||||
|
||||
};
|
||||
|
||||
|
@ -49,7 +49,7 @@ ox::Error TileSheetPixels::buildShader() noexcept {
|
||||
return glutils::buildShaderProgram(s_programSrc).moveTo(m_shader);
|
||||
}
|
||||
|
||||
void TileSheetPixels::draw(bool const update, ox::Vec2 const&scroll) noexcept {
|
||||
void TileSheetPixels::draw(bool const update, ox::Vec2 const &scroll) noexcept {
|
||||
glUseProgram(m_shader);
|
||||
glBindVertexArray(m_bufferSet.vao);
|
||||
if (update) {
|
||||
@ -62,7 +62,7 @@ void TileSheetPixels::draw(bool const update, ox::Vec2 const&scroll) noexcept {
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
void TileSheetPixels::initBufferSet(ox::Vec2 const&paneSize) noexcept {
|
||||
void TileSheetPixels::initBufferSet(ox::Vec2 const &paneSize) noexcept {
|
||||
m_bufferSet.vao = glutils::generateVertexArrayObject();
|
||||
m_bufferSet.vbo = glutils::generateBuffer();
|
||||
m_bufferSet.ebo = glutils::generateBuffer();
|
||||
@ -70,14 +70,14 @@ void TileSheetPixels::initBufferSet(ox::Vec2 const&paneSize) noexcept {
|
||||
glutils::setupShaderParams(m_shader, s_programSrc.shaderParams);
|
||||
}
|
||||
|
||||
void TileSheetPixels::update(ox::Vec2 const&paneSize) noexcept {
|
||||
void TileSheetPixels::update(ox::Vec2 const &paneSize) noexcept {
|
||||
glBindVertexArray(m_bufferSet.vao);
|
||||
setBufferObjects(paneSize);
|
||||
glutils::sendVbo(m_bufferSet);
|
||||
glutils::sendEbo(m_bufferSet);
|
||||
}
|
||||
|
||||
ox::Vec2 TileSheetPixels::pixelSize(ox::Vec2 const&paneSize) const noexcept {
|
||||
ox::Vec2 TileSheetPixels::pixelSize(ox::Vec2 const &paneSize) const noexcept {
|
||||
auto const [sw, sh] = paneSize;
|
||||
constexpr float ymod = 0.35f / 10.0f;
|
||||
auto const xmod = ymod * sh / sw;
|
||||
@ -85,7 +85,7 @@ ox::Vec2 TileSheetPixels::pixelSize(ox::Vec2 const&paneSize) const noexcept {
|
||||
}
|
||||
|
||||
void TileSheetPixels::setPixelBufferObject(
|
||||
ox::Vec2 const&paneSize,
|
||||
ox::Vec2 const &paneSize,
|
||||
unsigned const vertexRow,
|
||||
float x, float y,
|
||||
Color16 const color,
|
||||
@ -112,15 +112,15 @@ void TileSheetPixels::setPixelBufferObject(
|
||||
ox::spancpy(ebo, ox::SpanView<GLuint>{elms});
|
||||
}
|
||||
|
||||
void TileSheetPixels::setBufferObjects(ox::Vec2 const&paneSize) noexcept {
|
||||
void TileSheetPixels::setBufferObjects(ox::Vec2 const &paneSize) noexcept {
|
||||
// set buffer lengths
|
||||
auto const&subSheet = m_model.activeSubSheet();
|
||||
auto const &subSheet = m_model.activeSubSheet();
|
||||
if (subSheet.columns < 1 || subSheet.rows < 1) {
|
||||
m_bufferSet.vertices.clear();
|
||||
m_bufferSet.elements.clear();
|
||||
return;
|
||||
}
|
||||
auto const&pal = m_model.pal();
|
||||
auto const &pal = m_model.pal();
|
||||
auto const width = subSheet.columns * TileWidth;
|
||||
auto const height = subSheet.rows * TileHeight;
|
||||
auto const pixels = static_cast<size_t>(width) * static_cast<size_t>(height);
|
||||
|
@ -22,7 +22,7 @@ class TileSheetPixels {
|
||||
float m_pixelSizeMod = 1;
|
||||
glutils::GLProgram m_shader;
|
||||
glutils::BufferSet m_bufferSet;
|
||||
class TileSheetEditorModel const&m_model;
|
||||
class TileSheetEditorModel const &m_model;
|
||||
|
||||
public:
|
||||
explicit TileSheetPixels(class TileSheetEditorModel &model) noexcept;
|
||||
@ -31,18 +31,18 @@ class TileSheetPixels {
|
||||
|
||||
ox::Error buildShader() noexcept;
|
||||
|
||||
void draw(bool update, ox::Vec2 const&scroll) noexcept;
|
||||
void draw(bool update, ox::Vec2 const &scroll) noexcept;
|
||||
|
||||
void initBufferSet(ox::Vec2 const&paneSize) noexcept;
|
||||
void initBufferSet(ox::Vec2 const &paneSize) noexcept;
|
||||
|
||||
void update(ox::Vec2 const&paneSize) noexcept;
|
||||
void update(ox::Vec2 const &paneSize) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
ox::Vec2 pixelSize(ox::Vec2 const&paneSize) const noexcept;
|
||||
ox::Vec2 pixelSize(ox::Vec2 const &paneSize) const noexcept;
|
||||
|
||||
private:
|
||||
void setPixelBufferObject(
|
||||
ox::Vec2 const&paneSize,
|
||||
ox::Vec2 const &paneSize,
|
||||
unsigned vertexRow,
|
||||
float x,
|
||||
float y,
|
||||
@ -50,7 +50,7 @@ class TileSheetPixels {
|
||||
ox::Span<float> vbo,
|
||||
ox::Span<GLuint> ebo) const noexcept;
|
||||
|
||||
void setBufferObjects(ox::Vec2 const&paneSize) noexcept;
|
||||
void setBufferObjects(ox::Vec2 const &paneSize) noexcept;
|
||||
|
||||
};
|
||||
|
||||
|
@ -12,16 +12,16 @@
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
std::size_t idx(TileSheet::SubSheet const&ss, ox::Point const&pt) noexcept {
|
||||
std::size_t idx(TileSheet::SubSheet const &ss, ox::Point const &pt) noexcept {
|
||||
return ptToIdx(pt, ss.columns);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
static TileSheet::SubSheet const *getSubsheet(TileSheet::SubSheet const&ss, SubSheetId const id) noexcept {
|
||||
static TileSheet::SubSheet const *getSubsheet(TileSheet::SubSheet const &ss, SubSheetId const id) noexcept {
|
||||
if (ss.id == id) {
|
||||
return &ss;
|
||||
}
|
||||
for (auto const&child: ss.subsheets) {
|
||||
for (auto const &child: ss.subsheets) {
|
||||
if (auto out = getSubsheet(child, id)) {
|
||||
return out;
|
||||
}
|
||||
@ -30,31 +30,31 @@ static TileSheet::SubSheet const *getSubsheet(TileSheet::SubSheet const&ss, SubS
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
static size_t getTileCnt(TileSheet::SubSheet const&ss) noexcept {
|
||||
static size_t getTileCnt(TileSheet::SubSheet const &ss) noexcept {
|
||||
if (ss.subsheets.empty()) {
|
||||
return ss.pixels.size() / PixelsPerTile;
|
||||
} else {
|
||||
size_t out{};
|
||||
for (auto const&child: ss.subsheets) {
|
||||
for (auto const &child: ss.subsheets) {
|
||||
out += getTileCnt(child);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
size_t getTileCnt(TileSheet const&ts) noexcept {
|
||||
size_t getTileCnt(TileSheet const &ts) noexcept {
|
||||
return getTileCnt(ts.subsheet);
|
||||
}
|
||||
|
||||
TileSheet::SubSheet const *getSubsheet(TileSheet const&ts, SubSheetId const id) noexcept {
|
||||
TileSheet::SubSheet const *getSubsheet(TileSheet const &ts, SubSheetId const id) noexcept {
|
||||
return getSubsheet(ts.subsheet, id);
|
||||
}
|
||||
|
||||
static ox::Optional<size_t> getPixelIdx(
|
||||
TileSheet::SubSheet const&ss,
|
||||
TileSheet::SubSheet const &ss,
|
||||
SubSheetId const id,
|
||||
size_t &idx) noexcept {
|
||||
for (auto const&child: ss.subsheets) {
|
||||
for (auto const &child: ss.subsheets) {
|
||||
if (child.id == id) {
|
||||
return ox::Optional<size_t>(ox::in_place, idx);
|
||||
}
|
||||
@ -66,17 +66,17 @@ static ox::Optional<size_t> getPixelIdx(
|
||||
return ox::Optional<size_t>{};
|
||||
}
|
||||
|
||||
ox::Optional<size_t> getTileIdx(TileSheet const&ts, SubSheetId const id) noexcept {
|
||||
ox::Optional<size_t> getTileIdx(TileSheet const &ts, SubSheetId const id) noexcept {
|
||||
size_t idx{};
|
||||
auto const out = getPixelIdx(ts.subsheet, id, idx);
|
||||
return out ? ox::Optional<size_t>{ox::in_place, *out / PixelsPerTile} : out;
|
||||
}
|
||||
|
||||
uint8_t getPixel(TileSheet::SubSheet const&ss, std::size_t const idx) noexcept {
|
||||
uint8_t getPixel(TileSheet::SubSheet const &ss, std::size_t const idx) noexcept {
|
||||
return ss.pixels[idx];
|
||||
}
|
||||
|
||||
uint8_t getPixel(TileSheet::SubSheet const&ss, ox::Point const&pt) noexcept {
|
||||
uint8_t getPixel(TileSheet::SubSheet const &ss, ox::Point const &pt) noexcept {
|
||||
auto const idx = ptToIdx(pt, ss.columns);
|
||||
return getPixel(ss, idx);
|
||||
}
|
||||
@ -84,14 +84,14 @@ uint8_t getPixel(TileSheet::SubSheet const&ss, ox::Point const&pt) noexcept {
|
||||
static void setPixel(
|
||||
ox::Vector<uint8_t> &pixels,
|
||||
int const columns,
|
||||
ox::Point const&pt,
|
||||
ox::Point const &pt,
|
||||
uint8_t const palIdx) noexcept {
|
||||
const auto idx = ptToIdx(pt, columns);
|
||||
auto const idx = ptToIdx(pt, columns);
|
||||
pixels[idx] = palIdx;
|
||||
}
|
||||
|
||||
void setPixel(TileSheet::SubSheet &ss, ox::Point const&pt, uint8_t const palIdx) noexcept {
|
||||
const auto idx = ptToIdx(pt, ss.columns);
|
||||
void setPixel(TileSheet::SubSheet &ss, ox::Point const &pt, uint8_t const palIdx) noexcept {
|
||||
auto const idx = ptToIdx(pt, ss.columns);
|
||||
ss.pixels[idx] = palIdx;
|
||||
}
|
||||
|
||||
@ -129,11 +129,11 @@ void flipY(TileSheet::SubSheet &ss, ox::Point const &a, ox::Point const &b) noex
|
||||
}
|
||||
}
|
||||
|
||||
unsigned pixelCnt(TileSheet::SubSheet const&ss) noexcept {
|
||||
unsigned pixelCnt(TileSheet::SubSheet const &ss) noexcept {
|
||||
return static_cast<unsigned>(ss.pixels.size());
|
||||
}
|
||||
|
||||
ox::Error resizeSubsheet(TileSheet::SubSheet &ss, ox::Size const&sz) noexcept {
|
||||
ox::Error resizeSubsheet(TileSheet::SubSheet &ss, ox::Size const &sz) noexcept {
|
||||
ox::Vector<uint8_t> out;
|
||||
OX_RETURN_ERROR(setPixelCount(out, static_cast<size_t>(sz.width * sz.height) * PixelsPerTile));
|
||||
auto const w = ox::min<int32_t>(ss.columns, sz.width) * TileWidth;
|
||||
@ -150,12 +150,12 @@ ox::Error resizeSubsheet(TileSheet::SubSheet &ss, ox::Size const&sz) noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Result<ox::StringView> getNameFor(TileSheet::SubSheet const&ss, SubSheetId const pId) noexcept {
|
||||
ox::Result<ox::StringView> getNameFor(TileSheet::SubSheet const &ss, SubSheetId const pId) noexcept {
|
||||
if (ss.id == pId) {
|
||||
return ox::StringView(ss.name);
|
||||
}
|
||||
for (const auto &sub : ss.subsheets) {
|
||||
const auto [name, err] = getNameFor(sub, pId);
|
||||
for (auto const &sub : ss.subsheets) {
|
||||
auto const [name, err] = getNameFor(sub, pId);
|
||||
if (!err) {
|
||||
return name;
|
||||
}
|
||||
@ -167,7 +167,7 @@ ox::Result<ox::StringView> getNameFor(TileSheet::SubSheet const&ss, SubSheetId c
|
||||
TileSheet::SubSheetIdx validateSubSheetIdx(
|
||||
TileSheet::SubSheetIdx &&pIdx,
|
||||
std::size_t const pIdxIt,
|
||||
TileSheet::SubSheet const&pSubsheet) noexcept {
|
||||
TileSheet::SubSheet const &pSubsheet) noexcept {
|
||||
if (pIdxIt >= pIdx.size()) {
|
||||
return std::move(pIdx);
|
||||
}
|
||||
@ -185,7 +185,7 @@ TileSheet::SubSheetIdx validateSubSheetIdx(
|
||||
return validateSubSheetIdx(std::move(pIdx), pIdxIt + 1, pSubsheet.subsheets[currentIdx]);
|
||||
}
|
||||
|
||||
TileSheet::SubSheetIdx validateSubSheetIdx(TileSheet const&ts, TileSheet::SubSheetIdx idx) noexcept {
|
||||
TileSheet::SubSheetIdx validateSubSheetIdx(TileSheet const &ts, TileSheet::SubSheetIdx idx) noexcept {
|
||||
return validateSubSheetIdx(std::move(idx), 0, ts.subsheet);
|
||||
}
|
||||
|
||||
@ -215,14 +215,14 @@ ox::Result<TileSheet::SubSheetIdx> getSubSheetIdx(TileSheet const &ts, SubSheetI
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdangling-reference"
|
||||
#endif
|
||||
static TileSheet::SubSheet const&getSubSheet(
|
||||
static TileSheet::SubSheet const &getSubSheet(
|
||||
ox::SpanView<uint32_t> const &idx,
|
||||
std::size_t const idxIt,
|
||||
TileSheet::SubSheet const &pSubsheet) noexcept {
|
||||
if (idxIt == idx.size()) {
|
||||
return pSubsheet;
|
||||
}
|
||||
const auto currentIdx = idx[idxIt];
|
||||
auto const currentIdx = idx[idxIt];
|
||||
if (pSubsheet.subsheets.size() < currentIdx) {
|
||||
return pSubsheet;
|
||||
}
|
||||
@ -246,7 +246,7 @@ TileSheet::SubSheet &getSubSheet(
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdangling-reference"
|
||||
#endif
|
||||
TileSheet::SubSheet const&getSubSheet(TileSheet const &ts, ox::SpanView<uint32_t> const &idx) noexcept {
|
||||
TileSheet::SubSheet const &getSubSheet(TileSheet const &ts, ox::SpanView<uint32_t> const &idx) noexcept {
|
||||
return gfx::getSubSheet(idx, 0, ts.subsheet);
|
||||
}
|
||||
|
||||
@ -257,7 +257,7 @@ TileSheet::SubSheet &getSubSheet(TileSheet &ts, ox::SpanView<uint32_t> const &id
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
ox::Error addSubSheet(TileSheet &ts, TileSheet::SubSheetIdx const&idx) noexcept {
|
||||
ox::Error addSubSheet(TileSheet &ts, TileSheet::SubSheetIdx const &idx) noexcept {
|
||||
auto &parent = getSubSheet(ts, idx);
|
||||
if (parent.subsheets.size() < 2) {
|
||||
parent.subsheets.emplace_back(++ts.idIt, ox::sfmt("Subsheet {}", parent.subsheets.size()), 1, 1);
|
||||
@ -268,7 +268,7 @@ ox::Error addSubSheet(TileSheet &ts, TileSheet::SubSheetIdx const&idx) noexcept
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error insertSubSheet(TileSheet &ts, ox::SpanView<uint32_t> const&idx, TileSheet::SubSheet ss) noexcept {
|
||||
ox::Error insertSubSheet(TileSheet &ts, ox::SpanView<uint32_t> const &idx, TileSheet::SubSheet ss) noexcept {
|
||||
if (idx.empty()) {
|
||||
return ox::Error{1, "invalid insert idx"};
|
||||
}
|
||||
@ -283,7 +283,7 @@ ox::Error insertSubSheet(TileSheet &ts, ox::SpanView<uint32_t> const&idx, TileSh
|
||||
|
||||
ox::Error rmSubSheet(
|
||||
TileSheet &ts,
|
||||
TileSheet::SubSheetIdx const&idx,
|
||||
TileSheet::SubSheetIdx const &idx,
|
||||
std::size_t const idxIt,
|
||||
TileSheet::SubSheet &pSubsheet) noexcept {
|
||||
if (idxIt == idx.size() - 1) {
|
||||
@ -292,21 +292,21 @@ ox::Error rmSubSheet(
|
||||
return rmSubSheet(ts, idx, idxIt + 1, pSubsheet.subsheets[idx[idxIt]]);
|
||||
}
|
||||
|
||||
ox::Error rmSubSheet(TileSheet &ts, TileSheet::SubSheetIdx const&idx) noexcept {
|
||||
ox::Error rmSubSheet(TileSheet &ts, TileSheet::SubSheetIdx const &idx) noexcept {
|
||||
return rmSubSheet(ts, idx, 0, ts.subsheet);
|
||||
}
|
||||
|
||||
uint8_t getPixel(
|
||||
TileSheet const&ts,
|
||||
ox::Point const&pt,
|
||||
TileSheet::SubSheetIdx const&subsheetIdx) noexcept {
|
||||
TileSheet const &ts,
|
||||
ox::Point const &pt,
|
||||
TileSheet::SubSheetIdx const &subsheetIdx) noexcept {
|
||||
auto &s = getSubSheet(ts, subsheetIdx);
|
||||
auto const idx = ptToIdx(pt, s.columns);
|
||||
return getPixel(s, idx);
|
||||
}
|
||||
|
||||
uint8_t getPixel4Bpp(
|
||||
CompactTileSheet const&ts,
|
||||
CompactTileSheet const &ts,
|
||||
size_t const idx) noexcept {
|
||||
oxAssert(ts.bpp == 4, "TileSheet::getPixel4Bpp: wrong bpp");
|
||||
if (idx & 1) {
|
||||
@ -317,14 +317,14 @@ uint8_t getPixel4Bpp(
|
||||
}
|
||||
|
||||
uint8_t getPixel8Bpp(
|
||||
CompactTileSheet const&ts,
|
||||
CompactTileSheet const &ts,
|
||||
size_t const idx) noexcept {
|
||||
oxAssert(ts.bpp == 8, "TileSheet::getPixel8Bpp: wrong bpp");
|
||||
return ts.pixels[idx];
|
||||
}
|
||||
|
||||
ox::Pair<uint8_t> get2Pixels4Bpp(
|
||||
CompactTileSheet const&ts,
|
||||
CompactTileSheet const &ts,
|
||||
size_t const idx) noexcept {
|
||||
oxAssert(ts.bpp == 4, "TileSheet::getPixel4Bpp: wrong bpp");
|
||||
auto const out = ts.pixels[idx / 2];
|
||||
@ -335,7 +335,7 @@ ox::Pair<uint8_t> get2Pixels4Bpp(
|
||||
}
|
||||
|
||||
ox::Pair<uint8_t> get2Pixels8Bpp(
|
||||
CompactTileSheet const&ts,
|
||||
CompactTileSheet const &ts,
|
||||
size_t const idx) noexcept {
|
||||
oxAssert(ts.bpp == 8, "TileSheet::getPixel8Bpp: wrong bpp");
|
||||
return {
|
||||
@ -345,8 +345,8 @@ ox::Pair<uint8_t> get2Pixels8Bpp(
|
||||
}
|
||||
|
||||
static ox::Result<SubSheetId> getIdFor(
|
||||
TileSheet::SubSheet const&ss,
|
||||
ox::SpanView<ox::StringView> const&pNamePath,
|
||||
TileSheet::SubSheet const &ss,
|
||||
ox::SpanView<ox::StringView> const &pNamePath,
|
||||
std::size_t const pIt = 0) noexcept {
|
||||
for (auto &sub : ss.subsheets) {
|
||||
if (sub.name == pNamePath[pIt]) {
|
||||
@ -359,7 +359,7 @@ static ox::Result<SubSheetId> getIdFor(
|
||||
return ox::Error(1, "SubSheet not found");
|
||||
}
|
||||
|
||||
ox::Result<SubSheetId> getIdFor(TileSheet const&ts, ox::StringViewCR path) noexcept {
|
||||
ox::Result<SubSheetId> getIdFor(TileSheet const &ts, ox::StringViewCR path) noexcept {
|
||||
return getIdFor(ts.subsheet, ox::split<8>(path, '.'));
|
||||
}
|
||||
|
||||
@ -367,8 +367,8 @@ ox::Result<SubSheetId> getIdFor(TileSheet const&ts, ox::StringViewCR path) noexc
|
||||
* Gets the offset in tiles of the desired subsheet.
|
||||
*/
|
||||
static ox::Result<uint32_t> getTileOffset(
|
||||
TileSheet::SubSheet const&ss,
|
||||
ox::SpanView<ox::StringView> const&pNamePath,
|
||||
TileSheet::SubSheet const &ss,
|
||||
ox::SpanView<ox::StringView> const &pNamePath,
|
||||
std::size_t const pIt = 0,
|
||||
uint32_t pCurrentTotal = 0) noexcept {
|
||||
// pIt == pNamePath.size() - 1 &&
|
||||
@ -391,7 +391,7 @@ static ox::Result<uint32_t> getTileOffset(
|
||||
return ox::Error(1, "SubSheet not found");
|
||||
}
|
||||
|
||||
ox::Result<uint32_t> getTileOffset(TileSheet const&ts, ox::StringViewCR pNamePath) noexcept {
|
||||
ox::Result<uint32_t> getTileOffset(TileSheet const &ts, ox::StringViewCR pNamePath) noexcept {
|
||||
return gfx::getTileOffset(ts.subsheet, ox::split<8>(pNamePath, '.'));
|
||||
}
|
||||
|
||||
@ -399,7 +399,7 @@ ox::Result<ox::StringView> getNameFor(TileSheet &ts, SubSheetId const pId) noexc
|
||||
return gfx::getNameFor(ts.subsheet, pId);
|
||||
}
|
||||
|
||||
ox::Result<ox::StringView> getNameFor(TileSheet const&ts, SubSheetId const pId) noexcept {
|
||||
ox::Result<ox::StringView> getNameFor(TileSheet const &ts, SubSheetId const pId) noexcept {
|
||||
return gfx::getNameFor(ts.subsheet, pId);
|
||||
}
|
||||
|
||||
@ -431,19 +431,19 @@ ox::Vector<uint8_t> pixels(TileSheet &ts) noexcept {
|
||||
|
||||
|
||||
ox::Vector<uint32_t> resizeTileSheetData(
|
||||
ox::Vector<uint32_t> const&srcPixels,
|
||||
ox::Size const&srcSize,
|
||||
ox::Vector<uint32_t> const &srcPixels,
|
||||
ox::Size const &srcSize,
|
||||
int const scale) noexcept {
|
||||
ox::Vector<uint32_t> dst;
|
||||
auto dstWidth = srcSize.width * scale;
|
||||
auto dstHeight = srcSize.height * scale;
|
||||
const auto pixelCnt = dstWidth * dstHeight;
|
||||
auto const pixelCnt = dstWidth * dstHeight;
|
||||
dst.resize(static_cast<std::size_t>(pixelCnt));
|
||||
for (auto i = 0; i < pixelCnt; ++i) {
|
||||
const auto dstPt = idxToPt(i, 1, scale);
|
||||
const auto srcPt = dstPt / ox::Point{scale, scale};
|
||||
const auto srcIdx = ptToIdx(srcPt, 1);
|
||||
const auto srcPixel = srcPixels[srcIdx];
|
||||
auto const dstPt = idxToPt(i, 1, scale);
|
||||
auto const srcPt = dstPt / ox::Point{scale, scale};
|
||||
auto const srcIdx = ptToIdx(srcPt, 1);
|
||||
auto const srcPixel = srcPixels[srcIdx];
|
||||
dst[static_cast<std::size_t>(i)] = srcPixel;
|
||||
}
|
||||
return dst;
|
||||
|
@ -24,7 +24,7 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
|
||||
},
|
||||
};
|
||||
|
||||
int main(int argc, const char **argv) {
|
||||
int main(int argc, char const **argv) {
|
||||
int retval = -1;
|
||||
if (argc > 0) {
|
||||
auto const args = ox::Span{argv, static_cast<size_t>(argc)};
|
||||
|
@ -11,7 +11,7 @@
|
||||
static std::map<ox::StringView, ox::Error(*)()> tests = {
|
||||
};
|
||||
|
||||
int main(int argc, const char **argv) {
|
||||
int main(int argc, char const **argv) {
|
||||
int retval = -1;
|
||||
if (argc > 0) {
|
||||
auto const args = ox::Span{argv, static_cast<size_t>(argc)};
|
||||
|
@ -55,7 +55,7 @@ void registerStudioModules() noexcept;
|
||||
#if defined(_WIN32) && OLYMPIC_GUI_APP
|
||||
int WinMain() {
|
||||
auto const argc = __argc;
|
||||
auto const argv = const_cast<const char**>(__argv);
|
||||
auto const argv = const_cast<char const**>(__argv);
|
||||
#else
|
||||
int main(int const argc, char const **argv) {
|
||||
#endif
|
||||
|
@ -26,7 +26,7 @@ ox::Error writeUuidHeader(ox::Writer_c auto &writer, ox::UUID const&uuid) noexce
|
||||
template<typename T>
|
||||
ox::Result<T> readAsset(ox::BufferView buff) noexcept {
|
||||
std::size_t offset = 0;
|
||||
const auto err = readUuidHeader(buff).error;
|
||||
auto const err = readUuidHeader(buff).error;
|
||||
if (!err) {
|
||||
offset = K1HdrSz; // the size of K1 headers
|
||||
}
|
||||
|
@ -37,8 +37,8 @@ ox::Result<ox::ModelObject> readAsset(ox::TypeStore &ts, ox::BufferView buff) no
|
||||
}
|
||||
|
||||
ox::Result<ox::StringView> readAssetTypeId(ox::BufferView const buff) noexcept {
|
||||
const auto err = readUuidHeader(buff).error;
|
||||
const auto offset = err ? 0u : K1HdrSz;
|
||||
auto const err = readUuidHeader(buff).error;
|
||||
auto const offset = err ? 0u : K1HdrSz;
|
||||
if (offset >= buff.size()) [[unlikely]] {
|
||||
return ox::Error(1, "Buffer too small for expected data");
|
||||
}
|
||||
@ -47,8 +47,8 @@ ox::Result<ox::StringView> readAssetTypeId(ox::BufferView const buff) noexcept {
|
||||
|
||||
ox::Result<AssetHdr> readAssetHeader(ox::BufferView buff) noexcept {
|
||||
ox::Result<AssetHdr> out;
|
||||
const auto err = readUuidHeader(buff).moveTo(out.value.uuid);
|
||||
const auto offset = err ? 0u : K1HdrSz;
|
||||
auto const err = readUuidHeader(buff).moveTo(out.value.uuid);
|
||||
auto const offset = err ? 0u : K1HdrSz;
|
||||
if (offset >= buff.size()) [[unlikely]] {
|
||||
return ox::Error(1, "Buffer too small for expected data");
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ static ox::Result<ox::UPtr<Wrap>> convert(
|
||||
if (!subConverter.converter().dstMatches(dstTypeName, dstTypeVersion)) {
|
||||
continue;
|
||||
}
|
||||
const auto [intermediate, chainErr] =
|
||||
auto const [intermediate, chainErr] =
|
||||
convert(ctx, converters, src, srcTypeName, srcTypeVersion,
|
||||
subConverter.converter().srcTypeName(), subConverter.converter().srcTypeVersion());
|
||||
if (!chainErr) {
|
||||
|
@ -25,7 +25,7 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
|
||||
},
|
||||
};
|
||||
|
||||
int main(int argc, const char **argv) {
|
||||
int main(int argc, char const **argv) {
|
||||
int retval = -1;
|
||||
if (argc > 0) {
|
||||
auto const args = ox::Span{argv, static_cast<size_t>(argc)};
|
||||
|
@ -61,7 +61,7 @@ static ox::Error runApp(
|
||||
static ox::Error run(
|
||||
ox::StringViewCR appName,
|
||||
ox::StringViewCR projectDataDir,
|
||||
ox::SpanView<const char*>) {
|
||||
ox::SpanView<ox::CString>) {
|
||||
// seed UUID generator
|
||||
auto const time = std::time(nullptr);
|
||||
ox::UUID::seedGenerator({
|
||||
|
@ -140,14 +140,14 @@ void ClawEditor::drawVar(ObjPath &path, ox::StringViewCR name, ox::ModelValue co
|
||||
|
||||
void ClawEditor::drawTree(ObjPath &path, ox::ModelObject const&obj) noexcept {
|
||||
using Str = ox::BasicString<100>;
|
||||
for (const auto &c : obj) {
|
||||
for (auto const &c : obj) {
|
||||
ImGui::TableNextRow(0, 5);
|
||||
auto pathStr = ox::join<Str>("##", path).unwrap();
|
||||
auto lbl = ox::sfmt<Str>("{}##{}", c->name, pathStr);
|
||||
const auto rowSelected = false;
|
||||
const auto hasChildren = c->value.type() == ox::ModelValue::Type::Object
|
||||
auto const rowSelected = false;
|
||||
auto const hasChildren = c->value.type() == ox::ModelValue::Type::Object
|
||||
|| c->value.type() == ox::ModelValue::Type::Vector;
|
||||
const auto flags = ImGuiTreeNodeFlags_SpanFullWidth
|
||||
auto const flags = ImGuiTreeNodeFlags_SpanFullWidth
|
||||
| ImGuiTreeNodeFlags_OpenOnArrow
|
||||
| (hasChildren ? 0 : ImGuiTreeNodeFlags_Leaf)
|
||||
| (rowSelected ? ImGuiTreeNodeFlags_Selected : 0);
|
||||
@ -158,7 +158,7 @@ void ClawEditor::drawTree(ObjPath &path, ox::ModelObject const&obj) noexcept {
|
||||
//}
|
||||
path.push_back(c->name);
|
||||
if (c->value.type() == ox::ModelValue::Type::Object) {
|
||||
const auto open = ImGui::TreeNodeEx(lbl.c_str(), flags);
|
||||
auto const open = ImGui::TreeNodeEx(lbl.c_str(), flags);
|
||||
ImGui::SameLine();
|
||||
drawRow(c->value);
|
||||
if (open) {
|
||||
|
@ -131,7 +131,7 @@ class ChildStackItem {
|
||||
class IDStackItem {
|
||||
public:
|
||||
explicit IDStackItem(int id) noexcept;
|
||||
explicit IDStackItem(const char *id) noexcept;
|
||||
explicit IDStackItem(ox::CString const id) noexcept;
|
||||
explicit IDStackItem(ox::CStringViewCR id) noexcept;
|
||||
~IDStackItem() noexcept;
|
||||
};
|
||||
@ -244,7 +244,7 @@ bool BeginPopup(turbine::Context &ctx, ox::CStringViewCR popupName, bool &show,
|
||||
* @return true if new value selected, false otherwise
|
||||
*/
|
||||
bool ComboBox(
|
||||
ox::CStringView lbl,
|
||||
ox::CStringView const &lbl,
|
||||
ox::SpanView<ox::CStringView> list,
|
||||
size_t &selectedIdx) noexcept;
|
||||
|
||||
@ -255,7 +255,7 @@ bool ComboBox(
|
||||
* @param selectedIdx
|
||||
* @return true if new value selected, false otherwise
|
||||
*/
|
||||
bool ComboBox(ox::CStringView lbl, ox::Span<const ox::String> list, size_t &selectedIdx) noexcept;
|
||||
bool ComboBox(ox::CStringView const &lbl, ox::Span<ox::String const> list, size_t &selectedIdx) noexcept;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -18,11 +18,11 @@ ChildStackItem::~ChildStackItem() noexcept {
|
||||
ImGui::EndChild();
|
||||
}
|
||||
|
||||
IDStackItem::IDStackItem(int id) noexcept {
|
||||
IDStackItem::IDStackItem(int const id) noexcept {
|
||||
ImGui::PushID(id);
|
||||
}
|
||||
|
||||
IDStackItem::IDStackItem(const char *id) noexcept {
|
||||
IDStackItem::IDStackItem(ox::CString const id) noexcept {
|
||||
ImGui::PushID(id);
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ bool PushButton(ox::CStringViewCR lbl, ImVec2 const &btnSz) noexcept {
|
||||
}
|
||||
|
||||
PopupResponse PopupControlsOkCancel(
|
||||
float popupWidth,
|
||||
float const popupWidth,
|
||||
bool &popupOpen,
|
||||
ox::CStringViewCR ok,
|
||||
ox::CStringViewCR cancel) {
|
||||
@ -110,14 +110,14 @@ bool BeginPopup(turbine::Context &ctx, ox::CStringViewCR popupName, bool &show,
|
||||
}
|
||||
|
||||
bool ComboBox(
|
||||
ox::CStringView lbl,
|
||||
ox::SpanView<ox::CStringView> list,
|
||||
ox::CStringView const &lbl,
|
||||
ox::SpanView<ox::CStringView> const list,
|
||||
size_t &selectedIdx) noexcept {
|
||||
bool out{};
|
||||
auto const first = selectedIdx < list.size() ? list[selectedIdx].c_str() : "";
|
||||
if (ImGui::BeginCombo(lbl.c_str(), first, 0)) {
|
||||
for (auto i = 0u; i < list.size(); ++i) {
|
||||
const auto selected = (selectedIdx == i);
|
||||
auto const selected = (selectedIdx == i);
|
||||
if (ImGui::Selectable(list[i].c_str(), selected) && selectedIdx != i) {
|
||||
selectedIdx = i;
|
||||
out = true;
|
||||
@ -129,14 +129,14 @@ bool ComboBox(
|
||||
}
|
||||
|
||||
bool ComboBox(
|
||||
ox::CStringView lbl,
|
||||
ox::Span<const ox::String> list,
|
||||
ox::CStringView const &lbl,
|
||||
ox::Span<ox::String const> const list,
|
||||
size_t &selectedIdx) noexcept {
|
||||
bool out{};
|
||||
auto const first = selectedIdx < list.size() ? list[selectedIdx].c_str() : "";
|
||||
if (ImGui::BeginCombo(lbl.c_str(), first, 0)) {
|
||||
for (auto i = 0u; i < list.size(); ++i) {
|
||||
const auto selected = (selectedIdx == i);
|
||||
auto const selected = (selectedIdx == i);
|
||||
if (ImGui::Selectable(list[i].c_str(), selected) && selectedIdx != i) {
|
||||
selectedIdx = i;
|
||||
out = true;
|
||||
@ -150,13 +150,13 @@ bool ComboBox(
|
||||
bool ComboBox(
|
||||
ox::CStringViewCR lbl,
|
||||
std::function<ox::CStringView(size_t)> const &f,
|
||||
size_t strCnt,
|
||||
size_t const strCnt,
|
||||
size_t &selectedIdx) noexcept {
|
||||
bool out{};
|
||||
auto const first = selectedIdx < strCnt ? f(selectedIdx).c_str() : "";
|
||||
if (ImGui::BeginCombo(lbl.c_str(), first, 0)) {
|
||||
for (auto i = 0u; i < strCnt; ++i) {
|
||||
const auto selected = (selectedIdx == i);
|
||||
auto const selected = (selectedIdx == i);
|
||||
if (ImGui::Selectable(f(i).c_str(), selected) && selectedIdx != i) {
|
||||
selectedIdx = i;
|
||||
out = true;
|
||||
|
Reference in New Issue
Block a user