Page 1 of 1

CEGUI sans mouse input Problem

Posted: Tue Sep 12, 2006 15:44
by arkos
Hey guys,

I am thinking about making a game with Ogre that uses the Xbox360 controller. I was wondering if there was a way that I could integrate the controllers d-pad (or the arrow buttons on the computer's keyboard) with CEGUI.

I only have like three menus so I was thinking that I could just have an array that contained each button. Then I would intially have the top button "hovered over", but I don't know if you can do this without a mouse. When the player hits the down arrow then the next button in the array would be "hovering".

Any ideas would be appreciated.

Posted: Sun Sep 17, 2006 16:08
by arkos
Hey guys,

I wrote some code to let me do what I want. I am putting it up so that someone else can use it if they need to or they can make it better.

Code: Select all


class ButtonContainerClass
{
   public:
      void addBtn(CEGUI::String);            // Add a button to the container
      void nextBtn();                  // Move the selection to the next button
      void prevBtn();                  // Move the selection to the prev button
      int getSize();
      ButtonContainerClass(bool);
      ~ButtonContainerClass(void);
                          
   private:
      void updateSelection();
      std::vector<CEGUI::String> buttons;      // Buttons are id'ed by name string
      int cur_btn;                  // Index of current button
      bool loop;                     // True if selection should go to beginning after the end
            
};


and here is the cpp

Code: Select all


ButtonContainerClass::ButtonContainerClass(bool loop_selection)
{
   loop = loop_selection;
   cur_btn = 0;
}
   
ButtonContainerClass::~ButtonContainerClass()
{
   
}

void ButtonContainerClass::addBtn(CEGUI::String btn_str)
{
   buttons.push_back(btn_str);
   if(buttons.size() == 1)
   {
      updateSelection();
   }
}

int ButtonContainerClass::getSize()
{
   return buttons.size();
}

void ButtonContainerClass::nextBtn()
{
   if(cur_btn == buttons.size() - 1)      // end of list
   {
      if(loop)
      {
         cur_btn = 0;
         updateSelection();
      }
   }
   else
   {
      cur_btn++;
      updateSelection();
   }
   
   return;
}

void ButtonContainerClass::prevBtn()
{
   if(cur_btn == 0)      // start of list
   {
      if(loop)
      {
         cur_btn = buttons.size() - 1;
         updateSelection();
      }
   }
   else
   {
      cur_btn--;
      updateSelection();
   }
   
   return;
}

void ButtonContainerClass::updateSelection()
{
   CEGUI::Point pos = getWindow(buttons[cur_btn])->getPosition(CEGUI::MetricsMode::Absolute);
   CEGUI::System::getSingleton().injectMousePosition(pos.d_x, pos.d_y);
   return;
}


By the way in order to use this class, you have to add the button name strings with the add function. Then I have it so when you press the arrow keys it either calls nextBtn or prevBtn.

Let me know if this helps anyone.