00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "gui.h"
00012
00013
00014
00015
00016 GuiButton::GuiButton()
00017 {
00018 image = NULL;
00019 imageOver = NULL;
00020 imageHold = NULL;
00021 imageClick = NULL;
00022 icon = NULL;
00023 iconOver = NULL;
00024 iconHold = NULL;
00025 iconClick = NULL;
00026
00027 for(int i=0; i < 3; i++)
00028 {
00029 label[i] = NULL;
00030 labelOver[i] = NULL;
00031 labelHold[i] = NULL;
00032 labelClick[i] = NULL;
00033 }
00034
00035 soundOver = NULL;
00036 soundHold = NULL;
00037 soundClick = NULL;
00038 selectable = true;
00039 holdable = false;
00040 clickable = true;
00041 }
00042
00043 GuiButton::GuiButton(int w, int h)
00044 {
00045 width = w;
00046 height = h;
00047 image = NULL;
00048 imageOver = NULL;
00049 imageHold = NULL;
00050 imageClick = NULL;
00051 icon = NULL;
00052 iconOver = NULL;
00053 iconHold = NULL;
00054 iconClick = NULL;
00055
00056 for(int i=0; i < 3; i++)
00057 {
00058 label[i] = NULL;
00059 labelOver[i] = NULL;
00060 labelHold[i] = NULL;
00061 labelClick[i] = NULL;
00062 }
00063
00064 soundOver = NULL;
00065 soundHold = NULL;
00066 soundClick = NULL;
00067 selectable = true;
00068 holdable = false;
00069 clickable = true;
00070 }
00071
00072
00073
00074
00075 GuiButton::~GuiButton()
00076 {
00077 }
00078
00079 void GuiButton::SetImage(GuiImage* img)
00080 {
00081 image = img;
00082 if(img) img->SetParent(this);
00083 }
00084 void GuiButton::SetImageOver(GuiImage* img)
00085 {
00086 imageOver = img;
00087 if(img) img->SetParent(this);
00088 }
00089 void GuiButton::SetImageHold(GuiImage* img)
00090 {
00091 imageHold = img;
00092 if(img) img->SetParent(this);
00093 }
00094 void GuiButton::SetImageClick(GuiImage* img)
00095 {
00096 imageClick = img;
00097 if(img) img->SetParent(this);
00098 }
00099 void GuiButton::SetIcon(GuiImage* img)
00100 {
00101 icon = img;
00102 if(img) img->SetParent(this);
00103 }
00104 void GuiButton::SetIconOver(GuiImage* img)
00105 {
00106 iconOver = img;
00107 if(img) img->SetParent(this);
00108 }
00109 void GuiButton::SetIconHold(GuiImage* img)
00110 {
00111 iconHold = img;
00112 if(img) img->SetParent(this);
00113 }
00114 void GuiButton::SetIconClick(GuiImage* img)
00115 {
00116 iconClick = img;
00117 if(img) img->SetParent(this);
00118 }
00119 void GuiButton::SetLabel(GuiText* txt, int n)
00120 {
00121 label[n] = txt;
00122 if(txt) txt->SetParent(this);
00123 }
00124 void GuiButton::SetLabelOver(GuiText* txt, int n)
00125 {
00126 labelOver[n] = txt;
00127 if(txt) txt->SetParent(this);
00128 }
00129 void GuiButton::SetLabelHold(GuiText* txt, int n)
00130 {
00131 labelHold[n] = txt;
00132 if(txt) txt->SetParent(this);
00133 }
00134 void GuiButton::SetLabelClick(GuiText* txt, int n)
00135 {
00136 labelClick[n] = txt;
00137 if(txt) txt->SetParent(this);
00138 }
00139 void GuiButton::SetSoundOver(GuiSound * snd)
00140 {
00141 soundOver = snd;
00142 }
00143 void GuiButton::SetSoundHold(GuiSound * snd)
00144 {
00145 soundHold = snd;
00146 }
00147 void GuiButton::SetSoundClick(GuiSound * snd)
00148 {
00149 soundClick = snd;
00150 }
00151
00152
00153
00154
00155 void GuiButton::Draw()
00156 {
00157 if(!this->IsVisible())
00158 return;
00159
00160
00161 if((state == STATE_SELECTED || state == STATE_HELD) && imageOver)
00162 imageOver->Draw();
00163 else if(image)
00164 image->Draw();
00165
00166 if((state == STATE_SELECTED || state == STATE_HELD) && iconOver)
00167 iconOver->Draw();
00168 else if(icon)
00169 icon->Draw();
00170
00171 for(int i=0; i<3; i++)
00172 {
00173 if((state == STATE_SELECTED || state == STATE_HELD) && labelOver[i])
00174 labelOver[i]->Draw();
00175 else if(label[i])
00176 label[i]->Draw();
00177 }
00178
00179 this->UpdateEffects();
00180 }
00181
00182 void GuiButton::Update(GuiTrigger * t)
00183 {
00184 if(state == STATE_CLICKED || state == STATE_DISABLED || !t)
00185 return;
00186 else if(parentElement && parentElement->GetState() == STATE_DISABLED)
00187 return;
00188
00189 #ifdef HW_RVL
00190
00191 if(t->wpad->ir.valid && t->chan >= 0)
00192 {
00193 if(this->IsInside(t->wpad->ir.x, t->wpad->ir.y))
00194 {
00195 if(state == STATE_DEFAULT)
00196 {
00197 this->SetState(STATE_SELECTED, t->chan);
00198
00199 if(this->Rumble())
00200 rumbleRequest[t->chan] = 1;
00201
00202 if(soundOver)
00203 soundOver->Play();
00204
00205 if(effectsOver && !effects)
00206 {
00207
00208 effects = effectsOver;
00209 effectAmount = effectAmountOver;
00210 effectTarget = effectTargetOver;
00211 }
00212 }
00213 }
00214 else
00215 {
00216 if(state == STATE_SELECTED && (stateChan == t->chan || stateChan == -1))
00217 this->ResetState();
00218
00219 if(effectTarget == effectTargetOver && effectAmount == effectAmountOver)
00220 {
00221
00222 effects = effectsOver;
00223 effectAmount = -effectAmountOver;
00224 effectTarget = 100;
00225 }
00226 }
00227 }
00228 #endif
00229
00230
00231 if(this->IsClickable())
00232 {
00233 s32 wm_btns, wm_btns_trig, cc_btns, cc_btns_trig;
00234 for(int i=0; i<2; i++)
00235 {
00236 if(trigger[i] && (trigger[i]->chan == -1 || trigger[i]->chan == t->chan))
00237 {
00238
00239 wm_btns = t->wpad->btns_d << 16;
00240 wm_btns_trig = trigger[i]->wpad->btns_d << 16;
00241
00242
00243 cc_btns = t->wpad->btns_d >> 16;
00244 cc_btns_trig = trigger[i]->wpad->btns_d >> 16;
00245
00246 if(
00247 (t->wpad->btns_d > 0 &&
00248 (wm_btns == wm_btns_trig ||
00249 (cc_btns == cc_btns_trig && t->wpad->exp.type == EXP_CLASSIC))) ||
00250 (t->pad.btns_d == trigger[i]->pad.btns_d && t->pad.btns_d > 0))
00251 {
00252 if(t->chan == stateChan || stateChan == -1)
00253 {
00254 if(state == STATE_SELECTED)
00255 {
00256 if(!t->wpad->ir.valid || this->IsInside(t->wpad->ir.x, t->wpad->ir.y))
00257 {
00258 this->SetState(STATE_CLICKED, t->chan);
00259
00260 if(soundClick)
00261 soundClick->Play();
00262 }
00263 }
00264 else if(trigger[i]->type == TRIGGER_BUTTON_ONLY)
00265 {
00266 this->SetState(STATE_CLICKED, t->chan);
00267 }
00268 else if(trigger[i]->type == TRIGGER_BUTTON_ONLY_IN_FOCUS &&
00269 parentElement->IsFocused())
00270 {
00271 this->SetState(STATE_CLICKED, t->chan);
00272 }
00273 }
00274 }
00275 }
00276 }
00277 }
00278
00279 if(this->IsHoldable())
00280 {
00281 bool held = false;
00282 s32 wm_btns, wm_btns_h, wm_btns_trig, cc_btns, cc_btns_h, cc_btns_trig;
00283
00284 for(int i=0; i<2; i++)
00285 {
00286 if(trigger[i] && (trigger[i]->chan == -1 || trigger[i]->chan == t->chan))
00287 {
00288
00289 wm_btns = t->wpad->btns_d << 16;
00290 wm_btns_h = t->wpad->btns_h << 16;
00291 wm_btns_trig = trigger[i]->wpad->btns_h << 16;
00292
00293
00294 cc_btns = t->wpad->btns_d >> 16;
00295 cc_btns_h = t->wpad->btns_h >> 16;
00296 cc_btns_trig = trigger[i]->wpad->btns_h >> 16;
00297
00298 if(
00299 (t->wpad->btns_d > 0 &&
00300 (wm_btns == wm_btns_trig ||
00301 (cc_btns == cc_btns_trig && t->wpad->exp.type == EXP_CLASSIC))) ||
00302 (t->pad.btns_d == trigger[i]->pad.btns_h && t->pad.btns_d > 0))
00303 {
00304 if(trigger[i]->type == TRIGGER_HELD && state == STATE_SELECTED &&
00305 (t->chan == stateChan || stateChan == -1))
00306 this->SetState(STATE_CLICKED, t->chan);
00307 }
00308
00309 if(
00310 (t->wpad->btns_h > 0 &&
00311 (wm_btns_h == wm_btns_trig ||
00312 (cc_btns_h == cc_btns_trig && t->wpad->exp.type == EXP_CLASSIC))) ||
00313 (t->pad.btns_h == trigger[i]->pad.btns_h && t->pad.btns_h > 0))
00314 {
00315 if(trigger[i]->type == TRIGGER_HELD)
00316 held = true;
00317 }
00318
00319 if(!held && state == STATE_HELD && stateChan == t->chan)
00320 {
00321 this->ResetState();
00322 }
00323 else if(held && state == STATE_CLICKED && stateChan == t->chan)
00324 {
00325 this->SetState(STATE_HELD, t->chan);
00326 }
00327 }
00328 }
00329 }
00330
00331 if(updateCB)
00332 updateCB(this);
00333 }