Compare commits
6 Commits
d4329981e7
...
7da2f68d30
Author | SHA1 | Date | |
---|---|---|---|
7da2f68d30 | |||
d20889aef1 | |||
50c8302f4a | |||
d8195d300d | |||
a8c1387d5a | |||
ff1e8f260b |
2
deps/ox/src/ox/clargs/clargs.cpp
vendored
2
deps/ox/src/ox/clargs/clargs.cpp
vendored
@ -29,7 +29,7 @@ ClArgs::ClArgs(ox::SpanView<const char*> args) noexcept {
|
||||
m_bools[arg] = false;
|
||||
}
|
||||
m_strings[arg] = val;
|
||||
if (auto r = ox::atoi(val.c_str()); r.error == 0) {
|
||||
if (auto r = ox::strToInt(val); r.error == 0) {
|
||||
m_ints[arg] = r.value;
|
||||
}
|
||||
++i;
|
||||
|
2
deps/ox/src/ox/claw/read.cpp
vendored
2
deps/ox/src/ox/claw/read.cpp
vendored
@ -81,7 +81,7 @@ Result<ClawHeader> readClawHeader(ox::BufferView buff) noexcept {
|
||||
return ox::Error(4, "Claw format does not match any supported format/version combo");
|
||||
}
|
||||
hdr.typeName = typeName;
|
||||
std::ignore = ox::atoi(versionStr).copyTo(hdr.typeVersion);
|
||||
std::ignore = ox::strToInt(versionStr).copyTo(hdr.typeVersion);
|
||||
hdr.data = buffRaw;
|
||||
hdr.dataSize = buffLen;
|
||||
return hdr;
|
||||
|
@ -31,10 +31,10 @@ FileAddress::FileAddress(uint64_t inode) noexcept {
|
||||
FileAddress::FileAddress(ox::StringViewCR path) noexcept {
|
||||
auto pathSize = path.bytes();
|
||||
m_data.path = new char[pathSize + 1];
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
memcpy(m_data.path, path.data(), pathSize);
|
||||
OX_CLANG_NOWARN_BEGIN(-Wunsafe-buffer-usage)
|
||||
m_data.path[pathSize] = 0;
|
||||
OX_CLANG_NOWARN_END
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
m_type = FileAddressType::Path;
|
||||
}
|
||||
|
||||
@ -48,9 +48,11 @@ FileAddress &FileAddress::operator=(const FileAddress &other) noexcept {
|
||||
case FileAddressType::Path:
|
||||
{
|
||||
if (other.m_data.path) {
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
auto strSize = ox::strlen(other.m_data.path) + 1;
|
||||
m_data.path = new char[strSize];
|
||||
ox::memcpy(m_data.path, other.m_data.path, strSize);
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
} else {
|
||||
m_data.constPath = "";
|
||||
m_type = FileAddressType::ConstPath;
|
||||
|
2
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
2
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
@ -468,7 +468,7 @@ Error FileSystemTemplate<FileStore, Directory>::writeFilePath(
|
||||
|
||||
template<typename FileStore, typename Directory>
|
||||
Error FileSystemTemplate<FileStore, Directory>::writeFileInode(uint64_t inode, const void *buffer, uint64_t size, FileType fileType) noexcept {
|
||||
oxTrace("ox.fs.FileSystemTemplate.writeFileInode", ox::itoa(inode));
|
||||
oxTrace("ox.fs.FileSystemTemplate.writeFileInode", ox::intToStr(inode));
|
||||
return m_fs.write(inode, buffer, static_cast<size_t>(size), static_cast<uint8_t>(fileType));
|
||||
}
|
||||
|
||||
|
6
deps/ox/src/ox/fs/test/tests.cpp
vendored
6
deps/ox/src/ox/fs/test/tests.cpp
vendored
@ -119,7 +119,9 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
|
||||
auto constexpr path = ox::StringLiteral("/usr/share/charset.gbag");
|
||||
ox::PathIterator it(path.c_str(), path.len());
|
||||
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
oxAssert(it.dirPath(buff, path.len()) == 0 && ox::strcmp(buff, "/usr/share/") == 0, "PathIterator shows incorrect dir path");
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
return ox::Error(0);
|
||||
}
|
||||
},
|
||||
@ -127,7 +129,9 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
|
||||
"PathIterator::hasNext",
|
||||
[](ox::StringView) {
|
||||
const auto path = "/file1";
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
ox::PathIterator it(path, ox::strlen(path));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
oxAssert(it.hasNext(), "PathIterator shows incorrect hasNext");
|
||||
oxAssert(!it.next().hasNext(), "PathIterator shows incorrect hasNext");
|
||||
return ox::Error(0);
|
||||
@ -163,9 +167,11 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
|
||||
[](ox::StringView) {
|
||||
constexpr auto buffLen = 5000;
|
||||
constexpr auto str1 = "Hello, World!";
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
constexpr auto str1Len = ox::strlen(str1) + 1;
|
||||
constexpr auto str2 = "Hello, Moon!";
|
||||
constexpr auto str2Len = ox::strlen(str2) + 1;
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
auto list = new (ox_alloca(buffLen)) ox::ptrarith::NodeBuffer<uint32_t, ox::FileStoreItem<uint32_t>>(buffLen);
|
||||
oxAssert(ox::FileStore32::format(list, buffLen), "FileStore::format failed.");
|
||||
ox::FileStore32 fileStore(list, buffLen);
|
||||
|
2
deps/ox/src/ox/fs/tool.cpp
vendored
2
deps/ox/src/ox/fs/tool.cpp
vendored
@ -57,7 +57,9 @@ static ox::Error runRead(ox::FileSystem *fs, ox::Span<const char*> args) noexcep
|
||||
return ox::Error(1);
|
||||
}
|
||||
OX_REQUIRE(buff, fs->read(ox::StringView(args[1])));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
std::ignore = fwrite(buff.data(), sizeof(decltype(buff)::value_type), buff.size(), stdout);
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
return ox::Error(0);
|
||||
}
|
||||
|
||||
|
10
deps/ox/src/ox/mc/intops.hpp
vendored
10
deps/ox/src/ox/mc/intops.hpp
vendored
@ -71,7 +71,9 @@ constexpr McInt encodeInteger(I pInput) noexcept {
|
||||
// move input to uint64_t to allow consistent bit manipulation, and to avoid
|
||||
// overflow concerns
|
||||
uint64_t val = 0;
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
ox::memcpy(&val, &input, sizeof(input));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
if (val) {
|
||||
// bits needed to represent number factoring in space possibly
|
||||
// needed for signed bit
|
||||
@ -94,7 +96,9 @@ constexpr McInt encodeInteger(I pInput) noexcept {
|
||||
}
|
||||
if (bytes == 9) {
|
||||
out.data[0] = bytesIndicator;
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
ox::memcpy(&out.data[1], &leVal, 8);
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
if (inputNegative) {
|
||||
out.data[1] |= 0b1000'0000;
|
||||
}
|
||||
@ -104,7 +108,9 @@ constexpr McInt encodeInteger(I pInput) noexcept {
|
||||
auto intermediate =
|
||||
static_cast<uint64_t>(leVal.raw() | (negBit << (valBits - 1))) << bytes |
|
||||
static_cast<uint64_t>(bytesIndicator);
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
ox::memcpy(&out.data[0], &intermediate, sizeof(intermediate));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
}
|
||||
out.length = bytes;
|
||||
}
|
||||
@ -160,7 +166,9 @@ constexpr Result<I> decodeInteger(Reader_c auto&rdr, std::size_t *bytesRead) noe
|
||||
ox::Array<uint32_t, 2> d = {};
|
||||
//d[0] = decoded & 0xffff'ffff;
|
||||
//d[1] = decoded >> 32;
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
ox::memcpy(&d[0], &decoded, sizeof(decoded));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
auto bit = negBit;
|
||||
for (; bit < ox::min<std::size_t>(Bits<I>, 32); ++bit) {
|
||||
d[0] |= 1 << bit;
|
||||
@ -175,7 +183,9 @@ constexpr Result<I> decodeInteger(Reader_c auto&rdr, std::size_t *bytesRead) noe
|
||||
d[0] = d[1];
|
||||
d[1] = d0Tmp;
|
||||
}
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
ox::memcpy(&out, &d[0], sizeof(out));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
6
deps/ox/src/ox/mc/write.hpp
vendored
6
deps/ox/src/ox/mc/write.hpp
vendored
@ -211,10 +211,12 @@ constexpr Error MetalClawWriter<Writer>::field(const char *name, const IString<L
|
||||
}
|
||||
|
||||
template<Writer_c Writer>
|
||||
constexpr Error MetalClawWriter<Writer>::fieldCString(const char*, const char *const*val, std::size_t) noexcept {
|
||||
constexpr Error MetalClawWriter<Writer>::fieldCString(const char*, const char *const*val, std::size_t buffLen) noexcept {
|
||||
bool fieldSet = false;
|
||||
if (!m_unionIdx.has_value() || *m_unionIdx == m_field) {
|
||||
const auto strLen = *val ? ox::strlen(*val) : 0;
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
const auto strLen = *val ? ox::strnlen_s(*val, buffLen) : 0;
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
// write the length
|
||||
const auto strLenBuff = mc::encodeInteger(strLen);
|
||||
OX_RETURN_ERROR(m_writer.write(reinterpret_cast<const char*>(strLenBuff.data.data()), strLenBuff.length));
|
||||
|
12
deps/ox/src/ox/model/modelvalue.hpp
vendored
12
deps/ox/src/ox/model/modelvalue.hpp
vendored
@ -997,7 +997,7 @@ constexpr ModelValue::ModelValue(const ModelValue &other) noexcept {
|
||||
case Type::SignedInteger16:
|
||||
case Type::SignedInteger32:
|
||||
case Type::SignedInteger64:
|
||||
ox::memcpy(&m_data, &other.m_data, sizeof(m_data));
|
||||
m_data = other.m_data;
|
||||
break;
|
||||
case Type::String:
|
||||
m_data.str = new String(other.get<String>());
|
||||
@ -1030,8 +1030,8 @@ constexpr ModelValue::ModelValue(ModelValue &&other) noexcept {
|
||||
case Type::SignedInteger16:
|
||||
case Type::SignedInteger32:
|
||||
case Type::SignedInteger64:
|
||||
ox::memcpy(&m_data, &other.m_data, sizeof(m_data));
|
||||
ox::memset(&other.m_data, 0, sizeof(m_data));
|
||||
m_data = other.m_data;
|
||||
other.m_data.ui64 = 0;
|
||||
break;
|
||||
case Type::String:
|
||||
m_data.str = other.m_data.str;
|
||||
@ -1223,7 +1223,7 @@ constexpr ModelValue &ModelValue::operator=(const ModelValue &other) noexcept {
|
||||
case Type::SignedInteger16:
|
||||
case Type::SignedInteger32:
|
||||
case Type::SignedInteger64:
|
||||
ox::memcpy(&m_data, &other.m_data, sizeof(m_data));
|
||||
m_data = other.m_data;
|
||||
break;
|
||||
case Type::String:
|
||||
m_data.str = new String(other.get<String>());
|
||||
@ -1261,8 +1261,8 @@ constexpr ModelValue &ModelValue::operator=(ModelValue &&other) noexcept {
|
||||
case Type::SignedInteger16:
|
||||
case Type::SignedInteger32:
|
||||
case Type::SignedInteger64:
|
||||
ox::memcpy(&m_data, &other.m_data, sizeof(m_data));
|
||||
ox::memset(&other.m_data, 0, sizeof(m_data));
|
||||
m_data = other.m_data;
|
||||
other.m_data = {};
|
||||
break;
|
||||
case Type::String:
|
||||
m_data.str = other.m_data.str;
|
||||
|
2
deps/ox/src/ox/oc/read.cpp
vendored
2
deps/ox/src/ox/oc/read.cpp
vendored
@ -15,7 +15,7 @@ namespace ox {
|
||||
|
||||
OrganicClawReader::OrganicClawReader(const uint8_t *buff, std::size_t buffSize) {
|
||||
auto json = reinterpret_cast<const char*>(buff);
|
||||
auto jsonLen = ox::strnlen(json, buffSize);
|
||||
auto jsonLen = ox::strnlen_s(json, buffSize);
|
||||
Json::CharReaderBuilder parserBuilder;
|
||||
auto parser = std::unique_ptr<Json::CharReader>(parserBuilder.newCharReader());
|
||||
if (!parser->parse(json, json + jsonLen, &m_json, nullptr)) {
|
||||
|
4
deps/ox/src/ox/oc/read.hpp
vendored
4
deps/ox/src/ox/oc/read.hpp
vendored
@ -8,7 +8,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/std/def.hpp>
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
#include <json/json.h>
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
|
||||
#include <ox/model/fieldcounter.hpp>
|
||||
#include <ox/model/modelhandleradaptor.hpp>
|
||||
|
8
deps/ox/src/ox/oc/write.hpp
vendored
8
deps/ox/src/ox/oc/write.hpp
vendored
@ -8,7 +8,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/std/def.hpp>
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
#include <json/json.h>
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
|
||||
#include <ox/model/fieldcounter.hpp>
|
||||
#include <ox/model/modelhandleradaptor.hpp>
|
||||
@ -258,7 +262,9 @@ Result<ox::Buffer> writeOC(const auto &val) noexcept {
|
||||
const auto str = Json::writeString(jsonBuilder, writer.m_json);
|
||||
Result<Buffer> buff;
|
||||
buff.value.resize(str.size() + 1);
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
memcpy(buff.value.data(), str.data(), str.size() + 1);
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
return buff;
|
||||
}
|
||||
|
||||
@ -270,7 +276,9 @@ Result<ox::String> writeOCString(const auto &val) noexcept {
|
||||
const auto str = Json::writeString(jsonBuilder, writer.m_json);
|
||||
Result<ox::String> buff;
|
||||
buff.value.resize(str.size());
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
memcpy(buff.value.data(), str.data(), str.size() + 1);
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
return buff;
|
||||
}
|
||||
|
||||
|
9
deps/ox/src/ox/std/cstrops.hpp
vendored
9
deps/ox/src/ox/std/cstrops.hpp
vendored
@ -30,9 +30,12 @@ constexpr T1 strncpy(T1 dest, T2 src, std::size_t maxLen) noexcept {
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto strnlen(const char *str1, std::size_t maxLen) noexcept {
|
||||
std::size_t len = 0;
|
||||
for (; len < maxLen && str1[len]; len++);
|
||||
constexpr size_t strnlen_s(const char *str, size_t const maxLen) noexcept {
|
||||
if (!str) [[unlikely]] {
|
||||
return 0;
|
||||
}
|
||||
size_t len = 0;
|
||||
for (; len < maxLen && str[len]; len++);
|
||||
return len;
|
||||
}
|
||||
|
||||
|
2
deps/ox/src/ox/std/istring.hpp
vendored
2
deps/ox/src/ox/std/istring.hpp
vendored
@ -245,7 +245,7 @@ struct MaybeView<ox::IString<sz>> {
|
||||
|
||||
template<Integer_c Integer>
|
||||
[[nodiscard]]
|
||||
constexpr auto itoa(Integer v) noexcept {
|
||||
constexpr auto intToStr(Integer v) noexcept {
|
||||
constexpr auto Cap = [] {
|
||||
auto out = 0;
|
||||
switch (sizeof(Integer)) {
|
||||
|
18
deps/ox/src/ox/std/span.hpp
vendored
18
deps/ox/src/ox/std/span.hpp
vendored
@ -8,6 +8,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if __has_include(<array>)
|
||||
#include <array>
|
||||
#endif
|
||||
|
||||
#include "array.hpp"
|
||||
#include "bit.hpp"
|
||||
#include "def.hpp"
|
||||
@ -35,6 +39,20 @@ class Span {
|
||||
|
||||
constexpr Span() noexcept = default;
|
||||
|
||||
#if __has_include(<array>)
|
||||
template<std::size_t sz>
|
||||
constexpr Span(std::array<T, sz> &a) noexcept:
|
||||
m_items(a.data()),
|
||||
m_size(a.size()) {
|
||||
}
|
||||
|
||||
template<std::size_t sz>
|
||||
constexpr Span(std::array<ox::remove_const_t<T>, sz> const&a) noexcept:
|
||||
m_items(a.data()),
|
||||
m_size(a.size()) {
|
||||
}
|
||||
#endif
|
||||
|
||||
template<std::size_t sz>
|
||||
constexpr Span(ox::Array<T, sz> &a) noexcept:
|
||||
m_items(a.data()),
|
||||
|
10
deps/ox/src/ox/std/string.hpp
vendored
10
deps/ox/src/ox/std/string.hpp
vendored
@ -28,7 +28,7 @@ OX_CLANG_NOWARN_BEGIN(-Wunsafe-buffer-usage)
|
||||
namespace ox {
|
||||
|
||||
template<typename Integer>
|
||||
constexpr ox::IString<21> itoa(Integer v) noexcept;
|
||||
constexpr ox::IString<21> intToStr(Integer v) noexcept;
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
class BasicString {
|
||||
@ -317,13 +317,13 @@ constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operat
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator=(int64_t i) noexcept {
|
||||
set(ox::itoa(i));
|
||||
set(ox::intToStr(i));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator=(uint64_t i) noexcept {
|
||||
set(ox::itoa(i));
|
||||
set(ox::intToStr(i));
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -371,7 +371,7 @@ constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operat
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator+=(Integer_c auto i) noexcept {
|
||||
auto const str = ox::itoa(i);
|
||||
auto const str = ox::intToStr(i);
|
||||
return this->operator+=(str.c_str());
|
||||
}
|
||||
|
||||
@ -414,7 +414,7 @@ constexpr BasicString<SmallStringSize_v> BasicString<SmallStringSize_v>::operato
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v> BasicString<SmallStringSize_v>::operator+(Integer_c auto i) const noexcept {
|
||||
auto const str = ox::itoa(i);
|
||||
auto const str = ox::intToStr(i);
|
||||
return *this + str;
|
||||
}
|
||||
|
||||
|
2
deps/ox/src/ox/std/stringliteral.hpp
vendored
2
deps/ox/src/ox/std/stringliteral.hpp
vendored
@ -32,7 +32,9 @@ class StringLiteral: public detail::BaseStringView {
|
||||
|
||||
constexpr explicit StringLiteral(const char *str, std::size_t len) noexcept: BaseStringView(str, len) {}
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
constexpr explicit StringLiteral(char const *str) noexcept: StringLiteral(str, ox::strlen(str)) {}
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
|
||||
constexpr StringLiteral &operator=(StringLiteral const&other) noexcept {
|
||||
if (&other != this) {
|
||||
|
4
deps/ox/src/ox/std/stringview.hpp
vendored
4
deps/ox/src/ox/std/stringview.hpp
vendored
@ -100,7 +100,8 @@ constexpr auto toStdStringView(StringViewCR sv) noexcept {
|
||||
#endif
|
||||
|
||||
|
||||
constexpr ox::Result<int> atoi(ox::StringViewCR str) noexcept {
|
||||
constexpr ox::Result<int> strToInt(ox::StringViewCR str) noexcept {
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
int total = 0;
|
||||
int multiplier = 1;
|
||||
for (auto i = static_cast<int64_t>(str.len()) - 1; i != -1; --i) {
|
||||
@ -113,6 +114,7 @@ constexpr ox::Result<int> atoi(ox::StringViewCR str) noexcept {
|
||||
}
|
||||
}
|
||||
return total;
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
}
|
||||
|
||||
|
||||
|
4
deps/ox/src/ox/std/strops.cpp
vendored
4
deps/ox/src/ox/std/strops.cpp
vendored
@ -9,6 +9,8 @@
|
||||
#include "def.hpp"
|
||||
#include "strops.hpp"
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
|
||||
static_assert(ox::strcmp("asdf", "hijk") < 0, "asdf < hijk");
|
||||
static_assert(ox::strcmp("hijk", "asdf") > 0, "hijk > asdf");
|
||||
static_assert(ox::strcmp("resize", "read") > 0, "resize > read");
|
||||
@ -42,3 +44,5 @@ std::size_t strlen(const char *str) {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
2
deps/ox/src/ox/std/test/tests.cpp
vendored
2
deps/ox/src/ox/std/test/tests.cpp
vendored
@ -145,6 +145,7 @@ OX_CLANG_NOWARN_END
|
||||
return ox::Error{};
|
||||
}
|
||||
},
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
{
|
||||
"ABCDEFG != HIJKLMN",
|
||||
[]() {
|
||||
@ -169,6 +170,7 @@ OX_CLANG_NOWARN_END
|
||||
return ox::Error(ox::memcmp("ABCDEFGHI", "ABCDEFG", 7) != 0);
|
||||
}
|
||||
},
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
{
|
||||
"IString",
|
||||
[]() {
|
||||
|
4
deps/ox/src/ox/std/tracehook.cpp
vendored
4
deps/ox/src/ox/std/tracehook.cpp
vendored
@ -39,6 +39,8 @@ enum LogChan {
|
||||
Debug = 4,
|
||||
};
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
|
||||
template<LogChan chan>
|
||||
static void log(ox::StringViewCR str) {
|
||||
const auto sz = ox::min<std::size_t>(0x100, str.bytes());
|
||||
@ -103,5 +105,7 @@ void oxTraceHook([[maybe_unused]] const char *file, [[maybe_unused]] int line,
|
||||
#endif
|
||||
}
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
|
||||
}
|
||||
|
||||
|
4
deps/ox/src/ox/std/uuid.hpp
vendored
4
deps/ox/src/ox/std/uuid.hpp
vendored
@ -105,6 +105,10 @@ class UUID {
|
||||
ox::Array<uint8_t, 16> m_value{};
|
||||
|
||||
public:
|
||||
|
||||
static constexpr auto TypeName = "net.drinkingtea.ox.UUID";
|
||||
static constexpr auto TypeVersion = 1;
|
||||
|
||||
static void seedGenerator(const RandomSeed &seed) noexcept;
|
||||
|
||||
static ox::Result<UUID> generate() noexcept;
|
||||
|
28
sample_project/Palettes/SC9K_Logo.npal
Normal file
28
sample_project/Palettes/SC9K_Logo.npal
Normal file
@ -0,0 +1,28 @@
|
||||
K1;3d1a77ec-265f-4905-2061-4f1003ee2189;O1;net.drinkingtea.nostalgia.gfx.Palette;5;{
|
||||
"colorNames" :
|
||||
[
|
||||
"Color 1",
|
||||
"Color 2",
|
||||
"Color 3"
|
||||
],
|
||||
"pages" :
|
||||
[
|
||||
{
|
||||
"colors" :
|
||||
[
|
||||
{
|
||||
"b" : 10,
|
||||
"g" : 5,
|
||||
"r" : 5
|
||||
},
|
||||
{},
|
||||
{
|
||||
"b" : 31,
|
||||
"g" : 31,
|
||||
"r" : 31
|
||||
}
|
||||
],
|
||||
"name" : "Page 1"
|
||||
}
|
||||
]
|
||||
}
|
4111
sample_project/TileSheets/NS_Logo64.nts
Normal file
4111
sample_project/TileSheets/NS_Logo64.nts
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@ -238,7 +238,7 @@ uint_t spriteCount(Context &ctx) noexcept;
|
||||
|
||||
ox::Error initConsole(Context &ctx) noexcept;
|
||||
|
||||
void puts(Context &ctx, int column, int row, ox::StringViewCR str) noexcept;
|
||||
void consoleWrite(Context &ctx, int column, int row, ox::StringViewCR str) noexcept;
|
||||
|
||||
}
|
||||
|
||||
|
@ -36,13 +36,13 @@ OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
setBgStatus(*ctx, 0, true);
|
||||
clearBg(*ctx, 0);
|
||||
auto const serr = ox::sfmt<ox::IString<23>>("Error code: {}", static_cast<int64_t>(err));
|
||||
puts(*ctx, 32 + 1, 1, "SADNESS...");
|
||||
puts(*ctx, 32 + 1, 4, "UNEXPECTED STATE:");
|
||||
puts(*ctx, 32 + 2, 6, panicMsg);
|
||||
consoleWrite(*ctx, 32 + 1, 1, "SADNESS...");
|
||||
consoleWrite(*ctx, 32 + 1, 4, "UNEXPECTED STATE:");
|
||||
consoleWrite(*ctx, 32 + 2, 6, panicMsg);
|
||||
if (err) {
|
||||
puts(*ctx, 32 + 2, 8, serr);
|
||||
consoleWrite(*ctx, 32 + 2, 8, serr);
|
||||
}
|
||||
puts(*ctx, 32 + 1, 15, "PLEASE RESTART THE SYSTEM");
|
||||
consoleWrite(*ctx, 32 + 1, 15, "PLEASE RESTART THE SYSTEM");
|
||||
// print to terminal if in mGBA
|
||||
oxErrf("\033[31;1;1mPANIC:\033[0m [{}:{}]: {}\n", file, line, panicMsg);
|
||||
if (err.msg) {
|
||||
|
@ -251,7 +251,7 @@ ox::Error initConsole(Context &ctx) noexcept {
|
||||
return loadBgPalette(ctx, 0, PaletteAddr);
|
||||
}
|
||||
|
||||
void puts(
|
||||
void consoleWrite(
|
||||
Context &ctx,
|
||||
int const column,
|
||||
int const row,
|
||||
|
@ -105,13 +105,13 @@ void PaletteEditorImGui::navigateTo(ox::StringViewCR arg) noexcept {
|
||||
auto const &color = args[0];
|
||||
auto const &page = args[1];
|
||||
{
|
||||
auto const [c, err] = atoi(color);
|
||||
auto const [c, err] = strToInt(color);
|
||||
if (!err && static_cast<size_t>(c) < colorCnt(m_pal)) {
|
||||
m_selectedColorRow = static_cast<size_t>(c);
|
||||
}
|
||||
}
|
||||
{
|
||||
auto const [pg, err] = atoi(page);
|
||||
auto const [pg, err] = strToInt(page);
|
||||
if (!err && static_cast<size_t>(pg) < m_pal.pages.size()) {
|
||||
m_page = static_cast<size_t>(pg);
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ class PaletteEditorImGui: public studio::Editor {
|
||||
static void drawColumn(ox::CStringView txt) noexcept;
|
||||
|
||||
static void drawColumn(ox::Integer_c auto i) noexcept {
|
||||
drawColumn(ox::itoa(i));
|
||||
drawColumn(ox::intToStr(i));
|
||||
}
|
||||
|
||||
static void numShortcuts(size_t &val, size_t sizeRange) noexcept;
|
||||
|
@ -35,8 +35,10 @@ ox::Error gfx::DeleteTilesCommand::redo() noexcept {
|
||||
auto const src = &p[srcPos];
|
||||
auto const dst1 = &p[m_deletePos];
|
||||
auto const dst2 = &p[(p.size() - m_deleteSz)];
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
ox::memmove(dst1, src, p.size() - srcPos);
|
||||
ox::memset(dst2, 0, m_deleteSz * sizeof(decltype(p[0])));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
return {};
|
||||
}
|
||||
|
||||
@ -47,8 +49,10 @@ ox::Error DeleteTilesCommand::undo() noexcept {
|
||||
auto const dst1 = &p[m_deletePos + m_deleteSz];
|
||||
auto const dst2 = src;
|
||||
auto const sz = p.size() - m_deletePos - m_deleteSz;
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
ox::memmove(dst1, src, sz);
|
||||
ox::memcpy(dst2, m_deletedPixels.data(), m_deletedPixels.size());
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,8 @@ InsertTilesCommand::InsertTilesCommand(
|
||||
}
|
||||
}
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
|
||||
ox::Error InsertTilesCommand::redo() noexcept {
|
||||
auto &s = getSubSheet(m_img, m_idx);
|
||||
auto &p = s.pixels;
|
||||
@ -55,6 +57,8 @@ ox::Error InsertTilesCommand::undo() noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
|
||||
int InsertTilesCommand::commandId() const noexcept {
|
||||
return static_cast<int>(CommandId::InsertTile);
|
||||
}
|
||||
|
@ -549,7 +549,7 @@ void TileSheetEditorImGui::drawPaletteMenu() noexcept {
|
||||
ImGui::PushID(static_cast<int>(i));
|
||||
// Column: color idx
|
||||
ImGui::TableNextColumn();
|
||||
auto const label = ox::itoa(i + 1);
|
||||
auto const label = ox::intToStr(i + 1);
|
||||
auto const rowSelected = i == m_view.palIdx();
|
||||
if (ImGui::Selectable(
|
||||
label.c_str(), rowSelected, ImGuiSelectableFlags_SpanAllColumns)) {
|
||||
|
@ -5,12 +5,13 @@
|
||||
#include <ox/claw/write.hpp>
|
||||
|
||||
#include <nostalgia/gfx/consts.hpp>
|
||||
#include <nostalgia/gfx/gfx.hpp>
|
||||
|
||||
#include "tilesheetpixelgrid.hpp"
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
void TileSheetGrid::setPixelSizeMod(float sm) noexcept {
|
||||
void TileSheetGrid::setPixelSizeMod(float const sm) noexcept {
|
||||
m_pixelSizeMod = sm;
|
||||
}
|
||||
|
||||
@ -18,10 +19,11 @@ ox::Error TileSheetGrid::buildShader() noexcept {
|
||||
auto const pixelLineVshad = ox::sfmt(VShad, gl::GlslVersion);
|
||||
auto const pixelLineFshad = ox::sfmt(FShad, gl::GlslVersion);
|
||||
auto const pixelLineGshad = ox::sfmt(GShad, gl::GlslVersion);
|
||||
return glutils::buildShaderProgram(pixelLineVshad, pixelLineFshad, pixelLineGshad).moveTo(m_shader);
|
||||
return glutils::buildShaderProgram(
|
||||
pixelLineVshad, pixelLineFshad, pixelLineGshad).moveTo(m_shader);
|
||||
}
|
||||
|
||||
void TileSheetGrid::draw(bool 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);
|
||||
@ -51,7 +53,8 @@ void TileSheetGrid::initBufferSet(ox::Vec2 const&paneSize, TileSheet::SubSheet c
|
||||
// vbo layout
|
||||
auto const pt1Attr = static_cast<GLuint>(glGetAttribLocation(m_shader, "vPt1"));
|
||||
glEnableVertexAttribArray(pt1Attr);
|
||||
glVertexAttribPointer(pt1Attr, 2, GL_FLOAT, GL_FALSE, VertexVboRowLength * sizeof(float), nullptr);
|
||||
glVertexAttribPointer(
|
||||
pt1Attr, 2, GL_FLOAT, GL_FALSE, VertexVboRowLength * sizeof(float), nullptr);
|
||||
auto const pt2Attr = static_cast<GLuint>(glGetAttribLocation(m_shader, "vPt2"));
|
||||
glEnableVertexAttribArray(pt2Attr);
|
||||
glVertexAttribPointer(pt2Attr, 2, GL_FLOAT, GL_FALSE, VertexVboRowLength * sizeof(float),
|
||||
@ -70,18 +73,18 @@ void TileSheetGrid::update(ox::Vec2 const&paneSize, TileSheet::SubSheet const&su
|
||||
}
|
||||
|
||||
void TileSheetGrid::setBufferObject(
|
||||
ox::Point pt1,
|
||||
ox::Point pt2,
|
||||
Color32 c,
|
||||
float *vbo,
|
||||
ox::Point const pt1,
|
||||
ox::Point const pt2,
|
||||
Color32 const c,
|
||||
ox::Span<float> const vbo,
|
||||
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;
|
||||
auto const y2 = 1.f - static_cast<float>(pt2.y) * pixSize.y;
|
||||
// don't worry, this memcpy gets optimized to something much more ideal
|
||||
// don't worry, this gets optimized to something much more ideal
|
||||
ox::Array<float, VertexVboLength> const vertices = {x1, y1, x2, y2, redf(c), greenf(c), bluef(c)};
|
||||
memcpy(vbo, vertices.data(), sizeof(vertices));
|
||||
ox::spancpy(vbo, ox::SpanView<float>{vertices});
|
||||
}
|
||||
|
||||
void TileSheetGrid::setBufferObjects(ox::Vec2 const&paneSize, TileSheet::SubSheet const&subsheet) noexcept {
|
||||
@ -92,7 +95,8 @@ void TileSheetGrid::setBufferObjects(ox::Vec2 const&paneSize, TileSheet::SubShee
|
||||
}
|
||||
auto const pixSize = pixelSize(paneSize);
|
||||
auto const set = [&](std::size_t i, ox::Point pt1, ox::Point pt2, Color32 c) {
|
||||
auto const vbo = &m_bufferSet.vertices[i * VertexVboLength];
|
||||
auto const idx = i * VertexVboLength;
|
||||
auto const vbo = ox::Span{m_bufferSet.vertices} + idx;
|
||||
setBufferObject(pt1, pt2, c, vbo, pixSize);
|
||||
};
|
||||
// set buffer length
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include <glutils/glutils.hpp>
|
||||
#include <studio/studio.hpp>
|
||||
|
||||
#include <nostalgia/gfx/gfx.hpp>
|
||||
#include <nostalgia/gfx/tilesheet.hpp>
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
@ -74,7 +73,7 @@ class TileSheetGrid {
|
||||
void update(ox::Vec2 const&paneSize, TileSheet::SubSheet const&subsheet) noexcept;
|
||||
|
||||
private:
|
||||
static void setBufferObject(ox::Point pt1, ox::Point pt2, Color32 c, 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;
|
||||
|
||||
|
@ -2,8 +2,6 @@
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <nostalgia/gfx/consts.hpp>
|
||||
#include <nostalgia/gfx/ptidxconv.hpp>
|
||||
#include "tilesheeteditormodel.hpp"
|
||||
#include "tilesheetpixels.hpp"
|
||||
|
||||
@ -88,11 +86,11 @@ ox::Vec2 TileSheetPixels::pixelSize(ox::Vec2 const&paneSize) const noexcept {
|
||||
|
||||
void TileSheetPixels::setPixelBufferObject(
|
||||
ox::Vec2 const&paneSize,
|
||||
unsigned vertexRow,
|
||||
unsigned const vertexRow,
|
||||
float x, float y,
|
||||
Color16 color,
|
||||
float *vbo,
|
||||
GLuint *ebo) const noexcept {
|
||||
Color16 const color,
|
||||
ox::Span<float> const vbo,
|
||||
ox::Span<GLuint> const ebo) const noexcept {
|
||||
auto const [xmod, ymod] = pixelSize(paneSize);
|
||||
x *= xmod;
|
||||
y *= -ymod;
|
||||
@ -106,12 +104,12 @@ void TileSheetPixels::setPixelBufferObject(
|
||||
x + xmod, y + ymod, r, g, b, // top right
|
||||
x, y + ymod, r, g, b, // top left
|
||||
};
|
||||
memcpy(vbo, vertices.data(), sizeof(vertices));
|
||||
ox::spancpy(vbo, ox::SpanView<float>{vertices});
|
||||
std::array const elms = {
|
||||
vertexRow + 0, vertexRow + 1, vertexRow + 2,
|
||||
vertexRow + 2, vertexRow + 3, vertexRow + 0,
|
||||
};
|
||||
memcpy(ebo, elms.data(), sizeof(elms));
|
||||
ox::spancpy(ebo, ox::SpanView<GLuint>{elms});
|
||||
}
|
||||
|
||||
void TileSheetPixels::setBufferObjects(ox::Vec2 const&paneSize) noexcept {
|
||||
@ -137,8 +135,8 @@ void TileSheetPixels::setBufferObjects(ox::Vec2 const&paneSize) noexcept {
|
||||
auto const pt = idxToPt(static_cast<int>(i), subSheet.columns);
|
||||
auto const fx = static_cast<float>(pt.x);
|
||||
auto const fy = static_cast<float>(pt.y);
|
||||
auto const vbo = &m_bufferSet.vertices[i * vboLen];
|
||||
auto const ebo = &m_bufferSet.elements[i * VertexEboLength];
|
||||
auto const vbo = ox::Span{m_bufferSet.vertices} + i * vboLen;
|
||||
auto const ebo = ox::Span{m_bufferSet.elements} + i * VertexEboLength;
|
||||
if (i * vboLen + vboLen > m_bufferSet.vertices.size()) {
|
||||
return;
|
||||
}
|
||||
|
@ -6,11 +6,9 @@
|
||||
|
||||
#include <ox/std/vec.hpp>
|
||||
|
||||
#include <glutils/glutils.hpp>
|
||||
#include <studio/studio.hpp>
|
||||
|
||||
#include <nostalgia/gfx/color.hpp>
|
||||
#include <nostalgia/gfx/gfx.hpp>
|
||||
|
||||
#include <glutils/glutils.hpp>
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
@ -44,15 +42,15 @@ class TileSheetPixels {
|
||||
|
||||
private:
|
||||
void setPixelBufferObject(
|
||||
ox::Vec2 const&paneS,
|
||||
ox::Vec2 const&paneSize,
|
||||
unsigned vertexRow,
|
||||
float x,
|
||||
float y,
|
||||
Color16 color,
|
||||
float *vbo,
|
||||
GLuint *ebo) const noexcept;
|
||||
ox::Span<float> vbo,
|
||||
ox::Span<GLuint> ebo) const noexcept;
|
||||
|
||||
void setBufferObjects(ox::Vec2 const&paneS) noexcept;
|
||||
void setBufferObjects(ox::Vec2 const&paneSize) noexcept;
|
||||
|
||||
};
|
||||
|
||||
|
@ -69,7 +69,7 @@ static ox::Error runTest(turbine::Context &tctx) {
|
||||
OX_RETURN_ERROR(gfx::loadSpriteTileSheet(*cctx, "/TileSheets/Charset.nts"));
|
||||
OX_RETURN_ERROR(gfx::loadSpritePalette(*cctx, "/Palettes/Chester.npal"));
|
||||
OX_RETURN_ERROR(gfx::initConsole(*cctx));
|
||||
gfx::puts(*cctx, 10, 9, "DOPENESS!!!");
|
||||
gfx::consoleWrite(*cctx, 10, 9, "DOPENESS!!!");
|
||||
turbine::setUpdateHandler(tctx, testUpdateHandler);
|
||||
turbine::setKeyEventHandler(tctx, testKeyEventHandler);
|
||||
return turbine::run(tctx);
|
||||
|
@ -17,6 +17,12 @@
|
||||
#include "font.hpp"
|
||||
#include "studioui.hpp"
|
||||
|
||||
#ifdef OX_OS_Darwin
|
||||
#define STUDIO_CTRL "Cmd"
|
||||
#else
|
||||
#define STUDIO_CTRL "Ctrl"
|
||||
#endif
|
||||
|
||||
namespace studio {
|
||||
|
||||
static bool shutdownHandler(turbine::Context &ctx) {
|
||||
@ -174,45 +180,64 @@ bool StudioUI::handleShutdown() noexcept {
|
||||
void StudioUI::drawMenu() noexcept {
|
||||
if (ImGui::BeginMainMenuBar()) {
|
||||
if (ImGui::BeginMenu("File")) {
|
||||
if (ImGui::MenuItem("New...", "Ctrl+N", false, m_project)) {
|
||||
if (ImGui::MenuItem("New...", STUDIO_CTRL "+N", false, m_project)) {
|
||||
m_newMenu.open();
|
||||
}
|
||||
if (ImGui::MenuItem("New Project...", "Ctrl+Shift+N")) {
|
||||
if (ImGui::MenuItem("New Project...", STUDIO_CTRL "+Shift+N")) {
|
||||
m_newProject.open();
|
||||
}
|
||||
if (ImGui::MenuItem("Open Project...", "Ctrl+O")) {
|
||||
if (ImGui::MenuItem("Open Project...", STUDIO_CTRL "+O")) {
|
||||
m_taskRunner.add(*ox::make<FileDialogManager>(this, &StudioUI::openProjectPath));
|
||||
}
|
||||
if (ImGui::MenuItem("Save", "Ctrl+S", false, m_activeEditor && m_activeEditor->unsavedChanges())) {
|
||||
if (ImGui::MenuItem(
|
||||
"Save",
|
||||
STUDIO_CTRL "+S",
|
||||
false,
|
||||
m_activeEditor && m_activeEditor->unsavedChanges())) {
|
||||
m_activeEditor->save();
|
||||
}
|
||||
if (ImGui::MenuItem("Quit", "Ctrl+Q")) {
|
||||
if (ImGui::MenuItem("Quit", STUDIO_CTRL "+Q")) {
|
||||
turbine::requestShutdown(m_tctx);
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
if (ImGui::BeginMenu("Edit")) {
|
||||
auto undoStack = m_activeEditor ? m_activeEditor->undoStack() : nullptr;
|
||||
if (ImGui::MenuItem("Undo", "Ctrl+Z", false, undoStack && undoStack->canUndo())) {
|
||||
if (ImGui::MenuItem(
|
||||
"Undo", STUDIO_CTRL "+Z", false, undoStack && undoStack->canUndo())) {
|
||||
oxLogError(undoStack->undo());
|
||||
}
|
||||
if (ImGui::MenuItem("Redo", "Ctrl+Y", false, undoStack && undoStack->canRedo())) {
|
||||
if (ImGui::MenuItem(
|
||||
"Redo", STUDIO_CTRL "+Y", false, undoStack && undoStack->canRedo())) {
|
||||
oxLogError(undoStack->redo());
|
||||
}
|
||||
ImGui::Separator();
|
||||
if (ImGui::MenuItem("Copy", "Ctrl+C", false, m_activeEditor && m_activeEditor->copyEnabled())) {
|
||||
if (ImGui::MenuItem(
|
||||
"Copy",
|
||||
STUDIO_CTRL "+C",
|
||||
false,
|
||||
m_activeEditor && m_activeEditor->copyEnabled())) {
|
||||
m_activeEditor->copy();
|
||||
}
|
||||
if (ImGui::MenuItem("Cut", "Ctrl+X", false, m_activeEditor && m_activeEditor->cutEnabled())) {
|
||||
if (ImGui::MenuItem(
|
||||
"Cut",
|
||||
STUDIO_CTRL "+X",
|
||||
false,
|
||||
m_activeEditor && m_activeEditor->cutEnabled())) {
|
||||
m_activeEditor->cut();
|
||||
}
|
||||
if (ImGui::MenuItem("Paste", "Ctrl+V", false, m_activeEditor && m_activeEditor->pasteEnabled())) {
|
||||
if (ImGui::MenuItem(
|
||||
"Paste",
|
||||
STUDIO_CTRL "+V",
|
||||
false,
|
||||
m_activeEditor && m_activeEditor->pasteEnabled())) {
|
||||
m_activeEditor->paste();
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
if (ImGui::BeginMenu("View")) {
|
||||
if (ImGui::MenuItem("Project Explorer", "Ctrl+Shift+1", m_showProjectExplorer)) {
|
||||
if (ImGui::MenuItem(
|
||||
"Project Explorer", STUDIO_CTRL "+Shift+1", m_showProjectExplorer)) {
|
||||
toggleProjectExplorer();
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
@ -278,12 +303,8 @@ void StudioUI::drawTabs() noexcept {
|
||||
if (m_activeEditor == (*it).get()) {
|
||||
m_activeEditor = nullptr;
|
||||
}
|
||||
try {
|
||||
OX_THROW_ERROR(m_editors.erase(it).moveTo(it));
|
||||
} catch (ox::Exception const&ex) {
|
||||
oxErrf("Editor tab deletion failed: {} ({}:{})\n", ex.what(), ex.src.file_name(), ex.src.line());
|
||||
} catch (std::exception const&ex) {
|
||||
oxErrf("Editor tab deletion failed: {}\n", ex.what());
|
||||
if (auto const err = m_editors.erase(it).moveTo(it)) {
|
||||
oxErrf("Editor tab deletion failed: {} ({}:{})\n", toStr(err), err.src.file_name(), err.src.line());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -478,12 +499,25 @@ ox::Error StudioUI::createOpenProject(ox::StringViewCR path) noexcept {
|
||||
|
||||
ox::Error StudioUI::openProjectPath(ox::StringParam path) noexcept {
|
||||
OX_REQUIRE_M(fs, keel::loadRomFs(path.view()));
|
||||
OX_RETURN_ERROR(keel::setRomFs(keelCtx(m_tctx), std::move(fs)));
|
||||
keel::DuplicateSet ds;
|
||||
OX_RETURN_ERROR(keel::setRomFs(keelCtx(m_tctx), std::move(fs), ds));
|
||||
if (ds.size()) {
|
||||
ox::String msg;
|
||||
msg += "Multiple files have the same UUID:\n";
|
||||
for (auto const &k : ds.keys()) {
|
||||
msg += ox::sfmt("\n\t{}:\n", k.toString());
|
||||
for (auto const &v : ds[k]) {
|
||||
msg += ox::sfmt("\t\t - {}\n", v);
|
||||
}
|
||||
}
|
||||
m_messagePopup.show(msg);
|
||||
}
|
||||
OX_RETURN_ERROR(
|
||||
ox::make_unique_catch<Project>(keelCtx(m_tctx), std::move(path), m_projectDataDir)
|
||||
.moveTo(m_project));
|
||||
m_sctx.project = m_project.get();
|
||||
turbine::setWindowTitle(m_tctx, ox::sfmt("{} - {}", keelCtx(m_tctx).appName, m_project->projectPath()));
|
||||
turbine::setWindowTitle(
|
||||
m_tctx, ox::sfmt("{} - {}", keelCtx(m_tctx).appName, m_project->projectPath()));
|
||||
m_deleteConfirmation.deleteFile.connect(m_sctx.project, &Project::deleteItem);
|
||||
m_copyFilePopup.makeCopy.connect(m_sctx.project, &Project::copyItem);
|
||||
m_newDirDialog.newDir.connect(m_sctx.project, &Project::mkdir);
|
||||
|
@ -52,11 +52,12 @@ class StudioUI: public ox::SignalHandler {
|
||||
"Close Application?",
|
||||
"There are files with unsaved changes. Close?"
|
||||
};
|
||||
ig::MessagePopup m_messagePopup{"Message", ""};
|
||||
MakeCopyPopup m_copyFilePopup;
|
||||
RenameFile m_renameFile;
|
||||
NewProject m_newProject;
|
||||
AboutPopup m_aboutPopup;
|
||||
ox::Array<Widget*, 9> const m_widgets {
|
||||
ox::Array<Widget*, 10> const m_widgets {
|
||||
&m_closeFileConfirm,
|
||||
&m_closeAppConfirm,
|
||||
&m_copyFilePopup,
|
||||
@ -66,6 +67,7 @@ class StudioUI: public ox::SignalHandler {
|
||||
&m_deleteConfirmation,
|
||||
&m_newDirDialog,
|
||||
&m_renameFile,
|
||||
&m_messagePopup,
|
||||
};
|
||||
bool m_showProjectExplorer = true;
|
||||
struct NavAction {
|
||||
|
@ -169,7 +169,9 @@ TextInput<ox::IString<MaxChars>> InputText(
|
||||
out.changed = ImGui::InputText(
|
||||
label.c_str(), out.text.data(), MaxChars + 1, flags, callback, user_data);
|
||||
if (out.changed) {
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
std::ignore = out.text.unsafeResize(ox::strlen(out.text.c_str()));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@ -186,7 +188,9 @@ TextInput<ox::IString<MaxChars>> InputTextWithHint(
|
||||
out.changed = ImGui::InputTextWithHint(
|
||||
label.c_str(), hint.c_str(), out.text.data(), MaxChars + 1, flags, callback, user_data);
|
||||
if (out.changed) {
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
std::ignore = out.text.unsafeResize(ox::strlen(out.text.c_str()));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@ -201,7 +205,9 @@ bool InputText(
|
||||
auto const out = ImGui::InputText(
|
||||
label.c_str(), text.data(), StrCap + 1, flags, callback, user_data);
|
||||
if (out) {
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
std::ignore = text.unsafeResize(ox::strlen(text.c_str()));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@ -223,6 +229,10 @@ PopupResponse PopupControlsOkCancel(
|
||||
ox::CStringViewCR ok = "OK",
|
||||
ox::CStringViewCR cancel = "Cancel");
|
||||
|
||||
PopupResponse PopupControlsOk(
|
||||
bool &popupOpen,
|
||||
ox::CStringViewCR ok);
|
||||
|
||||
[[nodiscard]]
|
||||
bool BeginPopup(turbine::Context &ctx, ox::CStringViewCR popupName, bool &show, ImVec2 const&sz = {285, 0});
|
||||
|
||||
@ -250,7 +260,7 @@ bool ComboBox(ox::CStringView lbl, ox::Span<const ox::String> list, size_t &sele
|
||||
/**
|
||||
*
|
||||
* @param lbl
|
||||
* @param callback
|
||||
* @param f callback function
|
||||
* @param selectedIdx
|
||||
* @return true if new value selected, false otherwise
|
||||
*/
|
||||
@ -285,7 +295,7 @@ bool ListBox(ox::CStringViewCR name, ox::SpanView<ox::String> const&list, size_t
|
||||
class FilePicker {
|
||||
private:
|
||||
bool m_show{};
|
||||
studio::StudioContext &m_sctx;
|
||||
StudioContext &m_sctx;
|
||||
ox::String const m_title;
|
||||
ox::String const m_fileExt;
|
||||
ImVec2 const m_size;
|
||||
@ -304,8 +314,8 @@ class FilePicker {
|
||||
|
||||
};
|
||||
|
||||
class QuestionPopup: public Widget {
|
||||
private:
|
||||
class Popup: public Widget {
|
||||
protected:
|
||||
enum class Stage {
|
||||
Closed,
|
||||
Opening,
|
||||
@ -314,12 +324,11 @@ class QuestionPopup: public Widget {
|
||||
Stage m_stage = Stage::Closed;
|
||||
bool m_open{};
|
||||
ox::String m_title;
|
||||
ox::String m_question;
|
||||
|
||||
public:
|
||||
ox::Signal<ox::Error(PopupResponse)> response;
|
||||
|
||||
QuestionPopup(ox::StringParam title, ox::StringParam question) noexcept;
|
||||
explicit Popup(ox::StringParam title) noexcept;
|
||||
|
||||
void open() noexcept;
|
||||
|
||||
@ -328,7 +337,33 @@ class QuestionPopup: public Widget {
|
||||
[[nodiscard]]
|
||||
bool isOpen() const noexcept;
|
||||
|
||||
void draw(StudioContext &ctx) noexcept;
|
||||
};
|
||||
|
||||
class QuestionPopup: public Popup {
|
||||
private:
|
||||
ox::String m_question;
|
||||
|
||||
public:
|
||||
ox::Signal<ox::Error(PopupResponse)> response;
|
||||
|
||||
QuestionPopup(ox::StringParam title, ox::StringParam question) noexcept;
|
||||
|
||||
void draw(StudioContext &ctx) noexcept override;
|
||||
|
||||
};
|
||||
|
||||
class MessagePopup: public Popup {
|
||||
private:
|
||||
ox::String m_msg;
|
||||
|
||||
public:
|
||||
ox::Signal<ox::Error(PopupResponse)> response;
|
||||
|
||||
MessagePopup(ox::StringParam title, ox::StringParam msg) noexcept;
|
||||
|
||||
void show(ox::StringParam msg) noexcept;
|
||||
|
||||
void draw(StudioContext &ctx) noexcept override;
|
||||
|
||||
};
|
||||
|
||||
|
@ -12,10 +12,12 @@
|
||||
namespace studio {
|
||||
|
||||
FDFilterItem::FDFilterItem(ox::StringViewCR pName, ox::StringViewCR pSpec) noexcept {
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
name.resize(pName.len() + 1);
|
||||
ox::strncpy(name.data(), pName.data(), pName.len());
|
||||
spec.resize(pSpec.len() + 1);
|
||||
ox::strncpy(spec.data(), pSpec.data(), pSpec.len());
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
}
|
||||
|
||||
static ox::Result<ox::String> toResult(nfdresult_t r, NFD::UniquePathN const&path) noexcept {
|
||||
|
@ -88,7 +88,7 @@ PopupResponse PopupControlsOk(
|
||||
auto out = PopupResponse::None;
|
||||
constexpr auto btnSz = ImVec2{50, BtnSz.y};
|
||||
ImGui::Separator();
|
||||
ImGui::SetCursorPosX(ImGui::GetContentRegionAvail().x - 101);
|
||||
ImGui::SetCursorPosX(ImGui::GetContentRegionAvail().x - 42);
|
||||
if (ImGui::Button(ok.c_str(), btnSz)) {
|
||||
popupOpen = false;
|
||||
out = PopupResponse::OK;
|
||||
@ -245,24 +245,28 @@ void FilePicker::show() noexcept {
|
||||
}
|
||||
|
||||
|
||||
QuestionPopup::QuestionPopup(ox::StringParam title, ox::StringParam question) noexcept:
|
||||
m_title{std::move(title)},
|
||||
m_question{std::move(question)} {
|
||||
Popup::Popup(ox::StringParam title) noexcept: m_title{std::move(title)} {
|
||||
}
|
||||
|
||||
void QuestionPopup::open() noexcept {
|
||||
void Popup::open() noexcept {
|
||||
m_stage = Stage::Opening;
|
||||
}
|
||||
|
||||
void QuestionPopup::close() noexcept {
|
||||
void Popup::close() noexcept {
|
||||
m_stage = Stage::Closed;
|
||||
m_open = false;
|
||||
}
|
||||
|
||||
bool QuestionPopup::isOpen() const noexcept {
|
||||
bool Popup::isOpen() const noexcept {
|
||||
return m_open;
|
||||
}
|
||||
|
||||
|
||||
QuestionPopup::QuestionPopup(ox::StringParam title, ox::StringParam question) noexcept:
|
||||
Popup{std::move(title)},
|
||||
m_question{std::move(question)} {
|
||||
}
|
||||
|
||||
void QuestionPopup::draw(StudioContext &ctx) noexcept {
|
||||
switch (m_stage) {
|
||||
case Stage::Closed:
|
||||
@ -298,6 +302,49 @@ void QuestionPopup::draw(StudioContext &ctx) noexcept {
|
||||
}
|
||||
|
||||
|
||||
MessagePopup::MessagePopup(ox::StringParam title, ox::StringParam msg) noexcept:
|
||||
Popup{std::move(title)},
|
||||
m_msg{std::move(msg)} {
|
||||
}
|
||||
|
||||
void MessagePopup::show(ox::StringParam msg) noexcept {
|
||||
m_msg = std::move(msg);
|
||||
open();
|
||||
}
|
||||
|
||||
void MessagePopup::draw(StudioContext &ctx) noexcept {
|
||||
switch (m_stage) {
|
||||
case Stage::Closed:
|
||||
break;
|
||||
case Stage::Opening:
|
||||
ImGui::OpenPopup(m_title.c_str());
|
||||
m_stage = Stage::Open;
|
||||
m_open = true;
|
||||
[[fallthrough]];
|
||||
case Stage::Open:
|
||||
centerNextWindow(ctx.tctx);
|
||||
ImGui::SetNextWindowSize({});
|
||||
constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
|
||||
if (ImGui::BeginPopupModal(m_title.c_str(), &m_open, modalFlags)) {
|
||||
ImGui::Text("%s", m_msg.c_str());
|
||||
auto const r = PopupControlsOk(m_open, "OK");
|
||||
switch (r) {
|
||||
case PopupResponse::None:
|
||||
break;
|
||||
case PopupResponse::OK:
|
||||
response.emit(r);
|
||||
close();
|
||||
break;
|
||||
case PopupResponse::Cancel:
|
||||
break;
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool s_mainWinHasFocus{};
|
||||
bool mainWinHasFocus() noexcept {
|
||||
return s_mainWinHasFocus;
|
||||
|
@ -44,10 +44,10 @@ static ox::Result<std::size_t> findPreloadSection() noexcept {
|
||||
// media section
|
||||
constexpr auto headerP2 = "DER_____________";
|
||||
constexpr auto headerP1 = "KEEL_PRELOAD_HEA";
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
constexpr auto headerP1Len = ox::strlen(headerP2);
|
||||
constexpr auto headerP2Len = ox::strlen(headerP1);
|
||||
constexpr auto headerLen = headerP1Len + headerP2Len;
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
for (auto current = MEM_ROM; current < reinterpret_cast<char*>(0x0a000000); current += headerLen) {
|
||||
if (memcmp(current, headerP1, headerP1Len) == 0 &&
|
||||
memcmp(current + headerP1Len, headerP2, headerP2Len) == 0) {
|
||||
|
@ -18,7 +18,9 @@ ox::String getClipboardText(Context &ctx) noexcept {
|
||||
|
||||
void setClipboardText(Context &ctx, ox::StringViewCR text) noexcept {
|
||||
auto cstr = ox_malloca(text.bytes() + 1, char);
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
ox::strncpy(cstr.get(), text.data(), text.bytes());
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
glfwSetClipboardString(ctx.window, cstr.get());
|
||||
}
|
||||
|
||||
|
@ -267,7 +267,9 @@ ox::Error setWindowIcon(Context &ctx, ox::SpanView<ox::SpanView<uint8_t>> const
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user