2015-04-16 16:55:32 +00:00
|
|
|
/*
|
|
|
|
GWEN
|
|
|
|
Copyright (c) 2010 Facepunch Studios
|
|
|
|
See license in Gwen.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Gwen/ToolTip.h"
|
|
|
|
#include "Gwen/Utility.h"
|
|
|
|
|
|
|
|
using namespace Gwen;
|
|
|
|
using namespace Gwen::Controls;
|
|
|
|
|
|
|
|
namespace ToolTip
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
Base* g_ToolTip = NULL;
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void Enable(Controls::Base* pControl)
|
|
|
|
{
|
|
|
|
if (!pControl->GetToolTip())
|
|
|
|
return;
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
g_ToolTip = pControl;
|
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void Disable(Controls::Base* pControl)
|
|
|
|
{
|
|
|
|
if (g_ToolTip == pControl)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
g_ToolTip = NULL;
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void RenderToolTip(Skin::Base* skin)
|
|
|
|
{
|
|
|
|
if (!g_ToolTip) return;
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
Gwen::Renderer::Base* render = skin->GetRender();
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
Gwen::Point pOldRenderOffset = render->GetRenderOffset();
|
|
|
|
Gwen::Point MousePos = Input::GetMousePosition();
|
|
|
|
Gwen::Rect Bounds = g_ToolTip->GetToolTip()->GetBounds();
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
Gwen::Rect rOffset = Gwen::Rect(MousePos.x - Bounds.w * 0.5f, MousePos.y - Bounds.h - 10, Bounds.w, Bounds.h);
|
|
|
|
rOffset = Utility::ClampRectToRect(rOffset, g_ToolTip->GetCanvas()->GetBounds());
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
//Calculate offset on screen bounds
|
|
|
|
render->AddRenderOffset(rOffset);
|
|
|
|
render->EndClip();
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
skin->DrawToolTip(g_ToolTip->GetToolTip());
|
|
|
|
g_ToolTip->GetToolTip()->DoRender(skin);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
render->SetRenderOffset(pOldRenderOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControlDeleted(Controls::Base* pControl)
|
|
|
|
{
|
|
|
|
Disable(pControl);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
} // namespace ToolTip
|