Compare commits

..

21 Commits

Author SHA1 Message Date
a6814030ee [studio/applib] Cleanup
All checks were successful
Build / build (push) Successful in 1m13s
2025-05-17 16:15:32 -05:00
9937a01042 [turbine] Cleanup 2025-05-17 16:12:16 -05:00
abcf2adc56 [nostalgia/gfx] Cleanup
All checks were successful
Build / build (push) Successful in 1m14s
2025-05-17 03:02:59 -05:00
05f9023550 [nostalgia/gfx] Cleanup
All checks were successful
Build / build (push) Successful in 1m14s
2025-05-17 02:51:56 -05:00
5ba0bcf963 [turbine] Consolidate some files that didn't have sensible distinctions
Some checks failed
Build / build (push) Has been cancelled
2025-05-17 02:51:23 -05:00
3ccadba2f5 [nostalgia/gfx/studio/tilesheet] Fix dragging cursor on image
All checks were successful
Build / build (push) Successful in 1m20s
2025-05-16 21:22:33 -05:00
00e52b6491 [nostalgia] Make pkg-dmg more versatile
All checks were successful
Build / build (push) Successful in 1m14s
2025-05-15 22:26:35 -05:00
ae40487990 [nostalgia/gfx] Add navigateTo handler to TileSheetEditor
All checks were successful
Build / build (push) Successful in 1m20s
2025-05-15 20:39:50 -05:00
84b612c693 [studio/modlib] Give navigateTo a default argument 2025-05-15 20:39:01 -05:00
3c2a6b047e [studio/applib] Make navigateTo handle UUID paths 2025-05-15 20:38:27 -05:00
626da322d9 [ox/std] Add StringParam(IString const&) constructor 2025-05-15 20:37:44 -05:00
0de428a2e5 [studio/applib] Cleanup
All checks were successful
Build / build (push) Successful in 1m19s
2025-05-14 22:11:43 -05:00
8a52df4f76 [nostalgia/gfx] More cleanup
All checks were successful
Build / build (push) Successful in 1m16s
2025-05-14 01:43:59 -05:00
efec6eb3c8 [nostalgia/gfx/studio/palette] Add RGB key shortcuts for focusing color channels
All checks were successful
Build / build (push) Successful in 1m15s
2025-05-14 01:13:40 -05:00
56eeb24900 [nostalgia/gfx/opengl] More cleanup
All checks were successful
Build / build (push) Successful in 1m56s
2025-05-13 22:06:08 -05:00
ae81f6b3de [ox/std] Make Span::operator[] const
All checks were successful
Build / build (push) Successful in 1m17s
2025-05-13 22:02:23 -05:00
c1108301c0 [nostalgia/gfx] Cleanup 2025-05-13 22:01:59 -05:00
83fbe6ac74 [keel,turbine,studio] Fix some install mistakes
All checks were successful
Build / build (push) Successful in 2m17s
2025-05-13 21:39:37 -05:00
80b452833f [nostalgia/gfx] Cleanup
All checks were successful
Build / build (push) Successful in 2m28s
2025-05-13 21:24:04 -05:00
0fa394333b [nostalgia] Add release note about Mac menubar using Cmd
All checks were successful
Build / build (push) Successful in 1m15s
2025-05-10 01:01:11 -05:00
cae7535034 [nostalgia] Fix typos in release notes
All checks were successful
Build / build (push) Successful in 1m15s
2025-05-10 00:57:45 -05:00
49 changed files with 657 additions and 666 deletions

View File

@@ -19,7 +19,7 @@ pkg-gba: build
.PHONY: pkg-mac
pkg-mac: install
${BC_CMD_ENVRUN} ${BC_PY3} ./util/scripts/pkg-dmg.py
${BC_CMD_ENVRUN} ${BC_PY3} ./util/scripts/pkg-dmg.py NostalgiaStudio
.PHONY: generate-studio-rsrc
generate-studio-rsrc:

View File

@@ -146,12 +146,7 @@ class Span {
return iterator<const T&, const T*, true>(m_items, MaxValue<size_type>, m_size);
}
constexpr T &operator[](std::size_t i) noexcept {
boundsCheck(__FILE__, __LINE__, i, size(), "Span access overflow");
return m_items[i];
}
constexpr T const&operator[](std::size_t i) const noexcept {
constexpr T &operator[](std::size_t i) const noexcept {
boundsCheck(__FILE__, __LINE__, i, size(), "Span access overflow");
return m_items[i];
}

View File

@@ -20,6 +20,8 @@ class StringParam {
constexpr StringParam(StringParam &&o) noexcept: m_value{std::move(o.m_value)} {}
constexpr StringParam(char const*value) noexcept: m_value{value} {}
constexpr StringParam(detail::BaseStringView const&value) noexcept: m_value{value} {}
template<size_t sz>
constexpr StringParam(ox::IString<sz> const&value) noexcept: m_value{value} {}
constexpr StringParam(ox::String const&value) noexcept: m_value{value} {}
constexpr StringParam(ox::String &&value) noexcept: m_value{std::move(value)} {}
constexpr operator ox::String() && noexcept { return std::move(m_value); }

View File

@@ -1,19 +1,24 @@
# d2025.06.0
* PaletteEditor: Add RGB key shortcuts for focusing color channels
# d2025.05.0
* Add app icon for both window and file
* Change application font to Roboto Medium
* Closing application will now confirm with user if any files have unsaved
changes.
* UUID duplicates will now be reported when opening a project
* Deleting a directory now closes files in that directory
* Delete key now initiates deletion of selected directory
* UUID duplicates will now be reported when opening a project.
* Deleting a directory now closes files in that directory.
* Delete key now initiates deletion of selected directory.
* Remove ability to re-order tabs. There were bugs associated with that.
* TileSheetEditor: Fix selection clearing in to work when clicking outside
image.
* Mac: Menu bar shortcuts now say Cmd instead of Ctrl.
* TileSheetEditor: Fix selection clearing to work when clicking outside image.
* TileSheetEditor: Fix Delete Tile functionality, which was completely broken
* PaletteEditor: Fix color number key range in. Previously, pressing A caused
the editor to jump to the last color.
* PaletteEditor: page rename will now take effect upon pressing enter if the
* TileSheetEditor: Fix Insert Tile functionality, which was completely broken
* PaletteEditor: Fix color number key range. Previously, pressing A caused the
editor to jump to the last color.
* PaletteEditor: Page rename will now take effect upon pressing enter if the
text input has focus
# d2025.02.1

View File

@@ -1,14 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include "color.hpp"
#include "context.hpp"
#include "gfx.hpp"
#include "initparams.hpp"
#include "keelmodule.hpp"
#include "palette.hpp"
#include "ptidxconv.hpp"
#include "tilesheet.hpp"

View File

@@ -9,8 +9,14 @@
#include <ox/std/types.hpp>
#include <ox/model/def.hpp>
#include "color.hpp"
#include "context.hpp"
#include "context.hpp"
#include "initparams.hpp"
#include "keelmodule.hpp"
#include "palette.hpp"
#include "palette.hpp"
#include "ptidxconv.hpp"
#include "tilesheet.hpp"
namespace nostalgia::gfx {
@@ -223,7 +229,7 @@ bool bgStatus(Context &ctx, unsigned bg) noexcept;
void setBgStatus(Context &ctx, unsigned bg, bool status) noexcept;
void setBgCbb(Context &ctx, unsigned bgIdx, unsigned cbb) noexcept;
void setBgCbb(Context &ctx, unsigned bgIdx, unsigned cbbIdx) noexcept;
void setBgPriority(Context &ctx, uint_t bgIdx, uint_t priority) noexcept;
@@ -231,10 +237,10 @@ void hideSprite(Context &ctx, unsigned) noexcept;
void showSprite(Context &ctx, unsigned) noexcept;
void setSprite(Context &c, uint_t idx, Sprite const&s) noexcept;
void setSprite(Context &ctx, uint_t idx, Sprite const&sprite) noexcept;
[[nodiscard]]
uint_t spriteCount(Context &ctx) noexcept;
uint_t spriteCount(Context const &ctx) noexcept;
ox::Error initConsole(Context &ctx) noexcept;

View File

@@ -426,6 +426,8 @@ ox::Error resizeSubsheet(TileSheet::SubSheet &ss, ox::Size const&sz) noexcept;
[[nodiscard]]
TileSheet::SubSheetIdx validateSubSheetIdx(TileSheet const&ts, TileSheet::SubSheetIdx idx) noexcept;
ox::Result<TileSheet::SubSheetIdx> getSubSheetIdx(TileSheet const &ts, SubSheetId pId) noexcept;
[[nodiscard]]
TileSheet::SubSheet &getSubSheet(
ox::SpanView<uint32_t> const&idx,

View File

@@ -4,8 +4,6 @@
#include <turbine/turbine.hpp>
#include <nostalgia/gfx/gfx.hpp>
#include "context.hpp"
namespace nostalgia::gfx {
@@ -22,7 +20,7 @@ ox::Error initGfx(Context &ctx, InitParams const&) noexcept;
ox::Result<ox::UPtr<Context>> init(turbine::Context &tctx, InitParams const&params) noexcept {
auto ctx = ox::make_unique<Context>(tctx);
OX_RETURN_ERROR(initGfx(*ctx, params));
return ox::UPtr<Context>(std::move(ctx));
return ctx;
}
keel::Context &keelCtx(Context &ctx) noexcept {

View File

@@ -36,9 +36,9 @@ ox::Error initGfx(Context&, InitParams const&) noexcept {
ox::Error loadBgPalette(
Context&,
size_t palBank,
size_t const palBank,
CompactPalette const&palette,
size_t page) noexcept {
size_t const page) noexcept {
if (palette.pages.empty()) {
return {};
}
@@ -52,7 +52,7 @@ ox::Error loadBgPalette(
ox::Error loadSpritePalette(
Context&,
CompactPalette const&palette,
size_t page) noexcept {
size_t const page) noexcept {
if (palette.pages.empty()) {
return {};
}
@@ -133,7 +133,7 @@ ox::Error loadBgTileSheet(
ox::Error loadBgTileSheet(
Context &ctx,
unsigned cbb,
unsigned const cbb,
CompactTileSheet const&ts,
ox::Optional<unsigned> const&paletteBank) noexcept {
auto const cnt = (ts.pixels.size() * PixelsPerTile) / (1 + (ts.bpp == 4));
@@ -184,7 +184,7 @@ static void setSpritesBpp(unsigned const bpp) noexcept {
ox::Error loadSpriteTileSheet(
Context &ctx,
CompactTileSheet const&ts,
bool loadDefaultPalette) noexcept {
bool const loadDefaultPalette) noexcept {
for (size_t i = 0; i < ts.pixels.size(); i += 2) {
uint16_t v = ts.pixels[i];
v |= static_cast<uint16_t>(ts.pixels[i + 1] << 8);
@@ -206,7 +206,8 @@ ox::Error loadSpriteTileSheet(
return {};
}
void setBgTile(Context &ctx, uint_t bgIdx, int column, int row, BgTile const&tile) noexcept {
void setBgTile(
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] =
@@ -216,7 +217,7 @@ void setBgTile(Context &ctx, uint_t bgIdx, int column, int row, BgTile const&til
static_cast<uint16_t>(tile.palBank << 0xc);
}
void clearBg(Context &ctx, uint_t bgIdx) noexcept {
void clearBg(Context &ctx, uint_t const bgIdx) noexcept {
memset(MEM_BG_MAP[bgIdx].data(), 0, static_cast<size_t>(tileRows(ctx) * tileColumns(ctx)));
}
@@ -224,39 +225,39 @@ uint8_t bgStatus(Context&) noexcept {
return (REG_DISPCTL >> 8u) & 0b1111u;
}
void setBgStatus(Context&, uint32_t status) noexcept {
void setBgStatus(Context&, uint32_t const status) noexcept {
constexpr auto BgStatus = 8;
REG_DISPCTL = (REG_DISPCTL & ~0b111100000000u) | status << BgStatus;
}
bool bgStatus(Context&, unsigned bg) noexcept {
bool bgStatus(Context&, unsigned const bg) noexcept {
return (REG_DISPCTL >> (8 + bg)) & 1;
}
void setBgStatus(Context&, unsigned bg, bool status) noexcept {
void setBgStatus(Context&, unsigned const bg, bool const status) noexcept {
constexpr auto Bg0Status = 8;
const auto mask = static_cast<uint32_t>(status) << (Bg0Status + bg);
REG_DISPCTL = REG_DISPCTL | ((REG_DISPCTL & ~mask) | mask);
}
void setBgBpp(Context&, unsigned bgIdx, unsigned bpp) noexcept {
void setBgBpp(Context&, unsigned const bgIdx, unsigned const bpp) noexcept {
auto &bgCtl = regBgCtl(bgIdx);
teagba::bgSetBpp(bgCtl, bpp);
}
void setBgCbb(Context &ctx, unsigned bgIdx, unsigned cbb) noexcept {
void setBgCbb(Context &ctx, unsigned const bgIdx, unsigned const cbbIdx) noexcept {
auto &bgCtl = regBgCtl(bgIdx);
const auto &cbbData = ctx.cbbData[cbb];
const auto &cbbData = ctx.cbbData[cbbIdx];
teagba::bgSetBpp(bgCtl, cbbData.bpp);
teagba::bgSetCbb(bgCtl, cbb);
teagba::bgSetCbb(bgCtl, cbbIdx);
}
void setBgPriority(Context&, uint_t bgIdx, uint_t priority) noexcept {
void setBgPriority(Context&, uint_t const bgIdx, uint_t const priority) noexcept {
auto &bgCtl = regBgCtl(bgIdx);
bgCtl = (bgCtl & 0b1111'1111'1111'1100u) | (priority & 0b11);
}
void hideSprite(Context&, unsigned idx) noexcept {
void hideSprite(Context&, unsigned const idx) noexcept {
//oxAssert(g_spriteUpdates < config::GbaSpriteBufferLen, "Sprite update buffer overflow");
teagba::addSpriteUpdate({
.attr0 = uint16_t{0b11 << 8},
@@ -264,7 +265,7 @@ void hideSprite(Context&, unsigned idx) noexcept {
});
}
void showSprite(Context&, unsigned idx) noexcept {
void showSprite(Context&, unsigned const idx) noexcept {
//oxAssert(g_spriteUpdates < config::GbaSpriteBufferLen, "Sprite update buffer overflow");
teagba::addSpriteUpdate({
.attr0 = 0,
@@ -272,7 +273,7 @@ void showSprite(Context&, unsigned idx) noexcept {
});
}
void setSprite(Context&, uint_t idx, Sprite const&s) noexcept {
void setSprite(Context&, uint_t const idx, Sprite const&s) noexcept {
//oxAssert(g_spriteUpdates < config::GbaSpriteBufferLen, "Sprite update buffer overflow");
uint16_t const eightBpp = s.bpp == 8;
teagba::addSpriteUpdate({
@@ -293,7 +294,7 @@ void setSprite(Context&, uint_t idx, Sprite const&s) noexcept {
});
}
uint_t spriteCount(Context&) noexcept {
uint_t spriteCount(Context const&) noexcept {
return SpriteCount;
}

View File

@@ -12,7 +12,7 @@
#include <teagba/addresses.hpp>
#include <teagba/bios.hpp>
#include <nostalgia/gfx/core.hpp>
#include <nostalgia/gfx/gfx.hpp>
#include "gfx.hpp"

View File

@@ -26,7 +26,7 @@ Context::~Context() noexcept {
ox::Result<ox::UPtr<Context>> init(turbine::Context &tctx, InitParams const&params) noexcept {
auto ctx = ox::make_unique<Context>(tctx, params);
OX_RETURN_ERROR(initGfx(*ctx, params));
return ox::UPtr<Context>(ctx.release());
return ctx;
}
keel::Context &keelCtx(Context &ctx) noexcept {

View File

@@ -28,7 +28,7 @@ static constexpr auto PriorityScale = 0.01f;
Drawer::Drawer(Context &ctx) noexcept: m_ctx(ctx) {}
void Drawer::draw(turbine::Context &tctx) noexcept {
gfx::gl::draw(m_ctx, turbine::getScreenSize(tctx));
gl::draw(m_ctx, turbine::getScreenSize(tctx));
}
static constexpr ox::CStringView bgvshadTmpl = R"glsl(
@@ -106,7 +106,7 @@ static constexpr ox::CStringView spritefshadTmpl = R"glsl(
})glsl";
[[nodiscard]]
static constexpr auto bgVertexRow(uint_t x, uint_t y) noexcept {
static constexpr auto bgVertexRow(uint_t const x, uint_t const y) noexcept {
return y * TileRows + x;
}
@@ -183,7 +183,7 @@ static void setTileBufferObject(
ox::spancpy<GLuint>(ebo, elms);
}
static void initSpriteBufferObjects(Context &ctx, glutils::BufferSet &bs) noexcept {
static void initSpriteBufferObjects(Context const &ctx, glutils::BufferSet &bs) noexcept {
for (auto i = 0u; i < ctx.spriteCount; ++i) {
auto const vbo = ox::Span{bs.vertices}
+ i * static_cast<std::size_t>(SpriteVertexVboLength);
@@ -256,7 +256,7 @@ static void initSpritesBufferset(Context &ctx) noexcept {
}
static void initBackgroundBufferset(
GLuint shader,
GLuint const shader,
glutils::BufferSet &bs) noexcept {
// vao
bs.vao = glutils::generateVertexArrayObject();
@@ -290,8 +290,8 @@ static void initBackgroundBufferset(
}
static glutils::GLTexture createTexture(
GLsizei w,
GLsizei h,
GLsizei const w,
GLsizei const h,
void const*pixels) noexcept {
GLuint texId = 0;
glGenTextures(1, &texId);
@@ -375,10 +375,10 @@ static void drawSprites(Context &ctx, ox::Size const&renderSz) noexcept {
static void loadPalette(
ox::Array<GLfloat, 1024> &palette,
size_t palOffset,
GLuint shaderPgrm,
size_t const palOffset,
GLuint const shaderPgrm,
CompactPalette const&pal,
size_t page = 0) noexcept {
size_t const page = 0) noexcept {
static constexpr std::size_t ColorCnt = 256;
for (auto i = palOffset; auto const c : pal.pages[page]) {
palette[i++] = redf(c);
@@ -523,14 +523,18 @@ static ox::Result<TileSheetData> normalizeTileSheet(
pixels[i * 2 + 1] = ts.pixels[i] >> 4;
}
}
return TileSheetData{std::move(pixels), width, height};
return TileSheetData{
.pixels = std::move(pixels),
.width = width,
.height = height
};
}
ox::Error loadBgPalette(
Context &ctx,
size_t palBank,
size_t const palBank,
CompactPalette const&palette,
size_t page) noexcept {
size_t const page) noexcept {
renderer::loadPalette(ctx.bgPalette, palBank * 16 * 4, ctx.bgShader, palette, page);
return {};
}
@@ -538,14 +542,14 @@ ox::Error loadBgPalette(
ox::Error loadSpritePalette(
Context &ctx,
CompactPalette const&palette,
size_t page) noexcept {
size_t const page) noexcept {
ox::Array<GLfloat, 1024> pal;
renderer::loadPalette(pal, 0, ctx.spriteShader, palette, page);
return {};
}
static ox::Result<TileSheetData> buildSetTsd(
Context &ctx,
Context const &ctx,
TileSheetSet const&set) noexcept {
auto &kctx = keelCtx(ctx.turbineCtx);
TileSheetData setTsd;
@@ -567,7 +571,7 @@ static ox::Result<TileSheetData> buildSetTsd(
static void copyPixels(
CompactTileSheet const&ts,
ox::Span<uint32_t> dst,
ox::Span<uint32_t> const dst,
size_t const srcPxIdx,
size_t const pxlCnt) noexcept {
size_t idx{};
@@ -624,7 +628,7 @@ ox::Error loadBgTileSheet(
ox::Error loadBgTileSheet(
Context &ctx,
uint_t cbb,
uint_t const cbb,
CompactTileSheet const&ts,
ox::Optional<unsigned> const&paletteBank) noexcept {
auto const bytesPerTile = static_cast<uint64_t>(PixelsPerTile / (1 + (ts.bpp == 4)));
@@ -638,7 +642,7 @@ ox::Error loadBgTileSheet(
ox::Error loadBgTileSheet(
Context &ctx,
unsigned cbb,
unsigned const cbb,
TileSheetSet const&set) noexcept {
OX_REQUIRE(setTsd, buildSetTsd(ctx, set));
ctx.cbbs[cbb].tex = renderer::createTexture(setTsd.width, setTsd.height, setTsd.pixels.data());
@@ -648,7 +652,7 @@ ox::Error loadBgTileSheet(
ox::Error loadSpriteTileSheet(
Context &ctx,
CompactTileSheet const&ts,
bool loadDefaultPalette) noexcept {
bool const loadDefaultPalette) noexcept {
OX_REQUIRE(tsd, normalizeTileSheet(ts));
oxTracef("nostalgia.gfx.gl", "loadSpriteTexture: { w: {}, h: {} }", tsd.width, tsd.height);
ctx.spriteBlocks.tex = renderer::createTexture(tsd.width, tsd.height, tsd.pixels.data());
@@ -668,9 +672,9 @@ ox::Error loadSpriteTileSheet(
void setBgTile(
Context &ctx,
uint_t bgIdx,
int column,
int row,
uint_t const bgIdx,
int const column,
int const row,
BgTile const&tile) noexcept {
oxTracef(
"nostalgia.gfx.setBgTile",
@@ -698,7 +702,7 @@ void setBgTile(
cbb.updated = true;
}
void clearBg(Context &ctx, uint_t bgIdx) noexcept {
void clearBg(Context &ctx, uint_t const bgIdx) noexcept {
auto &cbb = ctx.cbbs[static_cast<std::size_t>(bgIdx)];
initBackgroundBufferObjects(cbb);
cbb.updated = true;
@@ -714,61 +718,59 @@ uint8_t bgStatus(Context &ctx) noexcept {
return out;
}
void setBgStatus(Context &ctx, uint32_t status) noexcept {
void setBgStatus(Context &ctx, uint32_t const status) noexcept {
for (uint_t i = 0; i < ctx.cbbs.size(); ++i) {
ctx.backgrounds[i].enabled = (status >> i) & 1;
}
}
bool bgStatus(Context &ctx, uint_t bg) noexcept {
bool bgStatus(Context &ctx, uint_t const bg) noexcept {
return ctx.backgrounds[bg].enabled;
}
void setBgStatus(Context&ctx, uint_t bg, bool status) noexcept {
void setBgStatus(Context&ctx, uint_t const bg, bool const status) noexcept {
ctx.backgrounds[bg].enabled = status;
}
void setBgBpp(Context&, unsigned, unsigned) noexcept {}
void setBgCbb(Context &ctx, uint_t bgIdx, uint_t cbbIdx) noexcept {
void setBgCbb(Context &ctx, uint_t const bgIdx, uint_t const cbbIdx) noexcept {
auto &bg = ctx.backgrounds[bgIdx];
bg.cbbIdx = cbbIdx;
}
void setBgPriority(Context &ctx, uint_t bgIdx, uint_t priority) noexcept {
void setBgPriority(Context &ctx, uint_t const bgIdx, uint_t const priority) noexcept {
auto &bg = ctx.backgrounds[bgIdx];
bg.priority = static_cast<float>(priority & 0b11);
}
void hideSprite(Context &ctx, uint_t idx) noexcept {
void hideSprite(Context &ctx, uint_t const idx) noexcept {
auto &s = ctx.spriteStates[idx];
s.enabled = false;
renderer::setSprite(ctx, idx, s);
}
void showSprite(Context &ctx, uint_t idx) noexcept {
void showSprite(Context &ctx, uint_t const idx) noexcept {
auto &s = ctx.spriteStates[idx];
s.enabled = true;
renderer::setSprite(ctx, idx, s);
}
void setSprite(Context &ctx, uint_t idx, Sprite const&sprite) noexcept {
void setSprite(Context &ctx, uint_t const idx, Sprite const&sprite) noexcept {
auto &s = ctx.spriteStates[idx];
s = sprite;
renderer::setSprite(ctx, idx, s);
}
uint_t spriteCount(Context &ctx) noexcept {
uint_t spriteCount(Context const &ctx) noexcept {
return ctx.spriteCount;
}
namespace gl {
ox::Size drawSize(int scale) noexcept {
ox::Size drawSize(int const scale) noexcept {
return {240 * scale, 160 * scale};
}
void draw(gfx::Context &ctx, ox::Size const&renderSz) noexcept {
void draw(Context &ctx, ox::Size const&renderSz) noexcept {
glViewport(0, 0, renderSz.width, renderSz.height);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
@@ -783,7 +785,7 @@ void draw(gfx::Context &ctx, ox::Size const&renderSz) noexcept {
glDisable(GL_BLEND);
}
void draw(gfx::Context &ctx, int scale) noexcept {
void draw(Context &ctx, int const scale) noexcept {
draw(ctx, drawSize(scale));
}

View File

@@ -118,12 +118,12 @@ void PaletteEditorImGui::navigateTo(ox::StringViewCR arg) noexcept {
}
}
void PaletteEditorImGui::drawColumnLeftAlign(ox::CStringView txt) noexcept {
void PaletteEditorImGui::drawColumnLeftAlign(ox::CStringViewCR txt) noexcept {
ImGui::TableNextColumn();
ImGui::Text("%s", txt.c_str());
}
void PaletteEditorImGui::drawColumn(ox::CStringView txt) noexcept {
void PaletteEditorImGui::drawColumn(ox::CStringViewCR txt) noexcept {
ImGui::TableNextColumn();
ImGui::SetCursorPosX(
ImGui::GetCursorPosX() + ImGui::GetColumnWidth() - ImGui::CalcTextSize(txt.data()).x);
@@ -143,7 +143,15 @@ void PaletteEditorImGui::numShortcuts(size_t &val, size_t const sizeRange) noexc
}
}
void PaletteEditorImGui::colorInput(ox::CStringView label, int &v, bool &inputFocused) noexcept {
void PaletteEditorImGui::colorInput(
ox::CStringViewCR label,
int &v,
bool &inputFocused,
FocusCmd const colorChannel) noexcept {
if (colorChannel == m_focusCmd) [[unlikely]] {
ImGui::SetKeyboardFocusHere();
m_focusCmd = FocusCmd::None;
}
ImGui::InputInt(label.c_str(), &v, 1, 5);
inputFocused = inputFocused || ImGui::IsItemFocused();
v = ox::max(v, 0);
@@ -296,9 +304,9 @@ void PaletteEditorImGui::drawColorEditor() noexcept {
"Name", m_pal.colorNames[m_selectedColorRow]);
bool inputFocused = ImGui::IsItemFocused();
ImGui::Separator();
colorInput("Red", r, inputFocused);
colorInput("Green", g, inputFocused);
colorInput("Blue", b, inputFocused);
colorInput("Red", r, inputFocused, FocusCmd::Red);
colorInput("Green", g, inputFocused, FocusCmd::Green);
colorInput("Blue", b, inputFocused, FocusCmd::Blue);
if (ig::PushButton("Apply to all pages", {-1, ig::BtnSz.y})) {
std::ignore = pushCommand<ApplyColorAllPagesCommand>(
m_pal, m_page, m_selectedColorRow);
@@ -309,6 +317,15 @@ void PaletteEditorImGui::drawColorEditor() noexcept {
} else {
numShortcuts(m_page, m_pal.pages.size());
}
if (ImGui::IsKeyDown(ImGuiKey_R)) {
m_focusCmd = FocusCmd::Red;
}
if (ImGui::IsKeyDown(ImGuiKey_G)) {
m_focusCmd = FocusCmd::Green;
}
if (ImGui::IsKeyDown(ImGuiKey_B)) {
m_focusCmd = FocusCmd::Blue;
}
}
auto const newColor = color16(r, g, b, a);
if (c != newColor) {
@@ -320,7 +337,7 @@ void PaletteEditorImGui::drawColorEditor() noexcept {
}
}
ox::Error PaletteEditorImGui::renamePage(ox::StringView name) noexcept {
ox::Error PaletteEditorImGui::renamePage(ox::StringViewCR name) noexcept {
return pushCommand<RenamePageCommand>(m_pal, m_page, name);
}

View File

@@ -36,6 +36,13 @@ class PaletteEditorImGui: public studio::Editor {
Palette m_pal;
size_t m_selectedColorRow = 0;
size_t m_page = 0;
enum class FocusCmd {
None,
Red,
Green,
Blue,
};
FocusCmd m_focusCmd;
public:
PaletteEditorImGui(studio::Context &sctx, ox::StringParam path);
@@ -48,9 +55,9 @@ class PaletteEditorImGui: public studio::Editor {
void navigateTo(ox::StringViewCR arg) noexcept override;
private:
static void drawColumnLeftAlign(ox::CStringView txt) noexcept;
static void drawColumnLeftAlign(ox::CStringViewCR txt) noexcept;
static void drawColumn(ox::CStringView txt) noexcept;
static void drawColumn(ox::CStringViewCR txt) noexcept;
static void drawColumn(ox::Integer_c auto i) noexcept {
drawColumn(ox::intToStr(i));
@@ -58,7 +65,7 @@ class PaletteEditorImGui: public studio::Editor {
static void numShortcuts(size_t &val, size_t sizeRange) noexcept;
static void colorInput(ox::CStringView label, int &v, bool &inputFocused) noexcept;
void colorInput(ox::CStringViewCR label, int &v, bool &inputFocused, FocusCmd colorChannel) noexcept;
void drawColorsEditor() noexcept;
@@ -66,7 +73,7 @@ class PaletteEditorImGui: public studio::Editor {
void drawColorEditor() noexcept;
ox::Error renamePage(ox::StringView name) noexcept;
ox::Error renamePage(ox::StringViewCR name) noexcept;
ox::Error handleCommand(studio::UndoCommand const*) noexcept;
};

View File

@@ -388,6 +388,17 @@ ox::Error TileSheetEditorImGui::saveItem() noexcept {
return m_model.saveFile();
}
void TileSheetEditorImGui::navigateTo(ox::StringViewCR arg) noexcept {
auto const subSheetId = strToInt(arg);
if (subSheetId.error) {
return;
}
if (auto const [val, err] = getSubSheetIdx(m_model.img(), subSheetId.value);
!err) {
setActiveSubsheet(val);
}
}
void TileSheetEditorImGui::showSubsheetEditor() noexcept {
auto const&sheet = m_model.activeSubSheet();
if (!sheet.subsheets.empty()) {
@@ -451,7 +462,10 @@ void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const&fbSize) noexcept {
if (wheelh != 0) {
m_view.scrollH(fbSize, wheelh);
}
if (ImGui::IsMouseDown(0) && m_prevMouseDownPos != mousePos) {
using ImGui::IsMouseClicked;
using ImGui::IsMouseDragging;
if ((IsMouseDragging(ImGuiMouseButton_Left) || IsMouseClicked(ImGuiMouseButton_Left))
&& m_prevMouseDownPos != mousePos) {
m_prevMouseDownPos = mousePos;
switch (m_tool) {
case TileSheetTool::Draw:

View File

@@ -87,6 +87,8 @@ class TileSheetEditorImGui: public studio::Editor {
protected:
ox::Error saveItem() noexcept override;
void navigateTo(ox::StringViewCR arg) noexcept override;
private:
void showSubsheetEditor() noexcept;

View File

@@ -2,6 +2,8 @@
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include "nostalgia/gfx/tilesheet.hpp"
#include <ox/std/size.hpp>
#include <ox/std/vector.hpp>
@@ -187,6 +189,28 @@ TileSheet::SubSheetIdx validateSubSheetIdx(TileSheet const&ts, TileSheet::SubShe
return validateSubSheetIdx(std::move(idx), 0, ts.subsheet);
}
static ox::Error getSubSheetIdx(TileSheet::SubSheet const &ss, SubSheetId const pId, TileSheet::SubSheetIdx &idx) noexcept {
if (ss.id == pId) {
return {};
}
for (uint32_t i{}; auto const &sub : ss.subsheets) {
idx.emplace_back(i);
auto const err = getSubSheetIdx(sub, pId, idx);
if (!err) {
return {};
}
idx.pop_back();
++i;
}
return ox::Error{1, "SubSheet not found"};
}
ox::Result<TileSheet::SubSheetIdx> getSubSheetIdx(TileSheet const &ts, SubSheetId const pId) noexcept {
ox::Result<TileSheet::SubSheetIdx> out;
OX_RETURN_ERROR(getSubSheetIdx(ts.subsheet, pId, out.value));
return out;
}
#if defined(__GNUC__) && __GNUC__ >= 13
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdangling-reference"

View File

@@ -6,8 +6,8 @@
#include <map>
#include <ox/std/error.hpp>
#include <ox/mc/mc.hpp>
#include <nostalgia/gfx/core.hpp>
#include <ox/mc/write.hpp>
#include <nostalgia/gfx/gfx.hpp>
using namespace nostalgia;
@@ -15,7 +15,7 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
{
"readWriteTileSheet",
[]() -> ox::Error {
gfx::TileSheet in;
gfx::TileSheet const in;
OX_REQUIRE(buff, ox::writeMC(in));
OX_REQUIRE(out, ox::readMC<gfx::TileSheet>(buff));
oxAssert(in.subsheet.name == out.subsheet.name, "subsheet.name serialization broken");

View File

@@ -5,7 +5,7 @@
#include <keel/media.hpp>
#include <turbine/turbine.hpp>
#include <nostalgia/gfx/core.hpp>
#include <nostalgia/gfx/gfx.hpp>
using namespace nostalgia;

View File

@@ -15,7 +15,7 @@ target_link_libraries(
target_compile_definitions(
NostalgiaStudio PUBLIC
OLYMPIC_APP_VERSION="d2025.05.0"
OLYMPIC_APP_VERSION="dev build"
)
install(

View File

@@ -18,7 +18,7 @@
<string>APPL</string>
<key>CFBundleVersion</key>
<string>d2025.05.0</string>
<string>dev build</string>
<key>LSMinimumSystemVersion</key>
<string>12.0.0</string>

View File

@@ -28,7 +28,7 @@ install(
DIRECTORY
../include/keel
DESTINATION
include/keel
include
)
install(
@@ -60,4 +60,11 @@ if(TURBINE_BUILD_TYPE STREQUAL "Native")
OxClaw
OxLogConn
)
install(
TARGETS
KeelPack-AppLib
DESTINATION
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
endif()

View File

@@ -13,8 +13,9 @@ extern ox::String appVersion;
namespace studio {
AboutPopup::AboutPopup(turbine::Context &ctx) noexcept: Popup("About") {
m_text = ox::sfmt("{} - {}", keelCtx(ctx).appName, olympic::appVersion);
AboutPopup::AboutPopup(turbine::Context &ctx) noexcept:
Popup("About"),
m_text{sfmt("{} - {}", keelCtx(ctx).appName, olympic::appVersion)} {
}
void AboutPopup::draw(Context &sctx) noexcept {

View File

@@ -15,7 +15,7 @@ namespace studio {
class AboutPopup final: public ig::Popup {
private:
ox::String m_text;
ox::String const m_text;
public:
explicit AboutPopup(turbine::Context &ctx) noexcept;

View File

@@ -8,7 +8,7 @@
namespace studio {
studio::TaskState FileDialogManager::update(turbine::Context &ctx) noexcept {
TaskState FileDialogManager::update(turbine::Context &ctx) noexcept {
switch (m_state) {
case UpdateProjectPathState::EnableSystemCursor: {
// switch to system cursor in this update and open file dialog in the next

View File

@@ -31,7 +31,15 @@ static bool shutdownHandler(turbine::Context &ctx) {
}
void navigateTo(Context &ctx, ox::StringParam filePath, ox::StringParam navArgs) noexcept {
ctx.ui.navigateTo(std::move(filePath), std::move(navArgs));
ox::String path = std::move(filePath);
if (beginsWith(path, "uuid://")) {
auto [p, err] = keel::uuidUrlToPath(keelCtx(ctx), path);
if (err) {
return;
}
path = p;
}
ctx.ui.navigateTo(std::move(path), std::move(navArgs));
}
namespace ig {

View File

@@ -27,6 +27,6 @@ inline keel::Context &keelCtx(Context &ctx) noexcept {
return keelCtx(ctx.tctx);
}
void navigateTo(Context &ctx, ox::StringParam filePath, ox::StringParam navArgs) noexcept;
void navigateTo(Context &ctx, ox::StringParam filePath, ox::StringParam navArgs = "") noexcept;
}

View File

@@ -6,6 +6,8 @@
#include <ox/event/signal.hpp>
#include <turbine/turbine.hpp>
#include "undostack.hpp"
#include "widget.hpp"

View File

@@ -44,5 +44,5 @@ install(
DIRECTORY
../include/studio
DESTINATION
include/studio
include
)

View File

@@ -34,7 +34,7 @@ void setClipboardText(Context &ctx, ox::StringViewCR text) noexcept;
void setClipboardObject(Context &ctx, ox::UPtr<BaseClipboardObject> &&obj) noexcept;
ox::Result<BaseClipboardObject*> getClipboardData(Context &ctx, ox::StringView typeId) noexcept;
ox::Result<BaseClipboardObject*> getClipboardData(Context &ctx, ox::StringViewCR typeId) noexcept;
template<typename T>
ox::Result<T*> getClipboardObject(Context &ctx) noexcept {

View File

@@ -6,13 +6,9 @@
#include <ox/fs/fs.hpp>
#include <ox/model/desctypes.hpp>
#include <ox/std/buffer.hpp>
#include <ox/std/size.hpp>
#include <keel/context.hpp>
#include "input.hpp"
namespace turbine {
class Context;
@@ -47,10 +43,5 @@ T *applicationData(Context &ctx) noexcept {
return applicationDataRaw(ctx).get<T>();
}
void setKeyEventHandler(Context &ctx, KeyEventHandler h) noexcept;
[[nodiscard]]
KeyEventHandler keyEventHandler(Context &ctx) noexcept;
}

View File

@@ -1,17 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
namespace turbine {
class Context;
using UpdateHandler = int(*)(Context&);
// Sets event handler that sleeps for the time given in the return value. The
// sleep time is a minimum of ~16 milliseconds.
void setUpdateHandler(Context &ctx, UpdateHandler) noexcept;
}

View File

@@ -21,11 +21,9 @@ class Drawer {
virtual void draw(Context&) noexcept = 0;
};
void addDrawer(Context &ctx, Drawer *cd) noexcept;
void removeDrawer(Context &ctx, Drawer *cd) noexcept;
void removeDrawer(Context &ctx, Drawer const *cd) noexcept;
}
ox::Error initGfx(Context &ctx) noexcept;
ox::Error setWindowIcon(Context &ctx, ox::SpanView<ox::SpanView<uint8_t>> const &iconPngs) noexcept;
void setWindowTitle(Context &ctx, ox::StringViewCR title) noexcept;

View File

@@ -1,79 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <ox/std/defines.hpp>
namespace turbine {
enum Key {
// GBA implementation currently relies on GamePad entry order
GamePad_A = 0,
GamePad_B,
GamePad_Select,
GamePad_Start,
GamePad_Right,
GamePad_Left,
GamePad_Up,
GamePad_Down,
GamePad_R,
GamePad_L,
Num_0,
Num_1,
Num_2,
Num_3,
Num_4,
Num_5,
Num_6,
Num_7,
Num_8,
Num_9,
Alpha_A,
Alpha_B,
Alpha_C,
Alpha_D,
Alpha_E,
Alpha_F,
Alpha_G,
Alpha_H,
Alpha_I,
Alpha_J,
Alpha_K,
Alpha_L,
Alpha_M,
Alpha_N,
Alpha_O,
Alpha_P,
Alpha_Q,
Alpha_R,
Alpha_S,
Alpha_T,
Alpha_U,
Alpha_V,
Alpha_W,
Alpha_X,
Alpha_Y,
Alpha_Z,
Mod_Alt,
Mod_Ctrl,
Mod_Super,
Mod_Shift,
Escape,
End
};
class Context;
[[nodiscard]]
bool buttonDown(Context const&ctx, Key) noexcept;
using KeyEventHandler = void(*)(Context&, Key, bool);
}

View File

@@ -8,13 +8,85 @@
#include <ox/fs/fs.hpp>
#include "clipboard.hpp"
#include "event.hpp"
#include "gfx.hpp"
#include "input.hpp"
namespace turbine {
class Context;
using TimeMs = uint64_t;
using UpdateHandler = int(*)(Context&);
enum Key {
// GBA implementation currently relies on GamePad entry order
GamePad_A = 0,
GamePad_B,
GamePad_Select,
GamePad_Start,
GamePad_Right,
GamePad_Left,
GamePad_Up,
GamePad_Down,
GamePad_R,
GamePad_L,
Num_0,
Num_1,
Num_2,
Num_3,
Num_4,
Num_5,
Num_6,
Num_7,
Num_8,
Num_9,
Alpha_A,
Alpha_B,
Alpha_C,
Alpha_D,
Alpha_E,
Alpha_F,
Alpha_G,
Alpha_H,
Alpha_I,
Alpha_J,
Alpha_K,
Alpha_L,
Alpha_M,
Alpha_N,
Alpha_O,
Alpha_P,
Alpha_Q,
Alpha_R,
Alpha_S,
Alpha_T,
Alpha_U,
Alpha_V,
Alpha_W,
Alpha_X,
Alpha_Y,
Alpha_Z,
Mod_Alt,
Mod_Ctrl,
Mod_Super,
Mod_Shift,
Escape,
End
};
using KeyEventHandler = void(*)(Context&, Key, bool);
void setKeyEventHandler(Context &ctx, KeyEventHandler h) noexcept;
[[nodiscard]]
KeyEventHandler keyEventHandler(Context &ctx) noexcept;
[[nodiscard]]
bool buttonDown(Context const&ctx, Key) noexcept;
ox::Result<ox::UPtr<Context>> init(ox::UPtr<ox::FileSystem> &&fs, ox::StringViewCR appName) noexcept;
@@ -33,4 +105,8 @@ using ShutdownHandler = bool (*)(Context&);
void setShutdownHandler(Context &ctx, ShutdownHandler handler) noexcept;
// Sets event handler that sleeps for the time given in the return value. The
// sleep time is a minimum of ~16 milliseconds.
void setUpdateHandler(Context &ctx, UpdateHandler) noexcept;
}

View File

@@ -38,7 +38,7 @@ install(
DIRECTORY
../include/turbine
DESTINATION
include/turbine
include
)
install(

View File

@@ -6,8 +6,6 @@ target_sources(
Turbine-GBA PRIVATE
context.cpp
clipboard.cpp
event.cpp
gfx.cpp
irq.arm.cpp
turbine.arm.cpp
turbine.cpp

View File

@@ -5,6 +5,7 @@
#include <ox/std/string.hpp>
#include <turbine/context.hpp>
#include <turbine/clipboard.hpp>
namespace turbine {
@@ -15,4 +16,8 @@ ox::String getClipboardText(Context&) noexcept {
void setClipboardText(Context&, ox::StringViewCR) noexcept {
}
ox::Result<BaseClipboardObject*> getClipboardData(Context&, ox::StringViewCR) noexcept {
return ox::Error{1, "not implemented"};
}
}

View File

@@ -6,9 +6,8 @@
#include <keel/context.hpp>
#include <turbine/clipboard.hpp>
#include <turbine/context.hpp>
#include <turbine/event.hpp>
#include <turbine/turbine.hpp>
namespace turbine {

View File

@@ -1,23 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <turbine/event.hpp>
#include "context.hpp"
namespace turbine {
void setUpdateHandler(Context &ctx, UpdateHandler h) noexcept {
ctx.updateHandler = h;
}
void setKeyEventHandler(Context &ctx, KeyEventHandler h) noexcept {
ctx.keyEventHandler = h;
}
KeyEventHandler keyEventHandler(Context &ctx) noexcept {
return ctx.keyEventHandler;
}
}

View File

@@ -1,50 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <ox/std/size.hpp>
#include <ox/std/stringview.hpp>
#include <teagba/addresses.hpp>
#include <teagba/gfx.hpp>
#include <teagba/irq.hpp>
#include <turbine/context.hpp>
namespace turbine {
ox::Error initGfx(Context&) noexcept {
REG_DISPCTL = teagba::DispCtl_Mode0
| teagba::DispCtl_SpriteMap1D
| teagba::DispCtl_Obj;
// tell display to trigger vblank interrupts
REG_DISPSTAT = REG_DISPSTAT | teagba::DispStat_irq_vblank;
// enable vblank interrupt
REG_IE = REG_IE | teagba::Int_vblank;
return {};
}
void setWindowTitle(Context&, ox::StringViewCR) noexcept {
}
int getScreenWidth(Context const&) noexcept {
return 240;
}
int getScreenHeight(Context const&) noexcept {
return 160;
}
ox::Size getScreenSize(Context const&) noexcept {
return {240, 160};
}
ox::Bounds getWindowBounds(Context const&) noexcept {
return {0, 0, 240, 160};
}
ox::Error setWindowBounds(Context&, ox::Bounds const&) noexcept {
return ox::Error(1, "setWindowBounds not supported on GBA");
}
}

View File

@@ -3,8 +3,10 @@
*/
#include <teagba/addresses.hpp>
#include <teagba/gfx.hpp>
#include <teagba/irq.hpp>
#include <keel/keel.hpp>
#include <turbine/context.hpp>
#include <turbine/gfx.hpp>
@@ -58,6 +60,40 @@ OX_ALLOW_UNSAFE_BUFFERS_END
return ox::Error(1);
}
static ox::Error initGfx(Context&) noexcept {
REG_DISPCTL = teagba::DispCtl_Mode0
| teagba::DispCtl_SpriteMap1D
| teagba::DispCtl_Obj;
// tell display to trigger vblank interrupts
REG_DISPSTAT = REG_DISPSTAT | teagba::DispStat_irq_vblank;
// enable vblank interrupt
REG_IE = REG_IE | teagba::Int_vblank;
return {};
}
void setWindowTitle(Context&, ox::StringViewCR) noexcept {
}
int getScreenWidth(Context const&) noexcept {
return 240;
}
int getScreenHeight(Context const&) noexcept {
return 160;
}
ox::Size getScreenSize(Context const&) noexcept {
return {240, 160};
}
ox::Bounds getWindowBounds(Context const&) noexcept {
return {0, 0, 240, 160};
}
ox::Error setWindowBounds(Context&, ox::Bounds const&) noexcept {
return ox::Error(1, "setWindowBounds not supported on GBA");
}
ox::Result<ox::UPtr<Context>> init(
ox::UPtr<ox::FileSystem> &&fs, ox::StringViewCR appName) noexcept {
auto ctx = ox::make_unique<Context>();
@@ -68,7 +104,7 @@ ox::Result<ox::UPtr<Context>> init(
OX_RETURN_ERROR(initGfx(*ctx));
initTimer();
initIrq();
return ox::UPtr<Context>(std::move(ctx));
return ctx;
}
void shutdown(Context&) noexcept {
@@ -89,4 +125,16 @@ void requestShutdown(Context &ctx, bool) noexcept {
void setShutdownHandler(Context&, ShutdownHandler) noexcept {
}
void setUpdateHandler(Context &ctx, UpdateHandler h) noexcept {
ctx.updateHandler = h;
}
void setKeyEventHandler(Context &ctx, KeyEventHandler h) noexcept {
ctx.keyEventHandler = h;
}
KeyEventHandler keyEventHandler(Context &ctx) noexcept {
return ctx.keyEventHandler;
}
}

View File

@@ -5,8 +5,6 @@ target_sources(
Turbine PRIVATE
context.cpp
clipboard.cpp
event.cpp
gfx.cpp
turbine.cpp
)

View File

@@ -28,7 +28,7 @@ void setClipboardObject(Context &ctx, ox::UPtr<BaseClipboardObject> &&obj) noexc
ctx.clipboard = std::move(obj);
}
ox::Result<BaseClipboardObject*> getClipboardData(Context &ctx, ox::StringView typeId) noexcept {
ox::Result<BaseClipboardObject*> getClipboardData(Context &ctx, ox::StringViewCR typeId) noexcept {
if (ctx.clipboard && ctx.clipboard->typeId() == typeId) {
return ctx.clipboard.get();
}

View File

@@ -7,7 +7,6 @@
#include <turbine/clipboard.hpp>
#include <turbine/context.hpp>
#include <turbine/gfx.hpp>
#include <turbine/event.hpp>
#include <turbine/turbine.hpp>
namespace turbine {

View File

@@ -1,23 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <turbine/event.hpp>
#include "context.hpp"
namespace turbine {
void setUpdateHandler(Context &ctx, UpdateHandler h) noexcept {
ctx.updateHandler = h;
}
void setKeyEventHandler(Context &ctx, KeyEventHandler h) noexcept {
ctx.keyEventHandler = h;
}
KeyEventHandler keyEventHandler(Context &ctx) noexcept {
return ctx.keyEventHandler;
}
}

View File

@@ -1,324 +0,0 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <lodepng.h>
#if TURBINE_USE_IMGUI
#include <imgui_impl_glfw.h>
#include <imgui_impl_opengl3.h>
#endif
#include "config.hpp"
#include <ox/std/span.hpp>
#include "context.hpp"
namespace turbine {
namespace gl {
void addDrawer(Context &ctx, Drawer *cd) noexcept {
ctx.drawers.emplace_back(cd);
}
void removeDrawer(Context &ctx, Drawer *cd) noexcept {
for (auto i = 0u; i < ctx.drawers.size(); ++i) {
if (ctx.drawers[i] == cd) {
std::ignore = ctx.drawers.erase(i);
break;
}
}
}
}
static void handleGlfwError(int err, char const*desc) noexcept {
oxErrf("GLFW error ({}): {}\n", err, desc);
}
static auto setKeyDownStatus(Context &ctx, Key key, bool down) noexcept {
ctx.keysDown &= ~(1llu << static_cast<int>(key));
ctx.keysDown |= static_cast<uint64_t>(down) << static_cast<int>(key);
}
static void handleKeyPress(Context &ctx, int key, bool down) noexcept {
static constexpr auto keyMap = [] {
ox::Array<Key, GLFW_KEY_LAST> map = {};
for (auto i = 0u; i < 26; ++i) {
map[GLFW_KEY_A + i] = static_cast<Key>(static_cast<unsigned>(Key::Alpha_A) + i);
}
for (auto i = 0u; i < 10; ++i) {
map[GLFW_KEY_0 + i] = static_cast<Key>(static_cast<unsigned>(Key::Num_0) + i);
}
map[GLFW_KEY_LEFT_ALT] = Key::Mod_Alt;
map[GLFW_KEY_RIGHT_ALT] = Key::Mod_Alt;
map[GLFW_KEY_LEFT_CONTROL] = Key::Mod_Ctrl;
map[GLFW_KEY_RIGHT_CONTROL] = Key::Mod_Ctrl;
map[GLFW_KEY_LEFT_SUPER] = Key::Mod_Super;
map[GLFW_KEY_RIGHT_SUPER] = Key::Mod_Super;
map[GLFW_KEY_LEFT_SHIFT] = Key::Mod_Shift;
map[GLFW_KEY_RIGHT_SHIFT] = Key::Mod_Shift;
map[GLFW_KEY_ESCAPE] = Key::Escape;
return map;
}();
auto const eventHandler = keyEventHandler(ctx);
auto const keyIdx = static_cast<std::size_t>(key);
if (keyIdx < keyMap.size()) {
auto const k = keyMap[keyIdx];
setKeyDownStatus(ctx, k, down);
if (eventHandler) {
eventHandler(ctx, k, down);
}
}
}
static void handleGlfwCursorPosEvent(GLFWwindow*, double, double) noexcept {
}
static void handleGlfwMouseButtonEvent(GLFWwindow *window, int, int, int) noexcept {
auto &ctx = *static_cast<Context*>(glfwGetWindowUserPointer(window));
ctx.mandatoryRefreshPeriodEnd = ticksMs(ctx) + config::MandatoryRefreshPeriod;
}
static void handleGlfwKeyEvent(GLFWwindow *window, int key, int, int action, int) noexcept {
auto &ctx = *static_cast<Context*>(glfwGetWindowUserPointer(window));
ctx.mandatoryRefreshPeriodEnd = ticksMs(ctx) + config::MandatoryRefreshPeriod;
if (action == GLFW_PRESS) {
handleKeyPress(ctx, key, true);
} else if (action == GLFW_RELEASE) {
handleKeyPress(ctx, key, false);
}
}
static void handleGlfwWindowCloseEvent(GLFWwindow *window) noexcept {
auto &ctx = *static_cast<Context*>(glfwGetWindowUserPointer(window));
ctx.mandatoryRefreshPeriodEnd = ticksMs(ctx) + config::MandatoryRefreshPeriod;
ctx.running = ctx.shutdownHandler ? !ctx.shutdownHandler(ctx) : false;
glfwSetWindowShouldClose(window, !ctx.running);
glfwPostEmptyEvent();
}
#if TURBINE_USE_IMGUI
static void themeImgui() noexcept {
// Dark Ruda style by Raikiri from ImThemes
auto &style = ImGui::GetStyle();
style.Alpha = 1.0;
style.DisabledAlpha = 0.6000000238418579;
style.WindowPadding = ImVec2(8.0, 8.0);
style.WindowRounding = 0.0;
style.WindowBorderSize = 1.0;
style.WindowMinSize = ImVec2(32.0, 32.0);
style.WindowTitleAlign = ImVec2(0.0, 0.5);
style.WindowMenuButtonPosition = ImGuiDir_Left;
style.ChildRounding = 0.0;
style.ChildBorderSize = 1.0;
style.PopupRounding = 0.0;
style.PopupBorderSize = 1.0;
style.FramePadding = ImVec2(4.0, 3.0);
// custom value
style.FrameRounding = 3.0;
style.FrameBorderSize = 0.0;
style.ItemSpacing = ImVec2(8.0, 4.0);
style.ItemInnerSpacing = ImVec2(4.0, 4.0);
style.CellPadding = ImVec2(4.0, 2.0);
style.IndentSpacing = 21.0;
style.ColumnsMinSpacing = 6.0;
style.ScrollbarSize = 14.0;
style.ScrollbarRounding = 9.0;
style.GrabMinSize = 10.0;
style.GrabRounding = 4.0;
style.TabRounding = 4.0;
style.TabBorderSize = 0.0;
style.TabMinWidthForCloseButton = 0.0;
style.ColorButtonPosition = ImGuiDir_Right;
style.ButtonTextAlign = ImVec2(0.5, 0.5);
style.SelectableTextAlign = ImVec2(0.0, 0.0);
// colors
constexpr auto imVec4 = [](double r, double g, double b, double a) {
return ImVec4(
static_cast<float>(r),
static_cast<float>(g),
static_cast<float>(b),
static_cast<float>(a));
};
auto colors = ox::Span(style.Colors);
colors[ImGuiCol_Text] = imVec4(0.9490196108818054, 0.95686274766922, 0.9764705896377563, 1.0);
colors[ImGuiCol_TextDisabled] = imVec4(0.3568627536296844, 0.4196078479290009, 0.4666666686534882, 1.0);
colors[ImGuiCol_WindowBg] = imVec4(0.1098039224743843, 0.1490196138620377, 0.168627455830574, 1.0);
colors[ImGuiCol_ChildBg] = imVec4(0.1490196138620377, 0.1764705926179886, 0.2196078449487686, 1.0);
colors[ImGuiCol_PopupBg] = imVec4(0.0784313753247261, 0.0784313753247261, 0.0784313753247261, 0.9399999976158142);
colors[ImGuiCol_Border] = imVec4(0.0784313753247261, 0.09803921729326248, 0.1176470592617989, 1.0);
colors[ImGuiCol_BorderShadow] = imVec4(0.0, 0.0, 0.0, 0.0);
colors[ImGuiCol_FrameBg] = imVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0);
colors[ImGuiCol_FrameBgHovered] = imVec4(0.1176470592617989, 0.2000000029802322, 0.2784313857555389, 1.0);
colors[ImGuiCol_FrameBgActive] = imVec4(0.08627451211214066, 0.1176470592617989, 0.1372549086809158, 1.0);
colors[ImGuiCol_TitleBg] = imVec4(0.08627451211214066, 0.1176470592617989, 0.1372549086809158, 0.6499999761581421);
colors[ImGuiCol_TitleBgActive] = imVec4(0.0784313753247261, 0.09803921729326248, 0.1176470592617989, 1.0);
colors[ImGuiCol_TitleBgCollapsed] = imVec4(0.0, 0.0, 0.0, 0.5099999904632568);
colors[ImGuiCol_MenuBarBg] = imVec4(0.1490196138620377, 0.1764705926179886, 0.2196078449487686, 1.0);
colors[ImGuiCol_ScrollbarBg] = imVec4(0.01960784383118153, 0.01960784383118153, 0.01960784383118153, 0.3899999856948853);
colors[ImGuiCol_ScrollbarGrab] = imVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0);
colors[ImGuiCol_ScrollbarGrabHovered] = imVec4(0.1764705926179886, 0.2196078449487686, 0.2470588237047195, 1.0);
colors[ImGuiCol_ScrollbarGrabActive] = imVec4(0.08627451211214066, 0.2078431397676468, 0.3098039329051971, 1.0);
colors[ImGuiCol_CheckMark] = imVec4(0.2784313857555389, 0.5568627715110779, 1.0, 1.0);
colors[ImGuiCol_SliderGrab] = imVec4(0.2784313857555389, 0.5568627715110779, 1.0, 1.0);
colors[ImGuiCol_SliderGrabActive] = imVec4(0.3686274588108063, 0.6078431606292725, 1.0, 1.0);
colors[ImGuiCol_Button] = imVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0);
colors[ImGuiCol_ButtonHovered] = imVec4(0.2784313857555389, 0.5568627715110779, 1.0, 1.0);
colors[ImGuiCol_ButtonActive] = imVec4(0.05882352963089943, 0.529411792755127, 0.9764705896377563, 1.0);
// custom value
colors[ImGuiCol_Header] = imVec4(0.4000000029802322, 0.4470588237047195, 0.4862745225429535, 0.550000011920929);
colors[ImGuiCol_HeaderHovered] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.800000011920929);
colors[ImGuiCol_HeaderActive] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 1.0);
colors[ImGuiCol_Separator] = imVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0);
colors[ImGuiCol_SeparatorHovered] = imVec4(0.09803921729326248, 0.4000000059604645, 0.7490196228027344, 0.7799999713897705);
colors[ImGuiCol_SeparatorActive] = imVec4(0.09803921729326248, 0.4000000059604645, 0.7490196228027344, 1.0);
colors[ImGuiCol_ResizeGrip] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.25);
colors[ImGuiCol_ResizeGripHovered] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.6700000166893005);
colors[ImGuiCol_ResizeGripActive] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.949999988079071);
colors[ImGuiCol_Tab] = imVec4(0.1098039224743843, 0.1490196138620377, 0.168627455830574, 1.0);
colors[ImGuiCol_TabHovered] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.800000011920929);
colors[ImGuiCol_TabActive] = imVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0);
colors[ImGuiCol_TabUnfocused] = imVec4(0.1098039224743843, 0.1490196138620377, 0.168627455830574, 1.0);
colors[ImGuiCol_TabUnfocusedActive] = imVec4(0.1098039224743843, 0.1490196138620377, 0.168627455830574, 1.0);
colors[ImGuiCol_PlotLines] = imVec4(0.6078431606292725, 0.6078431606292725, 0.6078431606292725, 1.0);
colors[ImGuiCol_PlotLinesHovered] = imVec4(1.0, 0.4274509847164154, 0.3490196168422699, 1.0);
colors[ImGuiCol_PlotHistogram] = imVec4(0.8980392217636108, 0.6980392336845398, 0.0, 1.0);
colors[ImGuiCol_PlotHistogramHovered] = imVec4(1.0, 0.6000000238418579, 0.0, 1.0);
colors[ImGuiCol_TableHeaderBg] = imVec4(0.1882352977991104, 0.1882352977991104, 0.2000000029802322, 1.0);
colors[ImGuiCol_TableBorderStrong] = imVec4(0.3098039329051971, 0.3098039329051971, 0.3490196168422699, 1.0);
colors[ImGuiCol_TableBorderLight] = imVec4(0.2274509817361832, 0.2274509817361832, 0.2470588237047195, 1.0);
colors[ImGuiCol_TableRowBg] = imVec4(0.0, 0.0, 0.0, 0.0);
colors[ImGuiCol_TableRowBgAlt] = imVec4(1.0, 1.0, 1.0, 0.05999999865889549);
colors[ImGuiCol_TextSelectedBg] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.3499999940395355);
colors[ImGuiCol_DragDropTarget] = imVec4(1.0, 1.0, 0.0, 0.8999999761581421);
colors[ImGuiCol_NavHighlight] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 1.0);
colors[ImGuiCol_NavWindowingHighlight] = imVec4(1.0, 1.0, 1.0, 0.699999988079071);
colors[ImGuiCol_NavWindowingDimBg] = imVec4(0.800000011920929, 0.800000011920929, 0.800000011920929, 0.2000000029802322);
colors[ImGuiCol_ModalWindowDimBg] = imVec4(0.800000011920929, 0.800000011920929, 0.800000011920929, 0.3499999940395355);
}
#endif
ox::Error initGfx(Context &ctx) noexcept {
glfwSetErrorCallback(handleGlfwError);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
constexpr auto Scale = 5;
ctx.window = glfwCreateWindow(240 * Scale, 160 * Scale, ctx.keelCtx.appName.c_str(), nullptr, nullptr);
//ctx.window = glfwCreateWindow(876, 743, ctx.keelCtx.appName.c_str(), nullptr, nullptr);
if (ctx.window == nullptr) {
return ox::Error(1, "Could not open GLFW window");
}
glfwSetCursorPosCallback(ctx.window, handleGlfwCursorPosEvent);
glfwSetMouseButtonCallback(ctx.window, handleGlfwMouseButtonEvent);
glfwSetKeyCallback(ctx.window, handleGlfwKeyEvent);
glfwSetWindowCloseCallback(ctx.window, handleGlfwWindowCloseEvent);
glfwSetWindowUserPointer(ctx.window, &ctx);
glfwMakeContextCurrent(ctx.window);
if (!gladLoadGLES2Loader(reinterpret_cast<GLADloadproc>(glfwGetProcAddress))) {
return ox::Error(2, "Could not init Glad");
}
#if TURBINE_USE_IMGUI
IMGUI_CHECKVERSION();
ImGui::CreateContext();
auto &io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
//io.MouseDrawCursor = true;
ImGui_ImplGlfw_InitForOpenGL(ctx.window, true);
ImGui_ImplOpenGL3_Init();
io.IniFilename = nullptr;
themeImgui();
#endif
return {};
}
struct IconData {
std::vector<uint8_t> pixels;
int w{}, h{};
};
[[nodiscard]]
[[maybe_unused]]
static ox::Result<IconData> toGlfwImgPixels(ox::SpanView<uint8_t> const &iconPng) noexcept {
ox::Result<IconData> out;
unsigned w{}, h{};
if (lodepng::decode(out.value.pixels, w, h, iconPng.data(), iconPng.size())) {
return ox::Error{1, "unable to decode window icon PNG data"};
}
out.value.w = static_cast<int>(w);
out.value.h = static_cast<int>(h);
return out;
}
ox::Error setWindowIcon(Context &ctx, ox::SpanView<ox::SpanView<uint8_t>> const &iconPngs) noexcept {
if constexpr(ox::defines::OS != ox::OS::Darwin) {
ox::Vector<IconData, 8> src;
ox::Vector<GLFWimage, 8> imgs;
for (auto const &iconPng : iconPngs) {
OX_RETURN_ERROR(toGlfwImgPixels(iconPng).moveTo(src.emplace_back()));
auto &icon = *src.back().unwrap();
imgs.emplace_back(GLFWimage{
.width = icon.w,
.height = icon.h,
.pixels = icon.pixels.data(),
});
}
glfwSetWindowIcon(ctx.window, static_cast<int>(imgs.size()), imgs.data());
}
return {};
}
void setWindowTitle(Context &ctx, ox::StringViewCR title) noexcept {
auto cstr = ox_malloca(title.bytes() + 1, char);
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
ox::strncpy(cstr.get(), title.data(), title.bytes());
OX_ALLOW_UNSAFE_BUFFERS_END
glfwSetWindowTitle(ctx.window, cstr.get());
}
void focusWindow(Context &ctx) noexcept {
glfwFocusWindow(ctx.window);
}
int getScreenWidth(Context const &ctx) noexcept {
int w = 0, h = 0;
glfwGetFramebufferSize(ctx.window, &w, &h);
return w;
}
int getScreenHeight(Context const &ctx) noexcept {
int w = 0, h = 0;
glfwGetFramebufferSize(ctx.window, &w, &h);
return h;
}
ox::Size getScreenSize(Context const &ctx) noexcept {
int w = 0, h = 0;
glfwGetFramebufferSize(ctx.window, &w, &h);
return {w, h};
}
ox::Bounds getWindowBounds(Context const &ctx) noexcept {
ox::Bounds bnds;
glfwGetWindowPos(ctx.window, &bnds.x, &bnds.y);
glfwGetWindowSize(ctx.window, &bnds.width, &bnds.height);
return bnds;
}
ox::Error setWindowBounds(Context &ctx, ox::Bounds const&bnds) noexcept {
glfwSetWindowPos(ctx.window, bnds.x, bnds.y);
glfwSetWindowSize(ctx.window, bnds.width, bnds.height);
return {};
}
void setRefreshWithin(Context &ctx, int ms) noexcept {
ctx.refreshWithinMs = ox::min(ms, ctx.refreshWithinMs);
}
}

View File

@@ -2,7 +2,9 @@
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <lodepng.h>
#if TURBINE_USE_IMGUI
#include <imgui_impl_opengl3.h>
#include <imgui_impl_glfw.h>
@@ -17,6 +19,207 @@
namespace turbine {
namespace gl {
void addDrawer(Context &ctx, Drawer *cd) noexcept {
ctx.drawers.emplace_back(cd);
}
void removeDrawer(Context &ctx, Drawer const *cd) noexcept {
for (auto i = 0u; i < ctx.drawers.size(); ++i) {
if (ctx.drawers[i] == cd) {
std::ignore = ctx.drawers.erase(i);
break;
}
}
}
}
#if TURBINE_USE_IMGUI
static void themeImgui() noexcept {
// Dark Ruda style by Raikiri from ImThemes
auto &style = ImGui::GetStyle();
style.Alpha = 1.0;
style.DisabledAlpha = 0.6000000238418579;
style.WindowPadding = ImVec2(8.0, 8.0);
style.WindowRounding = 0.0;
style.WindowBorderSize = 1.0;
style.WindowMinSize = ImVec2(32.0, 32.0);
style.WindowTitleAlign = ImVec2(0.0, 0.5);
style.WindowMenuButtonPosition = ImGuiDir_Left;
style.ChildRounding = 0.0;
style.ChildBorderSize = 1.0;
style.PopupRounding = 0.0;
style.PopupBorderSize = 1.0;
style.FramePadding = ImVec2(4.0, 3.0);
// custom value
style.FrameRounding = 3.0;
style.FrameBorderSize = 0.0;
style.ItemSpacing = ImVec2(8.0, 4.0);
style.ItemInnerSpacing = ImVec2(4.0, 4.0);
style.CellPadding = ImVec2(4.0, 2.0);
style.IndentSpacing = 21.0;
style.ColumnsMinSpacing = 6.0;
style.ScrollbarSize = 14.0;
style.ScrollbarRounding = 9.0;
style.GrabMinSize = 10.0;
style.GrabRounding = 4.0;
style.TabRounding = 4.0;
style.TabBorderSize = 0.0;
style.TabMinWidthForCloseButton = 0.0;
style.ColorButtonPosition = ImGuiDir_Right;
style.ButtonTextAlign = ImVec2(0.5, 0.5);
style.SelectableTextAlign = ImVec2(0.0, 0.0);
// colors
constexpr auto imVec4 = [](double r, double g, double b, double a) {
return ImVec4(
static_cast<float>(r),
static_cast<float>(g),
static_cast<float>(b),
static_cast<float>(a));
};
auto colors = ox::Span(style.Colors);
colors[ImGuiCol_Text] = imVec4(0.9490196108818054, 0.95686274766922, 0.9764705896377563, 1.0);
colors[ImGuiCol_TextDisabled] = imVec4(0.3568627536296844, 0.4196078479290009, 0.4666666686534882, 1.0);
colors[ImGuiCol_WindowBg] = imVec4(0.1098039224743843, 0.1490196138620377, 0.168627455830574, 1.0);
colors[ImGuiCol_ChildBg] = imVec4(0.1490196138620377, 0.1764705926179886, 0.2196078449487686, 1.0);
colors[ImGuiCol_PopupBg] = imVec4(0.0784313753247261, 0.0784313753247261, 0.0784313753247261, 0.9399999976158142);
colors[ImGuiCol_Border] = imVec4(0.0784313753247261, 0.09803921729326248, 0.1176470592617989, 1.0);
colors[ImGuiCol_BorderShadow] = imVec4(0.0, 0.0, 0.0, 0.0);
colors[ImGuiCol_FrameBg] = imVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0);
colors[ImGuiCol_FrameBgHovered] = imVec4(0.1176470592617989, 0.2000000029802322, 0.2784313857555389, 1.0);
colors[ImGuiCol_FrameBgActive] = imVec4(0.08627451211214066, 0.1176470592617989, 0.1372549086809158, 1.0);
colors[ImGuiCol_TitleBg] = imVec4(0.08627451211214066, 0.1176470592617989, 0.1372549086809158, 0.6499999761581421);
colors[ImGuiCol_TitleBgActive] = imVec4(0.0784313753247261, 0.09803921729326248, 0.1176470592617989, 1.0);
colors[ImGuiCol_TitleBgCollapsed] = imVec4(0.0, 0.0, 0.0, 0.5099999904632568);
colors[ImGuiCol_MenuBarBg] = imVec4(0.1490196138620377, 0.1764705926179886, 0.2196078449487686, 1.0);
colors[ImGuiCol_ScrollbarBg] = imVec4(0.01960784383118153, 0.01960784383118153, 0.01960784383118153, 0.3899999856948853);
colors[ImGuiCol_ScrollbarGrab] = imVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0);
colors[ImGuiCol_ScrollbarGrabHovered] = imVec4(0.1764705926179886, 0.2196078449487686, 0.2470588237047195, 1.0);
colors[ImGuiCol_ScrollbarGrabActive] = imVec4(0.08627451211214066, 0.2078431397676468, 0.3098039329051971, 1.0);
colors[ImGuiCol_CheckMark] = imVec4(0.2784313857555389, 0.5568627715110779, 1.0, 1.0);
colors[ImGuiCol_SliderGrab] = imVec4(0.2784313857555389, 0.5568627715110779, 1.0, 1.0);
colors[ImGuiCol_SliderGrabActive] = imVec4(0.3686274588108063, 0.6078431606292725, 1.0, 1.0);
colors[ImGuiCol_Button] = imVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0);
colors[ImGuiCol_ButtonHovered] = imVec4(0.2784313857555389, 0.5568627715110779, 1.0, 1.0);
colors[ImGuiCol_ButtonActive] = imVec4(0.05882352963089943, 0.529411792755127, 0.9764705896377563, 1.0);
// custom value
colors[ImGuiCol_Header] = imVec4(0.4000000029802322, 0.4470588237047195, 0.4862745225429535, 0.550000011920929);
colors[ImGuiCol_HeaderHovered] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.800000011920929);
colors[ImGuiCol_HeaderActive] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 1.0);
colors[ImGuiCol_Separator] = imVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0);
colors[ImGuiCol_SeparatorHovered] = imVec4(0.09803921729326248, 0.4000000059604645, 0.7490196228027344, 0.7799999713897705);
colors[ImGuiCol_SeparatorActive] = imVec4(0.09803921729326248, 0.4000000059604645, 0.7490196228027344, 1.0);
colors[ImGuiCol_ResizeGrip] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.25);
colors[ImGuiCol_ResizeGripHovered] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.6700000166893005);
colors[ImGuiCol_ResizeGripActive] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.949999988079071);
colors[ImGuiCol_Tab] = imVec4(0.1098039224743843, 0.1490196138620377, 0.168627455830574, 1.0);
colors[ImGuiCol_TabHovered] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.800000011920929);
colors[ImGuiCol_TabActive] = imVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0);
colors[ImGuiCol_TabUnfocused] = imVec4(0.1098039224743843, 0.1490196138620377, 0.168627455830574, 1.0);
colors[ImGuiCol_TabUnfocusedActive] = imVec4(0.1098039224743843, 0.1490196138620377, 0.168627455830574, 1.0);
colors[ImGuiCol_PlotLines] = imVec4(0.6078431606292725, 0.6078431606292725, 0.6078431606292725, 1.0);
colors[ImGuiCol_PlotLinesHovered] = imVec4(1.0, 0.4274509847164154, 0.3490196168422699, 1.0);
colors[ImGuiCol_PlotHistogram] = imVec4(0.8980392217636108, 0.6980392336845398, 0.0, 1.0);
colors[ImGuiCol_PlotHistogramHovered] = imVec4(1.0, 0.6000000238418579, 0.0, 1.0);
colors[ImGuiCol_TableHeaderBg] = imVec4(0.1882352977991104, 0.1882352977991104, 0.2000000029802322, 1.0);
colors[ImGuiCol_TableBorderStrong] = imVec4(0.3098039329051971, 0.3098039329051971, 0.3490196168422699, 1.0);
colors[ImGuiCol_TableBorderLight] = imVec4(0.2274509817361832, 0.2274509817361832, 0.2470588237047195, 1.0);
colors[ImGuiCol_TableRowBg] = imVec4(0.0, 0.0, 0.0, 0.0);
colors[ImGuiCol_TableRowBgAlt] = imVec4(1.0, 1.0, 1.0, 0.05999999865889549);
colors[ImGuiCol_TextSelectedBg] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.3499999940395355);
colors[ImGuiCol_DragDropTarget] = imVec4(1.0, 1.0, 0.0, 0.8999999761581421);
colors[ImGuiCol_NavHighlight] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 1.0);
colors[ImGuiCol_NavWindowingHighlight] = imVec4(1.0, 1.0, 1.0, 0.699999988079071);
colors[ImGuiCol_NavWindowingDimBg] = imVec4(0.800000011920929, 0.800000011920929, 0.800000011920929, 0.2000000029802322);
colors[ImGuiCol_ModalWindowDimBg] = imVec4(0.800000011920929, 0.800000011920929, 0.800000011920929, 0.3499999940395355);
}
#endif
struct IconData {
std::vector<uint8_t> pixels;
int w{}, h{};
};
[[nodiscard]]
[[maybe_unused]]
static ox::Result<IconData> toGlfwImgPixels(ox::SpanView<uint8_t> const &iconPng) noexcept {
ox::Result<IconData> out;
unsigned w{}, h{};
if (lodepng::decode(out.value.pixels, w, h, iconPng.data(), iconPng.size())) {
return ox::Error{1, "unable to decode window icon PNG data"};
}
out.value.w = static_cast<int>(w);
out.value.h = static_cast<int>(h);
return out;
}
ox::Error setWindowIcon(Context &ctx, ox::SpanView<ox::SpanView<uint8_t>> const &iconPngs) noexcept {
if constexpr(ox::defines::OS != ox::OS::Darwin) {
ox::Vector<IconData, 8> src;
ox::Vector<GLFWimage, 8> imgs;
for (auto const &iconPng : iconPngs) {
OX_RETURN_ERROR(toGlfwImgPixels(iconPng).moveTo(src.emplace_back()));
auto &icon = *src.back().unwrap();
imgs.emplace_back(GLFWimage{
.width = icon.w,
.height = icon.h,
.pixels = icon.pixels.data(),
});
}
glfwSetWindowIcon(ctx.window, static_cast<int>(imgs.size()), imgs.data());
}
return {};
}
void setWindowTitle(Context &ctx, ox::StringViewCR title) noexcept {
auto cstr = ox_malloca(title.bytes() + 1, char);
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
ox::strncpy(cstr.get(), title.data(), title.bytes());
OX_ALLOW_UNSAFE_BUFFERS_END
glfwSetWindowTitle(ctx.window, cstr.get());
}
void focusWindow(Context &ctx) noexcept {
glfwFocusWindow(ctx.window);
}
int getScreenWidth(Context const &ctx) noexcept {
int w = 0, h = 0;
glfwGetFramebufferSize(ctx.window, &w, &h);
return w;
}
int getScreenHeight(Context const &ctx) noexcept {
int w = 0, h = 0;
glfwGetFramebufferSize(ctx.window, &w, &h);
return h;
}
ox::Size getScreenSize(Context const &ctx) noexcept {
int w = 0, h = 0;
glfwGetFramebufferSize(ctx.window, &w, &h);
return {w, h};
}
ox::Bounds getWindowBounds(Context const &ctx) noexcept {
ox::Bounds bnds;
glfwGetWindowPos(ctx.window, &bnds.x, &bnds.y);
glfwGetWindowSize(ctx.window, &bnds.width, &bnds.height);
return bnds;
}
ox::Error setWindowBounds(Context &ctx, ox::Bounds const&bnds) noexcept {
glfwSetWindowPos(ctx.window, bnds.x, bnds.y);
glfwSetWindowSize(ctx.window, bnds.width, bnds.height);
return {};
}
void setRefreshWithin(Context &ctx, int ms) noexcept {
ctx.refreshWithinMs = ox::min(ms, ctx.refreshWithinMs);
}
static void draw(Context &ctx) noexcept {
// draw start
#if TURBINE_USE_IMGUI
@@ -35,11 +238,77 @@ static void draw(Context &ctx) noexcept {
glfwSwapBuffers(ctx.window);
}
static void draw(GLFWwindow *window, int, int) noexcept {
static void handleGlfwResize(GLFWwindow *window, int, int) noexcept {
auto &ctx = *static_cast<Context*>(glfwGetWindowUserPointer(window));
draw(ctx);
}
static void handleGlfwError(int const err, char const *desc) noexcept {
oxErrf("GLFW error ({}): {}\n", err, desc);
}
static auto setKeyDownStatus(Context &ctx, Key const key, bool const down) noexcept {
ctx.keysDown &= ~(1llu << static_cast<int>(key));
ctx.keysDown |= static_cast<uint64_t>(down) << static_cast<int>(key);
}
static void handleKeyPress(Context &ctx, int const key, bool const down) noexcept {
static constexpr auto keyMap = [] {
ox::Array<Key, GLFW_KEY_LAST> map = {};
for (auto i = 0u; i < 26; ++i) {
map[GLFW_KEY_A + i] = static_cast<Key>(static_cast<unsigned>(Key::Alpha_A) + i);
}
for (auto i = 0u; i < 10; ++i) {
map[GLFW_KEY_0 + i] = static_cast<Key>(static_cast<unsigned>(Key::Num_0) + i);
}
map[GLFW_KEY_LEFT_ALT] = Key::Mod_Alt;
map[GLFW_KEY_RIGHT_ALT] = Key::Mod_Alt;
map[GLFW_KEY_LEFT_CONTROL] = Key::Mod_Ctrl;
map[GLFW_KEY_RIGHT_CONTROL] = Key::Mod_Ctrl;
map[GLFW_KEY_LEFT_SUPER] = Key::Mod_Super;
map[GLFW_KEY_RIGHT_SUPER] = Key::Mod_Super;
map[GLFW_KEY_LEFT_SHIFT] = Key::Mod_Shift;
map[GLFW_KEY_RIGHT_SHIFT] = Key::Mod_Shift;
map[GLFW_KEY_ESCAPE] = Key::Escape;
return map;
}();
auto const eventHandler = keyEventHandler(ctx);
auto const keyIdx = static_cast<std::size_t>(key);
if (keyIdx < keyMap.size()) {
auto const k = keyMap[keyIdx];
setKeyDownStatus(ctx, k, down);
if (eventHandler) {
eventHandler(ctx, k, down);
}
}
}
static void handleGlfwCursorPosEvent(GLFWwindow*, double, double) noexcept {
}
static void handleGlfwMouseButtonEvent(GLFWwindow *window, int, int, int) noexcept {
auto &ctx = *static_cast<Context*>(glfwGetWindowUserPointer(window));
ctx.mandatoryRefreshPeriodEnd = ticksMs(ctx) + config::MandatoryRefreshPeriod;
}
static void handleGlfwKeyEvent(GLFWwindow *window, int const key, int, int const action, int) noexcept {
auto &ctx = *static_cast<Context*>(glfwGetWindowUserPointer(window));
ctx.mandatoryRefreshPeriodEnd = ticksMs(ctx) + config::MandatoryRefreshPeriod;
if (action == GLFW_PRESS) {
handleKeyPress(ctx, key, true);
} else if (action == GLFW_RELEASE) {
handleKeyPress(ctx, key, false);
}
}
static void handleGlfwWindowCloseEvent(GLFWwindow *window) noexcept {
auto &ctx = *static_cast<Context*>(glfwGetWindowUserPointer(window));
ctx.mandatoryRefreshPeriodEnd = ticksMs(ctx) + config::MandatoryRefreshPeriod;
ctx.running = ctx.shutdownHandler ? !ctx.shutdownHandler(ctx) : false;
glfwSetWindowShouldClose(window, !ctx.running);
glfwPostEmptyEvent();
}
ox::Result<ox::UPtr<Context>> init(
ox::UPtr<ox::FileSystem> &&fs, ox::StringViewCR appName) noexcept {
auto ctx = ox::make_unique<Context>();
@@ -47,11 +316,44 @@ ox::Result<ox::UPtr<Context>> init(
using namespace std::chrono;
ctx->startTime = static_cast<TimeMs>(
duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count());
glfwInit();
OX_RETURN_ERROR(initGfx(*ctx));
glfwSetWindowSizeCallback(ctx->window, draw);
ctx->mandatoryRefreshPeriodEnd = ticksMs(*ctx) + config::MandatoryRefreshPeriod;
return ox::UPtr<Context>(ctx.release());
// init GLFW context
glfwInit();
glfwSetErrorCallback(handleGlfwError);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
constexpr auto Scale = 5;
ctx->window = glfwCreateWindow(240 * Scale, 160 * Scale, ctx->keelCtx.appName.c_str(), nullptr, nullptr);
//ctx.window = glfwCreateWindow(876, 743, ctx.keelCtx.appName.c_str(), nullptr, nullptr);
if (ctx->window == nullptr) {
return ox::Error(1, "Could not open GLFW window");
}
glfwSetCursorPosCallback(ctx->window, handleGlfwCursorPosEvent);
glfwSetMouseButtonCallback(ctx->window, handleGlfwMouseButtonEvent);
glfwSetKeyCallback(ctx->window, handleGlfwKeyEvent);
glfwSetWindowCloseCallback(ctx->window, handleGlfwWindowCloseEvent);
glfwSetWindowSizeCallback(ctx->window, handleGlfwResize);
glfwSetWindowUserPointer(ctx->window, ctx.get());
glfwMakeContextCurrent(ctx->window);
if (!gladLoadGLES2Loader(reinterpret_cast<GLADloadproc>(glfwGetProcAddress))) {
return ox::Error(2, "Could not init Glad");
}
// init ImGui
#if TURBINE_USE_IMGUI
IMGUI_CHECKVERSION();
ImGui::CreateContext();
auto &io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
//io.MouseDrawCursor = true;
ImGui_ImplGlfw_InitForOpenGL(ctx->window, true);
ImGui_ImplOpenGL3_Init();
io.IniFilename = nullptr;
themeImgui();
#endif
return ctx;
}
static void tickFps(Context &ctx, uint64_t const nowMs) noexcept {
@@ -132,4 +434,16 @@ void setShutdownHandler(Context &ctx, ShutdownHandler const handler) noexcept {
ctx.shutdownHandler = handler;
}
void setUpdateHandler(Context &ctx, UpdateHandler h) noexcept {
ctx.updateHandler = h;
}
void setKeyEventHandler(Context &ctx, KeyEventHandler h) noexcept {
ctx.keyEventHandler = h;
}
KeyEventHandler keyEventHandler(Context &ctx) noexcept {
return ctx.keyEventHandler;
}
}

View File

@@ -5,6 +5,8 @@ import shutil
import subprocess
import sys
target_name = sys.argv[1]
def rm(path: str):
file_exists = os.path.exists(path)
is_link = os.path.islink(path)
@@ -26,12 +28,12 @@ def run(args: list[str]):
dmg_dir = 'dist/darwin-arm64-release/NostalgiaStudio'
dmg_dir = f'dist/darwin-arm64-release/{target_name}'
dmg = f'{dmg_dir}.dmg'
rm(dmg)
rm(dmg_dir)
mkdir_p(dmg_dir)
shutil.copytree('dist/darwin-arm64-release/NostalgiaStudio.app', f'{dmg_dir}/NostalgiaStudio.app')
shutil.copytree(f'dist/darwin-arm64-release/{target_name}.app', f'{dmg_dir}/{target_name}.app')
os.symlink('/Applications', f'{dmg_dir}/Applications')
run(['hdiutil', 'create', '-srcfolder', dmg_dir, dmg])
rm(dmg_dir)