2009-05-03 20:53:31 +02:00
|
|
|
|
/****************************************************************************
|
|
|
|
|
* libwiigui
|
|
|
|
|
*
|
|
|
|
|
* Tantric 2009
|
|
|
|
|
*
|
|
|
|
|
* gui_element.cpp
|
|
|
|
|
*
|
|
|
|
|
* GUI class definitions
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "gui.h"
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor for the Object class.
|
|
|
|
|
*/
|
2009-11-10 23:03:52 +01:00
|
|
|
|
//mutex_t GuiElement::mutex = LWP_MUTEX_NULL;
|
|
|
|
|
mutex_t GuiElement::_lock_mutex = LWP_MUTEX_NULL;
|
2010-02-09 11:59:55 +01:00
|
|
|
|
GuiElement::GuiElement()
|
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
xoffset = 0;
|
|
|
|
|
yoffset = 0;
|
|
|
|
|
zoffset = 0;
|
|
|
|
|
xmin = 0;
|
|
|
|
|
xmax = 0;
|
|
|
|
|
ymin = 0;
|
|
|
|
|
ymax = 0;
|
|
|
|
|
width = 0;
|
|
|
|
|
height = 0;
|
|
|
|
|
alpha = 255;
|
|
|
|
|
scale = 1;
|
|
|
|
|
state = STATE_DEFAULT;
|
|
|
|
|
stateChan = -1;
|
|
|
|
|
trigger[0] = NULL;
|
|
|
|
|
trigger[1] = NULL;
|
|
|
|
|
trigger[2] = NULL;
|
|
|
|
|
trigger[3] = NULL;
|
|
|
|
|
trigger[4] = NULL;
|
|
|
|
|
trigger[5] = NULL;
|
|
|
|
|
parentElement = NULL;
|
|
|
|
|
rumble = true;
|
|
|
|
|
selectable = false;
|
|
|
|
|
clickable = false;
|
|
|
|
|
holdable = false;
|
|
|
|
|
visible = true;
|
|
|
|
|
focus = -1; // cannot be focused
|
|
|
|
|
updateCB = NULL;
|
|
|
|
|
yoffsetDyn = 0;
|
|
|
|
|
xoffsetDyn = 0;
|
|
|
|
|
yoffsetDynFloat = 0;
|
|
|
|
|
alphaDyn = -1;
|
|
|
|
|
scaleDyn = 1;
|
|
|
|
|
effects = 0;
|
|
|
|
|
effectAmount = 0;
|
|
|
|
|
effectTarget = 0;
|
|
|
|
|
effectsOver = 0;
|
|
|
|
|
effectAmountOver = 0;
|
|
|
|
|
effectTargetOver = 0;
|
|
|
|
|
frequency = 0.0f;
|
|
|
|
|
changervar = 0;
|
|
|
|
|
degree = -90.0f;
|
|
|
|
|
circleamount = 360.0f;
|
|
|
|
|
Radius = 150;
|
|
|
|
|
angleDyn = 0.0f;
|
|
|
|
|
anglespeed = 0.0f;
|
|
|
|
|
|
|
|
|
|
// default alignment - align to top left
|
|
|
|
|
alignmentVert = ALIGN_TOP;
|
|
|
|
|
alignmentHor = ALIGN_LEFT;
|
2010-09-24 02:48:03 +02:00
|
|
|
|
// if(mutex == LWP_MUTEX_NULL) LWP_MutexInit(&mutex, true);
|
|
|
|
|
if (_lock_mutex == LWP_MUTEX_NULL) LWP_MutexInit(&_lock_mutex, true);
|
|
|
|
|
_lock_thread = LWP_THREAD_NULL;
|
|
|
|
|
_lock_count = 0;
|
|
|
|
|
_lock_queue = LWP_TQUEUE_NULL;
|
2009-11-10 23:03:52 +01:00
|
|
|
|
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Destructor for the GuiElement class.
|
|
|
|
|
*/
|
2010-02-09 11:59:55 +01:00
|
|
|
|
GuiElement::~GuiElement()
|
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
|
// LWP_MutexDestroy(mutex);
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
void GuiElement::SetParent(GuiElement * e)
|
2010-02-09 11:59:55 +01:00
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
LOCK( this );
|
|
|
|
|
parentElement = e;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
2009-07-24 22:34:55 +02:00
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
|
GuiElement * GuiElement::GetParent()
|
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
return parentElement;
|
2009-07-24 22:34:55 +02:00
|
|
|
|
}
|
2009-05-03 20:53:31 +02:00
|
|
|
|
/**
|
|
|
|
|
* Get the left position of the GuiElement.
|
|
|
|
|
* @see SetLeft()
|
|
|
|
|
* @return Left position in pixel.
|
|
|
|
|
*/
|
2010-02-09 11:59:55 +01:00
|
|
|
|
int GuiElement::GetLeft()
|
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
int x = 0;
|
|
|
|
|
int pWidth = 0;
|
|
|
|
|
int pLeft = 0;
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (parentElement)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
pWidth = parentElement->GetWidth();
|
|
|
|
|
pLeft = parentElement->GetLeft();
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (effects & (EFFECT_SLIDE_IN | EFFECT_SLIDE_OUT | EFFECT_GOROUND | EFFECT_ROCK_VERTICLE)) pLeft += xoffsetDyn;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
switch (alignmentHor)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
case ALIGN_LEFT:
|
|
|
|
|
x = pLeft;
|
|
|
|
|
break;
|
|
|
|
|
case ALIGN_CENTRE:
|
2010-09-24 02:48:03 +02:00
|
|
|
|
x = pLeft + (pWidth / 2) - (width / 2);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
break;
|
|
|
|
|
case ALIGN_RIGHT:
|
|
|
|
|
x = pLeft + pWidth - width;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return x + xoffset;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the top position of the GuiElement.
|
|
|
|
|
* @see SetTop()
|
|
|
|
|
* @return Top position in pixel.
|
|
|
|
|
*/
|
2010-02-09 11:59:55 +01:00
|
|
|
|
int GuiElement::GetTop()
|
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
int y = 0;
|
|
|
|
|
int pHeight = 0;
|
|
|
|
|
int pTop = 0;
|
2009-05-27 19:16:36 +02:00
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (parentElement)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
pHeight = parentElement->GetHeight();
|
|
|
|
|
pTop = parentElement->GetTop();
|
|
|
|
|
}
|
2010-02-09 11:59:55 +01:00
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (effects & (EFFECT_SLIDE_IN | EFFECT_SLIDE_OUT | EFFECT_GOROUND | EFFECT_ROCK_VERTICLE)) pTop += yoffsetDyn;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
switch (alignmentVert)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
case ALIGN_TOP:
|
|
|
|
|
y = pTop;
|
|
|
|
|
break;
|
|
|
|
|
case ALIGN_MIDDLE:
|
2010-09-24 02:48:03 +02:00
|
|
|
|
y = pTop + (pHeight / 2) - (height / 2);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
break;
|
|
|
|
|
case ALIGN_BOTTOM:
|
|
|
|
|
y = pTop + pHeight - height;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return y + yoffset;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
void GuiElement::SetMinX(int x)
|
2010-02-09 11:59:55 +01:00
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
LOCK( this );
|
|
|
|
|
xmin = x;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
|
int GuiElement::GetMinX()
|
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
return xmin;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
void GuiElement::SetMaxX(int x)
|
2010-02-09 11:59:55 +01:00
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
LOCK( this );
|
|
|
|
|
xmax = x;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
|
int GuiElement::GetMaxX()
|
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
return xmax;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
void GuiElement::SetMinY(int y)
|
2010-02-09 11:59:55 +01:00
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
LOCK( this );
|
|
|
|
|
ymin = y;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
|
int GuiElement::GetMinY()
|
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
return ymin;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
void GuiElement::SetMaxY(int y)
|
2010-02-09 11:59:55 +01:00
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
LOCK( this );
|
|
|
|
|
ymax = y;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
|
int GuiElement::GetMaxY()
|
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
return ymax;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the width of the GuiElement.
|
|
|
|
|
* @see SetWidth()
|
|
|
|
|
* @return Width of the GuiElement.
|
|
|
|
|
*/
|
2010-02-09 11:59:55 +01:00
|
|
|
|
int GuiElement::GetWidth()
|
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
return width;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the height of the GuiElement.
|
|
|
|
|
* @see SetHeight()
|
|
|
|
|
* @return Height of the GuiElement.
|
|
|
|
|
*/
|
2010-02-09 11:59:55 +01:00
|
|
|
|
int GuiElement::GetHeight()
|
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
return height;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the width and height of the GuiElement.
|
|
|
|
|
* @param[in] Width Width in pixel.
|
|
|
|
|
* @param[in] Height Height in pixel.
|
|
|
|
|
* @see SetWidth()
|
|
|
|
|
* @see SetHeight()
|
|
|
|
|
*/
|
2010-09-24 02:48:03 +02:00
|
|
|
|
void GuiElement::SetSize(int w, int h)
|
2010-02-09 11:59:55 +01:00
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
LOCK( this );
|
2009-05-03 20:53:31 +02:00
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
|
width = w;
|
|
|
|
|
height = h;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get visible.
|
|
|
|
|
* @see SetVisible()
|
|
|
|
|
* @return true if visible, false otherwise.
|
|
|
|
|
*/
|
2010-02-09 11:59:55 +01:00
|
|
|
|
bool GuiElement::IsVisible()
|
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
return visible;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set visible.
|
|
|
|
|
* @param[in] Visible Set to true to show GuiElement.
|
|
|
|
|
* @see IsVisible()
|
|
|
|
|
*/
|
2010-09-24 02:48:03 +02:00
|
|
|
|
void GuiElement::SetVisible(bool v)
|
2010-02-09 11:59:55 +01:00
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
LOCK( this );
|
|
|
|
|
visible = v;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
void GuiElement::SetAlpha(int a)
|
2010-02-09 11:59:55 +01:00
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
LOCK( this );
|
|
|
|
|
alpha = a;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
|
int GuiElement::GetAlpha()
|
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
int a;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (alphaDyn >= 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
a = alphaDyn;
|
2010-09-24 02:48:03 +02:00
|
|
|
|
else a = alpha;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (parentElement) a *= parentElement->GetAlpha() / 255.0;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
|
return a;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
|
float GuiElement::GetAngleDyn()
|
|
|
|
|
{
|
2009-05-27 19:16:36 +02:00
|
|
|
|
float a = 0.0;
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (angleDyn) a = angleDyn;
|
2009-05-27 19:16:36 +02:00
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (parentElement && !angleDyn) a = parentElement->GetAngleDyn();
|
2009-05-27 19:16:36 +02:00
|
|
|
|
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
void GuiElement::SetScale(float s)
|
2010-02-09 11:59:55 +01:00
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
LOCK( this );
|
|
|
|
|
scale = s;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
|
float GuiElement::GetScale()
|
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
float s = scale * scaleDyn;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (parentElement) s *= parentElement->GetScale();
|
2009-05-03 20:53:31 +02:00
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
|
return s;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
|
int GuiElement::GetState()
|
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
return state;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
|
int GuiElement::GetStateChan()
|
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
return stateChan;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
void GuiElement::SetState(int s, int c)
|
2010-02-09 11:59:55 +01:00
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
LOCK( this );
|
|
|
|
|
state = s;
|
|
|
|
|
stateChan = c;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
|
void GuiElement::ResetState()
|
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
LOCK( this );
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (state != STATE_DISABLED)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
state = STATE_DEFAULT;
|
|
|
|
|
stateChan = -1;
|
|
|
|
|
}
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
void GuiElement::SetClickable(bool c)
|
2010-02-09 11:59:55 +01:00
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
LOCK( this );
|
|
|
|
|
clickable = c;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
void GuiElement::SetSelectable(bool s)
|
2010-02-09 11:59:55 +01:00
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
LOCK( this );
|
|
|
|
|
selectable = s;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
void GuiElement::SetHoldable(bool d)
|
2010-02-09 11:59:55 +01:00
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
LOCK( this );
|
|
|
|
|
holdable = d;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
|
bool GuiElement::IsSelectable()
|
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (state == STATE_DISABLED || state == STATE_CLICKED)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
return false;
|
2010-09-24 02:48:03 +02:00
|
|
|
|
else return selectable;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
|
bool GuiElement::IsClickable()
|
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (state == STATE_DISABLED || state == STATE_CLICKED || state == STATE_HELD)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
return false;
|
2010-09-24 02:48:03 +02:00
|
|
|
|
else return clickable;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
|
bool GuiElement::IsHoldable()
|
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (state == STATE_DISABLED)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
return false;
|
2010-09-24 02:48:03 +02:00
|
|
|
|
else return holdable;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
void GuiElement::SetFocus(int f)
|
2010-02-09 11:59:55 +01:00
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
LOCK( this );
|
|
|
|
|
focus = f;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
|
int GuiElement::IsFocused()
|
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
return focus;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
void GuiElement::SetTrigger(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 (!trigger[0])
|
2010-09-19 01:16:05 +02:00
|
|
|
|
trigger[0] = t;
|
2010-09-24 02:48:03 +02:00
|
|
|
|
else if (!trigger[1])
|
2010-09-19 01:16:05 +02:00
|
|
|
|
trigger[1] = t;
|
2010-09-24 02:48:03 +02:00
|
|
|
|
else if (!trigger[2])
|
2010-09-19 01:16:05 +02:00
|
|
|
|
trigger[2] = t;
|
2010-09-24 02:48:03 +02:00
|
|
|
|
else if (!trigger[3])
|
2010-09-19 01:16:05 +02:00
|
|
|
|
trigger[3] = t;
|
2010-09-24 02:48:03 +02:00
|
|
|
|
else if (!trigger[4])
|
2010-09-19 01:16:05 +02:00
|
|
|
|
trigger[4] = t;
|
2010-09-24 02:48:03 +02:00
|
|
|
|
else if (!trigger[5])
|
2010-09-19 01:16:05 +02:00
|
|
|
|
trigger[5] = t;
|
|
|
|
|
else // both were assigned, so we'll just overwrite the first one
|
2010-09-24 02:48:03 +02:00
|
|
|
|
trigger[0] = t;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
void GuiElement::SetTrigger(u8 i, GuiTrigger * t)
|
2010-02-09 11:59:55 +01:00
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
LOCK( this );
|
|
|
|
|
trigger[i] = t;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
void GuiElement::RemoveTrigger(u8 i)
|
2010-02-09 11:59:55 +01:00
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
LOCK( this );
|
|
|
|
|
trigger[i] = NULL;
|
2009-05-13 08:48:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
|
bool GuiElement::Rumble()
|
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
return rumble;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
void GuiElement::SetRumble(bool r)
|
2010-02-09 11:59:55 +01:00
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
LOCK( this );
|
|
|
|
|
rumble = r;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
|
int GuiElement::GetEffect()
|
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
LOCK( this );
|
|
|
|
|
return effects;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
|
int GuiElement::GetEffectOnOver()
|
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
LOCK( this );
|
|
|
|
|
return effectsOver;
|
2009-05-30 05:02:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
|
float GuiElement::GetFrequency()
|
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
LOCK( this );
|
|
|
|
|
return frequency;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
void GuiElement::SetEffect(int eff, int speed, f32 circles, int r, f32 startdegree, f32 anglespeedset, int center_x,
|
|
|
|
|
int center_y)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
2009-05-27 10:41:05 +02:00
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (eff & EFFECT_GOROUND)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
|
xoffsetDyn = 0; //!position of circle in x
|
|
|
|
|
yoffsetDyn = 0; //!position of circle in y
|
|
|
|
|
Radius = r; //!radius of the circle
|
|
|
|
|
degree = startdegree; //!for example -90 (<28>) to start at top of circle
|
|
|
|
|
circleamount = circles; //!circleamoutn in degrees for example 360 for 1 circle
|
|
|
|
|
angleDyn = 0.0f; //!this is used by the code to calc the angle
|
2010-09-19 01:16:05 +02:00
|
|
|
|
anglespeed = anglespeedset; //!This is anglespeed depending on circle speed 1 is same speed and 0.5 half speed
|
2010-09-24 02:48:03 +02:00
|
|
|
|
temp_xoffset = center_x; //!position of center in x
|
|
|
|
|
temp_yoffset = center_y; //!position of center in y
|
2009-05-27 10:41:05 +02:00
|
|
|
|
}
|
|
|
|
|
effects |= eff;
|
2010-09-24 02:48:03 +02:00
|
|
|
|
effectAmount = speed; //!Circlespeed
|
2009-05-27 10:41:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
void GuiElement::SetEffect(int eff, int amount, int target)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
LOCK( this );
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (eff & EFFECT_SLIDE_IN)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
// these calculations overcompensate a little
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (eff & EFFECT_SLIDE_TOP)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
yoffsetDyn = -screenheight;
|
2010-09-24 02:48:03 +02:00
|
|
|
|
else if (eff & EFFECT_SLIDE_LEFT)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
xoffsetDyn = -screenwidth;
|
2010-09-24 02:48:03 +02:00
|
|
|
|
else if (eff & EFFECT_SLIDE_BOTTOM)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
yoffsetDyn = screenheight;
|
2010-09-24 02:48:03 +02:00
|
|
|
|
else if (eff & EFFECT_SLIDE_RIGHT) xoffsetDyn = screenwidth;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (eff & EFFECT_FADE && amount > 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
alphaDyn = 0;
|
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
|
else if (eff & EFFECT_FADE && amount < 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
alphaDyn = alpha;
|
|
|
|
|
|
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
|
else if (eff & EFFECT_ROCK_VERTICLE)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
changervar = 0;
|
2009-05-27 00:48:20 +02:00
|
|
|
|
yoffsetDyn = 0;
|
|
|
|
|
yoffsetDynFloat = 0.0;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
}
|
2010-02-09 11:59:55 +01:00
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
|
effects |= eff;
|
|
|
|
|
effectAmount = amount;
|
|
|
|
|
effectTarget = target;
|
2010-02-09 11:59:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
void GuiElement::SetEffectOnOver(int eff, int amount, int target)
|
2010-02-09 11:59:55 +01:00
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
LOCK( this );
|
|
|
|
|
effectsOver |= eff;
|
|
|
|
|
effectAmountOver = amount;
|
|
|
|
|
effectTargetOver = target;
|
2010-02-09 11:59:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GuiElement::SetEffectGrow()
|
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
|
SetEffectOnOver(EFFECT_SCALE, 4, 110);
|
2010-02-09 11:59:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GuiElement::StopEffect()
|
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
xoffsetDyn = 0;
|
|
|
|
|
yoffsetDyn = 0;
|
|
|
|
|
effects = 0;
|
|
|
|
|
effectsOver = 0;
|
|
|
|
|
effectAmount = 0;
|
|
|
|
|
effectAmountOver = 0;
|
|
|
|
|
effectTarget = 0;
|
|
|
|
|
effectTargetOver = 0;
|
|
|
|
|
scaleDyn = 1;
|
|
|
|
|
frequency = 0.0f;
|
|
|
|
|
changervar = 0;
|
|
|
|
|
//angleDyn = 0.0f;
|
|
|
|
|
anglespeed = 0.0f;
|
2010-02-09 11:59:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GuiElement::UpdateEffects()
|
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
LOCK( this );
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (effects & (EFFECT_SLIDE_IN | EFFECT_SLIDE_OUT | EFFECT_GOROUND))
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (effects & EFFECT_SLIDE_IN)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (effects & EFFECT_SLIDE_LEFT)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
xoffsetDyn += effectAmount;
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (xoffsetDyn >= 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
xoffsetDyn = 0;
|
|
|
|
|
effects = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
|
else if (effects & EFFECT_SLIDE_RIGHT)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
xoffsetDyn -= effectAmount;
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (xoffsetDyn <= 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
xoffsetDyn = 0;
|
|
|
|
|
effects = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
|
else if (effects & EFFECT_SLIDE_TOP)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
yoffsetDyn += effectAmount;
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (yoffsetDyn >= 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
yoffsetDyn = 0;
|
|
|
|
|
effects = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
|
else if (effects & EFFECT_SLIDE_BOTTOM)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
yoffsetDyn -= effectAmount;
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (yoffsetDyn <= 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
yoffsetDyn = 0;
|
|
|
|
|
effects = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (effects & EFFECT_SLIDE_LEFT)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
xoffsetDyn -= effectAmount;
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (xoffsetDyn <= -screenwidth) effects = 0; // shut off effect
|
2010-09-19 01:16:05 +02:00
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
|
else if (effects & EFFECT_SLIDE_RIGHT)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
xoffsetDyn += effectAmount;
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (xoffsetDyn >= screenwidth) effects = 0; // shut off effect
|
2010-09-19 01:16:05 +02:00
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
|
else if (effects & EFFECT_SLIDE_TOP)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
yoffsetDyn -= effectAmount;
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (yoffsetDyn <= -screenheight) effects = 0; // shut off effect
|
2010-09-19 01:16:05 +02:00
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
|
else if (effects & EFFECT_SLIDE_BOTTOM)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
yoffsetDyn += effectAmount;
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (yoffsetDyn >= screenheight) effects = 0; // shut off effect
|
2010-09-19 01:16:05 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (effects & EFFECT_GOROUND)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
//!< check out gui.h for info
|
|
|
|
|
xoffset = temp_xoffset;
|
|
|
|
|
yoffset = temp_yoffset;
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (fabs(frequency) < circleamount)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
|
angleDyn = (frequency + degree + 90.0f) * anglespeed;
|
|
|
|
|
xoffsetDyn = (int) lround(((f32) Radius) * cos((frequency + degree) * PI / 180.0f));
|
|
|
|
|
yoffsetDyn = (int) lround(((f32) Radius) * sin((frequency + degree) * PI / 180.0f));
|
|
|
|
|
frequency += ((f32) effectAmount) * 0.01f;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
|
f32 temp_frequency = ((effectAmount < 0) ? -1.0f : 1.0f) * circleamount;
|
|
|
|
|
angleDyn = (temp_frequency + degree + 90.0f) * anglespeed;
|
|
|
|
|
xoffsetDyn = (int) lround(((f32) Radius) * cos((temp_frequency + degree) * PI / 180.0f));
|
|
|
|
|
yoffsetDyn = (int) lround(((f32) Radius) * sin((temp_frequency + degree) * PI / 180.0f));
|
2010-09-19 01:16:05 +02:00
|
|
|
|
xoffset += xoffsetDyn;
|
|
|
|
|
yoffset += yoffsetDyn;
|
|
|
|
|
effects ^= EFFECT_GOROUND;
|
|
|
|
|
frequency = 0.0f;
|
|
|
|
|
}
|
2009-05-27 00:48:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (effects & EFFECT_ROCK_VERTICLE)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
2009-05-27 00:48:20 +02:00
|
|
|
|
//move up to 10pixel above 0
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (changervar == 0 && yoffsetDynFloat < 11.0)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
|
yoffsetDynFloat += (effectAmount * 0.01);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
|
else if (yoffsetDynFloat > 10.0)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
2009-05-27 00:48:20 +02:00
|
|
|
|
changervar = 1;
|
|
|
|
|
}
|
|
|
|
|
//move down till 10pixel under 0
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (changervar == 1 && yoffsetDynFloat > -11.0)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
|
yoffsetDynFloat -= (effectAmount * 0.01);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
|
else if (yoffsetDynFloat < -10.0)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
2009-05-27 00:48:20 +02:00
|
|
|
|
changervar = 0;
|
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
|
yoffsetDyn = (int) (yoffsetDynFloat);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (effects & EFFECT_FADE)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
alphaDyn += effectAmount;
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (effectAmount < 0 && alphaDyn <= 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
alphaDyn = 0;
|
|
|
|
|
effects = 0; // shut off effect
|
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
|
else if (effectAmount > 0 && alphaDyn >= alpha)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
alphaDyn = alpha;
|
|
|
|
|
effects = 0; // shut off effect
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (effects & EFFECT_SCALE)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
scaleDyn += effectAmount / 100.0;
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if ((effectAmount < 0 && scaleDyn <= effectTarget / 100.0) || (effectAmount > 0 && scaleDyn >= effectTarget
|
|
|
|
|
/ 100.0))
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
scaleDyn = effectTarget / 100.0;
|
|
|
|
|
effects = 0; // shut off effect
|
|
|
|
|
}
|
2009-05-27 00:48:20 +02:00
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (effects & EFFECT_PULSE)
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
|
|
|
|
int percent = 10; //go down from target by this
|
2009-05-27 00:48:20 +02:00
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if ((scaleDyn <= (effectTarget * 0.01)) && (!changervar))
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
|
scaleDyn += (effectAmount * 0.001);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
|
else if (scaleDyn > (effectTarget * 0.01))
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
2009-05-27 00:48:20 +02:00
|
|
|
|
changervar = 1;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if ((scaleDyn >= ((effectTarget - percent) * 0.01)) && (changervar))
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
|
scaleDyn -= (effectAmount * 0.001);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
|
else if (scaleDyn < ((effectTarget - percent) * 0.01))
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
2009-05-27 00:48:20 +02:00
|
|
|
|
changervar = 0;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
void GuiElement::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 (updateCB) updateCB(this);
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
void GuiElement::SetUpdateCallback(UpdateCallback u)
|
2010-02-09 11:59:55 +01:00
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
LOCK( this );
|
|
|
|
|
updateCB = u;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
void GuiElement::SetPosition(int xoff, int yoff, int zoff)
|
2010-02-09 11:59:55 +01:00
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
LOCK( this );
|
|
|
|
|
xoffset = xoff;
|
|
|
|
|
yoffset = yoff;
|
|
|
|
|
zoffset = zoff;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
void GuiElement::SetAlignment(int hor, int vert)
|
2010-02-09 11:59:55 +01:00
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
LOCK( this );
|
|
|
|
|
alignmentHor = hor;
|
|
|
|
|
alignmentVert = vert;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
|
int GuiElement::GetSelected()
|
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
return -1;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Draw an element on screen.
|
|
|
|
|
*/
|
2010-02-09 11:59:55 +01:00
|
|
|
|
void GuiElement::Draw()
|
|
|
|
|
{
|
2009-05-03 20:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2009-05-04 21:06:16 +02:00
|
|
|
|
/**
|
|
|
|
|
* Draw Tooltips on screen.
|
|
|
|
|
*/
|
2010-02-09 11:59:55 +01:00
|
|
|
|
void GuiElement::DrawTooltip()
|
|
|
|
|
{
|
2009-05-04 21:06:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
2009-05-03 20:53:31 +02:00
|
|
|
|
/**
|
|
|
|
|
* Check if a position is inside the GuiElement.
|
|
|
|
|
* @param[in] x X position in pixel.
|
|
|
|
|
* @param[in] y Y position in pixel.
|
|
|
|
|
*/
|
2010-09-24 02:48:03 +02:00
|
|
|
|
bool GuiElement::IsInside(int x, int y)
|
2010-02-09 11:59:55 +01:00
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (x > this->GetLeft() && x < (this->GetLeft() + width) && y > this->GetTop() && y < (this->GetTop() + height)) return true;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
return false;
|
2010-02-09 11:59:55 +01:00
|
|
|
|
}
|
|
|
|
|
void GuiElement::Lock()
|
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
|
// LWP_MutexLock(mutex);
|
|
|
|
|
for (;;) // loop while element is locked by self
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
|
LWP_MutexLock(_lock_mutex);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (_lock_thread == LWP_THREAD_NULL) // element is not locked
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
|
_lock_thread = LWP_GetSelf(); // mark as locked
|
|
|
|
|
_lock_count = 1; // set count of lock to 1
|
|
|
|
|
LWP_MutexUnlock(_lock_mutex);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
|
else if (_lock_thread == LWP_GetSelf()) // thread is locked by my self
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
|
_lock_count++; // inc count of locks;
|
|
|
|
|
LWP_MutexUnlock(_lock_mutex);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
|
else // otherwise the element is locked by an other thread
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (_lock_queue == LWP_TQUEUE_NULL) // no queue - meens it is the first access to the locked element
|
|
|
|
|
LWP_InitQueue(&_lock_queue); // init queue
|
|
|
|
|
LWP_MutexUnlock(_lock_mutex);
|
|
|
|
|
LWP_ThreadSleep(_lock_queue); // and sleep
|
2010-09-19 01:16:05 +02:00
|
|
|
|
// try lock again;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-02-09 11:59:55 +01:00
|
|
|
|
}
|
|
|
|
|
void GuiElement::Unlock()
|
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
|
// LWP_MutexUnlock(mutex);
|
|
|
|
|
LWP_MutexLock(_lock_mutex);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
// only the thread was locked this element, can call unlock
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (_lock_thread == LWP_GetSelf()) // but we check it here <20> safe is safe
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
|
if (--_lock_count == 0) // dec count of locks and check if it last lock;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
|
_lock_thread = LWP_THREAD_NULL; // mark as unlocked
|
|
|
|
|
if (_lock_queue != LWP_TQUEUE_NULL) // has a queue
|
2010-09-19 01:16:05 +02:00
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
|
LWP_CloseQueue(_lock_queue); // close the queue and wake all waited threads
|
2010-09-19 01:16:05 +02:00
|
|
|
|
_lock_queue = LWP_TQUEUE_NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
|
LWP_MutexUnlock(_lock_mutex);
|
2010-02-09 11:59:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
|
SimpleLock::SimpleLock(GuiElement *e) :
|
|
|
|
|
element(e)
|
2010-02-09 11:59:55 +01:00
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
element->Lock();
|
2010-02-09 11:59:55 +01:00
|
|
|
|
}
|
|
|
|
|
SimpleLock::~SimpleLock()
|
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
|
element->Unlock();
|
2009-11-10 23:03:52 +01:00
|
|
|
|
}
|