usbloadergx/source/libwiigui/gui_tooltip.cpp

101 lines
2.3 KiB
C++
Raw Normal View History

/****************************************************************************
* libwiigui
*
* Tantric 2009
*
* gui_tooltip.cpp
*
* GUI class definitions
***************************************************************************/
#include "gui.h"
#include "themes/CTheme.h"
/**
* Constructor for the GuiTooltip class.
*/
GuiTooltip::GuiTooltip(const char *t, int Alpha/*=255*/)
{
tooltipLeft = Resources::GetImageData("tooltip_left.png");
tooltipTile = Resources::GetImageData("tooltip_tile.png");
tooltipRight = Resources::GetImageData("tooltip_right.png");
leftImage = new GuiImage(tooltipLeft);
tileImage = new GuiImage(tooltipTile);
rightImage = new GuiImage(tooltipRight);
text = NULL;
height = leftImage->GetHeight();
leftImage->SetParent(this);
tileImage->SetParent(this);
rightImage->SetParent(this);
leftImage->SetParentAngle(false);
tileImage->SetParentAngle(false);
rightImage->SetParentAngle(false);
2010-09-24 02:48:03 +02:00
SetText(t);
SetAlpha(Alpha);
}
/*
* Destructor for the GuiTooltip class.
*/
GuiTooltip::~GuiTooltip()
{
2010-09-24 02:48:03 +02:00
if (text) delete text;
delete tooltipLeft;
delete tooltipTile;
delete tooltipRight;
delete leftImage;
delete tileImage;
delete rightImage;
}
float GuiTooltip::GetScale()
{
float s = scale * scaleDyn;
return s;
}
/* !Sets the text of the GuiTooltip element
* !\param t Text
*/
2010-09-24 02:48:03 +02:00
void GuiTooltip::SetText(const char * t)
{
LOCK( this );
2010-09-24 02:48:03 +02:00
if (text)
{
delete text;
text = NULL;
}
int tile_cnt = 0;
2010-09-24 02:48:03 +02:00
if (t && (text = new GuiText(t, 22, ( GXColor )
{ 0, 0, 0, 255})))
{
2010-09-24 02:48:03 +02:00
text->SetParent(this);
tile_cnt = (text->GetTextWidth() - 12) / tileImage->GetWidth();
2010-09-24 02:48:03 +02:00
if (tile_cnt < 0) tile_cnt = 0;
}
tileImage->SetPosition(leftImage->GetWidth(), 0);
tileImage->SetTile(tile_cnt);
rightImage->SetPosition(leftImage->GetWidth() + tile_cnt * tileImage->GetWidth(), 0);
width = leftImage->GetWidth() + tile_cnt * tileImage->GetWidth() + rightImage->GetWidth();
}
2010-09-24 02:48:03 +02:00
void GuiTooltip::SetWidescreen(bool )
{
}
/*
* Draw the Tooltip on screen
*/
void GuiTooltip::Draw()
{
LOCK( this );
2010-09-24 02:48:03 +02:00
if (!this->IsVisible()) return;
leftImage->Draw();
tileImage->Draw();
rightImage->Draw();
2010-09-24 02:48:03 +02:00
if (text) text->Draw();
this->UpdateEffects();
}