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