Data loss in generalized windows.

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

Bane
Just popping in
Just popping in
Posts: 4
Joined: Tue Aug 12, 2008 21:54

Data loss in generalized windows.

Postby Bane » Wed Aug 13, 2008 17:17

Basically I'm making a config manager, all the windows are generated dynamically. For each part of the config there is a button, and window associated with it. and on each window has a statictext and editbox that will edit the config file. All is fine when creating the windows.. But i need interaction with them. I have the buttons working through an external singleton. but now i want the editbox's to change the data in the configmanager singleton.

Image

the buttons were ok because there is a function i found called
CEGUI::System::getSingletonPtr()->getWindowContainingMouse();

but now with the editbox's how can i generalize which window they are typing in?

and im sure there is a better way to retrieve generalized windows than using an external singleton..

ideas?


Setting up the windows.

Code: Select all

      CEGUI::Window  *tempButton;
      CEGUI::Editbox *editBox;
      CEGUI::Window *staticText;
      vector<ConfigWindowData> configWindowData = ConfigManager::Instance()->getConfigWindowData();

      int numWindows = (int)(configWindowData.size());
      int numVars;
      MainButtonYSize = (LWINDOW_HEIGHT - DIVIDER_HEIGHT*numWindows)/numWindows;
      for(int i=0; i<numWindows; i++)
      {
         //set up the different windows for each
         temporaryName = "SetupConfig/" + configWindowData.at(i).window_name;
         allWindows.push_back(win->createWindow((CEGUI::utf8*)"TaharezLook/StaticImage", temporaryName));
         allWindows.at(i)->setSize(CEGUI::UVector2(CEGUI::UDim(MWINDOW_WIDTH, 0), CEGUI::UDim(MWINDOW_HEIGHT, 0)));
         allWindows.at(i)->setPosition(CEGUI::UVector2(CEGUI::UDim(LWINDOW_WIDTH, 0), CEGUI::UDim(0, 0)));
         allWindows.at(i)->setProperty("Image", CEGUI::PropertyHelper::imageToString(&imageSet->getImage((CEGUI::utf8*)"RttImage")));
         allWindows.at(i)->setVisible(false);

         MainButtonYLoc += DIVIDER_HEIGHT;
         
         //set up each button
         temporaryName = "SetupConfig/" + configWindowData.at(i).window_name + ".button";
         tempButton = win->createWindow("TaharezLook/Button", temporaryName );
         tempButton->setText( configWindowData.at(i).window_name );
         tempButton->setSize(CEGUI::UVector2(CEGUI::UDim(LWINDOW_WIDTH, 0), CEGUI::UDim(MainButtonYSize, 0)));
         tempButton->setPosition(CEGUI::UVector2(CEGUI::UDim( 0, 0), CEGUI::UDim( MainButtonYLoc, 0)));
         ConfigManager::Instance()->addButton(tempButton);
         sheet->addChildWindow(ConfigManager::Instance()->getAllButtons().at(i));

         MainButtonYLoc += MainButtonYSize;
         
         //make it fit to the screen accordingly
         numVars = (int)(configWindowData.at(i).variable_names.size());
         if(numVars<=20)
            varYSize = (1.0 - (numVars*DIVIDER_HEIGHT))/numVars;
         else
            varYSize = (1.0/numVars);


         varYLoc = 0;
         for(int j=0; j<numVars; j++)
         {
            varXLoc = LWINDOW_WIDTH;
            if(numVars<=20)
               varYLoc += DIVIDER_HEIGHT;
            temporaryName = "SetupConfig/" + configWindowData.at(i).window_name + "/" + configWindowData.at(i).variable_names.at(j);
            staticText = (win->createWindow("TaharezLook/StaticText", temporaryName));//static_cast<CEGUI::DefaultWindow*>(win->getWindow("StaticText"));
            staticText->setText( configWindowData.at(i).variable_names.at(j) );
            staticText->setPosition(CEGUI::UVector2(CEGUI::UDim( .1f, 0), CEGUI::UDim( varYLoc, 0)));
            varXSize = configWindowData.at(i).variable_names.at(j).length()*PIXELS_PER_LETTER + PIXELS_PER_LETTER;
            staticText->setSize(CEGUI::UVector2(CEGUI::UDim(varXSize, 0), CEGUI::UDim(varYSize, 0)));
            staticText->setTooltipText( configWindowData.at(i).comments.at(j) );
            allWindows.at(i)->addChildWindow(staticText);

            varXLoc =DIVIDER_WIDTH;

            temporaryName = "SetupConfig/" + configWindowData.at(i).window_name + "/" + configWindowData.at(i).variable_names.at(j) + ".value";

            editBox = static_cast<CEGUI::Editbox*>(win->createWindow("TaharezLook/Editbox", temporaryName));
            editBox->setPosition(CEGUI::UVector2(cegui_reldim(0.1f), cegui_reldim(0.1f)));
            editBox->setSize(CEGUI::UVector2(CEGUI::UDim(.35f, 0), CEGUI::UDim(varYSize, 0)));
            editBox->setText(configWindowData.at(i).variable_values.at(j));
            editBox->setPosition(CEGUI::UVector2(CEGUI::UDim( varXLoc, 0), CEGUI::UDim( varYLoc, 0)));
            editBox->setTooltipText(configWindowData.at(i).comments.at(j));
            //editBox->subscribeEvent(CEGUI::Editbox::EventTextAccepted, CEGUI::Event::Subscriber(&TutorialListener::quit, this));
            allWindows.at(i)->addChildWindow(editBox);

            varYLoc += varYSize;
         }
         ConfigManager::Instance()->addWindow(allWindows.at(i));
         sheet->addChildWindow(allWindows.at(i));
      }
      ConfigManager::Instance()->setCurrentWindow(0);
      allWindows.at(ConfigManager::Instance()->getCurrentWindow())->setVisible(true);


responding to mouse clicks

Code: Select all

   bool mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
   {
      CEGUI::System::getSingleton().injectMouseButtonDown(convertButton(id));
      
      CEGUI::Window *currentWin = CEGUI::System::getSingletonPtr()->getWindowContainingMouse();
      vector<CEGUI::Window*> allButtons = ConfigManager::Instance()->getAllButtons();
      int winSize = (int)(allButtons.size());
      for(int i=0; i<winSize; i++)
      {
         if(currentWin->getName().compare(allButtons.at(i)->getName()) == 0 )
         {
            ConfigManager::Instance()->setCurrentWindow(i);
         }
      }

      return true;
   }


activating button functionality

Code: Select all

      int numWindows = (int)(configWindowData.size());
      for(int i=0; i<numWindows; i++)
      {
         buttonName = "SetupConfig/" + configWindowData.at(i).window_name + ".button";
         tempWindow = wmgr->getWindow(buttonName);
         tempWindow->subscribeEvent(CEGUI::PushButton::EventClicked,
         CEGUI::Event::Subscriber(&TutorialListener::changeWindow, this));
      }


and finally the call function

Code: Select all

   bool changeWindow(const CEGUI::EventArgs &e)
   {
      
      vector<CEGUI::Window*> allWindows = ConfigManager::Instance()->getAllWindows();
      int currentWindow = ConfigManager::Instance()->getCurrentWindow();
      int numWindows = (int)(allWindows.size());
      for(int i=0; i < numWindows; i++)
      {
         if(i==currentWindow)
         {
            allWindows.at(i)->setVisible(true);
         } else {
            allWindows.at(i)->setVisible(false);
         }
      }

      return true;
   }


I'd like to do something similar with the edit box's but im not certain what I can do.. any help is much appreciated.

Bane
Just popping in
Just popping in
Posts: 4
Joined: Tue Aug 12, 2008 21:54

Postby Bane » Thu Aug 14, 2008 19:40

Solved


I used my singleton to keep track of the string of the last window clicked
and used a parsing and deparsing method to find out the names of oriented windows

mousepressed

Code: Select all

   bool mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
   {
      CEGUI::System::getSingleton().injectMouseButtonDown(convertButton(id));
      
      CEGUI::Window *currentWin = CEGUI::System::getSingletonPtr()->getWindowContainingMouse();
      ConfigManager::Instance()->setLastWindowClickedName(currentWin->getName().c_str());

      return true;
   }


ontextaccepted

Code: Select all

   bool onTextAccepted(const CEGUI::EventArgs &e)
   {
      
      string buttonName = ConfigManager::Instance()->getLastWindowClickedName();
      CEGUI::Editbox * editBox = static_cast<CEGUI::Editbox*>(CEGUI::WindowManager::getSingletonPtr()->getWindow( buttonName ));
      
      string temp = ConfigManager::Instance()->getLastWindowClickedName();
      //"SetupConfig/" + configWindowData.at(i).window_name + "/" + configWindowData.at(i).variable_names.at(j) + ".value";
      //13 = "SetupConfig/ + /
      vector<ConfigWindowData> cwd = ConfigManager::Instance()->getConfigWindowData();
      int currentWindow = ConfigManager::Instance()->getCurrentWindow();
      temp = temp.substr(13 + (int)(cwd.at(currentWindow).window_name.size()));
      temp = temp.substr(0, (int)(temp.size())-6);
      int variableLength = (int)(cwd.at(currentWindow).variable_names.size());
      for(int i=0; i<variableLength; i++)
      {
         if(temp.compare(cwd.at(currentWindow).variable_names.at(i)) == 0)
         {
            ConfigManager::Instance()->setCurrentVariableWindow(i);
         }
      }

      string currentText = editBox->getText().c_str();
      ConfigManager::Instance()->setVariableValueText(currentText);
      return true;
   }


Return to “Help”

Who is online

Users browsing this forum: No registered users and 7 guests