(element)->GetValue().c_str());
tweening_parameters.duration = value;
if (auto el_duration = element->GetElementById("duration"))
el_duration->SetInnerRML(CreateString(20, "%2.2f", value));
}
else if (value == "rating")
{
auto el_rating = element->GetElementById("rating");
auto el_rating_emoji = element->GetElementById("rating_emoji");
if (el_rating && el_rating_emoji)
{
enum { Sad, Mediocre, Exciting, Celebrate, Champion, CountEmojis };
static const Rml::Core::String emojis[CountEmojis] = {
(const char*)u8"😢", (const char*)u8"😐", (const char*)u8"😮",
(const char*)u8"😎", (const char*)u8"🏆"
};
int value = event.GetParameter("value", 50);
Rml::Core::String emoji;
if (value <= 0)
emoji = emojis[Sad];
else if(value < 50)
emoji = emojis[Mediocre];
else if (value < 75)
emoji = emojis[Exciting];
else if (value < 100)
emoji = emojis[Celebrate];
else
emoji = emojis[Champion];
el_rating->SetInnerRML(Rml::Core::CreateString(30, "%d%%", value));
el_rating_emoji->SetInnerRML(emoji);
}
}
else if (value == "submit_form")
{
const auto& p = event.GetParameters();
Rml::Core::String output = "";
for (auto& entry : p)
{
auto value = Rml::Core::StringUtilities::EncodeRml(entry.second.Get());
if (entry.first == "message")
value = "
" + value;
output += "" + entry.first + ": " + value + "
";
}
output += "
";
demo_window->SubmitForm(output);
}
else if (value == "set_sandbox_body")
{
if (auto source = static_cast(element->GetElementById("sandbox_rml_source")))
{
auto value = source->GetValue();
demo_window->SetSandboxBody(value);
}
}
else if (value == "set_sandbox_style")
{
if (auto source = static_cast(element->GetElementById("sandbox_rcss_source")))
{
auto value = source->GetValue();
demo_window->SetSandboxStylesheet(value);
}
}
}
void OnDetach(Rml::Core::Element* /*element*/) override { delete this; }
private:
Rml::Core::String value;
Rml::Core::Element* element;
};
class DemoEventListenerInstancer : public Rml::Core::EventListenerInstancer
{
public:
Rml::Core::EventListener* InstanceEventListener(const Rml::Core::String& value, Rml::Core::Element* element) override
{
return new DemoEventListener(value, element);
}
};
#if defined RMLUI_PLATFORM_WIN32
#include
int APIENTRY WinMain(HINSTANCE RMLUI_UNUSED_PARAMETER(instance_handle), HINSTANCE RMLUI_UNUSED_PARAMETER(previous_instance_handle), char* RMLUI_UNUSED_PARAMETER(command_line), int RMLUI_UNUSED_PARAMETER(command_show))
#else
int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
#endif
{
#ifdef RMLUI_PLATFORM_WIN32
RMLUI_UNUSED(instance_handle);
RMLUI_UNUSED(previous_instance_handle);
RMLUI_UNUSED(command_line);
RMLUI_UNUSED(command_show);
#else
RMLUI_UNUSED(argc);
RMLUI_UNUSED(argv);
#endif
const int width = 1600;
const int height = 900;
ShellRenderInterfaceOpenGL opengl_renderer;
shell_renderer = &opengl_renderer;
// Generic OS initialisation, creates a window and attaches OpenGL.
if (!Shell::Initialise() ||
!Shell::OpenWindow("Demo Sample", shell_renderer, width, height, true))
{
Shell::Shutdown();
return -1;
}
// RmlUi initialisation.
Rml::Core::SetRenderInterface(&opengl_renderer);
opengl_renderer.SetViewport(width, height);
ShellSystemInterface system_interface;
Rml::Core::SetSystemInterface(&system_interface);
Rml::Core::Initialise();
// Create the main RmlUi context and set it on the shell's input layer.
context = Rml::Core::CreateContext("main", Rml::Core::Vector2i(width, height));
if (context == nullptr)
{
Rml::Core::Shutdown();
Shell::Shutdown();
return -1;
}
Rml::Controls::Initialise();
Rml::Debugger::Initialise(context);
Input::SetContext(context);
shell_renderer->SetContext(context);
context->SetDensityIndependentPixelRatio(1.0f);
DemoEventListenerInstancer event_listener_instancer;
Rml::Core::Factory::RegisterEventListenerInstancer(&event_listener_instancer);
Shell::LoadFonts("assets/");
demo_window = std::make_unique("Demo sample", Rml::Core::Vector2f(150, 50), context);
demo_window->GetDocument()->AddEventListener(Rml::Core::EventId::Keydown, demo_window.get());
demo_window->GetDocument()->AddEventListener(Rml::Core::EventId::Keyup, demo_window.get());
demo_window->GetDocument()->AddEventListener(Rml::Core::EventId::Animationend, demo_window.get());
Shell::EventLoop(GameLoop);
demo_window->Shutdown();
// Shutdown RmlUi.
Rml::Core::Shutdown();
Shell::CloseWindow();
Shell::Shutdown();
demo_window.reset();
return 0;
}