void UIContext::set_debugger_size(const Size2i& dims) { if( this->valid() ) { Rocket::Core::ElementDocument* target = this->context()->GetDocument("rkt-debug-hook"); NOM_ASSERT( target != nullptr ); if( target ) { // NOM_DUMP( target->GetSourceURL().CString() ); Rocket::Core::Element* body_tag = target->GetParentNode(); NOM_ASSERT( body_tag != nullptr ); if( body_tag ) { // Sets width of visual debugger's Element Info window Rocket::Core::Element* info = body_tag->GetElementById("rkt-debug-info"); NOM_ASSERT( info != nullptr ); if( info ) { Rocket::Core::Property width(dims.w, Rocket::Core::Property::PX); info->SetProperty("min-width", width); info->SetProperty("width", width); } // end if info // Sets height of visual debugger's Element Info window Rocket::Core::Element* content = body_tag->GetElementById("content"); NOM_ASSERT( content != nullptr ); if( content ) { // As per Rocket/Debugger/MenuSource.h // int menu_height = 32; // Maximum height shall be no more than half the size of the context, // add menu height Rocket::Core::Property max_height( dims.h, Rocket::Core::Property::PX); content->SetProperty("max-height", max_height); } // end if debug_content } // end if body_tag } // end if target } // end if valid context }
void TimeWindow::updateTime() { Time & t = game->time; window->GetElementById("watch")->SetAttribute<float>("time", t.hour); Rocket::Core::Element * weekday = window->GetElementById("date-weekday"); Rocket::Core::Element * weekend = window->GetElementById("date-weekend"); weekday->SetInnerRML(t.day == 0 ? "1st WD" : "2nd WD"); weekday->SetProperty("display", (t.day == 2 ? "none" : "inline")); weekend->SetProperty("display", (t.day != 2 ? "none" : "inline")); char c[128]; snprintf(c, 128, "%iQ", t.quarter); window->GetElementById("date-quarter")->SetInnerRML(c); const char * suffix = "th"; int yl = (t.year % 10); if (yl == 1) suffix = "st"; if (yl == 2) suffix = "nd"; if (yl == 3) suffix = "rd"; snprintf(c, 128, "%i%s", t.year, suffix); window->GetElementById("date-year")->SetInnerRML(c); }
void Rocket_SetPropertyById( const char *id, const char *property, const char *value ) { if ( *id ) { Rocket::Core::ElementDocument *document = menuContext->GetFocusElement()->GetOwnerDocument(); if ( document ) { Rocket::Core::Element *element = document->GetElementById( id ); if ( element ) { element->SetProperty( property, value ); } } } else if ( activeElement ) { activeElement->SetProperty( property, value ); } }
InteractMenu::InteractMenu(WindowFramework* window, Rocket::Core::Context* context, InstanceDynamicObject& object) : UiBase(window, context) { Interactions::InteractionList& interactions = object.GetInteractions(); _done = false; root = context->LoadDocument("data/interact_menu.rml"); if (root) { Rocket::Core::Element* element = root->GetElementById("menu"); if (element) { // Positioning the interact_menu { std::stringstream strTop, strLeft, maxHeight; MouseData pointer = window->get_graphics_window()->get_pointer(0); strTop << (pointer.get_y()); strLeft << (pointer.get_x()); maxHeight << (window->get_graphics_window()->get_y_size() - pointer.get_y()); element->SetProperty("position", "absolute"); element->SetProperty("top", strTop.str().c_str()); element->SetProperty("left", strLeft.str().c_str()); element->SetProperty("max-height", maxHeight.str().c_str()); } // Generating and setting the RML for the interact_menu { std::stringstream rml; for_each(interactions.begin(), interactions.end(), [&rml](Interactions::Interaction& interaction) { rml << "<div id='interaction-" << interaction.name << "'>"; rml << "<button id='" << interaction.name << "' class='interact_button'>"; rml << "<img src='../textures/buttons/" + interaction.name + "-normal.png' />"; rml << "</button></div>"; }); element->SetInnerRML(rml.str().c_str()); } int it = 0; _listeners.resize(interactions.size()); for_each(interactions.begin(), interactions.end(), [this, &it](Interactions::Interaction& interaction) { ToggleEventListener(true, interaction.name, "click", _buttonListener); ToggleEventListener(true, interaction.name, "mouseover", _buttonHover); ToggleEventListener(true, interaction.name, "mouseout", _buttonHover); ToggleEventListener(true, interaction.name, "mousedown", _buttonClick); ToggleEventListener(true, interaction.name, "mouseup", _buttonClick); _listeners[it] = &interaction; _obs.Connect(_buttonListener.EventReceived, *this, &InteractMenu::ButtonClicked); _obs.Connect(_buttonHover.EventReceived, *this, &InteractMenu::ButtonHovered); _obs.Connect(_buttonClick.EventReceived, *this, &InteractMenu::MouseButton); ++it; }); } Show(); } }