/
SilovAndrey
/
easel_examples
Обзор
Документация
Войти
/
SilovAndrey
/
easel_examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
common/app_impl.cpp
175 строк
4 KB
Arch Hipper
Set compiled tipography exampl
14 июл 2026, 05:25
14 июл 2026, 05:25
7ea4243
Код
Авторство
О чём код?
module; #include <chrono> #include <filesystem> #include <iostream> #include <functional> #include <memory> //#include <wayland-client-protocol.h> //#include "xdg-shell-client-protocol.h" #include "thorvg.h" module App; import Wayland; import Wayland.TopLevelSurface; import Wayland.EGLBackend; import Wayland.Log; import Resource; namespace fs = std::filesystem; float elapsed_ = 0; // rendering elapsed time // namespace resource // { void init_paths() { // resource::Path p(fs::current_path() / "resources"); // std::cout<<"ppp "<<p<<std::endl; resource::add_path(fs::current_path() / "resources"); resource::add_path(fs::current_path() / "resources/images"); //resource::add_path(fs::current_path() / "resources/fonts"); } // This is declared in font.hpp // fs::path get_user_fonts_directory() // { // return fs::path(fs::current_path() / "resources/fonts"); // } // } using namespace WL; class XDGWindow: public TopLevelSurface, public SensitiveLayer { public: XDGWindow(uint32_t width, uint32_t height) : TopLevelSurface("MyApp", width, height) , m_corrupt(false) , m_elapsed(0.0) { set_input_handler(this); commit(); } std::function<void()> on_closed; bool animate = false; private: void key(const Keyboard &kb) override { std::cout<<"key: "<<kb.symbol()<<" str "<<kb.utf8()<<std::endl; } void on_close() override { //m_closed = true; animate = false; if (on_closed) on_closed(); } void on_configure(uint32_t w, uint32_t h) override { m_glCanvas.reset(tvg::GlCanvas::gen()); if (m_glCanvas) { canvas_resize(m_width, m_height); //on_render(scale()); } else throw std::runtime_error("Failed to initialize ThorVG GL canvas target"); } void on_resize(uint32_t w, uint32_t h) override { canvas_resize(m_width, m_height); refresh(); } void on_render(float scale) override { auto start = std::chrono::steady_clock::now(); easel::canvas cvs(easel::make_state(m_glCanvas.get(), scale)); ::draw(cvs, m_width, m_height); cvs.flush(); if (animate) m_glCanvas->update(); m_glCanvas->draw(); m_glCanvas->sync(); //context().present(); if (animate) { //m_glCanvas->update(); refresh(); } auto stop = std::chrono::steady_clock::now(); m_elapsed = std::chrono::duration<double>{stop - start}.count(); } void on_scale_changed(float sc) override { // m_width *= sc; m_height *= sc; } void canvas_resize(uint32_t w, uint32_t h) { auto ctx = m_context->gpu_native(); auto res = m_glCanvas->target(ctx.display, ctx.surface, ctx.context, 0, w, h, tvg::ColorSpace::ABGR8888S); if (res != tvg::Result::Success) throw std::runtime_error("Failed to initialize ThorVG GL canvas target"); }; double m_elapsed; bool m_corrupt; //по идее порядок уничтожения важен но на практике для ThorVG нет. std::unique_ptr<tvg::GlCanvas> m_glCanvas; }; //Logger syslogger("panelvg_lib_wayland"); int run_app( int argc , char const* argv[] , extent window_size , color background_color , bool animate ) { try { auto loop = init_display<EGLBackend, XDGWindow>(); if (tvg::Initializer::init(4) != tvg::Result::Success) throw std::runtime_error("Failed to initialize ThorVG"); XDGWindow window(window_size.x, window_size.y); window.setTitle("Example application"); window.animate = animate; window.on_closed = [&loop](){loop.quit();}; loop.run(); tvg::Initializer::term(); } catch (const std::runtime_error& e) { WL::log_error("Error application : %s", e.what()); exit(1); } return 0; }