Improved text box widget implementation. Main consequence is that keyboard naviagtion is now possible in player info dialog
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3644 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
cf85ff876d
commit
5c57b19a0a
@ -150,9 +150,18 @@ EnterPlayerNameDialog::EnterPlayerNameDialog(const float w, const float h) :
|
||||
const int bottomHeight = bottomYTo - bottomYFrom;
|
||||
const int textAreaYFrom = bottomYFrom + bottomHeight/2 - textHeight/2;
|
||||
|
||||
core::rect< s32 > area_bottom(50, textAreaYFrom - 10, m_area.getWidth()-50, textAreaYFrom + textHeight + 10);
|
||||
textCtrl = GUIEngine::getGUIEnv()->addEditBox (L"", area_bottom, true /* border */, m_irrlicht_window);
|
||||
GUIEngine::getGUIEnv()->setFocus(textCtrl);
|
||||
textCtrl = new TextBoxWidget();
|
||||
textCtrl->m_type = WTYPE_BUTTON;
|
||||
textCtrl->m_properties[PROP_TEXT] = "";
|
||||
textCtrl->x = 50;
|
||||
textCtrl->y = textAreaYFrom - 10;
|
||||
textCtrl->w = m_area.getWidth()-100;
|
||||
textCtrl->h = textHeight + 5;
|
||||
textCtrl->setParent(m_irrlicht_window);
|
||||
m_children.push_back(textCtrl);
|
||||
textCtrl->add();
|
||||
GUIEngine::getGUIEnv()->setFocus( textCtrl->m_element );
|
||||
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------------
|
||||
@ -160,7 +169,8 @@ EnterPlayerNameDialog::EnterPlayerNameDialog(const float w, const float h) :
|
||||
void EnterPlayerNameDialog::onEnterPressedInternal()
|
||||
{
|
||||
stringw playerName = textCtrl->getText();
|
||||
StateManager::gotNewPlayerName( playerName );
|
||||
if(playerName.size() > 0)
|
||||
StateManager::gotNewPlayerName( playerName );
|
||||
ModalDialog::dismiss();
|
||||
}
|
||||
|
||||
@ -222,7 +232,6 @@ TrackInfoDialog::TrackInfoDialog(const char* trackName, ITexture* screenshot, co
|
||||
void TrackInfoDialog::onEnterPressedInternal()
|
||||
{
|
||||
IVideoDriver* driver = GUIEngine::getDriver();
|
||||
IGUIFont* font = GUIEngine::getFont();
|
||||
|
||||
// TODO : draw a loading screen
|
||||
driver->endScene();
|
||||
@ -254,18 +263,28 @@ PlayerInfoDialog::PlayerInfoDialog(Player* player, const float w, const float h)
|
||||
|
||||
IGUIFont* font = GUIEngine::getFont();
|
||||
const int textHeight = font->getDimension(L"X").Height;
|
||||
|
||||
const int buttonHeight = textHeight + 10;
|
||||
|
||||
stringw playerName = player->getName();
|
||||
|
||||
core::rect< s32 > area_bottom(50, y1 - textHeight/2, m_area.getWidth()-50, y1 + textHeight/2 + 10);
|
||||
GUIEngine::getGUIEnv()->addEditBox(playerName.c_str(), area_bottom, true /* border */, m_irrlicht_window);
|
||||
{
|
||||
TextBoxWidget* widget = new TextBoxWidget();
|
||||
widget->m_type = WTYPE_BUTTON;
|
||||
widget->m_properties[PROP_ID] = "renameplayer";
|
||||
widget->m_properties[PROP_TEXT] = player->getName();
|
||||
widget->x = 50;
|
||||
widget->y = y1 - textHeight/2;
|
||||
widget->w = m_area.getWidth()-100;
|
||||
widget->h = textHeight + 5;
|
||||
widget->setParent(m_irrlicht_window);
|
||||
m_children.push_back(widget);
|
||||
widget->add();
|
||||
GUIEngine::getGUIEnv()->setFocus( widget->m_element );
|
||||
}
|
||||
|
||||
{
|
||||
ButtonWidget* widget = new ButtonWidget();
|
||||
widget->m_type = WTYPE_BUTTON;
|
||||
widget->m_properties[PROP_TEXT] = _("Rename");
|
||||
widget->m_properties[PROP_ID] = "renameplayer";
|
||||
widget->m_properties[PROP_TEXT] = _("Rename"); // TODO : catch events
|
||||
|
||||
const int textWidth = font->getDimension( stringw(widget->m_properties[PROP_TEXT].c_str()).c_str() ).Width + 40;
|
||||
|
||||
@ -281,7 +300,8 @@ PlayerInfoDialog::PlayerInfoDialog(Player* player, const float w, const float h)
|
||||
{
|
||||
ButtonWidget* widget = new ButtonWidget();
|
||||
widget->m_type = WTYPE_BUTTON;
|
||||
widget->m_properties[PROP_TEXT] = _("Remove");
|
||||
widget->m_properties[PROP_ID] = "removeplayer";
|
||||
widget->m_properties[PROP_TEXT] = _("Remove"); // TODO : catch events
|
||||
|
||||
const int textWidth = font->getDimension( stringw(widget->m_properties[PROP_TEXT].c_str()).c_str() ).Width + 40;
|
||||
|
||||
|
@ -23,6 +23,7 @@ class Player;
|
||||
namespace GUIEngine
|
||||
{
|
||||
class Widget;
|
||||
class TextBoxWidget;
|
||||
|
||||
/**
|
||||
* Base class, derive your own.
|
||||
@ -65,7 +66,7 @@ public:
|
||||
|
||||
class EnterPlayerNameDialog : public ModalDialog
|
||||
{
|
||||
irr::gui::IGUIEditBox* textCtrl;
|
||||
TextBoxWidget* textCtrl;
|
||||
public:
|
||||
/**
|
||||
* Creates a modal dialog with given percentage of screen width and height
|
||||
|
@ -851,6 +851,7 @@ void Skin::draw3DSunkenPane (IGUIElement *element, video::SColor bgcolor, bool f
|
||||
{
|
||||
if(dynamic_cast<IGUIEditBox*>(element) != NULL)
|
||||
{
|
||||
// TODO : make configurable in skin file
|
||||
GUIEngine::getDriver()->draw2DRectangle( SColor(100, 150, 150, 150), rect );
|
||||
return;
|
||||
}
|
||||
@ -878,10 +879,12 @@ void Skin::draw3DSunkenPane (IGUIElement *element, video::SColor bgcolor, bool f
|
||||
core::rect< s32 > Skin::draw3DWindowBackground (IGUIElement *element, bool drawTitleBar, video::SColor titleBarColor, const core::rect< s32 > &rect, const core::rect< s32 > *clip)
|
||||
{
|
||||
// fade out background
|
||||
// TODO : make configurable in skin file
|
||||
GUIEngine::getDriver()->draw2DRectangle( SColor(150, 255, 255, 255),
|
||||
core::rect< s32 >(position2d< s32 >(0,0) , GUIEngine::getDriver()->getCurrentRenderTargetSize()) );
|
||||
|
||||
// draw frame (since it's transluscent, draw many times to get opacity)
|
||||
// TODO : make configurable in skin file
|
||||
drawBoxFromStretchableTexture(rect, SkinConfig::m_render_params["window::neutral"]);
|
||||
drawBoxFromStretchableTexture(rect, SkinConfig::m_render_params["window::neutral"]);
|
||||
|
||||
|
@ -1277,7 +1277,7 @@ void ListWidget::add()
|
||||
{
|
||||
rect<s32> widget_size = rect<s32>(x, y, x + w, y + h);
|
||||
|
||||
m_element = GUIEngine::getGUIEnv()->addListBox (widget_size, NULL, ++id_counter);
|
||||
m_element = GUIEngine::getGUIEnv()->addListBox (widget_size, m_parent, ++id_counter);
|
||||
}
|
||||
|
||||
void ListWidget::addItem(const char* item)
|
||||
@ -1298,4 +1298,31 @@ std::string ListWidget::getSelectionName() const
|
||||
IGUIListBox* list = dynamic_cast<IGUIListBox*>(m_element);
|
||||
assert(list != NULL);
|
||||
return stringc( list->getListItem( list->getSelected() ) ).c_str();
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
#pragma mark -
|
||||
#pragma mark Text Box Widget
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void TextBoxWidget::add()
|
||||
{
|
||||
rect<s32> widget_size = rect<s32>(x, y, x + w, y + h);
|
||||
|
||||
stringw text = m_properties[PROP_TEXT].c_str();
|
||||
m_element = GUIEngine::getGUIEnv()->addEditBox(text.c_str(), widget_size,
|
||||
true /* border */, m_parent, ++id_counter);
|
||||
id = m_element->getID();
|
||||
m_element->setTabOrder(id);
|
||||
m_element->setTabGroup(false);
|
||||
}
|
||||
|
||||
stringw TextBoxWidget::getText() const
|
||||
{
|
||||
IGUIEditBox* textCtrl = dynamic_cast<IGUIEditBox*>(m_element);
|
||||
assert(textCtrl != NULL);
|
||||
|
||||
return stringw(textCtrl->getText());
|
||||
}
|
||||
|
@ -43,7 +43,8 @@ namespace GUIEngine
|
||||
WTYPE_DIV,
|
||||
WTYPE_RIBBON_GRID,
|
||||
WTYPE_MODEL_VIEW,
|
||||
WTYPE_LIST
|
||||
WTYPE_LIST,
|
||||
WTYPE_TEXTBOX
|
||||
};
|
||||
|
||||
enum Property
|
||||
@ -355,6 +356,15 @@ namespace GUIEngine
|
||||
int getSelection() const;
|
||||
std::string getSelectionName() const;
|
||||
};
|
||||
|
||||
class TextBoxWidget : public Widget
|
||||
{
|
||||
public:
|
||||
void add();
|
||||
void addItem(const char* item);
|
||||
|
||||
stringw getText() const;
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user