2019-07-26 11:57:28 -07:00
|
|
|
/* Copyright (C) 2019 Wildfire Games.
|
2009-04-18 10:00:33 -07:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
|
*
|
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2004-06-03 11:38:14 -07:00
|
|
|
#include "precompiled.h"
|
2015-08-21 10:08:41 -07:00
|
|
|
|
2004-05-28 21:06:50 -07:00
|
|
|
#include "CText.h"
|
2015-08-21 10:08:41 -07:00
|
|
|
|
2019-07-26 11:57:28 -07:00
|
|
|
#include "gui/CGUIScrollBarVertical.h"
|
|
|
|
|
#include "gui/GUI.h"
|
2006-06-01 19:10:27 -07:00
|
|
|
#include "lib/ogl.h"
|
2003-12-26 22:26:03 -08:00
|
|
|
|
2019-08-01 13:20:24 -07:00
|
|
|
CText::CText(CGUI* pGUI)
|
2019-08-01 16:55:10 -07:00
|
|
|
: IGUIObject(pGUI), IGUIScrollBarOwner(pGUI), IGUITextOwner(pGUI)
|
2003-12-26 22:26:03 -08:00
|
|
|
{
|
2019-08-03 19:20:08 -07:00
|
|
|
AddSetting<float>("buffer_zone");
|
|
|
|
|
AddSetting<CGUIString>("caption");
|
|
|
|
|
AddSetting<int>("cell_id");
|
|
|
|
|
AddSetting<bool>("clip");
|
|
|
|
|
AddSetting<CStrW>("font");
|
|
|
|
|
AddSetting<bool>("scrollbar");
|
|
|
|
|
AddSetting<CStr>("scrollbar_style");
|
|
|
|
|
AddSetting<bool>("scroll_bottom");
|
|
|
|
|
AddSetting<bool>("scroll_top");
|
|
|
|
|
AddSetting<CGUISpriteInstance>("sprite");
|
|
|
|
|
AddSetting<EAlign>("text_align");
|
|
|
|
|
AddSetting<EVAlign>("text_valign");
|
|
|
|
|
AddSetting<CGUIColor>("textcolor");
|
|
|
|
|
AddSetting<CGUIColor>("textcolor_disabled");
|
|
|
|
|
AddSetting<CStrW>("tooltip");
|
|
|
|
|
AddSetting<CStr>("tooltip_style");
|
2003-12-26 22:26:03 -08:00
|
|
|
|
2011-02-18 14:36:39 -08:00
|
|
|
// Private settings
|
2019-08-03 19:20:08 -07:00
|
|
|
AddSetting<CStrW>("_icon_tooltip");
|
|
|
|
|
AddSetting<CStr>("_icon_tooltip_style");
|
2010-10-29 21:02:42 -07:00
|
|
|
|
2004-05-28 21:06:50 -07:00
|
|
|
//GUI<bool>::SetSetting(this, "ghost", true);
|
|
|
|
|
GUI<bool>::SetSetting(this, "scrollbar", false);
|
2010-05-30 06:42:56 -07:00
|
|
|
GUI<bool>::SetSetting(this, "clip", true);
|
2003-12-26 22:26:03 -08:00
|
|
|
|
|
|
|
|
// Add scroll-bar
|
2019-08-01 13:20:24 -07:00
|
|
|
CGUIScrollBarVertical* bar = new CGUIScrollBarVertical(pGUI);
|
2003-12-26 22:26:03 -08:00
|
|
|
bar->SetRightAligned(true);
|
|
|
|
|
AddScrollBar(bar);
|
2004-05-28 21:06:50 -07:00
|
|
|
|
|
|
|
|
// Add text
|
|
|
|
|
AddText(new SGUIText());
|
2003-12-26 22:26:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CText::~CText()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-28 21:06:50 -07:00
|
|
|
void CText::SetupText()
|
|
|
|
|
{
|
2019-08-01 13:20:24 -07:00
|
|
|
if (m_GeneratedTexts.empty())
|
2004-05-28 21:06:50 -07:00
|
|
|
return;
|
|
|
|
|
|
2009-11-03 13:46:35 -08:00
|
|
|
CStrW font;
|
|
|
|
|
if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_OK || font.empty())
|
2004-07-31 12:52:15 -07:00
|
|
|
// Use the default if none is specified
|
2004-08-30 19:09:58 -07:00
|
|
|
// TODO Gee: (2004-08-14) Don't define standard like this. Do it with the default style.
|
2009-11-03 13:46:35 -08:00
|
|
|
font = L"default";
|
2004-07-31 12:52:15 -07:00
|
|
|
|
Use NONCOPYABLE for most GUI classes and structs to have the compiler indicate unintended copies, refs 3028551b91 / D2163.
That is CChartData, CGUIList, CGUISeries, COListColumn, GUITooltip,
SGUIMessage, SSpriteCall, STextCall, SFeedback, IGUISetting,
CGUISetting, GUI, IGUIObject, IGUIScrollBar.
Drop copying GetSetting and SetSetting template functions for CGUIList,
CGUISeries, CClientArea, CGUIString.
Stop copying COListColumn.
Drop copying GUI<CClientArea>::GetSetting call in
IGUIObject::UpdateCachedSize() and four copying
GUI<CGUIString>::GetSetting calls in SetupText() functions.
Delete unused GUIRenderer IGLState class from 849f50a500 obsolete since
1f5b8f1c9a.
Differential Revision: https://code.wildfiregames.com/D2164
This was SVN commit r22638.
2019-08-09 17:04:17 -07:00
|
|
|
CGUIString* caption = nullptr;
|
|
|
|
|
GUI<CGUIString>::GetSettingPointer(this, "caption", caption);
|
|
|
|
|
|
2004-05-28 21:06:50 -07:00
|
|
|
bool scrollbar;
|
|
|
|
|
GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
|
|
|
|
|
|
2004-09-02 22:48:47 -07:00
|
|
|
float width = m_CachedActualSize.GetWidth();
|
2004-05-28 21:06:50 -07:00
|
|
|
// remove scrollbar if applicable
|
|
|
|
|
if (scrollbar && GetScrollBar(0).GetStyle())
|
|
|
|
|
width -= GetScrollBar(0).GetStyle()->m_Width;
|
|
|
|
|
|
2004-08-30 20:25:36 -07:00
|
|
|
|
2015-08-21 10:08:41 -07:00
|
|
|
float buffer_zone = 0.f;
|
2005-01-01 04:06:17 -08:00
|
|
|
GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
|
Use NONCOPYABLE for most GUI classes and structs to have the compiler indicate unintended copies, refs 3028551b91 / D2163.
That is CChartData, CGUIList, CGUISeries, COListColumn, GUITooltip,
SGUIMessage, SSpriteCall, STextCall, SFeedback, IGUISetting,
CGUISetting, GUI, IGUIObject, IGUIScrollBar.
Drop copying GetSetting and SetSetting template functions for CGUIList,
CGUISeries, CClientArea, CGUIString.
Stop copying COListColumn.
Drop copying GUI<CClientArea>::GetSetting call in
IGUIObject::UpdateCachedSize() and four copying
GUI<CGUIString>::GetSetting calls in SetupText() functions.
Delete unused GUIRenderer IGLState class from 849f50a500 obsolete since
1f5b8f1c9a.
Differential Revision: https://code.wildfiregames.com/D2164
This was SVN commit r22638.
2019-08-09 17:04:17 -07:00
|
|
|
*m_GeneratedTexts[0] = GetGUI()->GenerateText(*caption, font, width, buffer_zone, this);
|
2004-05-28 21:06:50 -07:00
|
|
|
|
2015-08-21 10:08:41 -07:00
|
|
|
if (!scrollbar)
|
2004-12-28 04:17:04 -08:00
|
|
|
CalculateTextPosition(m_CachedActualSize, m_TextPos, *m_GeneratedTexts[0]);
|
|
|
|
|
|
2004-05-28 21:06:50 -07:00
|
|
|
// Setup scrollbar
|
|
|
|
|
if (scrollbar)
|
|
|
|
|
{
|
2016-12-11 13:15:50 -08:00
|
|
|
bool scroll_top = false, scroll_bottom = false;
|
|
|
|
|
GUI<bool>::GetSetting(this, "scroll_bottom", scroll_bottom);
|
|
|
|
|
GUI<bool>::GetSetting(this, "scroll_top", scroll_top);
|
2010-07-02 14:28:48 -07:00
|
|
|
|
|
|
|
|
// If we are currently scrolled to the bottom of the text,
|
|
|
|
|
// then add more lines of text, update the scrollbar so we
|
|
|
|
|
// stick to the bottom.
|
|
|
|
|
// (Use 1.5px delta so this triggers the first time caption is set)
|
|
|
|
|
bool bottom = false;
|
2016-12-11 13:15:50 -08:00
|
|
|
if (scroll_bottom && GetScrollBar(0).GetPos() > GetScrollBar(0).GetMaxPos() - 1.5f)
|
2010-07-02 14:28:48 -07:00
|
|
|
bottom = true;
|
|
|
|
|
|
|
|
|
|
GetScrollBar(0).SetScrollRange(m_GeneratedTexts[0]->m_Size.cy);
|
|
|
|
|
GetScrollBar(0).SetScrollSpace(m_CachedActualSize.GetHeight());
|
|
|
|
|
|
2010-07-03 06:12:44 -07:00
|
|
|
GetScrollBar(0).SetX(m_CachedActualSize.right);
|
|
|
|
|
GetScrollBar(0).SetY(m_CachedActualSize.top);
|
|
|
|
|
GetScrollBar(0).SetZ(GetBufferedZ());
|
|
|
|
|
GetScrollBar(0).SetLength(m_CachedActualSize.bottom - m_CachedActualSize.top);
|
|
|
|
|
|
2010-07-02 14:28:48 -07:00
|
|
|
if (bottom)
|
|
|
|
|
GetScrollBar(0).SetPos(GetScrollBar(0).GetMaxPos());
|
2016-12-11 13:15:50 -08:00
|
|
|
if (scroll_top)
|
|
|
|
|
GetScrollBar(0).SetPos(0.0f);
|
2004-05-28 21:06:50 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-21 10:08:41 -07:00
|
|
|
void CText::HandleMessage(SGUIMessage& Message)
|
2003-12-26 22:26:03 -08:00
|
|
|
{
|
|
|
|
|
IGUIScrollBarOwner::HandleMessage(Message);
|
2005-02-04 23:25:16 -08:00
|
|
|
//IGUITextOwner::HandleMessage(Message); <== placed it after the switch instead!
|
2003-12-26 22:26:03 -08:00
|
|
|
|
|
|
|
|
switch (Message.type)
|
|
|
|
|
{
|
|
|
|
|
case GUIM_SETTINGS_UPDATED:
|
2010-07-03 06:12:44 -07:00
|
|
|
if (Message.value == "scrollbar")
|
2005-02-04 23:25:16 -08:00
|
|
|
SetupText();
|
|
|
|
|
|
2004-05-28 21:06:50 -07:00
|
|
|
// Update scrollbar
|
2010-07-03 06:12:44 -07:00
|
|
|
if (Message.value == "scrollbar_style")
|
2003-12-26 22:26:03 -08:00
|
|
|
{
|
2004-05-28 21:06:50 -07:00
|
|
|
CStr scrollbar_style;
|
|
|
|
|
GUI<CStr>::GetSetting(this, Message.value, scrollbar_style);
|
|
|
|
|
|
2015-08-21 10:08:41 -07:00
|
|
|
GetScrollBar(0).SetScrollBarStyle(scrollbar_style);
|
2005-04-07 02:13:10 -07:00
|
|
|
|
|
|
|
|
SetupText();
|
2003-12-26 22:26:03 -08:00
|
|
|
}
|
2004-05-28 21:06:50 -07:00
|
|
|
|
2003-12-26 22:26:03 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GUIM_MOUSE_WHEEL_DOWN:
|
2015-08-21 10:08:41 -07:00
|
|
|
{
|
2005-10-20 08:27:39 -07:00
|
|
|
GetScrollBar(0).ScrollPlus();
|
2004-05-28 21:06:50 -07:00
|
|
|
// Since the scroll was changed, let's simulate a mouse movement
|
|
|
|
|
// to check if scrollbar now is hovered
|
2011-04-28 13:42:11 -07:00
|
|
|
SGUIMessage msg(GUIM_MOUSE_MOTION);
|
|
|
|
|
HandleMessage(msg);
|
2003-12-26 22:26:03 -08:00
|
|
|
break;
|
2015-08-21 10:08:41 -07:00
|
|
|
}
|
2003-12-26 22:26:03 -08:00
|
|
|
case GUIM_MOUSE_WHEEL_UP:
|
2015-08-21 10:08:41 -07:00
|
|
|
{
|
2005-10-20 08:27:39 -07:00
|
|
|
GetScrollBar(0).ScrollMinus();
|
2004-05-28 21:06:50 -07:00
|
|
|
// Since the scroll was changed, let's simulate a mouse movement
|
|
|
|
|
// to check if scrollbar now is hovered
|
2011-04-28 13:42:11 -07:00
|
|
|
SGUIMessage msg(GUIM_MOUSE_MOTION);
|
|
|
|
|
HandleMessage(msg);
|
2003-12-26 22:26:03 -08:00
|
|
|
break;
|
2015-08-21 10:08:41 -07:00
|
|
|
}
|
2005-02-04 23:25:16 -08:00
|
|
|
case GUIM_LOAD:
|
2015-08-21 10:08:41 -07:00
|
|
|
{
|
|
|
|
|
GetScrollBar(0).SetX(m_CachedActualSize.right);
|
|
|
|
|
GetScrollBar(0).SetY(m_CachedActualSize.top);
|
|
|
|
|
GetScrollBar(0).SetZ(GetBufferedZ());
|
|
|
|
|
GetScrollBar(0).SetLength(m_CachedActualSize.bottom - m_CachedActualSize.top);
|
2005-02-04 23:25:16 -08:00
|
|
|
|
|
|
|
|
CStr scrollbar_style;
|
|
|
|
|
GUI<CStr>::GetSetting(this, "scrollbar_style", scrollbar_style);
|
2015-08-21 10:08:41 -07:00
|
|
|
GetScrollBar(0).SetScrollBarStyle(scrollbar_style);
|
2005-02-04 23:25:16 -08:00
|
|
|
break;
|
2015-08-21 10:08:41 -07:00
|
|
|
}
|
2005-02-04 23:25:16 -08:00
|
|
|
|
2003-12-26 22:26:03 -08:00
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2005-02-04 23:25:16 -08:00
|
|
|
|
|
|
|
|
IGUITextOwner::HandleMessage(Message);
|
2003-12-26 22:26:03 -08:00
|
|
|
}
|
|
|
|
|
|
2015-08-21 10:08:41 -07:00
|
|
|
void CText::Draw()
|
2003-12-26 22:26:03 -08:00
|
|
|
{
|
2004-05-28 21:06:50 -07:00
|
|
|
float bz = GetBufferedZ();
|
|
|
|
|
|
2003-12-26 22:26:03 -08:00
|
|
|
// First call draw on ScrollBarOwner
|
2004-05-28 21:06:50 -07:00
|
|
|
bool scrollbar;
|
|
|
|
|
GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
|
2003-12-26 22:26:03 -08:00
|
|
|
|
2004-05-28 21:06:50 -07:00
|
|
|
if (scrollbar)
|
|
|
|
|
// Draw scrollbar
|
|
|
|
|
IGUIScrollBarOwner::Draw();
|
|
|
|
|
|
2015-08-21 10:08:41 -07:00
|
|
|
CGUISpriteInstance* sprite;
|
|
|
|
|
int cell_id;
|
|
|
|
|
bool clip;
|
|
|
|
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
|
|
|
|
|
GUI<int>::GetSetting(this, "cell_id", cell_id);
|
|
|
|
|
GUI<bool>::GetSetting(this, "clip", clip);
|
2005-07-24 01:29:02 -07:00
|
|
|
|
2015-08-21 10:08:41 -07:00
|
|
|
GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize);
|
2010-05-30 06:42:56 -07:00
|
|
|
|
2015-08-21 10:08:41 -07:00
|
|
|
float scroll = 0.f;
|
|
|
|
|
if (scrollbar)
|
|
|
|
|
scroll = GetScrollBar(0).GetPos();
|
2004-05-28 21:06:50 -07:00
|
|
|
|
2015-08-21 10:08:41 -07:00
|
|
|
// Clipping area (we'll have to subtract the scrollbar)
|
|
|
|
|
CRect cliparea;
|
|
|
|
|
if (clip)
|
|
|
|
|
{
|
|
|
|
|
cliparea = m_CachedActualSize;
|
2004-05-28 21:06:50 -07:00
|
|
|
|
2004-12-28 04:17:04 -08:00
|
|
|
if (scrollbar)
|
2015-08-21 10:08:41 -07:00
|
|
|
{
|
|
|
|
|
// subtract scrollbar from cliparea
|
|
|
|
|
if (cliparea.right > GetScrollBar(0).GetOuterRect().left &&
|
|
|
|
|
cliparea.right <= GetScrollBar(0).GetOuterRect().right)
|
|
|
|
|
cliparea.right = GetScrollBar(0).GetOuterRect().left;
|
|
|
|
|
|
|
|
|
|
if (cliparea.left >= GetScrollBar(0).GetOuterRect().left &&
|
|
|
|
|
cliparea.left < GetScrollBar(0).GetOuterRect().right)
|
|
|
|
|
cliparea.left = GetScrollBar(0).GetOuterRect().right;
|
|
|
|
|
}
|
2004-05-28 21:06:50 -07:00
|
|
|
}
|
2015-08-21 10:08:41 -07:00
|
|
|
|
2016-12-05 09:21:51 -08:00
|
|
|
bool enabled;
|
|
|
|
|
GUI<bool>::GetSetting(this, "enabled", enabled);
|
|
|
|
|
|
2019-07-26 11:57:28 -07:00
|
|
|
CGUIColor color;
|
|
|
|
|
GUI<CGUIColor>::GetSetting(this, enabled ? "textcolor" : "textcolor_disabled", color);
|
2015-08-21 10:08:41 -07:00
|
|
|
|
|
|
|
|
if (scrollbar)
|
|
|
|
|
DrawText(0, color, m_CachedActualSize.TopLeft() - CPos(0.f, scroll), bz+0.1f, cliparea);
|
|
|
|
|
else
|
|
|
|
|
DrawText(0, color, m_TextPos, bz+0.1f, cliparea);
|
2003-12-26 22:26:03 -08:00
|
|
|
}
|
2010-10-29 21:02:42 -07:00
|
|
|
|
|
|
|
|
bool CText::MouseOverIcon()
|
|
|
|
|
{
|
2015-08-21 10:08:41 -07:00
|
|
|
for (SGUIText* const& guitext : m_GeneratedTexts)
|
|
|
|
|
for (const SGUIText::SSpriteCall& spritecall : guitext->m_SpriteCalls)
|
2010-10-29 21:02:42 -07:00
|
|
|
{
|
2015-08-21 10:08:41 -07:00
|
|
|
// Check mouse over sprite
|
2019-08-10 05:51:27 -07:00
|
|
|
if (!spritecall.m_Area.PointInside(m_pGUI->GetMousePos() - m_CachedActualSize.TopLeft()))
|
2015-08-21 10:08:41 -07:00
|
|
|
continue;
|
2010-10-29 21:02:42 -07:00
|
|
|
|
2015-08-21 10:08:41 -07:00
|
|
|
// If tooltip exists, set the property
|
|
|
|
|
if (!spritecall.m_Tooltip.empty())
|
2010-10-29 21:02:42 -07:00
|
|
|
{
|
2015-08-21 10:08:41 -07:00
|
|
|
SetSetting("_icon_tooltip_style", spritecall.m_TooltipStyle);
|
|
|
|
|
SetSetting("_icon_tooltip", spritecall.m_Tooltip);
|
2010-10-29 21:02:42 -07:00
|
|
|
}
|
2015-08-21 10:08:41 -07:00
|
|
|
|
|
|
|
|
return true;
|
2010-10-29 21:02:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|