Skip to content

Commit

Permalink
correction to battery level
Browse files Browse the repository at this point in the history
better handling of multiple wiimote cursors on-screen
code refactor - move trigger class definition to gui.h
better filebrowser scrollbar
allow all controllers to use Home button to exit in-game
  • Loading branch information
dborth committed Apr 13, 2009
1 parent dafe532 commit fe9d114
Show file tree
Hide file tree
Showing 14 changed files with 467 additions and 334 deletions.
347 changes: 226 additions & 121 deletions source/ngc/gui/gui.h

Large diffs are not rendered by default.

151 changes: 92 additions & 59 deletions source/ngc/gui/gui_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,26 @@ GuiButton::GuiButton(int w, int h)
height = h;
image = NULL;
imageOver = NULL;
imageHold = NULL;
imageClick = NULL;
icon = NULL;
iconOver = NULL;
iconHold = NULL;
iconClick = NULL;

for(int i=0; i < 3; i++)
{
label[i] = NULL;
labelOver[i] = NULL;
labelHold[i] = NULL;
labelClick[i] = NULL;
}

soundOver = NULL;
soundHold = NULL;
soundClick = NULL;
selectable = true;
holdable = false;
clickable = true;
}

Expand All @@ -44,63 +52,71 @@ GuiButton::~GuiButton()
void GuiButton::SetImage(GuiImage* img)
{
image = img;

if(img)
img->SetParent(this);
if(img) img->SetParent(this);
}
void GuiButton::SetImageOver(GuiImage* img)
{
imageOver = img;

if(img)
img->SetParent(this);
if(img) img->SetParent(this);
}
void GuiButton::SetImageHold(GuiImage* img)
{
imageHold = img;
if(img) img->SetParent(this);
}
void GuiButton::SetImageClick(GuiImage* img)
{
imageClick = img;
if(img) img->SetParent(this);
}
void GuiButton::SetIcon(GuiImage* img)
{
icon = img;

if(img)
img->SetParent(this);
if(img) img->SetParent(this);
}
void GuiButton::SetIconOver(GuiImage* img)
{
iconOver = img;

if(img)
img->SetParent(this);
if(img) img->SetParent(this);
}
void GuiButton::SetLabel(GuiText* txt)
void GuiButton::SetIconHold(GuiImage* img)
{
label[0] = txt;

if(txt)
txt->SetParent(this);
iconHold = img;
if(img) img->SetParent(this);
}
void GuiButton::SetLabelOver(GuiText* txt)
void GuiButton::SetIconClick(GuiImage* img)
{
labelOver[0] = txt;

if(txt)
txt->SetParent(this);
iconClick = img;
if(img) img->SetParent(this);
}
void GuiButton::SetLabel(GuiText* txt, int n)
{
label[n] = txt;

if(txt)
txt->SetParent(this);
if(txt) txt->SetParent(this);
}
void GuiButton::SetLabelOver(GuiText* txt, int n)
{
labelOver[n] = txt;

if(txt)
txt->SetParent(this);
if(txt) txt->SetParent(this);
}
void GuiButton::SetLabelHold(GuiText* txt, int n)
{
labelHold[n] = txt;
if(txt) txt->SetParent(this);
}
void GuiButton::SetLabelClick(GuiText* txt, int n)
{
labelClick[n] = txt;
if(txt) txt->SetParent(this);
}
void GuiButton::SetSoundOver(GuiSound * snd)
{
soundOver = snd;
}
void GuiButton::SetSoundHold(GuiSound * snd)
{
soundHold = snd;
}
void GuiButton::SetSoundClick(GuiSound * snd)
{
soundClick = snd;
Expand Down Expand Up @@ -151,7 +167,7 @@ void GuiButton::Update(GuiTrigger * t)
{
if(state == STATE_DEFAULT) // we weren't on the button before!
{
state = STATE_SELECTED;
this->SetState(STATE_SELECTED, t->chan);

if(this->Rumble())
rumbleRequest[t->chan] = 1;
Expand All @@ -170,8 +186,8 @@ void GuiButton::Update(GuiTrigger * t)
}
else
{
if(state == STATE_SELECTED)
state = STATE_DEFAULT;
if(state == STATE_SELECTED && (stateChan == t->chan || stateChan == -1))
this->ResetState();

if(effectTarget == effectTargetOver && effectAmount == effectAmountOver)
{
Expand All @@ -187,65 +203,83 @@ void GuiButton::Update(GuiTrigger * t)
// button triggers
if(this->IsClickable())
{
s32 wm_btns, wm_btns_trig, cc_btns, cc_btns_trig;
for(int i=0; i<2; i++)
{
if(trigger[i] && (trigger[i]->chan == -1 || trigger[i]->chan == t->chan))
{
// higher 16 bits only (wiimote)
s32 wm_btns = t->wpad.btns_d << 16;
s32 wm_btns_trig = trigger[i]->wpad.btns_d << 16;
wm_btns = t->wpad.btns_d << 16;
wm_btns_trig = trigger[i]->wpad.btns_d << 16;

// lower 16 bits only (classic controller)
s32 cc_btns = t->wpad.btns_d >> 16;
s32 cc_btns_trig = trigger[i]->wpad.btns_d >> 16;
cc_btns = t->wpad.btns_d >> 16;
cc_btns_trig = trigger[i]->wpad.btns_d >> 16;

if(
(t->wpad.btns_d > 0 &&
wm_btns == wm_btns_trig ||
(cc_btns == cc_btns_trig && t->wpad.exp.type == EXP_CLASSIC)) ||
(t->pad.btns_d == trigger[i]->pad.btns_d && t->pad.btns_d > 0))
{
if(state == STATE_SELECTED)
{
state = STATE_CLICKED;

if(soundClick)
soundClick->Play();
}
else if(trigger[i]->type == TRIGGER_BUTTON_ONLY)
{
state = STATE_CLICKED;
}
else if(trigger[i]->type == TRIGGER_BUTTON_ONLY_IN_FOCUS &&
parentElement->IsFocused())
if(t->chan == stateChan || stateChan == -1)
{
state = STATE_CLICKED;
if(state == STATE_SELECTED)
{
this->SetState(STATE_CLICKED, t->chan);

if(soundClick)
soundClick->Play();
}
else if(trigger[i]->type == TRIGGER_BUTTON_ONLY)
{
this->SetState(STATE_CLICKED, t->chan);
}
else if(trigger[i]->type == TRIGGER_BUTTON_ONLY_IN_FOCUS &&
parentElement->IsFocused())
{
this->SetState(STATE_CLICKED, t->chan);
}
}
}
}
}
}

if(this->IsDraggable())
if(this->IsHoldable())
{
bool held = false;
s32 wm_btns, wm_btns_h, wm_btns_trig, cc_btns, cc_btns_h, cc_btns_trig;

for(int i=0; i<2; i++)
{
if(trigger[i] && (trigger[i]->chan == -1 || trigger[i]->chan == t->chan))
{
// higher 16 bits only (wiimote)
s32 wm_btns = t->wpad.btns_h << 16;
s32 wm_btns_trig = trigger[i]->wpad.btns_h << 16;
wm_btns = t->wpad.btns_d << 16;
wm_btns_h = t->wpad.btns_h << 16;
wm_btns_trig = trigger[i]->wpad.btns_h << 16;

// lower 16 bits only (classic controller)
s32 cc_btns = t->wpad.btns_h >> 16;
s32 cc_btns_trig = trigger[i]->wpad.btns_h >> 16;
cc_btns = t->wpad.btns_d >> 16;
cc_btns_h = t->wpad.btns_h >> 16;
cc_btns_trig = trigger[i]->wpad.btns_h >> 16;

if(
(t->wpad.btns_h > 0 &&
(t->wpad.btns_d > 0 &&
wm_btns == wm_btns_trig ||
(cc_btns == cc_btns_trig && t->wpad.exp.type == EXP_CLASSIC)) ||
(t->pad.btns_d == trigger[i]->pad.btns_h && t->pad.btns_d > 0))
{
if(trigger[i]->type == TRIGGER_HELD && state == STATE_SELECTED &&
(t->chan == stateChan || stateChan == -1))
this->SetState(STATE_CLICKED, t->chan);
}

if(
(t->wpad.btns_h > 0 &&
wm_btns_h == wm_btns_trig ||
(cc_btns_h == cc_btns_trig && t->wpad.exp.type == EXP_CLASSIC)) ||
(t->pad.btns_h == trigger[i]->pad.btns_h && t->pad.btns_h > 0))
{
if(trigger[i]->type == TRIGGER_HELD)
Expand All @@ -254,12 +288,11 @@ void GuiButton::Update(GuiTrigger * t)

if(!held && state == STATE_HELD && stateChan == t->chan)
{
state = STATE_DEFAULT;
this->ResetState();
}
else if(held && state == STATE_SELECTED)
else if(held && state == STATE_CLICKED && stateChan == t->chan)
{
state = STATE_HELD;
stateChan = t->chan; // record which controller is holding the button
this->SetState(STATE_HELD, t->chan);
}
}
}
Expand Down
21 changes: 15 additions & 6 deletions source/ngc/gui/gui_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ GuiElement::GuiElement()
rumble = true;
selectable = false;
clickable = false;
draggable = false;
holdable = false;
visible = true;
focus = -1; // cannot be focused
updateCB = NULL;
Expand Down Expand Up @@ -268,15 +268,24 @@ int GuiElement::GetState()
return state;
}

void GuiElement::SetState(int s)
int GuiElement::GetStateChan()
{
return stateChan;
}

void GuiElement::SetState(int s, int c)
{
state = s;
stateChan = c;
}

void GuiElement::ResetState()
{
if(state != STATE_DISABLED)
{
state = STATE_DEFAULT;
stateChan = -1;
}
}

void GuiElement::SetClickable(bool c)
Expand All @@ -289,9 +298,9 @@ void GuiElement::SetSelectable(bool s)
selectable = s;
}

void GuiElement::SetDraggable(bool d)
void GuiElement::SetHoldable(bool d)
{
draggable = d;
holdable = d;
}

bool GuiElement::IsSelectable()
Expand All @@ -312,12 +321,12 @@ bool GuiElement::IsClickable()
return clickable;
}

bool GuiElement::IsDraggable()
bool GuiElement::IsHoldable()
{
if(state == STATE_DISABLED)
return false;
else
return draggable;
return holdable;
}

void GuiElement::SetFocus(int f)
Expand Down
Loading

0 comments on commit fe9d114

Please sign in to comment.