add touch events handling
This commit is contained in:
@@ -94,7 +94,7 @@ void Kernel::main_loop()
|
||||
return;
|
||||
}
|
||||
m_render_target = std::make_unique<RenderTarget>();
|
||||
if (!m_render_target->create_exported(1024, 1024))
|
||||
if (!m_render_target->create_exported(540, 960))
|
||||
{
|
||||
Logger::Log("failed to create render target");
|
||||
return;
|
||||
@@ -117,7 +117,7 @@ void Kernel::main_loop()
|
||||
Rml::SetFileInterface(&AssetFilesInterface::Instance());
|
||||
Rml::SetSystemInterface(&SystemInterface::Instance());
|
||||
Rml::Initialise();
|
||||
Rml::Context* context = Rml::CreateContext("default", Rml::Vector2i(1024, 1024));
|
||||
Rml::Context* context = Rml::CreateContext("default", Rml::Vector2i(540, 960));
|
||||
if (!context)
|
||||
{
|
||||
Logger::Log("RMLUI failed to create a context");
|
||||
@@ -126,6 +126,7 @@ void Kernel::main_loop()
|
||||
}
|
||||
Rml::LoadFontFace("Roboto/static/Roboto_Condensed-Regular.ttf");
|
||||
Rml::LoadFontFace("LatoLatin-Regular.ttf");
|
||||
Rml::LoadFontFace("NotoEmoji-Regular.ttf", true);
|
||||
|
||||
// Now we are ready to load our document.
|
||||
Rml::ElementDocument* document = context->LoadDocument("demo.rml");
|
||||
@@ -133,15 +134,21 @@ void Kernel::main_loop()
|
||||
|
||||
while (true)
|
||||
{
|
||||
static float angle = 0.0f;
|
||||
angle += 0.1f;
|
||||
if (!m_tasks.empty())
|
||||
{
|
||||
std::lock_guard _lock(m_mutex);
|
||||
for (const auto &task: m_tasks)
|
||||
task(context);
|
||||
m_tasks.clear();
|
||||
}
|
||||
|
||||
m_render_target->bind();
|
||||
glClearColor(fabs(sin(angle)), 0.0f, 0.0f, 1.0f);
|
||||
glClearColor(0.f, 0.f, 0.f, 1.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glViewport(0, 0, 1024, 1024);
|
||||
glViewport(0, 0, 540, 960);
|
||||
|
||||
context->Update();
|
||||
rmlui_render_interface.SetViewport(1024, 1024);
|
||||
rmlui_render_interface.SetViewport(540, 960);
|
||||
rmlui_render_interface.BeginFrame();
|
||||
context->Render();
|
||||
rmlui_render_interface.EndFrame(m_render_target->framebuffer());
|
||||
@@ -171,4 +178,23 @@ void Kernel::add_listener(const std::shared_ptr<IMosisListener> &listener)
|
||||
listener->onBufferAvailable(*m_aidl_buffer);
|
||||
}
|
||||
|
||||
void Kernel::on_touch_down(float x, float y)
|
||||
{
|
||||
Logger::Log(std::format("on_touch_down {} - {}", x, y));
|
||||
}
|
||||
|
||||
void Kernel::on_touch_move(float x, float y)
|
||||
{
|
||||
Logger::Log(std::format("on_touch_move {} - {}", x, y));
|
||||
std::lock_guard _lock(m_mutex);
|
||||
m_tasks.emplace_back([x, y](Rml::Context* context){
|
||||
context->ProcessMouseMove(x * 540, y * 960, 0);
|
||||
});
|
||||
}
|
||||
|
||||
void Kernel::on_touch_up(float x, float y)
|
||||
{
|
||||
Logger::Log(std::format("on_touch_up {} - {}", x, y));
|
||||
}
|
||||
|
||||
Kernel::~Kernel() = default;
|
||||
|
||||
Reference in New Issue
Block a user