3#include <Covellite/Gui/Window.hpp>
4#include <alicorn/platform/app-info.hpp>
5#include <alicorn/std/class-info.hpp>
6#include <alicorn/std/string.hpp>
7#include <alicorn/boost/string-cast.hpp>
8#include <Covellite/Events.hpp>
9#include <Covellite/App/Events.hpp>
10#include <Covellite/App/Settings.hpp>
11#include <Covellite/App/Vfs.hpp>
12#include <Covellite/Os/Events.hpp>
13#include <Covellite/Api/IWindow.hpp>
14#include <Covellite/Api/Events.hpp>
15#include <Covellite/Gui/Renderer.hpp>
16#include <Covellite/Gui/Initializer.hpp>
17#include <Covellite/Gui/StringTranslator.hpp>
18#include <Covellite/Gui/EventListener.hpp>
19#include <Covellite/Gui/Events.hpp>
20#include "SystemToGuiKeyCode.hpp"
23# include <alicorn\logger.hpp>
26using namespace covellite::gui;
28Window::Window(
const WindowApi_t & _Window) :
31 m_pRenderer(::std::make_shared<covellite::gui::
Renderer>(_Window.GetRenders())),
32 m_pEventListener(EventListener::Make(_Window)),
34 m_pInitializer(::std::make_unique<Initializer_t>(Initializer_t::Data
39 m_pContext(CovelliteGui::CreateContext(
"main", GetContextSize()),
40 [](CovelliteGui::Context * _pContext) { CovelliteGuiRemove(_pContext); })
42 if (m_pContext ==
nullptr)
44 throw STD_EXCEPTION <<
"Create context failed.";
47 if (::alicorn::extension::cpp::IS_DEBUG_CONFIGURATION)
55 if (!CovelliteGui::Debugger::SetContext(m_pContext.get()))
57 CovelliteGui::Debugger::Initialise(m_pContext.get());
61 m_pContext->AddEventListener(::covellite::events::Click.m_EventType.c_str(),
62 m_pEventListener.get(),
false);
63 m_pContext->AddEventListener(::covellite::events::Press.m_EventType.c_str(),
64 m_pEventListener.get(),
false);
65 m_pContext->AddEventListener(::covellite::events::Change.m_EventType.c_str(),
66 m_pEventListener.get(),
false);
70 m_Events[events::Window.Resize]
71 .Connect([&]() { m_pContext->SetDimensions(GetContextSize()); });
73 m_Events[events::Cursor.Motion]
76 m_pContext->ProcessMouseMove(_Position.X,
77 _Position.Y - m_WindowApi.GetClientRect().Top, 0);
79 m_Events[events::Cursor.Touch]
80 .Connect([&]() { m_pContext->ProcessMouseButtonDown(0, 0); });
81 m_Events[events::Cursor.Release]
82 .Connect([&]() { m_pContext->ProcessMouseButtonUp(0, 0); });
84 m_Events[events::Key.Back]
85 .Connect([&]() { Back(); });
86 m_Events[events::Key.Down]
89 m_pContext->ProcessKeyDown(SystemToGuiKeyCode(_Code), 0);
91 m_Events[events::Key.Pressed]
96 if (_Code < 0x20)
return;
98 m_pContext->ProcessTextInput(
static_cast<CovelliteGuiUnicode_t
>(_Code));
101 m_Events[events::Drawing.Do]
102 .Connect([&]() { DoDrawWindow(); });
105Window::~Window(
void)
noexcept
107 m_pContext->RemoveEventListener(::covellite::events::Click.m_EventType.c_str(),
108 m_pEventListener.get(),
false);
109 m_pContext->RemoveEventListener(::covellite::events::Press.m_EventType.c_str(),
110 m_pEventListener.get(),
false);
111 m_pContext->RemoveEventListener(::covellite::events::Change.m_EventType.c_str(),
112 m_pEventListener.get(),
false);
119Window::operator Events_t (
void)
const
128Window::DocumentPtr_t Window::LoadDocument(
const PathToFile_t & _Path)
130 const auto Start = ::std::chrono::system_clock::now();
132 auto pResult = DocumentPtr_t(m_pContext->LoadDocument(Layer::Convert(_Path).c_str()),
133 [](Document_t * _pDocument) { CovelliteGuiRemove(_pDocument); });
135 ::std::chrono::duration<double> TimeCall =
136 ::std::chrono::system_clock::now() - Start;
138 LOGGER(Info) << _Path.string() <<
": " << TimeCall.count();
149void Window::Set(
const StringBank_t & _Bank)
151 m_pStringTranslator->Set(_Bank);
162void Window::Back(
void)
164 LOGGER(Info) <<
"Pop layer";
166 const auto IsExistsLayer = m_Layers.Pop();
169 m_Events[::covellite::events::Application.Exit]();
177void Window::PushLayer(
const LayerPtr_t & _pLayer)
179 m_Layers.Push(_pLayer);
181 LOGGER(Info) <<
"Push layer [" <<
182 ::alicorn::extension::std::ClassInfo::GetPureName(*_pLayer) <<
"]";
191Window::Vector_t Window::GetContextSize(
void)
const
193 const auto Rect = m_WindowApi.GetClientRect();
194 return Vector_t(Rect.Width, Rect.Height - Rect.Top);
201void Window::DoDrawWindow(
void)
203 m_pContext->Update();
204 m_pContext->Render();
205 m_pRenderer->RenderScene();
217void Window::LoadFonts(
void)
219 const auto & CovelliteppSection =
220 ::covellite::app::Settings_t::GetInstance();
221 const auto PathToFontsDirectory =
222 CovelliteppSection.Get<Path_t>(uT(
"PathToFontsDirectory"));
224 ::covellite::app::Vfs_t::GetInstance();
226 Vfs.BrowsingFiles(PathToFontsDirectory, [&](
const Path_t & _FontFile)
230 m_RawDataFonts[_FontFile] = ::std::move(Vfs.GetData(_FontFile));
232 CovelliteGuiLoadFontFace(m_RawDataFonts[_FontFile]);
int32_t Code
Класс входит в проект Covellite.Os Класс параметра для передачи сигналу координат курсора.
Definition Events.hpp:159
Класс входит в проект Covellite.Gui Класс обобщенной логики рендеринга GUI.
Definition Renderer.hpp:44
Класс входит в проект Covellite.Gui Класс преобразователя строк.
Definition StringTranslator.hpp:34
Класс входит в проект Covellite.Os Класс параметра для передачи сигналу координат курсора.
Definition Events.hpp:99