made checkboxes clickable (those in options don't have any effect yet)

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3399 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2009-04-18 23:25:59 +00:00
parent 7ecc233171
commit 54c61cb569
6 changed files with 53 additions and 42 deletions

View File

@ -301,7 +301,7 @@ bool Screen::OnEvent(const SEvent& event)
if(w == NULL) break;
Widget* widget_to_call = w;
while(widget_to_call->m_parent != NULL) widget_to_call = widget_to_call->m_parent; // Find topmost parent
while(widget_to_call->m_event_handler != NULL) widget_to_call = widget_to_call->m_event_handler; // Find topmost parent
if(widget_to_call->leftPressed())
transmitEvent(w, w->m_properties[PROP_ID]);
@ -316,7 +316,7 @@ bool Screen::OnEvent(const SEvent& event)
if(w == NULL) break;
Widget* widget_to_call = w;
while(widget_to_call->m_parent != NULL) widget_to_call = widget_to_call->m_parent; // Find topmost parent
while(widget_to_call->m_event_handler != NULL) widget_to_call = widget_to_call->m_event_handler; // Find topmost parent
if(widget_to_call->rightPressed())
transmitEvent(widget_to_call, w->m_properties[PROP_ID]);
@ -399,10 +399,10 @@ bool Screen::OnEvent(const SEvent& event)
Widget* w = getWidget(id);
if(w == NULL) break;
Widget* parent = w->m_parent;
if(w->m_parent != NULL)
Widget* parent = w->m_event_handler;
if(w->m_event_handler != NULL)
{
while(parent->m_parent != NULL) parent = parent->m_parent; // Find topmost parent
while(parent->m_event_handler != NULL && parent->m_event_handler != parent) parent = parent->m_event_handler; // Find topmost parent
if(parent->transmitEvent(w, w->m_properties[PROP_ID]))
transmitEvent(parent, parent->m_properties[PROP_ID]);
@ -416,13 +416,13 @@ bool Screen::OnEvent(const SEvent& event)
if(w == NULL) break;
// select ribbons on hover
if(w->m_parent != NULL && w->m_parent->m_type == WTYPE_RIBBON)
if(w->m_event_handler != NULL && w->m_event_handler->m_type == WTYPE_RIBBON)
{
RibbonWidget* ribbon = dynamic_cast<RibbonWidget*>(w->m_parent);
RibbonWidget* ribbon = dynamic_cast<RibbonWidget*>(w->m_event_handler);
if(ribbon == NULL) break;
if(ribbon->mouseHovered(w))
transmitEvent(ribbon, ribbon->m_properties[PROP_ID]);
if(ribbon->m_parent != NULL) ribbon->m_parent->mouseHovered(w);
if(ribbon->m_event_handler != NULL) ribbon->m_event_handler->mouseHovered(w);
getGUIEnv()->setFocus(ribbon->m_element);
}
else

View File

@ -282,7 +282,7 @@ void Skin::drawRibbonChild(const core::rect< s32 > &rect, const Widget* widget,
{
bool mark_selected = widget->isSelected();
const bool parent_focused = GUIEngine::getGUIEnv()->getFocus() == widget->m_parent->m_element;
const bool parent_focused = GUIEngine::getGUIEnv()->getFocus() == widget->m_event_handler->m_element;
/* tab-bar ribbons */
if(widget->m_type == WTYPE_BUTTON)
@ -317,14 +317,14 @@ void Skin::drawRibbonChild(const core::rect< s32 > &rect, const Widget* widget,
{
bool use_glow = true;
if (widget->m_parent != NULL && widget->m_parent->m_properties[PROP_SQUARE] == "true") use_glow = false;
if (widget->m_parent != NULL && widget->m_parent->m_parent != NULL &&
widget->m_parent->m_parent->m_properties[PROP_SQUARE] == "true") use_glow = false;
if (widget->m_event_handler != NULL && widget->m_event_handler->m_properties[PROP_SQUARE] == "true") use_glow = false;
if (widget->m_event_handler != NULL && widget->m_event_handler->m_event_handler != NULL &&
widget->m_event_handler->m_event_handler->m_properties[PROP_SQUARE] == "true") use_glow = false;
if(widget->m_parent != NULL && widget->m_parent->m_type == WTYPE_RIBBON &&
((RibbonWidget*)widget->m_parent)->getRibbonType() == RIBBON_TOOLBAR &&
!GUIEngine::getGUIEnv()->hasFocus(widget->m_parent->m_element)) mark_selected = false;
if(widget->m_event_handler != NULL && widget->m_event_handler->m_type == WTYPE_RIBBON &&
((RibbonWidget*)widget->m_event_handler)->getRibbonType() == RIBBON_TOOLBAR &&
!GUIEngine::getGUIEnv()->hasFocus(widget->m_event_handler->m_element)) mark_selected = false;
if(mark_selected)
{
@ -424,7 +424,7 @@ void Skin::drawSpinnerChild(const core::rect< s32 > &rect, Widget* widget, const
if(pressed)
{
Widget* spinner = widget->m_parent;
Widget* spinner = widget->m_event_handler;
int areas = 0;
//std::cout << "drawing spinner child " << widget->m_properties[PROP_ID].c_str() << std::endl;
@ -551,11 +551,11 @@ void Skin::process3DPane(IGUIElement *element, const core::rect< s32 > &rect, co
// does not have widgets for everything we need. so at render time, we just check
// which type this button represents and render accordingly
if(widget->m_parent != NULL && widget->m_parent->m_type == WTYPE_RIBBON)
if(widget->m_event_handler != NULL && widget->m_event_handler->m_type == WTYPE_RIBBON)
{
drawRibbonChild(rect, widget, pressed /* pressed */, focused /* focused */);
}
else if(widget->m_parent != NULL && widget->m_parent->m_type == WTYPE_SPINNER)
else if(widget->m_event_handler != NULL && widget->m_event_handler->m_type == WTYPE_SPINNER)
{
drawSpinnerChild(rect, widget, pressed /* pressed */, focused /* focused */);
}

View File

@ -42,7 +42,7 @@ Widget::Widget()
m_element = NULL;
m_type = WTYPE_NONE;
m_selected = false;
m_parent = NULL;
m_event_handler = NULL;
}
// -----------------------------------------------------------------------------
/** will write to either absolute or percentage, depending on the case.
@ -242,6 +242,7 @@ void LabelWidget::add()
CheckBoxWidget::CheckBoxWidget()
{
m_state = true;
m_event_handler = this;
}
void CheckBoxWidget::add()
@ -256,6 +257,15 @@ void CheckBoxWidget::add()
m_element->setTabGroup(false);
}
bool CheckBoxWidget::transmitEvent(Widget* w, std::string& originator)
{
/* toggle */
m_state = !m_state;
/* notify main event handler */
return true;
}
#if 0
#pragma mark -
#pragma mark Gauge Widget
@ -401,9 +411,9 @@ bool RibbonWidget::rightPressed()
m_selection++;
if(m_selection >= m_children.size())
{
if(m_parent != NULL)
if(m_event_handler != NULL)
{
((RibbonGridWidget*)m_parent)->scroll(1); // FIXME? - find cleaner way to propagate event to parent
((RibbonGridWidget*)m_event_handler)->scroll(1); // FIXME? - find cleaner way to propagate event to parent
m_selection = m_children.size()-1;
}
else m_selection = 0;
@ -418,9 +428,9 @@ bool RibbonWidget::leftPressed()
m_selection--;
if(m_selection < 0)
{
if(m_parent != NULL)
if(m_event_handler != NULL)
{
((RibbonGridWidget*)m_parent)->scroll(-1); // FIXME? - find cleaner way to propagate event to parent
((RibbonGridWidget*)m_event_handler)->scroll(-1); // FIXME? - find cleaner way to propagate event to parent
m_selection = 0;
}
else m_selection = m_children.size()-1;
@ -432,7 +442,7 @@ bool RibbonWidget::leftPressed()
// -----------------------------------------------------------------------------
void RibbonWidget::focused()
{
if(m_parent != NULL) ((RibbonGridWidget*)m_parent)->updateLabel( this );
if(m_event_handler != NULL) ((RibbonGridWidget*)m_event_handler)->updateLabel( this );
}
// -----------------------------------------------------------------------------
bool RibbonWidget::mouseHovered(Widget* child)
@ -579,7 +589,7 @@ void RibbonWidget::add()
subbtn->setTabGroup(false);
m_children[i].id = subbtn->getID();
m_children[i].m_parent = this;
m_children[i].m_event_handler = this;
}// next sub-button
id = m_element->getID();
@ -637,7 +647,7 @@ void SpinnerWidget::add()
m_children[0].m_element = left_arrow;
m_children[0].m_type = WTYPE_BUTTON;
left_arrow->setTabStop(false);
m_children[0].m_parent = this;
m_children[0].m_event_handler = this;
m_children[0].m_properties[PROP_ID] = "left";
m_children[0].id = m_children[0].m_element->getID();
@ -683,7 +693,7 @@ void SpinnerWidget::add()
right_arrow->setTabStop(false);
m_children[2].m_element = right_arrow;
m_children[2].m_type = WTYPE_BUTTON;
m_children[2].m_parent = this;
m_children[2].m_event_handler = this;
m_children[2].m_properties[PROP_ID] = "right";
m_children[2].id = m_children[2].m_element->getID();
}
@ -794,7 +804,7 @@ void RibbonGridWidget::add()
ribbon->h = (int)(row_height);
ribbon->m_type = WTYPE_RIBBON;
ribbon->m_properties[PROP_ID] = this->m_properties[PROP_ID];
ribbon->m_parent = this;
ribbon->m_event_handler = this;
// add columns
for(int i=0; i<m_col_amount; i++)
@ -843,7 +853,7 @@ void RibbonGridWidget::add()
IGUIButton* right_arrow = GUIEngine::getGUIEnv()->addButton(right_arrow_location, NULL, ++id_counter_2, rmessage.c_str(), L"");
right_arrow->setTabStop(false);
m_right_widget->m_element = right_arrow;
m_right_widget->m_parent = this;
m_right_widget->m_event_handler = this;
m_right_widget->m_properties[PROP_ID] = "right";
m_right_widget->id = right_arrow->getID();
m_children.push_back( m_right_widget );
@ -856,7 +866,7 @@ void RibbonGridWidget::add()
IGUIButton* left_arrow = GUIEngine::getGUIEnv()->addButton(left_arrow_location, NULL, ++id_counter_2, lmessage.c_str(), L"");
left_arrow->setTabStop(false);
m_left_widget->m_element = left_arrow;
m_left_widget->m_parent = this;
m_left_widget->m_event_handler = this;
m_left_widget->m_properties[PROP_ID] = "left";
m_left_widget->id = left_arrow->getID();
m_children.push_back( m_left_widget );
@ -902,8 +912,8 @@ bool RibbonGridWidget::transmitEvent(Widget* w, std::string& originator)
}
// if it's something else, it might be a ribbon child with its own parent
if(w->m_parent != NULL && w->m_parent != this)
return w->m_parent->transmitEvent(w, originator);
if(w->m_event_handler != NULL && w->m_event_handler != this)
return w->m_event_handler->transmitEvent(w, originator);
// if we got there, must be a ribbon itself. in this case we can just transmit the event directly
return true;

View File

@ -80,11 +80,11 @@ namespace GUIEngine
virtual bool rightPressed() { return false; }
virtual bool leftPressed() { return false; }
/** used when you set parents - see m_parent explainations below.
/** used when you set parents - see m_event_handler explainations below.
returns whether main event callback should be notified or not */
virtual bool transmitEvent(Widget* w, std::string& originator) { return true; }
/** used when you set eventSupervisors - see m_parent explainations below
/** used when you set eventSupervisors - see m_event_handler explainations below
called when one of a widget's children is hovered.
Returns 'true' if main event handler should be notified of a change. */
virtual bool mouseHovered(Widget* child) { return false; }
@ -95,14 +95,14 @@ namespace GUIEngine
void readCoords(Widget* parent=NULL);
/**
* This is set to NULL by default; set to something else in a child to mean
* that events happening on the said child should not go straight into the
* event handler. Instead, they will first be passed to m_parent->transmitEvent,
* This is set to NULL by default; set to something else in a widget to mean
* that events happening on this widget should not go straight into the
* event handler. Instead, they will first be passed to m_event_handler->transmitEvent,
* which is usually the parent analysing events from its children.
* This is especially useful with logical widgets built with more than
* one irrlicht widgets (e.g. Spinner, Ribbon)
*/
Widget* m_parent;
Widget* m_event_handler;
static bool convertToCoord(std::string& x, int* absolute, int* percentage);
public:
@ -164,6 +164,7 @@ namespace GUIEngine
{
void add();
bool m_state;
bool transmitEvent(Widget* w, std::string& originator);
public:
CheckBoxWidget();
virtual ~CheckBoxWidget() {}

View File

@ -29,7 +29,7 @@ Item::Item(ItemType type, const Vec3& xyz, const Vec3& normal,
scene::IMesh* mesh, unsigned int item_id, bool rotate)
{
m_rotate = rotate;
m_parent = NULL;
m_event_handler = NULL;
m_deactive_time = 0;
// Sets heading to 0, and sets pitch and roll depending on the normal. */
Vec3 hpr = Vec3(0, normal);
@ -59,14 +59,14 @@ void Item::reset()
//-----------------------------------------------------------------------------
void Item::setParent(Kart* parent)
{
m_parent = parent;
m_event_handler = parent;
m_deactive_time = 1.5f;
}
//-----------------------------------------------------------------------------
void Item::update(float delta)
{
if(m_parent != NULL && m_deactive_time > 0) m_deactive_time -= delta;
if(m_event_handler != NULL && m_deactive_time > 0) m_deactive_time -= delta;
if(m_collected)
{

View File

@ -55,7 +55,7 @@ private:
/** optionally, set this if this item was laid by a particular kart. in this case,
the 'm_deactive_time' will also be set - see below. */
Kart* m_parent;
Kart* m_event_handler;
/** optionally, if item was placed by a kart, a timer can be used to temporarly
deactivate collision so a kart is not hit by its own item */
float m_deactive_time;