1
0
forked from 0ad/0ad

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:
leper 2015-08-21 17:08:41 +00:00
parent d821601978
commit 74c420f658
56 changed files with 2476 additions and 3368 deletions

View File

@ -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,14 +69,14 @@ 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);
@ -95,16 +87,19 @@ 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);

View File

@ -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 - 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
*
@ -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

View File

@ -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);
@ -120,7 +112,10 @@ 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);

View File

@ -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 - 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
*
@ -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

View File

@ -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");
@ -72,7 +65,7 @@ void CDropDown::SetupText()
CList::SetupText();
}
void CDropDown::HandleMessage(SGUIMessage &Message)
void CDropDown::HandleMessage(SGUIMessage& Message)
{
// Important
@ -96,26 +89,26 @@ void CDropDown::HandleMessage(SGUIMessage &Message)
case GUIM_MOUSE_MOTION:
{
if (m_Open)
{
if (!m_Open)
break;
CPos mouse = GetMousePos();
if (GetListRect().PointInside(mouse))
{
if (!GetListRect().PointInside(mouse))
break;
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();
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] &&
@ -129,12 +122,9 @@ void CDropDown::HandleMessage(SGUIMessage &Message)
if (set != -1)
{
//GUI<int>::SetSetting(this, "selected", set);
m_ElementHighlight = set;
//UpdateAutoScroll();
}
}
}
break;
}
@ -143,12 +133,12 @@ void CDropDown::HandleMessage(SGUIMessage &Message)
{
bool enabled;
GUI<bool>::GetSetting(this, "enabled", enabled);
if (enabled)
{
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)
{
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;
}
@ -344,18 +334,18 @@ InReaction CDropDown::ManuallyHandleEvent(const SDL_Event_* ev)
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)
@ -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,14 +467,12 @@ 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);
@ -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;

View File

@ -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.
@ -137,4 +121,4 @@ protected:
};
#endif
#endif // INCLUDED_CDROPDOWN

View File

@ -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)
@ -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.
@ -310,11 +301,8 @@ void CGUI::SendEventToAll(const CStr& EventName)
&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);
@ -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,9 +508,9 @@ 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
@ -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,
@ -613,11 +591,9 @@ SGUIText CGUI::GenerateText(const CGUIString &string,
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;
@ -631,10 +607,10 @@ SGUIText CGUI::GenerateText(const CGUIString &string,
_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.
@ -781,19 +755,16 @@ SGUIText CGUI::GenerateText(const CGUIString &string,
// 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];
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;
@ -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;
@ -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,7 +1499,7 @@ 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
@ -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
if (attr_name == "texture_size")
Image->m_Size = ca;
}
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
if (attr_name == "real_texture_placement")
Image->m_TextureSize = ca;
}
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
if (attr_name == "cell_size")
Image->m_TexturePlacementInFile = rect;
}
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
if (attr_name == "fixed_h_aspect_ratio")
Image->m_CellSize = size;
}
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
if (attr_name == "round_coordinates")
Image->m_FixedHAspectRatio = val;
}
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
if (attr_name == "wrap_mode")
Image->m_RoundCoordinates = b;
}
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
if (attr_name == "backcolor")
Image->m_DeltaZ = z_level/100.f;
}
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
if (attr_name == "bordercolor")
Image->m_BackColor = color;
}
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
if (attr_name == "border")
Image->m_BorderColor = color;
}
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())
{
@ -1801,8 +1733,7 @@ void CGUI::Xeromyces_ReadScrollBarStyle(XMBElement Element, CXeromyces* pFile)
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,41 +1765,29 @@ 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;
}
@ -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
CStr value(Element.GetText());
if (!value.empty())
{
if (value.empty())
return;
// Try setting color to value
if (!color.ParseString(value))
{
LOGERROR("GUI: Unable to create custom color '%s'. Invalid color syntax.", name.c_str());
return;
}
else
{
// input color
m_PreDefinedColors[name] = color;
}
}
}

View File

@ -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;
};
@ -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
@ -252,9 +225,7 @@ public:
* @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,7 +242,7 @@ 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(); };
@ -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
@ -671,4 +642,4 @@ private:
std::map<CStr, SGUIIcon> m_Icons;
};
#endif
#endif // INCLUDED_CGUI

View File

@ -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;
@ -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,7 +93,8 @@ 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,
@ -123,7 +125,7 @@ void CGUIScrollBarVertical::Draw()
}
}
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;

View File

@ -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

View File

@ -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();

View File

@ -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,6 +54,8 @@ 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)
@ -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

View File

@ -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");
@ -43,15 +37,15 @@ CImage::~CImage()
void CImage::Draw()
{
if (GetGUI())
{
if (!GetGUI())
return;
float bz = GetBufferedZ();
CGUISpriteInstance *sprite;
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);
}
}

View File

@ -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.
@ -75,4 +47,4 @@ protected:
virtual void Draw();
};
#endif
#endif // INCLUDED_CIMAGE

View File

@ -15,20 +15,18 @@
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
/*
CInput
*/
#include "precompiled.h"
#include "GUI.h"
#include "CInput.h"
#include "CGUIScrollBarVertical.h"
#include "GUI.h"
#include "graphics/FontMetrics.h"
#include "graphics/ShaderManager.h"
#include "graphics/TextRenderer.h"
#include "lib/ogl.h"
#include "lib/external_libraries/libsdl.h"
#include "lib/ogl.h"
#include "lib/sysdep/clipboard.h"
#include "lib/timer.h"
#include "lib/utf8.h"
@ -42,9 +40,6 @@ CInput
extern int g_yres;
//-------------------------------------------------------------------
// Constructor / Destructor
//-------------------------------------------------------------------
CInput::CInput()
: m_iBufferPos(-1), m_iBufferPos_Tail(-1), m_SelectingText(false), m_HorizontalScroll(0.f),
m_PrevTime(0.0), m_CursorVisState(true), m_CursorBlinkRate(0.5), m_ComposingText(false),
@ -71,7 +66,7 @@ CInput::CInput()
CFG_GET_VAL("gui.cursorblinkrate", m_CursorBlinkRate);
// Add scroll-bar
CGUIScrollBarVertical * bar = new CGUIScrollBarVertical();
CGUIScrollBarVertical* bar = new CGUIScrollBarVertical();
bar->SetRightAligned(true);
AddScrollBar(bar);
}
@ -88,7 +83,7 @@ void CInput::UpdateBufferPositionSetting()
void CInput::ClearComposedText()
{
CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
pCaption->erase(m_iInsertPos, m_iComposedLength);
m_iBufferPos = m_iInsertPos;
UpdateBufferPositionSetting();
@ -112,10 +107,10 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
else if (ev->ev.type == SDL_TEXTINPUT)
{
// Text has been committed, either single key presses or through an IME
CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
std::wstring text = wstring_from_utf8(ev->ev.text.text);
m_WantedX=0.0f;
m_WantedX = 0.0f;
if (SelectingText())
DeleteCurSelection();
@ -145,13 +140,13 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
{
// Text is being composed with an IME
// TODO: indicate this by e.g. underlining the uncommitted text
CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
const char *rawText = ev->ev.edit.text;
CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
const char* rawText = ev->ev.edit.text;
int rawLength = strlen(rawText);
std::wstring wtext = wstring_from_utf8(rawText);
debug_printf("SDL_TEXTEDITING: text=%s, start=%d, length=%d\n", rawText, ev->ev.edit.start, ev->ev.edit.length);
m_WantedX=0.0f;
m_WantedX = 0.0f;
if (SelectingText())
DeleteCurSelection();
@ -195,7 +190,7 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
// Since the GUI framework doesn't handle to set settings
// in Unicode (CStrW), we'll simply retrieve the actual
// pointer and edit that.
CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
bool shiftKeyPressed = g_keys[SDLK_RSHIFT] || g_keys[SDLK_LSHIFT];
#if !SDL_VERSION_ATLEAST(2, 0, 0)
@ -217,7 +212,7 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
break;
case SDLK_BACKSPACE: // '\b'
m_WantedX=0.0f;
m_WantedX = 0.0f;
if (SelectingText())
DeleteCurSelection();
@ -226,47 +221,38 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
m_iBufferPos_Tail = -1;
if (pCaption->empty() || m_iBufferPos == 0)
{
break;
}
else
{
if (m_iBufferPos == (int)pCaption->length())
*pCaption = pCaption->Left( (long) pCaption->length()-1);
*pCaption = pCaption->Left((long)pCaption->length()-1);
else
*pCaption = pCaption->Left( m_iBufferPos-1 ) +
pCaption->Right( (long) pCaption->length()-m_iBufferPos );
*pCaption = pCaption->Left(m_iBufferPos-1) +
pCaption->Right((long)pCaption->length()-m_iBufferPos);
--m_iBufferPos;
UpdateText(m_iBufferPos, m_iBufferPos+1, m_iBufferPos);
}
}
UpdateAutoScroll();
break;
case SDLK_DELETE:
m_WantedX=0.0f;
m_WantedX = 0.0f;
// If selection:
if (SelectingText())
{
DeleteCurSelection();
}
else
{
if (pCaption->empty() || m_iBufferPos == (int)pCaption->length())
{
break;
}
else
{
*pCaption = pCaption->Left( m_iBufferPos ) +
pCaption->Right( (long) pCaption->length()-(m_iBufferPos+1) );
*pCaption = pCaption->Left(m_iBufferPos) +
pCaption->Right((long)pCaption->length()-(m_iBufferPos+1));
UpdateText(m_iBufferPos, m_iBufferPos+1, m_iBufferPos);
}
}
UpdateAutoScroll();
break;
@ -285,7 +271,7 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
}
m_iBufferPos = 0;
m_WantedX=0.0f;
m_WantedX = 0.0f;
UpdateAutoScroll();
break;
@ -303,47 +289,42 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
m_iBufferPos_Tail = m_iBufferPos;
}
m_iBufferPos = (long) pCaption->length();
m_WantedX=0.0f;
m_iBufferPos = (long)pCaption->length();
m_WantedX = 0.0f;
UpdateAutoScroll();
break;
/**
Conventions for Left/Right when text is selected:
References:
Visual Studio
Visual Studio has the 'newer' approach, used by newer versions of
things, and in newer applications. A left press will always place
the pointer on the left edge of the selection, and then of course
remove the selection. Right will do the exakt same thing.
If you have the pointer on the right edge and press right, it will
in other words just remove the selection.
Windows (eg. Notepad)
A left press always takes the pointer a step to the left and
removes the selection as if it were never there in the first place.
Right of course does the same thing but to the right.
I chose the Visual Studio convention. Used also in Word, gtk 2.0, MSN
Messenger.
**/
* Conventions for Left/Right when text is selected:
*
* References:
*
* Visual Studio
* Visual Studio has the 'newer' approach, used by newer versions of
* things, and in newer applications. A left press will always place
* the pointer on the left edge of the selection, and then of course
* remove the selection. Right will do the exact same thing.
* If you have the pointer on the right edge and press right, it will
* in other words just remove the selection.
*
* Windows (eg. Notepad)
* A left press always takes the pointer a step to the left and
* removes the selection as if it were never there in the first place.
* Right of course does the same thing but to the right.
*
* I chose the Visual Studio convention. Used also in Word, gtk 2.0, MSN
* Messenger.
*/
case SDLK_LEFT:
m_WantedX=0.f;
m_WantedX = 0.f;
if (shiftKeyPressed || !SelectingText())
{
if (!shiftKeyPressed)
{
m_iBufferPos_Tail = -1;
}
else if (!SelectingText())
{
m_iBufferPos_Tail = m_iBufferPos;
}
if (m_iBufferPos > 0)
--m_iBufferPos;
@ -360,18 +341,14 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
break;
case SDLK_RIGHT:
m_WantedX=0.0f;
m_WantedX = 0.0f;
if (shiftKeyPressed || !SelectingText())
{
if (!shiftKeyPressed)
{
m_iBufferPos_Tail = -1;
}
else if (!SelectingText())
{
m_iBufferPos_Tail = m_iBufferPos;
}
if (m_iBufferPos < (int)pCaption->length())
++m_iBufferPos;
@ -388,35 +365,30 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
break;
/**
Conventions for Up/Down when text is selected:
References:
Visual Studio
Visual Studio has a very strange approach, down takes you below the
selection to the next row, and up to the one prior to the whole
selection. The weird part is that it is always aligned as the
'pointer'. I decided this is to much work for something that is
a bit arbitrary
Windows (eg. Notepad)
Just like with left/right, the selection is destroyed and it moves
just as if there never were a selection.
I chose the Notepad convention even though I use the VS convention with
left/right.
**/
* Conventions for Up/Down when text is selected:
*
* References:
*
* Visual Studio
* Visual Studio has a very strange approach, down takes you below the
* selection to the next row, and up to the one prior to the whole
* selection. The weird part is that it is always aligned as the
* 'pointer'. I decided this is to much work for something that is
* a bit arbitrary
*
* Windows (eg. Notepad)
* Just like with left/right, the selection is destroyed and it moves
* just as if there never were a selection.
*
* I chose the Notepad convention even though I use the VS convention with
* left/right.
*/
case SDLK_UP:
{
if (!shiftKeyPressed)
{
m_iBufferPos_Tail = -1;
}
else if (!SelectingText())
{
m_iBufferPos_Tail = m_iBufferPos;
}
std::list<SRow>::iterator current = m_CharacterPositions.begin();
while (current != m_CharacterPositions.end())
@ -449,19 +421,15 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
// else we can't move up
UpdateAutoScroll();
}
break;
}
case SDLK_DOWN:
{
if (!shiftKeyPressed)
{
m_iBufferPos_Tail = -1;
}
else if (!SelectingText())
{
m_iBufferPos_Tail = m_iBufferPos;
}
std::list<SRow>::iterator current = m_CharacterPositions.begin();
while (current != m_CharacterPositions.end())
@ -494,8 +462,8 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
// else we can't move up
UpdateAutoScroll();
}
break;
}
case SDLK_PAGEUP:
GetScrollBar(0).ScrollMinusPlenty();
@ -522,7 +490,7 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
cooked = '\n'; // Change to '\n' and do default:
// NOTE: Fall-through
}
default: //Insert a character
default: // Insert a character
{
#if !SDL_VERSION_ATLEAST(2, 0, 0)
if (cooked == 0)
@ -540,7 +508,7 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
if (max_length != 0 && (int)pCaption->length() >= max_length)
break;
m_WantedX=0.0f;
m_WantedX = 0.0f;
if (SelectingText())
DeleteCurSelection();
@ -557,9 +525,9 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
++m_iBufferPos;
UpdateAutoScroll();
}
break;
}
}
UpdateBufferPositionSetting();
return IN_HANDLED;
@ -571,21 +539,19 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
InReaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event_* ev)
{
CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
bool shiftKeyPressed = g_keys[SDLK_RSHIFT] || g_keys[SDLK_LSHIFT];
std::string hotkey = static_cast<const char*>(ev->ev.user.data1);
if (hotkey == "paste")
{
m_WantedX=0.0f;
m_WantedX = 0.0f;
wchar_t* text = sys_clipboard_get();
if (text)
{
if (SelectingText())
{
DeleteCurSelection();
}
if (m_iBufferPos == (int)pCaption->length())
*pCaption += text;
@ -605,7 +571,7 @@ InReaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event_* ev)
}
else if (hotkey == "copy" || hotkey == "cut")
{
m_WantedX=0.0f;
m_WantedX = 0.0f;
if (SelectingText())
{
@ -637,7 +603,7 @@ InReaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event_* ev)
}
else if (hotkey == "text.delete.left")
{
m_WantedX=0.0f;
m_WantedX = 0.0f;
if (SelectingText())
{
@ -646,7 +612,7 @@ InReaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event_* ev)
if (!pCaption->empty() && m_iBufferPos != 0)
{
m_iBufferPos_Tail = m_iBufferPos;
CStrW searchString = pCaption->Left( m_iBufferPos );
CStrW searchString = pCaption->Left(m_iBufferPos);
// If we are starting in whitespace, adjust position until we get a non whitespace
while (m_iBufferPos > 0)
@ -679,7 +645,7 @@ InReaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event_* ev)
}
else if (hotkey == "text.delete.right")
{
m_WantedX=0.0f;
m_WantedX = 0.0f;
if (SelectingText())
{
@ -703,7 +669,7 @@ InReaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event_* ev)
if (!iswspace((*pCaption)[m_iBufferPos]))
break;
m_iBufferPos++;
++m_iBufferPos;
}
UpdateBufferPositionSetting();
DeleteCurSelection();
@ -712,7 +678,7 @@ InReaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event_* ev)
}
else if (hotkey == "text.move.left")
{
m_WantedX=0.0f;
m_WantedX = 0.0f;
if (shiftKeyPressed || !SelectingText())
{
@ -727,7 +693,7 @@ InReaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event_* ev)
if (!pCaption->empty() && m_iBufferPos != 0)
{
CStrW searchString = pCaption->Left( m_iBufferPos );
CStrW searchString = pCaption->Left(m_iBufferPos);
// If we are starting in whitespace, adjust position until we get a non whitespace
while (m_iBufferPos > 0)
@ -769,7 +735,7 @@ InReaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event_* ev)
}
else if (hotkey == "text.move.right")
{
m_WantedX=0.0f;
m_WantedX = 0.0f;
if (shiftKeyPressed || !SelectingText())
{
@ -799,7 +765,7 @@ InReaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event_* ev)
if (!iswspace((*pCaption)[m_iBufferPos]))
break;
m_iBufferPos++;
++m_iBufferPos;
}
}
}
@ -823,9 +789,8 @@ InReaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event_* ev)
}
void CInput::HandleMessage(SGUIMessage &Message)
void CInput::HandleMessage(SGUIMessage& Message)
{
// TODO Gee:
IGUIScrollBarOwner::HandleMessage(Message);
switch (Message.type)
@ -886,16 +851,16 @@ void CInput::HandleMessage(SGUIMessage &Message)
UpdateText();
}
}break;
break;
}
case GUIM_MOUSE_PRESS_LEFT:
// Check if we're selecting the scrollbar:
{
bool scrollbar, multiline;
GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
GUI<bool>::GetSetting(this, "multiline", multiline);
// Check if we're selecting the scrollbar
if (GetScrollBar(0).GetStyle() && multiline)
{
if (GetMousePos().x > m_CachedActualSize.right - GetScrollBar(0).GetStyle()->m_Width)
@ -921,17 +886,17 @@ void CInput::HandleMessage(SGUIMessage &Message)
// If we immediately release the button it will just be seen as a click
// for the user though.
}break;
break;
}
case GUIM_MOUSE_DBLCLICK_LEFT:
{
if (m_ComposingText)
break;
CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
if (pCaption->length() == 0)
if (pCaption->empty())
break;
m_iBufferPos = m_iBufferPos_Tail = GetMouseHoveringTextPosition();
@ -1033,14 +998,12 @@ void CInput::HandleMessage(SGUIMessage &Message)
break;
}
}
}
break;
}
case GUIM_MOUSE_RELEASE_LEFT:
if (m_SelectingText)
{
m_SelectingText = false;
}
break;
case GUIM_MOUSE_MOTION:
@ -1060,18 +1023,18 @@ void CInput::HandleMessage(SGUIMessage &Message)
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);
UpdateText();
}
break;
}
case GUIM_GOT_FOCUS:
m_iBufferPos = 0;
@ -1164,16 +1127,13 @@ void CInput::Draw()
GUI<bool>::GetSetting(this, "mask", mask);
if (scrollbar && multiline)
{
// Draw scrollbar
IGUIScrollBarOwner::Draw();
}
if (GetGUI())
{
if (!GetGUI())
return;
CStrW font_name_w;
CColor color, color_selected;
//CStrW caption;
GUI<CStrW>::GetSetting(this, "font", font_name_w);
GUI<CColor>::GetSetting(this, "textcolor", color);
GUI<CColor>::GetSetting(this, "textcolor_selected", color_selected);
@ -1181,7 +1141,7 @@ void CInput::Draw()
// Get pointer of caption, it might be very large, and we don't
// want to copy it continuously.
CStrW *pCaption = NULL;
CStrW* pCaption = NULL;
wchar_t mask_char = L'*';
if (mask)
{
@ -1193,7 +1153,8 @@ void CInput::Draw()
else
pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
CGUISpriteInstance *sprite=NULL, *sprite_selectarea=NULL;
CGUISpriteInstance* sprite = NULL;
CGUISpriteInstance* sprite_selectarea = NULL;
int cell_id;
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
@ -1203,11 +1164,9 @@ void CInput::Draw()
GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize);
float scroll=0.f;
float scroll = 0.f;
if (scrollbar && multiline)
{
scroll = GetScrollBar(0).GetPos();
}
CFontMetrics font(font_name);
@ -1280,9 +1239,9 @@ void CInput::Draw()
// started, because we need to follow the iteration until we
// reach the end, before we can actually draw it.
bool drawing_box = false;
float box_x=0.f;
float box_x = 0.f;
float x_pointer=0.f;
float x_pointer = 0.f;
// If we have a selecting box (i.e. when you have selected letters, not just when
// the pointer is between two letters) we need to process all letters once
@ -1321,15 +1280,13 @@ void CInput::Draw()
it != m_CharacterPositions.end();
++it, buffered_y += ls, x_pointer = 0.f)
{
if (multiline)
{
if (buffered_y > m_CachedActualSize.GetHeight())
if (multiline
&& buffered_y > m_CachedActualSize.GetHeight())
break;
}
// We might as well use 'i' here to iterate, because we need it
// (often compared against ints, so don't make it size_t)
for (int i=0; i < (int)it->m_ListOfX.size()+2; ++i)
for (int i = 0; i < (int)it->m_ListOfX.size()+2; ++i)
{
if (it->m_ListStart + i == VirtualFrom)
{
@ -1418,11 +1375,9 @@ void CInput::Draw()
// line, we need to draw that line's box, and then reset
// the box drawing to the beginning of the new line.
if (drawing_box)
{
box_x = 0.f;
}
}
}
// Reset some from previous run
buffered_y = -scroll;
@ -1440,11 +1395,9 @@ void CInput::Draw()
{
if (buffered_y + buffer_zone >= -ls || !multiline)
{
if (multiline)
{
if (buffered_y + buffer_zone > m_CachedActualSize.GetHeight())
if (multiline
&& buffered_y + buffer_zone > m_CachedActualSize.GetHeight())
break;
}
CMatrix3D savedTransform = textRenderer.GetTransform();
@ -1456,7 +1409,7 @@ void CInput::Draw()
// We might as well use 'i' here, because we need it
// (often compared against ints, so don't make it size_t)
for (int i=0; i < (int)it->m_ListOfX.size()+1; ++i)
for (int i = 0; i < (int)it->m_ListOfX.size()+1; ++i)
{
if (!multiline && i < (int)it->m_ListOfX.size())
{
@ -1480,13 +1433,11 @@ void CInput::Draw()
textRenderer.Color(color);
}
if (i != (int)it->m_ListOfX.size() &&
it->m_ListStart + i == m_iBufferPos)
{
// selecting only one, then we need only to draw a cursor.
if (m_CursorVisState)
if (i != (int)it->m_ListOfX.size()
&& it->m_ListStart + i == m_iBufferPos
&& m_CursorVisState)
textRenderer.Put(0.0f, 0.0f, L"_");
}
// Drawing selected area
if (SelectingText() &&
@ -1507,12 +1458,10 @@ void CInput::Draw()
}
// check it's now outside a one-liner, then we'll break
if (!multiline && i < (int)it->m_ListOfX.size())
{
if (it->m_ListOfX[i] - m_HorizontalScroll > m_CachedActualSize.GetWidth()-buffer_zone)
if (!multiline && i < (int)it->m_ListOfX.size()
&& it->m_ListOfX[i] - m_HorizontalScroll > m_CachedActualSize.GetWidth()-buffer_zone)
break;
}
}
if (it->m_ListStart + (int)it->m_ListOfX.size() == m_iBufferPos)
{
@ -1521,10 +1470,8 @@ void CInput::Draw()
textRenderer.PutAdvance(L"_");
if (using_selected_color)
{
textRenderer.Color(color_selected);
}
}
textRenderer.SetTransform(savedTransform);
}
@ -1538,7 +1485,6 @@ void CInput::Draw()
glDisable(GL_SCISSOR_TEST);
tech->EndPass();
}
}
void CInput::UpdateText(int from, int to_before, int to_after)
@ -1603,20 +1549,23 @@ void CInput::UpdateText(int from, int to_before, int to_after)
{
ENSURE(to_before != -1);
std::list<SRow>::iterator destroy_row_from, destroy_row_to;
std::list<SRow>::iterator destroy_row_from;
std::list<SRow>::iterator destroy_row_to;
// Used to check if the above has been set to anything,
// previously a comparison like:
// destroy_row_from == std::list<SRow>::iterator()
// ... was used, but it didn't work with GCC.
bool destroy_row_from_used=false, destroy_row_to_used=false;
bool destroy_row_from_used = false;
bool destroy_row_to_used = false;
// Iterate, and remove everything between 'from' and 'to_before'
// actually remove the entire lines they are on, it'll all have
// to be redone. And when going along, we'll delete a row at a time
// when continuing to see how much more after 'to' we need to remake.
int i=0;
int i = 0;
for (std::list<SRow>::iterator it = m_CharacterPositions.begin();
it != m_CharacterPositions.end(); ++it, ++i)
it != m_CharacterPositions.end();
++it, ++i)
{
if (destroy_row_from_used == false &&
it->m_ListStart > from)
@ -1707,9 +1656,7 @@ void CInput::UpdateText(int from, int to_before, int to_after)
for (std::list<SRow>::iterator it = current_line;
it != m_CharacterPositions.end();
++it)
{
it->m_ListStart += delta;
}
// Update our check point too!
check_point_row_start += delta;
@ -1720,21 +1667,20 @@ void CInput::UpdateText(int from, int to_before, int to_after)
}
}
int last_word_started=from;
//int last_list_start=-1; // unused
int last_word_started = from;
float x_pos = 0.f;
//if (to_before != -1)
// return;
for (int i=from; i<to; ++i)
for (int i = from; i < to; ++i)
{
if (caption[i] == L'\n' && multiline)
{
if (i==to-1 && to != (int)caption.length())
if (i == to-1 && to != (int)caption.length())
break; // it will be added outside
current_line = m_CharacterPositions.insert( current_line, row );
current_line = m_CharacterPositions.insert(current_line, row);
++current_line;
@ -1764,7 +1710,7 @@ void CInput::UpdateText(int from, int to_before, int to_after)
{
last_word_started = i;
row.m_ListOfX.resize(row.m_ListOfX.size() - (i-last_word_started));
//row.m_ListOfX.push_back( x_pos );
//row.m_ListOfX.push_back(x_pos);
//continue;
}
else
@ -1779,20 +1725,20 @@ void CInput::UpdateText(int from, int to_before, int to_after)
// rows. With automatic word-wrapping, that is not possible. Which
// is intuitively correct.
current_line = m_CharacterPositions.insert( current_line, row );
current_line = m_CharacterPositions.insert(current_line, row);
++current_line;
// Setup the next row:
row.m_ListOfX.clear();
row.m_ListStart = last_word_started;
i=last_word_started-1;
i = last_word_started-1;
x_pos = 0.f;
}
else
// Get width of this character:
row.m_ListOfX.push_back( x_pos );
row.m_ListOfX.push_back(x_pos);
}
// Check if it's the last iteration, and we're not revising the whole string
@ -1803,20 +1749,23 @@ void CInput::UpdateText(int from, int to_before, int to_after)
// check all rows and see if any existing
if (row.m_ListStart != check_point_row_start)
{
std::list<SRow>::iterator destroy_row_from, destroy_row_to;
std::list<SRow>::iterator destroy_row_from;
std::list<SRow>::iterator destroy_row_to;
// Are used to check if the above has been set to anything,
// previously a comparison like:
// destroy_row_from == std::list<SRow>::iterator()
// was used, but it didn't work with GCC.
bool destroy_row_from_used=false, destroy_row_to_used=false;
bool destroy_row_from_used = false;
bool destroy_row_to_used = false;
// Iterate, and remove everything between 'from' and 'to_before'
// actually remove the entire lines they are on, it'll all have
// to be redone. And when going along, we'll delete a row at a time
// when continuing to see how much more after 'to' we need to remake.
int i=0;
for (std::list<SRow>::iterator it=m_CharacterPositions.begin();
it!=m_CharacterPositions.end(); ++it, ++i)
int i = 0;
for (std::list<SRow>::iterator it = m_CharacterPositions.begin();
it != m_CharacterPositions.end();
++it, ++i)
{
if (destroy_row_from_used == false &&
it->m_ListStart > check_point_row_start)
@ -1843,7 +1792,6 @@ void CInput::UpdateText(int from, int to_before, int to_after)
// have to continue.
// 'check_point_row_start' is where we store how the that
// line looked.
// if (destroy_row_to !=
if (destroy_row_to != m_CharacterPositions.end())
{
check_point_row_start = destroy_row_to->m_ListStart;
@ -1884,10 +1832,6 @@ void CInput::UpdateText(int from, int to_before, int to_after)
// in the coming erase.
current_line = destroy_row_to;
std::list<SRow>::iterator temp = destroy_row_to;
--temp;
m_CharacterPositions.erase(destroy_row_from, destroy_row_to);
}
// else, the for loop will end naturally.
@ -1900,7 +1844,7 @@ void CInput::UpdateText(int from, int to_before, int to_after)
if (current_line != m_CharacterPositions.end())
{
if (row.m_ListStart + (int)row.m_ListOfX.size() == current_line->m_ListStart)
row.m_ListOfX.resize( row.m_ListOfX.size()-1 );
row.m_ListOfX.resize(row.m_ListOfX.size()-1);
}
// add the final row (even if empty)
@ -1916,7 +1860,7 @@ void CInput::UpdateText(int from, int to_before, int to_after)
}
}
int CInput::GetMouseHoveringTextPosition()
int CInput::GetMouseHoveringTextPosition() const
{
if (m_CharacterPositions.empty())
return 0;
@ -1929,7 +1873,7 @@ int CInput::GetMouseHoveringTextPosition()
GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
GUI<bool>::GetSetting(this, "multiline", multiline);
std::list<SRow>::iterator current = m_CharacterPositions.begin();
std::list<SRow>::const_iterator current = m_CharacterPositions.begin();
CPos mouse = GetMousePos();
@ -1941,30 +1885,21 @@ int CInput::GetMouseHoveringTextPosition()
GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
CStrIntern font_name(font_name_w.ToUTF8());
float scroll=0.f;
float scroll = 0.f;
if (scrollbar)
{
scroll = GetScrollBar(0).GetPos();
}
// Pointer to caption, will come in handy
CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
UNUSED2(pCaption);
scroll = GetScrollBarPos(0);
// Now get the height of the font.
// TODO: Get the real font
CFontMetrics font(font_name);
float spacing = (float)font.GetLineSpacing();
//float height = (float)font.GetHeight(); // unused
// Change mouse position relative to text.
mouse -= m_CachedActualSize.TopLeft();
mouse.x -= buffer_zone;
mouse.y += scroll - buffer_zone;
//if ((m_CharacterPositions.size()-1) * spacing + height < mouse.y)
// m_iBufferPos = pCaption->Length();
int row = (int)((mouse.y) / spacing);//m_CharachterPositions.size()
int row = (int)((mouse.y) / spacing);
if (row < 0)
row = 0;
@ -1975,7 +1910,7 @@ int CInput::GetMouseHoveringTextPosition()
// TODO Gee (2004-11-21): Okay, I need a 'std::list' for some reasons, but I would really like to
// be able to get the specific element here. This is hopefully a temporary hack.
for (int i=0; i<row; ++i)
for (int i = 0; i < row; ++i)
++current;
}
else
@ -1987,7 +1922,6 @@ int CInput::GetMouseHoveringTextPosition()
// mouse.y is moot
}
//m_iBufferPos = m_CharacterPositions.get.m_ListStart;
retPosition = current->m_ListStart;
// Okay, now loop through the glyphs to find the appropriate X position
@ -1998,14 +1932,14 @@ int CInput::GetMouseHoveringTextPosition()
}
// Does not process horizontal scrolling, 'x' must be modified before inputted.
int CInput::GetXTextPosition(const std::list<SRow>::iterator &current, const float &x, float &wanted)
int CInput::GetXTextPosition(const std::list<SRow>::const_iterator& current, const float& x, float& wanted) const
{
int ret=0;
float previous=0.f;
int i=0;
int ret = 0;
float previous = 0.f;
int i = 0;
for (std::vector<float>::iterator it=current->m_ListOfX.begin();
it!=current->m_ListOfX.end();
for (std::vector<float>::const_iterator it = current->m_ListOfX.begin();
it != current->m_ListOfX.end();
++it, ++i)
{
if (*it >= x)
@ -2026,14 +1960,15 @@ int CInput::GetXTextPosition(const std::list<SRow>::iterator &current, const flo
ret += i;
wanted = x;
}
else wanted = 0.f;
else
wanted = 0.f;
return ret;
}
void CInput::DeleteCurSelection()
{
CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
int virtualFrom;
int virtualTo;
@ -2049,8 +1984,8 @@ void CInput::DeleteCurSelection()
virtualTo = m_iBufferPos;
}
*pCaption = pCaption->Left( virtualFrom ) +
pCaption->Right( (long) pCaption->length() - (virtualTo) );
*pCaption = pCaption->Left(virtualFrom) +
pCaption->Right((long)pCaption->length() - virtualTo);
UpdateText(virtualFrom, virtualTo, virtualFrom);
@ -2095,7 +2030,7 @@ void CInput::UpdateAutoScroll()
GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
CStrIntern font_name(font_name_w.ToUTF8());
float scroll=0.f;
float scroll = 0.f;
if (!scrollbar)
return;
@ -2111,7 +2046,7 @@ void CInput::UpdateAutoScroll()
// be able to get the specific element here. This is hopefully a temporary hack.
std::list<SRow>::iterator current = m_CharacterPositions.begin();
int row=0;
int row = 0;
while (current != m_CharacterPositions.end())
{
if (m_iBufferPos >= current->m_ListStart &&
@ -2128,9 +2063,8 @@ void CInput::UpdateAutoScroll()
// Scroll so the selected row is shown completely, also with buffer_zone length to the edge.
GetScrollBar(0).SetPos((float)(row+1) * spacing - m_CachedActualSize.GetHeight() + buffer_zone*2.f);
}
else
// If scrolling up
if (-scroll + (float)row * spacing < 0.f)
else if (-scroll + (float)row * spacing < 0.f)
{
// Scroll so the selected row is shown completely, also with buffer_zone length to the edge.
GetScrollBar(0).SetPos((float)row * spacing);
@ -2153,7 +2087,7 @@ void CInput::UpdateAutoScroll()
x_position = m_CharacterPositions.begin()->m_ListOfX[m_iBufferPos-1];
// Get complete length:
x_total = m_CharacterPositions.begin()->m_ListOfX[ m_CharacterPositions.begin()->m_ListOfX.size()-1 ];
x_total = m_CharacterPositions.begin()->m_ListOfX[m_CharacterPositions.begin()->m_ListOfX.size()-1];
}
// Check if outside to the right

View File

@ -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

View File

@ -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);
@ -134,24 +120,21 @@ 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")
@ -175,9 +156,7 @@ void CList::HandleMessage(SGUIMessage &Message)
}
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] &&
@ -246,9 +223,9 @@ void CList::HandleMessage(SGUIMessage &Message)
{
CStr scrollbar_style;
GUI<CStr>::GetSetting(this, "scrollbar_style", scrollbar_style);
GetScrollBar(0).SetScrollBarStyle( scrollbar_style );
}
GetScrollBar(0).SetScrollBarStyle(scrollbar_style);
break;
}
default:
break;
@ -317,10 +294,7 @@ void CList::Draw()
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;
}
}
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)
@ -490,9 +458,7 @@ void CList::SelectFirstElement()
GUI<int>::GetSetting(this, "selected", selected);
if (selected >= 0)
{
GUI<int>::SetSetting(this, "selected", 0);
}
}
void CList::SelectLastElement()
@ -500,13 +466,11 @@ 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());
}
}

View File

@ -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

View File

@ -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);
@ -155,7 +154,7 @@ void COList::HandleMessage(SGUIMessage &Message)
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,20 +244,25 @@ 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")
if (attributeName.empty() || attributeName != "heading")
{
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())
{
if (value.empty())
continue;
CStr context(grandchild.GetAttributes().GetNamedItem(attr_context)); // Read the context if any.
if (!context.empty())
{
@ -280,13 +275,6 @@ bool COList::HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile
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());
}
}
}
m_ObjectsDefs.push_back(oDef);
@ -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,31 +298,28 @@ 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, *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_name", 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)
{
@ -374,13 +356,14 @@ void COList::DrawList(const int &selected,
CColor color;
GUI<CColor>::GetSetting(this, _textcolor, color);
CGUISpriteInstance *sprite_heading=NULL;
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;
CGUISpriteInstance* sprite_order;
CGUISpriteInstance* sprite_not_sorted;
if (m_SelectedColumnOrder != -1)
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_asc", sprite_order);
else
@ -388,7 +371,7 @@ void COList::DrawList(const int &selected,
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_not_sorted", sprite_not_sorted);
float xpos = 0;
for (unsigned int def=0; def< m_ObjectsDefs.size(); ++def)
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;
@ -396,9 +379,9 @@ void COList::DrawList(const int &selected,
width *= m_TotalAvalibleColumnWidth;
CPos leftTopCorner = m_CachedActualSize.TopLeft() + CPos(xpos, 0);
CGUISpriteInstance *sprite;
CGUISpriteInstance* sprite;
// If the list sorted by current column
if (m_SelectedDef == static_cast<int> (def))
if (m_SelectedDef == def)
sprite = sprite_order;
else
sprite = sprite_not_sorted;
@ -408,8 +391,8 @@ void COList::DrawList(const int &selected,
xpos += width;
}
const unsigned int objectsCount = m_ObjectsDefs.size();
for (int i=0; i<(int)pList->m_Items.size(); ++i)
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())
@ -432,7 +415,7 @@ void COList::DrawList(const int &selected,
}
xpos = 0;
for (unsigned int def=0; def < objectsCount; ++def)
for (size_t def = 0; def < objectsCount; ++def)
{
// Determine text position and width
const CPos textPos = rect.TopLeft() + CPos(xpos, -scroll + m_ItemsYPositions[i]);
@ -451,5 +434,4 @@ void COList::DrawList(const int &selected,
xpos += width;
}
}
}
}

View File

@ -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:

View File

@ -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);
@ -70,11 +63,13 @@ void CProgressBar::HandleMessage(SGUIMessage &Message)
void CProgressBar::Draw()
{
if (GetGUI())
{
if (!GetGUI())
return;
float bz = GetBufferedZ();
CGUISpriteInstance *sprite_background, *sprite_bar;
CGUISpriteInstance* sprite_background;
CGUISpriteInstance* sprite_bar;
int cell_id = 0;
float value = 0;
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_background", sprite_background);
@ -83,10 +78,8 @@ void CProgressBar::Draw()
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);
}
}

View File

@ -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,41 +15,13 @@
* 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
*/
@ -71,7 +43,7 @@ protected:
/**
* @see IGUIObject#HandleMessage()
*/
void HandleMessage(SGUIMessage &Message);
void HandleMessage(SGUIMessage& Message);
};
#endif
#endif // INCLUDED_CPROGRESSBAR

View File

@ -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,18 +30,16 @@ void CRadioButton::HandleMessage(SGUIMessage &Message)
switch (Message.type)
{
case GUIM_PRESSED:
{
for (vector_pObjects::iterator it = GetParent()->ChildrenItBegin(); it != GetParent()->ChildrenItEnd(); ++it)
for (IGUIObject* const& obj : *GetParent())
{
// 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(obj, "checked", false);
}
GUI<bool>::SetSetting(this, "checked", true);
break;
}
default:
break;

View File

@ -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,25 +15,9 @@
* 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"
@ -51,7 +35,7 @@ public:
/**
* @see IGUIObject#HandleMessage()
*/
virtual void HandleMessage(SGUIMessage &Message);
virtual void HandleMessage(SGUIMessage& Message);
};
#endif
#endif // INCLUDED_CRADIOBUTTON

View File

@ -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();
}
@ -172,16 +164,16 @@ void CText::HandleMessage(SGUIMessage &Message)
}
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;
@ -199,14 +191,13 @@ void CText::Draw()
GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
if (scrollbar)
{
// Draw scrollbar
IGUIScrollBarOwner::Draw();
}
if (GetGUI())
{
CGUISpriteInstance *sprite;
if (!GetGUI())
return;
CGUISpriteInstance* sprite;
int cell_id;
bool clip;
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
@ -215,11 +206,9 @@ void CText::Draw()
GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize);
float scroll=0.f;
float scroll = 0.f;
if (scrollbar)
{
scroll = GetScrollBar(0).GetPos();
}
// Clipping area (we'll have to subtract the scrollbar)
CRect cliparea;
@ -247,27 +236,19 @@ void CText::Draw()
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)
for (SGUIText* const& guitext : m_GeneratedTexts)
for (const SGUIText::SSpriteCall& spritecall : guitext->m_SpriteCalls)
{
SGUIText* guitext = *text_it;
// Check mouse over sprite
if (!spritecall.m_Area.PointInside(GetMousePos() - m_CachedActualSize.TopLeft()))
continue;
for (sprite_it=guitext->m_SpriteCalls.begin(); sprite_it!=guitext->m_SpriteCalls.end(); ++sprite_it)
{
//Check mouse over sprite
SGUIText::SSpriteCall spritecall = *sprite_it;
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);
@ -275,8 +256,6 @@ bool CText::MouseOverIcon()
return true;
}
}
}
return false;
}

View File

@ -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,11 @@
* 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.
*
@ -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

View File

@ -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())
@ -144,18 +142,19 @@ 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()
{
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;
CGUISpriteInstance* sprite;
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
// Normally IGUITextOwner will handle this updating but since SetupText can modify the position
@ -172,5 +171,4 @@ void CTooltip::Draw()
GUI<CColor>::GetSetting(this, "textcolor", color);
DrawText(0, color, m_CachedActualSize.TopLeft(), z+0.1f);
}
}

View File

@ -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

View File

@ -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

View File

@ -118,14 +118,14 @@ void CGUIManager::PopPageCB(shared_ptr<ScriptInterface::StructuredClone> args)
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!");
@ -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)
for (SGUIPage& p : m_PageStack)
if (p.inputs.count(path))
{
if (it->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;
}
@ -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);
}
@ -398,10 +396,10 @@ void CGUIManager::TickObjects()
// 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);
}

View File

@ -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;
@ -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.
@ -143,7 +142,7 @@ public:
/**
* 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.

View File

@ -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:
@ -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)

View File

@ -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

View File

@ -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
@ -339,8 +340,8 @@ void GUITooltip::Update(IGUIObject* Nearest, CPos MousePos, CGUI* GUI)
// "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;

View File

@ -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);

View File

@ -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
//--------------------------------------------------------

View File

@ -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
@ -32,42 +32,24 @@ 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
@ -193,7 +175,7 @@ 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:
@ -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

View File

@ -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());
}

View File

@ -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

View File

@ -15,27 +15,22 @@
* 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
return false;
@ -44,28 +39,28 @@ bool __ParseString<bool>(const CStrW& Value, bool &Output)
}
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,7 +316,7 @@ 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);
@ -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,8 +365,7 @@ 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);
@ -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);

View File

@ -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,33 +32,21 @@ 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;
/**
@ -72,15 +60,15 @@ 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);
};
@ -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,15 +129,13 @@ 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);
}
@ -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,7 +163,7 @@ 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);
}
@ -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,7 +190,7 @@ 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));
@ -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,7 +249,7 @@ 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))
@ -278,11 +258,8 @@ private:
(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,7 +267,7 @@ 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;
@ -298,11 +275,8 @@ private:
(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

View File

@ -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,19 +159,15 @@ 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())
{
if (!GetGUI())
return;
bool enabled;
GUI<bool>::GetSetting(this, "enabled", enabled);
@ -208,5 +182,4 @@ void IGUIButtonBehavior::DrawButton(const CRect &rect,
}
else
GetGUI()->DrawSprite(sprite, cell_id, z, rect);
}
}

View File

@ -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

View File

@ -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)
{
switch (it->second.m_Type)
for (const std::pair<CStr, SGUISetting>& p : m_Settings)
switch (p.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;
#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,7 +99,7 @@ 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;
}
@ -130,7 +107,7 @@ void IGUIObject::AddChild(IGUIObject *pChild)
// 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());
@ -201,10 +178,13 @@ 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,10 +268,11 @@ PSRETURN IGUIObject::GetSettingType(const CStr& Setting, EGUISettingType &Type)
}
void IGUIObject::ChooseMouseOverAndClosest(IGUIObject* &pObject)
void IGUIObject::ChooseMouseOverAndClosest(IGUIObject*& pObject)
{
if (MouseOver())
{
if (!MouseOver())
return;
// Check if we've got competition at all
if (pObject == NULL)
{
@ -312,10 +286,9 @@ void IGUIObject::ChooseMouseOverAndClosest(IGUIObject* &pObject)
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
@ -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.
@ -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());
@ -571,13 +543,13 @@ 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",
Setting.c_str());

View File

@ -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,7 +173,7 @@ 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
@ -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(); }
//@}
//--------------------------------------------------------
@ -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
@ -300,7 +283,7 @@ 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.
@ -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,12 +347,12 @@ 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:
@ -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
@ -579,4 +564,4 @@ public:
virtual bool MouseOver() { return false; }
};
#endif
#endif // INCLUDED_IGUIOBJECT

View File

@ -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,17 +15,11 @@
* 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.
@ -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,7 +69,7 @@ const SGUIScrollBarStyle *IGUIScrollBar::GetStyle() const
return m_pHostObject->GetScrollBarStyle(m_ScrollBarStyle);
}
CGUI *IGUIScrollBar::GetGUI() const
CGUI* IGUIScrollBar::GetGUI() const
{
if (!m_pHostObject)
return NULL;
@ -87,12 +82,11 @@ 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)
{
@ -136,24 +130,22 @@ void IGUIScrollBar::HandleMessage(SGUIMessage &Message)
m_BarPressedAtPos = mouse;
m_PosWhenPressed = m_Pos;
}
else
// if button-minus is pressed
if (m_ButtonMinusHovered)
else if (m_ButtonMinusHovered)
{
m_ButtonMinusPressed = true;
ScrollMinus();
}
else
// if button-plus is pressed
if (m_ButtonPlusHovered)
else 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
else
{
if (GetOuterRect().PointInside(mouse))
{
@ -172,11 +164,9 @@ void IGUIScrollBar::HandleMessage(SGUIMessage &Message)
}
case GUIM_MOUSE_RELEASE_LEFT:
{
m_ButtonMinusPressed = false;
m_ButtonPlusPressed = false;
break;
}
case GUIM_MOUSE_WHEEL_UP:
{

View File

@ -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.
*
@ -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,19 +233,19 @@ 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
@ -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.
@ -451,4 +444,4 @@ protected:
//@}
};
#endif
#endif // INCLUDED_IGUISCROLLBAR

View File

@ -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()
{
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();
}

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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"
@ -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)
{
SetCameraPos();
m_Clicking = true;
}
break;
}
case GUIM_MOUSE_RELEASE_LEFT:
{
if(m_MouseHovering && m_Clicking)
if (m_MouseHovering && m_Clicking)
SetCameraPos();
m_Clicking = false;
break;
}
case GUIM_MOUSE_DBLCLICK_LEFT:
{
if(m_MouseHovering && m_Clicking)
if (m_MouseHovering && m_Clicking)
SetCameraPos();
m_Clicking = false;
break;
}
case GUIM_MOUSE_ENTER:
{
m_MouseHovering = true;
break;
}
case GUIM_MOUSE_LEAVE:
{
m_Clicking = false;
m_MouseHovering = false;
break;
}
case GUIM_MOUSE_RELEASE_RIGHT:
{
CMiniMap::FireWorldClickEvent(SDL_BUTTON_RIGHT, 1);
break;
}
case GUIM_MOUSE_DBLCLICK_RIGHT:
{
CMiniMap::FireWorldClickEvent(SDL_BUTTON_RIGHT, 2);
break;
}
case GUIM_MOUSE_MOTION:
{
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,7 +232,7 @@ 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);
@ -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);
@ -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);
}

View File

@ -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()
@ -109,4 +109,4 @@ protected:
bool m_BlinkState;
};
#endif
#endif // INCLUDED_MINIMAP

View File

@ -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
@ -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)
@ -106,6 +106,7 @@ bool JSI_GUISize::toString(JSContext* cx, uint argc, jsval* vp)
pScriptInterface->GetProperty(rec.thisv(), #side, val); \
pScriptInterface->GetProperty(rec.thisv(), "r"#side, valr); \
buffer += ToPercentString(val, valr);
SIDE(left);
buffer += " ";
SIDE(top);

View File

@ -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();
@ -167,16 +167,17 @@ bool JSI_IGUIObject::getProperty(JSContext* cx, JS::HandleObject obj, JS::Handle
vp.setObject(*obj);
JS::RootedValue c(cx);
// Attempt to minimise ugliness through macrosity
#define P(x) c = JS::NumberValue(color.x); \
#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
#undef P
break;
}
@ -189,7 +190,7 @@ bool JSI_IGUIObject::getProperty(JSContext* cx, JS::HandleObject obj, JS::Handle
vp.setObject(*obj);
try
{
#define P(x, y, z) pScriptInterface->SetProperty(vp, #z, area.x.y, false, true)
#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);
@ -198,7 +199,7 @@ bool JSI_IGUIObject::getProperty(JSContext* cx, JS::HandleObject obj, JS::Handle
P(percent, top, rtop);
P(percent, right, rright);
P(percent, bottom, rbottom);
#undef P
#undef P
}
catch (PSERROR_Scripting_ConversionFailed&)
{
@ -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,7 +355,6 @@ bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::Handle
switch (Type)
{
case GUIST_CStr:
{
std::string value;
@ -488,7 +488,7 @@ bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::Handle
GUI<CClientArea>::GetSetting(e, propName, area);
ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface;
#define P(x, y, z) pScriptInterface->GetProperty(vp, #z, area.x.y)
#define P(x, y, z) pScriptInterface->GetProperty(vp, #z, area.x.y)
P(pixel, left, left);
P(pixel, top, top);
P(pixel, right, right);
@ -497,7 +497,7 @@ bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::Handle
P(percent, top, rtop);
P(percent, right, rright);
P(percent, bottom, rbottom);
#undef P
#undef P
GUI<CClientArea>::SetSetting(e, propName, area);
}
@ -528,12 +528,16 @@ bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::Handle
CColor color;
JS::RootedValue t(cx);
double s;
#define PROP(x) JS_GetProperty(cx, vpObj, #x, &t); \
#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
PROP(r);
PROP(g);
PROP(b);
PROP(a);
#undef PROP
GUI<CColor>::SetSetting(e, propName, color);
}
else
@ -555,7 +559,7 @@ bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::Handle
CGUIList list;
for (u32 i=0; i<length; ++i)
for (u32 i = 0; i < length; ++i)
{
JS::RootedValue element(cx);
if (!JS_GetElement(cx, vpObj, i, &element))
@ -578,8 +582,6 @@ bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::Handle
break;
}
// TODO Gee: (2004-09-01) EAlign and EVAlign too.
default:
JS_ReportError(cx, "Setting '%s' uses an unimplemented type", propName.c_str());
break;
@ -616,9 +618,8 @@ 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);
@ -635,9 +636,8 @@ 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);
@ -653,9 +653,8 @@ 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);
@ -671,9 +670,8 @@ 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);

View File

@ -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
}