コード例 #1
0
void RocketMenuPlugin::ProcessEvent(Rocket::Core::Event& event) {
    Rocket::Core::Element *element = event.GetCurrentElement();

    if (event.GetType() == "click") {
        if (element->GetTagName() == "ftr") {
            SetNextItemValue(element->GetParentNode()->GetParentNode());
            event.StopPropagation();
        } else if (element->GetTagName() == "hdr") {
            SetPreviousItemValue(element->GetParentNode()->GetParentNode());
            event.StopPropagation();
        } else {
            DoItemAction(ItemActionEnter, element);
        }
    } else if (event.GetType() == "mousemove") {
        if (element->GetTagName() == "div") {
            HighlightItem(element);
        } else if (element->GetTagName() == "key1") {
            Rocket::Core::Element *menu_item = element->GetParentNode()->GetParentNode();
            SetActiveKeySlot(menu_item, 0);
        } else if (element->GetTagName() == "key2") {
            Rocket::Core::Element *menu_item = element->GetParentNode()->GetParentNode();
            SetActiveKeySlot(menu_item, 1);
        }
    } else if (event.GetType() == "change") {
        if (m_delegate != NULL && element->GetOwnerDocument()->IsVisible()) {
            Rocket::Core::Element *menu_item = element->GetParentNode()->GetParentNode();
            RangeData *data = GetRangeData(menu_item);
            const Rocket::Core::Dictionary  *p = event.GetParameters();
            float v = p->Get("value")->Get<float>();
            float new_value = data->min + v*(data->max - data->min);
            if (fabs(new_value-data->value) > 0.001f) {
                data->value = new_value;
                m_delegate->DidChangeRangeValue(menu_item, data->value);
            }
        }
    }
}
コード例 #2
0
ファイル: RocketUIManager.cpp プロジェクト: Unix4ever/engine
  bool RocketUIManager::doCapture(Rocket::Core::Context* ctx)
  {
    Rocket::Core::Element* e = ctx->GetHoverElement();

    if(e && e != ctx->GetRootElement())
    {
      if(e->GetTagName() == "body")
        return false;

      bool isVisible = true;
      while(e && (isVisible = e->IsVisible()))
      {
        e = e->GetParentNode();
      }

      return isVisible;
    }

    return false;
  }
コード例 #3
0
ファイル: SaveMenu.cpp プロジェクト: noam-c/EDEn
void SaveMenu::saveGameClicked(Rocket::Core::Event& event)
{
   Rocket::Core::Element* target = event.GetTargetElement();

   // Move up the DOM to the datagridrow item holding this element
   while(target->GetParentNode() != nullptr && target->GetTagName() != "datagridrow")
   {
      target = target->GetParentNode();
   }

   if(target != nullptr)
   {
      // If we found a row element, cast it and get its index
      Rocket::Controls::ElementDataGridRow* rowElement = dynamic_cast<Rocket::Controls::ElementDataGridRow*>(target);
      if(rowElement != nullptr)
      {
         int saveGameIndex = rowElement->GetParentRelativeIndex();
         showConfirmDialog(saveGameIndex);
      }
   }
}
コード例 #4
0
/// \brief Event listener callback for "mouseup" events generated by libRocket.
///
/// \param ev     The object containing event info.
/// \param store  The UIDataViewList widget to use.
/// \param db     The cards database to use for comparison against model
///               (table) data.
/// \param model  The data source model to use.
/// \param player_hand  The mock player hand object to use for holding card
///                     data, such as totals on number of cards of a type.
void on_mouseup(  Rocket::Core::Event& ev,
                  UIDataViewList* store,
                  const std::shared_ptr<CardCollection> db,
                  std::shared_ptr<CardsPageDataSource> model,
                  std::map<int,Card>& player_hand )
{
  EXPECT_TRUE( store != nullptr );
  EXPECT_TRUE( db != nullptr );
  EXPECT_TRUE( model != nullptr );

  // ID of card selection
  int selection = 0;
  Rocket::Core::Element* target = ev.GetTargetElement();

  if( ev == "mouseup" )
  {
    Rocket::Core::Input::KeyIdentifier button =
      (Rocket::Core::Input::KeyIdentifier) ev.GetParameter<int>("button", 3);

    EXPECT_TRUE( model->per_page() == model->GetNumRows("cards") );
    EXPECT_EQ( 57, model->num_rows() );

    if( target ) {

      Card card = model->lookup_by_name( target->GetInnerRML().CString() );
      selection = card.id();

      if( target->GetTagName() == "card" && button == 0 ) // Left click
      {
        // Card selection logic; player hand receives a card
        //
        // 1. Decrease available card count by one
        // 2. Sync the cards model to reflect modified card count (-1)
        // 3. Update player hand w/ a copy of the reference card
        if( card.num() > 0 )
        {
          card.set_num( card.num() - 1 );
          model->insert_card(selection, card);
          player_hand[card.id()] = card;
        }

      } // end if button == 0
      else if( target->GetTagName() == "card" && button == 1 )  // Right click
      {
        // Compare the selected card from the current model with the game
        // database; we rely on the game database to be the "safe" -- read-only.
        Card ref_card = db->lookup_by_id(selection);

        // Card selection logic; player hand removes a card
        //
        // 1. Increase available card count by one
        // 2. Sync the cards model to reflect modified card count (+1)
        // 3. Remove the card from the player's hand
        if( card.num() < ref_card.num() )
        {
          card.set_num( card.num() + 1 );
          model->insert_card(selection, card);
          player_hand.erase( card.id() );
        }
      } // end if button == 1

      NOM_LOG_INFO( NOM_LOG_CATEGORY_TEST, "Card ID:", selection );
      NOM_LOG_INFO( NOM_LOG_CATEGORY_TEST, "Card name:", target->GetInnerRML().CString() );

    } // end if target

  } // end if click
} // end func on_mouseup