forked from 0ad/0ad
Moves CSize into a separate file and renames it to CSize2D according to other geometric entities.
This was SVN commit r25143.
This commit is contained in:
parent
fa3e501f8f
commit
db84c2a9b2
@ -1228,8 +1228,8 @@ void CGUI::Xeromyces_ReadIcon(XMBElement Element, CXeromyces* pFile)
|
|||||||
icon.m_SpriteName = attr_value;
|
icon.m_SpriteName = attr_value;
|
||||||
else if (attr_name == "size")
|
else if (attr_name == "size")
|
||||||
{
|
{
|
||||||
CSize size;
|
CSize2D size;
|
||||||
if (!ParseString<CSize>(this, attr_value.FromUTF8(), size))
|
if (!ParseString<CSize2D>(this, attr_value.FromUTF8(), size))
|
||||||
LOGERROR("Error parsing '%s' (\"%s\") inside <icon>.", attr_name, attr_value);
|
LOGERROR("Error parsing '%s' (\"%s\") inside <icon>.", attr_name, attr_value);
|
||||||
else
|
else
|
||||||
icon.m_Size = size;
|
icon.m_Size = size;
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "gui/SGUIIcon.h"
|
#include "gui/SGUIIcon.h"
|
||||||
#include "gui/SGUIStyle.h"
|
#include "gui/SGUIStyle.h"
|
||||||
#include "lib/input.h"
|
#include "lib/input.h"
|
||||||
|
#include "maths/Size2D.h"
|
||||||
#include "ps/Shapes.h"
|
#include "ps/Shapes.h"
|
||||||
#include "ps/XML/Xeromyces.h"
|
#include "ps/XML/Xeromyces.h"
|
||||||
#include "scriptinterface/ScriptInterface.h"
|
#include "scriptinterface/ScriptInterface.h"
|
||||||
|
@ -35,20 +35,20 @@ extern float g_GuiScale;
|
|||||||
// TODO Gee: CRect => CPoint ?
|
// TODO Gee: CRect => CPoint ?
|
||||||
void SGenerateTextImage::SetupSpriteCall(
|
void SGenerateTextImage::SetupSpriteCall(
|
||||||
const bool Left, CGUIText::SSpriteCall& SpriteCall, const float width, const float y,
|
const bool Left, CGUIText::SSpriteCall& SpriteCall, const float width, const float y,
|
||||||
const CSize& Size, const CStr& TextureName, const float BufferZone)
|
const CSize2D& Size, const CStr& TextureName, const float BufferZone)
|
||||||
{
|
{
|
||||||
// TODO Gee: Temp hardcoded values
|
// TODO Gee: Temp hardcoded values
|
||||||
SpriteCall.m_Area.top = y + BufferZone;
|
SpriteCall.m_Area.top = y + BufferZone;
|
||||||
SpriteCall.m_Area.bottom = y + BufferZone + Size.cy;
|
SpriteCall.m_Area.bottom = y + BufferZone + Size.Height;
|
||||||
|
|
||||||
if (Left)
|
if (Left)
|
||||||
{
|
{
|
||||||
SpriteCall.m_Area.left = BufferZone;
|
SpriteCall.m_Area.left = BufferZone;
|
||||||
SpriteCall.m_Area.right = Size.cx + BufferZone;
|
SpriteCall.m_Area.right = Size.Width + BufferZone;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SpriteCall.m_Area.left = width-BufferZone - Size.cx;
|
SpriteCall.m_Area.left = width-BufferZone - Size.Width;
|
||||||
SpriteCall.m_Area.right = width-BufferZone;
|
SpriteCall.m_Area.right = width-BufferZone;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ void SGenerateTextImage::SetupSpriteCall(
|
|||||||
|
|
||||||
m_YFrom = SpriteCall.m_Area.top - BufferZone;
|
m_YFrom = SpriteCall.m_Area.top - BufferZone;
|
||||||
m_YTo = SpriteCall.m_Area.bottom + BufferZone;
|
m_YTo = SpriteCall.m_Area.bottom + BufferZone;
|
||||||
m_Indentation = Size.cx + BufferZone * 2;
|
m_Indentation = Size.Width + BufferZone * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
CGUIText::CGUIText(const CGUI& pGUI, const CGUIString& string, const CStrW& FontW, const float Width, const float BufferZone, const IGUIObject* pObject)
|
CGUIText::CGUIText(const CGUI& pGUI, const CGUIString& string, const CStrW& FontW, const float Width, const float BufferZone, const IGUIObject* pObject)
|
||||||
@ -102,8 +102,8 @@ CGUIText::CGUIText(const CGUI& pGUI, const CGUIString& string, const CStrW& Font
|
|||||||
|
|
||||||
pos_last_img = std::max(pos_last_img, i);
|
pos_last_img = std::max(pos_last_img, i);
|
||||||
|
|
||||||
x += Feedback.m_Size.cx;
|
x += Feedback.m_Size.Width;
|
||||||
prelim_line_height = std::max(prelim_line_height, Feedback.m_Size.cy);
|
prelim_line_height = std::max(prelim_line_height, Feedback.m_Size.Height);
|
||||||
|
|
||||||
// If Width is 0, then there's no word-wrapping, disable NewLine.
|
// If Width is 0, then there's no word-wrapping, disable NewLine.
|
||||||
if (((Width != 0 && (x > Width - BufferZone || Feedback.m_NewLine)) || i == static_cast<int>(string.m_Words.size()) - 2) &&
|
if (((Width != 0 && (x > Width - BufferZone || Feedback.m_NewLine)) || i == static_cast<int>(string.m_Words.size()) - 2) &&
|
||||||
@ -147,7 +147,7 @@ void CGUIText::SetupSpriteCalls(
|
|||||||
Image.SetupSpriteCall(j == CGUIString::SFeedback::Left, SpriteCall, Width, _y, icon.m_Size, icon.m_SpriteName, BufferZone);
|
Image.SetupSpriteCall(j == CGUIString::SFeedback::Left, SpriteCall, Width, _y, icon.m_Size, icon.m_SpriteName, BufferZone);
|
||||||
|
|
||||||
// Check if image is the lowest thing.
|
// Check if image is the lowest thing.
|
||||||
m_Size.cy = std::max(m_Size.cy, Image.m_YTo);
|
m_Size.Height = std::max(m_Size.Height, Image.m_YTo);
|
||||||
|
|
||||||
Images[j].emplace_back(Image);
|
Images[j].emplace_back(Image);
|
||||||
m_SpriteCalls.emplace_back(std::move(SpriteCall));
|
m_SpriteCalls.emplace_back(std::move(SpriteCall));
|
||||||
@ -171,7 +171,7 @@ void CGUIText::ComputeLineSize(
|
|||||||
const int i,
|
const int i,
|
||||||
const int temp_from,
|
const int temp_from,
|
||||||
float& x,
|
float& x,
|
||||||
CSize& line_size) const
|
CSize2D& line_size) const
|
||||||
{
|
{
|
||||||
for (int j = temp_from; j <= i; ++j)
|
for (int j = temp_from; j <= i; ++j)
|
||||||
{
|
{
|
||||||
@ -184,7 +184,7 @@ void CGUIText::ComputeLineSize(
|
|||||||
string.GenerateTextCall(pGUI, Feedback2, Font, string.m_Words[j], string.m_Words[j+1], FirstLine);
|
string.GenerateTextCall(pGUI, Feedback2, Font, string.m_Words[j], string.m_Words[j+1], FirstLine);
|
||||||
|
|
||||||
// Append X value.
|
// Append X value.
|
||||||
x += Feedback2.m_Size.cx;
|
x += Feedback2.m_Size.Width;
|
||||||
|
|
||||||
if (Width != 0 && x > width_range_to && j != temp_from && !Feedback2.m_NewLine)
|
if (Width != 0 && x > width_range_to && j != temp_from && !Feedback2.m_NewLine)
|
||||||
{
|
{
|
||||||
@ -192,12 +192,12 @@ void CGUIText::ComputeLineSize(
|
|||||||
// word and the next. When we're wrapping, we need subtract the width of the
|
// word and the next. When we're wrapping, we need subtract the width of the
|
||||||
// space after the last word on the line before the wrap.
|
// space after the last word on the line before the wrap.
|
||||||
CFontMetrics currentFont(Font);
|
CFontMetrics currentFont(Font);
|
||||||
line_size.cx -= currentFont.GetCharacterWidth(*L" ");
|
line_size.Width -= currentFont.GetCharacterWidth(*L" ");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let line_size.cy be the maximum m_Height we encounter.
|
// Let line_size.cy be the maximum m_Height we encounter.
|
||||||
line_size.cy = std::max(line_size.cy, Feedback2.m_Size.cy);
|
line_size.Height = std::max(line_size.Height, Feedback2.m_Size.Height);
|
||||||
|
|
||||||
// If the current word is an explicit new line ("\n"),
|
// If the current word is an explicit new line ("\n"),
|
||||||
// break now before adding the width of this character.
|
// break now before adding the width of this character.
|
||||||
@ -206,7 +206,7 @@ void CGUIText::ComputeLineSize(
|
|||||||
if (Width != 0 && Feedback2.m_NewLine)
|
if (Width != 0 && Feedback2.m_NewLine)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
line_size.cx += Feedback2.m_Size.cx;
|
line_size.Width += Feedback2.m_Size.Width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,14 +237,14 @@ bool CGUIText::ProcessLine(
|
|||||||
// Reset X for the next loop
|
// Reset X for the next loop
|
||||||
x = width_range_from;
|
x = width_range_from;
|
||||||
|
|
||||||
CSize line_size;
|
CSize2D line_size;
|
||||||
ComputeLineSize(pGUI, string, Font, FirstLine, Width, width_range_to, i, temp_from, x, line_size);
|
ComputeLineSize(pGUI, string, Font, FirstLine, Width, width_range_to, i, temp_from, x, line_size);
|
||||||
|
|
||||||
// Reset x once more
|
// Reset x once more
|
||||||
x = width_range_from;
|
x = width_range_from;
|
||||||
|
|
||||||
// Move down, because font drawing starts from the baseline
|
// Move down, because font drawing starts from the baseline
|
||||||
y += line_size.cy;
|
y += line_size.Height;
|
||||||
|
|
||||||
const float dx = GetLineOffset(align, width_range_from, width_range_to, line_size);
|
const float dx = GetLineOffset(align, width_range_from, width_range_to, line_size);
|
||||||
|
|
||||||
@ -255,8 +255,8 @@ bool CGUIText::ProcessLine(
|
|||||||
x = BufferZone;
|
x = BufferZone;
|
||||||
|
|
||||||
// Update dimensions
|
// Update dimensions
|
||||||
m_Size.cx = std::max(m_Size.cx, line_size.cx + BufferZone * 2);
|
m_Size.Width = std::max(m_Size.Width, line_size.Width + BufferZone * 2);
|
||||||
m_Size.cy = std::max(m_Size.cy, y + BufferZone);
|
m_Size.Height = std::max(m_Size.Height, y + BufferZone);
|
||||||
|
|
||||||
FirstLine = false;
|
FirstLine = false;
|
||||||
|
|
||||||
@ -315,7 +315,7 @@ float CGUIText::GetLineOffset(
|
|||||||
const EAlign align,
|
const EAlign align,
|
||||||
const float width_range_from,
|
const float width_range_from,
|
||||||
const float width_range_to,
|
const float width_range_to,
|
||||||
const CSize& line_size) const
|
const CSize2D& line_size) const
|
||||||
{
|
{
|
||||||
switch (align)
|
switch (align)
|
||||||
{
|
{
|
||||||
@ -324,10 +324,10 @@ float CGUIText::GetLineOffset(
|
|||||||
return 0.f;
|
return 0.f;
|
||||||
|
|
||||||
case EAlign::CENTER:
|
case EAlign::CENTER:
|
||||||
return ((width_range_to - width_range_from) - line_size.cx) / 2;
|
return ((width_range_to - width_range_from) - line_size.Width) / 2;
|
||||||
|
|
||||||
case EAlign::RIGHT:
|
case EAlign::RIGHT:
|
||||||
return width_range_to - line_size.cx;
|
return width_range_to - line_size.Width;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
debug_warn(L"Broken EAlign in CGUIText()");
|
debug_warn(L"Broken EAlign in CGUIText()");
|
||||||
@ -370,14 +370,14 @@ bool CGUIText::AssembleCalls(
|
|||||||
{
|
{
|
||||||
tc.m_Pos = CPos(dx + x + x_pointer, y);
|
tc.m_Pos = CPos(dx + x + x_pointer, y);
|
||||||
|
|
||||||
x_pointer += tc.m_Size.cx;
|
x_pointer += tc.m_Size.Width;
|
||||||
|
|
||||||
if (tc.m_pSpriteCall)
|
if (tc.m_pSpriteCall)
|
||||||
tc.m_pSpriteCall->m_Area += tc.m_Pos - CSize(0, tc.m_pSpriteCall->m_Area.GetHeight());
|
tc.m_pSpriteCall->m_Area += tc.m_Pos - CSize2D(0, tc.m_pSpriteCall->m_Area.GetHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append X value.
|
// Append X value.
|
||||||
x += Feedback2.m_Size.cx;
|
x += Feedback2.m_Size.Width;
|
||||||
|
|
||||||
// The first word overrides the width limit, what we
|
// The first word overrides the width limit, what we
|
||||||
// do, in those cases, are just drawing that word even
|
// do, in those cases, are just drawing that word even
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "gui/CGUISprite.h"
|
#include "gui/CGUISprite.h"
|
||||||
#include "gui/SettingTypes/CGUIColor.h"
|
#include "gui/SettingTypes/CGUIColor.h"
|
||||||
#include "gui/SettingTypes/EAlign.h"
|
#include "gui/SettingTypes/EAlign.h"
|
||||||
|
#include "maths/Size2D.h"
|
||||||
#include "ps/CStrIntern.h"
|
#include "ps/CStrIntern.h"
|
||||||
#include "ps/Shapes.h"
|
#include "ps/Shapes.h"
|
||||||
|
|
||||||
@ -106,7 +107,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Size
|
* Size
|
||||||
*/
|
*/
|
||||||
CSize m_Size;
|
CSize2D m_Size;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The string that is suppose to be rendered.
|
* The string that is suppose to be rendered.
|
||||||
@ -172,7 +173,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
void Draw(CGUI& pGUI, const CGUIColor& DefaultColor, const CPos& pos, const float z, const CRect& clipping) const;
|
void Draw(CGUI& pGUI, const CGUIColor& DefaultColor, const CPos& pos, const float z, const CRect& clipping) const;
|
||||||
|
|
||||||
const CSize& GetSize() const { return m_Size; }
|
const CSize2D& GetSize() const { return m_Size; }
|
||||||
|
|
||||||
const std::list<SSpriteCall>& GetSpriteCalls() const { return m_SpriteCalls; }
|
const std::list<SSpriteCall>& GetSpriteCalls() const { return m_SpriteCalls; }
|
||||||
|
|
||||||
@ -209,7 +210,7 @@ public:
|
|||||||
const EAlign align,
|
const EAlign align,
|
||||||
const float width_range_from,
|
const float width_range_from,
|
||||||
const float width_range_to,
|
const float width_range_to,
|
||||||
const CSize& line_size) const;
|
const CSize2D& line_size) const;
|
||||||
|
|
||||||
void ComputeLineRange(
|
void ComputeLineRange(
|
||||||
const SGenerateTextImages& Images,
|
const SGenerateTextImages& Images,
|
||||||
@ -229,7 +230,7 @@ public:
|
|||||||
const int i,
|
const int i,
|
||||||
const int temp_from,
|
const int temp_from,
|
||||||
float& x,
|
float& x,
|
||||||
CSize& line_size) const;
|
CSize2D& line_size) const;
|
||||||
|
|
||||||
bool AssembleCalls(
|
bool AssembleCalls(
|
||||||
const CGUI& pGUI,
|
const CGUI& pGUI,
|
||||||
@ -261,7 +262,7 @@ public:
|
|||||||
* Width and height of the whole output, used when setting up
|
* Width and height of the whole output, used when setting up
|
||||||
* scrollbars and such.
|
* scrollbars and such.
|
||||||
*/
|
*/
|
||||||
CSize m_Size;
|
CSize2D m_Size;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SGenerateTextImage
|
struct SGenerateTextImage
|
||||||
@ -277,7 +278,7 @@ struct SGenerateTextImage
|
|||||||
|
|
||||||
void SetupSpriteCall(
|
void SetupSpriteCall(
|
||||||
const bool Left, CGUIText::SSpriteCall& SpriteCall, const float width, const float y,
|
const bool Left, CGUIText::SSpriteCall& SpriteCall, const float width, const float y,
|
||||||
const CSize& Size, const CStr& TextureName, const float BufferZone);
|
const CSize2D& Size, const CStr& TextureName, const float BufferZone);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // INCLUDED_GUITEXT
|
#endif // INCLUDED_GUITEXT
|
||||||
|
@ -106,7 +106,7 @@ bool CGUI::ParseString<CGUIColor>(const CGUI* pGUI, const CStrW& Value, CGUIColo
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
bool CGUI::ParseString<CSize>(const CGUI* UNUSED(pGUI), const CStrW& Value, CSize& Output)
|
bool CGUI::ParseString<CSize2D>(const CGUI* UNUSED(pGUI), const CStrW& Value, CSize2D& Output)
|
||||||
{
|
{
|
||||||
const unsigned int NUM_COORDS = 2;
|
const unsigned int NUM_COORDS = 2;
|
||||||
float coords[NUM_COORDS];
|
float coords[NUM_COORDS];
|
||||||
@ -117,23 +117,23 @@ bool CGUI::ParseString<CSize>(const CGUI* UNUSED(pGUI), const CStrW& Value, CSiz
|
|||||||
{
|
{
|
||||||
if (stream.eof())
|
if (stream.eof())
|
||||||
{
|
{
|
||||||
LOGWARNING("Too few CSize parameters (min %i). Your input: '%s'", NUM_COORDS, Value.ToUTF8().c_str());
|
LOGWARNING("Too few CSize2D parameters (min %i). Your input: '%s'", NUM_COORDS, Value.ToUTF8().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
stream >> coords[i];
|
stream >> coords[i];
|
||||||
if ((stream.rdstate() & std::wstringstream::failbit) != 0)
|
if ((stream.rdstate() & std::wstringstream::failbit) != 0)
|
||||||
{
|
{
|
||||||
LOGWARNING("Unable to parse CSize parameters. Your input: '%s'", Value.ToUTF8().c_str());
|
LOGWARNING("Unable to parse CSize2D parameters. Your input: '%s'", Value.ToUTF8().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Output.cx = coords[0];
|
Output.Width = coords[0];
|
||||||
Output.cy = coords[1];
|
Output.Height = coords[1];
|
||||||
|
|
||||||
if (!stream.eof())
|
if (!stream.eof())
|
||||||
{
|
{
|
||||||
LOGWARNING("Too many CSize parameters (max %i). Your input: '%s'", NUM_COORDS, Value.ToUTF8().c_str());
|
LOGWARNING("Too many CSize2D parameters (max %i). Your input: '%s'", NUM_COORDS, Value.ToUTF8().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,10 +111,10 @@ void IGUITextOwner::CalculateTextPosition(CRect& ObjSize, CPos& TextPos, CGUITex
|
|||||||
break;
|
break;
|
||||||
case EVAlign::CENTER:
|
case EVAlign::CENTER:
|
||||||
// Round to integer pixel values, else the fonts look awful
|
// Round to integer pixel values, else the fonts look awful
|
||||||
TextPos.y = floorf(ObjSize.CenterPoint().y - Text.GetSize().cy / 2.f);
|
TextPos.y = floorf(ObjSize.CenterPoint().y - Text.GetSize().Height / 2.f);
|
||||||
break;
|
break;
|
||||||
case EVAlign::BOTTOM:
|
case EVAlign::BOTTOM:
|
||||||
TextPos.y = ObjSize.bottom - Text.GetSize().cy;
|
TextPos.y = ObjSize.bottom - Text.GetSize().Height;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
debug_warn(L"Broken EVAlign in CButton::SetupText()");
|
debug_warn(L"Broken EVAlign in CButton::SetupText()");
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2020 Wildfire Games.
|
/* Copyright (C) 2021 Wildfire Games.
|
||||||
* This file is part of 0 A.D.
|
* This file is part of 0 A.D.
|
||||||
*
|
*
|
||||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||||
@ -235,18 +235,18 @@ void CChart::SetupText()
|
|||||||
const float width = GetChartRect().GetWidth();
|
const float width = GetChartRect().GetWidth();
|
||||||
if (m_EqualX)
|
if (m_EqualX)
|
||||||
{
|
{
|
||||||
CSize text_size = AddFormattedValue(m_FormatX, m_RightTop.X, m_Font, m_BufferZone);
|
CSize2D text_size = AddFormattedValue(m_FormatX, m_RightTop.X, m_Font, m_BufferZone);
|
||||||
m_TextPositions.emplace_back(GetChartRect().BottomRight() - text_size);
|
m_TextPositions.emplace_back(GetChartRect().BottomRight() - text_size);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
for (int i = 0; i < 3; ++i)
|
for (int i = 0; i < 3; ++i)
|
||||||
{
|
{
|
||||||
CSize text_size = AddFormattedValue(m_FormatX, m_RightTop.X - (m_RightTop.X - m_LeftBottom.X) / 3 * i, m_Font, m_BufferZone);
|
CSize2D text_size = AddFormattedValue(m_FormatX, m_RightTop.X - (m_RightTop.X - m_LeftBottom.X) / 3 * i, m_Font, m_BufferZone);
|
||||||
m_TextPositions.emplace_back(GetChartRect().BottomRight() - text_size - CPos(width / 3 * i, 0.f));
|
m_TextPositions.emplace_back(GetChartRect().BottomRight() - text_size - CPos(width / 3 * i, 0.f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CSize CChart::AddFormattedValue(const CStrW& format, const float value, const CStrW& font, const float buffer_zone)
|
CSize2D CChart::AddFormattedValue(const CStrW& format, const float value, const CStrW& font, const float buffer_zone)
|
||||||
{
|
{
|
||||||
// TODO: we need to catch cases with equal formatted values.
|
// TODO: we need to catch cases with equal formatted values.
|
||||||
CGUIString gui_str;
|
CGUIString gui_str;
|
||||||
@ -278,7 +278,7 @@ CSize CChart::AddFormattedValue(const CStrW& format, const float value, const CS
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOGERROR("Unsupported chart format: " + format.EscapeToPrintableASCII());
|
LOGERROR("Unsupported chart format: " + format.EscapeToPrintableASCII());
|
||||||
return CSize();
|
return CSize2D();
|
||||||
}
|
}
|
||||||
|
|
||||||
return AddText(gui_str, font, 0, buffer_zone).GetSize();
|
return AddText(gui_str, font, 0, buffer_zone).GetSize();
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2020 Wildfire Games.
|
/* Copyright (C) 2021 Wildfire Games.
|
||||||
* This file is part of 0 A.D.
|
* This file is part of 0 A.D.
|
||||||
*
|
*
|
||||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||||
@ -24,6 +24,7 @@
|
|||||||
#include "gui/SettingTypes/CGUIColor.h"
|
#include "gui/SettingTypes/CGUIColor.h"
|
||||||
#include "gui/SettingTypes/CGUIList.h"
|
#include "gui/SettingTypes/CGUIList.h"
|
||||||
#include "gui/SettingTypes/CGUISeries.h"
|
#include "gui/SettingTypes/CGUISeries.h"
|
||||||
|
#include "maths/Size2D.h"
|
||||||
#include "maths/Vector2D.h"
|
#include "maths/Vector2D.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -104,7 +105,7 @@ private:
|
|||||||
// Represents axes as triangles and draws them with DrawTriangleStrip.
|
// Represents axes as triangles and draws them with DrawTriangleStrip.
|
||||||
void DrawAxes(const CShaderProgramPtr& shader) const;
|
void DrawAxes(const CShaderProgramPtr& shader) const;
|
||||||
|
|
||||||
CSize AddFormattedValue(const CStrW& format, const float value, const CStrW& font, const float buffer_zone);
|
CSize2D AddFormattedValue(const CStrW& format, const float value, const CStrW& font, const float buffer_zone);
|
||||||
|
|
||||||
void UpdateBounds();
|
void UpdateBounds();
|
||||||
};
|
};
|
||||||
|
@ -1124,8 +1124,8 @@ void CInput::HandleMessage(SGUIMessage& Message)
|
|||||||
|
|
||||||
// Tell the IME where to draw the candidate list
|
// Tell the IME where to draw the candidate list
|
||||||
SDL_Rect rect;
|
SDL_Rect rect;
|
||||||
rect.h = m_CachedActualSize.GetSize().cy;
|
rect.h = m_CachedActualSize.GetSize().Height;
|
||||||
rect.w = m_CachedActualSize.GetSize().cx;
|
rect.w = m_CachedActualSize.GetSize().Width;
|
||||||
rect.x = m_CachedActualSize.TopLeft().x;
|
rect.x = m_CachedActualSize.TopLeft().x;
|
||||||
rect.y = m_CachedActualSize.TopLeft().y;
|
rect.y = m_CachedActualSize.TopLeft().y;
|
||||||
SDL_SetTextInputRect(&rect);
|
SDL_SetTextInputRect(&rect);
|
||||||
|
@ -141,7 +141,7 @@ void CList::SetupText(bool append)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_ItemsYPositions[i] = buffered_y;
|
m_ItemsYPositions[i] = buffered_y;
|
||||||
buffered_y += text->GetSize().cy;
|
buffered_y += text->GetSize().Height;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_ItemsYPositions[m_List.m_Items.size()] = buffered_y;
|
m_ItemsYPositions[m_List.m_Items.size()] = buffered_y;
|
||||||
|
@ -76,7 +76,7 @@ void COList::SetupText()
|
|||||||
gui_string.SetValue(column.m_Heading);
|
gui_string.SetValue(column.m_Heading);
|
||||||
|
|
||||||
const CGUIText& text = AddText(gui_string, m_Font, width, m_BufferZone);
|
const CGUIText& text = AddText(gui_string, m_Font, width, m_BufferZone);
|
||||||
m_HeadingHeight = std::max(m_HeadingHeight, text.GetSize().cy + COLUMN_SHIFT.y);
|
m_HeadingHeight = std::max(m_HeadingHeight, text.GetSize().Height + COLUMN_SHIFT.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate texts
|
// Generate texts
|
||||||
@ -102,7 +102,7 @@ void COList::SetupText()
|
|||||||
align_string.SetValue(L" ");
|
align_string.SetValue(L" ");
|
||||||
text = &AddText(align_string, m_Font, width, m_BufferZone);
|
text = &AddText(align_string, m_Font, width, m_BufferZone);
|
||||||
}
|
}
|
||||||
shift = std::max(shift, text->GetSize().cy);
|
shift = std::max(shift, text->GetSize().Height);
|
||||||
}
|
}
|
||||||
buffered_y += shift;
|
buffered_y += shift;
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ void CText::SetupText()
|
|||||||
if (m_ScrollBottom && GetScrollBar(0).GetPos() > GetScrollBar(0).GetMaxPos() - 1.5f)
|
if (m_ScrollBottom && GetScrollBar(0).GetPos() > GetScrollBar(0).GetMaxPos() - 1.5f)
|
||||||
bottom = true;
|
bottom = true;
|
||||||
|
|
||||||
GetScrollBar(0).SetScrollRange(m_GeneratedTexts[0].GetSize().cy);
|
GetScrollBar(0).SetScrollRange(m_GeneratedTexts[0].GetSize().Height);
|
||||||
GetScrollBar(0).SetScrollSpace(m_CachedActualSize.GetHeight());
|
GetScrollBar(0).SetScrollSpace(m_CachedActualSize.GetHeight());
|
||||||
|
|
||||||
GetScrollBar(0).SetX(m_CachedActualSize.right);
|
GetScrollBar(0).SetX(m_CachedActualSize.right);
|
||||||
|
@ -87,8 +87,8 @@ void CTooltip::SetupText()
|
|||||||
|
|
||||||
const CPos& mousepos = m_Independent ? m_pGUI.GetMousePos() : m_MousePos;
|
const CPos& mousepos = m_Independent ? m_pGUI.GetMousePos() : m_MousePos;
|
||||||
|
|
||||||
float textwidth = m_GeneratedTexts[0].GetSize().cx;
|
float textwidth = m_GeneratedTexts[0].GetSize().Width;
|
||||||
float textheight = m_GeneratedTexts[0].GetSize().cy;
|
float textheight = m_GeneratedTexts[0].GetSize().Height;
|
||||||
|
|
||||||
CGUISize size;
|
CGUISize size;
|
||||||
size.pixel.left = mousepos.x + m_Offset.x;
|
size.pixel.left = mousepos.x + m_Offset.x;
|
||||||
|
@ -18,8 +18,8 @@
|
|||||||
#ifndef INCLUDED_SGUIICON
|
#ifndef INCLUDED_SGUIICON
|
||||||
#define INCLUDED_SGUIICON
|
#define INCLUDED_SGUIICON
|
||||||
|
|
||||||
|
#include "maths/Size2D.h"
|
||||||
#include "ps/CStr.h"
|
#include "ps/CStr.h"
|
||||||
#include "ps/Shapes.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Icon, you create them in the XML file with root element <setup>.
|
* Icon, you create them in the XML file with root element <setup>.
|
||||||
@ -37,7 +37,7 @@ struct SGUIIcon
|
|||||||
CStr m_SpriteName;
|
CStr m_SpriteName;
|
||||||
|
|
||||||
// Size
|
// Size
|
||||||
CSize m_Size;
|
CSize2D m_Size;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // INCLUDED_SGUIICON
|
#endif // INCLUDED_SGUIICON
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "gui/SettingTypes/CGUISeries.h"
|
#include "gui/SettingTypes/CGUISeries.h"
|
||||||
#include "gui/SettingTypes/CGUISize.h"
|
#include "gui/SettingTypes/CGUISize.h"
|
||||||
#include "lib/external_libraries/libsdl.h"
|
#include "lib/external_libraries/libsdl.h"
|
||||||
|
#include "maths/Size2D.h"
|
||||||
#include "maths/Vector2D.h"
|
#include "maths/Vector2D.h"
|
||||||
#include "ps/Hotkey.h"
|
#include "ps/Hotkey.h"
|
||||||
#include "ps/CLogger.h"
|
#include "ps/CLogger.h"
|
||||||
@ -157,28 +158,28 @@ template<> void ScriptInterface::ToJSVal<CGUIColor>(const ScriptRequest& rq, JS:
|
|||||||
*/
|
*/
|
||||||
template<> bool ScriptInterface::FromJSVal<CGUIColor>(const ScriptRequest& rq, JS::HandleValue v, CGUIColor& out) = delete;
|
template<> bool ScriptInterface::FromJSVal<CGUIColor>(const ScriptRequest& rq, JS::HandleValue v, CGUIColor& out) = delete;
|
||||||
|
|
||||||
template<> void ScriptInterface::ToJSVal<CSize>(const ScriptRequest& rq, JS::MutableHandleValue ret, const CSize& val)
|
template<> void ScriptInterface::ToJSVal<CSize2D>(const ScriptRequest& rq, JS::MutableHandleValue ret, const CSize2D& val)
|
||||||
{
|
{
|
||||||
CreateObject(rq, ret, "width", val.cx, "height", val.cy);
|
CreateObject(rq, ret, "width", val.Width, "height", val.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> bool ScriptInterface::FromJSVal<CSize>(const ScriptRequest& rq, JS::HandleValue v, CSize& out)
|
template<> bool ScriptInterface::FromJSVal<CSize2D>(const ScriptRequest& rq, JS::HandleValue v, CSize2D& out)
|
||||||
{
|
{
|
||||||
if (!v.isObject())
|
if (!v.isObject())
|
||||||
{
|
{
|
||||||
LOGERROR("CSize value must be an object!");
|
LOGERROR("CSize2D value must be an object!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!FromJSProperty(rq, v, "width", out.cx))
|
if (!FromJSProperty(rq, v, "width", out.Width))
|
||||||
{
|
{
|
||||||
LOGERROR("Failed to get CSize.cx property");
|
LOGERROR("Failed to get CSize2D.Width property");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!FromJSProperty(rq, v, "height", out.cy))
|
if (!FromJSProperty(rq, v, "height", out.Height))
|
||||||
{
|
{
|
||||||
LOGERROR("Failed to get CSize.cy property");
|
LOGERROR("Failed to get CSize2D.Height property");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ void CGUIString::SFeedback::Reset()
|
|||||||
m_Images[Right].clear();
|
m_Images[Right].clear();
|
||||||
m_TextCalls.clear();
|
m_TextCalls.clear();
|
||||||
m_SpriteCalls.clear();
|
m_SpriteCalls.clear();
|
||||||
m_Size = CSize();
|
m_Size = CSize2D();
|
||||||
m_NewLine = false;
|
m_NewLine = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,11 +129,11 @@ void CGUIString::GenerateTextCall(const CGUI& pGUI, SFeedback& Feedback, CStrInt
|
|||||||
// Get Icon from icon database in pGUI
|
// Get Icon from icon database in pGUI
|
||||||
const SGUIIcon& icon = pGUI.GetIcon(path);
|
const SGUIIcon& icon = pGUI.GetIcon(path);
|
||||||
|
|
||||||
const CSize& size = icon.m_Size;
|
const CSize2D& size = icon.m_Size;
|
||||||
|
|
||||||
// append width, and make maximum height the height.
|
// append width, and make maximum height the height.
|
||||||
Feedback.m_Size.cx += size.cx;
|
Feedback.m_Size.Width += size.Width;
|
||||||
Feedback.m_Size.cy = std::max(Feedback.m_Size.cy, size.cy);
|
Feedback.m_Size.Height = std::max(Feedback.m_Size.Height, size.Height);
|
||||||
|
|
||||||
// These are also needed later
|
// These are also needed later
|
||||||
TextCall.m_Size = size;
|
TextCall.m_Size = size;
|
||||||
@ -145,9 +145,9 @@ void CGUIString::GenerateTextCall(const CGUI& pGUI, SFeedback& Feedback, CStrInt
|
|||||||
if (tagAttrib.attrib == L"displace" && !tagAttrib.value.empty())
|
if (tagAttrib.attrib == L"displace" && !tagAttrib.value.empty())
|
||||||
{
|
{
|
||||||
// Displace the sprite
|
// Displace the sprite
|
||||||
CSize displacement;
|
CSize2D displacement;
|
||||||
// Parse the value
|
// Parse the value
|
||||||
if (!CGUI::ParseString<CSize>(&pGUI, tagAttrib.value, displacement))
|
if (!CGUI::ParseString<CSize2D>(&pGUI, tagAttrib.value, displacement))
|
||||||
LOGERROR("Error parsing 'displace' value for tag [ICON]");
|
LOGERROR("Error parsing 'displace' value for tag [ICON]");
|
||||||
else
|
else
|
||||||
SpriteCall.m_Area += displacement;
|
SpriteCall.m_Area += displacement;
|
||||||
@ -206,7 +206,7 @@ void CGUIString::GenerateTextCall(const CGUI& pGUI, SFeedback& Feedback, CStrInt
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the size of the font
|
// Calculate the size of the font
|
||||||
CSize size;
|
CSize2D size;
|
||||||
int cx, cy;
|
int cx, cy;
|
||||||
CFontMetrics font (TextCall.m_Font);
|
CFontMetrics font (TextCall.m_Font);
|
||||||
font.CalculateStringSize(TextCall.m_String.c_str(), cx, cy);
|
font.CalculateStringSize(TextCall.m_String.c_str(), cx, cy);
|
||||||
@ -215,12 +215,12 @@ void CGUIString::GenerateTextCall(const CGUI& pGUI, SFeedback& Feedback, CStrInt
|
|||||||
if (!FirstLine)
|
if (!FirstLine)
|
||||||
cy = font.GetLineSpacing();
|
cy = font.GetLineSpacing();
|
||||||
|
|
||||||
size.cx = (float)cx;
|
size.Width = (float)cx;
|
||||||
size.cy = (float)cy;
|
size.Height = (float)cy;
|
||||||
|
|
||||||
// Append width, and make maximum height the height.
|
// Append width, and make maximum height the height.
|
||||||
Feedback.m_Size.cx += size.cx;
|
Feedback.m_Size.Width += size.Width;
|
||||||
Feedback.m_Size.cy = std::max(Feedback.m_Size.cy, size.cy);
|
Feedback.m_Size.Height = std::max(Feedback.m_Size.Height, size.Height);
|
||||||
|
|
||||||
// These are also needed later
|
// These are also needed later
|
||||||
TextCall.m_Size = size;
|
TextCall.m_Size = size;
|
||||||
|
@ -149,7 +149,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Width and Height *feedback*
|
* Width and Height *feedback*
|
||||||
*/
|
*/
|
||||||
CSize m_Size;
|
CSize2D m_Size;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the word inputted was a new line.
|
* If the word inputted was a new line.
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
#ifndef INCLUDED_EALIGN
|
#ifndef INCLUDED_EALIGN
|
||||||
#define INCLUDED_EALIGN
|
#define INCLUDED_EALIGN
|
||||||
|
|
||||||
enum EAlign
|
enum class EAlign
|
||||||
{
|
{
|
||||||
LEFT,
|
LEFT,
|
||||||
RIGHT,
|
RIGHT,
|
||||||
|
@ -79,14 +79,14 @@ public:
|
|||||||
void test_size()
|
void test_size()
|
||||||
{
|
{
|
||||||
TestLogger nolog;
|
TestLogger nolog;
|
||||||
CSize test;
|
CSize2D test;
|
||||||
|
|
||||||
TS_ASSERT(CGUI::ParseString<CSize>(nullptr, CStrW(L"0.0 10.0"), test));
|
TS_ASSERT(CGUI::ParseString<CSize2D>(nullptr, CStrW(L"0.0 10.0"), test));
|
||||||
TS_ASSERT_EQUALS(CSize(0.0, 10.0), test);
|
TS_ASSERT_EQUALS(CSize2D(0.0, 10.0), test);
|
||||||
|
|
||||||
TS_ASSERT(!CGUI::ParseString<CSize>(nullptr, CStrW(L"0"), test));
|
TS_ASSERT(!CGUI::ParseString<CSize2D>(nullptr, CStrW(L"0"), test));
|
||||||
TS_ASSERT(!CGUI::ParseString<CSize>(nullptr, CStrW(L"0 10 20"), test));
|
TS_ASSERT(!CGUI::ParseString<CSize2D>(nullptr, CStrW(L"0 10 20"), test));
|
||||||
TS_ASSERT(!CGUI::ParseString<CSize>(nullptr, CStrW(L"0,0 10,0"), test));
|
TS_ASSERT(!CGUI::ParseString<CSize2D>(nullptr, CStrW(L"0,0 10,0"), test));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_pos()
|
void test_pos()
|
||||||
|
93
source/maths/Size2D.cpp
Normal file
93
source/maths/Size2D.cpp
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
/* Copyright (C) 2021 Wildfire Games.
|
||||||
|
* This file is part of 0 A.D.
|
||||||
|
*
|
||||||
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* 0 A.D. is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "precompiled.h"
|
||||||
|
|
||||||
|
#include "Size2D.h"
|
||||||
|
|
||||||
|
#include "ps/Shapes.h"
|
||||||
|
|
||||||
|
CSize2D::CSize2D() = default;
|
||||||
|
|
||||||
|
CSize2D::CSize2D(const CSize2D& size) : Width(size.Width), Height(size.Height)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CSize2D::CSize2D(const float width, const float height) : Width(width), Height(height)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CSize2D& CSize2D::operator=(const CSize2D& size)
|
||||||
|
{
|
||||||
|
Width = size.Width;
|
||||||
|
Height = size.Height;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CSize2D::operator==(const CSize2D& size) const
|
||||||
|
{
|
||||||
|
return Width == size.Width && Height == size.Height;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CSize2D::operator!=(const CSize2D& size) const
|
||||||
|
{
|
||||||
|
return !(*this == size);
|
||||||
|
}
|
||||||
|
|
||||||
|
CSize2D CSize2D::operator+(const CSize2D& size) const
|
||||||
|
{
|
||||||
|
return CSize2D(Width + size.Width, Height + size.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
CSize2D CSize2D::operator-(const CSize2D& size) const
|
||||||
|
{
|
||||||
|
return CSize2D(Width - size.Width, Height - size.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
CSize2D CSize2D::operator/(const float a) const
|
||||||
|
{
|
||||||
|
return CSize2D(Width / a, Height / a);
|
||||||
|
}
|
||||||
|
|
||||||
|
CSize2D CSize2D::operator*(const float a) const
|
||||||
|
{
|
||||||
|
return CSize2D(Width * a, Height * a);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSize2D::operator+=(const CSize2D& size)
|
||||||
|
{
|
||||||
|
Width += size.Width;
|
||||||
|
Height += size.Height;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSize2D::operator-=(const CSize2D& size)
|
||||||
|
{
|
||||||
|
Width -= size.Width;
|
||||||
|
Height -= size.Height;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSize2D::operator/=(const float a)
|
||||||
|
{
|
||||||
|
Width /= a;
|
||||||
|
Height /= a;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSize2D::operator*=(const float a)
|
||||||
|
{
|
||||||
|
Width *= a;
|
||||||
|
Height *= a;
|
||||||
|
}
|
52
source/maths/Size2D.h
Normal file
52
source/maths/Size2D.h
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/* Copyright (C) 2021 Wildfire Games.
|
||||||
|
* This file is part of 0 A.D.
|
||||||
|
*
|
||||||
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* 0 A.D. is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef INCLUDED_SIZE2D
|
||||||
|
#define INCLUDED_SIZE2D
|
||||||
|
|
||||||
|
class CPos;
|
||||||
|
class CRect;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Provides an interface for a size - geometric property in R2.
|
||||||
|
*/
|
||||||
|
class CSize2D
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CSize2D();
|
||||||
|
CSize2D(const CSize2D& size);
|
||||||
|
CSize2D(const float width, const float height);
|
||||||
|
|
||||||
|
CSize2D& operator=(const CSize2D& size);
|
||||||
|
bool operator==(const CSize2D& size) const;
|
||||||
|
bool operator!=(const CSize2D& size) const;
|
||||||
|
|
||||||
|
CSize2D operator+(const CSize2D& size) const;
|
||||||
|
CSize2D operator-(const CSize2D& size) const;
|
||||||
|
CSize2D operator/(const float a) const;
|
||||||
|
CSize2D operator*(const float a) const;
|
||||||
|
|
||||||
|
void operator+=(const CSize2D& a);
|
||||||
|
void operator-=(const CSize2D& a);
|
||||||
|
void operator/=(const float a);
|
||||||
|
void operator*=(const float a);
|
||||||
|
|
||||||
|
public:
|
||||||
|
float Width = 0.0f, Height = 0.0f;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // INCLUDED_SIZE2D
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2019 Wildfire Games.
|
/* Copyright (C) 2021 Wildfire Games.
|
||||||
* This file is part of 0 A.D.
|
* This file is part of 0 A.D.
|
||||||
*
|
*
|
||||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||||
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
#include "Shapes.h"
|
#include "Shapes.h"
|
||||||
|
|
||||||
|
#include "maths/Size2D.h"
|
||||||
|
|
||||||
CRect::CRect() :
|
CRect::CRect() :
|
||||||
left(0.f), top(0.f), right(0.f), bottom(0.f)
|
left(0.f), top(0.f), right(0.f), bottom(0.f)
|
||||||
{
|
{
|
||||||
@ -34,8 +36,8 @@ CRect::CRect(const CPos &pos) :
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CRect::CRect(const CSize& size) :
|
CRect::CRect(const CSize2D& size) :
|
||||||
left(0.f), top(0.f), right(size.cx), bottom(size.cy)
|
left(0.f), top(0.f), right(size.Width), bottom(size.Height)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,8 +46,8 @@ CRect::CRect(const CPos& upperleft, const CPos& bottomright) :
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CRect::CRect(const CPos& pos, const CSize& size) :
|
CRect::CRect(const CPos& pos, const CSize2D& size) :
|
||||||
left(pos.x), top(pos.y), right(pos.x + size.cx), bottom(pos.y + size.cy)
|
left(pos.x), top(pos.y), right(pos.x + size.Width), bottom(pos.y + size.Height)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,9 +98,9 @@ CRect CRect::operator+(const CPos& a) const
|
|||||||
return CRect(left + a.x, top + a.y, right + a.x, bottom + a.y);
|
return CRect(left + a.x, top + a.y, right + a.x, bottom + a.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
CRect CRect::operator+(const CSize& a) const
|
CRect CRect::operator+(const CSize2D& a) const
|
||||||
{
|
{
|
||||||
return CRect(left + a.cx, top + a.cy, right + a.cx, bottom + a.cy);
|
return CRect(left + a.Width, top + a.Height, right + a.Width, bottom + a.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
CRect CRect::operator-(const CRect& a) const
|
CRect CRect::operator-(const CRect& a) const
|
||||||
@ -111,9 +113,9 @@ CRect CRect::operator-(const CPos& a) const
|
|||||||
return CRect(left - a.x, top - a.y, right - a.x, bottom - a.y);
|
return CRect(left - a.x, top - a.y, right - a.x, bottom - a.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
CRect CRect::operator-(const CSize& a) const
|
CRect CRect::operator-(const CSize2D& a) const
|
||||||
{
|
{
|
||||||
return CRect(left - a.cx, top - a.cy, right - a.cx, bottom - a.cy);
|
return CRect(left - a.Width, top - a.Height, right - a.Width, bottom - a.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CRect::operator+=(const CRect& a)
|
void CRect::operator+=(const CRect& a)
|
||||||
@ -132,12 +134,12 @@ void CRect::operator+=(const CPos& a)
|
|||||||
bottom += a.y;
|
bottom += a.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CRect::operator+=(const CSize& a)
|
void CRect::operator+=(const CSize2D& a)
|
||||||
{
|
{
|
||||||
left += a.cx;
|
left += a.Width;
|
||||||
top += a.cy;
|
top += a.Height;
|
||||||
right += a.cx;
|
right += a.Width;
|
||||||
bottom += a.cy;
|
bottom += a.Height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CRect::operator-=(const CRect& a)
|
void CRect::operator-=(const CRect& a)
|
||||||
@ -156,12 +158,12 @@ void CRect::operator-=(const CPos& a)
|
|||||||
bottom -= a.y;
|
bottom -= a.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CRect::operator-=(const CSize& a)
|
void CRect::operator-=(const CSize2D& a)
|
||||||
{
|
{
|
||||||
left -= a.cx;
|
left -= a.Width;
|
||||||
top -= a.cy;
|
top -= a.Height;
|
||||||
right -= a.cx;
|
right -= a.Width;
|
||||||
bottom -= a.cy;
|
bottom -= a.Height;
|
||||||
}
|
}
|
||||||
|
|
||||||
float CRect::GetWidth() const
|
float CRect::GetWidth() const
|
||||||
@ -174,9 +176,9 @@ float CRect::GetHeight() const
|
|||||||
return bottom-top;
|
return bottom-top;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSize CRect::GetSize() const
|
CSize2D CRect::GetSize() const
|
||||||
{
|
{
|
||||||
return CSize(right - left, bottom - top);
|
return CSize2D(right - left, bottom - top);
|
||||||
}
|
}
|
||||||
|
|
||||||
CPos CRect::TopLeft() const
|
CPos CRect::TopLeft() const
|
||||||
@ -227,7 +229,7 @@ CPos::CPos(const CPos& pos) : x(pos.x), y(pos.y)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CPos::CPos(const CSize& s) : x(s.cx), y(s.cy)
|
CPos::CPos(const CSize2D& s) : x(s.Width), y(s.Height)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,9 +269,9 @@ CPos CPos::operator+(const CPos& a) const
|
|||||||
return CPos(x + a.x, y + a.y);
|
return CPos(x + a.x, y + a.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
CPos CPos::operator+(const CSize& a) const
|
CPos CPos::operator+(const CSize2D& a) const
|
||||||
{
|
{
|
||||||
return CPos(x + a.cx, y + a.cy);
|
return CPos(x + a.Width, y + a.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
CPos CPos::operator-(const CPos& a) const
|
CPos CPos::operator-(const CPos& a) const
|
||||||
@ -277,9 +279,9 @@ CPos CPos::operator-(const CPos& a) const
|
|||||||
return CPos(x - a.x, y - a.y);
|
return CPos(x - a.x, y - a.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
CPos CPos::operator-(const CSize& a) const
|
CPos CPos::operator-(const CSize2D& a) const
|
||||||
{
|
{
|
||||||
return CPos(x - a.cx, y - a.cy);
|
return CPos(x - a.Width, y - a.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPos::operator+=(const CPos& a)
|
void CPos::operator+=(const CPos& a)
|
||||||
@ -288,10 +290,10 @@ void CPos::operator+=(const CPos& a)
|
|||||||
y += a.y;
|
y += a.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPos::operator+=(const CSize& a)
|
void CPos::operator+=(const CSize2D& a)
|
||||||
{
|
{
|
||||||
x += a.cx;
|
x += a.Width;
|
||||||
y += a.cy;
|
y += a.Height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPos::operator-=(const CPos& a)
|
void CPos::operator-=(const CPos& a)
|
||||||
@ -300,101 +302,8 @@ void CPos::operator-=(const CPos& a)
|
|||||||
y -= a.y;
|
y -= a.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPos::operator-=(const CSize& a)
|
void CPos::operator-=(const CSize2D& a)
|
||||||
{
|
{
|
||||||
x -= a.cx;
|
x -= a.Width;
|
||||||
y -= a.cy;
|
y -= a.Height;
|
||||||
}
|
|
||||||
|
|
||||||
/*************************************************************************/
|
|
||||||
|
|
||||||
CSize::CSize() : cx(0.f), cy(0.f)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
CSize::CSize(const CSize& size) : cx(size.cx), cy(size.cy)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
CSize::CSize(const CRect &rect) : cx(rect.GetWidth()), cy(rect.GetHeight())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
CSize::CSize(const CPos &pos) : cx(pos.x), cy(pos.y)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
CSize::CSize(const float sx, const float sy) : cx(sx), cy(sy)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
CSize& CSize::operator=(const CSize& a)
|
|
||||||
{
|
|
||||||
cx = a.cx;
|
|
||||||
cy = a.cy;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CSize::operator==(const CSize &a) const
|
|
||||||
{
|
|
||||||
return cx == a.cx && cy == a.cy;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CSize::operator!=(const CSize& a) const
|
|
||||||
{
|
|
||||||
return !(*this == a);
|
|
||||||
}
|
|
||||||
|
|
||||||
CSize CSize::operator-() const
|
|
||||||
{
|
|
||||||
return CSize(-cx, -cy);
|
|
||||||
}
|
|
||||||
|
|
||||||
CSize CSize::operator+() const
|
|
||||||
{
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
CSize CSize::operator+(const CSize& a) const
|
|
||||||
{
|
|
||||||
return CSize(cx + a.cx, cy + a.cy);
|
|
||||||
}
|
|
||||||
|
|
||||||
CSize CSize::operator-(const CSize& a) const
|
|
||||||
{
|
|
||||||
return CSize(cx - a.cx, cy - a.cy);
|
|
||||||
}
|
|
||||||
|
|
||||||
CSize CSize::operator/(const float a) const
|
|
||||||
{
|
|
||||||
return CSize(cx / a, cy / a);
|
|
||||||
}
|
|
||||||
|
|
||||||
CSize CSize::operator*(const float a) const
|
|
||||||
{
|
|
||||||
return CSize(cx * a, cy * a);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CSize::operator+=(const CSize& a)
|
|
||||||
{
|
|
||||||
cx += a.cx;
|
|
||||||
cy += a.cy;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CSize::operator-=(const CSize& a)
|
|
||||||
{
|
|
||||||
cx -= a.cx;
|
|
||||||
cy -= a.cy;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CSize::operator/=(const float a)
|
|
||||||
{
|
|
||||||
cx /= a;
|
|
||||||
cy /= a;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CSize::operator*=(const float a)
|
|
||||||
{
|
|
||||||
cx *= a;
|
|
||||||
cy *= a;
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2019 Wildfire Games.
|
/* Copyright (C) 2021 Wildfire Games.
|
||||||
* This file is part of 0 A.D.
|
* This file is part of 0 A.D.
|
||||||
*
|
*
|
||||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||||
@ -15,18 +15,11 @@
|
|||||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
--Overview--
|
|
||||||
|
|
||||||
Classes mostly useful for representing 2D screen overlays;
|
|
||||||
includes functionality for overlay position, color, texture and borders.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef INCLUDED_SHAPES
|
#ifndef INCLUDED_SHAPES
|
||||||
#define INCLUDED_SHAPES
|
#define INCLUDED_SHAPES
|
||||||
|
|
||||||
class CPos;
|
class CPos;
|
||||||
class CSize;
|
class CSize2D;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,9 +32,9 @@ class CRect
|
|||||||
public:
|
public:
|
||||||
CRect();
|
CRect();
|
||||||
CRect(const CPos &pos);
|
CRect(const CPos &pos);
|
||||||
CRect(const CSize &size);
|
CRect(const CSize2D &size);
|
||||||
CRect(const CPos &upperleft, const CPos &bottomright);
|
CRect(const CPos &upperleft, const CPos &bottomright);
|
||||||
CRect(const CPos &pos, const CSize &size);
|
CRect(const CPos &pos, const CSize2D &size);
|
||||||
CRect(const float l, const float t, const float r, const float b);
|
CRect(const float l, const float t, const float r, const float b);
|
||||||
CRect(const CRect&);
|
CRect(const CRect&);
|
||||||
|
|
||||||
@ -53,17 +46,17 @@ public:
|
|||||||
|
|
||||||
CRect operator+(const CRect& a) const;
|
CRect operator+(const CRect& a) const;
|
||||||
CRect operator+(const CPos& a) const;
|
CRect operator+(const CPos& a) const;
|
||||||
CRect operator+(const CSize& a) const;
|
CRect operator+(const CSize2D& a) const;
|
||||||
CRect operator-(const CRect& a) const;
|
CRect operator-(const CRect& a) const;
|
||||||
CRect operator-(const CPos& a) const;
|
CRect operator-(const CPos& a) const;
|
||||||
CRect operator-(const CSize& a) const;
|
CRect operator-(const CSize2D& a) const;
|
||||||
|
|
||||||
void operator+=(const CRect& a);
|
void operator+=(const CRect& a);
|
||||||
void operator+=(const CPos& a);
|
void operator+=(const CPos& a);
|
||||||
void operator+=(const CSize& a);
|
void operator+=(const CSize2D& a);
|
||||||
void operator-=(const CRect& a);
|
void operator-=(const CRect& a);
|
||||||
void operator-=(const CPos& a);
|
void operator-=(const CPos& a);
|
||||||
void operator-=(const CSize& a);
|
void operator-=(const CSize2D& a);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Width of Rectangle
|
* @return Width of Rectangle
|
||||||
@ -78,7 +71,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Get Size
|
* Get Size
|
||||||
*/
|
*/
|
||||||
CSize GetSize() const;
|
CSize2D GetSize() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Position equivalent to top/left corner
|
* Get Position equivalent to top/left corner
|
||||||
@ -128,14 +121,14 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Made to represent screen positions and delta values.
|
* Made to represent screen positions and delta values.
|
||||||
* @see CRect
|
* @see CRect
|
||||||
* @see CSize
|
* @see CSize2D
|
||||||
*/
|
*/
|
||||||
class CPos
|
class CPos
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CPos();
|
CPos();
|
||||||
CPos(const CPos& pos);
|
CPos(const CPos& pos);
|
||||||
CPos(const CSize &pos);
|
CPos(const CSize2D &pos);
|
||||||
CPos(const float px, const float py);
|
CPos(const float px, const float py);
|
||||||
|
|
||||||
CPos& operator=(const CPos& a);
|
CPos& operator=(const CPos& a);
|
||||||
@ -145,14 +138,14 @@ public:
|
|||||||
CPos operator+() const;
|
CPos operator+() const;
|
||||||
|
|
||||||
CPos operator+(const CPos& a) const;
|
CPos operator+(const CPos& a) const;
|
||||||
CPos operator+(const CSize& a) const;
|
CPos operator+(const CSize2D& a) const;
|
||||||
CPos operator-(const CPos& a) const;
|
CPos operator-(const CPos& a) const;
|
||||||
CPos operator-(const CSize& a) const;
|
CPos operator-(const CSize2D& a) const;
|
||||||
|
|
||||||
void operator+=(const CPos& a);
|
void operator+=(const CPos& a);
|
||||||
void operator+=(const CSize& a);
|
void operator+=(const CSize2D& a);
|
||||||
void operator-=(const CPos& a);
|
void operator-=(const CPos& a);
|
||||||
void operator-=(const CSize& a);
|
void operator-=(const CSize2D& a);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@ -161,44 +154,4 @@ public:
|
|||||||
float x, y;
|
float x, y;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Made to represent a screen size, should in philosophy
|
|
||||||
* be made of unsigned ints, but for the sake of compatibility
|
|
||||||
* with CRect and CPos it's not.
|
|
||||||
* @see CRect
|
|
||||||
* @see CPos
|
|
||||||
*/
|
|
||||||
class CSize
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CSize();
|
|
||||||
CSize(const CRect &rect);
|
|
||||||
CSize(const CPos &pos);
|
|
||||||
CSize(const CSize& size);
|
|
||||||
CSize(const float sx, const float sy);
|
|
||||||
|
|
||||||
CSize& operator=(const CSize& a);
|
|
||||||
bool operator==(const CSize& a) const;
|
|
||||||
bool operator!=(const CSize& a) const;
|
|
||||||
CSize operator-() const;
|
|
||||||
CSize operator+() const;
|
|
||||||
|
|
||||||
CSize operator+(const CSize& a) const;
|
|
||||||
CSize operator-(const CSize& a) const;
|
|
||||||
CSize operator/(const float a) const;
|
|
||||||
CSize operator*(const float a) const;
|
|
||||||
|
|
||||||
void operator+=(const CSize& a);
|
|
||||||
void operator-=(const CSize& a);
|
|
||||||
void operator/=(const float a);
|
|
||||||
void operator*=(const float a);
|
|
||||||
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Size
|
|
||||||
*/
|
|
||||||
float cx, cy;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif // INCLUDED_SHAPES
|
#endif // INCLUDED_SHAPES
|
||||||
|
Loading…
Reference in New Issue
Block a user