d
This commit is contained in:
parent
fc6e4ef50f
commit
63ab0724a1
6 changed files with 310 additions and 309 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,3 +3,4 @@ out
|
|||
.idea
|
||||
cmake-build-debug
|
||||
build
|
||||
**/.DS_Store
|
||||
|
|
|
@ -41,11 +41,11 @@ if (WIN32)
|
|||
include_directories("include/windows")
|
||||
target_link_libraries (Keishiki PRIVATE freetype bgfx bx ${PROJECT_SOURCE_DIR}/lib/x64/SDL2.lib ${PROJECT_SOURCE_DIR}/lib/x64/SDL2main.lib)
|
||||
elseif (APPLE)
|
||||
target_link_libraries (Keishiki PRIVATE freetype bgfx bx SDL3::SDL3 fmt glaze_glaze)
|
||||
target_link_libraries (Keishiki PRIVATE bgfx bx SDL3::SDL3 fmt)
|
||||
else ()
|
||||
find_package(SDL3 REQUIRED CONFIG REQUIRED COMPONENTS SDL3-shared)
|
||||
find_package(ECM REQUIRED NO_MODULE)
|
||||
set(CMAKE_MODULE_PATH ${ECM_FIND_MODULE_DIR})
|
||||
find_package(Wayland REQUIRED Egl)
|
||||
target_link_libraries (Keishiki PRIVATE freetype bgfx bx SDL3::SDL3 ${Wayland_LIBRARIES} fmt glaze_glaze)
|
||||
target_link_libraries (Keishiki PRIVATE bgfx bx SDL3::SDL3 ${Wayland_LIBRARIES} fmt)
|
||||
endif ()
|
||||
|
|
|
@ -47,13 +47,13 @@ namespace K {
|
|||
bgfxInit.resolution.reset = BGFX_RESET_VSYNC | BGFX_RESET_HIDPI;
|
||||
|
||||
#if BX_PLATFORM_WINDOWS
|
||||
bgfxInit.platformData.nwh = SDL_GetProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL);
|
||||
bgfxInit.platformData.nwh = SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL);
|
||||
#elif BX_PLATFORM_OSX
|
||||
bgfxInit.platformData.nwh = SDL_GetProperty(SDL_GetWindowProperties(app_state.window), SDL_PROP_WINDOW_COCOA_WINDOW_POINTER, NULL);
|
||||
bgfxInit.platformData.nwh = SDL_GetPointerProperty(SDL_GetWindowProperties(app_state.window), SDL_PROP_WINDOW_COCOA_WINDOW_POINTER, NULL);
|
||||
bgfx::renderFrame();
|
||||
#elif BX_PLATFORM_LINUX
|
||||
if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0) {
|
||||
bgfxInit.platformData.ndt = SDL_GetProperty(SDL_GetWindowProperties(app_state.window), SDL_PROP_WINDOW_X11_DISPLAY_POINTER, NULL);
|
||||
bgfxInit.platformData.ndt = SDL_GetPointerProperty(SDL_GetWindowProperties(app_state.window), SDL_PROP_WINDOW_X11_DISPLAY_POINTER, NULL);
|
||||
bgfxInit.platformData.nwh = (void*)SDL_GetNumberProperty(SDL_GetWindowProperties(app_state.window), SDL_PROP_WINDOW_X11_WINDOW_NUMBER, 0);
|
||||
}
|
||||
#if WL_EGL_PLATFORM
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include "Graphics.h"
|
||||
#include <Keishiki.h>
|
||||
#include <Resource.h>
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
//#include <ft2build.h>
|
||||
//#include FT_FREETYPE_H
|
||||
|
||||
#include <bx/math.h>
|
||||
|
||||
|
@ -30,94 +30,94 @@ namespace {
|
|||
1, 2, 3
|
||||
};
|
||||
|
||||
FT_Library library;
|
||||
FT_Error error;
|
||||
|
||||
struct Glyph {
|
||||
bgfx::TextureHandle tex = { bgfx::kInvalidHandle };
|
||||
u32 w = 0, h = 0;
|
||||
i32 x = 0, y = 0, adv_x = 0, adv_y = 0;
|
||||
};
|
||||
|
||||
struct Font {
|
||||
FT_Face face = nullptr;
|
||||
K::Dict<K::Char, Glyph> cache{};
|
||||
|
||||
Glyph& get_char(K::Char c) {
|
||||
if (cache.find(c) == cache.end()) {
|
||||
FT_GlyphSlot slot = face->glyph;
|
||||
|
||||
error = FT_Load_Char(face, c, FT_LOAD_RENDER);
|
||||
if (error) {
|
||||
K::Log(K::K_L_Error, "Failed to load character");
|
||||
}
|
||||
|
||||
if (slot->bitmap.width != 0) {
|
||||
const bgfx::Memory *buf = bgfx::copy(slot->bitmap.buffer, slot->bitmap.pitch * slot->bitmap.rows);
|
||||
|
||||
cache.emplace(c, Glyph{
|
||||
bgfx::createTexture2D(
|
||||
slot->bitmap.width,
|
||||
slot->bitmap.rows,
|
||||
false,
|
||||
1,
|
||||
bgfx::TextureFormat::A8,
|
||||
BGFX_TEXTURE_NONE | BGFX_SAMPLER_UVW_CLAMP,
|
||||
buf
|
||||
),
|
||||
slot->bitmap.width,
|
||||
slot->bitmap.rows,
|
||||
slot->bitmap_left,
|
||||
slot->bitmap_top,
|
||||
static_cast<i32>(slot->advance.x),
|
||||
static_cast<i32>(slot->advance.y)
|
||||
});
|
||||
}
|
||||
else cache.emplace(c, Glyph{
|
||||
{ bgfx::kInvalidHandle },
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
static_cast<i32>(slot->advance.x),
|
||||
static_cast<i32>(slot->advance.y)
|
||||
});
|
||||
}
|
||||
return cache[c];
|
||||
}
|
||||
};
|
||||
|
||||
std::optional<Font> GetFont(const char *path) {
|
||||
Font f;
|
||||
|
||||
error = FT_New_Face(library, path, 0, &f.face);
|
||||
if (error == FT_Err_Unknown_File_Format) {
|
||||
K::Log(K::K_L_Error, "FreeType Unknown_File_Format");
|
||||
return std::nullopt;
|
||||
}
|
||||
else if (error) {
|
||||
K::Log(K::K_L_Error, "FreeType font loading error");
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
error = FT_Set_Char_Size(f.face, 0, 20 * 64, 72, 72);
|
||||
if (error) {
|
||||
K::Log(K::K_L_Error, "FreeType Set_Char_Size error");
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
void DestroyFont(Font& f) {
|
||||
FT_Done_Face(f.face);
|
||||
for (auto & it : f.cache) {
|
||||
if (isValid(it.second.tex))
|
||||
bgfx::destroy(it.second.tex);
|
||||
}
|
||||
}
|
||||
|
||||
Font regular, bold;
|
||||
// FT_Library library;
|
||||
// FT_Error error;
|
||||
//
|
||||
// struct Glyph {
|
||||
// bgfx::TextureHandle tex = { bgfx::kInvalidHandle };
|
||||
// u32 w = 0, h = 0;
|
||||
// i32 x = 0, y = 0, adv_x = 0, adv_y = 0;
|
||||
// };
|
||||
//
|
||||
// struct Font {
|
||||
// FT_Face face = nullptr;
|
||||
// K::Dict<K::Char, Glyph> cache{};
|
||||
//
|
||||
// Glyph& get_char(K::Char c) {
|
||||
// if (cache.find(c) == cache.end()) {
|
||||
// FT_GlyphSlot slot = face->glyph;
|
||||
//
|
||||
// error = FT_Load_Char(face, c, FT_LOAD_RENDER);
|
||||
// if (error) {
|
||||
// K::Log(K::K_L_Error, "Failed to load character");
|
||||
// }
|
||||
//
|
||||
// if (slot->bitmap.width != 0) {
|
||||
// const bgfx::Memory *buf = bgfx::copy(slot->bitmap.buffer, slot->bitmap.pitch * slot->bitmap.rows);
|
||||
//
|
||||
// cache.emplace(c, Glyph{
|
||||
// bgfx::createTexture2D(
|
||||
// slot->bitmap.width,
|
||||
// slot->bitmap.rows,
|
||||
// false,
|
||||
// 1,
|
||||
// bgfx::TextureFormat::A8,
|
||||
// BGFX_TEXTURE_NONE | BGFX_SAMPLER_UVW_CLAMP,
|
||||
// buf
|
||||
// ),
|
||||
// slot->bitmap.width,
|
||||
// slot->bitmap.rows,
|
||||
// slot->bitmap_left,
|
||||
// slot->bitmap_top,
|
||||
// static_cast<i32>(slot->advance.x),
|
||||
// static_cast<i32>(slot->advance.y)
|
||||
// });
|
||||
// }
|
||||
// else cache.emplace(c, Glyph{
|
||||
// { bgfx::kInvalidHandle },
|
||||
// 0,
|
||||
// 0,
|
||||
// 0,
|
||||
// 0,
|
||||
// static_cast<i32>(slot->advance.x),
|
||||
// static_cast<i32>(slot->advance.y)
|
||||
// });
|
||||
// }
|
||||
// return cache[c];
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// std::optional<Font> GetFont(const char *path) {
|
||||
// Font f;
|
||||
//
|
||||
// error = FT_New_Face(library, path, 0, &f.face);
|
||||
// if (error == FT_Err_Unknown_File_Format) {
|
||||
// K::Log(K::K_L_Error, "FreeType Unknown_File_Format");
|
||||
// return std::nullopt;
|
||||
// }
|
||||
// else if (error) {
|
||||
// K::Log(K::K_L_Error, "FreeType font loading error");
|
||||
// return std::nullopt;
|
||||
// }
|
||||
//
|
||||
// error = FT_Set_Char_Size(f.face, 0, 20 * 64, 72, 72);
|
||||
// if (error) {
|
||||
// K::Log(K::K_L_Error, "FreeType Set_Char_Size error");
|
||||
// return std::nullopt;
|
||||
// }
|
||||
//
|
||||
// return f;
|
||||
// }
|
||||
//
|
||||
// void DestroyFont(Font& f) {
|
||||
// FT_Done_Face(f.face);
|
||||
// for (auto & it : f.cache) {
|
||||
// if (isValid(it.second.tex))
|
||||
// bgfx::destroy(it.second.tex);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Font regular, bold;
|
||||
bgfx::ProgramHandle imga_program;
|
||||
bgfx::ProgramHandle a_program;
|
||||
|
||||
|
@ -135,15 +135,15 @@ namespace {
|
|||
|
||||
namespace K::Graphics {
|
||||
bool Init() {
|
||||
error = FT_Init_FreeType(&library);
|
||||
if (error) {
|
||||
Log(K_L_Info, "FreeType init error: {}", error);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (auto f = GetFont("SourceHanSans-Regular.ttc")) regular = *f; else return false;
|
||||
if (auto f = GetFont("SourceHanSans-Bold.ttc")) bold = *f; else return false;
|
||||
// error = FT_Init_FreeType(&library);
|
||||
// if (error) {
|
||||
// Log(K_L_Info, "FreeType init error: {}", error);
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// if (auto f = GetFont("SourceHanSans-Regular.ttc")) regular = *f; else return false;
|
||||
// if (auto f = GetFont("SourceHanSans-Bold.ttc")) bold = *f; else return false;
|
||||
//
|
||||
pcvDecl.begin()
|
||||
.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float)
|
||||
.add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float)
|
||||
|
@ -167,9 +167,9 @@ namespace K::Graphics {
|
|||
}
|
||||
|
||||
void Shutdown() {
|
||||
DestroyFont(regular);
|
||||
DestroyFont(bold);
|
||||
FT_Done_FreeType(library);
|
||||
// DestroyFont(regular);
|
||||
// DestroyFont(bold);
|
||||
// FT_Done_FreeType(library);
|
||||
|
||||
bgfx::destroy(imga_program);
|
||||
bgfx::destroy(a_program);
|
||||
|
@ -227,130 +227,130 @@ namespace K::Graphics {
|
|||
DrawTexture(view_id, tex, pos_x, pos_y, w, h, (BGFX_STATE_DEFAULT | BGFX_STATE_BLEND_ALPHA) & ~(BGFX_STATE_WRITE_Z | BGFX_STATE_DEPTH_TEST_LESS), a_program);
|
||||
}
|
||||
|
||||
void WalkGlyph(u32 view_id, Char c, i32& pos_x, i32& pos_y) {
|
||||
Font *f = ®ular;
|
||||
|
||||
auto& [tx, w, h, l, t, x, y] = f->get_char(c);
|
||||
|
||||
pos_x += l;
|
||||
|
||||
pos_x += x >> 6;
|
||||
pos_y += y >> 6;
|
||||
}
|
||||
|
||||
void RenderWalkGlyph(u32 view_id, Char c, i32& pos_x, i32& pos_y, u32 col) {
|
||||
Font *f = ®ular;
|
||||
|
||||
auto& [tx, w, h, l, t, x, y] = f->get_char(c);
|
||||
|
||||
pos_x += l;
|
||||
|
||||
if (isValid(tx) && w != 0) {
|
||||
DrawTextureStencilAlpha(view_id, tx, pos_x, pos_y - (h - t), w, h);
|
||||
}
|
||||
|
||||
pos_x += x >> 6;
|
||||
pos_y += y >> 6;
|
||||
}
|
||||
|
||||
void RenderGlyph(u32 view_id, Char c, i32 pos_x, i32 pos_y, u32 col) {
|
||||
Font *f = ®ular;
|
||||
|
||||
auto& [tx, w, h, l, t, x, y] = f->get_char(c);
|
||||
|
||||
pos_x += l;
|
||||
|
||||
if (isValid(tx) && w != 0) {
|
||||
DrawTextureStencilAlpha(view_id, tx, pos_x, pos_y - (h - t), w, h);
|
||||
}
|
||||
|
||||
pos_x += x >> 6;
|
||||
pos_y += y >> 6;
|
||||
}
|
||||
|
||||
void WalkString(u32 view_id, const String& s, i32& pos_x, i32& pos_y) {
|
||||
for (const auto& c : s)
|
||||
WalkGlyph(view_id, c, pos_x, pos_y);
|
||||
}
|
||||
|
||||
void RenderString(u32 view_id, const String& s, i32 pos_x, i32 pos_y, u32 col) {
|
||||
for (const auto& c : s)
|
||||
RenderWalkGlyph(view_id, c, pos_x, pos_y, col);
|
||||
}
|
||||
|
||||
void WalkString(u32 view_id, String::const_iterator cbegin, String::const_iterator cend, i32& pos_x, i32& pos_y) {
|
||||
while (cbegin < cend)
|
||||
WalkGlyph(view_id, *cbegin++, pos_x, pos_y);
|
||||
}
|
||||
|
||||
void RenderString(u32 view_id, String::const_iterator cbegin, String::const_iterator cend, i32 pos_x, i32 pos_y, u32 col) {
|
||||
while (cbegin < cend)
|
||||
RenderGlyph(view_id, *cbegin++, pos_x, pos_y, col);
|
||||
}
|
||||
|
||||
void RenderStringCentered(u32 view_id, const String& s, i32 pos_x, i32 pos_y, u32 col) {
|
||||
i32 copy_x = 0, copy_y = 0;
|
||||
WalkString(view_id, s, copy_x, copy_y);
|
||||
RenderString(view_id, s, pos_x - copy_x / 2, pos_y, col);
|
||||
}
|
||||
|
||||
// I cannot reason this function, returns where the string would end if it was not halted
|
||||
i32 RenderSubstringBox(u32 view_id, const String& s, i32& pos_x, i32& pos_y, i32 reset_x, u32 w, u32 col, size_t s_end) {
|
||||
Font *f = ®ular;
|
||||
|
||||
String::const_iterator last = s.cbegin(), end = s.cend(), pos = std::find(last, end, u' '),
|
||||
halt = s_end > s.length() ? end : last + s_end;
|
||||
if (pos == end) { // Render the entire thing with hard break if we don't split at all
|
||||
String::const_iterator last_copy = last;
|
||||
i32 copy_x = pos_x, copy_y = pos_y;
|
||||
while (last != std::min(pos, halt)) {
|
||||
RenderGlyph(view_id, *last++, pos_x, pos_y, col);
|
||||
if (pos_x - reset_x > w) {
|
||||
pos_x = reset_x;
|
||||
pos_y -= f->face->size->metrics.height / 64;
|
||||
}
|
||||
if (last >= halt) {
|
||||
WalkString(view_id, last_copy, pos, copy_x, copy_y);
|
||||
return copy_x;
|
||||
};
|
||||
}
|
||||
}
|
||||
else while (last != end) { // Loop through all segments
|
||||
i32 copy_x = pos_x, old_x = pos_x, copy_y = pos_y;
|
||||
WalkString(view_id, last, pos, copy_x, copy_y);
|
||||
if (copy_x - reset_x > w) { // if walk exceeded max w
|
||||
copy_x = reset_x, copy_y = pos_y; // try walk again from leftmost of box, see if a soft break works; reset y from last walk
|
||||
WalkString(view_id, last, pos, copy_x, copy_y);
|
||||
if (copy_x - reset_x > w) { // soft break won't work, go back to old x and hard break
|
||||
pos_x = old_x;
|
||||
while (last != pos) {
|
||||
RenderGlyph(view_id, *last++, pos_x, pos_y, col);
|
||||
if (pos_x - reset_x > w) {
|
||||
pos_x = reset_x;
|
||||
pos_y -= f->face->size->metrics.height / 64;
|
||||
}
|
||||
if (last >= halt) return copy_x;
|
||||
}
|
||||
}
|
||||
else { // soft break and kill beginning space
|
||||
pos_x = reset_x;
|
||||
pos_y -= f->face->size->metrics.height / 64;
|
||||
last++;
|
||||
RenderString(view_id, last, std::min(pos, halt), pos_x, pos_y, col);
|
||||
if (last >= halt) return copy_x;
|
||||
}
|
||||
}
|
||||
else {
|
||||
RenderString(view_id, last, std::min(pos, halt), pos_x, pos_y, col);
|
||||
if (last >= halt) return copy_x;
|
||||
}
|
||||
|
||||
last = pos;
|
||||
if (pos != end)
|
||||
pos = std::find(std::next(pos), end, ' ');
|
||||
}
|
||||
return pos_x;
|
||||
}
|
||||
// void WalkGlyph(u32 view_id, Char c, i32& pos_x, i32& pos_y) {
|
||||
// Font *f = ®ular;
|
||||
//
|
||||
// auto& [tx, w, h, l, t, x, y] = f->get_char(c);
|
||||
//
|
||||
// pos_x += l;
|
||||
//
|
||||
// pos_x += x >> 6;
|
||||
// pos_y += y >> 6;
|
||||
// }
|
||||
//
|
||||
// void RenderWalkGlyph(u32 view_id, Char c, i32& pos_x, i32& pos_y, u32 col) {
|
||||
// Font *f = ®ular;
|
||||
//
|
||||
// auto& [tx, w, h, l, t, x, y] = f->get_char(c);
|
||||
//
|
||||
// pos_x += l;
|
||||
//
|
||||
// if (isValid(tx) && w != 0) {
|
||||
// DrawTextureStencilAlpha(view_id, tx, pos_x, pos_y - (h - t), w, h);
|
||||
// }
|
||||
//
|
||||
// pos_x += x >> 6;
|
||||
// pos_y += y >> 6;
|
||||
// }
|
||||
//
|
||||
// void RenderGlyph(u32 view_id, Char c, i32 pos_x, i32 pos_y, u32 col) {
|
||||
// Font *f = ®ular;
|
||||
//
|
||||
// auto& [tx, w, h, l, t, x, y] = f->get_char(c);
|
||||
//
|
||||
// pos_x += l;
|
||||
//
|
||||
// if (isValid(tx) && w != 0) {
|
||||
// DrawTextureStencilAlpha(view_id, tx, pos_x, pos_y - (h - t), w, h);
|
||||
// }
|
||||
//
|
||||
// pos_x += x >> 6;
|
||||
// pos_y += y >> 6;
|
||||
// }
|
||||
//
|
||||
// void WalkString(u32 view_id, const String& s, i32& pos_x, i32& pos_y) {
|
||||
// for (const auto& c : s)
|
||||
// WalkGlyph(view_id, c, pos_x, pos_y);
|
||||
// }
|
||||
//
|
||||
// void RenderString(u32 view_id, const String& s, i32 pos_x, i32 pos_y, u32 col) {
|
||||
// for (const auto& c : s)
|
||||
// RenderWalkGlyph(view_id, c, pos_x, pos_y, col);
|
||||
// }
|
||||
//
|
||||
// void WalkString(u32 view_id, String::const_iterator cbegin, String::const_iterator cend, i32& pos_x, i32& pos_y) {
|
||||
// while (cbegin < cend)
|
||||
// WalkGlyph(view_id, *cbegin++, pos_x, pos_y);
|
||||
// }
|
||||
//
|
||||
// void RenderString(u32 view_id, String::const_iterator cbegin, String::const_iterator cend, i32 pos_x, i32 pos_y, u32 col) {
|
||||
// while (cbegin < cend)
|
||||
// RenderGlyph(view_id, *cbegin++, pos_x, pos_y, col);
|
||||
// }
|
||||
//
|
||||
// void RenderStringCentered(u32 view_id, const String& s, i32 pos_x, i32 pos_y, u32 col) {
|
||||
// i32 copy_x = 0, copy_y = 0;
|
||||
// WalkString(view_id, s, copy_x, copy_y);
|
||||
// RenderString(view_id, s, pos_x - copy_x / 2, pos_y, col);
|
||||
// }
|
||||
//
|
||||
// // I cannot reason this function, returns where the string would end if it was not halted
|
||||
// i32 RenderSubstringBox(u32 view_id, const String& s, i32& pos_x, i32& pos_y, i32 reset_x, u32 w, u32 col, size_t s_end) {
|
||||
// Font *f = ®ular;
|
||||
//
|
||||
// String::const_iterator last = s.cbegin(), end = s.cend(), pos = std::find(last, end, u' '),
|
||||
// halt = s_end > s.length() ? end : last + s_end;
|
||||
// if (pos == end) { // Render the entire thing with hard break if we don't split at all
|
||||
// String::const_iterator last_copy = last;
|
||||
// i32 copy_x = pos_x, copy_y = pos_y;
|
||||
// while (last != std::min(pos, halt)) {
|
||||
// RenderGlyph(view_id, *last++, pos_x, pos_y, col);
|
||||
// if (pos_x - reset_x > w) {
|
||||
// pos_x = reset_x;
|
||||
// pos_y -= f->face->size->metrics.height / 64;
|
||||
// }
|
||||
// if (last >= halt) {
|
||||
// WalkString(view_id, last_copy, pos, copy_x, copy_y);
|
||||
// return copy_x;
|
||||
// };
|
||||
// }
|
||||
// }
|
||||
// else while (last != end) { // Loop through all segments
|
||||
// i32 copy_x = pos_x, old_x = pos_x, copy_y = pos_y;
|
||||
// WalkString(view_id, last, pos, copy_x, copy_y);
|
||||
// if (copy_x - reset_x > w) { // if walk exceeded max w
|
||||
// copy_x = reset_x, copy_y = pos_y; // try walk again from leftmost of box, see if a soft break works; reset y from last walk
|
||||
// WalkString(view_id, last, pos, copy_x, copy_y);
|
||||
// if (copy_x - reset_x > w) { // soft break won't work, go back to old x and hard break
|
||||
// pos_x = old_x;
|
||||
// while (last != pos) {
|
||||
// RenderGlyph(view_id, *last++, pos_x, pos_y, col);
|
||||
// if (pos_x - reset_x > w) {
|
||||
// pos_x = reset_x;
|
||||
// pos_y -= f->face->size->metrics.height / 64;
|
||||
// }
|
||||
// if (last >= halt) return copy_x;
|
||||
// }
|
||||
// }
|
||||
// else { // soft break and kill beginning space
|
||||
// pos_x = reset_x;
|
||||
// pos_y -= f->face->size->metrics.height / 64;
|
||||
// last++;
|
||||
// RenderString(view_id, last, std::min(pos, halt), pos_x, pos_y, col);
|
||||
// if (last >= halt) return copy_x;
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// RenderString(view_id, last, std::min(pos, halt), pos_x, pos_y, col);
|
||||
// if (last >= halt) return copy_x;
|
||||
// }
|
||||
//
|
||||
// last = pos;
|
||||
// if (pos != end)
|
||||
// pos = std::find(std::next(pos), end, ' ');
|
||||
// }
|
||||
// return pos_x;
|
||||
// }
|
||||
|
||||
void Composite(bgfx::FrameBufferHandle fb, bgfx::TextureHandle composite, bgfx::TextureHandle from, Blending mode, u16 w, u16 h, f32 proj[16], f32 transform[16]) {
|
||||
static f32 pack[4]{};
|
||||
|
|
|
@ -3,71 +3,71 @@
|
|||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <Keishiki.h>
|
||||
#include <glaze/glaze.hpp>
|
||||
//#include <glaze/glaze.hpp>
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include <stb_image.h>
|
||||
|
||||
namespace glz {
|
||||
template <>
|
||||
struct meta<ImVec2> {
|
||||
using T = ImVec2;
|
||||
static constexpr auto value = array(&T::x, &T::y);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct meta<K::Uniform> {
|
||||
using T = K::Uniform;
|
||||
static constexpr auto value = object(&T::name,
|
||||
&T::val,
|
||||
// &T::connection, // todo need lookup
|
||||
&T::status);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct meta<K::Sampler> {
|
||||
using T = K::Sampler;
|
||||
static constexpr auto value = object(&T::name);
|
||||
// &T::resource, // todo need lookup
|
||||
// &T::dims, // todo need lookup
|
||||
// &T::frame); // todo need lookup
|
||||
};
|
||||
|
||||
template <>
|
||||
struct meta<K::VisualTrack> {
|
||||
using T = K::VisualTrack;
|
||||
static constexpr auto value = object(&T::shader, &T::uniforms, &T::samplers);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct meta<K::Plugboard::Plugboard> {
|
||||
using T = K::Plugboard::Plugboard;
|
||||
static constexpr auto value = object(); // todo this one is actually so complicated
|
||||
};
|
||||
|
||||
template <>
|
||||
struct meta<K::CompositionState> {
|
||||
using T = K::CompositionState;
|
||||
static constexpr auto value = object(&T::name,
|
||||
&T::current_frame,
|
||||
&T::frame_max,
|
||||
&T::fps,
|
||||
&T::width,
|
||||
&T::height,
|
||||
&T::layers,
|
||||
&T::active,
|
||||
&T::selected,
|
||||
&T::disabled,
|
||||
&T::plugboard);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct meta<K::ProjectState> {
|
||||
using T = K::ProjectState;
|
||||
static constexpr auto value = object(&T::compositions);
|
||||
};
|
||||
|
||||
}
|
||||
//namespace glz {
|
||||
//template <>
|
||||
//struct meta<ImVec2> {
|
||||
// using T = ImVec2;
|
||||
// static constexpr auto value = array(&T::x, &T::y);
|
||||
//};
|
||||
//
|
||||
//template <>
|
||||
//struct meta<K::Uniform> {
|
||||
// using T = K::Uniform;
|
||||
// static constexpr auto value = object(&T::name,
|
||||
// &T::val,
|
||||
// // &T::connection, // todo need lookup
|
||||
// &T::status);
|
||||
//};
|
||||
//
|
||||
//template <>
|
||||
//struct meta<K::Sampler> {
|
||||
// using T = K::Sampler;
|
||||
// static constexpr auto value = object(&T::name);
|
||||
// // &T::resource, // todo need lookup
|
||||
// // &T::dims, // todo need lookup
|
||||
// // &T::frame); // todo need lookup
|
||||
//};
|
||||
//
|
||||
//template <>
|
||||
//struct meta<K::VisualTrack> {
|
||||
// using T = K::VisualTrack;
|
||||
// static constexpr auto value = object(&T::shader, &T::uniforms, &T::samplers);
|
||||
//};
|
||||
//
|
||||
//template <>
|
||||
//struct meta<K::Plugboard::Plugboard> {
|
||||
// using T = K::Plugboard::Plugboard;
|
||||
// static constexpr auto value = object(); // todo this one is actually so complicated
|
||||
//};
|
||||
//
|
||||
//template <>
|
||||
//struct meta<K::CompositionState> {
|
||||
// using T = K::CompositionState;
|
||||
// static constexpr auto value = object(&T::name,
|
||||
// &T::current_frame,
|
||||
// &T::frame_max,
|
||||
// &T::fps,
|
||||
// &T::width,
|
||||
// &T::height,
|
||||
// &T::layers,
|
||||
// &T::active,
|
||||
// &T::selected,
|
||||
// &T::disabled,
|
||||
// &T::plugboard);
|
||||
//};
|
||||
//
|
||||
//template <>
|
||||
//struct meta<K::ProjectState> {
|
||||
// using T = K::ProjectState;
|
||||
// static constexpr auto value = object(&T::compositions);
|
||||
//};
|
||||
//
|
||||
//}
|
||||
|
||||
namespace K::Resource {
|
||||
void ReadProject() {
|
||||
|
@ -85,10 +85,10 @@ namespace K::Resource {
|
|||
return;
|
||||
|
||||
while (*filelist) {
|
||||
auto ec = glz::read_file_json(app_state.project, *filelist, String{});
|
||||
if (ec.ec != glz::error_code::none) {
|
||||
Log(K_L_Error, "{}", ec.includer_error);
|
||||
}
|
||||
// auto ec = glz::read_file_json(app_state.project, *filelist, String{});
|
||||
// if (ec.ec != glz::error_code::none) {
|
||||
// Log(K_L_Error, "{}", ec.includer_error);
|
||||
// }
|
||||
filelist++;
|
||||
}
|
||||
|
||||
|
@ -121,10 +121,10 @@ namespace K::Resource {
|
|||
return;
|
||||
|
||||
while (*filelist) {
|
||||
auto ec = glz::write_file_json(app_state.project, *filelist, String{});
|
||||
if (ec.ec != glz::error_code::none) {
|
||||
Log(K_L_Error, "{}", ec.includer_error);
|
||||
}
|
||||
// auto ec = glz::write_file_json(app_state.project, *filelist, String{});
|
||||
// if (ec.ec != glz::error_code::none) {
|
||||
// Log(K_L_Error, "{}", ec.includer_error);
|
||||
// }
|
||||
filelist++;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,16 +28,16 @@ namespace K::Graphics {
|
|||
void DrawTextureStencilAlpha(u32 view_id, const bgfx::TextureHandle& tex, i32 pos_x, i32 pos_y, u32 w, u32 h);
|
||||
|
||||
// Text
|
||||
void WalkGlyph(u32 view_id, Char c, i32& pos_x, i32& pos_y);
|
||||
void RenderWalkGlyph(u32 view_id, Char c, i32& pos_x, i32& pos_y, u32 col);
|
||||
void RenderGlyph(u32 view_id, Char c, i32 pos_x, i32 pos_y, u32 col);
|
||||
|
||||
void WalkString(u32 view_id, const String& s, i32& pos_x, i32& pos_y);
|
||||
void RenderString(u32 view_id, const String& s, i32 pos_x, i32 pos_y, u32 col);
|
||||
void WalkString(u32 view_id, String::const_iterator cbegin, String::const_iterator cend, i32& pos_x, i32& pos_y);
|
||||
void RenderString(u32 view_id, String::const_iterator cbegin, String::const_iterator cend, i32 pos_x, i32 pos_y, u32 col);
|
||||
|
||||
i32 RenderSubstringBox(u32 view_id, const String& s, i32& pos_x, i32& pos_y, i32 reset_x, u32 w, u32 col, size_t s_end = String::npos);
|
||||
// void WalkGlyph(u32 view_id, Char c, i32& pos_x, i32& pos_y);
|
||||
// void RenderWalkGlyph(u32 view_id, Char c, i32& pos_x, i32& pos_y, u32 col);
|
||||
// void RenderGlyph(u32 view_id, Char c, i32 pos_x, i32 pos_y, u32 col);
|
||||
//
|
||||
// void WalkString(u32 view_id, const String& s, i32& pos_x, i32& pos_y);
|
||||
// void RenderString(u32 view_id, const String& s, i32 pos_x, i32 pos_y, u32 col);
|
||||
// void WalkString(u32 view_id, String::const_iterator cbegin, String::const_iterator cend, i32& pos_x, i32& pos_y);
|
||||
// void RenderString(u32 view_id, String::const_iterator cbegin, String::const_iterator cend, i32 pos_x, i32 pos_y, u32 col);
|
||||
//
|
||||
// i32 RenderSubstringBox(u32 view_id, const String& s, i32& pos_x, i32& pos_y, i32 reset_x, u32 w, u32 col, size_t s_end = String::npos);
|
||||
|
||||
enum Blending {
|
||||
K_V_AlphaOver = 0,
|
||||
|
|
Loading…
Add table
Reference in a new issue