GUI code cleanup. Fixes #3354.
Lots of code style fixes: * type [*&]varname -> type[*&] varname * else if (...) -> else if (...) * Spaces around some ops. * i++ -> ++i. * switch-case style fixes. * Indentation fixes. * Removing some commented out code. * include header sorting * Changed multiple pointer var declarations to be one per line. * Removed strange spaces in some places. * Changed some include header guards to be consistent with the rest of the codebase. * Use UNUSED() instead of UNUSED2(). Some small code fixes: * Using .find() instead of .count() == 0. * !.empty() instead of .size() == 0. * Range-based for loops. * Making some member functions const by small changes. * Adds GetScrollBarPos(idx) const for this. * Using early returns/continues in some places. * Uses size_t for some loops in CList and COList. * Removes unused heading element (not attribute) from COList. * Use ENSURE in one case where some custom code did something similar. * Made some parameters const ptrs/refs. * Change removal loop in GUItext.cpp to erase-unique. * Made some static things const. * Allow iterating over children of IGUIObject with range-based for loops by exposing begin() and end() (rename from ChildrenIt{Begin,End}()) and use it. Comments: * Comment COList. * Update a few comments. * Remove useless or duplicated comments. This was SVN commit r16931.
This commit is contained in:
parent
d821601978
commit
74c420f658
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2013 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -15,20 +15,12 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
CButton
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "CButton.h"
|
||||
|
||||
#include "lib/ogl.h"
|
||||
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Constructor / Destructor
|
||||
//-------------------------------------------------------------------
|
||||
CButton::CButton()
|
||||
{
|
||||
AddSetting(GUIST_float, "buffer_zone");
|
||||
@ -66,7 +58,7 @@ void CButton::SetupText()
|
||||
if (!GetGUI())
|
||||
return;
|
||||
|
||||
ENSURE(m_GeneratedTexts.size()==1);
|
||||
ENSURE(m_GeneratedTexts.size() == 1);
|
||||
|
||||
CStrW font;
|
||||
if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_OK || font.empty())
|
||||
@ -77,34 +69,37 @@ void CButton::SetupText()
|
||||
CGUIString caption;
|
||||
GUI<CGUIString>::GetSetting(this, "caption", caption);
|
||||
|
||||
float buffer_zone=0.f;
|
||||
float buffer_zone = 0.f;
|
||||
GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
|
||||
*m_GeneratedTexts[0] = GetGUI()->GenerateText(caption, font, m_CachedActualSize.GetWidth(), buffer_zone, this);
|
||||
|
||||
CalculateTextPosition(m_CachedActualSize, m_TextPos, *m_GeneratedTexts[0]);
|
||||
}
|
||||
|
||||
void CButton::HandleMessage(SGUIMessage &Message)
|
||||
void CButton::HandleMessage(SGUIMessage& Message)
|
||||
{
|
||||
// Important
|
||||
IGUIButtonBehavior::HandleMessage(Message);
|
||||
IGUITextOwner::HandleMessage(Message);
|
||||
}
|
||||
|
||||
void CButton::Draw()
|
||||
void CButton::Draw()
|
||||
{
|
||||
float bz = GetBufferedZ();
|
||||
|
||||
CGUISpriteInstance *sprite, *sprite_over, *sprite_pressed, *sprite_disabled;
|
||||
CGUISpriteInstance* sprite;
|
||||
CGUISpriteInstance* sprite_over;
|
||||
CGUISpriteInstance* sprite_pressed;
|
||||
CGUISpriteInstance* sprite_disabled;
|
||||
int cell_id;
|
||||
|
||||
// Statically initialise some strings, so we don't have to do
|
||||
// lots of allocation every time this function is called
|
||||
static CStr strSprite("sprite");
|
||||
static CStr strSpriteOver("sprite_over");
|
||||
static CStr strSpritePressed("sprite_pressed");
|
||||
static CStr strSpriteDisabled("sprite_disabled");
|
||||
static CStr strCellId("cell_id");
|
||||
static const CStr strSprite("sprite");
|
||||
static const CStr strSpriteOver("sprite_over");
|
||||
static const CStr strSpritePressed("sprite_pressed");
|
||||
static const CStr strSpriteDisabled("sprite_disabled");
|
||||
static const CStr strCellId("cell_id");
|
||||
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, strSprite, sprite);
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, strSpriteOver, sprite_over);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -15,42 +15,14 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
GUI Object - Button
|
||||
|
||||
--Overview--
|
||||
|
||||
GUI Object representing a simple button
|
||||
|
||||
--More info--
|
||||
|
||||
Check GUI.h
|
||||
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_CBUTTON
|
||||
#define INCLUDED_CBUTTON
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Includes / Compiler directives
|
||||
//--------------------------------------------------------
|
||||
#include "GUI.h"
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Macros
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Types
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Declarations
|
||||
//--------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Button
|
||||
*
|
||||
*
|
||||
* @see IGUIObject
|
||||
* @see IGUIButtonBehavior
|
||||
*/
|
||||
@ -70,7 +42,7 @@ public:
|
||||
/**
|
||||
* @see IGUIObject#HandleMessage()
|
||||
*/
|
||||
virtual void HandleMessage(SGUIMessage &Message);
|
||||
virtual void HandleMessage(SGUIMessage& Message);
|
||||
|
||||
/**
|
||||
* Draws the Button
|
||||
@ -90,4 +62,4 @@ protected:
|
||||
CPos m_TextPos;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // INCLUDED_CBUTTON
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2013 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -15,22 +15,14 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
CCheckBox
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "CCheckBox.h"
|
||||
|
||||
#include "graphics/FontMetrics.h"
|
||||
#include "ps/CLogger.h"
|
||||
#include "ps/CStrIntern.h"
|
||||
#include "graphics/FontMetrics.h"
|
||||
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Constructor / Destructor
|
||||
//-------------------------------------------------------------------
|
||||
CCheckBox::CCheckBox()
|
||||
{
|
||||
AddSetting(GUIST_float, "buffer_zone");
|
||||
@ -72,7 +64,7 @@ void CCheckBox::SetupText()
|
||||
if (!GetGUI())
|
||||
return;
|
||||
|
||||
ENSURE(m_GeneratedTexts.size()==1);
|
||||
ENSURE(m_GeneratedTexts.size() == 1);
|
||||
|
||||
CStrW font;
|
||||
if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_OK || font.empty())
|
||||
@ -86,12 +78,12 @@ void CCheckBox::SetupText()
|
||||
CGUIString caption;
|
||||
GUI<CGUIString>::GetSetting(this, "caption", caption);
|
||||
|
||||
float buffer_zone=0.f;
|
||||
float buffer_zone = 0.f;
|
||||
GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
|
||||
*m_GeneratedTexts[0] = GetGUI()->GenerateText(caption, font, m_CachedActualSize.GetWidth()-square_side, 0.f, this);
|
||||
}
|
||||
|
||||
void CCheckBox::HandleMessage(SGUIMessage &Message)
|
||||
void CCheckBox::HandleMessage(SGUIMessage& Message)
|
||||
{
|
||||
// Important
|
||||
IGUIButtonBehavior::HandleMessage(Message);
|
||||
@ -115,12 +107,15 @@ void CCheckBox::HandleMessage(SGUIMessage &Message)
|
||||
}
|
||||
}
|
||||
|
||||
void CCheckBox::Draw()
|
||||
void CCheckBox::Draw()
|
||||
{
|
||||
float bz = GetBufferedZ();
|
||||
bool checked;
|
||||
int cell_id;
|
||||
CGUISpriteInstance *sprite, *sprite_over, *sprite_pressed, *sprite_disabled;
|
||||
CGUISpriteInstance* sprite;
|
||||
CGUISpriteInstance* sprite_over;
|
||||
CGUISpriteInstance* sprite_pressed;
|
||||
CGUISpriteInstance* sprite_disabled;
|
||||
|
||||
GUI<bool>::GetSetting(this, "checked", checked);
|
||||
GUI<int>::GetSetting(this, "cell_id", cell_id);
|
||||
@ -140,7 +135,7 @@ void CCheckBox::Draw()
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_disabled", sprite_disabled);
|
||||
}
|
||||
|
||||
DrawButton(m_CachedActualSize,
|
||||
DrawButton(m_CachedActualSize,
|
||||
bz,
|
||||
*sprite,
|
||||
*sprite_over,
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -15,42 +15,14 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
GUI Object - Check box
|
||||
|
||||
--Overview--
|
||||
|
||||
GUI Object representing a check box
|
||||
|
||||
--More info--
|
||||
|
||||
Check GUI.h
|
||||
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_CCHECKBOX
|
||||
#define INCLUDED_CCHECKBOX
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Includes / Compiler directives
|
||||
//--------------------------------------------------------
|
||||
#include "GUI.h"
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Macros
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Types
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Declarations
|
||||
//--------------------------------------------------------
|
||||
|
||||
/**
|
||||
* CheckBox
|
||||
*
|
||||
*
|
||||
* @see IGUIObject
|
||||
* @see IGUISettingsObject
|
||||
* @see IGUIButtonBehavior
|
||||
@ -71,7 +43,7 @@ public:
|
||||
/**
|
||||
* @see IGUIObject#HandleMessage()
|
||||
*/
|
||||
virtual void HandleMessage(SGUIMessage &Message);
|
||||
virtual void HandleMessage(SGUIMessage& Message);
|
||||
|
||||
/**
|
||||
* Draws the control
|
||||
@ -86,4 +58,4 @@ protected:
|
||||
void SetupText();
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // INCLUDED_CCHECKBOX
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2014 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -15,25 +15,18 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
CDropDown
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "CDropDown.h"
|
||||
|
||||
#include "ps/CLogger.h"
|
||||
#include "lib/external_libraries/libsdl.h"
|
||||
#include "lib/ogl.h"
|
||||
#include "lib/timer.h"
|
||||
#include "ps/CLogger.h"
|
||||
#include "soundmanager/ISoundManager.h"
|
||||
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Constructor / Destructor
|
||||
//-------------------------------------------------------------------
|
||||
CDropDown::CDropDown() : m_Open(false), m_HideScrollBar(false), m_ElementHighlight(-1)
|
||||
CDropDown::CDropDown()
|
||||
: m_Open(false), m_HideScrollBar(false), m_ElementHighlight(-1)
|
||||
{
|
||||
AddSetting(GUIST_float, "button_width");
|
||||
AddSetting(GUIST_float, "dropdown_size");
|
||||
@ -51,7 +44,7 @@ CDropDown::CDropDown() : m_Open(false), m_HideScrollBar(false), m_ElementHighlig
|
||||
AddSetting(GUIST_CGUISpriteInstance, "sprite2_pressed");
|
||||
AddSetting(GUIST_CGUISpriteInstance, "sprite2_disabled");
|
||||
AddSetting(GUIST_EVAlign, "text_valign");
|
||||
|
||||
|
||||
// Add these in CList! And implement TODO
|
||||
//AddSetting(GUIST_CColor, "textcolor_over");
|
||||
//AddSetting(GUIST_CColor, "textcolor_pressed");
|
||||
@ -72,7 +65,7 @@ void CDropDown::SetupText()
|
||||
CList::SetupText();
|
||||
}
|
||||
|
||||
void CDropDown::HandleMessage(SGUIMessage &Message)
|
||||
void CDropDown::HandleMessage(SGUIMessage& Message)
|
||||
{
|
||||
// Important
|
||||
|
||||
@ -89,53 +82,50 @@ void CDropDown::HandleMessage(SGUIMessage &Message)
|
||||
Message.value == "button_width")
|
||||
{
|
||||
SetupListRect();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIM_MOUSE_MOTION:
|
||||
{
|
||||
if (m_Open)
|
||||
if (!m_Open)
|
||||
break;
|
||||
|
||||
CPos mouse = GetMousePos();
|
||||
|
||||
if (!GetListRect().PointInside(mouse))
|
||||
break;
|
||||
|
||||
bool scrollbar;
|
||||
CGUIList* pList;
|
||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
|
||||
GUI<CGUIList>::GetSettingPointer(this, "list", pList);
|
||||
float scroll = 0.f;
|
||||
if (scrollbar)
|
||||
scroll = GetScrollBar(0).GetPos();
|
||||
|
||||
CRect rect = GetListRect();
|
||||
mouse.y += scroll;
|
||||
int set = -1;
|
||||
for (int i = 0; i < (int)pList->m_Items.size(); ++i)
|
||||
{
|
||||
CPos mouse = GetMousePos();
|
||||
|
||||
if (GetListRect().PointInside(mouse))
|
||||
if (mouse.y >= rect.top + m_ItemsYPositions[i] &&
|
||||
mouse.y < rect.top + m_ItemsYPositions[i+1] &&
|
||||
// mouse is not over scroll-bar
|
||||
!(mouse.x >= GetScrollBar(0).GetOuterRect().left &&
|
||||
mouse.x <= GetScrollBar(0).GetOuterRect().right))
|
||||
{
|
||||
bool scrollbar;
|
||||
CGUIList *pList;
|
||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
|
||||
GUI<CGUIList>::GetSettingPointer(this, "list", pList);
|
||||
float scroll=0.f;
|
||||
if (scrollbar)
|
||||
{
|
||||
scroll = GetScrollBar(0).GetPos();
|
||||
}
|
||||
|
||||
CRect rect = GetListRect();
|
||||
mouse.y += scroll;
|
||||
int set=-1;
|
||||
for (int i=0; i<(int)pList->m_Items.size(); ++i)
|
||||
{
|
||||
if (mouse.y >= rect.top + m_ItemsYPositions[i] &&
|
||||
mouse.y < rect.top + m_ItemsYPositions[i+1] &&
|
||||
// mouse is not over scroll-bar
|
||||
!(mouse.x >= GetScrollBar(0).GetOuterRect().left &&
|
||||
mouse.x <= GetScrollBar(0).GetOuterRect().right))
|
||||
{
|
||||
set = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (set != -1)
|
||||
{
|
||||
//GUI<int>::SetSetting(this, "selected", set);
|
||||
m_ElementHighlight = set;
|
||||
//UpdateAutoScroll();
|
||||
}
|
||||
set = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (set != -1)
|
||||
{
|
||||
m_ElementHighlight = set;
|
||||
//UpdateAutoScroll();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@ -143,12 +133,12 @@ void CDropDown::HandleMessage(SGUIMessage &Message)
|
||||
{
|
||||
bool enabled;
|
||||
GUI<bool>::GetSetting(this, "enabled", enabled);
|
||||
if (enabled)
|
||||
{
|
||||
CStrW soundPath;
|
||||
if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_enter", soundPath) == PSRETURN_OK && !soundPath.empty())
|
||||
g_SoundManager->PlayAsUI(soundPath.c_str(), false);
|
||||
}
|
||||
if (!enabled)
|
||||
break;
|
||||
|
||||
CStrW soundPath;
|
||||
if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_enter", soundPath) == PSRETURN_OK && !soundPath.empty())
|
||||
g_SoundManager->PlayAsUI(soundPath.c_str(), false);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -158,12 +148,12 @@ void CDropDown::HandleMessage(SGUIMessage &Message)
|
||||
|
||||
bool enabled;
|
||||
GUI<bool>::GetSetting(this, "enabled", enabled);
|
||||
if (enabled)
|
||||
{
|
||||
CStrW soundPath;
|
||||
if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_leave", soundPath) == PSRETURN_OK && !soundPath.empty())
|
||||
g_SoundManager->PlayAsUI(soundPath.c_str(), false);
|
||||
}
|
||||
if (!enabled)
|
||||
break;
|
||||
|
||||
CStrW soundPath;
|
||||
if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_leave", soundPath) == PSRETURN_OK && !soundPath.empty())
|
||||
g_SoundManager->PlayAsUI(soundPath.c_str(), false);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -183,7 +173,7 @@ void CDropDown::HandleMessage(SGUIMessage &Message)
|
||||
|
||||
if (!m_Open)
|
||||
{
|
||||
CGUIList *pList;
|
||||
CGUIList* pList;
|
||||
GUI<CGUIList>::GetSettingPointer(this, "list", pList);
|
||||
if (pList->m_Items.empty())
|
||||
return;
|
||||
@ -193,7 +183,7 @@ void CDropDown::HandleMessage(SGUIMessage &Message)
|
||||
GUI<int>::GetSetting(this, "selected", m_ElementHighlight);
|
||||
|
||||
// Start at the position of the selected item, if possible.
|
||||
GetScrollBar(0).SetPos( m_ItemsYPositions.empty() ? 0 : m_ItemsYPositions[m_ElementHighlight] - 60);
|
||||
GetScrollBar(0).SetPos(m_ItemsYPositions.empty() ? 0 : m_ItemsYPositions[m_ElementHighlight] - 60);
|
||||
|
||||
CStrW soundPath;
|
||||
if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_opened", soundPath) == PSRETURN_OK && !soundPath.empty())
|
||||
@ -242,7 +232,7 @@ void CDropDown::HandleMessage(SGUIMessage &Message)
|
||||
if (m_ElementHighlight + 1 >= (int)m_ItemsYPositions.size() - 1)
|
||||
break;
|
||||
|
||||
m_ElementHighlight++;
|
||||
++m_ElementHighlight;
|
||||
GUI<int>::SetSetting(this, "selected", m_ElementHighlight);
|
||||
break;
|
||||
}
|
||||
@ -302,7 +292,7 @@ InReaction CDropDown::ManuallyHandleEvent(const SDL_Event_* ev)
|
||||
if (ev->ev.type == SDL_KEYDOWN)
|
||||
{
|
||||
int szChar = ev->ev.key.keysym.sym;
|
||||
|
||||
|
||||
switch (szChar)
|
||||
{
|
||||
case '\r':
|
||||
@ -341,21 +331,21 @@ InReaction CDropDown::ManuallyHandleEvent(const SDL_Event_* ev)
|
||||
m_InputBuffer = szChar;
|
||||
else
|
||||
m_InputBuffer += szChar;
|
||||
|
||||
|
||||
m_TimeOfLastInput = timer_Time();
|
||||
|
||||
CGUIList *pList;
|
||||
|
||||
CGUIList* pList;
|
||||
GUI<CGUIList>::GetSettingPointer(this, "list", pList);
|
||||
// let's look for the closest element
|
||||
// basically it's alphabetic order and "as many letters as we can get".
|
||||
int closest = -1;
|
||||
int bestIndex = -1;
|
||||
int difference = 1250;
|
||||
for (int i=0; i<(int)pList->m_Items.size(); ++i)
|
||||
for (int i = 0; i < (int)pList->m_Items.size(); ++i)
|
||||
{
|
||||
int indexOfDifference = 0;
|
||||
int diff = 0;
|
||||
for (size_t j=0; j < m_InputBuffer.length(); ++j)
|
||||
for (size_t j = 0; j < m_InputBuffer.length(); ++j)
|
||||
{
|
||||
diff = abs(pList->m_Items[i].GetOriginalString().LowerCase()[j] - (int)m_InputBuffer[j]);
|
||||
if (diff == 0)
|
||||
@ -438,7 +428,7 @@ bool CDropDown::MouseOver()
|
||||
return m_CachedActualSize.PointInside(GetMousePos());
|
||||
}
|
||||
|
||||
void CDropDown::Draw()
|
||||
void CDropDown::Draw()
|
||||
{
|
||||
if (!GetGUI())
|
||||
return;
|
||||
@ -449,8 +439,10 @@ void CDropDown::Draw()
|
||||
GUI<float>::GetSetting(this, "dropdown_size", dropdown_size);
|
||||
GUI<float>::GetSetting(this, "button_width", button_width);
|
||||
|
||||
CGUISpriteInstance *sprite, *sprite2, *sprite2_second;
|
||||
int cell_id, selected=0;
|
||||
CGUISpriteInstance* sprite;
|
||||
CGUISpriteInstance* sprite2;
|
||||
CGUISpriteInstance* sprite2_second;
|
||||
int cell_id, selected = 0;
|
||||
CColor color;
|
||||
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
|
||||
@ -475,19 +467,17 @@ void CDropDown::Draw()
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite2_disabled", sprite2_second);
|
||||
GetGUI()->DrawSprite(GUI<>::FallBackSprite(*sprite2_second, *sprite2), cell_id, bz+0.05f, rect);
|
||||
}
|
||||
else
|
||||
if (m_Open)
|
||||
else if (m_Open)
|
||||
{
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite2_pressed", sprite2_second);
|
||||
GetGUI()->DrawSprite(GUI<>::FallBackSprite(*sprite2_second, *sprite2), cell_id, bz+0.05f, rect);
|
||||
}
|
||||
else
|
||||
if (m_MouseHovering)
|
||||
else if (m_MouseHovering)
|
||||
{
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite2_over", sprite2_second);
|
||||
GetGUI()->DrawSprite(GUI<>::FallBackSprite(*sprite2_second, *sprite2), cell_id, bz+0.05f, rect);
|
||||
}
|
||||
else
|
||||
else
|
||||
GetGUI()->DrawSprite(*sprite2, cell_id, bz+0.05f, rect);
|
||||
}
|
||||
|
||||
@ -501,7 +491,8 @@ void CDropDown::Draw()
|
||||
DrawText(selected, color, pos, bz+0.1f, cliparea);
|
||||
}
|
||||
|
||||
bool *scrollbar=NULL, old;
|
||||
bool* scrollbar = NULL;
|
||||
bool old;
|
||||
GUI<bool>::GetSettingPointer(this, "scrollbar", scrollbar);
|
||||
|
||||
old = *scrollbar;
|
||||
@ -509,10 +500,10 @@ void CDropDown::Draw()
|
||||
if (m_Open)
|
||||
{
|
||||
if (m_HideScrollBar)
|
||||
*scrollbar = false;
|
||||
*scrollbar = false;
|
||||
|
||||
DrawList(m_ElementHighlight, "sprite_list", "sprite_selectarea", "textcolor");
|
||||
|
||||
|
||||
if (m_HideScrollBar)
|
||||
*scrollbar = old;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -33,24 +33,8 @@ GUI Object - Drop Down (list)
|
||||
#ifndef INCLUDED_CDROPDOWN
|
||||
#define INCLUDED_CDROPDOWN
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Includes / Compiler directives
|
||||
//--------------------------------------------------------
|
||||
#include "GUI.h"
|
||||
#include "CList.h"
|
||||
//class CList;
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Macros
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Types
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Declarations
|
||||
//--------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Drop Down
|
||||
@ -74,7 +58,7 @@ public:
|
||||
/**
|
||||
* @see IGUIObject#HandleMessage()
|
||||
*/
|
||||
virtual void HandleMessage(SGUIMessage &Message);
|
||||
virtual void HandleMessage(SGUIMessage& Message);
|
||||
|
||||
/**
|
||||
* Handle events manually to catch keyboard inputting.
|
||||
@ -99,7 +83,7 @@ protected:
|
||||
* made that can change the visual.
|
||||
*/
|
||||
void SetupText();
|
||||
|
||||
|
||||
// Sets up the cached GetListRect. Decided whether it should
|
||||
// have a scrollbar, and so on.
|
||||
virtual void SetupListRect();
|
||||
@ -127,14 +111,14 @@ protected:
|
||||
// it is set to "selected", but then when moving the mouse it will
|
||||
// change.
|
||||
int m_ElementHighlight;
|
||||
|
||||
|
||||
// Stores any text entered by the user for quick access to an element
|
||||
// (ie if you type "acro" it will take you to acropolis).
|
||||
std::string m_InputBuffer;
|
||||
|
||||
|
||||
// used to know if we want to restart anew or add to m_inputbuffer.
|
||||
double m_TimeOfLastInput;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // INCLUDED_CDROPDOWN
|
||||
|
@ -15,50 +15,45 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
CGUI
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <string>
|
||||
|
||||
#include "GUI.h"
|
||||
|
||||
// Types - when including them into the engine.
|
||||
#include "CButton.h"
|
||||
#include "CImage.h"
|
||||
#include "CText.h"
|
||||
#include "CCheckBox.h"
|
||||
#include "CRadioButton.h"
|
||||
#include "CDropDown.h"
|
||||
#include "CImage.h"
|
||||
#include "CInput.h"
|
||||
#include "CList.h"
|
||||
#include "COList.h"
|
||||
#include "CDropDown.h"
|
||||
#include "CProgressBar.h"
|
||||
#include "CRadioButton.h"
|
||||
#include "CText.h"
|
||||
#include "CTooltip.h"
|
||||
#include "MiniMap.h"
|
||||
#include "scripting/ScriptFunctions.h"
|
||||
|
||||
#include "graphics/FontMetrics.h"
|
||||
#include "graphics/ShaderManager.h"
|
||||
#include "graphics/TextRenderer.h"
|
||||
#include "lib/input.h"
|
||||
#include "lib/bits.h"
|
||||
#include "i18n/L10n.h"
|
||||
#include "lib/timer.h"
|
||||
#include "lib/bits.h"
|
||||
#include "lib/input.h"
|
||||
#include "lib/sysdep/sysdep.h"
|
||||
#include "lib/timer.h"
|
||||
#include "lib/utf8.h"
|
||||
#include "ps/CLogger.h"
|
||||
#include "ps/Filesystem.h"
|
||||
#include "ps/Hotkey.h"
|
||||
#include "ps/Globals.h"
|
||||
#include "ps/Hotkey.h"
|
||||
#include "ps/Profile.h"
|
||||
#include "ps/Pyrogenesis.h"
|
||||
#include "ps/XML/Xeromyces.h"
|
||||
#include "renderer/Renderer.h"
|
||||
#include "scripting/ScriptFunctions.h"
|
||||
#include "scriptinterface/ScriptInterface.h"
|
||||
|
||||
extern int g_yres;
|
||||
@ -75,12 +70,8 @@ InReaction CGUI::HandleEvent(const SDL_Event_* ev)
|
||||
const char* hotkey = static_cast<const char*>(ev->ev.user.data1);
|
||||
std::map<CStr, std::vector<IGUIObject*> >::iterator it = m_HotkeyObjects.find(hotkey);
|
||||
if (it != m_HotkeyObjects.end())
|
||||
{
|
||||
for (size_t i = 0; i < it->second.size(); ++i)
|
||||
{
|
||||
it->second[i]->SendEvent(GUIM_PRESSED, "press");
|
||||
}
|
||||
}
|
||||
for (IGUIObject* const& obj : it->second)
|
||||
obj->SendEvent(GUIM_PRESSED, "press");
|
||||
}
|
||||
|
||||
else if (ev->ev.type == SDL_MOUSEMOTION)
|
||||
@ -91,8 +82,8 @@ InReaction CGUI::HandleEvent(const SDL_Event_* ev)
|
||||
m_MousePos = CPos((float)ev->ev.motion.x * g_GuiScale, (float)ev->ev.motion.y * g_GuiScale);
|
||||
|
||||
SGUIMessage msg(GUIM_MOUSE_MOTION);
|
||||
GUI<SGUIMessage>::RecurseObject(GUIRR_HIDDEN | GUIRR_GHOST, m_BaseObject,
|
||||
&IGUIObject::HandleMessage,
|
||||
GUI<SGUIMessage>::RecurseObject(GUIRR_HIDDEN | GUIRR_GHOST, m_BaseObject,
|
||||
&IGUIObject::HandleMessage,
|
||||
msg);
|
||||
}
|
||||
|
||||
@ -119,12 +110,12 @@ InReaction CGUI::HandleEvent(const SDL_Event_* ev)
|
||||
}
|
||||
|
||||
// Only one object can be hovered
|
||||
IGUIObject *pNearest = NULL;
|
||||
IGUIObject* pNearest = NULL;
|
||||
|
||||
// TODO Gee: (2004-09-08) Big TODO, don't do the below if the SDL_Event is something like a keypress!
|
||||
try
|
||||
{
|
||||
PROFILE( "mouse events" );
|
||||
PROFILE("mouse events");
|
||||
// TODO Gee: Optimizations needed!
|
||||
// these two recursive function are quite overhead heavy.
|
||||
|
||||
@ -134,8 +125,8 @@ InReaction CGUI::HandleEvent(const SDL_Event_* ev)
|
||||
// Now we'll call UpdateMouseOver on *all* objects,
|
||||
// we'll input the one hovered, and they will each
|
||||
// update their own data and send messages accordingly
|
||||
GUI<IGUIObject*>::RecurseObject(GUIRR_HIDDEN | GUIRR_GHOST, m_BaseObject,
|
||||
&IGUIObject::UpdateMouseOver,
|
||||
GUI<IGUIObject*>::RecurseObject(GUIRR_HIDDEN | GUIRR_GHOST, m_BaseObject,
|
||||
&IGUIObject::UpdateMouseOver,
|
||||
pNearest);
|
||||
|
||||
if (ev->ev.type == SDL_MOUSEBUTTONDOWN)
|
||||
@ -194,7 +185,7 @@ InReaction CGUI::HandleEvent(const SDL_Event_* ev)
|
||||
{
|
||||
double timeElapsed = timer_Time() - pNearest->m_LastClickTime[SDL_BUTTON_LEFT];
|
||||
pNearest->m_LastClickTime[SDL_BUTTON_LEFT] = timer_Time();
|
||||
|
||||
|
||||
//Double click?
|
||||
if (timeElapsed < SELECT_DBLCLICK_RATE)
|
||||
{
|
||||
@ -211,7 +202,7 @@ InReaction CGUI::HandleEvent(const SDL_Event_* ev)
|
||||
{
|
||||
double timeElapsed = timer_Time() - pNearest->m_LastClickTime[SDL_BUTTON_RIGHT];
|
||||
pNearest->m_LastClickTime[SDL_BUTTON_RIGHT] = timer_Time();
|
||||
|
||||
|
||||
//Double click?
|
||||
if (timeElapsed < SELECT_DBLCLICK_RATE)
|
||||
{
|
||||
@ -226,12 +217,12 @@ InReaction CGUI::HandleEvent(const SDL_Event_* ev)
|
||||
}
|
||||
|
||||
// Reset all states on all visible objects
|
||||
GUI<>::RecurseObject(GUIRR_HIDDEN, m_BaseObject,
|
||||
GUI<>::RecurseObject(GUIRR_HIDDEN, m_BaseObject,
|
||||
&IGUIObject::ResetStates);
|
||||
|
||||
// Since the hover state will have been reset, we reload it.
|
||||
GUI<IGUIObject*>::RecurseObject(GUIRR_HIDDEN | GUIRR_GHOST, m_BaseObject,
|
||||
&IGUIObject::UpdateMouseOver,
|
||||
GUI<IGUIObject*>::RecurseObject(GUIRR_HIDDEN | GUIRR_GHOST, m_BaseObject,
|
||||
&IGUIObject::UpdateMouseOver,
|
||||
pNearest);
|
||||
}
|
||||
}
|
||||
@ -272,7 +263,7 @@ InReaction CGUI::HandleEvent(const SDL_Event_* ev)
|
||||
(ev->ev.type == SDL_KEYDOWN &&
|
||||
ev->ev.key.keysym.sym != SDLK_ESCAPE &&
|
||||
!g_keys[SDLK_LCTRL] && !g_keys[SDLK_RCTRL] &&
|
||||
!g_keys[SDLK_LALT] && !g_keys[SDLK_RALT])
|
||||
!g_keys[SDLK_LALT] && !g_keys[SDLK_RALT])
|
||||
|| ev->ev.type == SDL_HOTKEYDOWN
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
|| ev->ev.type == SDL_TEXTINPUT || ev->ev.type == SDL_TEXTEDITING
|
||||
@ -290,7 +281,7 @@ InReaction CGUI::HandleEvent(const SDL_Event_* ev)
|
||||
void CGUI::TickObjects()
|
||||
{
|
||||
CStr action = "tick";
|
||||
GUI<CStr>::RecurseObject(0, m_BaseObject,
|
||||
GUI<CStr>::RecurseObject(0, m_BaseObject,
|
||||
&IGUIObject::ScriptEvent, action);
|
||||
|
||||
// Also update tooltips:
|
||||
@ -306,21 +297,18 @@ void CGUI::SendEventToAll(const CStr& EventName)
|
||||
// (sending events here) wasn't converting to lower case,
|
||||
// leading to a similar problem.
|
||||
// now fixed; case is irrelevant since all are converted to lower.
|
||||
GUI<CStr>::RecurseObject(0, m_BaseObject,
|
||||
GUI<CStr>::RecurseObject(0, m_BaseObject,
|
||||
&IGUIObject::ScriptEvent, EventName.LowerCase());
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Constructor / Destructor
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
CGUI::CGUI(const shared_ptr<ScriptRuntime>& runtime) : m_MouseButtons(0), m_FocusedObject(NULL), m_InternalNameNumber(0)
|
||||
CGUI::CGUI(const shared_ptr<ScriptRuntime>& runtime)
|
||||
: m_MouseButtons(0), m_FocusedObject(NULL), m_InternalNameNumber(0)
|
||||
{
|
||||
m_ScriptInterface.reset(new ScriptInterface("Engine", "GUIPage", runtime));
|
||||
GuiScriptingInit(*m_ScriptInterface);
|
||||
m_ScriptInterface->LoadGlobalScripts();
|
||||
m_BaseObject = new CGUIDummyObject;
|
||||
m_BaseObject->SetGUI(this);
|
||||
m_BaseObject->SetGUI(this);
|
||||
}
|
||||
|
||||
CGUI::~CGUI()
|
||||
@ -331,10 +319,7 @@ CGUI::~CGUI()
|
||||
delete m_BaseObject;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Functions
|
||||
//-------------------------------------------------------------------
|
||||
IGUIObject *CGUI::ConstructObject(const CStr& str)
|
||||
IGUIObject* CGUI::ConstructObject(const CStr& str)
|
||||
{
|
||||
if (m_ObjectTypes.count(str) > 0)
|
||||
return (*m_ObjectTypes[str])();
|
||||
@ -383,11 +368,7 @@ void CGUI::Draw()
|
||||
}
|
||||
}
|
||||
|
||||
void CGUI::DrawSprite(const CGUISpriteInstance& Sprite,
|
||||
int CellID,
|
||||
const float& Z,
|
||||
const CRect& Rect,
|
||||
const CRect& UNUSED(Clipping))
|
||||
void CGUI::DrawSprite(const CGUISpriteInstance& Sprite, int CellID, const float& Z, const CRect& Rect, const CRect& UNUSED(Clipping))
|
||||
{
|
||||
// If the sprite doesn't exist (name == ""), don't bother drawing anything
|
||||
if (Sprite.IsEmpty())
|
||||
@ -402,11 +383,11 @@ void CGUI::Destroy()
|
||||
{
|
||||
// We can use the map to delete all
|
||||
// now we don't want to cancel all if one Destroy fails
|
||||
for (map_pObjects::iterator it = m_pAllObjects.begin(); it != m_pAllObjects.end(); ++it)
|
||||
for (const std::pair<CStr, IGUIObject*>& p : m_pAllObjects)
|
||||
{
|
||||
try
|
||||
{
|
||||
it->second->Destroy();
|
||||
p.second->Destroy();
|
||||
}
|
||||
catch (PSERROR_GUI& e)
|
||||
{
|
||||
@ -415,13 +396,12 @@ void CGUI::Destroy()
|
||||
// TODO Gee: Handle
|
||||
}
|
||||
|
||||
delete it->second;
|
||||
delete p.second;
|
||||
}
|
||||
|
||||
// Clear all
|
||||
m_pAllObjects.clear();
|
||||
for(std::map<CStr, CGUISprite*>::iterator it = m_Sprites.begin(); it != m_Sprites.end(); ++it)
|
||||
delete it->second;
|
||||
|
||||
for (const std::pair<CStr, CGUISprite*>& p : m_Sprites)
|
||||
delete p.second;
|
||||
m_Sprites.clear();
|
||||
m_Icons.clear();
|
||||
}
|
||||
@ -429,7 +409,7 @@ void CGUI::Destroy()
|
||||
void CGUI::UpdateResolution()
|
||||
{
|
||||
// Update ALL cached
|
||||
GUI<>::RecurseObject(0, m_BaseObject, &IGUIObject::UpdateCachedSize );
|
||||
GUI<>::RecurseObject(0, m_BaseObject, &IGUIObject::UpdateCachedSize);
|
||||
}
|
||||
|
||||
void CGUI::AddObject(IGUIObject* pObject)
|
||||
@ -464,7 +444,7 @@ void CGUI::UpdateObjects()
|
||||
try
|
||||
{
|
||||
// Fill freshly
|
||||
GUI< map_pObjects >::RecurseObject(0, m_BaseObject, &IGUIObject::AddToPointersMap, AllObjects );
|
||||
GUI<map_pObjects>::RecurseObject(0, m_BaseObject, &IGUIObject::AddToPointersMap, AllObjects);
|
||||
}
|
||||
catch (PSERROR_GUI&)
|
||||
{
|
||||
@ -528,15 +508,15 @@ struct SGenerateTextImage
|
||||
|
||||
// Some help functions
|
||||
// TODO Gee: CRect => CPoint ?
|
||||
void SetupSpriteCall(const bool Left, SGUIText::SSpriteCall &SpriteCall,
|
||||
void SetupSpriteCall(const bool Left, SGUIText::SSpriteCall& SpriteCall,
|
||||
const float width, const float y,
|
||||
const CSize &Size, const CStr& TextureName,
|
||||
const CSize& Size, const CStr& TextureName,
|
||||
const float BufferZone, const int CellID)
|
||||
{
|
||||
// TODO Gee: Temp hardcoded values
|
||||
SpriteCall.m_Area.top = y+BufferZone;
|
||||
SpriteCall.m_Area.bottom = y+BufferZone + Size.cy;
|
||||
|
||||
|
||||
if (Left)
|
||||
{
|
||||
SpriteCall.m_Area.left = BufferZone;
|
||||
@ -557,27 +537,25 @@ struct SGenerateTextImage
|
||||
}
|
||||
};
|
||||
|
||||
SGUIText CGUI::GenerateText(const CGUIString &string,
|
||||
const CStrW& FontW, const float &Width, const float &BufferZone,
|
||||
const IGUIObject *pObject)
|
||||
SGUIText CGUI::GenerateText(const CGUIString& string, const CStrW& FontW, const float& Width, const float& BufferZone, const IGUIObject* pObject)
|
||||
{
|
||||
SGUIText Text; // object we're generating
|
||||
|
||||
CStrIntern Font(FontW.ToUTF8());
|
||||
|
||||
if (string.m_Words.size() == 0)
|
||||
if (string.m_Words.empty())
|
||||
return Text;
|
||||
|
||||
float x=BufferZone, y=BufferZone; // drawing pointer
|
||||
int from=0;
|
||||
bool done=false;
|
||||
float x = BufferZone, y = BufferZone; // drawing pointer
|
||||
int from = 0;
|
||||
bool done = false;
|
||||
|
||||
bool FirstLine = true; // Necessary because text in the first line is shorter
|
||||
// (it doesn't count the line spacing)
|
||||
|
||||
// Images on the left or the right side.
|
||||
std::vector<SGenerateTextImage> Images[2];
|
||||
int pos_last_img=-1; // Position in the string where last img (either left or right) were encountered.
|
||||
int pos_last_img = -1; // Position in the string where last img (either left or right) were encountered.
|
||||
// in order to avoid duplicate processing.
|
||||
|
||||
// Easier to read.
|
||||
@ -590,7 +568,7 @@ SGUIText CGUI::GenerateText(const CGUIString &string,
|
||||
GUI<EAlign>::GetSetting(pObject, "text_align", align);
|
||||
|
||||
// Go through string word by word
|
||||
for (int i=0; i<(int)string.m_Words.size()-1 && !done; ++i)
|
||||
for (int i = 0; i < (int)string.m_Words.size()-1 && !done; ++i)
|
||||
{
|
||||
// Pre-process each line one time, so we know which floating images
|
||||
// will be added for that line.
|
||||
@ -599,7 +577,7 @@ SGUIText CGUI::GenerateText(const CGUIString &string,
|
||||
CGUIString::SFeedback Feedback;
|
||||
|
||||
// Preliminary line_height, used for word-wrapping with floating images.
|
||||
float prelim_line_height=0.f;
|
||||
float prelim_line_height = 0.f;
|
||||
|
||||
// Width and height of all text calls generated.
|
||||
string.GenerateTextCall(this, Feedback, Font,
|
||||
@ -607,17 +585,15 @@ SGUIText CGUI::GenerateText(const CGUIString &string,
|
||||
FirstLine);
|
||||
|
||||
// Loop through our images queues, to see if images has been added.
|
||||
|
||||
|
||||
// Check if this has already been processed.
|
||||
// Also, floating images are only applicable if Word-Wrapping is on
|
||||
if (WordWrapping && i > pos_last_img)
|
||||
{
|
||||
// Loop left/right
|
||||
for (int j=0; j<2; ++j)
|
||||
for (int j = 0; j < 2; ++j)
|
||||
{
|
||||
for (std::vector<CStr>::const_iterator it = Feedback.m_Images[j].begin();
|
||||
it != Feedback.m_Images[j].end();
|
||||
++it)
|
||||
for (const CStr& imgname : Feedback.m_Images[j])
|
||||
{
|
||||
SGUIText::SSpriteCall SpriteCall;
|
||||
SGenerateTextImage Image;
|
||||
@ -628,13 +604,13 @@ SGUIText CGUI::GenerateText(const CGUIString &string,
|
||||
if (!Images[j].empty())
|
||||
_y = std::max(y, Images[j].back().m_YTo);
|
||||
else
|
||||
_y = y;
|
||||
_y = y;
|
||||
|
||||
// Get Size from Icon database
|
||||
SGUIIcon icon = GetIcon(*it);
|
||||
SGUIIcon icon = GetIcon(imgname);
|
||||
|
||||
CSize size = icon.m_Size;
|
||||
Image.SetupSpriteCall((j==CGUIString::SFeedback::Left), SpriteCall, Width, _y, size, icon.m_SpriteName, BufferZone, icon.m_CellID);
|
||||
Image.SetupSpriteCall((j == CGUIString::SFeedback::Left), SpriteCall, Width, _y, size, icon.m_SpriteName, BufferZone, icon.m_CellID);
|
||||
|
||||
// Check if image is the lowest thing.
|
||||
Text.m_Size.cy = std::max(Text.m_Size.cy, Image.m_YTo);
|
||||
@ -657,7 +633,7 @@ SGUIText CGUI::GenerateText(const CGUIString &string,
|
||||
int temp_from = from;
|
||||
from = i;
|
||||
|
||||
static const int From=0, To=1;
|
||||
static const int From = 0, To = 1;
|
||||
//int width_from=0, width_to=width;
|
||||
float width_range[2];
|
||||
width_range[From] = BufferZone;
|
||||
@ -674,26 +650,24 @@ SGUIText CGUI::GenerateText(const CGUIString &string,
|
||||
// structures his text in a stylistically pure fashion. Even if not, it
|
||||
// is still quite unlikely it will happen.
|
||||
// Loop through left and right side, from and to.
|
||||
for (int j=0; j<2; ++j)
|
||||
for (int j = 0; j < 2; ++j)
|
||||
{
|
||||
for (std::vector<SGenerateTextImage>::const_iterator it = Images[j].begin();
|
||||
it != Images[j].end();
|
||||
++it)
|
||||
for (const SGenerateTextImage& img : Images[j])
|
||||
{
|
||||
// We're working with two intervals here, the image's and the line height's.
|
||||
// let's find the union of these two.
|
||||
float union_from, union_to;
|
||||
|
||||
union_from = std::max(y, it->m_YFrom);
|
||||
union_to = std::min(y+prelim_line_height, it->m_YTo);
|
||||
|
||||
union_from = std::max(y, img.m_YFrom);
|
||||
union_to = std::min(y+prelim_line_height, img.m_YTo);
|
||||
|
||||
// The union is not empty
|
||||
if (union_to > union_from)
|
||||
{
|
||||
if (j == From)
|
||||
width_range[From] = std::max(width_range[From], it->m_Indentation);
|
||||
width_range[From] = std::max(width_range[From], img.m_Indentation);
|
||||
else
|
||||
width_range[To] = std::min(width_range[To], Width - it->m_Indentation);
|
||||
width_range[To] = std::min(width_range[To], Width - img.m_Indentation);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -709,9 +683,9 @@ SGUIText CGUI::GenerateText(const CGUIString &string,
|
||||
// because it didn't regard images, so we don't know
|
||||
// if all characters processed, will actually be involved
|
||||
// in that line.
|
||||
float line_height=0.f;
|
||||
float line_width=0.f;
|
||||
for (int j=temp_from; j<=i; ++j)
|
||||
float line_height = 0.f;
|
||||
float line_width = 0.f;
|
||||
for (int j = temp_from; j <= i; ++j)
|
||||
{
|
||||
// We don't want to use Feedback now, so we'll have to use
|
||||
// another.
|
||||
@ -766,7 +740,7 @@ SGUIText CGUI::GenerateText(const CGUIString &string,
|
||||
y += line_height;
|
||||
|
||||
// Do the real processing now
|
||||
for (int j=temp_from; j<=i; ++j)
|
||||
for (int j = temp_from; j <= i; ++j)
|
||||
{
|
||||
// We don't want to use Feedback now, so we'll have to use
|
||||
// another one.
|
||||
@ -774,26 +748,23 @@ SGUIText CGUI::GenerateText(const CGUIString &string,
|
||||
|
||||
// Defaults
|
||||
string.GenerateTextCall(this, Feedback2, Font,
|
||||
string.m_Words[j], string.m_Words[j+1],
|
||||
string.m_Words[j], string.m_Words[j+1],
|
||||
FirstLine, pObject);
|
||||
|
||||
// Iterate all and set X/Y values
|
||||
// Since X values are not set, we need to make an internal
|
||||
// iteration with an increment that will append the internal
|
||||
// x, that is what x_pointer is for.
|
||||
float x_pointer=0.f;
|
||||
float x_pointer = 0.f;
|
||||
|
||||
std::vector<SGUIText::STextCall>::iterator it;
|
||||
for (it = Feedback2.m_TextCalls.begin(); it != Feedback2.m_TextCalls.end(); ++it)
|
||||
for (SGUIText::STextCall& tc : Feedback2.m_TextCalls)
|
||||
{
|
||||
it->m_Pos = CPos(dx + x + x_pointer, y);
|
||||
tc.m_Pos = CPos(dx + x + x_pointer, y);
|
||||
|
||||
x_pointer += it->m_Size.cx;
|
||||
x_pointer += tc.m_Size.cx;
|
||||
|
||||
if (it->m_pSpriteCall)
|
||||
{
|
||||
it->m_pSpriteCall->m_Area += it->m_Pos - CSize(0,it->m_pSpriteCall->m_Area.GetHeight());
|
||||
}
|
||||
if (tc.m_pSpriteCall)
|
||||
tc.m_pSpriteCall->m_Area += tc.m_Pos - CSize(0, tc.m_pSpriteCall->m_Area.GetHeight());
|
||||
}
|
||||
|
||||
// Append X value.
|
||||
@ -815,14 +786,12 @@ SGUIText CGUI::GenerateText(const CGUIString &string,
|
||||
Text.m_SpriteCalls.insert(Text.m_SpriteCalls.end(), Feedback2.m_SpriteCalls.begin(), Feedback2.m_SpriteCalls.end());
|
||||
break;
|
||||
}
|
||||
else
|
||||
if (x > width_range[To] && j==temp_from)
|
||||
else if (x > width_range[To] && j == temp_from)
|
||||
{
|
||||
from = j+1;
|
||||
// do not break, since we want it to be added to m_TextCalls
|
||||
}
|
||||
else
|
||||
if (x > width_range[To])
|
||||
else if (x > width_range[To])
|
||||
{
|
||||
from = j;
|
||||
break;
|
||||
@ -856,8 +825,7 @@ SGUIText CGUI::GenerateText(const CGUIString &string,
|
||||
return Text;
|
||||
}
|
||||
|
||||
void CGUI::DrawText(SGUIText &Text, const CColor &DefaultColor,
|
||||
const CPos &pos, const float &z, const CRect &clipping)
|
||||
void CGUI::DrawText(SGUIText& Text, const CColor& DefaultColor, const CPos& pos, const float& z, const CRect& clipping)
|
||||
{
|
||||
CShaderTechniquePtr tech = g_Renderer.GetShaderManager().LoadEffect(str_gui_text);
|
||||
|
||||
@ -878,29 +846,23 @@ void CGUI::DrawText(SGUIText &Text, const CColor &DefaultColor,
|
||||
textRenderer.SetClippingRect(clipping);
|
||||
textRenderer.Translate(0.0f, 0.0f, z);
|
||||
|
||||
for (std::vector<SGUIText::STextCall>::const_iterator it = Text.m_TextCalls.begin();
|
||||
it != Text.m_TextCalls.end();
|
||||
++it)
|
||||
for (const SGUIText::STextCall& tc : Text.m_TextCalls)
|
||||
{
|
||||
// If this is just a placeholder for a sprite call, continue
|
||||
if (it->m_pSpriteCall)
|
||||
if (tc.m_pSpriteCall)
|
||||
continue;
|
||||
|
||||
CColor color = it->m_UseCustomColor ? it->m_Color : DefaultColor;
|
||||
CColor color = tc.m_UseCustomColor ? tc.m_Color : DefaultColor;
|
||||
|
||||
textRenderer.Color(color);
|
||||
textRenderer.Font(it->m_Font);
|
||||
textRenderer.Put((float)(int)(pos.x+it->m_Pos.x), (float)(int)(pos.y+it->m_Pos.y), &it->m_String);
|
||||
textRenderer.Font(tc.m_Font);
|
||||
textRenderer.Put((float)(int)(pos.x + tc.m_Pos.x), (float)(int)(pos.y + tc.m_Pos.y), &tc.m_String);
|
||||
}
|
||||
|
||||
textRenderer.Render();
|
||||
|
||||
for (std::list<SGUIText::SSpriteCall>::iterator it=Text.m_SpriteCalls.begin();
|
||||
it!=Text.m_SpriteCalls.end();
|
||||
++it)
|
||||
{
|
||||
DrawSprite(it->m_Sprite, it->m_CellID, z, it->m_Area + pos);
|
||||
}
|
||||
for (const SGUIText::SSpriteCall& sc : Text.m_SpriteCalls)
|
||||
DrawSprite(sc.m_Sprite, sc.m_CellID, z, sc.m_Area + pos);
|
||||
|
||||
if (isClipped)
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
@ -908,17 +870,14 @@ void CGUI::DrawText(SGUIText &Text, const CColor &DefaultColor,
|
||||
tech->EndPass();
|
||||
}
|
||||
|
||||
bool CGUI::GetPreDefinedColor(const CStr& name, CColor &Output)
|
||||
bool CGUI::GetPreDefinedColor(const CStr& name, CColor& Output) const
|
||||
{
|
||||
if (m_PreDefinedColors.count(name) == 0)
|
||||
{
|
||||
std::map<CStr, CColor>::const_iterator cit = m_PreDefinedColors.find(name);
|
||||
if (cit == m_PreDefinedColors.end())
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Output = m_PreDefinedColors[name];
|
||||
return true;
|
||||
}
|
||||
|
||||
Output = cit->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -941,7 +900,6 @@ void CGUI::LoadXmlFile(const VfsPath& Filename, boost::unordered_set<VfsPath>& P
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
if (root_name == "objects")
|
||||
{
|
||||
Xeromyces_ReadRootObjects(node, &XeroFile, Paths);
|
||||
@ -949,26 +907,14 @@ void CGUI::LoadXmlFile(const VfsPath& Filename, boost::unordered_set<VfsPath>& P
|
||||
// Re-cache all values so these gets cached too.
|
||||
//UpdateResolution();
|
||||
}
|
||||
else
|
||||
if (root_name == "sprites")
|
||||
{
|
||||
else if (root_name == "sprites")
|
||||
Xeromyces_ReadRootSprites(node, &XeroFile);
|
||||
}
|
||||
else
|
||||
if (root_name == "styles")
|
||||
{
|
||||
else if (root_name == "styles")
|
||||
Xeromyces_ReadRootStyles(node, &XeroFile);
|
||||
}
|
||||
else
|
||||
if (root_name == "setup")
|
||||
{
|
||||
else if (root_name == "setup")
|
||||
Xeromyces_ReadRootSetup(node, &XeroFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
debug_warn(L"CGUI::LoadXmlFile error");
|
||||
// TODO Gee: Output in log
|
||||
}
|
||||
}
|
||||
catch (PSERROR_GUI& e)
|
||||
{
|
||||
@ -1029,42 +975,29 @@ void CGUI::Xeromyces_ReadRootSetup(XMBElement Element, CXeromyces* pFile)
|
||||
CStr name(pFile->GetElementString(child.GetNodeName()));
|
||||
|
||||
if (name == "scrollbar")
|
||||
{
|
||||
Xeromyces_ReadScrollBarStyle(child, pFile);
|
||||
}
|
||||
else
|
||||
if (name == "icon")
|
||||
{
|
||||
else if (name == "icon")
|
||||
Xeromyces_ReadIcon(child, pFile);
|
||||
}
|
||||
else
|
||||
if (name == "tooltip")
|
||||
{
|
||||
else if (name == "tooltip")
|
||||
Xeromyces_ReadTooltip(child, pFile);
|
||||
}
|
||||
else
|
||||
if (name == "color")
|
||||
{
|
||||
else if (name == "color")
|
||||
Xeromyces_ReadColor(child, pFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
debug_warn(L"Invalid data - DTD shouldn't allow this");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObject *pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, boost::unordered_set<VfsPath>& Paths, u32 nesting_depth)
|
||||
void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObject* pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, boost::unordered_set<VfsPath>& Paths, u32 nesting_depth)
|
||||
{
|
||||
ENSURE(pParent);
|
||||
|
||||
// Our object we are going to create
|
||||
IGUIObject *object = NULL;
|
||||
IGUIObject* object = NULL;
|
||||
|
||||
XMBAttributeList attributes = Element.GetAttributes();
|
||||
|
||||
// Well first of all we need to determine the type
|
||||
CStr type (attributes.GetNamedItem(pFile->GetAttributeID("type")));
|
||||
CStr type(attributes.GetNamedItem(pFile->GetAttributeID("type")));
|
||||
if (type.empty())
|
||||
type = "empty";
|
||||
|
||||
@ -1150,8 +1083,8 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
|
||||
CStr name(attr.Value);
|
||||
|
||||
// Apply the requested substitutions
|
||||
for (size_t j = 0; j < NameSubst.size(); ++j)
|
||||
name.Replace(NameSubst[j].first, NameSubst[j].second);
|
||||
for (const std::pair<CStr, CStr>& sub : NameSubst)
|
||||
name.Replace(sub.first, sub.second);
|
||||
|
||||
object->SetName(name);
|
||||
NameSet = true;
|
||||
@ -1377,7 +1310,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
|
||||
if (!object->HandleAdditionalChildren(child, pFile))
|
||||
LOGERROR("GUI: (object: %s) Reading unknown children for its type", object->GetPresentableName().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Check if Z wasn't manually set
|
||||
@ -1415,7 +1348,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
|
||||
}
|
||||
}
|
||||
|
||||
void CGUI::Xeromyces_ReadRepeat(XMBElement Element, CXeromyces* pFile, IGUIObject *pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, boost::unordered_set<VfsPath>& Paths, u32 nesting_depth)
|
||||
void CGUI::Xeromyces_ReadRepeat(XMBElement Element, CXeromyces* pFile, IGUIObject* pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, boost::unordered_set<VfsPath>& Paths, u32 nesting_depth)
|
||||
{
|
||||
#define ELMT(x) int elmt_##x = pFile->GetElementID(#x)
|
||||
#define ATTR(x) int attr_##x = pFile->GetAttributeID(#x)
|
||||
@ -1432,7 +1365,7 @@ void CGUI::Xeromyces_ReadRepeat(XMBElement Element, CXeromyces* pFile, IGUIObjec
|
||||
|
||||
for (int n = 0; n < count; ++n)
|
||||
{
|
||||
NameSubst.push_back(std::make_pair(var, "[" + CStr::FromInt(n) + "]"));
|
||||
NameSubst.emplace_back(var, "[" + CStr::FromInt(n) + "]");
|
||||
|
||||
XERO_ITER_EL(Element, child)
|
||||
{
|
||||
@ -1448,7 +1381,7 @@ void CGUI::Xeromyces_ReadRepeat(XMBElement Element, CXeromyces* pFile, IGUIObjec
|
||||
void CGUI::Xeromyces_ReadScript(XMBElement Element, CXeromyces* pFile, boost::unordered_set<VfsPath>& Paths)
|
||||
{
|
||||
// Check for a 'file' parameter
|
||||
CStrW file(Element.GetAttributes().GetNamedItem( pFile->GetAttributeID("file") ).FromUTF8());
|
||||
CStrW file(Element.GetAttributes().GetNamedItem(pFile->GetAttributeID("file")).FromUTF8());
|
||||
|
||||
// If there is a file specified, open and execute it
|
||||
if (!file.empty())
|
||||
@ -1465,7 +1398,7 @@ void CGUI::Xeromyces_ReadScript(XMBElement Element, CXeromyces* pFile, boost::un
|
||||
}
|
||||
|
||||
// If it has a directory attribute, read all JS files in that directory
|
||||
CStrW directory(Element.GetAttributes().GetNamedItem( pFile->GetAttributeID("directory") ).FromUTF8());
|
||||
CStrW directory(Element.GetAttributes().GetNamedItem(pFile->GetAttributeID("directory")).FromUTF8());
|
||||
if (!directory.empty())
|
||||
{
|
||||
VfsPaths pathnames;
|
||||
@ -1504,7 +1437,7 @@ void CGUI::Xeromyces_ReadSprite(XMBElement Element, CXeromyces* pFile)
|
||||
{
|
||||
// Sprite object we're adding
|
||||
CGUISprite* Sprite = new CGUISprite;
|
||||
|
||||
|
||||
// and what will be its reference name
|
||||
CStr name;
|
||||
|
||||
@ -1513,7 +1446,7 @@ void CGUI::Xeromyces_ReadSprite(XMBElement Element, CXeromyces* pFile)
|
||||
//
|
||||
|
||||
// Get name, we know it exists because of DTD requirements
|
||||
name = Element.GetAttributes().GetNamedItem( pFile->GetAttributeID("name") );
|
||||
name = Element.GetAttributes().GetNamedItem(pFile->GetAttributeID("name"));
|
||||
|
||||
if (m_Sprites.find(name) != m_Sprites.end())
|
||||
LOGWARNING("GUI sprite name '%s' used more than once; first definition will be discarded", name.c_str());
|
||||
@ -1553,9 +1486,9 @@ void CGUI::Xeromyces_ReadSprite(XMBElement Element, CXeromyces* pFile)
|
||||
// Apply the effects to every image (unless the image overrides it with
|
||||
// different effects)
|
||||
if (effects)
|
||||
for (std::vector<SGUIImage*>::iterator it = Sprite->m_Images.begin(); it != Sprite->m_Images.end(); ++it)
|
||||
if (!(*it)->m_Effects)
|
||||
(*it)->m_Effects = new SGUIImageEffects(*effects); // do a copy just so it can be deleted correctly later
|
||||
for (SGUIImage* const& img : Sprite->m_Images)
|
||||
if (!img->m_Effects)
|
||||
img->m_Effects = new SGUIImageEffects(*effects); // do a copy just so it can be deleted correctly later
|
||||
|
||||
delete effects;
|
||||
|
||||
@ -1566,16 +1499,16 @@ void CGUI::Xeromyces_ReadSprite(XMBElement Element, CXeromyces* pFile)
|
||||
m_Sprites[name] = Sprite;
|
||||
}
|
||||
|
||||
void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite &parent)
|
||||
void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite& parent)
|
||||
{
|
||||
|
||||
// Image object we're adding
|
||||
SGUIImage* Image = new SGUIImage;
|
||||
|
||||
|
||||
// Set defaults to "0 0 100% 100%"
|
||||
Image->m_TextureSize = CClientArea(CRect(0, 0, 0, 0), CRect(0, 0, 100, 100));
|
||||
Image->m_Size = CClientArea(CRect(0, 0, 0, 0), CRect(0, 0, 100, 100));
|
||||
|
||||
|
||||
// TODO Gee: Setup defaults here (or maybe they are in the SGUIImage ctor)
|
||||
|
||||
//
|
||||
@ -1592,56 +1525,55 @@ void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite
|
||||
{
|
||||
Image->m_TextureName = VfsPath("art/textures/ui") / attr_value;
|
||||
}
|
||||
else
|
||||
if (attr_name == "size")
|
||||
else if (attr_name == "size")
|
||||
{
|
||||
CClientArea ca;
|
||||
if (!GUI<CClientArea>::ParseString(attr_value, ca))
|
||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
|
||||
else Image->m_Size = ca;
|
||||
else
|
||||
Image->m_Size = ca;
|
||||
}
|
||||
else
|
||||
if (attr_name == "texture_size")
|
||||
else if (attr_name == "texture_size")
|
||||
{
|
||||
CClientArea ca;
|
||||
if (!GUI<CClientArea>::ParseString(attr_value, ca))
|
||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
|
||||
else Image->m_TextureSize = ca;
|
||||
else
|
||||
Image->m_TextureSize = ca;
|
||||
}
|
||||
else
|
||||
if (attr_name == "real_texture_placement")
|
||||
else if (attr_name == "real_texture_placement")
|
||||
{
|
||||
CRect rect;
|
||||
if (!GUI<CRect>::ParseString(attr_value, rect))
|
||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
|
||||
else Image->m_TexturePlacementInFile = rect;
|
||||
else
|
||||
Image->m_TexturePlacementInFile = rect;
|
||||
}
|
||||
else
|
||||
if (attr_name == "cell_size")
|
||||
else if (attr_name == "cell_size")
|
||||
{
|
||||
CSize size;
|
||||
if (!GUI<CSize>::ParseString(attr_value, size))
|
||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
|
||||
else Image->m_CellSize = size;
|
||||
else
|
||||
Image->m_CellSize = size;
|
||||
}
|
||||
else
|
||||
if (attr_name == "fixed_h_aspect_ratio")
|
||||
else if (attr_name == "fixed_h_aspect_ratio")
|
||||
{
|
||||
float val;
|
||||
if (!GUI<float>::ParseString(attr_value, val))
|
||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
|
||||
else Image->m_FixedHAspectRatio = val;
|
||||
else
|
||||
Image->m_FixedHAspectRatio = val;
|
||||
}
|
||||
else
|
||||
if (attr_name == "round_coordinates")
|
||||
else if (attr_name == "round_coordinates")
|
||||
{
|
||||
bool b;
|
||||
if (!GUI<bool>::ParseString(attr_value, b))
|
||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
|
||||
else Image->m_RoundCoordinates = b;
|
||||
else
|
||||
Image->m_RoundCoordinates = b;
|
||||
}
|
||||
else
|
||||
if (attr_name == "wrap_mode")
|
||||
else if (attr_name == "wrap_mode")
|
||||
{
|
||||
if (attr_value == L"repeat")
|
||||
Image->m_WrapMode = GL_REPEAT;
|
||||
@ -1652,37 +1584,37 @@ void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite
|
||||
else
|
||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
|
||||
}
|
||||
else
|
||||
if (attr_name == "z_level")
|
||||
else if (attr_name == "z_level")
|
||||
{
|
||||
float z_level;
|
||||
if (!GUI<float>::ParseString(attr_value, z_level))
|
||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
|
||||
else Image->m_DeltaZ = z_level/100.f;
|
||||
else
|
||||
Image->m_DeltaZ = z_level/100.f;
|
||||
}
|
||||
else
|
||||
if (attr_name == "backcolor")
|
||||
else if (attr_name == "backcolor")
|
||||
{
|
||||
CColor color;
|
||||
if (!GUI<CColor>::ParseString(attr_value, color))
|
||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
|
||||
else Image->m_BackColor = color;
|
||||
else
|
||||
Image->m_BackColor = color;
|
||||
}
|
||||
else
|
||||
if (attr_name == "bordercolor")
|
||||
else if (attr_name == "bordercolor")
|
||||
{
|
||||
CColor color;
|
||||
if (!GUI<CColor>::ParseString(attr_value, color))
|
||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
|
||||
else Image->m_BorderColor = color;
|
||||
else
|
||||
Image->m_BorderColor = color;
|
||||
}
|
||||
else
|
||||
if (attr_name == "border")
|
||||
else if (attr_name == "border")
|
||||
{
|
||||
bool b;
|
||||
if (!GUI<bool>::ParseString(attr_value, b))
|
||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
|
||||
else Image->m_Border = b;
|
||||
else
|
||||
Image->m_Border = b;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1719,7 +1651,7 @@ void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite
|
||||
parent.AddImage(Image);
|
||||
}
|
||||
|
||||
void CGUI::Xeromyces_ReadEffects(XMBElement Element, CXeromyces* pFile, SGUIImageEffects &effects)
|
||||
void CGUI::Xeromyces_ReadEffects(XMBElement Element, CXeromyces* pFile, SGUIImageEffects& effects)
|
||||
{
|
||||
for (XMBAttribute attr : Element.GetAttributes())
|
||||
{
|
||||
@ -1794,15 +1726,14 @@ void CGUI::Xeromyces_ReadScrollBarStyle(XMBElement Element, CXeromyces* pFile)
|
||||
for (XMBAttribute attr : Element.GetAttributes())
|
||||
{
|
||||
CStr attr_name = pFile->GetAttributeString(attr.Name);
|
||||
CStr attr_value(attr.Value);
|
||||
CStr attr_value(attr.Value);
|
||||
|
||||
if (attr_value == "null")
|
||||
continue;
|
||||
|
||||
if (attr_name == "name")
|
||||
name = attr_value;
|
||||
else
|
||||
if (attr_name == "show_edge_buttons")
|
||||
else if (attr_name == "show_edge_buttons")
|
||||
{
|
||||
bool b;
|
||||
if (!GUI<bool>::ParseString(attr_value.FromUTF8(), b))
|
||||
@ -1810,7 +1741,7 @@ void CGUI::Xeromyces_ReadScrollBarStyle(XMBElement Element, CXeromyces* pFile)
|
||||
else
|
||||
scrollbar.m_UseEdgeButtons = b;
|
||||
}
|
||||
if (attr_name == "width")
|
||||
else if (attr_name == "width")
|
||||
{
|
||||
float f;
|
||||
if (!GUI<float>::ParseString(attr_value.FromUTF8(), f))
|
||||
@ -1818,8 +1749,7 @@ void CGUI::Xeromyces_ReadScrollBarStyle(XMBElement Element, CXeromyces* pFile)
|
||||
else
|
||||
scrollbar.m_Width = f;
|
||||
}
|
||||
else
|
||||
if (attr_name == "minimum_bar_size")
|
||||
else if (attr_name == "minimum_bar_size")
|
||||
{
|
||||
float f;
|
||||
if (!GUI<float>::ParseString(attr_value.FromUTF8(), f))
|
||||
@ -1827,8 +1757,7 @@ void CGUI::Xeromyces_ReadScrollBarStyle(XMBElement Element, CXeromyces* pFile)
|
||||
else
|
||||
scrollbar.m_MinimumBarSize = f;
|
||||
}
|
||||
else
|
||||
if (attr_name == "maximum_bar_size")
|
||||
else if (attr_name == "maximum_bar_size")
|
||||
{
|
||||
float f;
|
||||
if (!GUI<float>::ParseString(attr_value.FromUTF8(), f))
|
||||
@ -1836,46 +1765,34 @@ void CGUI::Xeromyces_ReadScrollBarStyle(XMBElement Element, CXeromyces* pFile)
|
||||
else
|
||||
scrollbar.m_MaximumBarSize = f;
|
||||
}
|
||||
else
|
||||
if (attr_name == "sprite_button_top")
|
||||
else if (attr_name == "sprite_button_top")
|
||||
scrollbar.m_SpriteButtonTop = attr_value;
|
||||
else
|
||||
if (attr_name == "sprite_button_top_pressed")
|
||||
else if (attr_name == "sprite_button_top_pressed")
|
||||
scrollbar.m_SpriteButtonTopPressed = attr_value;
|
||||
else
|
||||
if (attr_name == "sprite_button_top_disabled")
|
||||
else if (attr_name == "sprite_button_top_disabled")
|
||||
scrollbar.m_SpriteButtonTopDisabled = attr_value;
|
||||
else
|
||||
if (attr_name == "sprite_button_top_over")
|
||||
else if (attr_name == "sprite_button_top_over")
|
||||
scrollbar.m_SpriteButtonTopOver = attr_value;
|
||||
else
|
||||
if (attr_name == "sprite_button_bottom")
|
||||
else if (attr_name == "sprite_button_bottom")
|
||||
scrollbar.m_SpriteButtonBottom = attr_value;
|
||||
else
|
||||
if (attr_name == "sprite_button_bottom_pressed")
|
||||
else if (attr_name == "sprite_button_bottom_pressed")
|
||||
scrollbar.m_SpriteButtonBottomPressed = attr_value;
|
||||
else
|
||||
if (attr_name == "sprite_button_bottom_disabled")
|
||||
else if (attr_name == "sprite_button_bottom_disabled")
|
||||
scrollbar.m_SpriteButtonBottomDisabled = attr_value;
|
||||
else
|
||||
if (attr_name == "sprite_button_bottom_over")
|
||||
else if (attr_name == "sprite_button_bottom_over")
|
||||
scrollbar.m_SpriteButtonBottomOver = attr_value;
|
||||
else
|
||||
if (attr_name == "sprite_back_vertical")
|
||||
else if (attr_name == "sprite_back_vertical")
|
||||
scrollbar.m_SpriteBackVertical = attr_value;
|
||||
else
|
||||
if (attr_name == "sprite_bar_vertical")
|
||||
else if (attr_name == "sprite_bar_vertical")
|
||||
scrollbar.m_SpriteBarVertical = attr_value;
|
||||
else
|
||||
if (attr_name == "sprite_bar_vertical_over")
|
||||
else if (attr_name == "sprite_bar_vertical_over")
|
||||
scrollbar.m_SpriteBarVerticalOver = attr_value;
|
||||
else
|
||||
if (attr_name == "sprite_bar_vertical_pressed")
|
||||
else if (attr_name == "sprite_bar_vertical_pressed")
|
||||
scrollbar.m_SpriteBarVerticalPressed = attr_value;
|
||||
}
|
||||
|
||||
//
|
||||
// Add to CGUI
|
||||
// Add to CGUI
|
||||
//
|
||||
|
||||
m_ScrollBarStyles[name] = scrollbar;
|
||||
@ -1951,23 +1868,21 @@ void CGUI::Xeromyces_ReadColor(XMBElement Element, CXeromyces* pFile)
|
||||
|
||||
XMBAttributeList attributes = Element.GetAttributes();
|
||||
|
||||
//IGUIObject* object = new CTooltip;
|
||||
CColor color;
|
||||
CStr name = attributes.GetNamedItem(pFile->GetAttributeID("name"));
|
||||
|
||||
// Try parsing value
|
||||
// Try parsing value
|
||||
CStr value(Element.GetText());
|
||||
if (!value.empty())
|
||||
if (value.empty())
|
||||
return;
|
||||
|
||||
// Try setting color to value
|
||||
if (!color.ParseString(value))
|
||||
{
|
||||
// Try setting color to value
|
||||
if (!color.ParseString(value))
|
||||
{
|
||||
LOGERROR("GUI: Unable to create custom color '%s'. Invalid color syntax.", name.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
// input color
|
||||
m_PreDefinedColors[name] = color;
|
||||
}
|
||||
LOGERROR("GUI: Unable to create custom color '%s'. Invalid color syntax.", name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
// input color
|
||||
m_PreDefinedColors[name] = color;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2014 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -32,48 +32,23 @@ CGUI
|
||||
#ifndef INCLUDED_CGUI
|
||||
#define INCLUDED_CGUI
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Includes / Compiler directives
|
||||
//--------------------------------------------------------
|
||||
// NOTE: GUI.h included at the bottom of this file (has to be after CGUI class
|
||||
// definition)
|
||||
|
||||
#include "GUITooltip.h"
|
||||
#include "GUIbase.h"
|
||||
#include "scriptinterface/ScriptInterface.h"
|
||||
|
||||
#include "ps/Shapes.h"
|
||||
|
||||
#include "lib/input.h"
|
||||
|
||||
#include "ps/Shapes.h"
|
||||
#include "ps/XML/Xeromyces.h"
|
||||
#include "scriptinterface/ScriptInterface.h"
|
||||
|
||||
#include <boost/unordered_set.hpp>
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Macros
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Types
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Error declarations
|
||||
//--------------------------------------------------------
|
||||
|
||||
ERROR_TYPE(GUI, JSOpenFailed);
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Declarations
|
||||
//--------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Contains a list of values for new defaults to objects.
|
||||
*/
|
||||
struct SGUIStyle
|
||||
{
|
||||
// A list of defaults for
|
||||
std::map<CStr, CStrW> m_SettingsDefaults;
|
||||
};
|
||||
|
||||
@ -98,7 +73,7 @@ class GUITooltip;
|
||||
class CGUI
|
||||
{
|
||||
NONCOPYABLE(CGUI);
|
||||
|
||||
|
||||
friend class IGUIObject;
|
||||
friend class IGUIScrollBarOwner;
|
||||
friend class CInternalCGUIAccessorBase;
|
||||
@ -115,7 +90,7 @@ public:
|
||||
* Initializes the GUI, needs to be called before the GUI is used
|
||||
*/
|
||||
void Initialize();
|
||||
|
||||
|
||||
/**
|
||||
* Performs processing that should happen every frame
|
||||
* (including sending the "Tick" event to scripts)
|
||||
@ -145,8 +120,7 @@ public:
|
||||
* @param Rect Position and Size
|
||||
* @param Clipping The sprite shouldn't be drawn outside this rectangle
|
||||
*/
|
||||
void DrawSprite(const CGUISpriteInstance& Sprite, int CellID, const float &Z,
|
||||
const CRect &Rect, const CRect &Clipping=CRect());
|
||||
void DrawSprite(const CGUISpriteInstance& Sprite, int CellID, const float& Z, const CRect& Rect, const CRect& Clipping = CRect());
|
||||
|
||||
/**
|
||||
* Draw a SGUIText object
|
||||
@ -157,8 +131,7 @@ public:
|
||||
* @param z z value.
|
||||
* @param clipping
|
||||
*/
|
||||
void DrawText(SGUIText &Text, const CColor &DefaultColor,
|
||||
const CPos &pos, const float &z, const CRect &clipping);
|
||||
void DrawText(SGUIText& Text, const CColor& DefaultColor, const CPos& pos, const float& z, const CRect& clipping);
|
||||
|
||||
/**
|
||||
* Clean up, call this to clean up all memory allocated
|
||||
@ -211,7 +184,7 @@ public:
|
||||
* The GUI needs to have all object types inputted and
|
||||
* their constructors. Also it needs to associate a type
|
||||
* by a string name of the type.
|
||||
*
|
||||
*
|
||||
* To add a type:
|
||||
* @code
|
||||
* AddObjectType("button", &CButton::ConstructObject);
|
||||
@ -242,19 +215,17 @@ public:
|
||||
* will be sent to the Renderer. Also, horizontal alignment
|
||||
* is taken into acount in this method but NOT vertical alignment.
|
||||
*
|
||||
* Done through the CGUI since it can communicate with
|
||||
* Done through the CGUI since it can communicate with
|
||||
*
|
||||
* @param Text Text to generate SGUIText object from
|
||||
* @param Font Default font, notice both Default color and default font
|
||||
* can be changed by tags.
|
||||
* @param Width Width, 0 if no word-wrapping.
|
||||
* @param BufferZone space between text and edge, and space between text and images.
|
||||
* @param pObject Optional parameter for error output. Used *only* if error parsing fails,
|
||||
* and we need to be able to output which object the error occured in to aid the user.
|
||||
* @param pObject Optional parameter for error output. Used *only* if error parsing fails,
|
||||
* and we need to be able to output which object the error occured in to aid the user.
|
||||
*/
|
||||
SGUIText GenerateText(const CGUIString &Text, const CStrW& Font,
|
||||
const float &Width, const float &BufferZone,
|
||||
const IGUIObject *pObject=NULL);
|
||||
SGUIText GenerateText(const CGUIString& Text, const CStrW& Font, const float& Width, const float& BufferZone, const IGUIObject* pObject = NULL);
|
||||
|
||||
|
||||
/**
|
||||
@ -271,8 +242,8 @@ public:
|
||||
* Get pre-defined color (if it exists)
|
||||
* Returns false if it fails.
|
||||
*/
|
||||
bool GetPreDefinedColor(const CStr& name, CColor &Output);
|
||||
|
||||
bool GetPreDefinedColor(const CStr& name, CColor& Output) const;
|
||||
|
||||
shared_ptr<ScriptInterface> GetScriptInterface() { return m_ScriptInterface; };
|
||||
jsval GetGlobalObject() { return m_ScriptInterface->GetGlobalObject(); };
|
||||
|
||||
@ -291,7 +262,7 @@ private:
|
||||
|
||||
/**
|
||||
* Adds an object to the GUI's object database
|
||||
* Private, since you can only add objects through
|
||||
* Private, since you can only add objects through
|
||||
* XML files. Why? Because it enables the GUI to
|
||||
* be much more encapsulated and safe.
|
||||
*
|
||||
@ -307,12 +278,12 @@ private:
|
||||
* @param str Name of object type
|
||||
* @return Newly constructed IGUIObject (but constructed as a subclass)
|
||||
*/
|
||||
IGUIObject *ConstructObject(const CStr& str);
|
||||
IGUIObject* ConstructObject(const CStr& str);
|
||||
|
||||
/**
|
||||
* Get Focused Object.
|
||||
*/
|
||||
IGUIObject *GetFocusedObject() { return m_FocusedObject; }
|
||||
IGUIObject* GetFocusedObject() { return m_FocusedObject; }
|
||||
|
||||
public:
|
||||
/**
|
||||
@ -444,7 +415,7 @@ private:
|
||||
*
|
||||
* @see LoadXmlFile()
|
||||
*/
|
||||
void Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObject *pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, boost::unordered_set<VfsPath>& Paths, u32 nesting_depth);
|
||||
void Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObject* pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, boost::unordered_set<VfsPath>& Paths, u32 nesting_depth);
|
||||
|
||||
/**
|
||||
* Reads in the element \<repeat\>, which repeats its child \<object\>s
|
||||
@ -452,7 +423,7 @@ private:
|
||||
* 'var' enclosed in square brackets) in its descendants' names with "[0]",
|
||||
* "[1]", etc.
|
||||
*/
|
||||
void Xeromyces_ReadRepeat(XMBElement Element, CXeromyces* pFile, IGUIObject *pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, boost::unordered_set<VfsPath>& Paths, u32 nesting_depth);
|
||||
void Xeromyces_ReadRepeat(XMBElement Element, CXeromyces* pFile, IGUIObject* pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, boost::unordered_set<VfsPath>& Paths, u32 nesting_depth);
|
||||
|
||||
/**
|
||||
* Reads in the element \<script\> (the XMBElement) and executes
|
||||
@ -490,7 +461,7 @@ private:
|
||||
*
|
||||
* @see LoadXmlFile()
|
||||
*/
|
||||
void Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite &parent);
|
||||
void Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite& parent);
|
||||
|
||||
/**
|
||||
* Reads in the element \<effect\> (the XMBElement) and stores the
|
||||
@ -503,7 +474,7 @@ private:
|
||||
*
|
||||
* @see LoadXmlFile()
|
||||
*/
|
||||
void Xeromyces_ReadEffects(XMBElement Element, CXeromyces* pFile, SGUIImageEffects &effects);
|
||||
void Xeromyces_ReadEffects(XMBElement Element, CXeromyces* pFile, SGUIImageEffects& effects);
|
||||
|
||||
/**
|
||||
* Reads in the element \<style\> (the XMBElement) and stores the
|
||||
@ -540,7 +511,7 @@ private:
|
||||
* @see LoadXmlFile()
|
||||
*/
|
||||
void Xeromyces_ReadIcon(XMBElement Element, CXeromyces* pFile);
|
||||
|
||||
|
||||
/**
|
||||
* Reads in the element \<tooltip\> (the XMBElement) and stores the
|
||||
* result as an object with the name __tooltip_#.
|
||||
@ -575,11 +546,11 @@ private:
|
||||
/** @name Miscellaneous */
|
||||
//--------------------------------------------------------
|
||||
//@{
|
||||
|
||||
|
||||
shared_ptr<ScriptInterface> m_ScriptInterface;
|
||||
|
||||
/**
|
||||
* don't want to pass this around with the
|
||||
* don't want to pass this around with the
|
||||
* ChooseMouseOverAndClosest broadcast -
|
||||
* we'd need to pack this and pNearest in a struct
|
||||
*/
|
||||
@ -621,7 +592,7 @@ private:
|
||||
*/
|
||||
IGUIObject* m_FocusedObject;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Just pointers for fast name access, each object
|
||||
* is really constructed within its parent for easy
|
||||
* recursive management.
|
||||
@ -671,4 +642,4 @@ private:
|
||||
std::map<CStr, SGUIIcon> m_Icons;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // INCLUDED_CGUI
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -15,13 +15,12 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
IGUIScrollBar
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
#include "GUI.h"
|
||||
|
||||
#include "CGUIScrollBarVertical.h"
|
||||
|
||||
#include "GUI.h"
|
||||
|
||||
#include "ps/CLogger.h"
|
||||
|
||||
|
||||
@ -33,7 +32,7 @@ CGUIScrollBarVertical::~CGUIScrollBarVertical()
|
||||
{
|
||||
}
|
||||
|
||||
void CGUIScrollBarVertical::SetPosFromMousePos(const CPos &mouse)
|
||||
void CGUIScrollBarVertical::SetPosFromMousePos(const CPos& mouse)
|
||||
{
|
||||
if (!GetStyle())
|
||||
return;
|
||||
@ -62,7 +61,7 @@ void CGUIScrollBarVertical::Draw()
|
||||
// Draw background
|
||||
GetGUI()->DrawSprite(GetStyle()->m_SpriteBackVertical,
|
||||
0,
|
||||
m_Z+0.1f,
|
||||
m_Z+0.1f,
|
||||
CRect(outline.left,
|
||||
outline.top+(GetStyle()->m_UseEdgeButtons?GetStyle()->m_Width:0),
|
||||
outline.right,
|
||||
@ -72,7 +71,8 @@ void CGUIScrollBarVertical::Draw()
|
||||
if (GetStyle()->m_UseEdgeButtons)
|
||||
{
|
||||
// Get Appropriate sprites
|
||||
const CGUISpriteInstance *button_top, *button_bottom;
|
||||
const CGUISpriteInstance* button_top;
|
||||
const CGUISpriteInstance* button_bottom;
|
||||
|
||||
// figure out what sprite to use for top button
|
||||
if (m_ButtonMinusHovered)
|
||||
@ -82,7 +82,8 @@ void CGUIScrollBarVertical::Draw()
|
||||
else
|
||||
button_top = &GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonTopOver, GetStyle()->m_SpriteButtonTop);
|
||||
}
|
||||
else button_top = &GetStyle()->m_SpriteButtonTop;
|
||||
else
|
||||
button_top = &GetStyle()->m_SpriteButtonTop;
|
||||
|
||||
// figure out what sprite to use for bottom button
|
||||
if (m_ButtonPlusHovered)
|
||||
@ -92,8 +93,9 @@ void CGUIScrollBarVertical::Draw()
|
||||
else
|
||||
button_bottom = &GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonBottomOver, GetStyle()->m_SpriteButtonBottom);
|
||||
}
|
||||
else button_bottom = &GetStyle()->m_SpriteButtonBottom;
|
||||
|
||||
else
|
||||
button_bottom = &GetStyle()->m_SpriteButtonBottom;
|
||||
|
||||
// Draw top button
|
||||
GetGUI()->DrawSprite(*button_top,
|
||||
0,
|
||||
@ -103,7 +105,7 @@ void CGUIScrollBarVertical::Draw()
|
||||
outline.right,
|
||||
outline.top+GetStyle()->m_Width)
|
||||
);
|
||||
|
||||
|
||||
// Draw bottom button
|
||||
GetGUI()->DrawSprite(*button_bottom,
|
||||
0,
|
||||
@ -121,9 +123,9 @@ void CGUIScrollBarVertical::Draw()
|
||||
m_Z + 0.2f,
|
||||
GetBarRect());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CGUIScrollBarVertical::HandleMessage(SGUIMessage &Message)
|
||||
void CGUIScrollBarVertical::HandleMessage(SGUIMessage& Message)
|
||||
{
|
||||
IGUIScrollBar::HandleMessage(Message);
|
||||
}
|
||||
@ -167,7 +169,7 @@ CRect CGUIScrollBarVertical::GetOuterRect() const
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool CGUIScrollBarVertical::HoveringButtonMinus(const CPos &mouse)
|
||||
bool CGUIScrollBarVertical::HoveringButtonMinus(const CPos& mouse)
|
||||
{
|
||||
if (!GetStyle())
|
||||
return false;
|
||||
@ -180,7 +182,7 @@ bool CGUIScrollBarVertical::HoveringButtonMinus(const CPos &mouse)
|
||||
mouse.y <= m_Y + GetStyle()->m_Width);
|
||||
}
|
||||
|
||||
bool CGUIScrollBarVertical::HoveringButtonPlus(const CPos &mouse)
|
||||
bool CGUIScrollBarVertical::HoveringButtonPlus(const CPos& mouse)
|
||||
{
|
||||
if (!GetStyle())
|
||||
return false;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -37,22 +37,15 @@ A GUI ScrollBar
|
||||
#ifndef INCLUDED_CGUISCROLLBARVERTICAL
|
||||
#define INCLUDED_CGUISCROLLBARVERTICAL
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Includes / Compiler directives
|
||||
//--------------------------------------------------------
|
||||
#include "IGUIScrollBar.h"
|
||||
#include "GUI.h"
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Declarations
|
||||
//--------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Vertical implementation of IGUIScrollBar
|
||||
*
|
||||
* @see IGUIScrollBar
|
||||
*/
|
||||
class CGUIScrollBarVertical : public IGUIScrollBar
|
||||
class CGUIScrollBarVertical : public IGUIScrollBar
|
||||
{
|
||||
public:
|
||||
CGUIScrollBarVertical();
|
||||
@ -71,28 +64,28 @@ public:
|
||||
*
|
||||
* @see IGUIObject#HandleMessage()
|
||||
*/
|
||||
virtual void HandleMessage(SGUIMessage &Message);
|
||||
virtual void HandleMessage(SGUIMessage& Message);
|
||||
|
||||
/**
|
||||
* Set m_Pos with g_mouse_x/y input, i.e. when dragging.
|
||||
*/
|
||||
virtual void SetPosFromMousePos(const CPos &mouse);
|
||||
virtual void SetPosFromMousePos(const CPos& mouse);
|
||||
|
||||
/**
|
||||
* @see IGUIScrollBar#HoveringButtonMinus
|
||||
*/
|
||||
virtual bool HoveringButtonMinus(const CPos &mouse);
|
||||
virtual bool HoveringButtonMinus(const CPos& mouse);
|
||||
|
||||
/**
|
||||
* @see IGUIScrollBar#HoveringButtonPlus
|
||||
*/
|
||||
virtual bool HoveringButtonPlus(const CPos &mouse);
|
||||
virtual bool HoveringButtonPlus(const CPos& mouse);
|
||||
|
||||
/**
|
||||
* Set Right Aligned
|
||||
* @param align Alignment
|
||||
*/
|
||||
void SetRightAligned(const bool &align) { m_RightAligned = align; }
|
||||
void SetRightAligned(const bool& align) { m_RightAligned = align; }
|
||||
|
||||
/**
|
||||
* Get the rectangle of the actual BAR.
|
||||
@ -115,4 +108,4 @@ protected:
|
||||
bool m_RightAligned;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // INCLUDED_CGUISCROLLBARVERTICAL
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -16,14 +16,13 @@
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "CGUISprite.h"
|
||||
|
||||
CGUISprite::~CGUISprite()
|
||||
{
|
||||
for (std::vector<SGUIImage*>::iterator it = m_Images.begin(); it != m_Images.end(); it++)
|
||||
{
|
||||
delete *it;
|
||||
}
|
||||
for (SGUIImage* const& img : m_Images)
|
||||
delete img;
|
||||
}
|
||||
|
||||
void CGUISprite::AddImage(SGUIImage* image)
|
||||
@ -31,7 +30,7 @@ void CGUISprite::AddImage(SGUIImage* image)
|
||||
m_Images.push_back(image);
|
||||
}
|
||||
|
||||
void CGUISpriteInstance::Draw(CRect Size, int CellID, std::map<CStr, CGUISprite*> &Sprites, float Z) const
|
||||
void CGUISpriteInstance::Draw(CRect Size, int CellID, std::map<CStr, CGUISprite*>& Sprites, float Z) const
|
||||
{
|
||||
if (m_CachedSize != Size || m_CachedCellID != CellID)
|
||||
{
|
||||
@ -50,7 +49,7 @@ void CGUISpriteInstance::Invalidate()
|
||||
|
||||
bool CGUISpriteInstance::IsEmpty() const
|
||||
{
|
||||
return m_SpriteName=="";
|
||||
return m_SpriteName.empty();
|
||||
}
|
||||
|
||||
// Plus a load of constructors / assignment operators, which don't copy the
|
||||
@ -67,12 +66,12 @@ CGUISpriteInstance::CGUISpriteInstance(const CStr& SpriteName)
|
||||
{
|
||||
}
|
||||
|
||||
CGUISpriteInstance::CGUISpriteInstance(const CGUISpriteInstance &Sprite)
|
||||
CGUISpriteInstance::CGUISpriteInstance(const CGUISpriteInstance& Sprite)
|
||||
: m_SpriteName(Sprite.m_SpriteName), m_CachedCellID(-1)
|
||||
{
|
||||
}
|
||||
|
||||
CGUISpriteInstance &CGUISpriteInstance::operator=(const CStr& SpriteName)
|
||||
CGUISpriteInstance& CGUISpriteInstance::operator=(const CStr& SpriteName)
|
||||
{
|
||||
m_SpriteName = SpriteName;
|
||||
m_DrawCallCache.clear();
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -37,30 +37,10 @@ A GUI Sprite
|
||||
#ifndef INCLUDED_CGUISPRITE
|
||||
#define INCLUDED_CGUISPRITE
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Includes / Compiler directives
|
||||
//--------------------------------------------------------
|
||||
#include "GUIbase.h"
|
||||
|
||||
#include "lib/res/graphics/ogl_tex.h"
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Macros
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Types
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Error declarations
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Declarations
|
||||
//--------------------------------------------------------
|
||||
|
||||
|
||||
struct SGUIImageEffects
|
||||
{
|
||||
SGUIImageEffects() : m_Greyscale(false) {}
|
||||
@ -74,12 +54,14 @@ struct SGUIImageEffects
|
||||
*/
|
||||
struct SGUIImage
|
||||
{
|
||||
NONCOPYABLE(SGUIImage);
|
||||
public:
|
||||
SGUIImage() :
|
||||
m_FixedHAspectRatio(0.f), m_RoundCoordinates(true), m_WrapMode(GL_REPEAT),
|
||||
m_Effects(NULL), m_Border(false), m_DeltaZ(0.f)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
~SGUIImage()
|
||||
{
|
||||
delete m_Effects;
|
||||
@ -138,8 +120,6 @@ struct SGUIImage
|
||||
* way of declaring delta-z.
|
||||
*/
|
||||
float m_DeltaZ;
|
||||
|
||||
NONCOPYABLE(SGUIImage);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -153,6 +133,7 @@ struct SGUIImage
|
||||
*/
|
||||
class CGUISprite
|
||||
{
|
||||
NONCOPYABLE(CGUISprite);
|
||||
public:
|
||||
CGUISprite() {}
|
||||
virtual ~CGUISprite();
|
||||
@ -166,8 +147,6 @@ public:
|
||||
|
||||
/// List of images
|
||||
std::vector<SGUIImage*> m_Images;
|
||||
|
||||
NONCOPYABLE(CGUISprite);
|
||||
};
|
||||
|
||||
#include "GUIRenderer.h"
|
||||
@ -180,8 +159,8 @@ class CGUISpriteInstance
|
||||
public:
|
||||
CGUISpriteInstance();
|
||||
CGUISpriteInstance(const CStr& SpriteName);
|
||||
CGUISpriteInstance(const CGUISpriteInstance &Sprite);
|
||||
CGUISpriteInstance &operator=(const CStr& SpriteName);
|
||||
CGUISpriteInstance(const CGUISpriteInstance& Sprite);
|
||||
CGUISpriteInstance& operator=(const CStr& SpriteName);
|
||||
void Draw(CRect Size, int CellID, std::map<CStr, CGUISprite*>& Sprites, float Z) const;
|
||||
void Invalidate();
|
||||
bool IsEmpty() const;
|
||||
@ -198,4 +177,4 @@ private:
|
||||
mutable int m_CachedCellID;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // INCLUDED_CGUISPRITE
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -15,20 +15,14 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
CImage
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
#include "GUI.h"
|
||||
|
||||
#include "CImage.h"
|
||||
|
||||
#include "GUI.h"
|
||||
|
||||
#include "lib/ogl.h"
|
||||
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Constructor / Destructor
|
||||
//-------------------------------------------------------------------
|
||||
CImage::CImage()
|
||||
{
|
||||
AddSetting(GUIST_CGUISpriteInstance, "sprite");
|
||||
@ -41,17 +35,17 @@ CImage::~CImage()
|
||||
{
|
||||
}
|
||||
|
||||
void CImage::Draw()
|
||||
void CImage::Draw()
|
||||
{
|
||||
if (GetGUI())
|
||||
{
|
||||
float bz = GetBufferedZ();
|
||||
if (!GetGUI())
|
||||
return;
|
||||
|
||||
CGUISpriteInstance *sprite;
|
||||
int cell_id;
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
|
||||
GUI<int>::GetSetting(this, "cell_id", cell_id);
|
||||
float bz = GetBufferedZ();
|
||||
|
||||
GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize);
|
||||
}
|
||||
CGUISpriteInstance* sprite;
|
||||
int cell_id;
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
|
||||
GUI<int>::GetSetting(this, "cell_id", cell_id);
|
||||
|
||||
GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -15,39 +15,11 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
GUI Object - Image object
|
||||
|
||||
--Overview--
|
||||
|
||||
GUI Object for just drawing a sprite.
|
||||
|
||||
--More info--
|
||||
|
||||
Check GUI.h
|
||||
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_CIMAGE
|
||||
#define INCLUDED_CIMAGE
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Includes / Compiler directives
|
||||
//--------------------------------------------------------
|
||||
#include "GUI.h"
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Macros
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Types
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Declarations
|
||||
//--------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Object just for drawing a sprite. Like CText, without the
|
||||
* possibility to draw text.
|
||||
@ -57,7 +29,7 @@ GUI Object - Image object
|
||||
* without functionality used, and that is a lot of unnecessary
|
||||
* overhead. That's why I thought I'd go with an intuitive
|
||||
* control.
|
||||
*
|
||||
*
|
||||
* @see IGUIObject
|
||||
*/
|
||||
class CImage : public IGUIObject
|
||||
@ -75,4 +47,4 @@ protected:
|
||||
virtual void Draw();
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // INCLUDED_CIMAGE
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -15,39 +15,11 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
GUI Object - Input [box]
|
||||
|
||||
--Overview--
|
||||
|
||||
GUI Object representing a text field you can edit.
|
||||
|
||||
--More info--
|
||||
|
||||
Check GUI.h
|
||||
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_CINPUT
|
||||
#define INCLUDED_CINPUT
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Includes / Compiler directives
|
||||
//--------------------------------------------------------
|
||||
#include "GUI.h"
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Macros
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Types
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Declarations
|
||||
//--------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Text field where you can input and edit the text.
|
||||
*
|
||||
@ -75,18 +47,17 @@ public:
|
||||
|
||||
// Check where the mouse is hovering, and get the appropriate text position.
|
||||
// return is the text-position index.
|
||||
// const in philosophy, but I need to retrieve the caption in a non-const way.
|
||||
int GetMouseHoveringTextPosition();
|
||||
int GetMouseHoveringTextPosition() const;
|
||||
|
||||
// Same as above, but only on one row in X, and a given value, not the mouse's
|
||||
// wanted is filled with x if the row didn't extend as far as we
|
||||
int GetXTextPosition(const std::list<SRow>::iterator &c, const float &x, float &wanted);
|
||||
// Same as above, but only on one row in X, and a given value, not the mouse's.
|
||||
// wanted is filled with x if the row didn't extend as far as the mouse pos.
|
||||
int GetXTextPosition(const std::list<SRow>::const_iterator& c, const float& x, float& wanted) const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @see IGUIObject#HandleMessage()
|
||||
*/
|
||||
virtual void HandleMessage(SGUIMessage &Message);
|
||||
virtual void HandleMessage(SGUIMessage& Message);
|
||||
|
||||
/**
|
||||
* Handle events manually to catch keyboard inputting.
|
||||
@ -118,7 +89,7 @@ protected:
|
||||
* appears, because then the word-wrapping won't change after
|
||||
* that.
|
||||
*/
|
||||
void UpdateText(int from=0, int to_before=-1, int to_after=-1);
|
||||
void UpdateText(int from = 0, int to_before = -1, int to_after = -1);
|
||||
|
||||
/**
|
||||
* Delete the current selection. Also places the pointer at the
|
||||
@ -172,7 +143,7 @@ protected:
|
||||
* List of rows to ease changing its size, so iterators stay valid.
|
||||
* For one-liners only one row is used.
|
||||
*/
|
||||
std::list< SRow > m_CharacterPositions;
|
||||
std::list<SRow> m_CharacterPositions;
|
||||
|
||||
// *** Things for a multi-lined input control *** //
|
||||
|
||||
@ -205,4 +176,4 @@ protected:
|
||||
bool m_CursorVisState;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // INCLUDED_CINPUT
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2014 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -15,10 +15,6 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
CList
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "CList.h"
|
||||
@ -30,16 +26,12 @@ CList
|
||||
#include "soundmanager/ISoundManager.h"
|
||||
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Constructor / Destructor
|
||||
//-------------------------------------------------------------------
|
||||
CList::CList() :
|
||||
m_Modified(false)
|
||||
CList::CList()
|
||||
: m_Modified(false)
|
||||
{
|
||||
// Add sprite_disabled! TODO
|
||||
|
||||
AddSetting(GUIST_float, "buffer_zone");
|
||||
//AddSetting(GUIST_CGUIString, "caption"); will it break removing this? If I know my system, then no, but test just in case TODO (Gee).
|
||||
AddSetting(GUIST_CStrW, "font");
|
||||
AddSetting(GUIST_bool, "scrollbar");
|
||||
AddSetting(GUIST_CStr, "scrollbar_style");
|
||||
@ -64,7 +56,7 @@ CList::CList() :
|
||||
GUI<int>::SetSetting(this, "selected", -1);
|
||||
|
||||
// Add scroll-bar
|
||||
CGUIScrollBarVertical * bar = new CGUIScrollBarVertical();
|
||||
CGUIScrollBarVertical* bar = new CGUIScrollBarVertical();
|
||||
bar->SetRightAligned(true);
|
||||
AddScrollBar(bar);
|
||||
}
|
||||
@ -79,22 +71,18 @@ void CList::SetupText()
|
||||
return;
|
||||
|
||||
m_Modified = true;
|
||||
CGUIList *pList;
|
||||
CGUIList* pList;
|
||||
GUI<CGUIList>::GetSettingPointer(this, "list", pList);
|
||||
|
||||
//ENSURE(m_GeneratedTexts.size()>=1);
|
||||
|
||||
m_ItemsYPositions.resize( pList->m_Items.size()+1 );
|
||||
m_ItemsYPositions.resize(pList->m_Items.size()+1);
|
||||
|
||||
// Delete all generated texts. Some could probably be saved,
|
||||
// but this is easier, and this function will never be called
|
||||
// continuously, or even often, so it'll probably be okay.
|
||||
std::vector<SGUIText*>::iterator it;
|
||||
for (it=m_GeneratedTexts.begin(); it!=m_GeneratedTexts.end(); ++it)
|
||||
{
|
||||
if (*it)
|
||||
delete *it;
|
||||
}
|
||||
for (SGUIText* const& t : m_GeneratedTexts)
|
||||
delete t;
|
||||
m_GeneratedTexts.clear();
|
||||
|
||||
CStrW font;
|
||||
@ -103,9 +91,7 @@ void CList::SetupText()
|
||||
// TODO Gee: (2004-08-14) Don't define standard like this. Do it with the default style.
|
||||
font = L"default";
|
||||
|
||||
//CGUIString caption;
|
||||
bool scrollbar;
|
||||
//GUI<CGUIString>::GetSetting(this, "caption", caption);
|
||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
|
||||
|
||||
float width = GetListRect().GetWidth();
|
||||
@ -113,16 +99,16 @@ void CList::SetupText()
|
||||
if (scrollbar && GetScrollBar(0).GetStyle())
|
||||
width -= GetScrollBar(0).GetStyle()->m_Width;
|
||||
|
||||
float buffer_zone=0.f;
|
||||
float buffer_zone = 0.f;
|
||||
GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
|
||||
|
||||
// Generate texts
|
||||
float buffered_y = 0.f;
|
||||
|
||||
for (int i=0; i<(int)pList->m_Items.size(); ++i)
|
||||
|
||||
for (size_t i = 0; i < pList->m_Items.size(); ++i)
|
||||
{
|
||||
// Create a new SGUIText. Later on, input it using AddText()
|
||||
SGUIText *text = new SGUIText();
|
||||
SGUIText* text = new SGUIText();
|
||||
|
||||
*text = GetGUI()->GenerateText(pList->m_Items[i], font, width, buffer_zone, this);
|
||||
|
||||
@ -133,25 +119,22 @@ void CList::SetupText()
|
||||
}
|
||||
|
||||
m_ItemsYPositions[pList->m_Items.size()] = buffered_y;
|
||||
|
||||
//if (! scrollbar)
|
||||
// CalculateTextPosition(m_CachedActualSize, m_TextPos, *m_GeneratedTexts[0]);
|
||||
|
||||
// Setup scrollbar
|
||||
if (scrollbar)
|
||||
{
|
||||
GetScrollBar(0).SetScrollRange( m_ItemsYPositions.back() );
|
||||
GetScrollBar(0).SetScrollSpace( GetListRect().GetHeight() );
|
||||
GetScrollBar(0).SetScrollRange(m_ItemsYPositions.back());
|
||||
GetScrollBar(0).SetScrollSpace(GetListRect().GetHeight());
|
||||
|
||||
CRect rect = GetListRect();
|
||||
GetScrollBar(0).SetX( rect.right );
|
||||
GetScrollBar(0).SetY( rect.top );
|
||||
GetScrollBar(0).SetZ( GetBufferedZ() );
|
||||
GetScrollBar(0).SetLength( rect.bottom - rect.top );
|
||||
GetScrollBar(0).SetX(rect.right);
|
||||
GetScrollBar(0).SetY(rect.top);
|
||||
GetScrollBar(0).SetZ(GetBufferedZ());
|
||||
GetScrollBar(0).SetLength(rect.bottom - rect.top);
|
||||
}
|
||||
}
|
||||
|
||||
void CList::HandleMessage(SGUIMessage &Message)
|
||||
void CList::HandleMessage(SGUIMessage& Message)
|
||||
{
|
||||
IGUIScrollBarOwner::HandleMessage(Message);
|
||||
//IGUITextOwner::HandleMessage(Message); <== placed it after the switch instead!
|
||||
@ -161,9 +144,7 @@ void CList::HandleMessage(SGUIMessage &Message)
|
||||
{
|
||||
case GUIM_SETTINGS_UPDATED:
|
||||
if (Message.value == "list")
|
||||
{
|
||||
SetupText();
|
||||
}
|
||||
|
||||
// If selected is changed, call "SelectionChange"
|
||||
if (Message.value == "selected")
|
||||
@ -171,13 +152,11 @@ void CList::HandleMessage(SGUIMessage &Message)
|
||||
// TODO: Check range
|
||||
|
||||
// TODO only works if lower-case, shouldn't it be made case sensitive instead?
|
||||
ScriptEvent("selectionchange");
|
||||
ScriptEvent("selectionchange");
|
||||
}
|
||||
|
||||
if (Message.value == "scrollbar")
|
||||
{
|
||||
SetupText();
|
||||
}
|
||||
|
||||
// Update scrollbar
|
||||
if (Message.value == "scrollbar_style")
|
||||
@ -185,7 +164,7 @@ void CList::HandleMessage(SGUIMessage &Message)
|
||||
CStr scrollbar_style;
|
||||
GUI<CStr>::GetSetting(this, Message.value, scrollbar_style);
|
||||
|
||||
GetScrollBar(0).SetScrollBarStyle( scrollbar_style );
|
||||
GetScrollBar(0).SetScrollBarStyle(scrollbar_style);
|
||||
|
||||
SetupText();
|
||||
}
|
||||
@ -205,20 +184,18 @@ void CList::HandleMessage(SGUIMessage &Message)
|
||||
}
|
||||
|
||||
bool scrollbar;
|
||||
CGUIList *pList;
|
||||
CGUIList* pList;
|
||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
|
||||
GUI<CGUIList>::GetSettingPointer(this, "list", pList);
|
||||
float scroll=0.f;
|
||||
float scroll = 0.f;
|
||||
if (scrollbar)
|
||||
{
|
||||
scroll = GetScrollBar(0).GetPos();
|
||||
}
|
||||
|
||||
CRect rect = GetListRect();
|
||||
CPos mouse = GetMousePos();
|
||||
mouse.y += scroll;
|
||||
int set=-1;
|
||||
for (int i=0; i<(int)pList->m_Items.size(); ++i)
|
||||
int set = -1;
|
||||
for (int i = 0; i < (int)pList->m_Items.size(); ++i)
|
||||
{
|
||||
if (mouse.y >= rect.top + m_ItemsYPositions[i] &&
|
||||
mouse.y < rect.top + m_ItemsYPositions[i+1] &&
|
||||
@ -229,7 +206,7 @@ void CList::HandleMessage(SGUIMessage &Message)
|
||||
set = i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (set != -1)
|
||||
{
|
||||
GUI<int>::SetSetting(this, "selected", set);
|
||||
@ -243,12 +220,12 @@ void CList::HandleMessage(SGUIMessage &Message)
|
||||
}
|
||||
|
||||
case GUIM_LOAD:
|
||||
{
|
||||
{
|
||||
CStr scrollbar_style;
|
||||
GUI<CStr>::GetSetting(this, "scrollbar_style", scrollbar_style);
|
||||
GetScrollBar(0).SetScrollBarStyle( scrollbar_style );
|
||||
}
|
||||
GetScrollBar(0).SetScrollBarStyle(scrollbar_style);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
@ -309,18 +286,15 @@ InReaction CList::ManuallyHandleEvent(const SDL_Event_* ev)
|
||||
return result;
|
||||
}
|
||||
|
||||
void CList::Draw()
|
||||
void CList::Draw()
|
||||
{
|
||||
int selected;
|
||||
GUI<int>::GetSetting(this, "selected", selected);
|
||||
|
||||
|
||||
DrawList(selected, "sprite", "sprite_selectarea", "textcolor");
|
||||
}
|
||||
|
||||
void CList::DrawList(const int &selected,
|
||||
const CStr& _sprite,
|
||||
const CStr& _sprite_selected,
|
||||
const CStr& _textcolor)
|
||||
void CList::DrawList(const int& selected, const CStr& _sprite, const CStr& _sprite_selected, const CStr& _textcolor)
|
||||
{
|
||||
float bz = GetBufferedZ();
|
||||
|
||||
@ -329,31 +303,27 @@ void CList::DrawList(const int &selected,
|
||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
|
||||
|
||||
if (scrollbar)
|
||||
{
|
||||
// Draw scrollbar
|
||||
IGUIScrollBarOwner::Draw();
|
||||
}
|
||||
|
||||
if (GetGUI())
|
||||
{
|
||||
CRect rect = GetListRect();
|
||||
|
||||
CGUISpriteInstance *sprite=NULL, *sprite_selectarea=NULL;
|
||||
CGUISpriteInstance* sprite = NULL;
|
||||
CGUISpriteInstance* sprite_selectarea = NULL;
|
||||
int cell_id;
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, _sprite, sprite);
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, _sprite_selected, sprite_selectarea);
|
||||
GUI<int>::GetSetting(this, "cell_id", cell_id);
|
||||
|
||||
CGUIList *pList;
|
||||
CGUIList* pList;
|
||||
GUI<CGUIList>::GetSettingPointer(this, "list", pList);
|
||||
|
||||
GetGUI()->DrawSprite(*sprite, cell_id, bz, rect);
|
||||
|
||||
float scroll=0.f;
|
||||
float scroll = 0.f;
|
||||
if (scrollbar)
|
||||
{
|
||||
scroll = GetScrollBar(0).GetPos();
|
||||
}
|
||||
|
||||
if (selected != -1)
|
||||
{
|
||||
@ -390,7 +360,7 @@ void CList::DrawList(const int &selected,
|
||||
CColor color;
|
||||
GUI<CColor>::GetSetting(this, _textcolor, color);
|
||||
|
||||
for (int i=0; i<(int)pList->m_Items.size(); ++i)
|
||||
for (size_t i = 0; i < pList->m_Items.size(); ++i)
|
||||
{
|
||||
if (m_ItemsYPositions[i+1] - scroll < 0 ||
|
||||
m_ItemsYPositions[i] - scroll > rect.GetHeight())
|
||||
@ -417,17 +387,18 @@ void CList::DrawList(const int &selected,
|
||||
|
||||
void CList::AddItem(const CStrW& str, const CStrW& data)
|
||||
{
|
||||
CGUIList *pList, *pListData;
|
||||
CGUIList* pList;
|
||||
CGUIList* pListData;
|
||||
GUI<CGUIList>::GetSettingPointer(this, "list", pList);
|
||||
GUI<CGUIList>::GetSettingPointer(this, "list_data", pListData);
|
||||
|
||||
CGUIString gui_string;
|
||||
gui_string.SetValue(str);
|
||||
pList->m_Items.push_back( gui_string );
|
||||
pList->m_Items.push_back(gui_string);
|
||||
|
||||
CGUIString data_string;
|
||||
data_string.SetValue(data);
|
||||
pListData->m_Items.push_back( data_string );
|
||||
pListData->m_Items.push_back(data_string);
|
||||
|
||||
// TODO Temp
|
||||
SetupText();
|
||||
@ -440,13 +411,10 @@ bool CList::HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile)
|
||||
if (child.GetNodeName() == elmt_item)
|
||||
{
|
||||
AddItem(child.GetText().FromUTF8(), child.GetText().FromUTF8());
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CList::SelectNextElement()
|
||||
@ -454,7 +422,7 @@ void CList::SelectNextElement()
|
||||
int selected;
|
||||
GUI<int>::GetSetting(this, "selected", selected);
|
||||
|
||||
CGUIList *pList;
|
||||
CGUIList* pList;
|
||||
GUI<CGUIList>::GetSettingPointer(this, "list", pList);
|
||||
|
||||
if (selected != (int)pList->m_Items.size()-1)
|
||||
@ -467,7 +435,7 @@ void CList::SelectNextElement()
|
||||
g_SoundManager->PlayAsUI(soundPath.c_str(), false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CList::SelectPrevElement()
|
||||
{
|
||||
int selected;
|
||||
@ -490,23 +458,19 @@ void CList::SelectFirstElement()
|
||||
GUI<int>::GetSetting(this, "selected", selected);
|
||||
|
||||
if (selected >= 0)
|
||||
{
|
||||
GUI<int>::SetSetting(this, "selected", 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CList::SelectLastElement()
|
||||
{
|
||||
int selected;
|
||||
GUI<int>::GetSetting(this, "selected", selected);
|
||||
|
||||
CGUIList *pList;
|
||||
CGUIList* pList;
|
||||
GUI<CGUIList>::GetSettingPointer(this, "list", pList);
|
||||
|
||||
if (selected != (int)pList->m_Items.size()-1)
|
||||
{
|
||||
GUI<int>::SetSetting(this, "selected", (int)pList->m_Items.size()-1);
|
||||
}
|
||||
}
|
||||
|
||||
void CList::UpdateAutoScroll()
|
||||
@ -535,7 +499,5 @@ void CList::UpdateAutoScroll()
|
||||
|
||||
// Check lower boundary
|
||||
if (m_ItemsYPositions[selected+1]-rect.GetHeight() > scroll)
|
||||
{
|
||||
GetScrollBar(0).SetPos(m_ItemsYPositions[selected+1]-rect.GetHeight());
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -15,43 +15,11 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
GUI Object - List [box]
|
||||
|
||||
--Overview--
|
||||
|
||||
GUI Object for creating lists of information, wherein one
|
||||
of the elements can be selected. A scroll-bar will aid
|
||||
when there's too much information to be displayed at once.
|
||||
|
||||
--More info--
|
||||
|
||||
Check GUI.h
|
||||
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_CLIST
|
||||
#define INCLUDED_CLIST
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Includes / Compiler directives
|
||||
//--------------------------------------------------------
|
||||
|
||||
#include "IGUIScrollBar.h"
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Macros
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Types
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Declarations
|
||||
//--------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Create a list of elements, where one can be selected
|
||||
* by the user. The control will use a pre-processed
|
||||
@ -59,10 +27,8 @@ GUI Object - List [box]
|
||||
* by the IGUITextOwner structure.
|
||||
*
|
||||
* A scroll-bar will appear when needed. This will be
|
||||
* achieve with the IGUIScrollBarOwner structure.
|
||||
*
|
||||
* achieved with the IGUIScrollBarOwner structure.
|
||||
*/
|
||||
|
||||
class CList : public IGUIScrollBarOwner, public IGUITextOwner
|
||||
{
|
||||
GUI_OBJECT(CList)
|
||||
@ -91,7 +57,7 @@ protected:
|
||||
/**
|
||||
* @see IGUIObject#HandleMessage()
|
||||
*/
|
||||
virtual void HandleMessage(SGUIMessage &Message);
|
||||
virtual void HandleMessage(SGUIMessage& Message);
|
||||
|
||||
/**
|
||||
* Handle events manually to catch keyboard inputting.
|
||||
@ -121,8 +87,7 @@ protected:
|
||||
|
||||
// Extended drawing interface, this is so that classes built on the this one
|
||||
// can use other sprite names.
|
||||
virtual void DrawList(const int &selected, const CStr& _sprite,
|
||||
const CStr& _sprite_selected, const CStr& _textcolor);
|
||||
virtual void DrawList(const int& selected, const CStr& _sprite, const CStr& _sprite_selected, const CStr& _textcolor);
|
||||
|
||||
// Get the area of the list. This is so that it can easily be changed, like in CDropDown
|
||||
// where the area is not equal to m_CachedActualSize.
|
||||
@ -132,9 +97,6 @@ protected:
|
||||
// (and thus whether list items have possibly changed).
|
||||
virtual bool GetModified() const { return m_Modified; }
|
||||
|
||||
// List of items.
|
||||
//CGUIList m_List;
|
||||
|
||||
/**
|
||||
* List of each element's relative y position. Will be
|
||||
* one larger than m_Items, because it will end with the
|
||||
@ -148,4 +110,4 @@ private:
|
||||
bool m_Modified;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // INCLUDED_CLIST
|
||||
|
@ -14,14 +14,17 @@
|
||||
* 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/>.
|
||||
*/
|
||||
#include "precompiled.h"
|
||||
#include "COList.h"
|
||||
#include "i18n/L10n.h"
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "COList.h"
|
||||
|
||||
#include "i18n/L10n.h"
|
||||
#include "ps/CLogger.h"
|
||||
#include "soundmanager/ISoundManager.h"
|
||||
|
||||
COList::COList() : CList(),m_HeadingHeight(30.f),m_SelectedDef(-1),m_SelectedColumnOrder(1)
|
||||
COList::COList()
|
||||
: CList(), m_HeadingHeight(30.f), m_SelectedDef(-1), m_SelectedColumnOrder(1)
|
||||
{
|
||||
AddSetting(GUIST_CGUISpriteInstance, "sprite_heading");
|
||||
AddSetting(GUIST_bool, "sortable"); // The actual sorting is done in JS for more versatility
|
||||
@ -44,20 +47,16 @@ void COList::SetupText()
|
||||
if (!GetGUI())
|
||||
return;
|
||||
|
||||
CGUIList *pList;
|
||||
CGUIList* pList;
|
||||
GUI<CGUIList>::GetSettingPointer(this, "list_name", pList);
|
||||
|
||||
m_ItemsYPositions.resize( pList->m_Items.size()+1 );
|
||||
m_ItemsYPositions.resize(pList->m_Items.size() + 1);
|
||||
|
||||
// Delete all generated texts. Some could probably be saved,
|
||||
// but this is easier, and this function will never be called
|
||||
// continuously, or even often, so it'll probably be okay.
|
||||
std::vector<SGUIText*>::iterator it;
|
||||
for (it=m_GeneratedTexts.begin(); it!=m_GeneratedTexts.end(); ++it)
|
||||
{
|
||||
if (*it)
|
||||
delete *it;
|
||||
}
|
||||
for (SGUIText* const& t : m_GeneratedTexts)
|
||||
delete t;
|
||||
m_GeneratedTexts.clear();
|
||||
|
||||
CStrW font;
|
||||
@ -77,22 +76,22 @@ void COList::SetupText()
|
||||
// Cache width for other use
|
||||
m_TotalAvalibleColumnWidth = width;
|
||||
|
||||
float buffer_zone=0.f;
|
||||
float buffer_zone = 0.f;
|
||||
GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
|
||||
|
||||
CStr defaultColumn;
|
||||
GUI<CStr>::GetSetting(this, "default_column", defaultColumn);
|
||||
defaultColumn = "list_" + defaultColumn;
|
||||
|
||||
for (unsigned int c=0; c<m_ObjectsDefs.size(); ++c)
|
||||
for (size_t c = 0; c < m_ObjectsDefs.size(); ++c)
|
||||
{
|
||||
SGUIText *text = new SGUIText();
|
||||
SGUIText* text = new SGUIText();
|
||||
CGUIString gui_string;
|
||||
gui_string.SetValue(m_ObjectsDefs[c].m_Heading);
|
||||
*text = GetGUI()->GenerateText(gui_string, font, width, buffer_zone, this);
|
||||
AddText(text);
|
||||
|
||||
if (m_SelectedDef == -1 && defaultColumn == m_ObjectsDefs[c].m_Id)
|
||||
if (m_SelectedDef == (size_t)-1 && defaultColumn == m_ObjectsDefs[c].m_Id)
|
||||
m_SelectedDef = c;
|
||||
}
|
||||
|
||||
@ -100,16 +99,16 @@ void COList::SetupText()
|
||||
// Generate texts
|
||||
float buffered_y = 0.f;
|
||||
|
||||
for (int i=0; i<(int)pList->m_Items.size(); ++i)
|
||||
for (size_t i = 0; i < pList->m_Items.size(); ++i)
|
||||
{
|
||||
m_ItemsYPositions[i] = buffered_y;
|
||||
for (unsigned int c=0; c<m_ObjectsDefs.size(); ++c)
|
||||
for (size_t c = 0; c < m_ObjectsDefs.size(); ++c)
|
||||
{
|
||||
CGUIList * pList_c;
|
||||
CGUIList* pList_c;
|
||||
GUI<CGUIList>::GetSettingPointer(this, m_ObjectsDefs[c].m_Id, pList_c);
|
||||
SGUIText *text = new SGUIText();
|
||||
SGUIText* text = new SGUIText();
|
||||
*text = GetGUI()->GenerateText(pList_c->m_Items[i], font, width, buffer_zone, this);
|
||||
if (c==0)
|
||||
if (c == 0)
|
||||
buffered_y += text->m_Size.cy;
|
||||
AddText(text);
|
||||
}
|
||||
@ -120,14 +119,14 @@ void COList::SetupText()
|
||||
// Setup scrollbar
|
||||
if (scrollbar)
|
||||
{
|
||||
GetScrollBar(0).SetScrollRange( m_ItemsYPositions.back() );
|
||||
GetScrollBar(0).SetScrollSpace( GetListRect().GetHeight() );
|
||||
GetScrollBar(0).SetScrollRange(m_ItemsYPositions.back());
|
||||
GetScrollBar(0).SetScrollSpace(GetListRect().GetHeight());
|
||||
|
||||
CRect rect = GetListRect();
|
||||
GetScrollBar(0).SetX( rect.right );
|
||||
GetScrollBar(0).SetY( rect.top );
|
||||
GetScrollBar(0).SetZ( GetBufferedZ() );
|
||||
GetScrollBar(0).SetLength( rect.bottom - rect.top );
|
||||
GetScrollBar(0).SetX(rect.right);
|
||||
GetScrollBar(0).SetY(rect.top);
|
||||
GetScrollBar(0).SetZ(GetBufferedZ());
|
||||
GetScrollBar(0).SetLength(rect.bottom - rect.top);
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,7 +135,7 @@ CRect COList::GetListRect() const
|
||||
return m_CachedActualSize + CRect(0, m_HeadingHeight, 0, 0);
|
||||
}
|
||||
|
||||
void COList::HandleMessage(SGUIMessage &Message)
|
||||
void COList::HandleMessage(SGUIMessage& Message)
|
||||
{
|
||||
CList::HandleMessage(Message);
|
||||
|
||||
@ -153,9 +152,9 @@ void COList::HandleMessage(SGUIMessage &Message)
|
||||
CPos mouse = GetMousePos();
|
||||
if (!m_CachedActualSize.PointInside(mouse))
|
||||
return;
|
||||
|
||||
|
||||
float xpos = 0;
|
||||
for (unsigned int def = 0; def < m_ObjectsDefs.size(); ++def)
|
||||
for (size_t def = 0; def < m_ObjectsDefs.size(); ++def)
|
||||
{
|
||||
float width = m_ObjectsDefs[def].m_Width;
|
||||
// Check if it's a decimal value, and if so, assume relative positioning.
|
||||
@ -166,7 +165,7 @@ void COList::HandleMessage(SGUIMessage &Message)
|
||||
mouse.x < leftTopCorner.x + width &&
|
||||
mouse.y < leftTopCorner.y + m_HeadingHeight)
|
||||
{
|
||||
if (static_cast<int> (def) != m_SelectedDef)
|
||||
if (def != m_SelectedDef)
|
||||
{
|
||||
m_SelectedColumnOrder = 1;
|
||||
m_SelectedDef = def;
|
||||
@ -198,7 +197,6 @@ bool COList::HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile
|
||||
#define ELMT(x) int elmt_##x = pFile->GetElementID(#x)
|
||||
#define ATTR(x) int attr_##x = pFile->GetAttributeID(#x)
|
||||
ELMT(item);
|
||||
ELMT(heading);
|
||||
ELMT(def);
|
||||
ELMT(translatableAttribute);
|
||||
ATTR(id);
|
||||
@ -209,20 +207,14 @@ bool COList::HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile
|
||||
AddItem(child.GetText().FromUTF8(), child.GetText().FromUTF8());
|
||||
return true;
|
||||
}
|
||||
else if (child.GetNodeName() == elmt_heading)
|
||||
{
|
||||
CStrW text (child.GetText().FromUTF8());
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (child.GetNodeName() == elmt_def)
|
||||
{
|
||||
ObjectDef oDef;
|
||||
|
||||
for (XMBAttribute attr : child.GetAttributes())
|
||||
{
|
||||
CStr attr_name (pFile->GetAttributeString(attr.Name));
|
||||
CStr attr_value (attr.Value);
|
||||
CStr attr_name(pFile->GetAttributeString(attr.Name));
|
||||
CStr attr_value(attr.Value);
|
||||
|
||||
if (attr_name == "color")
|
||||
{
|
||||
@ -244,9 +236,7 @@ bool COList::HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile
|
||||
{
|
||||
// Check if it's a relative value, and save as decimal if so.
|
||||
if (attr_value.find("%") != std::string::npos)
|
||||
{
|
||||
width = width / 100.f;
|
||||
}
|
||||
oDef.m_Width = width;
|
||||
}
|
||||
}
|
||||
@ -254,37 +244,35 @@ bool COList::HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile
|
||||
{
|
||||
oDef.m_Heading = attr_value.FromUTF8();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (XMBElement grandchild : child.GetChildNodes())
|
||||
{
|
||||
if (grandchild.GetNodeName() == elmt_translatableAttribute)
|
||||
if (grandchild.GetNodeName() != elmt_translatableAttribute)
|
||||
continue;
|
||||
|
||||
CStr attributeName(grandchild.GetAttributes().GetNamedItem(attr_id));
|
||||
// only the heading is translatable for list defs
|
||||
if (attributeName.empty() || attributeName != "heading")
|
||||
{
|
||||
CStr attributeName(grandchild.GetAttributes().GetNamedItem(attr_id));
|
||||
// only the heading is translatable for list defs
|
||||
if (!attributeName.empty() && attributeName == "heading")
|
||||
{
|
||||
CStr value(grandchild.GetText());
|
||||
if (!value.empty())
|
||||
{
|
||||
CStr context(grandchild.GetAttributes().GetNamedItem(attr_context)); // Read the context if any.
|
||||
if (!context.empty())
|
||||
{
|
||||
CStr translatedValue(g_L10n.TranslateWithContext(context, value));
|
||||
oDef.m_Heading = translatedValue.FromUTF8();
|
||||
}
|
||||
else
|
||||
{
|
||||
CStr translatedValue(g_L10n.Translate(value));
|
||||
oDef.m_Heading = translatedValue.FromUTF8();
|
||||
}
|
||||
}
|
||||
}
|
||||
else // Ignore.
|
||||
{
|
||||
LOGERROR("GUI: translatable attribute in olist def that isn't a heading. (object: %s)", this->GetPresentableName().c_str());
|
||||
}
|
||||
LOGERROR("GUI: translatable attribute in olist def that isn't a heading. (object: %s)", this->GetPresentableName().c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
CStr value(grandchild.GetText());
|
||||
if (value.empty())
|
||||
continue;
|
||||
|
||||
CStr context(grandchild.GetAttributes().GetNamedItem(attr_context)); // Read the context if any.
|
||||
if (!context.empty())
|
||||
{
|
||||
CStr translatedValue(g_L10n.TranslateWithContext(context, value));
|
||||
oDef.m_Heading = translatedValue.FromUTF8();
|
||||
}
|
||||
else
|
||||
{
|
||||
CStr translatedValue(g_L10n.Translate(value));
|
||||
oDef.m_Heading = translatedValue.FromUTF8();
|
||||
}
|
||||
}
|
||||
|
||||
@ -301,10 +289,7 @@ bool COList::HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile
|
||||
}
|
||||
}
|
||||
|
||||
void COList::DrawList(const int &selected,
|
||||
const CStr& _sprite,
|
||||
const CStr& _sprite_selected,
|
||||
const CStr& _textcolor)
|
||||
void COList::DrawList(const int& selected, const CStr& _sprite, const CStr& _sprite_selected, const CStr& _textcolor)
|
||||
{
|
||||
float bz = GetBufferedZ();
|
||||
|
||||
@ -313,143 +298,140 @@ void COList::DrawList(const int &selected,
|
||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
|
||||
|
||||
if (scrollbar)
|
||||
{
|
||||
// Draw scrollbar
|
||||
IGUIScrollBarOwner::Draw();
|
||||
}
|
||||
|
||||
if (GetGUI())
|
||||
if (!GetGUI())
|
||||
return;
|
||||
|
||||
CRect rect = GetListRect();
|
||||
|
||||
CGUISpriteInstance* sprite = NULL;
|
||||
CGUISpriteInstance* sprite_selectarea = NULL;
|
||||
int cell_id;
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, _sprite, sprite);
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, _sprite_selected, sprite_selectarea);
|
||||
GUI<int>::GetSetting(this, "cell_id", cell_id);
|
||||
|
||||
CGUIList* pList;
|
||||
GUI<CGUIList>::GetSettingPointer(this, "list_name", pList);
|
||||
|
||||
GetGUI()->DrawSprite(*sprite, cell_id, bz, rect);
|
||||
|
||||
float scroll = 0.f;
|
||||
if (scrollbar)
|
||||
scroll = GetScrollBar(0).GetPos();
|
||||
|
||||
if (selected != -1)
|
||||
{
|
||||
CRect rect = GetListRect();
|
||||
ENSURE(selected >= 0 && selected+1 < (int)m_ItemsYPositions.size());
|
||||
|
||||
CGUISpriteInstance *sprite=NULL, *sprite_selectarea=NULL;
|
||||
int cell_id;
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, _sprite, sprite);
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, _sprite_selected, sprite_selectarea);
|
||||
GUI<int>::GetSetting(this, "cell_id", cell_id);
|
||||
// Get rectangle of selection:
|
||||
CRect rect_sel(rect.left, rect.top + m_ItemsYPositions[selected] - scroll,
|
||||
rect.right, rect.top + m_ItemsYPositions[selected+1] - scroll);
|
||||
|
||||
CGUIList *pList;
|
||||
GUI<CGUIList>::GetSettingPointer(this, "list_name", pList);
|
||||
|
||||
GetGUI()->DrawSprite(*sprite, cell_id, bz, rect);
|
||||
|
||||
float scroll=0.f;
|
||||
if (scrollbar)
|
||||
if (rect_sel.top <= rect.bottom &&
|
||||
rect_sel.bottom >= rect.top)
|
||||
{
|
||||
scroll = GetScrollBar(0).GetPos();
|
||||
}
|
||||
|
||||
if (selected != -1)
|
||||
{
|
||||
ENSURE(selected >= 0 && selected+1 < (int)m_ItemsYPositions.size());
|
||||
|
||||
// Get rectangle of selection:
|
||||
CRect rect_sel(rect.left, rect.top + m_ItemsYPositions[selected] - scroll,
|
||||
rect.right, rect.top + m_ItemsYPositions[selected+1] - scroll);
|
||||
|
||||
if (rect_sel.top <= rect.bottom &&
|
||||
rect_sel.bottom >= rect.top)
|
||||
{
|
||||
if (rect_sel.bottom > rect.bottom)
|
||||
rect_sel.bottom = rect.bottom;
|
||||
if (rect_sel.top < rect.top)
|
||||
rect_sel.top = rect.top;
|
||||
|
||||
if (scrollbar)
|
||||
{
|
||||
// Remove any overlapping area of the scrollbar.
|
||||
if (rect_sel.right > GetScrollBar(0).GetOuterRect().left &&
|
||||
rect_sel.right <= GetScrollBar(0).GetOuterRect().right)
|
||||
rect_sel.right = GetScrollBar(0).GetOuterRect().left;
|
||||
|
||||
if (rect_sel.left >= GetScrollBar(0).GetOuterRect().left &&
|
||||
rect_sel.left < GetScrollBar(0).GetOuterRect().right)
|
||||
rect_sel.left = GetScrollBar(0).GetOuterRect().right;
|
||||
}
|
||||
|
||||
GetGUI()->DrawSprite(*sprite_selectarea, cell_id, bz+0.05f, rect_sel);
|
||||
}
|
||||
}
|
||||
|
||||
CColor color;
|
||||
GUI<CColor>::GetSetting(this, _textcolor, color);
|
||||
|
||||
CGUISpriteInstance *sprite_heading=NULL;
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_heading", sprite_heading);
|
||||
CRect rect_head(m_CachedActualSize.left, m_CachedActualSize.top, m_CachedActualSize.right,
|
||||
m_CachedActualSize.top + m_HeadingHeight);
|
||||
GetGUI()->DrawSprite(*sprite_heading, cell_id, bz, rect_head);
|
||||
|
||||
CGUISpriteInstance *sprite_order, *sprite_not_sorted;
|
||||
if (m_SelectedColumnOrder != -1)
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_asc", sprite_order);
|
||||
else
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_desc", sprite_order);
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_not_sorted", sprite_not_sorted);
|
||||
|
||||
float xpos = 0;
|
||||
for (unsigned int def=0; def< m_ObjectsDefs.size(); ++def)
|
||||
{
|
||||
// Check if it's a decimal value, and if so, assume relative positioning.
|
||||
float width = m_ObjectsDefs[def].m_Width;
|
||||
if (m_ObjectsDefs[def].m_Width < 1 && m_ObjectsDefs[def].m_Width > 0)
|
||||
width *= m_TotalAvalibleColumnWidth;
|
||||
|
||||
CPos leftTopCorner = m_CachedActualSize.TopLeft() + CPos(xpos, 0);
|
||||
CGUISpriteInstance *sprite;
|
||||
// If the list sorted by current column
|
||||
if (m_SelectedDef == static_cast<int> (def))
|
||||
sprite = sprite_order;
|
||||
else
|
||||
sprite = sprite_not_sorted;
|
||||
GetGUI()->DrawSprite(*sprite, cell_id, bz + 0.1f, CRect(leftTopCorner + CPos(width - 16, 0), leftTopCorner + CPos(width, 16)));
|
||||
|
||||
DrawText(def, color, leftTopCorner + CPos(0, 4), bz + 0.1f, rect_head);
|
||||
xpos += width;
|
||||
}
|
||||
|
||||
const unsigned int objectsCount = m_ObjectsDefs.size();
|
||||
for (int i=0; i<(int)pList->m_Items.size(); ++i)
|
||||
{
|
||||
if (m_ItemsYPositions[i+1] - scroll < 0 ||
|
||||
m_ItemsYPositions[i] - scroll > rect.GetHeight())
|
||||
continue;
|
||||
|
||||
const float rowHeight = m_ItemsYPositions[i+1] - m_ItemsYPositions[i];
|
||||
|
||||
// Clipping area (we'll have to substract the scrollbar)
|
||||
CRect cliparea = GetListRect();
|
||||
if (rect_sel.bottom > rect.bottom)
|
||||
rect_sel.bottom = rect.bottom;
|
||||
if (rect_sel.top < rect.top)
|
||||
rect_sel.top = rect.top;
|
||||
|
||||
if (scrollbar)
|
||||
{
|
||||
if (cliparea.right > GetScrollBar(0).GetOuterRect().left &&
|
||||
cliparea.right <= GetScrollBar(0).GetOuterRect().right)
|
||||
cliparea.right = GetScrollBar(0).GetOuterRect().left;
|
||||
// Remove any overlapping area of the scrollbar.
|
||||
if (rect_sel.right > GetScrollBar(0).GetOuterRect().left &&
|
||||
rect_sel.right <= GetScrollBar(0).GetOuterRect().right)
|
||||
rect_sel.right = GetScrollBar(0).GetOuterRect().left;
|
||||
|
||||
if (cliparea.left >= GetScrollBar(0).GetOuterRect().left &&
|
||||
cliparea.left < GetScrollBar(0).GetOuterRect().right)
|
||||
cliparea.left = GetScrollBar(0).GetOuterRect().right;
|
||||
if (rect_sel.left >= GetScrollBar(0).GetOuterRect().left &&
|
||||
rect_sel.left < GetScrollBar(0).GetOuterRect().right)
|
||||
rect_sel.left = GetScrollBar(0).GetOuterRect().right;
|
||||
}
|
||||
|
||||
xpos = 0;
|
||||
for (unsigned int def=0; def < objectsCount; ++def)
|
||||
{
|
||||
// Determine text position and width
|
||||
const CPos textPos = rect.TopLeft() + CPos(xpos, -scroll + m_ItemsYPositions[i]);
|
||||
GetGUI()->DrawSprite(*sprite_selectarea, cell_id, bz+0.05f, rect_sel);
|
||||
}
|
||||
}
|
||||
|
||||
float width = m_ObjectsDefs[def].m_Width;;
|
||||
// Check if it's a decimal value, and if so, assume relative positioning.
|
||||
if (m_ObjectsDefs[def].m_Width < 1 && m_ObjectsDefs[def].m_Width > 0)
|
||||
width *= m_TotalAvalibleColumnWidth;
|
||||
CColor color;
|
||||
GUI<CColor>::GetSetting(this, _textcolor, color);
|
||||
|
||||
// Clip text to the column (to prevent drawing text into the neighboring column)
|
||||
CRect cliparea2 = cliparea;
|
||||
cliparea2.right = std::min(cliparea2.right, textPos.x + width);
|
||||
cliparea2.bottom = std::min(cliparea2.bottom, textPos.y + rowHeight);
|
||||
CGUISpriteInstance* sprite_heading = NULL;
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_heading", sprite_heading);
|
||||
CRect rect_head(m_CachedActualSize.left, m_CachedActualSize.top, m_CachedActualSize.right,
|
||||
m_CachedActualSize.top + m_HeadingHeight);
|
||||
GetGUI()->DrawSprite(*sprite_heading, cell_id, bz, rect_head);
|
||||
|
||||
DrawText(objectsCount * (i+/*Heading*/1) + def, m_ObjectsDefs[def].m_TextColor, textPos, bz+0.1f, cliparea2);
|
||||
xpos += width;
|
||||
}
|
||||
CGUISpriteInstance* sprite_order;
|
||||
CGUISpriteInstance* sprite_not_sorted;
|
||||
if (m_SelectedColumnOrder != -1)
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_asc", sprite_order);
|
||||
else
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_desc", sprite_order);
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_not_sorted", sprite_not_sorted);
|
||||
|
||||
float xpos = 0;
|
||||
for (size_t def = 0; def < m_ObjectsDefs.size(); ++def)
|
||||
{
|
||||
// Check if it's a decimal value, and if so, assume relative positioning.
|
||||
float width = m_ObjectsDefs[def].m_Width;
|
||||
if (m_ObjectsDefs[def].m_Width < 1 && m_ObjectsDefs[def].m_Width > 0)
|
||||
width *= m_TotalAvalibleColumnWidth;
|
||||
|
||||
CPos leftTopCorner = m_CachedActualSize.TopLeft() + CPos(xpos, 0);
|
||||
CGUISpriteInstance* sprite;
|
||||
// If the list sorted by current column
|
||||
if (m_SelectedDef == def)
|
||||
sprite = sprite_order;
|
||||
else
|
||||
sprite = sprite_not_sorted;
|
||||
GetGUI()->DrawSprite(*sprite, cell_id, bz + 0.1f, CRect(leftTopCorner + CPos(width - 16, 0), leftTopCorner + CPos(width, 16)));
|
||||
|
||||
DrawText(def, color, leftTopCorner + CPos(0, 4), bz + 0.1f, rect_head);
|
||||
xpos += width;
|
||||
}
|
||||
|
||||
const size_t objectsCount = m_ObjectsDefs.size();
|
||||
for (size_t i = 0; i < pList->m_Items.size(); ++i)
|
||||
{
|
||||
if (m_ItemsYPositions[i+1] - scroll < 0 ||
|
||||
m_ItemsYPositions[i] - scroll > rect.GetHeight())
|
||||
continue;
|
||||
|
||||
const float rowHeight = m_ItemsYPositions[i+1] - m_ItemsYPositions[i];
|
||||
|
||||
// Clipping area (we'll have to substract the scrollbar)
|
||||
CRect cliparea = GetListRect();
|
||||
|
||||
if (scrollbar)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
xpos = 0;
|
||||
for (size_t def = 0; def < objectsCount; ++def)
|
||||
{
|
||||
// Determine text position and width
|
||||
const CPos textPos = rect.TopLeft() + CPos(xpos, -scroll + m_ItemsYPositions[i]);
|
||||
|
||||
float width = m_ObjectsDefs[def].m_Width;;
|
||||
// Check if it's a decimal value, and if so, assume relative positioning.
|
||||
if (m_ObjectsDefs[def].m_Width < 1 && m_ObjectsDefs[def].m_Width > 0)
|
||||
width *= m_TotalAvalibleColumnWidth;
|
||||
|
||||
// Clip text to the column (to prevent drawing text into the neighboring column)
|
||||
CRect cliparea2 = cliparea;
|
||||
cliparea2.right = std::min(cliparea2.right, textPos.x + width);
|
||||
cliparea2.bottom = std::min(cliparea2.bottom, textPos.y + rowHeight);
|
||||
|
||||
DrawText(objectsCount * (i+/*Heading*/1) + def, m_ObjectsDefs[def].m_TextColor, textPos, bz+0.1f, cliparea2);
|
||||
xpos += width;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,24 +17,9 @@
|
||||
#ifndef INCLUDED_COLIST
|
||||
#define INCLUDED_COLIST
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Includes / Compiler directives
|
||||
//--------------------------------------------------------
|
||||
#include "GUI.h"
|
||||
#include "CList.h"
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Macros
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Types
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Declarations
|
||||
//--------------------------------------------------------
|
||||
|
||||
struct ObjectDef
|
||||
{
|
||||
CColor m_TextColor;
|
||||
@ -45,8 +30,12 @@ struct ObjectDef
|
||||
};
|
||||
|
||||
/**
|
||||
* Todo : add description
|
||||
* Multi-column list. One row can be selected by the user.
|
||||
* Individual cells are clipped if the contained text is too long.
|
||||
*
|
||||
* The list can be sorted dynamically by JS code when a
|
||||
* heading is ckicked.
|
||||
* A scroll-bar will appear when needed.
|
||||
*/
|
||||
class COList : public CList
|
||||
{
|
||||
@ -57,20 +46,19 @@ public:
|
||||
|
||||
protected:
|
||||
void SetupText();
|
||||
void HandleMessage(SGUIMessage &Message);
|
||||
void HandleMessage(SGUIMessage& Message);
|
||||
|
||||
/**
|
||||
* Handle the \<item\> tag.
|
||||
*/
|
||||
virtual bool HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile);
|
||||
|
||||
void DrawList(const int &selected, const CStr& _sprite,
|
||||
const CStr& _sprite_selected, const CStr& _textcolor);
|
||||
void DrawList(const int& selected, const CStr& _sprite, const CStr& _sprite_selected, const CStr& _textcolor);
|
||||
|
||||
virtual CRect GetListRect() const;
|
||||
|
||||
std::vector<ObjectDef> m_ObjectsDefs;
|
||||
int m_SelectedDef;
|
||||
size_t m_SelectedDef;
|
||||
int m_SelectedColumnOrder;
|
||||
|
||||
private:
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -15,20 +15,13 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
CProgressBar
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "GUI.h"
|
||||
#include "CProgressBar.h"
|
||||
|
||||
#include "lib/ogl.h"
|
||||
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Constructor / Destructor
|
||||
//-------------------------------------------------------------------
|
||||
CProgressBar::CProgressBar()
|
||||
{
|
||||
AddSetting(GUIST_CGUISpriteInstance, "sprite_background");
|
||||
@ -42,7 +35,7 @@ CProgressBar::~CProgressBar()
|
||||
{
|
||||
}
|
||||
|
||||
void CProgressBar::HandleMessage(SGUIMessage &Message)
|
||||
void CProgressBar::HandleMessage(SGUIMessage& Message)
|
||||
{
|
||||
// Important
|
||||
IGUIObject::HandleMessage(Message);
|
||||
@ -68,25 +61,25 @@ void CProgressBar::HandleMessage(SGUIMessage &Message)
|
||||
}
|
||||
}
|
||||
|
||||
void CProgressBar::Draw()
|
||||
void CProgressBar::Draw()
|
||||
{
|
||||
if (GetGUI())
|
||||
{
|
||||
float bz = GetBufferedZ();
|
||||
if (!GetGUI())
|
||||
return;
|
||||
|
||||
CGUISpriteInstance *sprite_background, *sprite_bar;
|
||||
int cell_id = 0;
|
||||
float value = 0;
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_background", sprite_background);
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_bar", sprite_bar);
|
||||
GUI<float>::GetSetting(this, "caption", value);
|
||||
float bz = GetBufferedZ();
|
||||
|
||||
GetGUI()->DrawSprite(*sprite_background, cell_id, bz, m_CachedActualSize);
|
||||
CGUISpriteInstance* sprite_background;
|
||||
CGUISpriteInstance* sprite_bar;
|
||||
int cell_id = 0;
|
||||
float value = 0;
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_background", sprite_background);
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_bar", sprite_bar);
|
||||
GUI<float>::GetSetting(this, "caption", value);
|
||||
|
||||
GetGUI()->DrawSprite(*sprite_background, cell_id, bz, m_CachedActualSize);
|
||||
|
||||
// Get size of bar (notice it is drawn slightly closer, to appear above the background)
|
||||
CRect bar_size(m_CachedActualSize.left, m_CachedActualSize.top,
|
||||
m_CachedActualSize.left+m_CachedActualSize.GetWidth()*(value/100.f), m_CachedActualSize.bottom);
|
||||
GetGUI()->DrawSprite(*sprite_bar, cell_id, bz+0.01f, bar_size);
|
||||
}
|
||||
// Get size of bar (notice it is drawn slightly closer, to appear above the background)
|
||||
CRect bar_size(m_CachedActualSize.left, m_CachedActualSize.top,
|
||||
m_CachedActualSize.left+m_CachedActualSize.GetWidth()*(value/100.f), m_CachedActualSize.bottom);
|
||||
GetGUI()->DrawSprite(*sprite_bar, cell_id, bz+0.01f, bar_size);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -15,42 +15,14 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
GUI Object - Progress bar
|
||||
|
||||
--Overview--
|
||||
|
||||
GUI Object to show progress or a value visually.
|
||||
|
||||
--More info--
|
||||
|
||||
Check GUI.h
|
||||
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_CPROGRESSBAR
|
||||
#define INCLUDED_CPROGRESSBAR
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Includes / Compiler directives
|
||||
//--------------------------------------------------------
|
||||
#include "GUI.h"
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Macros
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Types
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Declarations
|
||||
//--------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Object used to draw a value from 0 to 100 visually.
|
||||
*
|
||||
* Object used to draw a value (e.g. progress) from 0 to 100 visually.
|
||||
*
|
||||
* @see IGUIObject
|
||||
*/
|
||||
class CProgressBar : public IGUIObject
|
||||
@ -71,7 +43,7 @@ protected:
|
||||
/**
|
||||
* @see IGUIObject#HandleMessage()
|
||||
*/
|
||||
void HandleMessage(SGUIMessage &Message);
|
||||
void HandleMessage(SGUIMessage& Message);
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // INCLUDED_CPROGRESSBAR
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -15,16 +15,13 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
CCheckBox
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
#include "GUI.h"
|
||||
|
||||
#include "CRadioButton.h"
|
||||
|
||||
#include "GUI.h"
|
||||
|
||||
void CRadioButton::HandleMessage(SGUIMessage &Message)
|
||||
void CRadioButton::HandleMessage(SGUIMessage& Message)
|
||||
{
|
||||
// Important
|
||||
IGUIButtonBehavior::HandleMessage(Message);
|
||||
@ -33,19 +30,17 @@ void CRadioButton::HandleMessage(SGUIMessage &Message)
|
||||
switch (Message.type)
|
||||
{
|
||||
case GUIM_PRESSED:
|
||||
for (IGUIObject* const& obj : *GetParent())
|
||||
{
|
||||
for (vector_pObjects::iterator it = GetParent()->ChildrenItBegin(); it != GetParent()->ChildrenItEnd(); ++it)
|
||||
{
|
||||
// Notice, if you use other objects within the parent object that has got
|
||||
// the setting "checked", it too will change. Hence NO OTHER OBJECTS THAN
|
||||
// RADIO BUTTONS SHOULD BE WITHIN IT!
|
||||
GUI<bool>::SetSetting((*it), "checked", false);
|
||||
}
|
||||
|
||||
GUI<bool>::SetSetting(this, "checked", true);
|
||||
break;
|
||||
// Notice, if you use other objects within the parent object that has got
|
||||
// the setting "checked", it too will change. Hence NO OTHER OBJECTS THAN
|
||||
// RADIO BUTTONS SHOULD BE WITHIN IT!
|
||||
GUI<bool>::SetSetting(obj, "checked", false);
|
||||
}
|
||||
|
||||
GUI<bool>::SetSetting(this, "checked", true);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -15,32 +15,16 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
GUI Object - Radio Button
|
||||
|
||||
--Overview--
|
||||
|
||||
GUI Object representing a radio button
|
||||
|
||||
--More info--
|
||||
|
||||
Check GUI.h
|
||||
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_CRADIOBUTTON
|
||||
#define INCLUDED_CRADIOBUTTON
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Includes / Compiler directives
|
||||
//--------------------------------------------------------
|
||||
#include "GUI.h"
|
||||
#include "CCheckBox.h"
|
||||
|
||||
/**
|
||||
* Just like a check box, but it'll nullify its siblings (of the same kind),
|
||||
* and it won't switch itself.
|
||||
*
|
||||
*
|
||||
* @see CCheckBox
|
||||
*/
|
||||
class CRadioButton : public CCheckBox
|
||||
@ -51,7 +35,7 @@ public:
|
||||
/**
|
||||
* @see IGUIObject#HandleMessage()
|
||||
*/
|
||||
virtual void HandleMessage(SGUIMessage &Message);
|
||||
virtual void HandleMessage(SGUIMessage& Message);
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // INCLUDED_CRADIOBUTTON
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2010 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -15,21 +15,15 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
CText
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
#include "GUI.h"
|
||||
|
||||
#include "CText.h"
|
||||
|
||||
#include "CGUIScrollBarVertical.h"
|
||||
#include "GUI.h"
|
||||
|
||||
#include "lib/ogl.h"
|
||||
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Constructor / Destructor
|
||||
//-------------------------------------------------------------------
|
||||
CText::CText()
|
||||
{
|
||||
AddSetting(GUIST_float, "buffer_zone");
|
||||
@ -56,7 +50,7 @@ CText::CText()
|
||||
GUI<bool>::SetSetting(this, "clip", true);
|
||||
|
||||
// Add scroll-bar
|
||||
CGUIScrollBarVertical * bar = new CGUIScrollBarVertical();
|
||||
CGUIScrollBarVertical* bar = new CGUIScrollBarVertical();
|
||||
bar->SetRightAligned(true);
|
||||
AddScrollBar(bar);
|
||||
|
||||
@ -92,11 +86,11 @@ void CText::SetupText()
|
||||
width -= GetScrollBar(0).GetStyle()->m_Width;
|
||||
|
||||
|
||||
float buffer_zone=0.f;
|
||||
float buffer_zone = 0.f;
|
||||
GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
|
||||
*m_GeneratedTexts[0] = GetGUI()->GenerateText(caption, font, width, buffer_zone, this);
|
||||
|
||||
if (! scrollbar)
|
||||
if (!scrollbar)
|
||||
CalculateTextPosition(m_CachedActualSize, m_TextPos, *m_GeneratedTexts[0]);
|
||||
|
||||
// Setup scrollbar
|
||||
@ -126,7 +120,7 @@ void CText::SetupText()
|
||||
}
|
||||
}
|
||||
|
||||
void CText::HandleMessage(SGUIMessage &Message)
|
||||
void CText::HandleMessage(SGUIMessage& Message)
|
||||
{
|
||||
IGUIScrollBarOwner::HandleMessage(Message);
|
||||
//IGUITextOwner::HandleMessage(Message); <== placed it after the switch instead!
|
||||
@ -135,9 +129,7 @@ void CText::HandleMessage(SGUIMessage &Message)
|
||||
{
|
||||
case GUIM_SETTINGS_UPDATED:
|
||||
if (Message.value == "scrollbar")
|
||||
{
|
||||
SetupText();
|
||||
}
|
||||
|
||||
// Update scrollbar
|
||||
if (Message.value == "scrollbar_style")
|
||||
@ -145,7 +137,7 @@ void CText::HandleMessage(SGUIMessage &Message)
|
||||
CStr scrollbar_style;
|
||||
GUI<CStr>::GetSetting(this, Message.value, scrollbar_style);
|
||||
|
||||
GetScrollBar(0).SetScrollBarStyle( scrollbar_style );
|
||||
GetScrollBar(0).SetScrollBarStyle(scrollbar_style);
|
||||
|
||||
SetupText();
|
||||
}
|
||||
@ -153,35 +145,35 @@ void CText::HandleMessage(SGUIMessage &Message)
|
||||
break;
|
||||
|
||||
case GUIM_MOUSE_WHEEL_DOWN:
|
||||
{
|
||||
{
|
||||
GetScrollBar(0).ScrollPlus();
|
||||
// Since the scroll was changed, let's simulate a mouse movement
|
||||
// to check if scrollbar now is hovered
|
||||
SGUIMessage msg(GUIM_MOUSE_MOTION);
|
||||
HandleMessage(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
case GUIM_MOUSE_WHEEL_UP:
|
||||
{
|
||||
{
|
||||
GetScrollBar(0).ScrollMinus();
|
||||
// Since the scroll was changed, let's simulate a mouse movement
|
||||
// to check if scrollbar now is hovered
|
||||
SGUIMessage msg(GUIM_MOUSE_MOTION);
|
||||
HandleMessage(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
case GUIM_LOAD:
|
||||
{
|
||||
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 );
|
||||
{
|
||||
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);
|
||||
|
||||
CStr scrollbar_style;
|
||||
GUI<CStr>::GetSetting(this, "scrollbar_style", scrollbar_style);
|
||||
GetScrollBar(0).SetScrollBarStyle( scrollbar_style );
|
||||
}
|
||||
GetScrollBar(0).SetScrollBarStyle(scrollbar_style);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
@ -190,7 +182,7 @@ void CText::HandleMessage(SGUIMessage &Message)
|
||||
IGUITextOwner::HandleMessage(Message);
|
||||
}
|
||||
|
||||
void CText::Draw()
|
||||
void CText::Draw()
|
||||
{
|
||||
float bz = GetBufferedZ();
|
||||
|
||||
@ -199,84 +191,71 @@ void CText::Draw()
|
||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
|
||||
|
||||
if (scrollbar)
|
||||
{
|
||||
// Draw scrollbar
|
||||
IGUIScrollBarOwner::Draw();
|
||||
}
|
||||
|
||||
if (GetGUI())
|
||||
if (!GetGUI())
|
||||
return;
|
||||
|
||||
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);
|
||||
|
||||
GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize);
|
||||
|
||||
float scroll = 0.f;
|
||||
if (scrollbar)
|
||||
scroll = GetScrollBar(0).GetPos();
|
||||
|
||||
// Clipping area (we'll have to subtract the scrollbar)
|
||||
CRect cliparea;
|
||||
if (clip)
|
||||
{
|
||||
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);
|
||||
|
||||
GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize);
|
||||
|
||||
float scroll=0.f;
|
||||
if (scrollbar)
|
||||
{
|
||||
scroll = GetScrollBar(0).GetPos();
|
||||
}
|
||||
|
||||
// Clipping area (we'll have to subtract the scrollbar)
|
||||
CRect cliparea;
|
||||
if (clip)
|
||||
{
|
||||
cliparea = m_CachedActualSize;
|
||||
|
||||
if (scrollbar)
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
CColor color;
|
||||
GUI<CColor>::GetSetting(this, "textcolor", color);
|
||||
cliparea = m_CachedActualSize;
|
||||
|
||||
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);
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
CColor color;
|
||||
GUI<CColor>::GetSetting(this, "textcolor", color);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
bool CText::MouseOverIcon()
|
||||
{
|
||||
std::vector<SGUIText*>::iterator text_it;
|
||||
std::list<SGUIText::SSpriteCall>::iterator sprite_it;
|
||||
|
||||
for (text_it=m_GeneratedTexts.begin(); text_it!=m_GeneratedTexts.end(); ++text_it)
|
||||
{
|
||||
SGUIText* guitext = *text_it;
|
||||
|
||||
for (sprite_it=guitext->m_SpriteCalls.begin(); sprite_it!=guitext->m_SpriteCalls.end(); ++sprite_it)
|
||||
for (SGUIText* const& guitext : m_GeneratedTexts)
|
||||
for (const SGUIText::SSpriteCall& spritecall : guitext->m_SpriteCalls)
|
||||
{
|
||||
//Check mouse over sprite
|
||||
SGUIText::SSpriteCall spritecall = *sprite_it;
|
||||
// Check mouse over sprite
|
||||
if (!spritecall.m_Area.PointInside(GetMousePos() - m_CachedActualSize.TopLeft()))
|
||||
continue;
|
||||
|
||||
if (spritecall.m_Area.PointInside(GetMousePos() - m_CachedActualSize.TopLeft()))
|
||||
// If tooltip exists, set the property
|
||||
if (!spritecall.m_Tooltip.empty())
|
||||
{
|
||||
//If tooltip exists, set the property
|
||||
if(!spritecall.m_Tooltip.empty())
|
||||
{
|
||||
SetSetting("_icon_tooltip_style", spritecall.m_TooltipStyle);
|
||||
SetSetting("_icon_tooltip", spritecall.m_Tooltip);
|
||||
}
|
||||
|
||||
return true;
|
||||
SetSetting("_icon_tooltip_style", spritecall.m_TooltipStyle);
|
||||
SetSetting("_icon_tooltip", spritecall.m_Tooltip);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -15,45 +15,14 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
GUI Object - Text [field]
|
||||
|
||||
--Overview--
|
||||
|
||||
GUI Object representing a text field
|
||||
|
||||
--More info--
|
||||
|
||||
Check GUI.h
|
||||
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_CTEXT
|
||||
#define INCLUDED_CTEXT
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Includes / Compiler directives
|
||||
//--------------------------------------------------------
|
||||
#include "GUI.h"
|
||||
|
||||
// TODO Gee: Remove
|
||||
class IGUIScrollBar;
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Macros
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Types
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Declarations
|
||||
//--------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Text field that just displays static text.
|
||||
*
|
||||
*
|
||||
* @see IGUIObject
|
||||
*/
|
||||
class CText : public IGUIScrollBarOwner, public IGUITextOwner
|
||||
@ -84,7 +53,7 @@ protected:
|
||||
/**
|
||||
* @see IGUIObject#HandleMessage()
|
||||
*/
|
||||
virtual void HandleMessage(SGUIMessage &Message);
|
||||
virtual void HandleMessage(SGUIMessage& Message);
|
||||
|
||||
/**
|
||||
* Draws the Text
|
||||
@ -97,4 +66,4 @@ protected:
|
||||
CPos m_TextPos;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // INCLUDED_CTEXT
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2013 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -15,8 +15,6 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// CTooltip: GUI object used for tooltips
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "CTooltip.h"
|
||||
@ -66,7 +64,7 @@ void CTooltip::SetupText()
|
||||
if (!GetGUI())
|
||||
return;
|
||||
|
||||
ENSURE(m_GeneratedTexts.size()==1);
|
||||
ENSURE(m_GeneratedTexts.size() == 1);
|
||||
|
||||
CStrW font;
|
||||
if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_OK || font.empty())
|
||||
@ -89,7 +87,7 @@ void CTooltip::SetupText()
|
||||
CPos mousepos, offset;
|
||||
EVAlign anchor;
|
||||
bool independent;
|
||||
|
||||
|
||||
GUI<bool>::GetSetting(this, "independent", independent);
|
||||
if (independent)
|
||||
mousepos = GetMousePos();
|
||||
@ -144,33 +142,33 @@ void CTooltip::SetupText()
|
||||
GUI<CClientArea>::SetSetting(this, "size", size);
|
||||
}
|
||||
|
||||
void CTooltip::HandleMessage(SGUIMessage &Message)
|
||||
void CTooltip::HandleMessage(SGUIMessage& Message)
|
||||
{
|
||||
IGUITextOwner::HandleMessage(Message);
|
||||
}
|
||||
|
||||
void CTooltip::Draw()
|
||||
void CTooltip::Draw()
|
||||
{
|
||||
if (!GetGUI())
|
||||
return;
|
||||
|
||||
float z = 900.f; // TODO: Find a nicer way of putting the tooltip on top of everything else
|
||||
|
||||
if (GetGUI())
|
||||
CGUISpriteInstance* sprite;
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
|
||||
|
||||
// Normally IGUITextOwner will handle this updating but since SetupText can modify the position
|
||||
// we need to call it now *before* we do the rest of the drawing
|
||||
if (!m_GeneratedTextsValid)
|
||||
{
|
||||
CGUISpriteInstance *sprite;
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
|
||||
|
||||
// Normally IGUITextOwner will handle this updating but since SetupText can modify the position
|
||||
// we need to call it now *before* we do the rest of the drawing
|
||||
if (!m_GeneratedTextsValid)
|
||||
{
|
||||
SetupText();
|
||||
m_GeneratedTextsValid = true;
|
||||
}
|
||||
|
||||
GetGUI()->DrawSprite(*sprite, 0, z, m_CachedActualSize);
|
||||
|
||||
CColor color;
|
||||
GUI<CColor>::GetSetting(this, "textcolor", color);
|
||||
|
||||
DrawText(0, color, m_CachedActualSize.TopLeft(), z+0.1f);
|
||||
SetupText();
|
||||
m_GeneratedTextsValid = true;
|
||||
}
|
||||
|
||||
GetGUI()->DrawSprite(*sprite, 0, z, m_CachedActualSize);
|
||||
|
||||
CColor color;
|
||||
GUI<CColor>::GetSetting(this, "textcolor", color);
|
||||
|
||||
DrawText(0, color, m_CachedActualSize.TopLeft(), z+0.1f);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -15,20 +15,14 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
GUI Object - Tooltip
|
||||
|
||||
--Overview--
|
||||
|
||||
Mostly like CText, but intended for dynamic tooltips
|
||||
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_CTOOLTIP
|
||||
#define INCLUDED_CTOOLTIP
|
||||
|
||||
#include "IGUITextOwner.h"
|
||||
|
||||
/**
|
||||
* Dynamic tooltips. Similar to CText.
|
||||
*/
|
||||
class CTooltip : public IGUITextOwner
|
||||
{
|
||||
GUI_OBJECT(CTooltip)
|
||||
@ -43,9 +37,9 @@ protected:
|
||||
/**
|
||||
* @see IGUIObject#HandleMessage()
|
||||
*/
|
||||
virtual void HandleMessage(SGUIMessage &Message);
|
||||
virtual void HandleMessage(SGUIMessage& Message);
|
||||
|
||||
virtual void Draw();
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // INCLUDED_CTOOLTIP
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -32,24 +32,21 @@ GUI Inclusion file
|
||||
#ifndef INCLUDED_GUI
|
||||
#define INCLUDED_GUI
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Includes
|
||||
//--------------------------------------------------------
|
||||
#include <map>
|
||||
#include <stddef.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "ps/CStr.h"
|
||||
|
||||
#include "GUIbase.h"
|
||||
#include "GUIutil.h"
|
||||
#include "GUItext.h"
|
||||
#include "CGUIList.h"
|
||||
#include "IGUIObject.h"
|
||||
#include "GUIbase.h"
|
||||
#include "GUItext.h"
|
||||
#include "GUIutil.h"
|
||||
#include "IGUIButtonBehavior.h"
|
||||
#include "IGUIScrollBarOwner.h"
|
||||
#include "IGUITextOwner.h"
|
||||
#include "IGUIObject.h"
|
||||
#include "IGUIScrollBarOwner.h" // Required by IGUIScrollBar
|
||||
#include "IGUIScrollBar.h"
|
||||
#include "IGUITextOwner.h"
|
||||
|
||||
#endif
|
||||
#endif // INCLUDED_GUI
|
||||
|
@ -114,31 +114,31 @@ void CGUIManager::PopPageCB(shared_ptr<ScriptInterface::StructuredClone> args)
|
||||
{
|
||||
shared_ptr<ScriptInterface::StructuredClone> initDataClone = m_PageStack.back().initData;
|
||||
PopPage();
|
||||
|
||||
|
||||
shared_ptr<ScriptInterface> scriptInterface = m_PageStack.back().gui->GetScriptInterface();
|
||||
JSContext* cx = scriptInterface->GetContext();
|
||||
JS::RootedValue initDataVal(cx);
|
||||
if (initDataClone)
|
||||
scriptInterface->ReadStructuredClone(initDataClone, &initDataVal);
|
||||
else
|
||||
if (!initDataClone)
|
||||
{
|
||||
LOGERROR("Called PopPageCB when initData (which should contain the callback function name) isn't set!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
scriptInterface->ReadStructuredClone(initDataClone, &initDataVal);
|
||||
|
||||
if (!scriptInterface->HasProperty(initDataVal, "callback"))
|
||||
{
|
||||
LOGERROR("Called PopPageCB when the callback function name isn't set!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
std::string callback;
|
||||
if (!scriptInterface->GetProperty(initDataVal, "callback", callback))
|
||||
{
|
||||
LOGERROR("Failed to get the callback property as a string from initData in PopPageCB!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
JS::RootedValue global(cx, scriptInterface->GetGlobalObject());
|
||||
if (!scriptInterface->HasProperty(global, callback.c_str()))
|
||||
{
|
||||
@ -182,13 +182,13 @@ void CGUIManager::LoadPage(SGUIPage& page)
|
||||
shared_ptr<ScriptInterface> scriptInterface = page.gui->GetScriptInterface();
|
||||
JSContext* cx = scriptInterface->GetContext();
|
||||
JSAutoRequest rq(cx);
|
||||
|
||||
|
||||
JS::RootedValue global(cx, scriptInterface->GetGlobalObject());
|
||||
JS::RootedValue hotloadDataVal(cx);
|
||||
scriptInterface->CallFunction(global, "getHotloadData", &hotloadDataVal);
|
||||
scriptInterface->CallFunction(global, "getHotloadData", &hotloadDataVal);
|
||||
hotloadData = scriptInterface->WriteStructuredClone(hotloadDataVal);
|
||||
}
|
||||
|
||||
|
||||
page.inputs.clear();
|
||||
page.gui.reset(new CGUI(m_ScriptRuntime));
|
||||
|
||||
@ -252,20 +252,20 @@ void CGUIManager::LoadPage(SGUIPage& page)
|
||||
shared_ptr<ScriptInterface> scriptInterface = page.gui->GetScriptInterface();
|
||||
JSContext* cx = scriptInterface->GetContext();
|
||||
JSAutoRequest rq(cx);
|
||||
|
||||
|
||||
JS::RootedValue initDataVal(cx);
|
||||
JS::RootedValue hotloadDataVal(cx);
|
||||
JS::RootedValue global(cx, scriptInterface->GetGlobalObject());
|
||||
if (page.initData)
|
||||
if (page.initData)
|
||||
scriptInterface->ReadStructuredClone(page.initData, &initDataVal);
|
||||
if (hotloadData)
|
||||
scriptInterface->ReadStructuredClone(hotloadData, &hotloadDataVal);
|
||||
|
||||
|
||||
// Call the init() function
|
||||
if (!scriptInterface->CallFunctionVoid(
|
||||
global,
|
||||
"init",
|
||||
initDataVal,
|
||||
global,
|
||||
"init",
|
||||
initDataVal,
|
||||
hotloadDataVal)
|
||||
)
|
||||
{
|
||||
@ -277,15 +277,13 @@ void CGUIManager::LoadPage(SGUIPage& page)
|
||||
|
||||
Status CGUIManager::ReloadChangedFile(const VfsPath& path)
|
||||
{
|
||||
for (PageStackType::iterator it = m_PageStack.begin(); it != m_PageStack.end(); ++it)
|
||||
{
|
||||
if (it->inputs.count(path))
|
||||
for (SGUIPage& p : m_PageStack)
|
||||
if (p.inputs.count(path))
|
||||
{
|
||||
LOGMESSAGE("GUI file '%s' changed - reloading page '%s'", path.string8(), utf8_from_wstring(it->name));
|
||||
LoadPage(*it);
|
||||
LOGMESSAGE("GUI file '%s' changed - reloading page '%s'", path.string8(), utf8_from_wstring(p.name));
|
||||
LoadPage(p);
|
||||
// TODO: this can crash if LoadPage runs an init script which modifies the page stack and breaks our iterators
|
||||
}
|
||||
}
|
||||
|
||||
return INFO::OK;
|
||||
}
|
||||
@ -293,8 +291,8 @@ Status CGUIManager::ReloadChangedFile(const VfsPath& path)
|
||||
Status CGUIManager::ReloadAllPages()
|
||||
{
|
||||
// TODO: this can crash if LoadPage runs an init script which modifies the page stack and breaks our iterators
|
||||
for (PageStackType::iterator it = m_PageStack.begin(); it != m_PageStack.end(); ++it)
|
||||
LoadPage(*it);
|
||||
for (SGUIPage& p : m_PageStack)
|
||||
LoadPage(p);
|
||||
|
||||
return INFO::OK;
|
||||
}
|
||||
@ -304,7 +302,7 @@ std::string CGUIManager::GetSavedGameData()
|
||||
shared_ptr<ScriptInterface> scriptInterface = top()->GetScriptInterface();
|
||||
JSContext* cx = scriptInterface->GetContext();
|
||||
JSAutoRequest rq(cx);
|
||||
|
||||
|
||||
JS::RootedValue data(cx);
|
||||
JS::RootedValue global(cx, top()->GetGlobalObject());
|
||||
scriptInterface->CallFunction(global, "getSavedGameData", &data);
|
||||
@ -316,7 +314,7 @@ void CGUIManager::RestoreSavedGameData(std::string jsonData)
|
||||
shared_ptr<ScriptInterface> scriptInterface = top()->GetScriptInterface();
|
||||
JSContext* cx = scriptInterface->GetContext();
|
||||
JSAutoRequest rq(cx);
|
||||
|
||||
|
||||
JS::RootedValue global(cx, top()->GetGlobalObject());
|
||||
JS::RootedValue dataVal(cx);
|
||||
scriptInterface->ParseJSON(jsonData, &dataVal);
|
||||
@ -331,7 +329,7 @@ InReaction CGUIManager::HandleEvent(const SDL_Event_* ev)
|
||||
// visible game area), sometimes they'll want to intercepts events before the GUI (e.g.
|
||||
// to capture all mouse events until a mouseup after dragging).
|
||||
// So we call two separate handler functions:
|
||||
|
||||
|
||||
bool handled;
|
||||
|
||||
{
|
||||
@ -367,7 +365,7 @@ InReaction CGUIManager::HandleEvent(const SDL_Event_* ev)
|
||||
}
|
||||
|
||||
|
||||
bool CGUIManager::GetPreDefinedColor(const CStr& name, CColor& output)
|
||||
bool CGUIManager::GetPreDefinedColor(const CStr& name, CColor& output) const
|
||||
{
|
||||
return top()->GetPreDefinedColor(name, output);
|
||||
}
|
||||
@ -382,7 +380,7 @@ IGUIObject* CGUIManager::FindObjectByName(const CStr& name) const
|
||||
return top()->FindObjectByName(name);
|
||||
}
|
||||
|
||||
void CGUIManager::SendEventToAll(const CStr& eventName)
|
||||
void CGUIManager::SendEventToAll(const CStr& eventName) const
|
||||
{
|
||||
top()->SendEventToAll(eventName);
|
||||
}
|
||||
@ -394,14 +392,14 @@ void CGUIManager::TickObjects()
|
||||
// We share the script runtime with everything else that runs in the same thread.
|
||||
// This call makes sure we trigger GC regularly even if the simulation is not running.
|
||||
m_ScriptInterface->GetRuntime()->MaybeIncrementalGC(1.0f);
|
||||
|
||||
|
||||
// Save an immutable copy so iterators aren't invalidated by tick handlers
|
||||
PageStackType pageStack = m_PageStack;
|
||||
|
||||
for (PageStackType::iterator it = pageStack.begin(); it != pageStack.end(); ++it)
|
||||
for (const SGUIPage& p : pageStack)
|
||||
{
|
||||
m_CurrentGUI = it->gui;
|
||||
it->gui->TickObjects();
|
||||
m_CurrentGUI = p.gui;
|
||||
p.gui->TickObjects();
|
||||
}
|
||||
m_CurrentGUI.reset();
|
||||
}
|
||||
@ -410,17 +408,17 @@ void CGUIManager::Draw()
|
||||
{
|
||||
PROFILE3_GPU("gui");
|
||||
|
||||
for (PageStackType::iterator it = m_PageStack.begin(); it != m_PageStack.end(); ++it)
|
||||
it->gui->Draw();
|
||||
for (const SGUIPage& p : m_PageStack)
|
||||
p.gui->Draw();
|
||||
}
|
||||
|
||||
void CGUIManager::UpdateResolution()
|
||||
{
|
||||
for (PageStackType::iterator it = m_PageStack.begin(); it != m_PageStack.end(); ++it)
|
||||
it->gui->UpdateResolution();
|
||||
for (const SGUIPage& p : m_PageStack)
|
||||
p.gui->UpdateResolution();
|
||||
}
|
||||
|
||||
bool CGUIManager::TemplateExists(const std::string& templateName)
|
||||
bool CGUIManager::TemplateExists(const std::string& templateName) const
|
||||
{
|
||||
return m_TemplateLoader.TemplateExists(templateName);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2014 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -19,6 +19,7 @@
|
||||
#define INCLUDED_GUIMANAGER
|
||||
|
||||
#include <boost/unordered_set.hpp>
|
||||
#include <set>
|
||||
|
||||
#include "lib/input.h"
|
||||
#include "lib/file/vfs/vfs_path.h"
|
||||
@ -28,8 +29,6 @@
|
||||
#include "scriptinterface/ScriptVal.h"
|
||||
#include "scriptinterface/ScriptInterface.h"
|
||||
|
||||
#include <set>
|
||||
|
||||
class CGUI;
|
||||
class JSObject;
|
||||
class IGUIObject;
|
||||
@ -52,9 +51,9 @@ public:
|
||||
CGUIManager();
|
||||
~CGUIManager();
|
||||
|
||||
shared_ptr<ScriptInterface> GetScriptInterface()
|
||||
{
|
||||
return m_ScriptInterface;
|
||||
shared_ptr<ScriptInterface> GetScriptInterface()
|
||||
{
|
||||
return m_ScriptInterface;
|
||||
}
|
||||
shared_ptr<ScriptRuntime> GetRuntime() { return m_ScriptRuntime; }
|
||||
shared_ptr<CGUI> GetActiveGUI() { return top(); }
|
||||
@ -106,7 +105,7 @@ public:
|
||||
/**
|
||||
* See CGUI::GetPreDefinedColor; applies to the currently active page.
|
||||
*/
|
||||
bool GetPreDefinedColor(const CStr& name, CColor& output);
|
||||
bool GetPreDefinedColor(const CStr& name, CColor& output) const;
|
||||
|
||||
/**
|
||||
* See CGUI::FindObjectByName; applies to the currently active page.
|
||||
@ -116,7 +115,7 @@ public:
|
||||
/**
|
||||
* See CGUI::SendEventToAll; applies to the currently active page.
|
||||
*/
|
||||
void SendEventToAll(const CStr& eventName);
|
||||
void SendEventToAll(const CStr& eventName) const;
|
||||
|
||||
/**
|
||||
* See CGUI::TickObjects; applies to @em all loaded pages.
|
||||
@ -137,13 +136,13 @@ public:
|
||||
* Calls the current page's script function getSavedGameData() and returns the result.
|
||||
*/
|
||||
std::string GetSavedGameData();
|
||||
|
||||
|
||||
void RestoreSavedGameData(std::string jsonData);
|
||||
|
||||
/**
|
||||
* Check if a template with this name exists
|
||||
*/
|
||||
bool TemplateExists(const std::string& templateName);
|
||||
bool TemplateExists(const std::string& templateName) const;
|
||||
|
||||
/**
|
||||
* Retrieve the requested template, used for displaying faction specificities.
|
||||
@ -166,7 +165,7 @@ private:
|
||||
void LoadPage(SGUIPage& page);
|
||||
|
||||
shared_ptr<CGUI> top() const;
|
||||
|
||||
|
||||
shared_ptr<CGUI> m_CurrentGUI; // used to latch state during TickObjects/LoadPage (this is kind of ugly)
|
||||
shared_ptr<ScriptRuntime> m_ScriptRuntime;
|
||||
shared_ptr<ScriptInterface> m_ScriptInterface;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2014 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -57,7 +57,7 @@ DrawCalls& DrawCalls::operator=(const DrawCalls&)
|
||||
}
|
||||
|
||||
|
||||
void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, const CStr& SpriteName, const CRect &Size, int CellID, std::map<CStr, CGUISprite*> &Sprites)
|
||||
void GUIRenderer::UpdateDrawCallCache(DrawCalls& Calls, const CStr& SpriteName, const CRect& Size, int CellID, std::map<CStr, CGUISprite*>& Sprites)
|
||||
{
|
||||
// This is called only when something has changed (like the size of the
|
||||
// sprite), so it doesn't need to be particularly efficient.
|
||||
@ -72,7 +72,7 @@ void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, const CStr& SpriteName,
|
||||
return;
|
||||
|
||||
|
||||
std::map<CStr, CGUISprite*>::iterator it (Sprites.find(SpriteName));
|
||||
std::map<CStr, CGUISprite*>::iterator it(Sprites.find(SpriteName));
|
||||
if (it == Sprites.end())
|
||||
{
|
||||
// Sprite not found. Check whether this a special sprite:
|
||||
@ -86,7 +86,7 @@ void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, const CStr& SpriteName,
|
||||
{
|
||||
// TODO: Should check (nicely) that this is a valid file?
|
||||
SGUIImage* Image = new SGUIImage;
|
||||
|
||||
|
||||
// Allow grayscale images for disabled portraits
|
||||
if (SpriteName.substr(10, 10) == "grayscale:")
|
||||
{
|
||||
@ -107,7 +107,7 @@ void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, const CStr& SpriteName,
|
||||
Sprite->AddImage(Image);
|
||||
|
||||
Sprites[SpriteName] = Sprite;
|
||||
|
||||
|
||||
it = Sprites.find(SpriteName);
|
||||
ENSURE(it != Sprites.end()); // The insertion above shouldn't fail
|
||||
}
|
||||
@ -118,9 +118,9 @@ void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, const CStr& SpriteName,
|
||||
|
||||
double xRatio = SpriteName.BeforeFirst(",").AfterLast("(").ToDouble();
|
||||
double yRatio = SpriteName.BeforeFirst(")").AfterLast(",").ToDouble();
|
||||
|
||||
|
||||
int PathStart = SpriteName.Find(")") + 1;
|
||||
|
||||
|
||||
Image->m_TextureName = VfsPath("art/textures/ui") / wstring_from_utf8(SpriteName.substr(PathStart));
|
||||
|
||||
CClientArea ca(CRect(0, 0, 0, 0), CRect(0, 0, 100, 100));
|
||||
@ -132,7 +132,7 @@ void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, const CStr& SpriteName,
|
||||
Sprite->AddImage(Image);
|
||||
|
||||
Sprites[SpriteName] = Sprite;
|
||||
|
||||
|
||||
it = Sprites.find(SpriteName);
|
||||
ENSURE(it != Sprites.end()); // The insertion above shouldn't fail
|
||||
}
|
||||
@ -263,9 +263,7 @@ CRect SDrawCall::ComputeTexCoords() const
|
||||
float TexHeight = m_Texture->GetHeight();
|
||||
|
||||
if (!TexWidth || !TexHeight)
|
||||
{
|
||||
return CRect(0, 0, 1, 1);
|
||||
}
|
||||
|
||||
// Textures are positioned by defining a rectangular block of the
|
||||
// texture (usually the whole texture), and a rectangular block on
|
||||
@ -329,7 +327,7 @@ CRect SDrawCall::ComputeTexCoords() const
|
||||
return TexCoords;
|
||||
}
|
||||
|
||||
void GUIRenderer::Draw(DrawCalls &Calls, float Z)
|
||||
void GUIRenderer::Draw(DrawCalls& Calls, float Z)
|
||||
{
|
||||
// Called every frame, to draw the object (based on cached calculations)
|
||||
|
||||
@ -439,7 +437,7 @@ void GUIRenderer::Draw(DrawCalls &Calls, float Z)
|
||||
}
|
||||
#undef ADD
|
||||
}
|
||||
|
||||
|
||||
cit->m_Shader->EndPass();
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2013 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -15,14 +15,15 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GUIRenderer_h
|
||||
#define GUIRenderer_h
|
||||
#ifndef INCLUDED_GUIRENDERER
|
||||
#define INCLUDED_GUIRENDERER
|
||||
|
||||
#include "graphics/ShaderTechnique.h"
|
||||
#include "graphics/Texture.h"
|
||||
#include "lib/res/handle.h"
|
||||
#include "ps/CStr.h"
|
||||
#include "ps/Shapes.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
struct SGUIImageEffects;
|
||||
@ -34,8 +35,8 @@ namespace GUIRenderer
|
||||
{
|
||||
public:
|
||||
virtual ~IGLState() {};
|
||||
virtual void Set(const CTexturePtr& tex)=0;
|
||||
virtual void Unset()=0;
|
||||
virtual void Set(const CTexturePtr& tex) = 0;
|
||||
virtual void Unset() = 0;
|
||||
};
|
||||
|
||||
struct SDrawCall
|
||||
@ -77,9 +78,9 @@ namespace GUIRenderer
|
||||
|
||||
namespace GUIRenderer
|
||||
{
|
||||
void UpdateDrawCallCache(DrawCalls &Calls, const CStr& SpriteName, const CRect& Size, int CellID, std::map<CStr, CGUISprite*> &Sprites);
|
||||
void UpdateDrawCallCache(DrawCalls& Calls, const CStr& SpriteName, const CRect& Size, int CellID, std::map<CStr, CGUISprite*>& Sprites);
|
||||
|
||||
void Draw(DrawCalls &Calls, float Z);
|
||||
void Draw(DrawCalls& Calls, float Z);
|
||||
}
|
||||
|
||||
#endif // GUIRenderer_h
|
||||
#endif // INCLUDED_GUIRENDERER
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -18,11 +18,12 @@
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "GUITooltip.h"
|
||||
#include "lib/timer.h"
|
||||
#include "IGUIObject.h"
|
||||
|
||||
#include "CGUI.h"
|
||||
#include "GUIutil.h"
|
||||
#include "IGUIObject.h"
|
||||
|
||||
#include "lib/timer.h"
|
||||
#include "ps/CLogger.h"
|
||||
|
||||
/*
|
||||
@ -137,7 +138,7 @@ bool GUITooltip::GetTooltip(IGUIObject* obj, CStr& style)
|
||||
return false;
|
||||
}
|
||||
|
||||
void GUITooltip::ShowTooltip(IGUIObject* obj, CPos pos, const CStr& style, CGUI* gui)
|
||||
void GUITooltip::ShowTooltip(IGUIObject* obj, const CPos& pos, const CStr& style, CGUI* gui)
|
||||
{
|
||||
ENSURE(obj);
|
||||
|
||||
@ -147,7 +148,7 @@ void GUITooltip::ShowTooltip(IGUIObject* obj, CPos pos, const CStr& style, CGUI*
|
||||
|
||||
// Get the object referenced by 'tooltip_style'
|
||||
IGUIObject* tooltipobj = gui->FindObjectByName("__tooltip_"+style);
|
||||
if (! tooltipobj)
|
||||
if (!tooltipobj)
|
||||
{
|
||||
LOGERROR("Cannot find tooltip named '%s'", style.c_str());
|
||||
return;
|
||||
@ -160,7 +161,7 @@ void GUITooltip::ShowTooltip(IGUIObject* obj, CPos pos, const CStr& style, CGUI*
|
||||
&& !usedObjectName.empty())
|
||||
{
|
||||
usedobj = gui->FindObjectByName(usedObjectName);
|
||||
if (! usedobj)
|
||||
if (!usedobj)
|
||||
{
|
||||
LOGERROR("Cannot find object named '%s' used by tooltip '%s'", usedObjectName.c_str(), style.c_str());
|
||||
return;
|
||||
@ -211,7 +212,7 @@ void GUITooltip::HideTooltip(const CStr& style, CGUI* gui)
|
||||
return;
|
||||
|
||||
IGUIObject* tooltipobj = gui->FindObjectByName("__tooltip_"+style);
|
||||
if (! tooltipobj)
|
||||
if (!tooltipobj)
|
||||
{
|
||||
LOGERROR("Cannot find tooltip named '%s'", style.c_str());
|
||||
return;
|
||||
@ -222,7 +223,7 @@ void GUITooltip::HideTooltip(const CStr& style, CGUI* gui)
|
||||
&& !usedObjectName.empty())
|
||||
{
|
||||
IGUIObject* usedobj = gui->FindObjectByName(usedObjectName);
|
||||
if (! usedobj)
|
||||
if (!usedobj)
|
||||
{
|
||||
LOGERROR("Cannot find object named '%s' used by tooltip '%s'", usedObjectName.c_str(), style.c_str());
|
||||
return;
|
||||
@ -247,12 +248,12 @@ void GUITooltip::HideTooltip(const CStr& style, CGUI* gui)
|
||||
|
||||
}
|
||||
|
||||
static int GetTooltipDelay(CStr& style, CGUI* gui)
|
||||
static int GetTooltipDelay(const CStr& style, CGUI* gui)
|
||||
{
|
||||
int delay = 500; // default value (in msec)
|
||||
|
||||
IGUIObject* tooltipobj = gui->FindObjectByName("__tooltip_"+style);
|
||||
if (! tooltipobj)
|
||||
if (!tooltipobj)
|
||||
{
|
||||
LOGERROR("Cannot find tooltip object named '%s'", style.c_str());
|
||||
return delay;
|
||||
@ -261,7 +262,7 @@ static int GetTooltipDelay(CStr& style, CGUI* gui)
|
||||
return delay;
|
||||
}
|
||||
|
||||
void GUITooltip::Update(IGUIObject* Nearest, CPos MousePos, CGUI* GUI)
|
||||
void GUITooltip::Update(IGUIObject* Nearest, const CPos& MousePos, CGUI* GUI)
|
||||
{
|
||||
// Called once per frame, so efficiency isn't vital
|
||||
|
||||
@ -331,16 +332,16 @@ void GUITooltip::Update(IGUIObject* Nearest, CPos MousePos, CGUI* GUI)
|
||||
// Mouse moved onto a new object
|
||||
|
||||
if (GetTooltip(Nearest, style))
|
||||
{
|
||||
{
|
||||
CStr style_old;
|
||||
|
||||
// If we're displaying a tooltip with no delay, then we want to
|
||||
// If we're displaying a tooltip with no delay, then we want to
|
||||
// reset so that other object that should have delay can't
|
||||
// "ride this tail", it have to wait.
|
||||
// Notice that this doesn't apply to when you go from one delay=0
|
||||
// to another delay=0
|
||||
if (GetTooltip(m_PreviousObject, style_old) && GetTooltipDelay(style_old, GUI)==0 &&
|
||||
GetTooltipDelay(style, GUI)!=0)
|
||||
if (GetTooltip(m_PreviousObject, style_old) && GetTooltipDelay(style_old, GUI) == 0 &&
|
||||
GetTooltipDelay(style, GUI) != 0)
|
||||
{
|
||||
HideTooltip(m_PreviousTooltipName, GUI);
|
||||
nextstate = ST_IN_MOTION;
|
||||
@ -353,7 +354,7 @@ void GUITooltip::Update(IGUIObject* Nearest, CPos MousePos, CGUI* GUI)
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
nextstate = ST_COOLING;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -28,11 +28,11 @@ class GUITooltip
|
||||
{
|
||||
public:
|
||||
GUITooltip();
|
||||
void Update(IGUIObject* Nearest, CPos MousePos, CGUI* GUI);
|
||||
void Update(IGUIObject* Nearest, const CPos& MousePos, CGUI* GUI);
|
||||
|
||||
private:
|
||||
|
||||
void ShowTooltip(IGUIObject* obj, CPos pos, const CStr& style, CGUI* gui);
|
||||
void ShowTooltip(IGUIObject* obj, const CPos& pos, const CStr& style, CGUI* gui);
|
||||
void HideTooltip(const CStr& style, CGUI* gui);
|
||||
bool GetTooltip(IGUIObject* obj, CStr& style);
|
||||
|
||||
|
@ -15,18 +15,11 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
GUI base
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "ps/CLogger.h"
|
||||
#include "GUI.h"
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Help Classes/Structs for the GUI implementation
|
||||
//--------------------------------------------------------
|
||||
#include "ps/CLogger.h"
|
||||
|
||||
CClientArea::CClientArea() : pixel(0.f,0.f,0.f,0.f), percent(0.f,0.f,0.f,0.f)
|
||||
{
|
||||
@ -42,7 +35,7 @@ CClientArea::CClientArea(const CRect& pixel, const CRect& percent)
|
||||
{
|
||||
}
|
||||
|
||||
CRect CClientArea::GetClientArea(const CRect &parent) const
|
||||
CRect CClientArea::GetClientArea(const CRect& parent) const
|
||||
{
|
||||
// If it's a 0 0 100% 100% we need no calculations
|
||||
if (percent == CRect(0.f,0.f,100.f,100.f) && pixel == CRect(0.f,0.f,0.f,0.f))
|
||||
@ -78,7 +71,7 @@ bool CClientArea::SetClientArea(const CStr& Value)
|
||||
unsigned int coord = 0;
|
||||
float pixels[4] = {0, 0, 0, 0};
|
||||
float percents[4] = {0, 0, 0, 0};
|
||||
for (unsigned int i = 0; i < Value.length(); i++)
|
||||
for (unsigned int i = 0; i < Value.length(); ++i)
|
||||
{
|
||||
switch (input[i])
|
||||
{
|
||||
@ -110,7 +103,7 @@ bool CClientArea::SetClientArea(const CStr& Value)
|
||||
case ' ':
|
||||
pixels[coord] += buffer.ToFloat();
|
||||
buffer = "";
|
||||
coord++;
|
||||
++coord;
|
||||
break;
|
||||
default:
|
||||
LOGWARNING("ClientArea definitions may only contain numerics. Your input: '%s'", Value.c_str());
|
||||
@ -143,9 +136,3 @@ bool CClientArea::SetClientArea(const CStr& Value)
|
||||
percent.bottom = percents[3];
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Error definitions
|
||||
//--------------------------------------------------------
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -20,7 +20,7 @@ GUI Core, stuff that the whole GUI uses
|
||||
|
||||
--Overview--
|
||||
|
||||
Contains defines, includes, types etc that the whole
|
||||
Contains defines, includes, types etc that the whole
|
||||
GUI should have included.
|
||||
|
||||
--More info--
|
||||
@ -32,43 +32,25 @@ GUI Core, stuff that the whole GUI uses
|
||||
#ifndef INCLUDED_GUIBASE
|
||||
#define INCLUDED_GUIBASE
|
||||
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Includes / Compiler directives
|
||||
//--------------------------------------------------------
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "ps/CStr.h"
|
||||
#include "ps/Errors.h"
|
||||
// I would like to just forward declare CSize, but it doesn't
|
||||
// seem to be defined anywhere in the predefined header.
|
||||
#include "ps/Shapes.h"
|
||||
|
||||
#include "ps/CStr.h"
|
||||
|
||||
#include "ps/Errors.h"
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Forward declarations
|
||||
//--------------------------------------------------------
|
||||
class IGUIObject;
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Macros
|
||||
//--------------------------------------------------------
|
||||
|
||||
// Object settings setups
|
||||
|
||||
// Setup an object's ConstructObject function
|
||||
#define GUI_OBJECT(obj) \
|
||||
public: \
|
||||
static IGUIObject *ConstructObject() { return new obj(); }
|
||||
static IGUIObject* ConstructObject() { return new obj(); }
|
||||
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Types
|
||||
//--------------------------------------------------------
|
||||
|
||||
/**
|
||||
/**
|
||||
* Message types.
|
||||
* @see SGUIMessage
|
||||
*/
|
||||
@ -96,7 +78,7 @@ enum EGUIMessageType
|
||||
GUIM_LOST_FOCUS,
|
||||
GUIM_PRESSED_MOUSE_RIGHT,
|
||||
GUIM_DOUBLE_PRESSED_MOUSE_RIGHT,
|
||||
GUIM_TAB // Used by CInput
|
||||
GUIM_TAB // Used by CInput
|
||||
};
|
||||
|
||||
/**
|
||||
@ -193,14 +175,14 @@ public:
|
||||
/**
|
||||
* Get client area rectangle when the parent is given
|
||||
*/
|
||||
CRect GetClientArea(const CRect &parent) const;
|
||||
CRect GetClientArea(const CRect& parent) const;
|
||||
|
||||
/**
|
||||
* The ClientArea can be set from a string looking like:
|
||||
*
|
||||
* "0 0 100% 100%"
|
||||
* "50%-10 50%-10 50%+10 50%+10"
|
||||
*
|
||||
*
|
||||
* i.e. First percent modifier, then + or - and the pixel modifier.
|
||||
* Although you can use just the percent or the pixel modifier. Notice
|
||||
* though that the percent modifier must always be the first when
|
||||
@ -217,9 +199,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Error declarations
|
||||
//--------------------------------------------------------
|
||||
|
||||
ERROR_GROUP(GUI);
|
||||
|
||||
ERROR_TYPE(GUI, NullObjectProvided);
|
||||
@ -228,4 +208,4 @@ ERROR_TYPE(GUI, OperationNeedsGUIObject);
|
||||
ERROR_TYPE(GUI, NameAmbiguity);
|
||||
ERROR_TYPE(GUI, ObjectNeedsName);
|
||||
|
||||
#endif
|
||||
#endif // INCLUDED_GUIBASE
|
||||
|
@ -44,15 +44,10 @@ void CGUIString::SFeedback::Reset()
|
||||
m_TextCalls.clear();
|
||||
m_SpriteCalls.clear();
|
||||
m_Size = CSize();
|
||||
m_NewLine=false;
|
||||
m_NewLine = false;
|
||||
}
|
||||
|
||||
void CGUIString::GenerateTextCall(const CGUI* pGUI,
|
||||
SFeedback& Feedback,
|
||||
CStrIntern DefaultFont,
|
||||
const int& from, const int& to,
|
||||
const bool FirstLine,
|
||||
const IGUIObject* pObject) const
|
||||
void CGUIString::GenerateTextCall(const CGUI* pGUI, SFeedback& Feedback, CStrIntern DefaultFont, const int& from, const int& to, const bool FirstLine, const IGUIObject* pObject) const
|
||||
{
|
||||
// Reset width and height, because they will be determined with incrementation
|
||||
// or comparisons.
|
||||
@ -247,7 +242,7 @@ bool CGUIString::TextChunk::Tag::SetTagType(const CStrW& tagtype)
|
||||
return true;
|
||||
}
|
||||
|
||||
CGUIString::TextChunk::Tag::TagType CGUIString::TextChunk::Tag::GetTagType(const CStrW& tagtype)
|
||||
CGUIString::TextChunk::Tag::TagType CGUIString::TextChunk::Tag::GetTagType(const CStrW& tagtype) const
|
||||
{
|
||||
if (tagtype == L"color")
|
||||
return TAG_COLOR;
|
||||
@ -473,18 +468,5 @@ void CGUIString::SetValue(const CStrW& str)
|
||||
if (m_Words.size() <= 2)
|
||||
return;
|
||||
|
||||
std::vector<int>::iterator it;
|
||||
int last_word = -1;
|
||||
for (it = m_Words.begin(); it != m_Words.end(); )
|
||||
{
|
||||
if (last_word == *it)
|
||||
{
|
||||
it = m_Words.erase(it);
|
||||
}
|
||||
else
|
||||
{
|
||||
last_word = *it;
|
||||
++it;
|
||||
}
|
||||
}
|
||||
m_Words.erase(std::unique(m_Words.begin(), m_Words.end()), m_Words.end());
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ class CGUI;
|
||||
|
||||
/**
|
||||
* An SGUIText object is a parsed string, divided into
|
||||
* text-rendering components. Each component, being a
|
||||
* text-rendering components. Each component, being a
|
||||
* call to the Renderer. For instance, if you by tags
|
||||
* change the color, then the GUI will have to make
|
||||
* individual calls saying it want that color on the
|
||||
@ -89,7 +89,7 @@ struct SGUIText
|
||||
*/
|
||||
struct STextCall
|
||||
{
|
||||
STextCall() :
|
||||
STextCall() :
|
||||
m_UseCustomColor(false),
|
||||
m_Bold(false), m_Italic(false), m_Underlined(false),
|
||||
m_pSpriteCall(NULL) {}
|
||||
@ -210,7 +210,7 @@ public:
|
||||
* @return True if m_TagType was set.
|
||||
*/
|
||||
bool SetTagType(const CStrW& tagtype);
|
||||
TagType GetTagType(const CStrW& tagtype);
|
||||
TagType GetTagType(const CStrW& tagtype) const;
|
||||
|
||||
|
||||
/**
|
||||
@ -248,8 +248,8 @@ public:
|
||||
struct SFeedback
|
||||
{
|
||||
// Constants
|
||||
static const int Left=0;
|
||||
static const int Right=1;
|
||||
static const int Left = 0;
|
||||
static const int Right = 1;
|
||||
|
||||
/**
|
||||
* Reset all member data.
|
||||
@ -309,12 +309,7 @@ public:
|
||||
* to make several GenerateTextCall in different phases,
|
||||
* it avoids duplicates.
|
||||
*/
|
||||
void GenerateTextCall(const CGUI* pGUI,
|
||||
SFeedback& Feedback,
|
||||
CStrIntern DefaultFont,
|
||||
const int& from, const int& to,
|
||||
const bool FirstLine,
|
||||
const IGUIObject* pObject = NULL) const;
|
||||
void GenerateTextCall(const CGUI* pGUI, SFeedback& Feedback, CStrIntern DefaultFont, const int& from, const int& to, const bool FirstLine, const IGUIObject* pObject = NULL) const;
|
||||
|
||||
/**
|
||||
* Words
|
||||
@ -338,4 +333,4 @@ private:
|
||||
CStrW m_OriginalString;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // INCLUDED_GUITEXT
|
||||
|
@ -15,57 +15,52 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
GUI utilities
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "GUI.h"
|
||||
#include "GUIManager.h"
|
||||
|
||||
#include "maths/Matrix3D.h"
|
||||
#include "ps/CLogger.h"
|
||||
|
||||
extern int g_xres, g_yres;
|
||||
|
||||
#include "ps/CLogger.h"
|
||||
|
||||
|
||||
template <>
|
||||
bool __ParseString<bool>(const CStrW& Value, bool &Output)
|
||||
bool __ParseString<bool>(const CStrW& Value, bool& Output)
|
||||
{
|
||||
if (Value == L"true")
|
||||
Output = true;
|
||||
else
|
||||
if (Value == L"false")
|
||||
else if (Value == L"false")
|
||||
Output = false;
|
||||
else
|
||||
else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool __ParseString<int>(const CStrW& Value, int &Output)
|
||||
bool __ParseString<int>(const CStrW& Value, int& Output)
|
||||
{
|
||||
Output = Value.ToInt();
|
||||
return true;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool __ParseString<float>(const CStrW& Value, float &Output)
|
||||
bool __ParseString<float>(const CStrW& Value, float& Output)
|
||||
{
|
||||
Output = Value.ToFloat();
|
||||
return true;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool __ParseString<CRect>(const CStrW& Value, CRect &Output)
|
||||
bool __ParseString<CRect>(const CStrW& Value, CRect& Output)
|
||||
{
|
||||
const unsigned int NUM_COORDS = 4;
|
||||
float coords[NUM_COORDS];
|
||||
std::wstringstream stream;
|
||||
stream.str(Value);
|
||||
// Parse each coordinate
|
||||
for (unsigned int i = 0; i < NUM_COORDS; i++)
|
||||
for (unsigned int i = 0; i < NUM_COORDS; ++i)
|
||||
{
|
||||
if (stream.eof())
|
||||
{
|
||||
@ -93,13 +88,13 @@ bool __ParseString<CRect>(const CStrW& Value, CRect &Output)
|
||||
}
|
||||
|
||||
template <>
|
||||
bool __ParseString<CClientArea>(const CStrW& Value, CClientArea &Output)
|
||||
bool __ParseString<CClientArea>(const CStrW& Value, CClientArea& Output)
|
||||
{
|
||||
return Output.SetClientArea(Value.ToUTF8());
|
||||
}
|
||||
|
||||
template <>
|
||||
bool GUI<int>::ParseColor(const CStrW& Value, CColor &Output, int DefaultAlpha)
|
||||
bool GUI<int>::ParseColor(const CStrW& Value, CColor& Output, int DefaultAlpha)
|
||||
{
|
||||
// First, check our database in g_GUI for pre-defined colors
|
||||
// If we find anything, we'll ignore DefaultAlpha
|
||||
@ -112,7 +107,7 @@ bool GUI<int>::ParseColor(const CStrW& Value, CColor &Output, int DefaultAlpha)
|
||||
|
||||
|
||||
template <>
|
||||
bool __ParseString<CColor>(const CStrW& Value, CColor &Output)
|
||||
bool __ParseString<CColor>(const CStrW& Value, CColor& Output)
|
||||
{
|
||||
// First, check our database in g_GUI for pre-defined colors
|
||||
// If it fails, it won't do anything with Output
|
||||
@ -123,14 +118,14 @@ bool __ParseString<CColor>(const CStrW& Value, CColor &Output)
|
||||
}
|
||||
|
||||
template <>
|
||||
bool __ParseString<CSize>(const CStrW& Value, CSize &Output)
|
||||
bool __ParseString<CSize>(const CStrW& Value, CSize& Output)
|
||||
{
|
||||
const unsigned int NUM_COORDS = 2;
|
||||
float coords[NUM_COORDS];
|
||||
std::wstringstream stream;
|
||||
stream.str(Value);
|
||||
// Parse each coordinate
|
||||
for (unsigned int i = 0; i < NUM_COORDS; i++)
|
||||
for (unsigned int i = 0; i < NUM_COORDS; ++i)
|
||||
{
|
||||
if (stream.eof())
|
||||
{
|
||||
@ -158,14 +153,14 @@ bool __ParseString<CSize>(const CStrW& Value, CSize &Output)
|
||||
}
|
||||
|
||||
template <>
|
||||
bool __ParseString<CPos>(const CStrW& Value, CPos &Output)
|
||||
bool __ParseString<CPos>(const CStrW& Value, CPos& Output)
|
||||
{
|
||||
const unsigned int NUM_COORDS = 2;
|
||||
float coords[NUM_COORDS];
|
||||
std::wstringstream stream;
|
||||
stream.str(Value);
|
||||
// Parse each coordinate
|
||||
for (unsigned int i = 0; i < NUM_COORDS; i++)
|
||||
for (unsigned int i = 0; i < NUM_COORDS; ++i)
|
||||
{
|
||||
if (stream.eof())
|
||||
{
|
||||
@ -193,15 +188,13 @@ bool __ParseString<CPos>(const CStrW& Value, CPos &Output)
|
||||
}
|
||||
|
||||
template <>
|
||||
bool __ParseString<EAlign>(const CStrW& Value, EAlign &Output)
|
||||
bool __ParseString<EAlign>(const CStrW& Value, EAlign& Output)
|
||||
{
|
||||
if (Value == L"left")
|
||||
Output = EAlign_Left;
|
||||
else
|
||||
if (Value == L"center")
|
||||
else if (Value == L"center")
|
||||
Output = EAlign_Center;
|
||||
else
|
||||
if (Value == L"right")
|
||||
else if (Value == L"right")
|
||||
Output = EAlign_Right;
|
||||
else
|
||||
return false;
|
||||
@ -210,15 +203,13 @@ bool __ParseString<EAlign>(const CStrW& Value, EAlign &Output)
|
||||
}
|
||||
|
||||
template <>
|
||||
bool __ParseString<EVAlign>(const CStrW& Value, EVAlign &Output)
|
||||
bool __ParseString<EVAlign>(const CStrW& Value, EVAlign& Output)
|
||||
{
|
||||
if (Value == L"top")
|
||||
Output = EVAlign_Top;
|
||||
else
|
||||
if (Value == L"center")
|
||||
else if (Value == L"center")
|
||||
Output = EVAlign_Center;
|
||||
else
|
||||
if (Value == L"bottom")
|
||||
else if (Value == L"bottom")
|
||||
Output = EVAlign_Bottom;
|
||||
else
|
||||
return false;
|
||||
@ -227,10 +218,8 @@ bool __ParseString<EVAlign>(const CStrW& Value, EVAlign &Output)
|
||||
}
|
||||
|
||||
template <>
|
||||
bool __ParseString<CGUIString>(const CStrW& Value, CGUIString &Output)
|
||||
bool __ParseString<CGUIString>(const CStrW& Value, CGUIString& Output)
|
||||
{
|
||||
// TODO: i18n: Might want to translate the Value perhaps
|
||||
|
||||
Output.SetValue(Value);
|
||||
return true;
|
||||
}
|
||||
@ -246,14 +235,12 @@ bool __ParseString<CStr>(const CStrW& Value, CStr& Output)
|
||||
template <>
|
||||
bool __ParseString<CStrW>(const CStrW& Value, CStrW& Output)
|
||||
{
|
||||
// TODO: i18n: Might want to translate the Value perhaps
|
||||
|
||||
Output = Value;
|
||||
return true;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool __ParseString<CGUISpriteInstance>(const CStrW& Value, CGUISpriteInstance &Output)
|
||||
bool __ParseString<CGUISpriteInstance>(const CStrW& Value, CGUISpriteInstance& Output)
|
||||
{
|
||||
Output = CGUISpriteInstance(Value.ToUTF8());
|
||||
return true;
|
||||
@ -288,28 +275,22 @@ CMatrix3D GetDefaultGuiMatrix()
|
||||
//--------------------------------------------------------
|
||||
// Utilities implementation
|
||||
//--------------------------------------------------------
|
||||
IGUIObject * CInternalCGUIAccessorBase::GetObjectPointer(CGUI &GUIinstance, const CStr& Object)
|
||||
IGUIObject* CInternalCGUIAccessorBase::GetObjectPointer(CGUI& GUIinstance, const CStr& Object)
|
||||
{
|
||||
// if (!GUIinstance.ObjectExists(Object))
|
||||
// return NULL;
|
||||
|
||||
return GUIinstance.m_pAllObjects.find(Object)->second;
|
||||
return GUIinstance.FindObjectByName(Object);
|
||||
}
|
||||
|
||||
const IGUIObject * CInternalCGUIAccessorBase::GetObjectPointer(const CGUI &GUIinstance, const CStr& Object)
|
||||
const IGUIObject* CInternalCGUIAccessorBase::GetObjectPointer(const CGUI& GUIinstance, const CStr& Object)
|
||||
{
|
||||
// if (!GUIinstance.ObjectExists(Object))
|
||||
// return NULL;
|
||||
|
||||
return GUIinstance.m_pAllObjects.find(Object)->second;
|
||||
return GUIinstance.FindObjectByName(Object);
|
||||
}
|
||||
|
||||
void CInternalCGUIAccessorBase::QueryResetting(IGUIObject *pObject)
|
||||
void CInternalCGUIAccessorBase::QueryResetting(IGUIObject* pObject)
|
||||
{
|
||||
GUI<>::RecurseObject(0, pObject, &IGUIObject::ResetStates);
|
||||
}
|
||||
|
||||
void CInternalCGUIAccessorBase::HandleMessage(IGUIObject *pObject, SGUIMessage &message)
|
||||
void CInternalCGUIAccessorBase::HandleMessage(IGUIObject* pObject, SGUIMessage& message)
|
||||
{
|
||||
pObject->HandleMessage(message);
|
||||
}
|
||||
@ -335,14 +316,14 @@ void CInternalCGUIAccessorBase::HandleMessage(IGUIObject *pObject, SGUIMessage &
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
template <typename T>
|
||||
PSRETURN GUI<T>::GetSettingPointer(const IGUIObject *pObject, const CStr& Setting, T* &Value)
|
||||
PSRETURN GUI<T>::GetSettingPointer(const IGUIObject* pObject, const CStr& Setting, T*& Value)
|
||||
{
|
||||
ENSURE(pObject != NULL);
|
||||
|
||||
std::map<CStr, SGUISetting>::const_iterator it = pObject->m_Settings.find(Setting);
|
||||
if (it == pObject->m_Settings.end())
|
||||
{
|
||||
LOGWARNING("setting %s was not found on object %s",
|
||||
LOGWARNING("setting %s was not found on object %s",
|
||||
Setting.c_str(),
|
||||
pObject->GetPresentableName().c_str());
|
||||
return PSRETURN_GUI_InvalidSetting;
|
||||
@ -362,7 +343,7 @@ PSRETURN GUI<T>::GetSettingPointer(const IGUIObject *pObject, const CStr& Settin
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
PSRETURN GUI<T>::GetSetting(const IGUIObject *pObject, const CStr& Setting, T &Value)
|
||||
PSRETURN GUI<T>::GetSetting(const IGUIObject* pObject, const CStr& Setting, T& Value)
|
||||
{
|
||||
T* v = NULL;
|
||||
PSRETURN ret = GetSettingPointer(pObject, Setting, v);
|
||||
@ -384,14 +365,13 @@ bool IsBoolTrue<bool>(const bool& v)
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
PSRETURN GUI<T>::SetSetting(IGUIObject *pObject, const CStr& Setting,
|
||||
const T &Value, const bool& SkipMessage)
|
||||
PSRETURN GUI<T>::SetSetting(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage)
|
||||
{
|
||||
ENSURE(pObject != NULL);
|
||||
|
||||
if (!pObject->SettingExists(Setting))
|
||||
{
|
||||
LOGWARNING("setting %s was not found on object %s",
|
||||
LOGWARNING("setting %s was not found on object %s",
|
||||
Setting.c_str(),
|
||||
pObject->GetPresentableName().c_str());
|
||||
return PSRETURN_GUI_InvalidSetting;
|
||||
@ -413,8 +393,7 @@ PSRETURN GUI<T>::SetSetting(IGUIObject *pObject, const CStr& Setting,
|
||||
{
|
||||
RecurseObject(0, pObject, &IGUIObject::UpdateCachedSize);
|
||||
}
|
||||
else
|
||||
if (Setting == "hidden")
|
||||
else if (Setting == "hidden")
|
||||
{
|
||||
// Hiding an object requires us to reset it and all children
|
||||
if (IsBoolTrue(Value))
|
||||
@ -432,9 +411,9 @@ PSRETURN GUI<T>::SetSetting(IGUIObject *pObject, const CStr& Setting,
|
||||
|
||||
// Instantiate templated functions:
|
||||
#define TYPE(T) \
|
||||
template PSRETURN GUI<T>::GetSettingPointer(const IGUIObject *pObject, const CStr& Setting, T* &Value); \
|
||||
template PSRETURN GUI<T>::GetSetting(const IGUIObject *pObject, const CStr& Setting, T &Value); \
|
||||
template PSRETURN GUI<T>::SetSetting(IGUIObject *pObject, const CStr& Setting, const T &Value, const bool& SkipMessage);
|
||||
template PSRETURN GUI<T>::GetSettingPointer(const IGUIObject* pObject, const CStr& Setting, T*& Value); \
|
||||
template PSRETURN GUI<T>::GetSetting(const IGUIObject* pObject, const CStr& Setting, T& Value); \
|
||||
template PSRETURN GUI<T>::SetSetting(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage);
|
||||
#define GUITYPE_IGNORE_CGUISpriteInstance
|
||||
#include "GUItypes.h"
|
||||
#undef GUITYPE_IGNORE_CGUISpriteInstance
|
||||
@ -444,5 +423,5 @@ PSRETURN GUI<T>::SetSetting(IGUIObject *pObject, const CStr& Setting,
|
||||
// you attempt to retrieve a sprite using GetSetting, since that copies the sprite
|
||||
// and will mess up the caching performed by DrawSprite. You have to use GetSettingPointer
|
||||
// instead. (This is mainly useful to stop me accidentally using the wrong function.)
|
||||
template PSRETURN GUI<CGUISpriteInstance>::GetSettingPointer(const IGUIObject *pObject, const CStr& Setting, CGUISpriteInstance* &Value);
|
||||
template PSRETURN GUI<CGUISpriteInstance>::SetSetting(IGUIObject *pObject, const CStr& Setting, const CGUISpriteInstance &Value, const bool& SkipMessage);
|
||||
template PSRETURN GUI<CGUISpriteInstance>::GetSettingPointer(const IGUIObject* pObject, const CStr& Setting, CGUISpriteInstance*& Value);
|
||||
template PSRETURN GUI<CGUISpriteInstance>::SetSetting(IGUIObject* pObject, const CStr& Setting, const CGUISpriteInstance& Value, const bool& SkipMessage);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2014 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -32,37 +32,25 @@ GUI util
|
||||
#ifndef INCLUDED_GUIUTIL
|
||||
#define INCLUDED_GUIUTIL
|
||||
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Includes / Compiler directives
|
||||
//--------------------------------------------------------
|
||||
#include "GUIbase.h"
|
||||
// TODO Gee: New
|
||||
#include "CGUI.h"
|
||||
#include "CGUISprite.h"
|
||||
#include "GUIbase.h"
|
||||
#include "IGUIObject.h"
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Help Classes/Structs for the GUI
|
||||
//--------------------------------------------------------
|
||||
|
||||
class CClientArea;
|
||||
class CGUIString;
|
||||
class CMatrix3D;
|
||||
|
||||
template <typename T>
|
||||
bool __ParseString(const CStrW& Value, T &tOutput);
|
||||
bool __ParseString(const CStrW& Value, T& tOutput);
|
||||
|
||||
// Model-view-projection matrix with (0,0) in top-left of screen
|
||||
CMatrix3D GetDefaultGuiMatrix();
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Forward declarations
|
||||
//--------------------------------------------------------
|
||||
struct SGUIMessage;
|
||||
|
||||
/**
|
||||
* Base class to only the class GUI. This superclass is
|
||||
* Base class to only the class GUI. This superclass is
|
||||
* kind of a templateless extention of the class GUI.
|
||||
* Used for other functions to friend with, because it
|
||||
* can't friend with GUI since it's templated (at least
|
||||
@ -72,20 +60,20 @@ class CInternalCGUIAccessorBase
|
||||
{
|
||||
protected:
|
||||
/// Get object pointer
|
||||
static IGUIObject * GetObjectPointer(CGUI &GUIinstance, const CStr& Object);
|
||||
|
||||
static IGUIObject* GetObjectPointer(CGUI& GUIinstance, const CStr& Object);
|
||||
|
||||
/// const version
|
||||
static const IGUIObject * GetObjectPointer(const CGUI &GUIinstance, const CStr& Object);
|
||||
static const IGUIObject* GetObjectPointer(const CGUI& GUIinstance, const CStr& Object);
|
||||
|
||||
/// Wrapper for ResetStates
|
||||
static void QueryResetting(IGUIObject *pObject);
|
||||
static void QueryResetting(IGUIObject* pObject);
|
||||
|
||||
static void HandleMessage(IGUIObject *pObject, SGUIMessage &message);
|
||||
static void HandleMessage(IGUIObject* pObject, SGUIMessage& message);
|
||||
};
|
||||
|
||||
|
||||
#ifndef NDEBUG
|
||||
// Used to ensure type-safety, sort of
|
||||
// Used to ensure type-safety, sort of
|
||||
template<typename T> void CheckType(const IGUIObject* obj, const CStr& setting);
|
||||
#endif
|
||||
|
||||
@ -109,7 +97,7 @@ public:
|
||||
|
||||
// Like GetSetting (below), but doesn't make a copy of the value
|
||||
// (so it can be modified later)
|
||||
static PSRETURN GetSettingPointer(const IGUIObject *pObject, const CStr& Setting, T* &Value);
|
||||
static PSRETURN GetSettingPointer(const IGUIObject* pObject, const CStr& Setting, T*& Value);
|
||||
|
||||
/**
|
||||
* Retrieves a setting by name from object pointer
|
||||
@ -118,7 +106,7 @@ public:
|
||||
* @param Setting Setting by name
|
||||
* @param Value Stores value here, note type T!
|
||||
*/
|
||||
static PSRETURN GetSetting(const IGUIObject *pObject, const CStr& Setting, T &Value);
|
||||
static PSRETURN GetSetting(const IGUIObject* pObject, const CStr& Setting, T& Value);
|
||||
|
||||
/**
|
||||
* Sets a value by name using a real datatype as input.
|
||||
@ -131,8 +119,7 @@ public:
|
||||
* @param Value Sets value to this, note type T!
|
||||
* @param SkipMessage Does not send a GUIM_SETTINGS_UPDATED if true
|
||||
*/
|
||||
static PSRETURN SetSetting(IGUIObject *pObject, const CStr& Setting,
|
||||
const T &Value, const bool &SkipMessage=false);
|
||||
static PSRETURN SetSetting(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage = false);
|
||||
|
||||
/**
|
||||
* Retrieves a setting by settings name and object name
|
||||
@ -142,21 +129,19 @@ public:
|
||||
* @param Setting Setting by name
|
||||
* @param Value Stores value here, note type T!
|
||||
*/
|
||||
static PSRETURN GetSetting(
|
||||
const CGUI &GUIinstance, const CStr& Object,
|
||||
const CStr& Setting, T &Value)
|
||||
static PSRETURN GetSetting(const CGUI& GUIinstance, const CStr& Object, const CStr& Setting, T& Value)
|
||||
{
|
||||
if (!GUIinstance.ObjectExists(Object))
|
||||
return PSRETURN_GUI_NullObjectProvided;
|
||||
|
||||
// Retrieve pointer and call sibling function
|
||||
const IGUIObject *pObject = GetObjectPointer(GUIinstance, Object);
|
||||
const IGUIObject* pObject = GetObjectPointer(GUIinstance, Object);
|
||||
|
||||
return GetSetting(pObject, Setting, Value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a value by setting and object name using a real
|
||||
* Sets a value by setting and object name using a real
|
||||
* datatype as input
|
||||
*
|
||||
* This is just a wrapper so that we can type the object name
|
||||
@ -168,10 +153,7 @@ public:
|
||||
* @param Value Sets value to this, note type T!
|
||||
* @param SkipMessage Does not send a GUIM_SETTINGS_UPDATED if true
|
||||
*/
|
||||
static PSRETURN SetSetting(
|
||||
CGUI &GUIinstance, const CStr& Object,
|
||||
const CStr& Setting, const T &Value,
|
||||
const bool& SkipMessage=false)
|
||||
static PSRETURN SetSetting(CGUI& GUIinstance, const CStr& Object, const CStr& Setting, const T& Value, const bool& SkipMessage = false)
|
||||
{
|
||||
if (!GUIinstance.ObjectExists(Object))
|
||||
return PSRETURN_GUI_NullObjectProvided;
|
||||
@ -181,11 +163,11 @@ public:
|
||||
// Important, we don't want to use this T, we want
|
||||
// to use the standard T, since that will be the
|
||||
// one with the friend relationship
|
||||
IGUIObject *pObject = GetObjectPointer(GUIinstance, Object);
|
||||
IGUIObject* pObject = GetObjectPointer(GUIinstance, Object);
|
||||
|
||||
return SetSetting(pObject, Setting, Value, SkipMessage);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This will return the value of the first sprite if it's not null,
|
||||
* if it is null, it will return the value of the second sprite, if
|
||||
@ -195,9 +177,7 @@ public:
|
||||
* @param sec Secondary sprite if Primary should fail
|
||||
* @return Resulting string
|
||||
*/
|
||||
static const CGUISpriteInstance& FallBackSprite(
|
||||
const CGUISpriteInstance& prim,
|
||||
const CGUISpriteInstance& sec)
|
||||
static const CGUISpriteInstance& FallBackSprite(const CGUISpriteInstance& prim, const CGUISpriteInstance& sec)
|
||||
{
|
||||
return (prim.IsEmpty() ? sec : prim);
|
||||
}
|
||||
@ -210,14 +190,14 @@ public:
|
||||
* @return Resulting color
|
||||
* @see FallBackSprite
|
||||
*/
|
||||
static CColor FallBackColor(const CColor &prim, const CColor &sec)
|
||||
static CColor FallBackColor(const CColor& prim, const CColor& sec)
|
||||
{
|
||||
// CColor() == null.
|
||||
return ((prim!=CColor())?(prim):(sec));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a value by setting and object name using a real
|
||||
* Sets a value by setting and object name using a real
|
||||
* datatype as input.
|
||||
*
|
||||
* This is just a wrapper for __ParseString() which really
|
||||
@ -229,18 +209,18 @@ public:
|
||||
*
|
||||
* @see __ParseString()
|
||||
*/
|
||||
static bool ParseString(const CStrW& Value, T &tOutput)
|
||||
static bool ParseString(const CStrW& Value, T& tOutput)
|
||||
{
|
||||
return __ParseString<T>(Value, tOutput);
|
||||
}
|
||||
|
||||
static bool ParseColor(const CStrW& Value, CColor &tOutput, int DefaultAlpha);
|
||||
static bool ParseColor(const CStrW& Value, CColor& tOutput, int DefaultAlpha);
|
||||
|
||||
private:
|
||||
|
||||
// templated typedef of function pointer
|
||||
typedef void (IGUIObject::*void_Object_pFunction_argT)(const T &arg);
|
||||
typedef void (IGUIObject::*void_Object_pFunction_argRefT)(T &arg);
|
||||
typedef void (IGUIObject::*void_Object_pFunction_argT)(const T& arg);
|
||||
typedef void (IGUIObject::*void_Object_pFunction_argRefT)(T& arg);
|
||||
typedef void (IGUIObject::*void_Object_pFunction)();
|
||||
|
||||
/**
|
||||
@ -269,20 +249,17 @@ private:
|
||||
* @throws PSERROR Depends on what pFunc might throw. PSERROR is standard.
|
||||
* Itself doesn't throw anything.
|
||||
*/
|
||||
static void RecurseObject(int RR, IGUIObject *pObject, void_Object_pFunction_argT pFunc, const T &Argument)
|
||||
static void RecurseObject(int RR, IGUIObject* pObject, void_Object_pFunction_argT pFunc, const T& Argument)
|
||||
{
|
||||
// TODO Gee: Don't run this for the base object.
|
||||
if (CheckIfRestricted(RR, pObject))
|
||||
return;
|
||||
|
||||
(pObject->*pFunc)(Argument);
|
||||
|
||||
|
||||
// Iterate children
|
||||
vector_pObjects::iterator it;
|
||||
for (it = pObject->ChildrenItBegin(); it != pObject->ChildrenItEnd(); ++it)
|
||||
{
|
||||
RecurseObject(RR, *it, pFunc, Argument);
|
||||
}
|
||||
for (IGUIObject* const& obj : *pObject)
|
||||
RecurseObject(RR, obj, pFunc, Argument);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -290,19 +267,16 @@ private:
|
||||
*
|
||||
* @see RecurseObject()
|
||||
*/
|
||||
static void RecurseObject(int RR, IGUIObject *pObject, void_Object_pFunction_argRefT pFunc, T &Argument)
|
||||
static void RecurseObject(int RR, IGUIObject* pObject, void_Object_pFunction_argRefT pFunc, T& Argument)
|
||||
{
|
||||
if (CheckIfRestricted(RR, pObject))
|
||||
return;
|
||||
|
||||
(pObject->*pFunc)(Argument);
|
||||
|
||||
|
||||
// Iterate children
|
||||
vector_pObjects::iterator it;
|
||||
for (it = pObject->ChildrenItBegin(); it != pObject->ChildrenItEnd(); ++it)
|
||||
{
|
||||
RecurseObject(RR, *it, pFunc, Argument);
|
||||
}
|
||||
for (IGUIObject* const& obj : *pObject)
|
||||
RecurseObject(RR, obj, pFunc, Argument);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -310,7 +284,7 @@ private:
|
||||
*
|
||||
* @see RecurseObject()
|
||||
*/
|
||||
static void RecurseObject(int RR, IGUIObject *pObject, void_Object_pFunction pFunc)
|
||||
static void RecurseObject(int RR, IGUIObject* pObject, void_Object_pFunction pFunc)
|
||||
{
|
||||
if (CheckIfRestricted(RR, pObject))
|
||||
return;
|
||||
@ -318,11 +292,8 @@ private:
|
||||
(pObject->*pFunc)();
|
||||
|
||||
// Iterate children
|
||||
vector_pObjects::iterator it;
|
||||
for (it = pObject->ChildrenItBegin(); it != pObject->ChildrenItEnd(); ++it)
|
||||
{
|
||||
RecurseObject(RR, *it, pFunc);
|
||||
}
|
||||
for (IGUIObject* const& obj : *pObject)
|
||||
RecurseObject(RR, obj, pFunc);
|
||||
}
|
||||
|
||||
private:
|
||||
@ -336,13 +307,13 @@ private:
|
||||
* @param pObject Object
|
||||
* @return true if restricted
|
||||
*/
|
||||
static bool CheckIfRestricted(int RR, IGUIObject *pObject)
|
||||
static bool CheckIfRestricted(int RR, IGUIObject* pObject)
|
||||
{
|
||||
// Statically initialise some strings, so we don't have to do
|
||||
// lots of allocation every time this function is called
|
||||
static CStr strHidden("hidden");
|
||||
static CStr strEnabled("enabled");
|
||||
static CStr strGhost("ghost");
|
||||
static const CStr strHidden("hidden");
|
||||
static const CStr strEnabled("enabled");
|
||||
static const CStr strGhost("ghost");
|
||||
|
||||
if (RR & GUIRR_HIDDEN)
|
||||
{
|
||||
@ -374,4 +345,4 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // INCLUDED_GUIUTIL
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2013 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -15,19 +15,13 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
IGUIButtonBehavior
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
#include "ps/CLogger.h"
|
||||
|
||||
#include "GUI.h"
|
||||
|
||||
#include "ps/CLogger.h"
|
||||
#include "soundmanager/ISoundManager.h"
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Constructor / Destructor
|
||||
//-------------------------------------------------------------------
|
||||
IGUIButtonBehavior::IGUIButtonBehavior() : m_Pressed(false)
|
||||
{
|
||||
}
|
||||
@ -36,7 +30,7 @@ IGUIButtonBehavior::~IGUIButtonBehavior()
|
||||
{
|
||||
}
|
||||
|
||||
void IGUIButtonBehavior::HandleMessage(SGUIMessage &Message)
|
||||
void IGUIButtonBehavior::HandleMessage(SGUIMessage& Message)
|
||||
{
|
||||
bool enabled;
|
||||
GUI<bool>::GetSetting(this, "enabled", enabled);
|
||||
@ -45,27 +39,22 @@ void IGUIButtonBehavior::HandleMessage(SGUIMessage &Message)
|
||||
switch (Message.type)
|
||||
{
|
||||
case GUIM_MOUSE_ENTER:
|
||||
{
|
||||
if (!enabled)
|
||||
break;
|
||||
|
||||
if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_enter", soundPath) == PSRETURN_OK && !soundPath.empty())
|
||||
g_SoundManager->PlayAsUI(soundPath.c_str(), false);
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIM_MOUSE_LEAVE:
|
||||
{
|
||||
if (!enabled)
|
||||
break;
|
||||
|
||||
if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_leave", soundPath) == PSRETURN_OK && !soundPath.empty())
|
||||
g_SoundManager->PlayAsUI(soundPath.c_str(), false);
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIM_MOUSE_DBLCLICK_LEFT:
|
||||
{
|
||||
if (!enabled)
|
||||
break;
|
||||
|
||||
@ -73,10 +62,8 @@ void IGUIButtonBehavior::HandleMessage(SGUIMessage &Message)
|
||||
// doubleclick event, we let it handle playing sounds.
|
||||
SendEvent(GUIM_DOUBLE_PRESSED, "doublepress");
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIM_MOUSE_PRESS_LEFT:
|
||||
{
|
||||
if (!enabled)
|
||||
{
|
||||
if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_disabled", soundPath) == PSRETURN_OK && !soundPath.empty())
|
||||
@ -90,10 +77,8 @@ void IGUIButtonBehavior::HandleMessage(SGUIMessage &Message)
|
||||
SendEvent(GUIM_PRESSED, "press");
|
||||
m_Pressed = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIM_MOUSE_DBLCLICK_RIGHT:
|
||||
{
|
||||
if (!enabled)
|
||||
break;
|
||||
|
||||
@ -101,9 +86,8 @@ void IGUIButtonBehavior::HandleMessage(SGUIMessage &Message)
|
||||
// doubleclick event, we let it handle playing sounds.
|
||||
SendEvent(GUIM_DOUBLE_PRESSED_MOUSE_RIGHT, "doublepressright");
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIM_MOUSE_PRESS_RIGHT:
|
||||
{
|
||||
if (!enabled)
|
||||
{
|
||||
if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_disabled", soundPath) == PSRETURN_OK && !soundPath.empty())
|
||||
@ -117,10 +101,8 @@ void IGUIButtonBehavior::HandleMessage(SGUIMessage &Message)
|
||||
SendEvent(GUIM_PRESSED_MOUSE_RIGHT, "pressright");
|
||||
m_PressedRight = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIM_MOUSE_RELEASE_RIGHT:
|
||||
{
|
||||
if (!enabled)
|
||||
break;
|
||||
|
||||
@ -131,10 +113,8 @@ void IGUIButtonBehavior::HandleMessage(SGUIMessage &Message)
|
||||
g_SoundManager->PlayAsUI(soundPath.c_str(), false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIM_MOUSE_RELEASE_LEFT:
|
||||
{
|
||||
if (!enabled)
|
||||
break;
|
||||
|
||||
@ -145,7 +125,6 @@ void IGUIButtonBehavior::HandleMessage(SGUIMessage &Message)
|
||||
g_SoundManager->PlayAsUI(soundPath.c_str(), false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
@ -167,8 +146,7 @@ CColor IGUIButtonBehavior::ChooseColor()
|
||||
GUI<CColor>::GetSetting(this, "textcolor_disabled", color2);
|
||||
return GUI<>::FallBackColor(color2, color);
|
||||
}
|
||||
else
|
||||
if (m_MouseHovering)
|
||||
else if (m_MouseHovering)
|
||||
{
|
||||
if (m_Pressed)
|
||||
{
|
||||
@ -181,32 +159,27 @@ CColor IGUIButtonBehavior::ChooseColor()
|
||||
return GUI<>::FallBackColor(color2, color);
|
||||
}
|
||||
}
|
||||
else return color;
|
||||
else
|
||||
return color;
|
||||
}
|
||||
|
||||
void IGUIButtonBehavior::DrawButton(const CRect &rect,
|
||||
const float &z,
|
||||
CGUISpriteInstance& sprite,
|
||||
CGUISpriteInstance& sprite_over,
|
||||
CGUISpriteInstance& sprite_pressed,
|
||||
CGUISpriteInstance& sprite_disabled,
|
||||
int cell_id)
|
||||
void IGUIButtonBehavior::DrawButton(const CRect& rect, const float& z, CGUISpriteInstance& sprite, CGUISpriteInstance& sprite_over, CGUISpriteInstance& sprite_pressed, CGUISpriteInstance& sprite_disabled, int cell_id)
|
||||
{
|
||||
if (GetGUI())
|
||||
{
|
||||
bool enabled;
|
||||
GUI<bool>::GetSetting(this, "enabled", enabled);
|
||||
if (!GetGUI())
|
||||
return;
|
||||
|
||||
if (!enabled)
|
||||
GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_disabled, sprite), cell_id, z, rect);
|
||||
else if (m_MouseHovering)
|
||||
{
|
||||
if (m_Pressed)
|
||||
GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_pressed, sprite), cell_id, z, rect);
|
||||
else
|
||||
GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_over, sprite), cell_id, z, rect);
|
||||
}
|
||||
bool enabled;
|
||||
GUI<bool>::GetSetting(this, "enabled", enabled);
|
||||
|
||||
if (!enabled)
|
||||
GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_disabled, sprite), cell_id, z, rect);
|
||||
else if (m_MouseHovering)
|
||||
{
|
||||
if (m_Pressed)
|
||||
GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_pressed, sprite), cell_id, z, rect);
|
||||
else
|
||||
GetGUI()->DrawSprite(sprite, cell_id, z, rect);
|
||||
GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_over, sprite), cell_id, z, rect);
|
||||
}
|
||||
else
|
||||
GetGUI()->DrawSprite(sprite, cell_id, z, rect);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -35,25 +35,10 @@ GUI Object Base - Button Behavior
|
||||
#ifndef INCLUDED_IGUIBUTTONBEHAVIOR
|
||||
#define INCLUDED_IGUIBUTTONBEHAVIOR
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Includes / Compiler directives
|
||||
//--------------------------------------------------------
|
||||
#include "GUI.h"
|
||||
|
||||
class CGUISpriteInstance;
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Macros
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Types
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Declarations
|
||||
//--------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Appends button behaviours to the IGUIObject.
|
||||
* Can be used with multiple inheritance alongside
|
||||
@ -70,7 +55,7 @@ public:
|
||||
/**
|
||||
* @see IGUIObject#HandleMessage()
|
||||
*/
|
||||
virtual void HandleMessage(SGUIMessage &Message);
|
||||
virtual void HandleMessage(SGUIMessage& Message);
|
||||
|
||||
/**
|
||||
* This is a function that lets a button being drawn,
|
||||
@ -89,13 +74,7 @@ public:
|
||||
* @param cell_id Identifies the icon to be used (if the sprite contains
|
||||
* cell-using images)
|
||||
*/
|
||||
void DrawButton(const CRect &rect,
|
||||
const float &z,
|
||||
CGUISpriteInstance& sprite,
|
||||
CGUISpriteInstance& sprite_over,
|
||||
CGUISpriteInstance& sprite_pressed,
|
||||
CGUISpriteInstance& sprite_disabled,
|
||||
int cell_id);
|
||||
void DrawButton(const CRect& rect, const float& z, CGUISpriteInstance& sprite, CGUISpriteInstance& sprite_over, CGUISpriteInstance& sprite_pressed, CGUISpriteInstance& sprite_disabled, int cell_id);
|
||||
|
||||
/**
|
||||
* Choosing which color of the following according to object enabled/hovered/pressed status:
|
||||
@ -129,4 +108,4 @@ protected:
|
||||
bool m_PressedRight;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // INCLUDED_IGUIBUTTONBEHAVIOR
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2014 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -15,31 +15,18 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
IGUIObject
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "GUI.h"
|
||||
|
||||
#include "gui/scripting/JSInterface_IGUIObject.h"
|
||||
#include "gui/scripting/JSInterface_GUITypes.h"
|
||||
#include "gui/scripting/JSInterface_IGUIObject.h"
|
||||
#include "ps/CLogger.h"
|
||||
#include "scriptinterface/ScriptInterface.h"
|
||||
|
||||
#include "ps/CLogger.h"
|
||||
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Implementation Macros
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Constructor / Destructor
|
||||
//-------------------------------------------------------------------
|
||||
IGUIObject::IGUIObject() :
|
||||
m_pGUI(NULL),
|
||||
m_pParent(NULL),
|
||||
m_MouseHovering(false)
|
||||
IGUIObject::IGUIObject()
|
||||
: m_pGUI(NULL), m_pParent(NULL), m_MouseHovering(false), m_LastClickTime()
|
||||
{
|
||||
AddSetting(GUIST_bool, "enabled");
|
||||
AddSetting(GUIST_bool, "hidden");
|
||||
@ -58,29 +45,20 @@ IGUIObject::IGUIObject() :
|
||||
GUI<bool>::SetSetting(this, "ghost", false);
|
||||
GUI<bool>::SetSetting(this, "enabled", true);
|
||||
GUI<bool>::SetSetting(this, "absolute", true);
|
||||
|
||||
|
||||
for (int i=0; i<6; i++)
|
||||
m_LastClickTime[i]=0;
|
||||
}
|
||||
|
||||
IGUIObject::~IGUIObject()
|
||||
{
|
||||
{
|
||||
std::map<CStr, SGUISetting>::iterator it;
|
||||
for (it = m_Settings.begin(); it != m_Settings.end(); ++it)
|
||||
for (const std::pair<CStr, SGUISetting>& p : m_Settings)
|
||||
switch (p.second.m_Type)
|
||||
{
|
||||
switch (it->second.m_Type)
|
||||
{
|
||||
// delete() needs to know the type of the variable - never delete a void*
|
||||
#define TYPE(t) case GUIST_##t: delete (t*)it->second.m_pSetting; break;
|
||||
// delete() needs to know the type of the variable - never delete a void*
|
||||
#define TYPE(t) case GUIST_##t: delete (t*)p.second.m_pSetting; break;
|
||||
#include "GUItypes.h"
|
||||
#undef TYPE
|
||||
default:
|
||||
debug_warn(L"Invalid setting type");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_pGUI)
|
||||
JS_RemoveExtraGCRootsTracer(m_pGUI->GetScriptInterface()->GetJSRuntime(), Trace, this);
|
||||
@ -89,16 +67,15 @@ IGUIObject::~IGUIObject()
|
||||
//-------------------------------------------------------------------
|
||||
// Functions
|
||||
//-------------------------------------------------------------------
|
||||
void IGUIObject::SetGUI(CGUI * const &pGUI)
|
||||
void IGUIObject::SetGUI(CGUI* const& pGUI)
|
||||
{
|
||||
if (!m_pGUI)
|
||||
JS_AddExtraGCRootsTracer(pGUI->GetScriptInterface()->GetJSRuntime(), Trace, this);
|
||||
m_pGUI = pGUI;
|
||||
}
|
||||
|
||||
void IGUIObject::AddChild(IGUIObject *pChild)
|
||||
void IGUIObject::AddChild(IGUIObject* pChild)
|
||||
{
|
||||
//
|
||||
// ENSURE(pChild);
|
||||
|
||||
pChild->SetParent(this);
|
||||
@ -122,15 +99,15 @@ void IGUIObject::AddChild(IGUIObject *pChild)
|
||||
{
|
||||
// If anything went wrong, reverse what we did and throw
|
||||
// an exception telling it never added a child
|
||||
m_Children.erase( m_Children.end()-1 );
|
||||
|
||||
m_Children.erase(m_Children.end()-1);
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
// else do nothing
|
||||
}
|
||||
|
||||
void IGUIObject::AddToPointersMap(map_pObjects &ObjectMap)
|
||||
void IGUIObject::AddToPointersMap(map_pObjects& ObjectMap)
|
||||
{
|
||||
// Just don't do anything about the top node
|
||||
if (m_pParent == NULL)
|
||||
@ -158,13 +135,7 @@ void IGUIObject::Destroy()
|
||||
// Is there anything besides the children to destroy?
|
||||
}
|
||||
|
||||
// Notice if using this, the naming convention of GUIST_ should be strict.
|
||||
#define TYPE(type) \
|
||||
case GUIST_##type: \
|
||||
m_Settings[Name].m_pSetting = new type(); \
|
||||
break;
|
||||
|
||||
void IGUIObject::AddSetting(const EGUISettingType &Type, const CStr& Name)
|
||||
void IGUIObject::AddSetting(const EGUISettingType& Type, const CStr& Name)
|
||||
{
|
||||
// Is name already taken?
|
||||
if (m_Settings.count(Name) >= 1)
|
||||
@ -175,20 +146,26 @@ void IGUIObject::AddSetting(const EGUISettingType &Type, const CStr& Name)
|
||||
|
||||
switch (Type)
|
||||
{
|
||||
#define TYPE(type) \
|
||||
case GUIST_##type: \
|
||||
m_Settings[Name].m_pSetting = new type(); \
|
||||
break;
|
||||
|
||||
// Construct the setting.
|
||||
#include "GUItypes.h"
|
||||
|
||||
#undef TYPE
|
||||
|
||||
default:
|
||||
debug_warn(L"IGUIObject::AddSetting failed, type not recognized!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
#undef TYPE
|
||||
|
||||
|
||||
bool IGUIObject::MouseOver()
|
||||
{
|
||||
if(!GetGUI())
|
||||
if (!GetGUI())
|
||||
throw PSERROR_GUI_OperationNeedsGUIObject();
|
||||
|
||||
return m_CachedActualSize.PointInside(GetMousePos());
|
||||
@ -200,11 +177,14 @@ bool IGUIObject::MouseOverIcon()
|
||||
}
|
||||
|
||||
CPos IGUIObject::GetMousePos() const
|
||||
{
|
||||
return ((GetGUI())?(GetGUI()->m_MousePos):CPos());
|
||||
{
|
||||
if (GetGUI())
|
||||
return GetGUI()->m_MousePos;
|
||||
|
||||
return CPos();
|
||||
}
|
||||
|
||||
void IGUIObject::UpdateMouseOver(IGUIObject * const &pMouseOver)
|
||||
void IGUIObject::UpdateMouseOver(IGUIObject* const& pMouseOver)
|
||||
{
|
||||
// Check if this is the object being hovered.
|
||||
if (pMouseOver == this)
|
||||
@ -241,30 +221,28 @@ bool IGUIObject::SettingExists(const CStr& Setting) const
|
||||
return (m_Settings.count(Setting) >= 1);
|
||||
}
|
||||
|
||||
#define TYPE(type) \
|
||||
else \
|
||||
if (set.m_Type == GUIST_##type) \
|
||||
{ \
|
||||
type _Value; \
|
||||
if (!GUI<type>::ParseString(Value, _Value)) \
|
||||
return PSRETURN_GUI_UnableToParse; \
|
||||
\
|
||||
GUI<type>::SetSetting(this, Setting, _Value, SkipMessage); \
|
||||
}
|
||||
|
||||
PSRETURN IGUIObject::SetSetting(const CStr& Setting, const CStrW& Value, const bool& SkipMessage)
|
||||
{
|
||||
if (!SettingExists(Setting))
|
||||
{
|
||||
return PSRETURN_GUI_InvalidSetting;
|
||||
}
|
||||
|
||||
// Get setting
|
||||
SGUISetting set = m_Settings[Setting];
|
||||
|
||||
if (0);
|
||||
#define TYPE(type) \
|
||||
else if (set.m_Type == GUIST_##type) \
|
||||
{ \
|
||||
type _Value; \
|
||||
if (!GUI<type>::ParseString(Value, _Value)) \
|
||||
return PSRETURN_GUI_UnableToParse; \
|
||||
GUI<type>::SetSetting(this, Setting, _Value, SkipMessage); \
|
||||
}
|
||||
|
||||
if (0)
|
||||
;
|
||||
// else...
|
||||
#include "GUItypes.h"
|
||||
#undef TYPE
|
||||
else
|
||||
{
|
||||
// Why does it always fail?
|
||||
@ -274,20 +252,15 @@ PSRETURN IGUIObject::SetSetting(const CStr& Setting, const CStrW& Value, const b
|
||||
return PSRETURN_OK;
|
||||
}
|
||||
|
||||
#undef TYPE
|
||||
|
||||
|
||||
PSRETURN IGUIObject::GetSettingType(const CStr& Setting, EGUISettingType &Type) const
|
||||
PSRETURN IGUIObject::GetSettingType(const CStr& Setting, EGUISettingType& Type) const
|
||||
{
|
||||
if (!SettingExists(Setting))
|
||||
{
|
||||
return LogInvalidSettings(Setting);
|
||||
}
|
||||
|
||||
if (m_Settings.find(Setting) == m_Settings.end())
|
||||
{
|
||||
return LogInvalidSettings(Setting);
|
||||
}
|
||||
|
||||
Type = m_Settings.find(Setting)->second.m_Type;
|
||||
|
||||
@ -295,27 +268,27 @@ PSRETURN IGUIObject::GetSettingType(const CStr& Setting, EGUISettingType &Type)
|
||||
}
|
||||
|
||||
|
||||
void IGUIObject::ChooseMouseOverAndClosest(IGUIObject* &pObject)
|
||||
void IGUIObject::ChooseMouseOverAndClosest(IGUIObject*& pObject)
|
||||
{
|
||||
if (MouseOver())
|
||||
{
|
||||
// Check if we've got competition at all
|
||||
if (pObject == NULL)
|
||||
{
|
||||
pObject = this;
|
||||
return;
|
||||
}
|
||||
if (!MouseOver())
|
||||
return;
|
||||
|
||||
// Or if it's closer
|
||||
if (GetBufferedZ() >= pObject->GetBufferedZ())
|
||||
{
|
||||
pObject = this;
|
||||
return;
|
||||
}
|
||||
// Check if we've got competition at all
|
||||
if (pObject == NULL)
|
||||
{
|
||||
pObject = this;
|
||||
return;
|
||||
}
|
||||
|
||||
// Or if it's closer
|
||||
if (GetBufferedZ() >= pObject->GetBufferedZ())
|
||||
{
|
||||
pObject = this;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
IGUIObject *IGUIObject::GetParent() const
|
||||
IGUIObject* IGUIObject::GetParent() const
|
||||
{
|
||||
// Important, we're not using GetParent() for these
|
||||
// checks, that could screw it up
|
||||
@ -338,7 +311,7 @@ void IGUIObject::UpdateCachedSize()
|
||||
|
||||
CClientArea ca;
|
||||
GUI<CClientArea>::GetSetting(this, "size", ca);
|
||||
|
||||
|
||||
// If absolute="false" and the object has got a parent,
|
||||
// use its cached size instead of the screen. Notice
|
||||
// it must have just been cached for it to work.
|
||||
@ -367,10 +340,10 @@ void IGUIObject::UpdateCachedSize()
|
||||
}
|
||||
}
|
||||
|
||||
void IGUIObject::LoadStyle(CGUI &GUIinstance, const CStr& StyleName)
|
||||
void IGUIObject::LoadStyle(CGUI& GUIinstance, const CStr& StyleName)
|
||||
{
|
||||
// Fetch style
|
||||
if (GUIinstance.m_Styles.count(StyleName)==1)
|
||||
if (GUIinstance.m_Styles.count(StyleName) == 1)
|
||||
{
|
||||
LoadStyle(GUIinstance.m_Styles[StyleName]);
|
||||
}
|
||||
@ -380,14 +353,13 @@ void IGUIObject::LoadStyle(CGUI &GUIinstance, const CStr& StyleName)
|
||||
}
|
||||
}
|
||||
|
||||
void IGUIObject::LoadStyle(const SGUIStyle &Style)
|
||||
void IGUIObject::LoadStyle(const SGUIStyle& Style)
|
||||
{
|
||||
// Iterate settings, it won't be able to set them all probably, but that doesn't matter
|
||||
std::map<CStr, CStrW>::const_iterator cit;
|
||||
for (cit = Style.m_SettingsDefaults.begin(); cit != Style.m_SettingsDefaults.end(); ++cit)
|
||||
for (const std::pair<CStr, CStrW>& p : Style.m_SettingsDefaults)
|
||||
{
|
||||
// Try set setting in object
|
||||
SetSetting(cit->first, cit->second);
|
||||
SetSetting(p.first, p.second);
|
||||
|
||||
// It doesn't matter if it fail, it's not suppose to be able to set every setting.
|
||||
// since it's generic.
|
||||
@ -415,7 +387,7 @@ float IGUIObject::GetBufferedZ() const
|
||||
else
|
||||
{
|
||||
// In philosophy, a parentless object shouldn't be able to have a relative sizing,
|
||||
// but we'll accept it so that absolute can be used as default without a complaint.
|
||||
// but we'll accept it so that absolute can be used as default without a complaint.
|
||||
// Also, you could consider those objects children to the screen resolution.
|
||||
return Z;
|
||||
}
|
||||
@ -426,12 +398,12 @@ void IGUIObject::RegisterScriptHandler(const CStr& Action, const CStr& Code, CGU
|
||||
{
|
||||
if(!GetGUI())
|
||||
throw PSERROR_GUI_OperationNeedsGUIObject();
|
||||
|
||||
|
||||
JSContext* cx = pGUI->GetScriptInterface()->GetContext();
|
||||
JSAutoRequest rq(cx);
|
||||
JS::RootedValue globalVal(cx, pGUI->GetGlobalObject());
|
||||
JS::RootedObject globalObj(cx, &globalVal.toObject());
|
||||
|
||||
|
||||
const int paramCount = 1;
|
||||
const char* paramNames[paramCount] = { "mouse" };
|
||||
|
||||
@ -439,7 +411,7 @@ void IGUIObject::RegisterScriptHandler(const CStr& Action, const CStr& Code, CGU
|
||||
CStr CodeName = GetName()+" "+Action;
|
||||
|
||||
// Generate a unique name
|
||||
static int x=0;
|
||||
static int x = 0;
|
||||
char buf[64];
|
||||
sprintf_s(buf, ARRAY_SIZE(buf), "__eventhandler%d (%s)", x++, Action.c_str());
|
||||
|
||||
@ -452,7 +424,7 @@ void IGUIObject::RegisterScriptHandler(const CStr& Action, const CStr& Code, CGU
|
||||
|
||||
if (!func)
|
||||
return; // JS will report an error message
|
||||
|
||||
|
||||
JS::RootedObject funcObj(cx, JS_GetFunctionObject(func));
|
||||
SetScriptHandler(Action, funcObj);
|
||||
}
|
||||
@ -558,12 +530,12 @@ CStr IGUIObject::GetPresentableName() const
|
||||
|
||||
void IGUIObject::SetFocus()
|
||||
{
|
||||
GetGUI()->m_FocusedObject = this;
|
||||
GetGUI()->m_FocusedObject = this;
|
||||
}
|
||||
|
||||
bool IGUIObject::IsFocused() const
|
||||
{
|
||||
return GetGUI()->m_FocusedObject == this;
|
||||
return GetGUI()->m_FocusedObject == this;
|
||||
}
|
||||
|
||||
bool IGUIObject::IsRootObject() const
|
||||
@ -571,15 +543,15 @@ bool IGUIObject::IsRootObject() const
|
||||
return (GetGUI() != 0 && m_pParent == GetGUI()->m_BaseObject);
|
||||
}
|
||||
|
||||
void IGUIObject::TraceMember(JSTracer *trc)
|
||||
void IGUIObject::TraceMember(JSTracer* trc)
|
||||
{
|
||||
for (auto& handler : m_ScriptHandlers)
|
||||
JS_CallHeapObjectTracer(trc, &handler.second, "IGUIObject::m_ScriptHandlers");
|
||||
}
|
||||
|
||||
PSRETURN IGUIObject::LogInvalidSettings(const CStr8 &Setting) const
|
||||
PSRETURN IGUIObject::LogInvalidSettings(const CStr8& Setting) const
|
||||
{
|
||||
LOGWARNING("IGUIObject: setting %s was not found on an object",
|
||||
LOGWARNING("IGUIObject: setting %s was not found on an object",
|
||||
Setting.c_str());
|
||||
return PSRETURN_GUI_InvalidSetting;
|
||||
}
|
||||
|
@ -43,43 +43,24 @@ The base class of an object
|
||||
#ifndef INCLUDED_IGUIOBJECT
|
||||
#define INCLUDED_IGUIOBJECT
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Includes / Compiler directives
|
||||
//--------------------------------------------------------
|
||||
#include "GUIbase.h"
|
||||
#include "GUItext.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "lib/input.h" // just for IN_PASS
|
||||
|
||||
#include "ps/XML/Xeromyces.h"
|
||||
|
||||
#include "gui/scripting/JSInterface_IGUIObject.h"
|
||||
#include "lib/input.h" // just for IN_PASS
|
||||
#include "ps/XML/Xeromyces.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct SGUISetting;
|
||||
struct SGUIStyle;
|
||||
class CGUI;
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Macros
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Types
|
||||
//--------------------------------------------------------
|
||||
|
||||
class JSObject;
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Error declarations
|
||||
//--------------------------------------------------------
|
||||
|
||||
ERROR_TYPE(GUI, UnableToParse);
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Declarations
|
||||
//--------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Setting Type
|
||||
* @see SGUISetting
|
||||
@ -192,11 +173,11 @@ public:
|
||||
* @throws PSERROR_GUI_ObjectNeedsName Name is missing
|
||||
* @throws PSERROR_GUI_NameAmbiguity Name is already taken
|
||||
*/
|
||||
void AddToPointersMap(map_pObjects &ObjectMap);
|
||||
void AddToPointersMap(map_pObjects& ObjectMap);
|
||||
|
||||
/**
|
||||
* Notice nothing will be returned or thrown if the child hasn't
|
||||
* been inputted into the GUI yet. This is because that's were
|
||||
* Notice nothing will be returned or thrown if the child hasn't
|
||||
* been inputted into the GUI yet. This is because that's were
|
||||
* all is checked. Now we're just linking two objects, but
|
||||
* it's when we're inputting them into the GUI we'll check
|
||||
* validity! Notice also when adding it to the GUI this function
|
||||
@ -210,16 +191,18 @@ public:
|
||||
*
|
||||
* @throws PSERROR_GUI from CGUI::UpdateObjects().
|
||||
*/
|
||||
void AddChild(IGUIObject *pChild);
|
||||
void AddChild(IGUIObject* pChild);
|
||||
|
||||
//@}
|
||||
//--------------------------------------------------------
|
||||
/** @name Iterate */
|
||||
/** @name Iterate
|
||||
* Used to iterate over all children of this object.
|
||||
*/
|
||||
//--------------------------------------------------------
|
||||
//@{
|
||||
|
||||
vector_pObjects::iterator ChildrenItBegin() { return m_Children.begin(); }
|
||||
vector_pObjects::iterator ChildrenItEnd() { return m_Children.end(); }
|
||||
vector_pObjects::iterator begin() { return m_Children.begin(); }
|
||||
vector_pObjects::iterator end() { return m_Children.end(); }
|
||||
|
||||
//@}
|
||||
//--------------------------------------------------------
|
||||
@ -236,7 +219,7 @@ public:
|
||||
* @return True if settings exist.
|
||||
*/
|
||||
bool SettingExists(const CStr& Setting) const;
|
||||
|
||||
|
||||
/**
|
||||
* All sizes are relative to resolution, and the calculation
|
||||
* is not wanted in real time, therefore it is cached, update
|
||||
@ -255,7 +238,7 @@ public:
|
||||
*
|
||||
* @return PSRETURN (PSRETURN_OK if successful)
|
||||
*/
|
||||
PSRETURN SetSetting(const CStr& Setting, const CStrW& Value, const bool& SkipMessage=false);
|
||||
PSRETURN SetSetting(const CStr& Setting, const CStrW& Value, const bool& SkipMessage = false);
|
||||
|
||||
/**
|
||||
* Retrieves the type of a named setting.
|
||||
@ -264,7 +247,7 @@ public:
|
||||
* @param Type Stores an EGUISettingType
|
||||
* @return PSRETURN (PSRETURN_OK if successful)
|
||||
*/
|
||||
PSRETURN GetSettingType(const CStr& Setting, EGUISettingType &Type) const;
|
||||
PSRETURN GetSettingType(const CStr& Setting, EGUISettingType& Type) const;
|
||||
|
||||
/**
|
||||
* Set the script handler for a particular object-specific action
|
||||
@ -274,7 +257,7 @@ public:
|
||||
* @param pGUI GUI instance to associate the script with
|
||||
*/
|
||||
void RegisterScriptHandler(const CStr& Action, const CStr& Code, CGUI* pGUI);
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the JSObject representing this GUI object.
|
||||
*/
|
||||
@ -300,14 +283,14 @@ protected:
|
||||
* @param Type Setting type
|
||||
* @param Name Setting reference name
|
||||
*/
|
||||
void AddSetting(const EGUISettingType &Type, const CStr& Name);
|
||||
void AddSetting(const EGUISettingType& Type, const CStr& Name);
|
||||
|
||||
/**
|
||||
* Calls Destroy on all children, and deallocates all memory.
|
||||
* MEGA TODO Should it destroy it's children?
|
||||
*/
|
||||
virtual void Destroy();
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
* This function is called with different messages
|
||||
@ -326,7 +309,7 @@ protected:
|
||||
* it'll probably only output in the Error log, and not
|
||||
* disrupt the whole GUI drawing.
|
||||
*/
|
||||
virtual void Draw()=0;
|
||||
virtual void Draw() = 0;
|
||||
|
||||
/**
|
||||
* Some objects need to handle the SDL_Event_ manually.
|
||||
@ -346,14 +329,14 @@ protected:
|
||||
* @param GUIinstance Reference to the GUI
|
||||
* @param StyleName Style by name
|
||||
*/
|
||||
void LoadStyle(CGUI &GUIinstance, const CStr& StyleName);
|
||||
void LoadStyle(CGUI& GUIinstance, const CStr& StyleName);
|
||||
|
||||
/**
|
||||
* Loads a style.
|
||||
*
|
||||
* @param Style The style object.
|
||||
*/
|
||||
void LoadStyle(const SGUIStyle &Style);
|
||||
void LoadStyle(const SGUIStyle& Style);
|
||||
|
||||
/**
|
||||
* Returns not the Z value, but the actual buffered Z value, i.e. if it's
|
||||
@ -364,13 +347,13 @@ protected:
|
||||
*/
|
||||
virtual float GetBufferedZ() const;
|
||||
|
||||
void SetGUI(CGUI * const &pGUI);
|
||||
void SetGUI(CGUI* const& pGUI);
|
||||
|
||||
/**
|
||||
* Set parent of this object
|
||||
*/
|
||||
void SetParent(IGUIObject *pParent) { m_pParent = pParent; }
|
||||
|
||||
void SetParent(IGUIObject* pParent) { m_pParent = pParent; }
|
||||
|
||||
/**
|
||||
* Reset internal state of this object
|
||||
*/
|
||||
@ -381,8 +364,8 @@ protected:
|
||||
}
|
||||
|
||||
public:
|
||||
CGUI *GetGUI() { return m_pGUI; }
|
||||
const CGUI *GetGUI() const { return m_pGUI; }
|
||||
CGUI* GetGUI() { return m_pGUI; }
|
||||
const CGUI* GetGUI() const { return m_pGUI; }
|
||||
|
||||
/**
|
||||
* Take focus!
|
||||
@ -404,7 +387,7 @@ protected:
|
||||
*
|
||||
* @return Pointer to parent
|
||||
*/
|
||||
IGUIObject *GetParent() const;
|
||||
IGUIObject* GetParent() const;
|
||||
|
||||
/**
|
||||
* Get Mouse from CGUI.
|
||||
@ -419,8 +402,10 @@ protected:
|
||||
* Notice 'false' is default, because an object not using this function, should not
|
||||
* have any additional children (and this function should never be called).
|
||||
*/
|
||||
virtual bool HandleAdditionalChildren(const XMBElement& UNUSED(child),
|
||||
CXeromyces* UNUSED(pFile)) { return false; }
|
||||
virtual bool HandleAdditionalChildren(const XMBElement& UNUSED(child), CXeromyces* UNUSED(pFile))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cached size, real size m_Size is actually dependent on resolution
|
||||
@ -466,7 +451,7 @@ protected:
|
||||
* @param pMouseOver Object that is currently hovered,
|
||||
* can OF COURSE be NULL too!
|
||||
*/
|
||||
void UpdateMouseOver(IGUIObject * const &pMouseOver);
|
||||
void UpdateMouseOver(IGUIObject* const& pMouseOver);
|
||||
|
||||
//@}
|
||||
private:
|
||||
@ -474,7 +459,7 @@ private:
|
||||
/** @name Internal functions */
|
||||
//--------------------------------------------------------
|
||||
//@{
|
||||
|
||||
|
||||
/**
|
||||
* Inputs a reference pointer, checks if the new inputted object
|
||||
* if hovered, if so, then check if this's Z value is greater
|
||||
@ -487,7 +472,7 @@ private:
|
||||
* @param pObject Object pointer, can be either the old one, or
|
||||
* the new one.
|
||||
*/
|
||||
void ChooseMouseOverAndClosest(IGUIObject* &pObject);
|
||||
void ChooseMouseOverAndClosest(IGUIObject*& pObject);
|
||||
|
||||
// Is the object a Root object, in philosophy, this means it
|
||||
// has got no parent, and technically, it's got the m_BaseObject
|
||||
@ -501,12 +486,12 @@ private:
|
||||
*/
|
||||
PSRETURN LogInvalidSettings(const CStr8& Setting) const;
|
||||
|
||||
static void Trace(JSTracer *trc, void *data)
|
||||
static void Trace(JSTracer* trc, void* data)
|
||||
{
|
||||
reinterpret_cast<IGUIObject*>(data)->TraceMember(trc);
|
||||
}
|
||||
|
||||
void TraceMember(JSTracer *trc);
|
||||
void TraceMember(JSTracer* trc);
|
||||
|
||||
// Variables
|
||||
|
||||
@ -533,7 +518,7 @@ protected:
|
||||
* read. This is important to know because I don't want to force
|
||||
* the user to include its \<styles\>-XML-files first, so somehow
|
||||
* the GUI needs to know which settings were set, and which is meant
|
||||
* to
|
||||
* to.
|
||||
*/
|
||||
|
||||
// More variables
|
||||
@ -558,7 +543,7 @@ private:
|
||||
|
||||
// Internal storage for registered script handlers.
|
||||
std::map<CStr, JS::Heap<JSObject*> > m_ScriptHandlers;
|
||||
|
||||
|
||||
// Cached JSObject representing this GUI object
|
||||
DefPersistentRooted<JSObject*> m_JSObject;
|
||||
};
|
||||
@ -579,4 +564,4 @@ public:
|
||||
virtual bool MouseOver() { return false; }
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // INCLUDED_IGUIOBJECT
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -15,21 +15,15 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
IGUIScrollBar
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "GUI.h"
|
||||
#include "maths/MathUtil.h"
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// IGUIScrollBar
|
||||
//-------------------------------------------------------------------
|
||||
IGUIScrollBar::IGUIScrollBar() : m_pStyle(NULL), m_pGUI(NULL),
|
||||
m_X(300.f), m_Y(300.f),
|
||||
m_ScrollRange(1.f), m_ScrollSpace(0.f), // MaxPos: not 0, due to division.
|
||||
m_Length(200.f), m_Width(20.f),
|
||||
m_Length(200.f), m_Width(20.f),
|
||||
m_BarSize(0.f), m_Pos(0.f),
|
||||
m_ButtonPlusPressed(false),
|
||||
m_ButtonMinusPressed(false),
|
||||
@ -48,6 +42,7 @@ void IGUIScrollBar::SetupBarSize()
|
||||
{
|
||||
if (!GetStyle())
|
||||
return;
|
||||
|
||||
float min = GetStyle()->m_MinimumBarSize;
|
||||
float max = GetStyle()->m_MaximumBarSize;
|
||||
float length = m_Length;
|
||||
@ -66,7 +61,7 @@ void IGUIScrollBar::SetupBarSize()
|
||||
m_BarSize = clamp(length * std::min((float)m_ScrollSpace / (float)m_ScrollRange, 1.f), min, max);
|
||||
}
|
||||
|
||||
const SGUIScrollBarStyle *IGUIScrollBar::GetStyle() const
|
||||
const SGUIScrollBarStyle* IGUIScrollBar::GetStyle() const
|
||||
{
|
||||
if (!m_pHostObject)
|
||||
return NULL;
|
||||
@ -74,12 +69,12 @@ const SGUIScrollBarStyle *IGUIScrollBar::GetStyle() const
|
||||
return m_pHostObject->GetScrollBarStyle(m_ScrollBarStyle);
|
||||
}
|
||||
|
||||
CGUI *IGUIScrollBar::GetGUI() const
|
||||
{
|
||||
CGUI* IGUIScrollBar::GetGUI() const
|
||||
{
|
||||
if (!m_pHostObject)
|
||||
return NULL;
|
||||
|
||||
return m_pHostObject->GetGUI();
|
||||
return m_pHostObject->GetGUI();
|
||||
}
|
||||
|
||||
void IGUIScrollBar::UpdatePosBoundaries()
|
||||
@ -87,118 +82,113 @@ void IGUIScrollBar::UpdatePosBoundaries()
|
||||
if (m_Pos < 0.f ||
|
||||
m_ScrollRange < m_ScrollSpace) // <= scrolling not applicable
|
||||
m_Pos = 0.f;
|
||||
else
|
||||
if (m_Pos > GetMaxPos())
|
||||
else if (m_Pos > GetMaxPos())
|
||||
m_Pos = GetMaxPos();
|
||||
}
|
||||
|
||||
void IGUIScrollBar::HandleMessage(SGUIMessage &Message)
|
||||
void IGUIScrollBar::HandleMessage(SGUIMessage& Message)
|
||||
{
|
||||
switch (Message.type)
|
||||
{
|
||||
case GUIM_MOUSE_MOTION:
|
||||
case GUIM_MOUSE_MOTION:
|
||||
{
|
||||
// TODO Gee: Optimizations needed!
|
||||
|
||||
CPos mouse = m_pHostObject->GetMousePos();
|
||||
|
||||
// If bar is being dragged
|
||||
if (m_BarPressed)
|
||||
{
|
||||
// TODO Gee: Optimizations needed!
|
||||
|
||||
CPos mouse = m_pHostObject->GetMousePos();
|
||||
|
||||
// If bar is being dragged
|
||||
if (m_BarPressed)
|
||||
{
|
||||
SetPosFromMousePos(mouse);
|
||||
UpdatePosBoundaries();
|
||||
}
|
||||
|
||||
// check if components are being hovered
|
||||
m_BarHovered = GetBarRect().PointInside(mouse);
|
||||
m_ButtonMinusHovered = HoveringButtonMinus(mouse);
|
||||
m_ButtonPlusHovered = HoveringButtonPlus(mouse);
|
||||
|
||||
if (!m_ButtonMinusHovered)
|
||||
m_ButtonMinusPressed = false;
|
||||
|
||||
if (!m_ButtonPlusHovered)
|
||||
m_ButtonPlusPressed = false;
|
||||
break;
|
||||
SetPosFromMousePos(mouse);
|
||||
UpdatePosBoundaries();
|
||||
}
|
||||
|
||||
case GUIM_MOUSE_PRESS_LEFT:
|
||||
{
|
||||
if (!m_pHostObject)
|
||||
break;
|
||||
// check if components are being hovered
|
||||
m_BarHovered = GetBarRect().PointInside(mouse);
|
||||
m_ButtonMinusHovered = HoveringButtonMinus(mouse);
|
||||
m_ButtonPlusHovered = HoveringButtonPlus(mouse);
|
||||
|
||||
CPos mouse = m_pHostObject->GetMousePos();
|
||||
|
||||
// if bar is pressed
|
||||
if (GetBarRect().PointInside(mouse))
|
||||
{
|
||||
m_BarPressed = true;
|
||||
m_BarPressedAtPos = mouse;
|
||||
m_PosWhenPressed = m_Pos;
|
||||
}
|
||||
else
|
||||
// if button-minus is pressed
|
||||
if (m_ButtonMinusHovered)
|
||||
{
|
||||
m_ButtonMinusPressed = true;
|
||||
ScrollMinus();
|
||||
}
|
||||
else
|
||||
// if button-plus is pressed
|
||||
if (m_ButtonPlusHovered)
|
||||
{
|
||||
m_ButtonPlusPressed = true;
|
||||
ScrollPlus();
|
||||
}
|
||||
else
|
||||
// Pressing the background of the bar, to scroll
|
||||
// notice the if-sentence alone does not admit that,
|
||||
// it must be after the above if/elses
|
||||
{
|
||||
if (GetOuterRect().PointInside(mouse))
|
||||
{
|
||||
// Scroll plus or minus a lot, this might change, it doesn't
|
||||
// have to be fancy though.
|
||||
if (mouse.y < GetBarRect().top)
|
||||
ScrollMinusPlenty();
|
||||
else
|
||||
ScrollPlusPlenty();
|
||||
// Simulate mouse movement to see if bar now is hovered
|
||||
SGUIMessage msg(GUIM_MOUSE_MOTION);
|
||||
HandleMessage(msg);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIM_MOUSE_RELEASE_LEFT:
|
||||
{
|
||||
if (!m_ButtonMinusHovered)
|
||||
m_ButtonMinusPressed = false;
|
||||
|
||||
if (!m_ButtonPlusHovered)
|
||||
m_ButtonPlusPressed = false;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIM_MOUSE_WHEEL_UP:
|
||||
case GUIM_MOUSE_PRESS_LEFT:
|
||||
{
|
||||
if (!m_pHostObject)
|
||||
break;
|
||||
|
||||
CPos mouse = m_pHostObject->GetMousePos();
|
||||
|
||||
// if bar is pressed
|
||||
if (GetBarRect().PointInside(mouse))
|
||||
{
|
||||
m_BarPressed = true;
|
||||
m_BarPressedAtPos = mouse;
|
||||
m_PosWhenPressed = m_Pos;
|
||||
}
|
||||
// if button-minus is pressed
|
||||
else if (m_ButtonMinusHovered)
|
||||
{
|
||||
m_ButtonMinusPressed = true;
|
||||
ScrollMinus();
|
||||
// Since the scroll was changed, let's simulate a mouse movement
|
||||
// to check if scrollbar now is hovered
|
||||
SGUIMessage msg(GUIM_MOUSE_MOTION);
|
||||
HandleMessage(msg);
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIM_MOUSE_WHEEL_DOWN:
|
||||
// if button-plus is pressed
|
||||
else if (m_ButtonPlusHovered)
|
||||
{
|
||||
m_ButtonPlusPressed = true;
|
||||
ScrollPlus();
|
||||
// Since the scroll was changed, let's simulate a mouse movement
|
||||
// to check if scrollbar now is hovered
|
||||
SGUIMessage msg(GUIM_MOUSE_MOTION);
|
||||
HandleMessage(msg);
|
||||
break;
|
||||
}
|
||||
// Pressing the background of the bar, to scroll
|
||||
// notice the if-sentence alone does not admit that,
|
||||
// it must be after the above if/elses
|
||||
else
|
||||
{
|
||||
if (GetOuterRect().PointInside(mouse))
|
||||
{
|
||||
// Scroll plus or minus a lot, this might change, it doesn't
|
||||
// have to be fancy though.
|
||||
if (mouse.y < GetBarRect().top)
|
||||
ScrollMinusPlenty();
|
||||
else
|
||||
ScrollPlusPlenty();
|
||||
// Simulate mouse movement to see if bar now is hovered
|
||||
SGUIMessage msg(GUIM_MOUSE_MOTION);
|
||||
HandleMessage(msg);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
case GUIM_MOUSE_RELEASE_LEFT:
|
||||
m_ButtonMinusPressed = false;
|
||||
m_ButtonPlusPressed = false;
|
||||
break;
|
||||
|
||||
case GUIM_MOUSE_WHEEL_UP:
|
||||
{
|
||||
ScrollMinus();
|
||||
// Since the scroll was changed, let's simulate a mouse movement
|
||||
// to check if scrollbar now is hovered
|
||||
SGUIMessage msg(GUIM_MOUSE_MOTION);
|
||||
HandleMessage(msg);
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIM_MOUSE_WHEEL_DOWN:
|
||||
{
|
||||
ScrollPlus();
|
||||
// Since the scroll was changed, let's simulate a mouse movement
|
||||
// to check if scrollbar now is hovered
|
||||
SGUIMessage msg(GUIM_MOUSE_MOTION);
|
||||
HandleMessage(msg);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -37,15 +37,8 @@ A GUI ScrollBar
|
||||
#ifndef INCLUDED_IGUISCROLLBAR
|
||||
#define INCLUDED_IGUISCROLLBAR
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Includes / Compiler directives
|
||||
//--------------------------------------------------------
|
||||
#include "GUI.h"
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Declarations
|
||||
//--------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The GUI Scroll-bar style. Tells us how scroll-bars look and feel.
|
||||
*
|
||||
@ -96,7 +89,7 @@ struct SGUIScrollBarStyle
|
||||
* in pixels.
|
||||
*/
|
||||
float m_MaximumBarSize;
|
||||
|
||||
|
||||
/**
|
||||
* True if you want edge buttons, i.e. buttons that can be pressed in order
|
||||
* to scroll.
|
||||
@ -169,7 +162,7 @@ public:
|
||||
/**
|
||||
* Draw the scroll-bar
|
||||
*/
|
||||
virtual void Draw()=0;
|
||||
virtual void Draw() = 0;
|
||||
|
||||
/**
|
||||
* If an object that contains a scrollbar has got messages, send
|
||||
@ -178,12 +171,12 @@ public:
|
||||
*
|
||||
* @see IGUIObject#HandleMessage()
|
||||
*/
|
||||
virtual void HandleMessage(SGUIMessage &Message)=0;
|
||||
virtual void HandleMessage(SGUIMessage& Message) = 0;
|
||||
|
||||
/**
|
||||
* Set m_Pos with g_mouse_x/y input, i.e. when draggin.
|
||||
*/
|
||||
virtual void SetPosFromMousePos(const CPos &mouse)=0;
|
||||
virtual void SetPosFromMousePos(const CPos& mouse) = 0;
|
||||
|
||||
/**
|
||||
* Hovering the scroll minus button
|
||||
@ -240,26 +233,26 @@ public:
|
||||
* Set host object, must be done almost at creation of scroll bar.
|
||||
* @param pOwner Pointer to host object.
|
||||
*/
|
||||
void SetHostObject(IGUIScrollBarOwner * pOwner) { m_pHostObject = pOwner; }
|
||||
void SetHostObject(IGUIScrollBarOwner* pOwner) { m_pHostObject = pOwner; }
|
||||
|
||||
/**
|
||||
* Get GUI pointer
|
||||
* @return CGUI pointer
|
||||
*/
|
||||
CGUI *GetGUI() const;
|
||||
CGUI* GetGUI() const;
|
||||
|
||||
/**
|
||||
* Set GUI pointer
|
||||
* @param pGUI pointer to CGUI object.
|
||||
*/
|
||||
void SetGUI(CGUI *pGUI) { m_pGUI = pGUI; }
|
||||
void SetGUI(CGUI* pGUI) { m_pGUI = pGUI; }
|
||||
|
||||
/**
|
||||
* Set Width
|
||||
* @param width Width
|
||||
*/
|
||||
void SetWidth(float width) { m_Width = width; }
|
||||
|
||||
|
||||
/**
|
||||
* Set X Position
|
||||
* @param x Position in this axis
|
||||
@ -312,7 +305,7 @@ public:
|
||||
* Get style used by the scrollbar
|
||||
* @return Scroll bar style struct.
|
||||
*/
|
||||
const SGUIScrollBarStyle * GetStyle() const;
|
||||
const SGUIScrollBarStyle* GetStyle() const;
|
||||
|
||||
/**
|
||||
* Get the rectangle of the actual BAR. not the whole scroll-bar.
|
||||
@ -348,7 +341,7 @@ protected:
|
||||
/**
|
||||
* Width of the scroll bar
|
||||
*/
|
||||
float m_Width;
|
||||
float m_Width;
|
||||
|
||||
/**
|
||||
* Absolute X Position
|
||||
@ -451,4 +444,4 @@ protected:
|
||||
//@}
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // INCLUDED_IGUISCROLLBAR
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -15,50 +15,36 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
IGUIScrollBarOwner
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "GUI.h"
|
||||
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Constructor / Destructor
|
||||
//-------------------------------------------------------------------
|
||||
IGUIScrollBarOwner::IGUIScrollBarOwner()
|
||||
{
|
||||
}
|
||||
|
||||
IGUIScrollBarOwner::~IGUIScrollBarOwner()
|
||||
{
|
||||
// Delete scroll-bars
|
||||
std::vector<IGUIScrollBar*>::iterator it;
|
||||
for (it=m_ScrollBars.begin(); it!=m_ScrollBars.end(); ++it)
|
||||
{
|
||||
delete *it;
|
||||
}
|
||||
for (IGUIScrollBar* const& sb : m_ScrollBars)
|
||||
delete sb;
|
||||
}
|
||||
|
||||
void IGUIScrollBarOwner::ResetStates()
|
||||
{
|
||||
IGUIObject::ResetStates();
|
||||
|
||||
std::vector<IGUIScrollBar*>::iterator it;
|
||||
for (it=m_ScrollBars.begin(); it!=m_ScrollBars.end(); ++it)
|
||||
{
|
||||
(*it)->SetBarPressed(false);
|
||||
}
|
||||
|
||||
for (IGUIScrollBar* const& sb : m_ScrollBars)
|
||||
sb->SetBarPressed(false);
|
||||
}
|
||||
|
||||
void IGUIScrollBarOwner::AddScrollBar(IGUIScrollBar * scrollbar)
|
||||
void IGUIScrollBarOwner::AddScrollBar(IGUIScrollBar* scrollbar)
|
||||
{
|
||||
scrollbar->SetHostObject(this);
|
||||
scrollbar->SetGUI(GetGUI());
|
||||
m_ScrollBars.push_back(scrollbar);
|
||||
}
|
||||
|
||||
const SGUIScrollBarStyle * IGUIScrollBarOwner::GetScrollBarStyle(const CStr& style) const
|
||||
const SGUIScrollBarStyle* IGUIScrollBarOwner::GetScrollBarStyle(const CStr& style) const
|
||||
{
|
||||
if (!GetGUI())
|
||||
{
|
||||
@ -76,20 +62,19 @@ const SGUIScrollBarStyle * IGUIScrollBarOwner::GetScrollBarStyle(const CStr& sty
|
||||
return &it->second;
|
||||
}
|
||||
|
||||
void IGUIScrollBarOwner::HandleMessage(SGUIMessage &Message)
|
||||
void IGUIScrollBarOwner::HandleMessage(SGUIMessage& msg)
|
||||
{
|
||||
std::vector<IGUIScrollBar*>::iterator it;
|
||||
for (it=m_ScrollBars.begin(); it!=m_ScrollBars.end(); ++it)
|
||||
{
|
||||
(*it)->HandleMessage(Message);
|
||||
}
|
||||
for (IGUIScrollBar* const& sb : m_ScrollBars)
|
||||
sb->HandleMessage(msg);
|
||||
}
|
||||
|
||||
void IGUIScrollBarOwner::Draw()
|
||||
void IGUIScrollBarOwner::Draw()
|
||||
{
|
||||
std::vector<IGUIScrollBar*>::iterator it;
|
||||
for (it=m_ScrollBars.begin(); it!=m_ScrollBars.end(); ++it)
|
||||
{
|
||||
(*it)->Draw();
|
||||
}
|
||||
for (IGUIScrollBar* const& sb : m_ScrollBars)
|
||||
sb->Draw();
|
||||
}
|
||||
|
||||
float IGUIScrollBarOwner::GetScrollBarPos(const int index) const
|
||||
{
|
||||
return m_ScrollBars[index]->GetPos();
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -15,42 +15,14 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
GUI Object Base - Scroll-bar owner
|
||||
|
||||
--Overview--
|
||||
|
||||
Base-class this if you want scroll-bars in an object.
|
||||
|
||||
--More info--
|
||||
|
||||
Check GUI.h
|
||||
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_IGUISCROLLBAROWNER
|
||||
#define INCLUDED_IGUISCROLLBAROWNER
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Includes / Compiler directives
|
||||
//--------------------------------------------------------
|
||||
#include "GUI.h"
|
||||
|
||||
struct SGUIScrollBarStyle;
|
||||
class IGUIScrollBar;
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Macros
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Types
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Declarations
|
||||
//--------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Base-class this if you want an object to contain
|
||||
* one, or several, scroll-bars.
|
||||
@ -71,7 +43,7 @@ public:
|
||||
/**
|
||||
* @see IGUIObject#HandleMessage()
|
||||
*/
|
||||
virtual void HandleMessage(SGUIMessage &Message);
|
||||
virtual void HandleMessage(SGUIMessage& Message);
|
||||
|
||||
/**
|
||||
* @see IGUIObject#ResetStates()
|
||||
@ -81,22 +53,28 @@ public:
|
||||
/**
|
||||
* Interface for the m_ScrollBar to use.
|
||||
*/
|
||||
virtual const SGUIScrollBarStyle *GetScrollBarStyle(const CStr& style) const;
|
||||
virtual const SGUIScrollBarStyle* GetScrollBarStyle(const CStr& style) const;
|
||||
|
||||
/**
|
||||
* Add a scroll-bar
|
||||
*/
|
||||
virtual void AddScrollBar(IGUIScrollBar * scrollbar);
|
||||
virtual void AddScrollBar(IGUIScrollBar* scrollbar);
|
||||
|
||||
/**
|
||||
* Get Scroll Bar reference (it should be transparent it's actually
|
||||
* pointers).
|
||||
*/
|
||||
virtual IGUIScrollBar & GetScrollBar(const int &index)
|
||||
virtual IGUIScrollBar& GetScrollBar(const int& index)
|
||||
{
|
||||
return *m_ScrollBars[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the position of the scroll bar at @param index.
|
||||
* Equivalent to GetScrollbar(index).GetPos().
|
||||
*/
|
||||
virtual float GetScrollBarPos(const int index) const;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
@ -106,4 +84,4 @@ protected:
|
||||
std::vector<IGUIScrollBar*> m_ScrollBars;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // INCLUDED_IGUISCROLLBAROWNER
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2013 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -15,37 +15,26 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
IGUITextOwner
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "GUI.h"
|
||||
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Constructor / Destructor
|
||||
//-------------------------------------------------------------------
|
||||
IGUITextOwner::IGUITextOwner() : m_GeneratedTextsValid(false)
|
||||
{
|
||||
}
|
||||
|
||||
IGUITextOwner::~IGUITextOwner()
|
||||
{
|
||||
// Delete all generated texts.
|
||||
std::vector<SGUIText*>::iterator it;
|
||||
for (it=m_GeneratedTexts.begin(); it!=m_GeneratedTexts.end(); ++it)
|
||||
{
|
||||
delete *it;
|
||||
}
|
||||
for (SGUIText* const& t : m_GeneratedTexts)
|
||||
delete t;
|
||||
}
|
||||
|
||||
void IGUITextOwner::AddText(SGUIText * text)
|
||||
void IGUITextOwner::AddText(SGUIText* text)
|
||||
{
|
||||
m_GeneratedTexts.push_back(text);
|
||||
}
|
||||
|
||||
void IGUITextOwner::HandleMessage(SGUIMessage &Message)
|
||||
void IGUITextOwner::HandleMessage(SGUIMessage& Message)
|
||||
{
|
||||
switch (Message.type)
|
||||
{
|
||||
@ -78,7 +67,7 @@ void IGUITextOwner::UpdateCachedSize()
|
||||
m_GeneratedTextsValid = false;
|
||||
}
|
||||
|
||||
void IGUITextOwner::DrawText(int index, const CColor& color, const CPos& pos, float z, const CRect& clipping)
|
||||
void IGUITextOwner::DrawText(size_t index, const CColor& color, const CPos& pos, float z, const CRect& clipping)
|
||||
{
|
||||
if (!m_GeneratedTextsValid)
|
||||
{
|
||||
@ -86,19 +75,13 @@ void IGUITextOwner::DrawText(int index, const CColor& color, const CPos& pos, fl
|
||||
m_GeneratedTextsValid = true;
|
||||
}
|
||||
|
||||
if (index < 0 || index >= (int)m_GeneratedTexts.size())
|
||||
{
|
||||
debug_warn(L"Trying to draw a Text Index within a IGUITextOwner that doesn't exist");
|
||||
return;
|
||||
}
|
||||
ENSURE(index < m_GeneratedTexts.size() && "Trying to draw a Text Index within a IGUITextOwner that doesn't exist");
|
||||
|
||||
if (GetGUI())
|
||||
{
|
||||
GetGUI()->DrawText(*m_GeneratedTexts[index], color, pos, z, clipping);
|
||||
}
|
||||
}
|
||||
|
||||
void IGUITextOwner::CalculateTextPosition(CRect &ObjSize, CPos &TextPos, SGUIText &Text)
|
||||
void IGUITextOwner::CalculateTextPosition(CRect& ObjSize, CPos& TextPos, SGUIText& Text)
|
||||
{
|
||||
EVAlign valign;
|
||||
GUI<EVAlign>::GetSetting(this, "text_valign", valign);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -35,23 +35,8 @@ GUI Object Base - Text Owner
|
||||
#ifndef INCLUDED_IGUITEXTOWNER
|
||||
#define INCLUDED_IGUITEXTOWNER
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Includes / Compiler directives
|
||||
//--------------------------------------------------------
|
||||
#include "GUI.h"
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Macros
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Types
|
||||
//--------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Declarations
|
||||
//--------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Framework for handling Output text.
|
||||
*
|
||||
@ -66,12 +51,12 @@ public:
|
||||
/**
|
||||
* Adds a text object.
|
||||
*/
|
||||
void AddText(SGUIText * text);
|
||||
void AddText(SGUIText* text);
|
||||
|
||||
/**
|
||||
* @see IGUIObject#HandleMessage()
|
||||
*/
|
||||
virtual void HandleMessage(SGUIMessage &Message);
|
||||
virtual void HandleMessage(SGUIMessage& Message);
|
||||
|
||||
/**
|
||||
* @see IGUIObject#UpdateCachedSize()
|
||||
@ -88,7 +73,7 @@ public:
|
||||
* @param clipping Clipping rectangle, don't even add a parameter
|
||||
* to get no clipping.
|
||||
*/
|
||||
virtual void DrawText(int index, const CColor& color, const CPos& pos, float z, const CRect& clipping = CRect());
|
||||
virtual void DrawText(size_t index, const CColor& color, const CPos& pos, float z, const CRect& clipping = CRect());
|
||||
|
||||
/**
|
||||
* Test if mouse position is over an icon
|
||||
@ -100,7 +85,7 @@ protected:
|
||||
/**
|
||||
* Setup texts. Functions that sets up all texts when changes have been made.
|
||||
*/
|
||||
virtual void SetupText()=0;
|
||||
virtual void SetupText() = 0;
|
||||
|
||||
/**
|
||||
* Whether the cached text is currently valid (if not then SetupText will be called by Draw)
|
||||
@ -115,7 +100,7 @@ protected:
|
||||
/**
|
||||
* Calculate the position for the text, based on the alignment.
|
||||
*/
|
||||
void CalculateTextPosition(CRect &ObjSize, CPos &TextPos, SGUIText &Text);
|
||||
void CalculateTextPosition(CRect& ObjSize, CPos& TextPos, SGUIText& Text);
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // INCLUDED_IGUITEXTOWNER
|
||||
|
@ -30,9 +30,9 @@
|
||||
#include "graphics/TerritoryTexture.h"
|
||||
#include "gui/GUI.h"
|
||||
#include "gui/GUIManager.h"
|
||||
#include "lib/ogl.h"
|
||||
#include "lib/external_libraries/libsdl.h"
|
||||
#include "lib/bits.h"
|
||||
#include "lib/external_libraries/libsdl.h"
|
||||
#include "lib/ogl.h"
|
||||
#include "lib/timer.h"
|
||||
#include "ps/ConfigDB.h"
|
||||
#include "ps/Game.h"
|
||||
@ -86,11 +86,11 @@ CMiniMap::CMiniMap() :
|
||||
m_AttributePos.type = GL_FLOAT;
|
||||
m_AttributePos.elems = 2;
|
||||
m_VertexArray.AddAttribute(&m_AttributePos);
|
||||
|
||||
|
||||
m_AttributeColor.type = GL_UNSIGNED_BYTE;
|
||||
m_AttributeColor.elems = 4;
|
||||
m_VertexArray.AddAttribute(&m_AttributeColor);
|
||||
|
||||
|
||||
m_VertexArray.SetNumVertices(MAX_ENTITIES_DRAWN);
|
||||
m_VertexArray.Layout();
|
||||
|
||||
@ -105,7 +105,7 @@ CMiniMap::CMiniMap() :
|
||||
|
||||
VertexArrayIterator<float[2]> attrPos = m_AttributePos.GetIterator<float[2]>();
|
||||
VertexArrayIterator<u8[4]> attrColor = m_AttributeColor.GetIterator<u8[4]>();
|
||||
for (u16 i = 0; i < MAX_ENTITIES_DRAWN; i++)
|
||||
for (u16 i = 0; i < MAX_ENTITIES_DRAWN; ++i)
|
||||
{
|
||||
(*attrColor)[0] = 0;
|
||||
(*attrColor)[1] = 0;
|
||||
@ -137,60 +137,44 @@ CMiniMap::~CMiniMap()
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void CMiniMap::HandleMessage(SGUIMessage &Message)
|
||||
void CMiniMap::HandleMessage(SGUIMessage& Message)
|
||||
{
|
||||
switch(Message.type)
|
||||
switch (Message.type)
|
||||
{
|
||||
case GUIM_MOUSE_PRESS_LEFT:
|
||||
if (m_MouseHovering)
|
||||
{
|
||||
if (m_MouseHovering)
|
||||
{
|
||||
SetCameraPos();
|
||||
m_Clicking = true;
|
||||
}
|
||||
break;
|
||||
SetCameraPos();
|
||||
m_Clicking = true;
|
||||
}
|
||||
break;
|
||||
case GUIM_MOUSE_RELEASE_LEFT:
|
||||
{
|
||||
if(m_MouseHovering && m_Clicking)
|
||||
SetCameraPos();
|
||||
m_Clicking = false;
|
||||
break;
|
||||
}
|
||||
if (m_MouseHovering && m_Clicking)
|
||||
SetCameraPos();
|
||||
m_Clicking = false;
|
||||
break;
|
||||
case GUIM_MOUSE_DBLCLICK_LEFT:
|
||||
{
|
||||
if(m_MouseHovering && m_Clicking)
|
||||
SetCameraPos();
|
||||
m_Clicking = false;
|
||||
break;
|
||||
}
|
||||
if (m_MouseHovering && m_Clicking)
|
||||
SetCameraPos();
|
||||
m_Clicking = false;
|
||||
break;
|
||||
case GUIM_MOUSE_ENTER:
|
||||
{
|
||||
m_MouseHovering = true;
|
||||
break;
|
||||
}
|
||||
m_MouseHovering = true;
|
||||
break;
|
||||
case GUIM_MOUSE_LEAVE:
|
||||
{
|
||||
m_Clicking = false;
|
||||
m_MouseHovering = false;
|
||||
break;
|
||||
}
|
||||
m_Clicking = false;
|
||||
m_MouseHovering = false;
|
||||
break;
|
||||
case GUIM_MOUSE_RELEASE_RIGHT:
|
||||
{
|
||||
CMiniMap::FireWorldClickEvent(SDL_BUTTON_RIGHT, 1);
|
||||
break;
|
||||
}
|
||||
CMiniMap::FireWorldClickEvent(SDL_BUTTON_RIGHT, 1);
|
||||
break;
|
||||
case GUIM_MOUSE_DBLCLICK_RIGHT:
|
||||
{
|
||||
CMiniMap::FireWorldClickEvent(SDL_BUTTON_RIGHT, 2);
|
||||
break;
|
||||
}
|
||||
CMiniMap::FireWorldClickEvent(SDL_BUTTON_RIGHT, 2);
|
||||
break;
|
||||
case GUIM_MOUSE_MOTION:
|
||||
{
|
||||
if (m_MouseHovering && m_Clicking)
|
||||
SetCameraPos();
|
||||
break;
|
||||
}
|
||||
if (m_MouseHovering && m_Clicking)
|
||||
SetCameraPos();
|
||||
break;
|
||||
case GUIM_MOUSE_WHEEL_DOWN:
|
||||
case GUIM_MOUSE_WHEEL_UP:
|
||||
Message.Skip();
|
||||
@ -198,7 +182,7 @@ void CMiniMap::HandleMessage(SGUIMessage &Message)
|
||||
|
||||
default:
|
||||
break;
|
||||
} // switch
|
||||
}
|
||||
}
|
||||
|
||||
bool CMiniMap::MouseOver()
|
||||
@ -248,11 +232,11 @@ float CMiniMap::GetAngle()
|
||||
return -atan2(cameraIn.X, cameraIn.Z);
|
||||
}
|
||||
|
||||
void CMiniMap::FireWorldClickEvent(int button, int clicks)
|
||||
void CMiniMap::FireWorldClickEvent(int UNUSED(button), int UNUSED(clicks))
|
||||
{
|
||||
JSContext* cx = g_GUI->GetActiveGUI()->GetScriptInterface()->GetContext();
|
||||
JSAutoRequest rq(cx);
|
||||
|
||||
|
||||
float x, z;
|
||||
GetMouseWorldCoordinates(x, z);
|
||||
|
||||
@ -261,9 +245,6 @@ void CMiniMap::FireWorldClickEvent(int button, int clicks)
|
||||
g_GUI->GetActiveGUI()->GetScriptInterface()->SetProperty(coords, "x", x, false);
|
||||
g_GUI->GetActiveGUI()->GetScriptInterface()->SetProperty(coords, "z", z, false);
|
||||
ScriptEvent("worldclick", coords);
|
||||
|
||||
UNUSED2(button);
|
||||
UNUSED2(clicks);
|
||||
}
|
||||
|
||||
// This sets up and draws the rectangle on the minimap
|
||||
@ -284,7 +265,8 @@ void CMiniMap::DrawViewRect(CMatrix3D transform)
|
||||
hitPt[3] = m_Camera->GetWorldCoordinates(0, 0, h);
|
||||
|
||||
float ViewRect[4][2];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
// convert to minimap space
|
||||
ViewRect[i][0] = (width * hitPt[i].X * invTileMapSize);
|
||||
ViewRect[i][1] = (height * hitPt[i].Z * invTileMapSize);
|
||||
@ -301,7 +283,7 @@ void CMiniMap::DrawViewRect(CMatrix3D transform)
|
||||
glScissor(
|
||||
m_CachedActualSize.left / g_GuiScale,
|
||||
g_Renderer.GetHeight() - m_CachedActualSize.bottom / g_GuiScale,
|
||||
width / g_GuiScale,
|
||||
width / g_GuiScale,
|
||||
height / g_GuiScale);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glLineWidth(2.0f);
|
||||
@ -423,7 +405,7 @@ void CMiniMap::Draw()
|
||||
const double cur_time = timer_Time();
|
||||
const bool doUpdate = cur_time - last_time > 0.5;
|
||||
if (doUpdate)
|
||||
{
|
||||
{
|
||||
last_time = cur_time;
|
||||
if (m_TerrainDirty)
|
||||
RebuildTerrainTexture();
|
||||
@ -465,7 +447,7 @@ void CMiniMap::Draw()
|
||||
CTerritoryTexture& territoryTexture = g_Game->GetView()->GetTerritoryTexture();
|
||||
|
||||
shader->BindTexture(str_baseTex, territoryTexture.GetTexture());
|
||||
const CMatrix3D *territoryTransform = territoryTexture.GetMinimapTextureMatrix();
|
||||
const CMatrix3D* territoryTransform = territoryTexture.GetMinimapTextureMatrix();
|
||||
shader->Uniform(str_transform, baseTransform);
|
||||
shader->Uniform(str_textureTransform, *territoryTransform);
|
||||
|
||||
@ -484,7 +466,7 @@ void CMiniMap::Draw()
|
||||
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
const CMatrix3D *losTransform = losTexture.GetMinimapTextureMatrix();
|
||||
const CMatrix3D* losTransform = losTexture.GetMinimapTextureMatrix();
|
||||
shader->Uniform(str_transform, baseTransform);
|
||||
shader->Uniform(str_textureTransform, *losTransform);
|
||||
|
||||
@ -658,10 +640,10 @@ void CMiniMap::RebuildTerrainTexture()
|
||||
|
||||
m_TerrainDirty = false;
|
||||
|
||||
for(u32 j = 0; j < h; j++)
|
||||
for (u32 j = 0; j < h; ++j)
|
||||
{
|
||||
u32 *dataPtr = m_TerrainData + ((y + j) * (m_MapSize - 1)) + x;
|
||||
for(u32 i = 0; i < w; i++)
|
||||
u32* dataPtr = m_TerrainData + ((y + j) * (m_MapSize - 1)) + x;
|
||||
for (u32 i = 0; i < w; ++i)
|
||||
{
|
||||
float avgHeight = ( m_Terrain->GetVertexGroundLevel((int)i, (int)j)
|
||||
+ m_Terrain->GetVertexGroundLevel((int)i+1, (int)j)
|
||||
@ -686,11 +668,11 @@ void CMiniMap::RebuildTerrainTexture()
|
||||
|
||||
u32 color = 0xFFFFFFFF;
|
||||
|
||||
CMiniPatch *mp = m_Terrain->GetTile(x + i, y + j);
|
||||
if(mp)
|
||||
CMiniPatch* mp = m_Terrain->GetTile(x + i, y + j);
|
||||
if (mp)
|
||||
{
|
||||
CTerrainTextureEntry *tex = mp->GetTextureEntry();
|
||||
if(tex)
|
||||
CTerrainTextureEntry* tex = mp->GetTextureEntry();
|
||||
if (tex)
|
||||
{
|
||||
// If the texture can't be loaded yet, set the dirty flags
|
||||
// so we'll try regenerating the terrain texture again soon
|
||||
@ -713,12 +695,11 @@ void CMiniMap::RebuildTerrainTexture()
|
||||
|
||||
void CMiniMap::Destroy()
|
||||
{
|
||||
if(m_TerrainTexture)
|
||||
if (m_TerrainTexture)
|
||||
{
|
||||
glDeleteTextures(1, &m_TerrainTexture);
|
||||
m_TerrainTexture = 0;
|
||||
}
|
||||
|
||||
delete[] m_TerrainData;
|
||||
m_TerrainData = 0;
|
||||
SAFE_ARRAY_DELETE(m_TerrainData);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2013 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -37,7 +37,7 @@ protected:
|
||||
/**
|
||||
* @see IGUIObject#HandleMessage()
|
||||
*/
|
||||
virtual void HandleMessage(SGUIMessage &Message);
|
||||
virtual void HandleMessage(SGUIMessage& Message);
|
||||
|
||||
/**
|
||||
* @see IGUIObject#MouseOver()
|
||||
@ -84,7 +84,7 @@ protected:
|
||||
|
||||
// 1.f if map is circular or 1.414f if square (to shrink it inside the circle)
|
||||
float m_MapScale;
|
||||
|
||||
|
||||
// maximal water height to allow the passage of a unit (for underwater shallows).
|
||||
float m_ShallowPassageHeight;
|
||||
|
||||
@ -109,4 +109,4 @@ protected:
|
||||
bool m_BlinkState;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // INCLUDED_MINIMAP
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2013 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -30,7 +30,7 @@ JSClass JSI_GUISize::JSI_class = {
|
||||
NULL, NULL, JSI_GUISize::construct, NULL
|
||||
};
|
||||
|
||||
JSFunctionSpec JSI_GUISize::JSI_methods[] =
|
||||
JSFunctionSpec JSI_GUISize::JSI_methods[] =
|
||||
{
|
||||
JS_FS("toString", JSI_GUISize::toString, 0, 0),
|
||||
JS_FS_END
|
||||
@ -88,8 +88,8 @@ CStr ToPercentString(double pix, double per)
|
||||
{
|
||||
if (per == 0)
|
||||
return CStr::FromDouble(pix);
|
||||
else
|
||||
return CStr::FromDouble(per)+"%"+( pix == 0.0 ? CStr() : pix > 0.0 ? CStr("+")+CStr::FromDouble(pix) : CStr::FromDouble(pix) );
|
||||
|
||||
return CStr::FromDouble(per)+"%"+(pix == 0.0 ? CStr() : pix > 0.0 ? CStr("+")+CStr::FromDouble(pix) : CStr::FromDouble(pix));
|
||||
}
|
||||
|
||||
bool JSI_GUISize::toString(JSContext* cx, uint argc, jsval* vp)
|
||||
@ -103,9 +103,10 @@ bool JSI_GUISize::toString(JSContext* cx, uint argc, jsval* vp)
|
||||
ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface;
|
||||
double val, valr;
|
||||
#define SIDE(side) \
|
||||
pScriptInterface->GetProperty(rec.thisv(), #side, val); \
|
||||
pScriptInterface->GetProperty(rec.thisv(), "r"#side, valr); \
|
||||
buffer += ToPercentString(val, valr);
|
||||
pScriptInterface->GetProperty(rec.thisv(), #side, val); \
|
||||
pScriptInterface->GetProperty(rec.thisv(), "r"#side, valr); \
|
||||
buffer += ToPercentString(val, valr);
|
||||
|
||||
SIDE(left);
|
||||
buffer += " ";
|
||||
SIDE(top);
|
||||
@ -138,7 +139,7 @@ JSClass JSI_GUIColor::JSI_class = {
|
||||
NULL, NULL, JSI_GUIColor::construct, NULL
|
||||
};
|
||||
|
||||
JSFunctionSpec JSI_GUIColor::JSI_methods[] =
|
||||
JSFunctionSpec JSI_GUIColor::JSI_methods[] =
|
||||
{
|
||||
JS_FS("toString", JSI_GUIColor::toString, 0, 0),
|
||||
JS_FS_END
|
||||
@ -148,10 +149,10 @@ bool JSI_GUIColor::construct(JSContext* cx, uint argc, jsval* vp)
|
||||
{
|
||||
JSAutoRequest rq(cx);
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||
|
||||
|
||||
ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface;
|
||||
JS::RootedObject obj(cx, pScriptInterface->CreateCustomObject("GUIColor"));
|
||||
|
||||
|
||||
if (args.length() == 4)
|
||||
{
|
||||
JS_SetProperty(cx, obj, "r", args[0]);
|
||||
@ -208,7 +209,7 @@ JSClass JSI_GUIMouse::JSI_class = {
|
||||
NULL, NULL, JSI_GUIMouse::construct, NULL
|
||||
};
|
||||
|
||||
JSFunctionSpec JSI_GUIMouse::JSI_methods[] =
|
||||
JSFunctionSpec JSI_GUIMouse::JSI_methods[] =
|
||||
{
|
||||
JS_FS("toString", JSI_GUIMouse::toString, 0, 0),
|
||||
JS_FS_END
|
||||
|
@ -88,7 +88,7 @@ bool JSI_IGUIObject::getProperty(JSContext* cx, JS::HandleObject obj, JS::Handle
|
||||
// Use onWhatever to access event handlers
|
||||
if (propName.substr(0, 2) == "on")
|
||||
{
|
||||
CStr eventName (CStr(propName.substr(2)).LowerCase());
|
||||
CStr eventName(CStr(propName.substr(2)).LowerCase());
|
||||
auto it = e->m_ScriptHandlers.find(eventName);
|
||||
if (it == e->m_ScriptHandlers.end())
|
||||
vp.setNull();
|
||||
@ -135,162 +135,163 @@ bool JSI_IGUIObject::getProperty(JSContext* cx, JS::HandleObject obj, JS::Handle
|
||||
switch (Type)
|
||||
{
|
||||
case GUIST_bool:
|
||||
{
|
||||
bool value;
|
||||
GUI<bool>::GetSetting(e, propName, value);
|
||||
vp.set(JS::BooleanValue(value));
|
||||
break;
|
||||
}
|
||||
{
|
||||
bool value;
|
||||
GUI<bool>::GetSetting(e, propName, value);
|
||||
vp.set(JS::BooleanValue(value));
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIST_int:
|
||||
{
|
||||
int value;
|
||||
GUI<int>::GetSetting(e, propName, value);
|
||||
vp.set(JS::Int32Value(value));
|
||||
break;
|
||||
}
|
||||
{
|
||||
int value;
|
||||
GUI<int>::GetSetting(e, propName, value);
|
||||
vp.set(JS::Int32Value(value));
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIST_float:
|
||||
{
|
||||
float value;
|
||||
GUI<float>::GetSetting(e, propName, value);
|
||||
// Create a garbage-collectable double
|
||||
vp.set(JS::NumberValue(value));
|
||||
return !vp.isNull();
|
||||
}
|
||||
{
|
||||
float value;
|
||||
GUI<float>::GetSetting(e, propName, value);
|
||||
// Create a garbage-collectable double
|
||||
vp.set(JS::NumberValue(value));
|
||||
return !vp.isNull();
|
||||
}
|
||||
|
||||
case GUIST_CColor:
|
||||
{
|
||||
CColor color;
|
||||
GUI<CColor>::GetSetting(e, propName, color);
|
||||
JS::RootedObject obj(cx, pScriptInterface->CreateCustomObject("GUIColor"));
|
||||
vp.setObject(*obj);
|
||||
JS::RootedValue c(cx);
|
||||
// Attempt to minimise ugliness through macrosity
|
||||
#define P(x) c = JS::NumberValue(color.x); \
|
||||
if (c.isNull()) \
|
||||
return false; \
|
||||
JS_SetProperty(cx, obj, #x, c)
|
||||
P(r);
|
||||
P(g);
|
||||
P(b);
|
||||
P(a);
|
||||
#undef P
|
||||
{
|
||||
CColor color;
|
||||
GUI<CColor>::GetSetting(e, propName, color);
|
||||
JS::RootedObject obj(cx, pScriptInterface->CreateCustomObject("GUIColor"));
|
||||
vp.setObject(*obj);
|
||||
JS::RootedValue c(cx);
|
||||
// Attempt to minimise ugliness through macrosity
|
||||
#define P(x) \
|
||||
c = JS::NumberValue(color.x); \
|
||||
if (c.isNull()) \
|
||||
return false; \
|
||||
JS_SetProperty(cx, obj, #x, c)
|
||||
|
||||
break;
|
||||
}
|
||||
P(r);
|
||||
P(g);
|
||||
P(b);
|
||||
P(a);
|
||||
#undef P
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIST_CClientArea:
|
||||
{
|
||||
CClientArea area;
|
||||
GUI<CClientArea>::GetSetting(e, propName, area);
|
||||
|
||||
JS::RootedObject obj(cx, pScriptInterface->CreateCustomObject("GUISize"));
|
||||
vp.setObject(*obj);
|
||||
try
|
||||
{
|
||||
CClientArea area;
|
||||
GUI<CClientArea>::GetSetting(e, propName, area);
|
||||
|
||||
JS::RootedObject obj(cx, pScriptInterface->CreateCustomObject("GUISize"));
|
||||
vp.setObject(*obj);
|
||||
try
|
||||
{
|
||||
#define P(x, y, z) pScriptInterface->SetProperty(vp, #z, area.x.y, false, true)
|
||||
P(pixel, left, left);
|
||||
P(pixel, top, top);
|
||||
P(pixel, right, right);
|
||||
P(pixel, bottom, bottom);
|
||||
P(percent, left, rleft);
|
||||
P(percent, top, rtop);
|
||||
P(percent, right, rright);
|
||||
P(percent, bottom, rbottom);
|
||||
#undef P
|
||||
}
|
||||
catch (PSERROR_Scripting_ConversionFailed&)
|
||||
{
|
||||
debug_warn(L"Error creating size object!");
|
||||
break;
|
||||
}
|
||||
|
||||
#define P(x, y, z) pScriptInterface->SetProperty(vp, #z, area.x.y, false, true)
|
||||
P(pixel, left, left);
|
||||
P(pixel, top, top);
|
||||
P(pixel, right, right);
|
||||
P(pixel, bottom, bottom);
|
||||
P(percent, left, rleft);
|
||||
P(percent, top, rtop);
|
||||
P(percent, right, rright);
|
||||
P(percent, bottom, rbottom);
|
||||
#undef P
|
||||
}
|
||||
catch (PSERROR_Scripting_ConversionFailed&)
|
||||
{
|
||||
debug_warn(L"Error creating size object!");
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIST_CGUIString:
|
||||
{
|
||||
CGUIString value;
|
||||
GUI<CGUIString>::GetSetting(e, propName, value);
|
||||
ScriptInterface::ToJSVal(cx, vp, value.GetOriginalString());
|
||||
break;
|
||||
}
|
||||
{
|
||||
CGUIString value;
|
||||
GUI<CGUIString>::GetSetting(e, propName, value);
|
||||
ScriptInterface::ToJSVal(cx, vp, value.GetOriginalString());
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIST_CStr:
|
||||
{
|
||||
CStr value;
|
||||
GUI<CStr>::GetSetting(e, propName, value);
|
||||
ScriptInterface::ToJSVal(cx, vp, value);
|
||||
break;
|
||||
}
|
||||
{
|
||||
CStr value;
|
||||
GUI<CStr>::GetSetting(e, propName, value);
|
||||
ScriptInterface::ToJSVal(cx, vp, value);
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIST_CStrW:
|
||||
{
|
||||
CStrW value;
|
||||
GUI<CStrW>::GetSetting(e, propName, value);
|
||||
ScriptInterface::ToJSVal(cx, vp, value);
|
||||
break;
|
||||
}
|
||||
{
|
||||
CStrW value;
|
||||
GUI<CStrW>::GetSetting(e, propName, value);
|
||||
ScriptInterface::ToJSVal(cx, vp, value);
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIST_CGUISpriteInstance:
|
||||
{
|
||||
CGUISpriteInstance *value;
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(e, propName, value);
|
||||
ScriptInterface::ToJSVal(cx, vp, value->GetName());
|
||||
break;
|
||||
}
|
||||
{
|
||||
CGUISpriteInstance *value;
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(e, propName, value);
|
||||
ScriptInterface::ToJSVal(cx, vp, value->GetName());
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIST_EAlign:
|
||||
{
|
||||
EAlign value;
|
||||
GUI<EAlign>::GetSetting(e, propName, value);
|
||||
CStr word;
|
||||
switch (value)
|
||||
{
|
||||
EAlign value;
|
||||
GUI<EAlign>::GetSetting(e, propName, value);
|
||||
CStr word;
|
||||
switch (value)
|
||||
{
|
||||
case EAlign_Left: word = "left"; break;
|
||||
case EAlign_Right: word = "right"; break;
|
||||
case EAlign_Center: word = "center"; break;
|
||||
default: debug_warn(L"Invalid EAlign!"); word = "error"; break;
|
||||
}
|
||||
ScriptInterface::ToJSVal(cx, vp, word);
|
||||
break;
|
||||
case EAlign_Left: word = "left"; break;
|
||||
case EAlign_Right: word = "right"; break;
|
||||
case EAlign_Center: word = "center"; break;
|
||||
default: debug_warn(L"Invalid EAlign!"); word = "error"; break;
|
||||
}
|
||||
ScriptInterface::ToJSVal(cx, vp, word);
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIST_EVAlign:
|
||||
{
|
||||
EVAlign value;
|
||||
GUI<EVAlign>::GetSetting(e, propName, value);
|
||||
CStr word;
|
||||
switch (value)
|
||||
{
|
||||
EVAlign value;
|
||||
GUI<EVAlign>::GetSetting(e, propName, value);
|
||||
CStr word;
|
||||
switch (value)
|
||||
{
|
||||
case EVAlign_Top: word = "top"; break;
|
||||
case EVAlign_Bottom: word = "bottom"; break;
|
||||
case EVAlign_Center: word = "center"; break;
|
||||
default: debug_warn(L"Invalid EVAlign!"); word = "error"; break;
|
||||
}
|
||||
ScriptInterface::ToJSVal(cx, vp, word);
|
||||
break;
|
||||
case EVAlign_Top: word = "top"; break;
|
||||
case EVAlign_Bottom: word = "bottom"; break;
|
||||
case EVAlign_Center: word = "center"; break;
|
||||
default: debug_warn(L"Invalid EVAlign!"); word = "error"; break;
|
||||
}
|
||||
ScriptInterface::ToJSVal(cx, vp, word);
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIST_CGUIList:
|
||||
{
|
||||
CGUIList value;
|
||||
GUI<CGUIList>::GetSetting(e, propName, value);
|
||||
|
||||
JS::RootedObject obj(cx, JS_NewArrayObject(cx, JS::HandleValueArray::empty()));
|
||||
vp.setObject(*obj);
|
||||
|
||||
for (u32 i = 0; i < value.m_Items.size(); ++i)
|
||||
{
|
||||
CGUIList value;
|
||||
GUI<CGUIList>::GetSetting(e, propName, value);
|
||||
|
||||
JS::RootedObject obj(cx, JS_NewArrayObject(cx, JS::HandleValueArray::empty()));
|
||||
vp.setObject(*obj);
|
||||
|
||||
for (u32 i = 0; i < value.m_Items.size(); ++i)
|
||||
{
|
||||
JS::RootedValue val(cx);
|
||||
ScriptInterface::ToJSVal(cx, &val, value.m_Items[i].GetOriginalString());
|
||||
JS_SetElement(cx, obj, i, val);
|
||||
}
|
||||
|
||||
break;
|
||||
JS::RootedValue val(cx);
|
||||
ScriptInterface::ToJSVal(cx, &val, value.m_Items[i].GetOriginalString());
|
||||
JS_SetElement(cx, obj, i, val);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
JS_ReportError(cx, "Setting '%s' uses an unimplemented type", propName.c_str());
|
||||
DEBUG_WARN_ERR(ERR::LOGIC);
|
||||
@ -338,7 +339,7 @@ bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::Handle
|
||||
return false;
|
||||
}
|
||||
|
||||
CStr eventName (CStr(propName.substr(2)).LowerCase());
|
||||
CStr eventName(CStr(propName.substr(2)).LowerCase());
|
||||
e->SetScriptHandler(eventName, vpObj);
|
||||
|
||||
return true;
|
||||
@ -354,231 +355,232 @@ bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::Handle
|
||||
|
||||
switch (Type)
|
||||
{
|
||||
|
||||
case GUIST_CStr:
|
||||
{
|
||||
std::string value;
|
||||
if (!ScriptInterface::FromJSVal(cx, vp, value))
|
||||
return false;
|
||||
{
|
||||
std::string value;
|
||||
if (!ScriptInterface::FromJSVal(cx, vp, value))
|
||||
return false;
|
||||
|
||||
GUI<CStr>::SetSetting(e, propName, value);
|
||||
break;
|
||||
}
|
||||
GUI<CStr>::SetSetting(e, propName, value);
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIST_CStrW:
|
||||
{
|
||||
std::wstring value;
|
||||
if (!ScriptInterface::FromJSVal(cx, vp, value))
|
||||
return false;
|
||||
{
|
||||
std::wstring value;
|
||||
if (!ScriptInterface::FromJSVal(cx, vp, value))
|
||||
return false;
|
||||
|
||||
GUI<CStrW>::SetSetting(e, propName, value);
|
||||
break;
|
||||
}
|
||||
GUI<CStrW>::SetSetting(e, propName, value);
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIST_CGUISpriteInstance:
|
||||
{
|
||||
std::string value;
|
||||
if (!ScriptInterface::FromJSVal(cx, vp, value))
|
||||
return false;
|
||||
{
|
||||
std::string value;
|
||||
if (!ScriptInterface::FromJSVal(cx, vp, value))
|
||||
return false;
|
||||
|
||||
GUI<CGUISpriteInstance>::SetSetting(e, propName, CGUISpriteInstance(value));
|
||||
break;
|
||||
}
|
||||
GUI<CGUISpriteInstance>::SetSetting(e, propName, CGUISpriteInstance(value));
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIST_CGUIString:
|
||||
{
|
||||
std::wstring value;
|
||||
if (!ScriptInterface::FromJSVal(cx, vp, value))
|
||||
return false;
|
||||
|
||||
CGUIString str;
|
||||
str.SetValue(value);
|
||||
GUI<CGUIString>::SetSetting(e, propName, str);
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIST_EAlign:
|
||||
{
|
||||
std::string value;
|
||||
if (!ScriptInterface::FromJSVal(cx, vp, value))
|
||||
return false;
|
||||
|
||||
EAlign a;
|
||||
if (value == "left") a = EAlign_Left;
|
||||
else if (value == "right") a = EAlign_Right;
|
||||
else if (value == "center" || value == "centre") a = EAlign_Center;
|
||||
else
|
||||
{
|
||||
JS_ReportError(cx, "Invalid alignment (should be 'left', 'right' or 'center')");
|
||||
return false;
|
||||
}
|
||||
GUI<EAlign>::SetSetting(e, propName, a);
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIST_EVAlign:
|
||||
{
|
||||
std::string value;
|
||||
if (!ScriptInterface::FromJSVal(cx, vp, value))
|
||||
return false;
|
||||
|
||||
EVAlign a;
|
||||
if (value == "top") a = EVAlign_Top;
|
||||
else if (value == "bottom") a = EVAlign_Bottom;
|
||||
else if (value == "center" || value == "centre") a = EVAlign_Center;
|
||||
else
|
||||
{
|
||||
JS_ReportError(cx, "Invalid alignment (should be 'top', 'bottom' or 'center')");
|
||||
return false;
|
||||
}
|
||||
GUI<EVAlign>::SetSetting(e, propName, a);
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIST_int:
|
||||
{
|
||||
int value;
|
||||
if (ScriptInterface::FromJSVal(cx, vp, value))
|
||||
GUI<int>::SetSetting(e, propName, value);
|
||||
else
|
||||
{
|
||||
JS_ReportError(cx, "Cannot convert value to int");
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIST_float:
|
||||
{
|
||||
double value;
|
||||
if (JS::ToNumber(cx, vp, &value) == true)
|
||||
GUI<float>::SetSetting(e, propName, (float)value);
|
||||
else
|
||||
{
|
||||
JS_ReportError(cx, "Cannot convert value to float");
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIST_bool:
|
||||
{
|
||||
bool value = JS::ToBoolean(vp);
|
||||
GUI<bool>::SetSetting(e, propName, value);
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIST_CClientArea:
|
||||
{
|
||||
if (vp.isString())
|
||||
{
|
||||
std::wstring value;
|
||||
if (!ScriptInterface::FromJSVal(cx, vp, value))
|
||||
return false;
|
||||
|
||||
if (e->SetSetting(propName, value) != PSRETURN_OK)
|
||||
{
|
||||
JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (vp.isObject() && JS_InstanceOf(cx, vpObj, &JSI_GUISize::JSI_class, NULL))
|
||||
{
|
||||
CClientArea area;
|
||||
GUI<CClientArea>::GetSetting(e, propName, area);
|
||||
|
||||
ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface;
|
||||
#define P(x, y, z) pScriptInterface->GetProperty(vp, #z, area.x.y)
|
||||
P(pixel, left, left);
|
||||
P(pixel, top, top);
|
||||
P(pixel, right, right);
|
||||
P(pixel, bottom, bottom);
|
||||
P(percent, left, rleft);
|
||||
P(percent, top, rtop);
|
||||
P(percent, right, rright);
|
||||
P(percent, bottom, rbottom);
|
||||
#undef P
|
||||
|
||||
GUI<CClientArea>::SetSetting(e, propName, area);
|
||||
}
|
||||
else
|
||||
{
|
||||
JS_ReportError(cx, "Size only accepts strings or GUISize objects");
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIST_CColor:
|
||||
{
|
||||
if (vp.isString())
|
||||
{
|
||||
std::wstring value;
|
||||
if (!ScriptInterface::FromJSVal(cx, vp, value))
|
||||
return false;
|
||||
|
||||
if (e->SetSetting(propName, value) != PSRETURN_OK)
|
||||
{
|
||||
JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (vp.isObject() && JS_InstanceOf(cx, vpObj, &JSI_GUIColor::JSI_class, NULL))
|
||||
{
|
||||
CColor color;
|
||||
JS::RootedValue t(cx);
|
||||
double s;
|
||||
#define PROP(x) \
|
||||
JS_GetProperty(cx, vpObj, #x, &t); \
|
||||
s = t.toDouble(); \
|
||||
color.x = (float)s
|
||||
|
||||
PROP(r);
|
||||
PROP(g);
|
||||
PROP(b);
|
||||
PROP(a);
|
||||
#undef PROP
|
||||
GUI<CColor>::SetSetting(e, propName, color);
|
||||
}
|
||||
else
|
||||
{
|
||||
JS_ReportError(cx, "Color only accepts strings or GUIColor objects");
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIST_CGUIList:
|
||||
{
|
||||
u32 length;
|
||||
if (!vp.isObject() || !JS_GetArrayLength(cx, vpObj, &length))
|
||||
{
|
||||
JS_ReportError(cx, "List only accepts a GUIList object");
|
||||
return false;
|
||||
}
|
||||
|
||||
CGUIList list;
|
||||
|
||||
for (u32 i = 0; i < length; ++i)
|
||||
{
|
||||
JS::RootedValue element(cx);
|
||||
if (!JS_GetElement(cx, vpObj, i, &element))
|
||||
{
|
||||
JS_ReportError(cx, "Failed to get list element");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::wstring value;
|
||||
if (!ScriptInterface::FromJSVal(cx, element, value))
|
||||
return false;
|
||||
|
||||
CGUIString str;
|
||||
str.SetValue(value);
|
||||
GUI<CGUIString>::SetSetting(e, propName, str);
|
||||
break;
|
||||
|
||||
list.m_Items.push_back(str);
|
||||
}
|
||||
|
||||
case GUIST_EAlign:
|
||||
{
|
||||
std::string value;
|
||||
if (!ScriptInterface::FromJSVal(cx, vp, value))
|
||||
return false;
|
||||
|
||||
EAlign a;
|
||||
if (value == "left") a = EAlign_Left;
|
||||
else if (value == "right") a = EAlign_Right;
|
||||
else if (value == "center" || value == "centre") a = EAlign_Center;
|
||||
else
|
||||
{
|
||||
JS_ReportError(cx, "Invalid alignment (should be 'left', 'right' or 'center')");
|
||||
return false;
|
||||
}
|
||||
GUI<EAlign>::SetSetting(e, propName, a);
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIST_EVAlign:
|
||||
{
|
||||
std::string value;
|
||||
if (!ScriptInterface::FromJSVal(cx, vp, value))
|
||||
return false;
|
||||
|
||||
EVAlign a;
|
||||
if (value == "top") a = EVAlign_Top;
|
||||
else if (value == "bottom") a = EVAlign_Bottom;
|
||||
else if (value == "center" || value == "centre") a = EVAlign_Center;
|
||||
else
|
||||
{
|
||||
JS_ReportError(cx, "Invalid alignment (should be 'top', 'bottom' or 'center')");
|
||||
return false;
|
||||
}
|
||||
GUI<EVAlign>::SetSetting(e, propName, a);
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIST_int:
|
||||
{
|
||||
int value;
|
||||
if (ScriptInterface::FromJSVal(cx, vp, value))
|
||||
GUI<int>::SetSetting(e, propName, value);
|
||||
else
|
||||
{
|
||||
JS_ReportError(cx, "Cannot convert value to int");
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIST_float:
|
||||
{
|
||||
double value;
|
||||
if (JS::ToNumber(cx, vp, &value) == true)
|
||||
GUI<float>::SetSetting(e, propName, (float)value);
|
||||
else
|
||||
{
|
||||
JS_ReportError(cx, "Cannot convert value to float");
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIST_bool:
|
||||
{
|
||||
bool value = JS::ToBoolean(vp);
|
||||
GUI<bool>::SetSetting(e, propName, value);
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIST_CClientArea:
|
||||
{
|
||||
if (vp.isString())
|
||||
{
|
||||
std::wstring value;
|
||||
if (!ScriptInterface::FromJSVal(cx, vp, value))
|
||||
return false;
|
||||
|
||||
if (e->SetSetting(propName, value) != PSRETURN_OK)
|
||||
{
|
||||
JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (vp.isObject() && JS_InstanceOf(cx, vpObj, &JSI_GUISize::JSI_class, NULL))
|
||||
{
|
||||
CClientArea area;
|
||||
GUI<CClientArea>::GetSetting(e, propName, area);
|
||||
|
||||
ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface;
|
||||
#define P(x, y, z) pScriptInterface->GetProperty(vp, #z, area.x.y)
|
||||
P(pixel, left, left);
|
||||
P(pixel, top, top);
|
||||
P(pixel, right, right);
|
||||
P(pixel, bottom, bottom);
|
||||
P(percent, left, rleft);
|
||||
P(percent, top, rtop);
|
||||
P(percent, right, rright);
|
||||
P(percent, bottom, rbottom);
|
||||
#undef P
|
||||
|
||||
GUI<CClientArea>::SetSetting(e, propName, area);
|
||||
}
|
||||
else
|
||||
{
|
||||
JS_ReportError(cx, "Size only accepts strings or GUISize objects");
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIST_CColor:
|
||||
{
|
||||
if (vp.isString())
|
||||
{
|
||||
std::wstring value;
|
||||
if (!ScriptInterface::FromJSVal(cx, vp, value))
|
||||
return false;
|
||||
|
||||
if (e->SetSetting(propName, value) != PSRETURN_OK)
|
||||
{
|
||||
JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (vp.isObject() && JS_InstanceOf(cx, vpObj, &JSI_GUIColor::JSI_class, NULL))
|
||||
{
|
||||
CColor color;
|
||||
JS::RootedValue t(cx);
|
||||
double s;
|
||||
#define PROP(x) JS_GetProperty(cx, vpObj, #x, &t); \
|
||||
s = t.toDouble(); \
|
||||
color.x = (float)s
|
||||
PROP(r); PROP(g); PROP(b); PROP(a);
|
||||
#undef PROP
|
||||
|
||||
GUI<CColor>::SetSetting(e, propName, color);
|
||||
}
|
||||
else
|
||||
{
|
||||
JS_ReportError(cx, "Color only accepts strings or GUIColor objects");
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIST_CGUIList:
|
||||
{
|
||||
u32 length;
|
||||
if (!vp.isObject() || !JS_GetArrayLength(cx, vpObj, &length))
|
||||
{
|
||||
JS_ReportError(cx, "List only accepts a GUIList object");
|
||||
return false;
|
||||
}
|
||||
|
||||
CGUIList list;
|
||||
|
||||
for (u32 i=0; i<length; ++i)
|
||||
{
|
||||
JS::RootedValue element(cx);
|
||||
if (!JS_GetElement(cx, vpObj, i, &element))
|
||||
{
|
||||
JS_ReportError(cx, "Failed to get list element");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::wstring value;
|
||||
if (!ScriptInterface::FromJSVal(cx, element, value))
|
||||
return false;
|
||||
|
||||
CGUIString str;
|
||||
str.SetValue(value);
|
||||
|
||||
list.m_Items.push_back(str);
|
||||
}
|
||||
|
||||
GUI<CGUIList>::SetSetting(e, propName, list);
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO Gee: (2004-09-01) EAlign and EVAlign too.
|
||||
GUI<CGUIList>::SetSetting(e, propName, list);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
JS_ReportError(cx, "Setting '%s' uses an unimplemented type", propName.c_str());
|
||||
@ -594,7 +596,7 @@ bool JSI_IGUIObject::construct(JSContext* cx, uint argc, jsval* vp)
|
||||
JSAutoRequest rq(cx);
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||
ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface;
|
||||
|
||||
|
||||
if (args.length() == 0)
|
||||
{
|
||||
JS_ReportError(cx, "GUIObject has no default constructor");
|
||||
@ -616,14 +618,13 @@ void JSI_IGUIObject::init(ScriptInterface& scriptInterface)
|
||||
scriptInterface.DefineCustomObjectType(&JSI_class, construct, 1, JSI_props, JSI_methods, NULL, NULL);
|
||||
}
|
||||
|
||||
bool JSI_IGUIObject::toString(JSContext* cx, uint argc, jsval* vp)
|
||||
bool JSI_IGUIObject::toString(JSContext* cx, uint UNUSED(argc), jsval* vp)
|
||||
{
|
||||
UNUSED2(argc);
|
||||
JSAutoRequest rq(cx);
|
||||
JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
|
||||
|
||||
JS::RootedObject thisObj(cx, JS_THIS_OBJECT(cx, vp));
|
||||
|
||||
|
||||
IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, thisObj, &JSI_IGUIObject::JSI_class, NULL);
|
||||
if (!e)
|
||||
return false;
|
||||
@ -635,14 +636,13 @@ bool JSI_IGUIObject::toString(JSContext* cx, uint argc, jsval* vp)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JSI_IGUIObject::focus(JSContext* cx, uint argc, jsval* vp)
|
||||
bool JSI_IGUIObject::focus(JSContext* cx, uint UNUSED(argc), jsval* vp)
|
||||
{
|
||||
UNUSED2(argc);
|
||||
JSAutoRequest rq(cx);
|
||||
JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
|
||||
|
||||
JS::RootedObject thisObj(cx, JS_THIS_OBJECT(cx, vp));
|
||||
|
||||
|
||||
IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, thisObj, &JSI_IGUIObject::JSI_class, NULL);
|
||||
if (!e)
|
||||
return false;
|
||||
@ -653,14 +653,13 @@ bool JSI_IGUIObject::focus(JSContext* cx, uint argc, jsval* vp)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JSI_IGUIObject::blur(JSContext* cx, uint argc, jsval* vp)
|
||||
bool JSI_IGUIObject::blur(JSContext* cx, uint UNUSED(argc), jsval* vp)
|
||||
{
|
||||
UNUSED2(argc);
|
||||
JSAutoRequest rq(cx);
|
||||
JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
|
||||
|
||||
JS::RootedObject thisObj(cx, JS_THIS_OBJECT(cx, vp));
|
||||
|
||||
|
||||
IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, thisObj, &JSI_IGUIObject::JSI_class, NULL);
|
||||
if (!e)
|
||||
return false;
|
||||
@ -671,14 +670,13 @@ bool JSI_IGUIObject::blur(JSContext* cx, uint argc, jsval* vp)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JSI_IGUIObject::getComputedSize(JSContext* cx, uint argc, jsval* vp)
|
||||
bool JSI_IGUIObject::getComputedSize(JSContext* cx, uint UNUSED(argc), jsval* vp)
|
||||
{
|
||||
UNUSED2(argc);
|
||||
JSAutoRequest rq(cx);
|
||||
JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
|
||||
|
||||
|
||||
JS::RootedObject thisObj(cx, JS_THIS_OBJECT(cx, vp));
|
||||
|
||||
|
||||
IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, thisObj, &JSI_IGUIObject::JSI_class, NULL);
|
||||
if (!e)
|
||||
return false;
|
||||
|
@ -217,8 +217,8 @@ void StartGame(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue attribs,
|
||||
CSimulation2* sim = g_Game->GetSimulation2();
|
||||
JSContext* cxSim = sim->GetScriptInterface().GetContext();
|
||||
JSAutoRequest rqSim(cxSim);
|
||||
|
||||
JS::RootedValue gameAttribs(cxSim,
|
||||
|
||||
JS::RootedValue gameAttribs(cxSim,
|
||||
sim->GetScriptInterface().CloneValueFromOtherContext(*(pCxPrivate->pScriptInterface), attribs));
|
||||
|
||||
g_Game->SetPlayerID(playerID);
|
||||
@ -230,7 +230,7 @@ JS::Value StartSavedGame(ScriptInterface::CxPrivate* pCxPrivate, std::wstring na
|
||||
// We need to be careful with different compartments and contexts.
|
||||
// The GUI calls this function from the GUI context and expects the return value in the same context.
|
||||
// The game we start from here creates another context and expects data in this context.
|
||||
|
||||
|
||||
JSContext* cxGui = pCxPrivate->pScriptInterface->GetContext();
|
||||
JSAutoRequest rq(cxGui);
|
||||
|
||||
@ -247,13 +247,13 @@ JS::Value StartSavedGame(ScriptInterface::CxPrivate* pCxPrivate, std::wstring na
|
||||
return JS::UndefinedValue();
|
||||
|
||||
g_Game = new CGame();
|
||||
|
||||
|
||||
{
|
||||
CSimulation2* sim = g_Game->GetSimulation2();
|
||||
JSContext* cxGame = sim->GetScriptInterface().GetContext();
|
||||
JSAutoRequest rq(cxGame);
|
||||
|
||||
JS::RootedValue gameContextMetadata(cxGame,
|
||||
|
||||
JS::RootedValue gameContextMetadata(cxGame,
|
||||
sim->GetScriptInterface().CloneValueFromOtherContext(*(pCxPrivate->pScriptInterface), guiContextMetadata));
|
||||
JS::RootedValue gameInitAttributes(cxGame);
|
||||
sim->GetScriptInterface().GetProperty(gameContextMetadata, "initAttributes", &gameInitAttributes);
|
||||
@ -464,7 +464,7 @@ JS::Value GetMapSettings(ScriptInterface::CxPrivate* pCxPrivate)
|
||||
|
||||
JSContext* cx = g_Game->GetSimulation2()->GetScriptInterface().GetContext();
|
||||
JSAutoRequest rq(cx);
|
||||
|
||||
|
||||
JS::RootedValue mapSettings(cx);
|
||||
g_Game->GetSimulation2()->GetMapSettings(&mapSettings);
|
||||
return pCxPrivate->pScriptInterface->CloneValueFromOtherContext(
|
||||
@ -716,7 +716,7 @@ void SetPaused(ScriptInterface::CxPrivate* pCxPrivate, bool pause)
|
||||
}
|
||||
g_Game->m_Paused = pause;
|
||||
#if CONFIG2_AUDIO
|
||||
if ( g_SoundManager )
|
||||
if (g_SoundManager)
|
||||
g_SoundManager->Pause(pause);
|
||||
#endif
|
||||
}
|
||||
@ -888,7 +888,7 @@ static void InitJsTimers(ScriptInterface& scriptInterface)
|
||||
void StartJsTimer(ScriptInterface::CxPrivate* pCxPrivate, unsigned int slot)
|
||||
{
|
||||
ONCE(InitJsTimers(*(pCxPrivate->pScriptInterface)));
|
||||
|
||||
|
||||
if (slot >= MAX_JS_TIMERS)
|
||||
LOGERROR("Exceeded the maximum number of timer slots for scripts!");
|
||||
|
||||
@ -923,7 +923,7 @@ void GuiScriptingInit(ScriptInterface& scriptInterface)
|
||||
JSI_Sound::RegisterScriptFunctions(scriptInterface);
|
||||
JSI_L10n::RegisterScriptFunctions(scriptInterface);
|
||||
JSI_Lobby::RegisterScriptFunctions(scriptInterface);
|
||||
|
||||
|
||||
// VFS (external)
|
||||
scriptInterface.RegisterFunction<JS::Value, std::wstring, std::wstring, bool, &JSI_VFS::BuildDirEntList>("BuildDirEntList");
|
||||
scriptInterface.RegisterFunction<bool, CStrW, JSI_VFS::FileExists>("FileExists");
|
||||
|
Loading…
Reference in New Issue
Block a user