From 1ec7f71ce70a932e0a7b49d6aad3a14dd307d1fb Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 16 May 2012 14:02:31 -0400 Subject: [PATCH] Changed StringAlign on Meter=String to support both horizontal and vertical positioning --- Library/Meter.h | 14 ++++-- Library/MeterString.cpp | 109 ++++++++++++++++++++++++++++++++++++---- Library/MeterString.h | 1 + 3 files changed, 111 insertions(+), 13 deletions(-) diff --git a/Library/Meter.h b/Library/Meter.h index 53666a0d..89012ede 100644 --- a/Library/Meter.h +++ b/Library/Meter.h @@ -109,11 +109,17 @@ protected: enum METER_ALIGNMENT { - ALIGN_LEFT, - ALIGN_RIGHT, - ALIGN_CENTER + ALIGN_LEFT, // Same as LeftTop + ALIGN_RIGHT, // Same as RightTop + ALIGN_CENTER, // Same as CenterTop + ALIGN_LEFTBOTTOM, + ALIGN_RIGHTBOTTOM, + ALIGN_CENTERBOTTOM, + ALIGN_LEFTCENTER, + ALIGN_RIGHTCENTER, + ALIGN_CENTERCENTER }; - + enum METER_POSITION { POSITION_ABSOLUTE, diff --git a/Library/MeterString.cpp b/Library/MeterString.cpp index c30917ae..0b910b0e 100644 --- a/Library/MeterString.cpp +++ b/Library/MeterString.cpp @@ -103,15 +103,21 @@ int CMeterString::GetX(bool abs) { switch (m_Align) { - case ALIGN_CENTER: + case ALIGN_CENTER: // Same as ALIGN_CENTERTOP + case ALIGN_CENTERBOTTOM: + case ALIGN_CENTERCENTER: x -= m_W / 2; break; - case ALIGN_RIGHT: + case ALIGN_RIGHT: // Same as ALIGN_RIGHTTOP + case ALIGN_RIGHTBOTTOM: + case ALIGN_RIGHTCENTER: x -= m_W; break; - case ALIGN_LEFT: + case ALIGN_LEFT: // Same as ALIGN_LEFTTOP + case ALIGN_LEFTBOTTOM: + case ALIGN_LEFTCENTER: // This is already correct break; } @@ -120,6 +126,34 @@ int CMeterString::GetX(bool abs) return x; } +/* +** Returns the Y-coordinate of the meter +** +*/ +int CMeterString::GetY(bool abs) +{ + int y = CMeter::GetY(); + + if (!abs) + { + switch (m_Align) + { + case ALIGN_LEFTCENTER: + case ALIGN_RIGHTCENTER: + case ALIGN_CENTERCENTER: + y -= m_H / 2; + break; + + case ALIGN_LEFTBOTTOM: + case ALIGN_RIGHTBOTTOM: + case ALIGN_CENTERBOTTOM: + y -= m_H; + break; + } + } + + return y; +} /* ** Create the font that is used to draw the text. @@ -341,18 +375,42 @@ void CMeterString::ReadConfig(CConfigParser& parser, const WCHAR* section) m_Scale = parser.ParseDouble(scale.c_str(), 1); const WCHAR* align = parser.ReadString(section, L"StringAlign", L"LEFT").c_str(); - if (_wcsicmp(align, L"LEFT") == 0) + if (_wcsicmp(align, L"LEFT") == 0 || _wcsicmp(align, L"LEFTTOP") == 0) { m_Align = ALIGN_LEFT; } - else if (_wcsicmp(align, L"RIGHT") == 0) + else if (_wcsicmp(align, L"RIGHT") == 0 || _wcsicmp(align, L"RIGHTTOP") == 0) { m_Align = ALIGN_RIGHT; } - else if (_wcsicmp(align, L"CENTER") == 0) + else if (_wcsicmp(align, L"CENTER") == 0 || _wcsicmp(align, L"CENTERTOP") == 0) { m_Align = ALIGN_CENTER; } + else if (_wcsicmp(align, L"LEFTBOTTOM") == 0) + { + m_Align = ALIGN_LEFTBOTTOM; + } + else if (_wcsicmp(align, L"RIGHTBOTTOM") == 0) + { + m_Align = ALIGN_RIGHTBOTTOM; + } + else if (_wcsicmp(align, L"CENTERBOTTOM") == 0) + { + m_Align = ALIGN_CENTERBOTTOM; + } + else if (_wcsicmp(align, L"LEFTCENTER") == 0) + { + m_Align = ALIGN_LEFTCENTER; + } + else if (_wcsicmp(align, L"RIGHTCENTER") == 0) + { + m_Align = ALIGN_RIGHTCENTER; + } + else if (_wcsicmp(align, L"CENTERCENTER") == 0) + { + m_Align = ALIGN_CENTERCENTER; + } else { LogWithArgs(LOG_ERROR, L"StringAlign=%s is not valid in [%s]", align, m_Name.c_str()); @@ -541,16 +599,49 @@ bool CMeterString::DrawString(Graphics& graphics, RectF* rect) switch (m_Align) { - case ALIGN_CENTER: + case ALIGN_CENTERCENTER: stringFormat.SetAlignment(StringAlignmentCenter); + stringFormat.SetLineAlignment(StringAlignmentCenter); break; - case ALIGN_RIGHT: + case ALIGN_RIGHTCENTER: stringFormat.SetAlignment(StringAlignmentFar); + stringFormat.SetLineAlignment(StringAlignmentCenter); break; - case ALIGN_LEFT: + case ALIGN_LEFTCENTER: stringFormat.SetAlignment(StringAlignmentNear); + stringFormat.SetLineAlignment(StringAlignmentCenter); + break; + + case ALIGN_CENTERBOTTOM: + stringFormat.SetAlignment(StringAlignmentCenter); + stringFormat.SetLineAlignment(StringAlignmentFar); + break; + + case ALIGN_RIGHTBOTTOM: + stringFormat.SetAlignment(StringAlignmentFar); + stringFormat.SetLineAlignment(StringAlignmentFar); + break; + + case ALIGN_LEFTBOTTOM: + stringFormat.SetAlignment(StringAlignmentNear); + stringFormat.SetLineAlignment(StringAlignmentFar); + break; + + case ALIGN_CENTER: // Same as CenterTop + stringFormat.SetAlignment(StringAlignmentCenter); + stringFormat.SetLineAlignment(StringAlignmentNear); + break; + + case ALIGN_RIGHT: // Same as RightTop + stringFormat.SetAlignment(StringAlignmentFar); + stringFormat.SetLineAlignment(StringAlignmentNear); + break; + + case ALIGN_LEFT: // Same as LeftTop + stringFormat.SetAlignment(StringAlignmentNear); + stringFormat.SetLineAlignment(StringAlignmentNear); break; } diff --git a/Library/MeterString.h b/Library/MeterString.h index 17bb0099..09c53910 100644 --- a/Library/MeterString.h +++ b/Library/MeterString.h @@ -32,6 +32,7 @@ public: virtual UINT GetTypeID() { return TypeID(); } virtual int GetX(bool abs = false); + virtual int GetY(bool abs = false); virtual void Initialize(); virtual bool Update();