Data loss in generalized windows.
Posted: 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.
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.
responding to mouse clicks
activating button functionality
and finally the call function
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.
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.