2009-10-01 01:10:58 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* libwiigui
|
|
|
|
*
|
|
|
|
* Tantric 2009
|
|
|
|
*
|
|
|
|
* gui_window.cpp
|
|
|
|
*
|
|
|
|
* GUI class definitions
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "gui.h"
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
GuiWindow::GuiWindow()
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
width = 0;
|
|
|
|
height = 0;
|
|
|
|
focus = 0; // allow focus
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
GuiWindow::GuiWindow(int w, int h)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
width = w;
|
|
|
|
height = h;
|
|
|
|
focus = 0; // allow focus
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
GuiWindow::~GuiWindow()
|
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void GuiWindow::Append(GuiElement* e)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
LOCK( this );
|
2010-09-24 02:48:03 +02:00
|
|
|
if (e == NULL) return;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
Remove(e);
|
|
|
|
_elements.push_back(e);
|
|
|
|
e->SetParent(this);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void GuiWindow::Insert(GuiElement* e, u32 index)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
LOCK( this );
|
2010-09-24 02:48:03 +02:00
|
|
|
if (e == NULL || index > (_elements.size() - 1)) return;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
Remove(e);
|
|
|
|
_elements.insert(_elements.begin() + index, e);
|
|
|
|
e->SetParent(this);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void GuiWindow::Remove(GuiElement* e)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
LOCK( this );
|
2010-09-24 02:48:03 +02:00
|
|
|
if (e == NULL) return;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
for (u8 i = 0; i < _elements.size(); i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (e == _elements.at(i))
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
_elements.erase(_elements.begin() + i);
|
2010-09-19 01:16:05 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
void GuiWindow::RemoveAll()
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
LOCK( this );
|
|
|
|
_elements.clear();
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
GuiElement* GuiWindow::GetGuiElementAt(u32 index) const
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (index >= _elements.size()) return NULL;
|
|
|
|
return _elements.at(index);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
u32 GuiWindow::GetSize()
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
return _elements.size();
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
void GuiWindow::Draw()
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
LOCK( this );
|
2010-09-24 02:48:03 +02:00
|
|
|
if (_elements.size() == 0 || !this->IsVisible()) return;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
for (u8 i = 0; i < _elements.size(); i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
_elements.at(i)->Draw();
|
|
|
|
}
|
|
|
|
catch (const std::exception& e)
|
|
|
|
{
|
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
this->UpdateEffects();
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (parentElement && state == STATE_DISABLED)
|
|
|
|
//Menu_DrawRectangle(0,0,screenwidth,screenheight,(GXColor){0xbe, 0xca, 0xd5, 0x70},1);
|
|
|
|
Menu_DrawRectangle(0, 0, screenwidth, screenheight, ( GXColor )
|
|
|
|
{ 0, 0, 0, 0x70}, 1);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
2010-02-09 11:59:55 +01:00
|
|
|
void GuiWindow::DrawTooltip()
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
LOCK( this );
|
2010-09-24 02:48:03 +02:00
|
|
|
if (_elements.size() == 0 || !this->IsVisible()) return;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
for (u8 i = 0; i < _elements.size(); i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
_elements.at(i)->DrawTooltip();
|
|
|
|
}
|
|
|
|
catch (const std::exception& e)
|
|
|
|
{
|
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
2010-02-09 11:59:55 +01:00
|
|
|
void GuiWindow::ResetState()
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
LOCK( this );
|
2010-09-24 02:48:03 +02:00
|
|
|
if (state != STATE_DISABLED) state = STATE_DEFAULT;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
for (u8 i = 0; i < _elements.size(); i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
_elements.at(i)->ResetState();
|
|
|
|
}
|
|
|
|
catch (const std::exception& e)
|
|
|
|
{
|
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void GuiWindow::SetState(int s)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
LOCK( this );
|
|
|
|
state = s;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
for (u8 i = 0; i < _elements.size(); i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
_elements.at(i)->SetState(s);
|
|
|
|
}
|
|
|
|
catch (const std::exception& e)
|
|
|
|
{
|
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void GuiWindow::SetVisible(bool v)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
LOCK( this );
|
|
|
|
visible = v;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
for (u8 i = 0; i < _elements.size(); i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
_elements.at(i)->SetVisible(v);
|
|
|
|
}
|
|
|
|
catch (const std::exception& e)
|
|
|
|
{
|
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void GuiWindow::SetFocus(int f)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
LOCK( this );
|
|
|
|
focus = f;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (f == 1)
|
|
|
|
this->MoveSelectionVert(1);
|
|
|
|
else this->ResetState();
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void GuiWindow::ChangeFocus(GuiElement* e)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
LOCK( this );
|
2010-09-24 02:48:03 +02:00
|
|
|
if (parentElement) return; // this is only intended for the main window
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
for (u8 i = 0; i < _elements.size(); i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (e == _elements.at(i))
|
|
|
|
_elements.at(i)->SetFocus(1);
|
|
|
|
else if (_elements.at(i)->IsFocused() == 1) _elements.at(i)->SetFocus(0);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void GuiWindow::ToggleFocus(GuiTrigger * t)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
LOCK( this );
|
2010-09-24 02:48:03 +02:00
|
|
|
if (parentElement) return; // this is only intended for the main window
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
int found = -1;
|
|
|
|
int newfocus = -1;
|
|
|
|
u8 i;
|
|
|
|
|
|
|
|
// look for currently in focus element
|
2010-09-24 02:48:03 +02:00
|
|
|
for (i = 0; i < _elements.size(); i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (_elements.at(i)->IsFocused() == 1)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
found = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
catch (const std::exception& e)
|
|
|
|
{
|
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// element with focus not found, try to give focus
|
2010-09-24 02:48:03 +02:00
|
|
|
if (found == -1)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
for (i = 0; i < _elements.size(); i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (_elements.at(i)->IsFocused() == 0 && _elements.at(i)->GetState() != STATE_DISABLED) // focus is possible (but not set)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
_elements.at(i)->SetFocus(1); // give this element focus
|
2010-09-19 01:16:05 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
catch (const std::exception& e)
|
|
|
|
{
|
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// change focus
|
2010-09-24 02:48:03 +02:00
|
|
|
else if (t->wpad.btns_d & (WPAD_BUTTON_1 | WPAD_BUTTON_1 | WPAD_CLASSIC_BUTTON_PLUS) || t->pad.btns_d
|
|
|
|
& PAD_BUTTON_B)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
for (i = found; i < _elements.size(); i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (_elements.at(i)->IsFocused() == 0 && _elements.at(i)->GetState() != STATE_DISABLED) // focus is possible (but not set)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
newfocus = i;
|
2010-09-24 02:48:03 +02:00
|
|
|
_elements.at(i)->SetFocus(1); // give this element focus
|
|
|
|
_elements.at(found)->SetFocus(0); // disable focus on other element
|
2010-09-19 01:16:05 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
catch (const std::exception& e)
|
|
|
|
{
|
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (newfocus == -1)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
for (i = 0; i < found; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (_elements.at(i)->IsFocused() == 0 && _elements.at(i)->GetState() != STATE_DISABLED) // focus is possible (but not set)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
_elements.at(i)->SetFocus(1); // give this element focus
|
|
|
|
_elements.at(found)->SetFocus(0); // disable focus on other element
|
2010-09-19 01:16:05 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
catch (const std::exception& e)
|
|
|
|
{
|
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
int GuiWindow::GetSelected()
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
// find selected element
|
|
|
|
int found = -1;
|
2010-09-24 02:48:03 +02:00
|
|
|
for (u8 i = 0; i < _elements.size(); i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (_elements.at(i)->GetState() == STATE_SELECTED)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
found = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
catch (const std::exception& e)
|
|
|
|
{
|
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
return found;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// set element to left/right as selected
|
|
|
|
// there's probably a more clever way to do this, but this way works
|
2010-09-24 02:48:03 +02:00
|
|
|
void GuiWindow::MoveSelectionHor(int dir)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
LOCK( this );
|
|
|
|
int found = -1;
|
|
|
|
u16 left = 0;
|
|
|
|
u16 top = 0;
|
|
|
|
u8 i = 0;
|
|
|
|
|
|
|
|
int selected = this->GetSelected();
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (selected >= 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
left = _elements.at(selected)->GetLeft();
|
|
|
|
top = _elements.at(selected)->GetTop();
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// look for a button on the same row, to the left/right
|
2010-09-24 02:48:03 +02:00
|
|
|
for (i = 0; i < _elements.size(); i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (_elements.at(i)->IsSelectable())
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (_elements.at(i)->GetLeft() * dir > left * dir && _elements.at(i)->GetTop() == top)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (found == -1)
|
2010-09-19 01:16:05 +02:00
|
|
|
found = i;
|
2010-09-24 02:48:03 +02:00
|
|
|
else if (_elements.at(i)->GetLeft() * dir < _elements.at(found)->GetLeft() * dir) found = i; // this is a better match
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
catch (const std::exception& e)
|
|
|
|
{
|
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
if (found >= 0) goto matchfound;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
// match still not found, let's try the first button in the next row
|
2010-09-24 02:48:03 +02:00
|
|
|
for (i = 0; i < _elements.size(); i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (_elements.at(i)->IsSelectable())
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (_elements.at(i)->GetTop() * dir > top * dir)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (found == -1)
|
2010-09-19 01:16:05 +02:00
|
|
|
found = i;
|
2010-09-24 02:48:03 +02:00
|
|
|
else if (_elements.at(i)->GetTop() * dir < _elements.at(found)->GetTop() * dir)
|
2010-09-19 01:16:05 +02:00
|
|
|
found = i; // this is a better match
|
2010-09-24 02:48:03 +02:00
|
|
|
else if (_elements.at(i)->GetTop() * dir == _elements.at(found)->GetTop() * dir
|
|
|
|
&& _elements.at(i)->GetLeft() * dir < _elements.at(found)->GetLeft() * dir) found = i; // this is a better match
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
catch (const std::exception& e)
|
|
|
|
{
|
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// match found
|
2010-09-24 02:48:03 +02:00
|
|
|
matchfound: if (found >= 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
_elements.at(found)->SetState(STATE_SELECTED);
|
|
|
|
if (selected >= 0) _elements.at(selected)->ResetState();
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void GuiWindow::MoveSelectionVert(int dir)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
LOCK( this );
|
|
|
|
int found = -1;
|
|
|
|
u16 left = 0;
|
|
|
|
u16 top = 0;
|
|
|
|
u8 i = 0;
|
|
|
|
|
|
|
|
int selected = this->GetSelected();
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (selected >= 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
left = _elements.at(selected)->GetLeft();
|
|
|
|
top = _elements.at(selected)->GetTop();
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// look for a button above/below, with the least horizontal difference
|
2010-09-24 02:48:03 +02:00
|
|
|
for (i = 0; i < _elements.size(); i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (_elements.at(i)->IsSelectable())
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (_elements.at(i)->GetTop() * dir > top * dir)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (found == -1)
|
2010-09-19 01:16:05 +02:00
|
|
|
found = i;
|
2010-09-24 02:48:03 +02:00
|
|
|
else if (_elements.at(i)->GetTop() * dir < _elements.at(found)->GetTop() * dir)
|
2010-09-19 01:16:05 +02:00
|
|
|
found = i; // this is a better match
|
2010-09-24 02:48:03 +02:00
|
|
|
else if (_elements.at(i)->GetTop() * dir == _elements.at(found)->GetTop() * dir && abs(
|
|
|
|
_elements.at(i)->GetLeft() - left) < abs(_elements.at(found)->GetLeft() - left)) found = i;
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
catch (const std::exception& e)
|
|
|
|
{
|
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
if (found >= 0) goto matchfound;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
// match found
|
2010-09-24 02:48:03 +02:00
|
|
|
matchfound: if (found >= 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
_elements.at(found)->SetState(STATE_SELECTED);
|
|
|
|
if (selected >= 0) _elements.at(selected)->ResetState();
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void GuiWindow::Update(GuiTrigger * t)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
LOCK( this );
|
2010-09-24 02:48:03 +02:00
|
|
|
if (_elements.size() == 0 || (state == STATE_DISABLED && parentElement)) return;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
for (u8 i = 0; i < _elements.size(); i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
_elements.at(i)->Update(t);
|
|
|
|
}
|
|
|
|
catch (const std::exception& e)
|
|
|
|
{
|
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
this->ToggleFocus(t);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (focus) // only send actions to this window if it's in focus
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
// pad/joystick navigation
|
2010-09-24 02:48:03 +02:00
|
|
|
if (t->Right())
|
|
|
|
this->MoveSelectionHor(1);
|
|
|
|
else if (t->Left())
|
|
|
|
this->MoveSelectionHor(-1);
|
|
|
|
else if (t->Down())
|
|
|
|
this->MoveSelectionVert(1);
|
|
|
|
else if (t->Up()) this->MoveSelectionVert(-1);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (updateCB) updateCB(this);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|