Added mutex/mutexlock to synchronize the GuiThreads and the MainThread, again clockfont edited (bearing of "1")

This commit is contained in:
ardi@ist-einmalig.de 2009-05-06 22:36:28 +00:00
parent c223287548
commit 1768998644
14 changed files with 294 additions and 10 deletions

Binary file not shown.

View File

@ -374,6 +374,11 @@ class GuiElement
virtual void Draw(); virtual void Draw();
virtual void DrawTooltip(); virtual void DrawTooltip();
protected: protected:
void Lock();
void Unlock();
mutex_t mutex;
friend class SimpleLock;
//int position2; //! B Scrollbariable //int position2; //! B Scrollbariable
bool visible; //!< Visibility of the element. If false, Draw() is skipped bool visible; //!< Visibility of the element. If false, Draw() is skipped
int focus; //!< Element focus (-1 = focus disabled, 0 = not focused, 1 = focused) int focus; //!< Element focus (-1 = focus disabled, 0 = not focused, 1 = focused)
@ -409,6 +414,15 @@ class GuiElement
GuiElement * parentElement; //!< Parent element GuiElement * parentElement; //!< Parent element
UpdateCallback updateCB; //!< Callback function to call when this element is updated UpdateCallback updateCB; //!< Callback function to call when this element is updated
}; };
class SimpleLock
{
public:
SimpleLock(GuiElement *e);
~SimpleLock();
private:
GuiElement *element;
};
#define LOCK(e) SimpleLock LOCK(e)
//!Allows GuiElements to be grouped together into a "window" //!Allows GuiElements to be grouped together into a "window"
class GuiWindow : public GuiElement class GuiWindow : public GuiElement
@ -622,7 +636,11 @@ class GuiText : public GuiElement
//!\param hor Horizontal alignment (ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTRE) //!\param hor Horizontal alignment (ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTRE)
//!\param vert Vertical alignment (ALIGN_TOP, ALIGN_BOTTOM, ALIGN_MIDDLE) //!\param vert Vertical alignment (ALIGN_TOP, ALIGN_BOTTOM, ALIGN_MIDDLE)
void SetAlignment(int hor, int vert); void SetAlignment(int hor, int vert);
//!Sets the font
//!\param f Font
void SetFont(FreeTypeGX *f); void SetFont(FreeTypeGX *f);
//!Get the Horizontal Size of Text
int GetTextWidth();
//!Constantly called to draw the text //!Constantly called to draw the text
void Draw(); void Draw();
protected: protected:
@ -634,6 +652,32 @@ class GuiText : public GuiElement
FreeTypeGX *font; FreeTypeGX *font;
}; };
//!Display, manage, and manipulate tooltips in the GUI.
class GuiTooltip : public GuiElement
{
public:
//!Constructor
//!\param t Text
GuiTooltip(const char *t);
//!Destructor
~ GuiTooltip();
//!Sets the text of the GuiTooltip element
//!\param t Text
void SetText(const char * t);
//!Constantly called to draw the GuiButton
void Draw();
protected:
static GuiImageData tooltipStd;
static GuiImageData tooltipMedium;
static GuiImageData tooltipLarge;
GuiImage image; //!< Tooltip
GuiText *text;
};
//!Display, manage, and manipulate buttons in the GUI. Buttons can have images, icons, text, and sound set (all of which are optional) //!Display, manage, and manipulate buttons in the GUI. Buttons can have images, icons, text, and sound set (all of which are optional)
class GuiButton : public GuiElement class GuiButton : public GuiElement
{ {
@ -698,6 +742,10 @@ class GuiButton : public GuiElement
//!Sets the button's Tooltip on over //!Sets the button's Tooltip on over
//!\param i Pointer to GuiImage object, t Pointer to GuiText, x & y Positioning //!\param i Pointer to GuiImage object, t Pointer to GuiText, x & y Positioning
void SetToolTip(GuiImage* i, GuiText * t, int x, int y); void SetToolTip(GuiImage* i, GuiText * t, int x, int y);
//!Constantly called to draw the GuiButtons ToolTip
//!Sets the button's Tooltip on over
//!\param i Pointer to GuiImage object, t Pointer to GuiText, x & y Positioning
void SetToolTip(GuiElement* tt, int x, int y, int h=ALIGN_RIGHT, int v=ALIGN_TOP);
//!Constantly called to draw the GuiButton //!Constantly called to draw the GuiButton
void Draw(); void Draw();
void DrawTooltip(); void DrawTooltip();
@ -717,6 +765,7 @@ class GuiButton : public GuiElement
GuiImage * iconClick; //!< Button icon for STATE_CLICKED GuiImage * iconClick; //!< Button icon for STATE_CLICKED
GuiImage * toolTip; //!< Tooltip for STATE_SELECTED GuiImage * toolTip; //!< Tooltip for STATE_SELECTED
GuiText * toolTipTxt;//!< Tooltip Text GuiText * toolTipTxt;//!< Tooltip Text
GuiElement *toolTip2;
time_t time1, time2;//!< Tooltip timeconstants time_t time1, time2;//!< Tooltip timeconstants
GuiText * label[3]; //!< Label(s) to display (default) GuiText * label[3]; //!< Label(s) to display (default)
GuiText * labelOver[3]; //!< Label(s) to display for STATE_SELECTED GuiText * labelOver[3]; //!< Label(s) to display for STATE_SELECTED

View File

@ -29,6 +29,7 @@ GuiButton::GuiButton(int w, int h)
iconHold = NULL; iconHold = NULL;
iconClick = NULL; iconClick = NULL;
toolTip = NULL; toolTip = NULL;
toolTip2 = NULL;
toolTipTxt = NULL; toolTipTxt = NULL;
for(int i=0; i < 3; i++) for(int i=0; i < 3; i++)
@ -56,80 +57,96 @@ GuiButton::~GuiButton()
void GuiButton::SetImage(GuiImage* img) void GuiButton::SetImage(GuiImage* img)
{ {
LOCK(this);
image = img; image = img;
if(img) img->SetParent(this); if(img) img->SetParent(this);
} }
void GuiButton::SetImageOver(GuiImage* img) void GuiButton::SetImageOver(GuiImage* img)
{ {
LOCK(this);
imageOver = img; imageOver = img;
if(img) img->SetParent(this); if(img) img->SetParent(this);
} }
void GuiButton::SetImageHold(GuiImage* img) void GuiButton::SetImageHold(GuiImage* img)
{ {
LOCK(this);
imageHold = img; imageHold = img;
if(img) img->SetParent(this); if(img) img->SetParent(this);
} }
void GuiButton::SetImageClick(GuiImage* img) void GuiButton::SetImageClick(GuiImage* img)
{ {
LOCK(this);
imageClick = img; imageClick = img;
if(img) img->SetParent(this); if(img) img->SetParent(this);
} }
void GuiButton::SetIcon(GuiImage* img) void GuiButton::SetIcon(GuiImage* img)
{ {
LOCK(this);
icon = img; icon = img;
if(img) img->SetParent(this); if(img) img->SetParent(this);
} }
void GuiButton::SetIconOver(GuiImage* img) void GuiButton::SetIconOver(GuiImage* img)
{ {
LOCK(this);
iconOver = img; iconOver = img;
if(img) img->SetParent(this); if(img) img->SetParent(this);
} }
void GuiButton::SetIconHold(GuiImage* img) void GuiButton::SetIconHold(GuiImage* img)
{ {
LOCK(this);
iconHold = img; iconHold = img;
if(img) img->SetParent(this); if(img) img->SetParent(this);
} }
void GuiButton::SetIconClick(GuiImage* img) void GuiButton::SetIconClick(GuiImage* img)
{ {
LOCK(this);
iconClick = img; iconClick = img;
if(img) img->SetParent(this); if(img) img->SetParent(this);
} }
void GuiButton::SetLabel(GuiText* txt, int n) void GuiButton::SetLabel(GuiText* txt, int n)
{ {
LOCK(this);
label[n] = txt; label[n] = txt;
if(txt) txt->SetParent(this); if(txt) txt->SetParent(this);
} }
void GuiButton::SetLabelOver(GuiText* txt, int n) void GuiButton::SetLabelOver(GuiText* txt, int n)
{ {
LOCK(this);
labelOver[n] = txt; labelOver[n] = txt;
if(txt) txt->SetParent(this); if(txt) txt->SetParent(this);
} }
void GuiButton::SetLabelHold(GuiText* txt, int n) void GuiButton::SetLabelHold(GuiText* txt, int n)
{ {
LOCK(this);
labelHold[n] = txt; labelHold[n] = txt;
if(txt) txt->SetParent(this); if(txt) txt->SetParent(this);
} }
void GuiButton::SetLabelClick(GuiText* txt, int n) void GuiButton::SetLabelClick(GuiText* txt, int n)
{ {
LOCK(this);
labelClick[n] = txt; labelClick[n] = txt;
if(txt) txt->SetParent(this); if(txt) txt->SetParent(this);
} }
void GuiButton::SetSoundOver(GuiSound * snd) void GuiButton::SetSoundOver(GuiSound * snd)
{ {
LOCK(this);
soundOver = snd; soundOver = snd;
} }
void GuiButton::SetSoundHold(GuiSound * snd) void GuiButton::SetSoundHold(GuiSound * snd)
{ {
LOCK(this);
soundHold = snd; soundHold = snd;
} }
void GuiButton::SetSoundClick(GuiSound * snd) void GuiButton::SetSoundClick(GuiSound * snd)
{ {
LOCK(this);
soundClick = snd; soundClick = snd;
} }
//No delay for now //No delay for now
void GuiButton::SetToolTip(GuiImage* img, GuiText * txt, int x, int y) void GuiButton::SetToolTip(GuiImage* img, GuiText * txt, int x, int y)
{ {
LOCK(this);
if(img) if(img)
{ {
@ -145,11 +162,24 @@ void GuiButton::SetToolTip(GuiImage* img, GuiText * txt, int x, int y)
} }
} }
void GuiButton::SetToolTip(GuiElement* tt, int x, int y, int h_align, int v_align)
{
LOCK(this);
if(tt)
{
toolTip2 = tt;
toolTip2->SetParent(this);
toolTip2->SetAlignment(h_align, v_align);
toolTip2->SetPosition(x,y);
}
}
/** /**
* Draw the button on screen * Draw the button on screen
*/ */
void GuiButton::Draw() void GuiButton::Draw()
{ {
LOCK(this);
if(!this->IsVisible()) if(!this->IsVisible())
return; return;
@ -176,7 +206,8 @@ void GuiButton::Draw()
} }
void GuiButton::DrawTooltip() void GuiButton::DrawTooltip()
{ {
if(state == STATE_SELECTED && toolTip) LOCK(this);
if(state == STATE_SELECTED && (toolTip || toolTip2))
{ {
if (time2 == 0) if (time2 == 0)
time(&time2); time(&time2);
@ -184,29 +215,34 @@ void GuiButton::DrawTooltip()
time(&time1); time(&time1);
if (difftime(time1, time2) >= 2) { if (difftime(time1, time2) >= 2) {
toolTip->Draw(); if(toolTip) toolTip->Draw();
if(toolTip2) toolTip2->Draw();
if (toolTipTxt) if (toolTipTxt)
{ {
toolTipTxt->Draw(); toolTipTxt->Draw();
} }
} }
} }
else
time2 = 0;
} }
void GuiButton::ScrollIsOn(int f) void GuiButton::ScrollIsOn(int f)
{ {
LOCK(this);
scrollison = f; scrollison = f;
} }
void GuiButton::Update(GuiTrigger * t) void GuiButton::Update(GuiTrigger * t)
{ {
LOCK(this);
if(state == STATE_CLICKED || state == STATE_DISABLED || !t) if(state == STATE_CLICKED || state == STATE_DISABLED || !t)
return; return;
else if(parentElement && parentElement->GetState() == STATE_DISABLED) else if(parentElement && parentElement->GetState() == STATE_DISABLED)
return; return;
if(state != STATE_SELECTED && toolTip) { // if(state != STATE_SELECTED && toolTip) {
time2 = 0; // time2 = 0;
} // }
#ifdef HW_RVL #ifdef HW_RVL

View File

@ -190,12 +190,14 @@ GuiCustomOptionBrowser::~GuiCustomOptionBrowser()
void GuiCustomOptionBrowser::SetCol2Position(int x) void GuiCustomOptionBrowser::SetCol2Position(int x)
{ {
LOCK(this);
for(int i = 0; i < size; i++) for(int i = 0; i < size; i++)
optionVal[i]->SetPosition(x,0); optionVal[i]->SetPosition(x,0);
} }
void GuiCustomOptionBrowser::SetFocus(int f) void GuiCustomOptionBrowser::SetFocus(int f)
{ {
LOCK(this);
focus = f; focus = f;
for(int i = 0; i < size; i++) for(int i = 0; i < size; i++)
@ -207,6 +209,7 @@ void GuiCustomOptionBrowser::SetFocus(int f)
void GuiCustomOptionBrowser::ResetState() void GuiCustomOptionBrowser::ResetState()
{ {
LOCK(this);
if(state != STATE_DISABLED) if(state != STATE_DISABLED)
{ {
state = STATE_DEFAULT; state = STATE_DEFAULT;
@ -272,6 +275,7 @@ int GuiCustomOptionBrowser::FindMenuItem(int currentItem, int direction)
*/ */
void GuiCustomOptionBrowser::Draw() void GuiCustomOptionBrowser::Draw()
{ {
LOCK(this);
if(!this->IsVisible()) if(!this->IsVisible())
return; return;
@ -300,7 +304,9 @@ void GuiCustomOptionBrowser::Draw()
} }
void GuiCustomOptionBrowser::Update(GuiTrigger * t) void GuiCustomOptionBrowser::Update(GuiTrigger * t)
{ int next, prev, lang = options->length; {
LOCK(this);
int next, prev, lang = options->length;
if(state == STATE_DISABLED || !t) if(state == STATE_DISABLED || !t)
return; return;

View File

@ -55,6 +55,8 @@ GuiElement::GuiElement()
// default alignment - align to top left // default alignment - align to top left
alignmentVert = ALIGN_TOP; alignmentVert = ALIGN_TOP;
alignmentHor = ALIGN_LEFT; alignmentHor = ALIGN_LEFT;
LWP_MutexInit(&mutex, true);
} }
/** /**
@ -62,10 +64,12 @@ GuiElement::GuiElement()
*/ */
GuiElement::~GuiElement() GuiElement::~GuiElement()
{ {
LWP_MutexDestroy(mutex);
} }
void GuiElement::SetParent(GuiElement * e) void GuiElement::SetParent(GuiElement * e)
{ {
LOCK(this);
parentElement = e; parentElement = e;
} }
/** /**
@ -140,6 +144,7 @@ int GuiElement::GetTop()
void GuiElement::SetMinX(int x) void GuiElement::SetMinX(int x)
{ {
LOCK(this);
xmin = x; xmin = x;
} }
@ -150,6 +155,7 @@ int GuiElement::GetMinX()
void GuiElement::SetMaxX(int x) void GuiElement::SetMaxX(int x)
{ {
LOCK(this);
xmax = x; xmax = x;
} }
@ -160,6 +166,7 @@ int GuiElement::GetMaxX()
void GuiElement::SetMinY(int y) void GuiElement::SetMinY(int y)
{ {
LOCK(this);
ymin = y; ymin = y;
} }
@ -170,6 +177,7 @@ int GuiElement::GetMinY()
void GuiElement::SetMaxY(int y) void GuiElement::SetMaxY(int y)
{ {
LOCK(this);
ymax = y; ymax = y;
} }
@ -207,6 +215,7 @@ int GuiElement::GetHeight()
*/ */
void GuiElement::SetSize(int w, int h) void GuiElement::SetSize(int w, int h)
{ {
LOCK(this);
width = w; width = w;
height = h; height = h;
@ -229,11 +238,13 @@ bool GuiElement::IsVisible()
*/ */
void GuiElement::SetVisible(bool v) void GuiElement::SetVisible(bool v)
{ {
LOCK(this);
visible = v; visible = v;
} }
void GuiElement::SetAlpha(int a) void GuiElement::SetAlpha(int a)
{ {
LOCK(this);
alpha = a; alpha = a;
} }
@ -254,6 +265,7 @@ int GuiElement::GetAlpha()
void GuiElement::SetScale(float s) void GuiElement::SetScale(float s)
{ {
LOCK(this);
scale = s; scale = s;
} }
@ -279,12 +291,14 @@ int GuiElement::GetStateChan()
void GuiElement::SetState(int s, int c) void GuiElement::SetState(int s, int c)
{ {
LOCK(this);
state = s; state = s;
stateChan = c; stateChan = c;
} }
void GuiElement::ResetState() void GuiElement::ResetState()
{ {
LOCK(this);
if(state != STATE_DISABLED) if(state != STATE_DISABLED)
{ {
state = STATE_DEFAULT; state = STATE_DEFAULT;
@ -294,16 +308,19 @@ void GuiElement::ResetState()
void GuiElement::SetClickable(bool c) void GuiElement::SetClickable(bool c)
{ {
LOCK(this);
clickable = c; clickable = c;
} }
void GuiElement::SetSelectable(bool s) void GuiElement::SetSelectable(bool s)
{ {
LOCK(this);
selectable = s; selectable = s;
} }
void GuiElement::SetHoldable(bool d) void GuiElement::SetHoldable(bool d)
{ {
LOCK(this);
holdable = d; holdable = d;
} }
@ -335,6 +352,7 @@ bool GuiElement::IsHoldable()
void GuiElement::SetFocus(int f) void GuiElement::SetFocus(int f)
{ {
LOCK(this);
focus = f; focus = f;
} }
@ -345,6 +363,7 @@ int GuiElement::IsFocused()
void GuiElement::SetTrigger(GuiTrigger * t) void GuiElement::SetTrigger(GuiTrigger * t)
{ {
LOCK(this);
if(!trigger[0]) if(!trigger[0])
trigger[0] = t; trigger[0] = t;
else if(!trigger[1]) else if(!trigger[1])
@ -363,6 +382,7 @@ void GuiElement::SetTrigger(GuiTrigger * t)
void GuiElement::SetTrigger(u8 i, GuiTrigger * t) void GuiElement::SetTrigger(u8 i, GuiTrigger * t)
{ {
LOCK(this);
trigger[i] = t; trigger[i] = t;
} }
@ -373,6 +393,7 @@ bool GuiElement::Rumble()
void GuiElement::SetRumble(bool r) void GuiElement::SetRumble(bool r)
{ {
LOCK(this);
rumble = r; rumble = r;
} }
@ -383,6 +404,7 @@ int GuiElement::GetEffect()
void GuiElement::SetEffect(int eff, int amount, int target) void GuiElement::SetEffect(int eff, int amount, int target)
{ {
LOCK(this);
if(eff & EFFECT_SLIDE_IN) if(eff & EFFECT_SLIDE_IN)
{ {
// these calculations overcompensate a little // these calculations overcompensate a little
@ -411,6 +433,7 @@ void GuiElement::SetEffect(int eff, int amount, int target)
void GuiElement::SetEffectOnOver(int eff, int amount, int target) void GuiElement::SetEffectOnOver(int eff, int amount, int target)
{ {
LOCK(this);
effectsOver |= eff; effectsOver |= eff;
effectAmountOver = amount; effectAmountOver = amount;
effectTargetOver = target; effectTargetOver = target;
@ -423,6 +446,7 @@ void GuiElement::SetEffectGrow()
void GuiElement::UpdateEffects() void GuiElement::UpdateEffects()
{ {
LOCK(this);
if(effects & (EFFECT_SLIDE_IN | EFFECT_SLIDE_OUT)) if(effects & (EFFECT_SLIDE_IN | EFFECT_SLIDE_OUT))
{ {
if(effects & EFFECT_SLIDE_IN) if(effects & EFFECT_SLIDE_IN)
@ -530,23 +554,27 @@ void GuiElement::UpdateEffects()
void GuiElement::Update(GuiTrigger * t) void GuiElement::Update(GuiTrigger * t)
{ {
LOCK(this);
if(updateCB) if(updateCB)
updateCB(this); updateCB(this);
} }
void GuiElement::SetUpdateCallback(UpdateCallback u) void GuiElement::SetUpdateCallback(UpdateCallback u)
{ {
LOCK(this);
updateCB = u; updateCB = u;
} }
void GuiElement::SetPosition(int xoff, int yoff) void GuiElement::SetPosition(int xoff, int yoff)
{ {
LOCK(this);
xoffset = xoff; xoffset = xoff;
yoffset = yoff; yoffset = yoff;
} }
void GuiElement::SetAlignment(int hor, int vert) void GuiElement::SetAlignment(int hor, int vert)
{ {
LOCK(this);
alignmentHor = hor; alignmentHor = hor;
alignmentVert = vert; alignmentVert = vert;
} }
@ -582,3 +610,21 @@ bool GuiElement::IsInside(int x, int y)
return true; return true;
return false; return false;
} }
void GuiElement::Lock()
{
LWP_MutexLock(mutex);
}
void GuiElement::Unlock()
{
LWP_MutexUnlock(mutex);
}
SimpleLock::SimpleLock(GuiElement *e) : element(e)
{
element->Lock();
}
SimpleLock::~SimpleLock()
{
element->Unlock();
}

View File

@ -192,6 +192,7 @@ GuiGameBrowser::~GuiGameBrowser()
void GuiGameBrowser::SetFocus(int f) void GuiGameBrowser::SetFocus(int f)
{ {
LOCK(this);
focus = f; focus = f;
for(int i=0; i<pagesize; i++) for(int i=0; i<pagesize; i++)
@ -203,6 +204,7 @@ void GuiGameBrowser::SetFocus(int f)
void GuiGameBrowser::ResetState() void GuiGameBrowser::ResetState()
{ {
LOCK(this);
if(state != STATE_DISABLED) if(state != STATE_DISABLED)
{ {
state = STATE_DEFAULT; state = STATE_DEFAULT;
@ -273,6 +275,7 @@ int GuiGameBrowser::FindMenuItem(int currentItem, int direction)
*/ */
void GuiGameBrowser::Draw() void GuiGameBrowser::Draw()
{ {
LOCK(this);
if(!this->IsVisible()) if(!this->IsVisible())
return; return;
@ -302,6 +305,7 @@ void GuiGameBrowser::Draw()
void GuiGameBrowser::Update(GuiTrigger * t) void GuiGameBrowser::Update(GuiTrigger * t)
{ {
LOCK(this);
if(state == STATE_DISABLED || !t) if(state == STATE_DISABLED || !t)
return; return;

View File

@ -92,6 +92,9 @@ u8 * GuiImage::GetImage()
void GuiImage::SetImage(GuiImageData * img) void GuiImage::SetImage(GuiImageData * img)
{ {
LOCK(this);
if(imgType == IMAGE_COLOR && image)
free(image);
image = img->GetImage(); image = img->GetImage();
width = img->GetWidth(); width = img->GetWidth();
height = img->GetHeight(); height = img->GetHeight();
@ -100,6 +103,9 @@ void GuiImage::SetImage(GuiImageData * img)
void GuiImage::SetImage(u8 * img, int w, int h) void GuiImage::SetImage(u8 * img, int w, int h)
{ {
LOCK(this);
if(imgType == IMAGE_COLOR && image)
free(image);
image = img; image = img;
width = w; width = w;
height = h; height = h;
@ -108,16 +114,19 @@ void GuiImage::SetImage(u8 * img, int w, int h)
void GuiImage::SetAngle(float a) void GuiImage::SetAngle(float a)
{ {
LOCK(this);
imageangle = a; imageangle = a;
} }
void GuiImage::SetTile(int t) void GuiImage::SetTile(int t)
{ {
LOCK(this);
tile = t; tile = t;
} }
void GuiImage::SetWidescreen(short w) void GuiImage::SetWidescreen(short w)
{ {
LOCK(this);
widescreen = w; widescreen = w;
} }
@ -137,6 +146,7 @@ GXColor GuiImage::GetPixel(int x, int y)
void GuiImage::SetPixel(int x, int y, GXColor color) void GuiImage::SetPixel(int x, int y, GXColor color)
{ {
LOCK(this);
if(!image || this->GetWidth() <= 0 || x < 0 || y < 0) if(!image || this->GetWidth() <= 0 || x < 0 || y < 0)
return; return;
@ -149,11 +159,13 @@ void GuiImage::SetPixel(int x, int y, GXColor color)
void GuiImage::SetStripe(int s) void GuiImage::SetStripe(int s)
{ {
LOCK(this);
stripe = s; stripe = s;
} }
void GuiImage::ColorStripe(int shift) void GuiImage::ColorStripe(int shift)
{ {
LOCK(this);
int x, y; int x, y;
GXColor color; GXColor color;
int alt = 0; int alt = 0;
@ -211,6 +223,7 @@ void GuiImage::ColorStripe(int shift)
*/ */
void GuiImage::Draw() void GuiImage::Draw()
{ {
LOCK(this);
if(!image || !this->IsVisible() || tile == 0) if(!image || !this->IsVisible() || tile == 0)
return; return;

View File

@ -242,6 +242,7 @@ GuiKeyboard::~GuiKeyboard()
void GuiKeyboard::Update(GuiTrigger * t) void GuiKeyboard::Update(GuiTrigger * t)
{ {
LOCK(this);
if(_elements.size() == 0 || (state == STATE_DISABLED && parentElement)) if(_elements.size() == 0 || (state == STATE_DISABLED && parentElement))
return; return;

View File

@ -289,12 +289,14 @@ GuiOptionBrowser::~GuiOptionBrowser()
void GuiOptionBrowser::SetCol2Position(int x) void GuiOptionBrowser::SetCol2Position(int x)
{ {
LOCK(this);
for(int i=0; i<PAGESIZE; i++) for(int i=0; i<PAGESIZE; i++)
optionVal[i]->SetPosition(x,0); optionVal[i]->SetPosition(x,0);
} }
void GuiOptionBrowser::SetFocus(int f) void GuiOptionBrowser::SetFocus(int f)
{ {
LOCK(this);
focus = f; focus = f;
for(int i=0; i<PAGESIZE; i++) for(int i=0; i<PAGESIZE; i++)
@ -306,6 +308,7 @@ void GuiOptionBrowser::SetFocus(int f)
void GuiOptionBrowser::ResetState() void GuiOptionBrowser::ResetState()
{ {
LOCK(this);
if(state != STATE_DISABLED) if(state != STATE_DISABLED)
{ {
state = STATE_DEFAULT; state = STATE_DEFAULT;
@ -372,6 +375,7 @@ int GuiOptionBrowser::FindMenuItem(int currentItem, int direction)
*/ */
void GuiOptionBrowser::Draw() void GuiOptionBrowser::Draw()
{ {
LOCK(this);
if(!this->IsVisible()) if(!this->IsVisible())
return; return;
@ -400,7 +404,9 @@ void GuiOptionBrowser::Draw()
} }
void GuiOptionBrowser::Update(GuiTrigger * t) void GuiOptionBrowser::Update(GuiTrigger * t)
{ int next, prev, lang = options->length; {
LOCK(this);
int next, prev, lang = options->length;
//go to the last game selected //go to the last game selected
if ((loaded == 0) && (startat>0)) if ((loaded == 0) && (startat>0))

View File

@ -72,9 +72,9 @@ GuiText::~GuiText()
void GuiText::SetText(const char * t) void GuiText::SetText(const char * t)
{ {
LOCK(this);
if(text) if(text)
delete text; delete text;
text = NULL; text = NULL;
if(t) if(t)
@ -93,27 +93,32 @@ void GuiText::SetPresets(int sz, GXColor c, int w, u16 s, int h, int v)
void GuiText::SetFontSize(int s) void GuiText::SetFontSize(int s)
{ {
LOCK(this);
size = s; size = s;
} }
void GuiText::SetMaxWidth(int w) void GuiText::SetMaxWidth(int w)
{ {
LOCK(this);
maxWidth = w; maxWidth = w;
} }
void GuiText::SetColor(GXColor c) void GuiText::SetColor(GXColor c)
{ {
LOCK(this);
color = c; color = c;
alpha = c.a; alpha = c.a;
} }
void GuiText::SetStyle(u16 s) void GuiText::SetStyle(u16 s)
{ {
LOCK(this);
style = s; style = s;
} }
void GuiText::SetAlignment(int hor, int vert) void GuiText::SetAlignment(int hor, int vert)
{ {
LOCK(this);
style = 0; style = 0;
switch(hor) switch(hor)
@ -149,13 +154,30 @@ void GuiText::SetAlignment(int hor, int vert)
*/ */
void GuiText::SetFont(FreeTypeGX *f) void GuiText::SetFont(FreeTypeGX *f)
{ {
LOCK(this);
font = f; font = f;
} }
int GuiText::GetTextWidth()
{
LOCK(this);
int newSize = size*this->GetScale();
if(newSize != currentSize)
{
//fontSystem->changeSize(newSize);
(font ? font : fontSystem)->changeSize(newSize);
currentSize = newSize;
}
return (font ? font : fontSystem)->getWidth(text);
}
/** /**
* Draw the text on screen * Draw the text on screen
*/ */
void GuiText::Draw() void GuiText::Draw()
{ {
LOCK(this);
if(!text) if(!text)
return; return;

View File

@ -0,0 +1,77 @@
/****************************************************************************
* libwiigui
*
* Tantric 2009
*
* gui_tooltip.cpp
*
* GUI class definitions
***************************************************************************/
#include "gui.h"
GuiImageData GuiTooltip::tooltipStd(tooltip_png);
GuiImageData GuiTooltip::tooltipMedium(tooltip_medium_png);
GuiImageData GuiTooltip::tooltipLarge(tooltip_large_png);
/**
* Constructor for the GuiTooltip class.
*/
GuiTooltip::GuiTooltip(const char *t)
{
text = NULL;
image.SetParent(this);
SetText(t);
}
/*
* Destructor for the GuiTooltip class.
*/
GuiTooltip::~GuiTooltip()
{
if(text) delete text;
}
/* !Sets the text of the GuiTooltip element
* !\param t Text
*/
void GuiTooltip::SetText(const char * t)
{
LOCK(this);
if(text)
{
delete text;
text = NULL;
}
int t_width = 24;
if(t && (text = new GuiText(t, 22, (GXColor){0, 0, 0, 255})))
{
text->SetParent(this);
t_width += text->GetTextWidth();
}
if(t_width > tooltipMedium.GetWidth())
image.SetImage(&tooltipLarge);
else if(t_width > tooltipStd.GetWidth())
image.SetImage(&tooltipMedium);
else
image.SetImage(&tooltipStd);
image.SetPosition(0, 0);
width = image.GetWidth();
height = image.GetHeight();
}
/*
* Draw the Tooltip on screen
*/
void GuiTooltip::Draw()
{
LOCK(this);
if(!this->IsVisible()) return;
image.Draw();
if(text) text->Draw();
this->UpdateEffects();
}

View File

@ -30,6 +30,7 @@ GuiWindow::~GuiWindow()
void GuiWindow::Append(GuiElement* e) void GuiWindow::Append(GuiElement* e)
{ {
LOCK(this);
if (e == NULL) if (e == NULL)
return; return;
@ -40,6 +41,7 @@ void GuiWindow::Append(GuiElement* e)
void GuiWindow::Insert(GuiElement* e, u32 index) void GuiWindow::Insert(GuiElement* e, u32 index)
{ {
LOCK(this);
if (e == NULL || index > (_elements.size() - 1)) if (e == NULL || index > (_elements.size() - 1))
return; return;
@ -50,6 +52,7 @@ void GuiWindow::Insert(GuiElement* e, u32 index)
void GuiWindow::Remove(GuiElement* e) void GuiWindow::Remove(GuiElement* e)
{ {
LOCK(this);
if (e == NULL) if (e == NULL)
return; return;
@ -65,6 +68,7 @@ void GuiWindow::Remove(GuiElement* e)
void GuiWindow::RemoveAll() void GuiWindow::RemoveAll()
{ {
LOCK(this);
_elements.clear(); _elements.clear();
} }
@ -82,6 +86,7 @@ u32 GuiWindow::GetSize()
void GuiWindow::Draw() void GuiWindow::Draw()
{ {
LOCK(this);
if(_elements.size() == 0 || !this->IsVisible()) if(_elements.size() == 0 || !this->IsVisible())
return; return;
@ -99,6 +104,7 @@ void GuiWindow::Draw()
} }
void GuiWindow::DrawTooltip() void GuiWindow::DrawTooltip()
{ {
LOCK(this);
if(_elements.size() == 0 || !this->IsVisible()) if(_elements.size() == 0 || !this->IsVisible())
return; return;
@ -110,6 +116,7 @@ void GuiWindow::DrawTooltip()
} }
void GuiWindow::ResetState() void GuiWindow::ResetState()
{ {
LOCK(this);
if(state != STATE_DISABLED) if(state != STATE_DISABLED)
state = STATE_DEFAULT; state = STATE_DEFAULT;
@ -122,6 +129,7 @@ void GuiWindow::ResetState()
void GuiWindow::SetState(int s) void GuiWindow::SetState(int s)
{ {
LOCK(this);
state = s; state = s;
for (u8 i = 0; i < _elements.size(); i++) for (u8 i = 0; i < _elements.size(); i++)
@ -133,6 +141,7 @@ void GuiWindow::SetState(int s)
void GuiWindow::SetVisible(bool v) void GuiWindow::SetVisible(bool v)
{ {
LOCK(this);
visible = v; visible = v;
for (u8 i = 0; i < _elements.size(); i++) for (u8 i = 0; i < _elements.size(); i++)
@ -144,6 +153,7 @@ void GuiWindow::SetVisible(bool v)
void GuiWindow::SetFocus(int f) void GuiWindow::SetFocus(int f)
{ {
LOCK(this);
focus = f; focus = f;
if(f == 1) if(f == 1)
@ -154,6 +164,7 @@ void GuiWindow::SetFocus(int f)
void GuiWindow::ChangeFocus(GuiElement* e) void GuiWindow::ChangeFocus(GuiElement* e)
{ {
LOCK(this);
if(parentElement) if(parentElement)
return; // this is only intended for the main window return; // this is only intended for the main window
@ -168,6 +179,7 @@ void GuiWindow::ChangeFocus(GuiElement* e)
void GuiWindow::ToggleFocus(GuiTrigger * t) void GuiWindow::ToggleFocus(GuiTrigger * t)
{ {
LOCK(this);
if(parentElement) if(parentElement)
return; // this is only intended for the main window return; // this is only intended for the main window
@ -266,6 +278,7 @@ int GuiWindow::GetSelected()
// there's probably a more clever way to do this, but this way works // there's probably a more clever way to do this, but this way works
void GuiWindow::MoveSelectionHor(int dir) void GuiWindow::MoveSelectionHor(int dir)
{ {
LOCK(this);
int found = -1; int found = -1;
u16 left = 0; u16 left = 0;
u16 top = 0; u16 top = 0;
@ -335,6 +348,7 @@ void GuiWindow::MoveSelectionHor(int dir)
void GuiWindow::MoveSelectionVert(int dir) void GuiWindow::MoveSelectionVert(int dir)
{ {
LOCK(this);
int found = -1; int found = -1;
u16 left = 0; u16 left = 0;
u16 top = 0; u16 top = 0;
@ -386,6 +400,7 @@ void GuiWindow::MoveSelectionVert(int dir)
void GuiWindow::Update(GuiTrigger * t) void GuiWindow::Update(GuiTrigger * t)
{ {
LOCK(this);
if(_elements.size() == 0 || (state == STATE_DISABLED && parentElement)) if(_elements.size() == 0 || (state == STATE_DISABLED && parentElement))
return; return;

View File

@ -2438,6 +2438,7 @@ static int MenuDiscList()
GuiImageData ttsettings(tooltip_png); GuiImageData ttsettings(tooltip_png);
GuiImage ttsettingsImg(&ttsettings); GuiImage ttsettingsImg(&ttsettings);
ttsettingsImg.SetWidescreen(CFG.widescreen); ttsettingsImg.SetWidescreen(CFG.widescreen);
GuiTooltip tt_settings("Settings");
GuiImage settingsBtnImg(&btnSettings); GuiImage settingsBtnImg(&btnSettings);
settingsBtnImg.SetWidescreen(CFG.widescreen); //added settingsBtnImg.SetWidescreen(CFG.widescreen); //added
@ -2452,8 +2453,10 @@ static int MenuDiscList()
settingsBtn.SetSoundClick(&btnClick); settingsBtn.SetSoundClick(&btnClick);
settingsBtn.SetTrigger(&trigA); settingsBtn.SetTrigger(&trigA);
settingsBtn.SetEffectGrow(); settingsBtn.SetEffectGrow();
// if (Settings.tooltips == TooltipsOn && THEME.showToolTip != 0)
// settingsBtn.SetToolTip(&ttsettingsImg,&ttsettingsTxt,65,-30);
if (Settings.tooltips == TooltipsOn && THEME.showToolTip != 0) if (Settings.tooltips == TooltipsOn && THEME.showToolTip != 0)
settingsBtn.SetToolTip(&ttsettingsImg,&ttsettingsTxt,65,-30); settingsBtn.SetToolTip(&tt_settings,65,-30);
GuiText tthomeTxt("Back to HBC or Wii Menu", 22, (GXColor){0, 0, 0, 255}); //TOOLTIP DATA FOR HOME BUTTON GuiText tthomeTxt("Back to HBC or Wii Menu", 22, (GXColor){0, 0, 0, 255}); //TOOLTIP DATA FOR HOME BUTTON
GuiImageData tthome(tooltip_large_png); GuiImageData tthome(tooltip_large_png);
@ -2581,6 +2584,11 @@ static int MenuDiscList()
gameBrowser.SetPosition(THEME.selection_x, THEME.selection_y); gameBrowser.SetPosition(THEME.selection_x, THEME.selection_y);
gameBrowser.SetAlignment(ALIGN_LEFT, ALIGN_CENTRE); gameBrowser.SetAlignment(ALIGN_LEFT, ALIGN_CENTRE);
GuiText clockTimeBack("88:88", 40, (GXColor){138, 138, 138, 64});
clockTimeBack.SetAlignment(THEME.clockAlign, ALIGN_BOTTOM);
clockTimeBack.SetPosition(THEME.clock_x, THEME.clock_y);
clockTimeBack.SetFont(fontClock);
GuiText clockTime(theTime, 40, (GXColor){138, 138, 138, 255}); GuiText clockTime(theTime, 40, (GXColor){138, 138, 138, 255});
clockTime.SetAlignment(THEME.clockAlign, ALIGN_BOTTOM); clockTime.SetAlignment(THEME.clockAlign, ALIGN_BOTTOM);
clockTime.SetPosition(THEME.clock_x, THEME.clock_y); clockTime.SetPosition(THEME.clock_x, THEME.clock_y);
@ -2608,6 +2616,7 @@ static int MenuDiscList()
if(Settings.hddinfo == Clock) if(Settings.hddinfo == Clock)
{ {
w.Append(&clockTimeBack);
w.Append(&clockTime); w.Append(&clockTime);
} }

View File

@ -265,7 +265,7 @@ void Menu_DrawImg(f32 xpos, f32 ypos, u16 width, u16 height, u8 data[],
// guMtxConcat(m2,m1,m); // guMtxConcat(m2,m1,m);
guMtxConcat(m1,m2,m); guMtxConcat(m1,m2,m);
guMtxTransApply(m,m, xpos+width,ypos+height,0); guMtxTransApply(m,m, xpos+width+0.5,ypos+height+0.5,0);
guMtxConcat (GXmodelView2D, m, mv); guMtxConcat (GXmodelView2D, m, mv);
GX_LoadPosMtxImm (mv, GX_PNMTX0); GX_LoadPosMtxImm (mv, GX_PNMTX0);