Use native arrow cursors for game surfaces and controls (by Codex)
This commit is contained in:
1 parent
012612b06f
commit
6f98f894f2
6 files changed
+48
-6
No files matched your search
@@ -40,6 +40,8 @@ struct Renderer final : Rml::RenderInterface {
|
||||
};
|
||||
struct System final : Rml::SystemInterface {
|
||||
size_t stylesheet_errors = 0;
|
||||
Rml::String cursor;
|
||||
void SetMouseCursor(const Rml::String &name) override { cursor=name; }
|
||||
bool LogMessage(Rml::Log::Type type, const Rml::String &message) override {
|
||||
if ((type == Rml::Log::LT_WARNING || type == Rml::Log::LT_ERROR) &&
|
||||
(message.find("property") != message.npos ||
|
||||
@@ -98,6 +100,30 @@ struct ClickListener final : Rml::EventListener {
|
||||
++clicks;
|
||||
}
|
||||
};
|
||||
void cursor_cases(Rml::Context &context, System &system,
|
||||
const std::string &css, const std::string &theme, float density) {
|
||||
auto *doc=context.LoadDocumentFromMemory(
|
||||
"<rml><head><style>"+css+"</style></head><body class='"+theme+"'>"
|
||||
"<a id='cursor-link' href='https://example.invalid/' style='cursor:pointer;position:absolute;left:40dp;top:40dp;width:300dp;height:80dp;'>Web link</a>"
|
||||
"<button id='cursor-button' style='position:absolute;left:40dp;top:160dp;width:300dp;height:80dp;'>Game action</button>"
|
||||
"<button id='cursor-disabled' disabled style='position:absolute;left:40dp;top:280dp;width:300dp;height:80dp;'>Unavailable</button>"
|
||||
"<div id='cursor-widget' class='desk-card' style='position:absolute;left:40dp;top:400dp;width:300dp;height:80dp;'>Widget</div>"
|
||||
"<select id='cursor-select' style='position:absolute;left:40dp;top:520dp;width:300dp;height:80dp;'><option>Choice</option></select>"
|
||||
"<input id='cursor-input' type='text' value='Manager' style='position:absolute;left:40dp;top:640dp;width:300dp;height:80dp;'/>"
|
||||
"</body></rml>");
|
||||
require(doc,"Cursor fixture missing");doc->Show();context.Update();
|
||||
const auto hover=[&](const char *id) {
|
||||
auto *node=doc->GetElementById(id);const auto p=node->GetAbsoluteOffset(Rml::BoxArea::Border),s=node->GetBox().GetSize(Rml::BoxArea::Border);
|
||||
context.ProcessMouseMove(int(p.x+s.x/2),int(p.y+s.y/2),0);context.Update();
|
||||
};
|
||||
for(auto *id:{"cursor-button","cursor-disabled","cursor-widget","cursor-select"}) {
|
||||
hover("cursor-link");require(system.cursor=="pointer","Actual link lost its pointer");
|
||||
hover(id);require(system.cursor=="arrow","Game control retained hyperlink/stale cursor");
|
||||
}
|
||||
hover("cursor-input");require(system.cursor=="text","Text field lost editing cursor");
|
||||
doc->Close();context.Update();
|
||||
(void)density;
|
||||
}
|
||||
void script_locator_cases(Rml::Context &context, float density) {
|
||||
struct Case {
|
||||
const char *transform;
|
||||
@@ -366,11 +392,12 @@ int main(int argc, char **argv) try {
|
||||
}
|
||||
doc->Close();
|
||||
context->Update();
|
||||
cursor_cases(*context,system,css.str(),theme,density);
|
||||
script_locator_cases(*context,density);
|
||||
Rml::RemoveContext("controls");
|
||||
}
|
||||
Rml::Shutdown();
|
||||
std::cout << "Control text, dropdown arrows, popup fonts and rich cards "
|
||||
std::cout << "Control cursors, text, dropdown arrows, popup fonts and rich cards "
|
||||
"passed in 3 themes at 4 densities\n";
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << e.what() << '\n';
|
||||
|
||||
Reference in new issue
Block a user