Example #1
0
void UiBase::ToggleEventListener(bool toggle_on, const std::string& id, const std::string& event, RocketListener& listener)
{
  if (root)
  {
    Rocket::Core::Element* element = root->GetElementById(id.c_str());

    if (element)
    {
      Listener             registered(element, event, listener);
      auto                 it      = std::find(listeners.begin(), listeners.end(), registered);

      if (toggle_on)
      {
        if (it == listeners.end())
          listeners.push_back(registered);
        else
          element->RemoveEventListener(event.c_str(), &listener);
        element->AddEventListener(event.c_str(), &listener);
      }
      else
      {
        element->RemoveEventListener(event.c_str(), &listener);
        if (it != listeners.end())
          listeners.erase(it);
      }
    }
    else
      cout << "[WARNING] Element '" << id << "' doesn't exist." << endl;
  }
}
void             InventoryView::Destroy()
{
  Rocket::Core::Element* element;
  
  for (int i = 0 ; (element = _element.GetChild(i)) != 0 ; ++i)
  {
    element->RemoveEventListener("dblclick",  this);
    element->RemoveEventListener("mouseover", this);
    element->RemoveEventListener("click",     this);
  }
}
Example #3
0
UiBase::~UiBase()
{
  if (root)
  {
    std::for_each(listeners.begin(), listeners.end(), [this](const Listener& listener)
    {
      Rocket::Core::Element* elem = root->GetElementById(listener.elem.c_str());
      
      if (elem)
        elem->RemoveEventListener(listener.event.c_str(), &(listener.instance));
    });
    if (!root_outlives_this_object)
    {
      root->Hide();
      root->RemoveReference();
      root = 0;
    }
  }
}