void Spinner::setTextInputMode(TextInputMode mode) { if (mode != d_inputMode) { switch (mode) { case FloatingPoint: getEditbox()->setValidationString(FloatValidator); break; case Integer: getEditbox()->setValidationString(IntegerValidator); break; case Hexadecimal: getEditbox()->setValidationString(HexValidator); break; case Octal: getEditbox()->setValidationString(OctalValidator); break; default: throw InvalidRequestException("Spinner::setTextInputMode - An unknown TextInputMode was specified."); } d_inputMode = mode; WindowEventArgs args(this); onTextInputModeChanged(args); } }
/************************************************************************* Handler for selections made in the drop-list *************************************************************************/ bool Combobox::droplist_SelectionAcceptedHandler(const EventArgs& e) { // copy the text from the selected item into the edit box ListboxItem* item = ((ComboDropList*)((WindowEventArgs&)e).window)->getFirstSelectedItem(); if (item) { Editbox* editbox = getEditbox(); // Put the text from the list item into the edit box editbox->setText(item->getText()); // select text if it's editable, and move caret to end if (!isReadOnly()) { editbox->setSelection(0, item->getText().length()); editbox->setCaretIndex(item->getText().length()); } editbox->setCaretIndex(0); editbox->activate(); // fire off an event of our own WindowEventArgs args(this); onListSelectionAccepted(args); } return true; }
/************************************************************************* Handler for mouse button down events in editbox *************************************************************************/ bool Combobox::editbox_MouseDownHandler(const EventArgs& e) { // only interested in left button if (((const MouseEventArgs&)e).button == LeftButton) { Editbox* editbox = getEditbox(); // if edit box is read-only, show list if (editbox->isReadOnly()) { ComboDropList* droplist = getDropList(); // if there is an item with the same text as the edit box, pre-select it ListboxItem* item = droplist->findItemWithText(editbox->getText(), 0); if (item) { droplist->setItemSelectState(item, true); droplist->ensureItemIsVisible(item); } // no matching item, so select nothing else { droplist->clearAllSelections(); } showDropList(); return true; } } return false; }
void Spinner::onFontChanged(WindowEventArgs& e) { // Propagate to children getEditbox()->setFont(getFont()); // Call base class handler Window::onFontChanged(e); }
bool Spinner::handleEditTextChange(const EventArgs& e) { // set this windows text to match setText(getEditbox()->getText()); // update value setCurrentValue(getValueFromText()); return true; }
/************************************************************************* Activate the edit box component of the Combobox. *************************************************************************/ void Combobox::activateEditbox(void) { Editbox* editbox = getEditbox(); if (!editbox->isActive()) { editbox->activate(); } }
/************************************************************************* Handler for when widget font is changed *************************************************************************/ void Combobox::onFontChanged(WindowEventArgs& e) { // Propagate to children getEditbox()->setFont(d_font); getDropList()->setFont(d_font); // Call base class handler Window::onFontChanged(e); }
float Spinner::getValueFromText(void) const { String tmpTxt(getEditbox()->getText()); // handle empty and lone '-' or '.' cases if (tmpTxt.empty() || (tmpTxt == "-") || (tmpTxt == ".")) { return 0.0f; } int res, tmp; uint utmp; float val; switch (d_inputMode) { case FloatingPoint: res = sscanf(tmpTxt.c_str(), "%f", &val); break; case Integer: res = sscanf(tmpTxt.c_str(), "%d", &tmp); val = static_cast<float>(tmp); break; case Hexadecimal: res = sscanf(tmpTxt.c_str(), "%x", &utmp); val = static_cast<float>(utmp); break; case Octal: res = sscanf(tmpTxt.c_str(), "%o", &utmp); val = static_cast<float>(utmp); break; default: throw InvalidRequestException("Spinner::getValueFromText - An unknown TextInputMode was encountered."); } if (res) { return val; } throw InvalidRequestException("Spinner::getValueFromText - The string '" + getEditbox()->getText() + "' can not be converted to numerical representation."); }
//----------------------------------------------------------------------------// void Combobox::selectListItemWithEditboxText() { ComboDropList* const droplist = getDropList(); if (ListboxItem* item = droplist->findItemWithText(getEditbox()->getText(), 0)) { droplist->setItemSelectState(item, true); droplist->ensureItemIsVisible(item); } else droplist->clearAllSelections(); }
void Spinner::onActivated(ActivationEventArgs& e) { if (!isActive()) { Window::onActivated(e); Editbox* editbox = getEditbox(); if (!editbox->isActive()) { editbox->activate(); } } }
void Spinner::onTextInputModeChanged(WindowEventArgs& e) { Editbox* editbox = getEditbox(); // update edit box text to reflect new mode. // mute to save doing unnecessary events work. bool wasMuted = editbox->isMuted(); editbox->setMutedState(true); // Update text with new value. editbox->setText(getTextFromValue()); // restore previous mute state. editbox->setMutedState(wasMuted); fireEvent(EventTextInputModeChanged, e, EventNamespace); }
GameSaveLoadWindow::GameSaveLoadWindow() : AbstractWindow("gamesaveloadwindow.xml", WIT_MOUSE_INPUT | WIT_KEYBOARD_INPUT) { // Get a access to the filename edit box mFilename = getEditbox("GameSaveLoadWindow/FileSheet/Filename"); RlAssert(mFilename != NULL, "GameSaveLoadWindow/FileSheet/Filename is null"); mFilename->activate(); // Get a access to the savegame table mSaveGameTable = getMultiColumnList("GameSaveLoadWindow/FileSheet/SaveGameTable"); RlAssert(mSaveGameTable != NULL, "GameSaveLoadWindow/FileSheet/SaveGameTable is null"); mSaveGameTable->addColumn( (utf8*)"Filename", 0, cegui_reldim(0.65)); mSaveGameTable->addColumn( (utf8*)"Date", 1, cegui_reldim(0.35)); mSaveGameTable->setSelectionMode(MultiColumnList::RowSingle); mSaveGameTable->subscribeEvent(MultiColumnList::EventSelectionChanged, boost::bind(&GameSaveLoadWindow::handleSelectSaveGame, this)); centerWindow(); getPushButton("GameSaveLoadWindow/ButtonSheet/LoadButton")->subscribeEvent( CEGUI::Window::EventMouseClick, boost::bind( &GameSaveLoadWindow::handleLoadEvent, this )); getPushButton("GameSaveLoadWindow/ButtonSheet/SaveButton")->subscribeEvent( CEGUI::Window::EventMouseClick, boost::bind( &GameSaveLoadWindow::handleSaveEvent, this )); getPushButton("GameSaveLoadWindow/ButtonSheet/DeleteButton")->subscribeEvent( CEGUI::Window::EventMouseClick, boost::bind( &GameSaveLoadWindow::handleDeleteEvent, this )); bindDestroyWindowToXButton(); bindDestroyWindowToClick(getWindow("GameSaveLoadWindow/ButtonSheet/CancelButton")); mSelectionColour = CEGUI::ListboxItem::DefaultSelectionColour; mSelectionImageset = "RastullahLook-Images"; mSelectionBrush = "ListboxSelectionBrush"; }
void Spinner::onTextChanged(WindowEventArgs& e) { Editbox* editbox = getEditbox(); // update only if needed if (editbox->getText() != d_text) { // done before doing base class processing so event subscribers see // 'updated' version. editbox->setText(d_text); e.handled = true; Window::onTextChanged(e); } }
/************************************************************************* Handler for when text changes *************************************************************************/ void Combobox::onTextChanged(WindowEventArgs& e) { Editbox* editbox = getEditbox(); // update ourselves only if needed (prevents perpetual event loop & stack overflow) if (editbox->getText() != getText()) { // done before doing base class processing so event subscribers see 'updated' version of this. editbox->setText(getText()); ++e.handled; selectListItemWithEditboxText(); Window::onTextChanged(e); } }
void Spinner::onValueChanged(WindowEventArgs& e) { Editbox* editbox = getEditbox(); // mute to save doing unnecessary events work. bool wasMuted = editbox->isMuted(); editbox->setMutedState(true); // Update text with new value. // (allow empty and '-' cases to equal 0 with no text change required) if (!(d_currentValue == 0 && (editbox->getText().empty() || editbox->getText() == "-"))) { editbox->setText(getTextFromValue()); } // restore previous mute state. editbox->setMutedState(wasMuted); fireEvent(EventValueChanged, e, EventNamespace); }
void Spinner::initialiseComponents(void) { // get all the component widgets PushButton* increaseButton = getIncreaseButton(); PushButton* decreaseButton = getDecreaseButton(); Editbox* editbox = getEditbox(); // setup component controls increaseButton->setWantsMultiClickEvents(false); increaseButton->setMouseAutoRepeatEnabled(true); decreaseButton->setWantsMultiClickEvents(false); decreaseButton->setMouseAutoRepeatEnabled(true); // perform event subscriptions. increaseButton->subscribeEvent(Window::EventMouseButtonDown, Event::Subscriber(&Spinner::handleIncreaseButton, this)); decreaseButton->subscribeEvent(Window::EventMouseButtonDown, Event::Subscriber(&Spinner::handleDecreaseButton, this)); editbox->subscribeEvent(Window::EventTextChanged, Event::Subscriber(&Spinner::handleEditTextChange, this)); // final initialisation setTextInputMode(Integer); setCurrentValue(0.0f); performChildWindowLayout(); }
/************************************************************************* return true if the Editbox is read-only. *************************************************************************/ bool Combobox::isReadOnly(void) const { return getEditbox()->isReadOnly(); }
/************************************************************************* return the currently set validation string *************************************************************************/ const String& Combobox::getValidationString(void) const { return getEditbox()->getValidationString(); }
/************************************************************************* return the current position of the caret. *************************************************************************/ size_t Combobox::getCaretIndex(void) const { return getEditbox()->getCaretIndex(); }
/************************************************************************* return the length of the current selection (in code points / characters). *************************************************************************/ size_t Combobox::getSelectionLength(void) const { return getEditbox()->getSelectionLength(); }
/************************************************************************* return the current selection end point. *************************************************************************/ size_t Combobox::getSelectionEndIndex(void) const { return getEditbox()->getSelectionEndIndex(); }
/************************************************************************* Specify whether the Editbox is read-only. *************************************************************************/ void Combobox::setReadOnly(bool setting) { getEditbox()->setReadOnly(setting); }
/************************************************************************* return the maximum text length set for this Editbox. *************************************************************************/ size_t Combobox::getMaxTextLength(void) const { return getEditbox()->getMaxTextLength(); }
/************************************************************************* Set the current position of the caret. *************************************************************************/ void Combobox::setCaretIndex(size_t caret_pos) { getEditbox()->setCaretIndex(caret_pos); }
/************************************************************************* Set the text validation string. *************************************************************************/ void Combobox::setValidationString(const String& validation_string) { getEditbox()->setValidationString(validation_string); }
/************************************************************************* Define the current selection for the Editbox *************************************************************************/ void Combobox::setSelection(size_t start_pos, size_t end_pos) { getEditbox()->setSelection(start_pos, end_pos); }
/************************************************************************* Define the current selectionStart for the Editbox *************************************************************************/ void Combobox::setSelectionStart(size_t start_pos) { getEditbox()->setSelectionStart(start_pos); }
/************************************************************************* Define the current selectionLength for the Editbox *************************************************************************/ void Combobox::setSelectionLength(size_t length) { getEditbox()->setSelectionLength(length); }
/************************************************************************* return true if the Editbox text is valid given the currently set validation string. *************************************************************************/ Combobox::MatchState Combobox::getTextMatchState() const { return getEditbox()->getTextMatchState(); }
/************************************************************************* set the maximum text length for this Editbox. *************************************************************************/ void Combobox::setMaxTextLength(size_t max_len) { getEditbox()->setMaxTextLength(max_len); }