@@ -131,8 +131,9 @@ add_custom_target(generate_protocols ALL
|
|||||||
add_executable(waylight
|
add_executable(waylight
|
||||||
${GEN_C_PRIVATES}
|
${GEN_C_PRIVATES}
|
||||||
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/App.cpp
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/TextRenderer.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/TextRenderer.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src/ImGui.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src/App.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Tick.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/Tick.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp
|
||||||
)
|
)
|
||||||
|
|||||||
21
src/App.cpp
21
src/App.cpp
@@ -5,16 +5,16 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <span>
|
|
||||||
#include <unordered_set>
|
|
||||||
#include <vector>
|
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <span>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <sys/signalfd.h>
|
#include <sys/signalfd.h>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <unordered_set>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <GLES3/gl3.h>
|
#include <GLES3/gl3.h>
|
||||||
#include <fontconfig/fontconfig.h>
|
#include <fontconfig/fontconfig.h>
|
||||||
@@ -190,6 +190,15 @@ auto App::init_wayland() -> void
|
|||||||
bool alt = app->m_kbd.mod_active("Mod1");
|
bool alt = app->m_kbd.mod_active("Mod1");
|
||||||
bool meta = app->m_kbd.mod_active("Mod4");
|
bool meta = app->m_kbd.mod_active("Mod4");
|
||||||
if (!(ctrl || alt || meta)) {
|
if (!(ctrl || alt || meta)) {
|
||||||
|
if (sym == XKB_KEY_Left) {
|
||||||
|
app->m_kbd.typing.push_back(0);
|
||||||
|
} else if (sym == XKB_KEY_Down) {
|
||||||
|
app->m_kbd.typing.push_back(1);
|
||||||
|
} else if (sym == XKB_KEY_Up) {
|
||||||
|
app->m_kbd.typing.push_back(2);
|
||||||
|
} else if (sym == XKB_KEY_Right) {
|
||||||
|
app->m_kbd.typing.push_back(3);
|
||||||
|
} else {
|
||||||
u32 cp = xkb_keysym_to_utf32(sym);
|
u32 cp = xkb_keysym_to_utf32(sym);
|
||||||
if (cp >= 0x20) {
|
if (cp >= 0x20) {
|
||||||
char buf[8];
|
char buf[8];
|
||||||
@@ -198,6 +207,7 @@ auto App::init_wayland() -> void
|
|||||||
app->m_kbd.typing.push_utf8(buf);
|
app->m_kbd.typing.push_utf8(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
xkb_keysym_t sym
|
xkb_keysym_t sym
|
||||||
= xkb_state_key_get_one_sym(app->m_kbd.xkb_state_v, kc);
|
= xkb_state_key_get_one_sym(app->m_kbd.xkb_state_v, kc);
|
||||||
@@ -300,7 +310,7 @@ auto App::init_egl() -> void
|
|||||||
|
|
||||||
InitWindow(m_win_w, m_win_h, "");
|
InitWindow(m_win_w, m_win_h, "");
|
||||||
|
|
||||||
m_tr = TextRenderer();
|
m_tr = std::make_shared<TextRenderer>();
|
||||||
auto const font = find_font_path();
|
auto const font = find_font_path();
|
||||||
assert(font && "Could not find font");
|
assert(font && "Could not find font");
|
||||||
std::vector<std::filesystem::path> fallback_paths;
|
std::vector<std::filesystem::path> fallback_paths;
|
||||||
@@ -332,8 +342,7 @@ auto App::init_egl() -> void
|
|||||||
TraceLog(LOG_WARNING,
|
TraceLog(LOG_WARNING,
|
||||||
"No fallback fonts found; some glyphs may render as missing");
|
"No fallback fonts found; some glyphs may render as missing");
|
||||||
}
|
}
|
||||||
auto const font_handle
|
auto const font_handle = m_tr->load_font(*font, std::span(fallback_paths));
|
||||||
= m_tr->load_font(*font, std::span(fallback_paths));
|
|
||||||
assert(font_handle && "Could not load font");
|
assert(font_handle && "Could not load font");
|
||||||
m_font = *font_handle;
|
m_font = *font_handle;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ private:
|
|||||||
}
|
}
|
||||||
} m_kbd;
|
} m_kbd;
|
||||||
|
|
||||||
std::optional<TextRenderer> m_tr { std::nullopt };
|
std::shared_ptr<TextRenderer> m_tr { nullptr };
|
||||||
FontHandle m_font;
|
FontHandle m_font;
|
||||||
|
|
||||||
enum_array<Theme, ColorScheme> m_themes { make_default_themes() };
|
enum_array<Theme, ColorScheme> m_themes { make_default_themes() };
|
||||||
|
|||||||
26
src/ImGui.cpp
Normal file
26
src/ImGui.cpp
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#include "ImGui.hpp"
|
||||||
|
|
||||||
|
ImGui::ImGui(std::shared_ptr<TextRenderer> text_renderer)
|
||||||
|
: m_text_renderer(text_renderer)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui::begin(
|
||||||
|
std::pmr::vector<u32> const input_runes, bool ctrl, bool shift)
|
||||||
|
{
|
||||||
|
m_input_runes = input_runes;
|
||||||
|
m_ctrl = ctrl;
|
||||||
|
m_shift = shift;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui::end() { }
|
||||||
|
|
||||||
|
auto ImGui::text_input(std::size_t id, std::pmr::string &str, Rectangle rec,
|
||||||
|
TextInputOptions options) -> std::bitset<2>
|
||||||
|
{
|
||||||
|
bool submitted { false };
|
||||||
|
bool changed { false };
|
||||||
|
|
||||||
|
return std::bitset<2> { static_cast<unsigned long long>(
|
||||||
|
(submitted ? 1 : 0) | (changed ? 2 : 0)) };
|
||||||
|
}
|
||||||
61
src/ImGui.hpp
Normal file
61
src/ImGui.hpp
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <bitset>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include <raylib.h>
|
||||||
|
|
||||||
|
#include "TextRenderer.hpp"
|
||||||
|
|
||||||
|
struct TextInputOptions {
|
||||||
|
bool multiline { false };
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ImGui {
|
||||||
|
ImGui(std::shared_ptr<TextRenderer> text_renderer);
|
||||||
|
|
||||||
|
ImGui(ImGui const &) = delete;
|
||||||
|
auto operator=(ImGui const &) -> ImGui & = delete;
|
||||||
|
ImGui(ImGui &&) = default;
|
||||||
|
auto operator=(ImGui &&) -> ImGui & = default;
|
||||||
|
|
||||||
|
void begin(std::pmr::vector<u32> const input_runes, bool ctrl, bool shift);
|
||||||
|
void end();
|
||||||
|
|
||||||
|
// Bit 0 -> Submitted
|
||||||
|
// Bit 1 -> String changed
|
||||||
|
auto text_input(std::size_t id, std::pmr::string &str, Rectangle rec,
|
||||||
|
TextInputOptions options = {}) -> std::bitset<2>;
|
||||||
|
|
||||||
|
[[nodiscard]] inline auto id(std::string_view const str) -> std::size_t
|
||||||
|
{
|
||||||
|
std::hash<std::string_view> hasher;
|
||||||
|
return hasher(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct TextInputState {
|
||||||
|
int current_rune_idx { 0 };
|
||||||
|
};
|
||||||
|
|
||||||
|
std::unordered_map<std::size_t, TextInputState> m_ti_states;
|
||||||
|
std::size_t m_focused {};
|
||||||
|
std::pmr::vector<u32> m_input_runes {}; // 0123 <-> hjkl arrow keys
|
||||||
|
bool m_ctrl {};
|
||||||
|
bool m_shift {};
|
||||||
|
|
||||||
|
std::shared_ptr<TextRenderer> m_text_renderer {};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ImGuiGuard {
|
||||||
|
ImGuiGuard(ImGui *imgui, std::pmr::vector<u32> const input_runes, bool ctrl,
|
||||||
|
bool shift)
|
||||||
|
: m_imgui(imgui)
|
||||||
|
{
|
||||||
|
m_imgui->begin(input_runes, ctrl, shift);
|
||||||
|
}
|
||||||
|
~ImGuiGuard() { m_imgui->end(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
ImGui *m_imgui { nullptr };
|
||||||
|
};
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
struct hb_face_t;
|
struct hb_face_t;
|
||||||
struct hb_font_t;
|
struct hb_font_t;
|
||||||
struct FT_FaceRec_;
|
struct FT_FaceRec_;
|
||||||
using FT_Face = FT_FaceRec_*;
|
using FT_Face = FT_FaceRec_ *;
|
||||||
|
|
||||||
namespace msdfgen {
|
namespace msdfgen {
|
||||||
class FontHandle;
|
class FontHandle;
|
||||||
@@ -34,6 +34,7 @@ struct FontRuntime;
|
|||||||
struct TextRenderer {
|
struct TextRenderer {
|
||||||
TextRenderer(); // Requires raylib to be initialized!
|
TextRenderer(); // Requires raylib to be initialized!
|
||||||
~TextRenderer();
|
~TextRenderer();
|
||||||
|
|
||||||
TextRenderer(TextRenderer const &) = delete;
|
TextRenderer(TextRenderer const &) = delete;
|
||||||
auto operator=(TextRenderer const &) -> TextRenderer & = delete;
|
auto operator=(TextRenderer const &) -> TextRenderer & = delete;
|
||||||
TextRenderer(TextRenderer &&) = default;
|
TextRenderer(TextRenderer &&) = default;
|
||||||
@@ -120,9 +121,8 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
static auto flush_font(FontRuntime &rt, FontData &fd) -> void;
|
static auto flush_font(FontRuntime &rt, FontData &fd) -> void;
|
||||||
static auto allocate_region(
|
static auto allocate_region(FontRuntime &rt, FontData &fd, int width,
|
||||||
FontRuntime &rt, FontData &fd, int width, int height)
|
int height) -> std::optional<std::pair<int, int>>;
|
||||||
-> std::optional<std::pair<int, int>>;
|
|
||||||
static auto upload_region(FontData &fd, int dst_x, int dst_y, int width,
|
static auto upload_region(FontData &fd, int dst_x, int dst_y, int width,
|
||||||
int height, std::vector<Color> const &buffer) -> void;
|
int height, std::vector<Color> const &buffer) -> void;
|
||||||
static auto generate_glyph(FontRuntime &rt, FontData &fd, u32 glyph_index)
|
static auto generate_glyph(FontRuntime &rt, FontData &fd, u32 glyph_index)
|
||||||
|
|||||||
Reference in New Issue
Block a user