Fixed bounds calculation of CText
This commit is contained in:
1 parent
9021a444b5
commit
fa22096914
4 files changed
+39
-123
No files matched your search
@@ -116,10 +116,10 @@ namespace Vocaluxe.Base.Fonts
|
||||
float dx = (fullSize.Width - boundingSize.Width - 1) / 2;
|
||||
_DrawBounding.X -= dx;
|
||||
_Texture = CDraw.AddTexture(bmpCropped);
|
||||
_DrawBounding.X *= _Texture.Width / _DrawBounding.Width;
|
||||
/*_DrawBounding.X *= _Texture.Width / _DrawBounding.Width;
|
||||
_DrawBounding.Y *= _Texture.Width / _DrawBounding.Width;
|
||||
_DrawBounding.Width = _Texture.Width;
|
||||
_DrawBounding.Height = _Texture.Height;
|
||||
_DrawBounding.Height = _Texture.Height;*/
|
||||
if (false)
|
||||
{
|
||||
if (outline > 0)
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace Vocaluxe.Screens
|
||||
base.Init();
|
||||
const string test = " ÖÄÜabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPGRSTUVWGXZ1234567890";
|
||||
SColorF color = new SColorF(1, 0, 0, 1);
|
||||
CText text = new CText(10, 50, 1, 32, 0, EAlignment.Left, EStyle.Normal, "Normal", color, "Normal Text" + test, -1, 26, 0);
|
||||
CText text = new CText(10, 50, 1, 200, 0, EAlignment.Left, EStyle.Normal, "Normal", color, "Normal Text" + test, -1, 26, 0);
|
||||
_AddText(text);
|
||||
text = new CText(10, 90, 1, 32, 0, EAlignment.Left, EStyle.Bold, "Normal", color, "Bold Text" + test, -1, 26, 0);
|
||||
_AddText(text);
|
||||
@@ -51,7 +51,7 @@ namespace Vocaluxe.Screens
|
||||
_AddText(text);
|
||||
text = new CText(10, 210, 1, 32, 0, EAlignment.Left, EStyle.Bold, "Outline", color, "Bold Text" + test, -1, 26, 0);
|
||||
_AddText(text);
|
||||
text = new CText(10, 250, 1, 400, 0, EAlignment.Left, EStyle.Italic, "Outline", color, "Italic Text" + test, -1, 26, 0);
|
||||
text = new CText(10, 250, 1, 32, 0, EAlignment.Left, EStyle.Italic, "Outline", color, "Italic Text" + test, -1, 26, 0);
|
||||
_AddText(text);
|
||||
}
|
||||
|
||||
|
||||
@@ -999,51 +999,13 @@ namespace VocaluxeLib.Menu
|
||||
|
||||
private bool _IsMouseOver(int x, int y, CInteraction interact)
|
||||
{
|
||||
switch (interact.Type)
|
||||
bool result = CHelper.IsInBounds(_GetRect(interact.Num), x, y);
|
||||
if (result)
|
||||
return true;
|
||||
if (interact.Type == EType.SelectSlide)
|
||||
{
|
||||
case EType.Button:
|
||||
if (CHelper.IsInBounds(_Buttons[interact.Num].Rect, x, y))
|
||||
return true;
|
||||
break;
|
||||
case EType.SelectSlide:
|
||||
if (CHelper.IsInBounds(_SelectSlides[interact.Num].Rect, x, y) ||
|
||||
CHelper.IsInBounds(_SelectSlides[interact.Num].RectArrowLeft, x, y) ||
|
||||
CHelper.IsInBounds(_SelectSlides[interact.Num].RectArrowRight, x, y))
|
||||
return true;
|
||||
break;
|
||||
case EType.Static:
|
||||
if (CHelper.IsInBounds(_Statics[interact.Num].Rect, x, y))
|
||||
return true;
|
||||
break;
|
||||
case EType.Text:
|
||||
RectangleF bounds = CBase.Fonts.GetTextBounds(_Texts[interact.Num]);
|
||||
if (CHelper.IsInBounds(new SRectF(_Texts[interact.Num].X, _Texts[interact.Num].Y, bounds.Width, bounds.Height, _Texts[interact.Num].Z), x, y))
|
||||
return true;
|
||||
break;
|
||||
case EType.SongMenu:
|
||||
if (CHelper.IsInBounds(_SongMenus[interact.Num].Rect, x, y))
|
||||
return true;
|
||||
break;
|
||||
case EType.Lyric:
|
||||
if (CHelper.IsInBounds(_Lyrics[interact.Num].Rect, x, y))
|
||||
return true;
|
||||
break;
|
||||
case EType.NameSelection:
|
||||
if (CHelper.IsInBounds(_NameSelections[interact.Num].Rect, x, y))
|
||||
return true;
|
||||
break;
|
||||
case EType.Equalizer:
|
||||
if (CHelper.IsInBounds(_Equalizers[interact.Num].Rect, x, y))
|
||||
return true;
|
||||
break;
|
||||
case EType.Playlist:
|
||||
if (CHelper.IsInBounds(_Playlists[interact.Num].Rect, x, y))
|
||||
return true;
|
||||
break;
|
||||
case EType.ParticleEffect:
|
||||
if (CHelper.IsInBounds(_ParticleEffects[interact.Num].Rect, x, y))
|
||||
return true;
|
||||
break;
|
||||
return CHelper.IsInBounds(_SelectSlides[interact.Num].RectArrowLeft, x, y) ||
|
||||
CHelper.IsInBounds(_SelectSlides[interact.Num].RectArrowRight, x, y);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1634,7 +1596,7 @@ namespace VocaluxeLib.Menu
|
||||
return _Statics[_Interactions[interaction].Num].Rect;
|
||||
|
||||
case EType.Text:
|
||||
return _Texts[_Interactions[interaction].Num].Bounds;
|
||||
return _Texts[_Interactions[interaction].Num].Rect;
|
||||
|
||||
case EType.SongMenu:
|
||||
return _SongMenus[_Interactions[interaction].Num].Rect;
|
||||
|
||||
+28
-74
@@ -32,24 +32,6 @@ namespace VocaluxeLib.Menu
|
||||
public string SelColorName; //for Buttons
|
||||
}
|
||||
|
||||
struct STextPosition
|
||||
{
|
||||
public float X;
|
||||
public float Y;
|
||||
public float TextHeight;
|
||||
public float Width;
|
||||
public float Height;
|
||||
|
||||
public STextPosition(float initVal)
|
||||
{
|
||||
X = initVal;
|
||||
Y = initVal;
|
||||
TextHeight = initVal;
|
||||
Width = initVal;
|
||||
Height = initVal;
|
||||
}
|
||||
}
|
||||
|
||||
public class CText : IMenuElement
|
||||
{
|
||||
private SThemeText _Theme;
|
||||
@@ -65,8 +47,6 @@ namespace VocaluxeLib.Menu
|
||||
private bool _ButtonText;
|
||||
private bool _PositionNeedsUpdate = true;
|
||||
|
||||
private STextPosition _DrawPosition = new STextPosition(0);
|
||||
|
||||
private float _X;
|
||||
public float X
|
||||
{
|
||||
@@ -127,28 +107,6 @@ namespace VocaluxeLib.Menu
|
||||
if (Math.Abs(_MaxWidth - value) > 0.01)
|
||||
{
|
||||
_MaxWidth = value;
|
||||
// ReSharper disable ConvertIfStatementToConditionalTernaryExpression
|
||||
if (_MaxWidth > 0)
|
||||
// ReSharper restore ConvertIfStatementToConditionalTernaryExpression
|
||||
Bounds = new SRectF(-CBase.Settings.GetRenderW(), -CBase.Settings.GetRenderH(), _MaxWidth, 3f * CBase.Settings.GetRenderH(), 0f);
|
||||
else
|
||||
Bounds = new SRectF(-CBase.Settings.GetRenderW(), -CBase.Settings.GetRenderH(), 3f * CBase.Settings.GetRenderW(), 3f * CBase.Settings.GetRenderH(), 0f);
|
||||
|
||||
_PositionNeedsUpdate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private SRectF _Bounds;
|
||||
public SRectF Bounds
|
||||
{
|
||||
get { return _Bounds; }
|
||||
set
|
||||
{
|
||||
if (Math.Abs(_Bounds.X - value.X) > 0.01 || Math.Abs(_Bounds.Y - value.Y) > 0.01 || Math.Abs(_Bounds.W - value.W) > 0.01 || Math.Abs(_Bounds.H - value.H) > 0.01 ||
|
||||
Math.Abs(_Bounds.Z - value.Z) > 0.01)
|
||||
{
|
||||
_Bounds = value;
|
||||
_PositionNeedsUpdate = true;
|
||||
}
|
||||
}
|
||||
@@ -210,6 +168,20 @@ namespace VocaluxeLib.Menu
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Do NOT read/write this anywhere but in _UpdateTextPosition!
|
||||
/// </summary>
|
||||
private SRectF _Rect;
|
||||
public SRectF Rect
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_PositionNeedsUpdate)
|
||||
_UpdateTextPosition();
|
||||
return _Rect;
|
||||
}
|
||||
}
|
||||
|
||||
public SColorF Color; //normal Color
|
||||
public SColorF SelColor; //selected Color for Buttons
|
||||
|
||||
@@ -287,7 +259,6 @@ namespace VocaluxeLib.Menu
|
||||
_Z = text._Z;
|
||||
_Height = text._Height;
|
||||
_MaxWidth = text._MaxWidth;
|
||||
_Bounds = new SRectF(text._Bounds);
|
||||
_Align = text._Align;
|
||||
_HAlign = text._HAlign;
|
||||
_Style = text._Style;
|
||||
@@ -332,13 +303,6 @@ namespace VocaluxeLib.Menu
|
||||
|
||||
Selected = false;
|
||||
|
||||
// ReSharper disable ConvertIfStatementToConditionalTernaryExpression
|
||||
if (MaxWidth > 0)
|
||||
// ReSharper restore ConvertIfStatementToConditionalTernaryExpression
|
||||
Bounds = new SRectF(-CBase.Settings.GetRenderW(), -CBase.Settings.GetRenderH(), MaxWidth, 3f * CBase.Settings.GetRenderH(), 0f);
|
||||
else
|
||||
Bounds = new SRectF(-CBase.Settings.GetRenderW(), -CBase.Settings.GetRenderH(), 3f * CBase.Settings.GetRenderW(), 3f * CBase.Settings.GetRenderH(), 0f);
|
||||
|
||||
ReflectionSpace = rspace;
|
||||
ReflectionHeight = rheight;
|
||||
}
|
||||
@@ -403,16 +367,7 @@ namespace VocaluxeLib.Menu
|
||||
_PositionNeedsUpdate = true;
|
||||
|
||||
if (_ThemeLoaded)
|
||||
{
|
||||
LoadTextures();
|
||||
|
||||
// ReSharper disable ConvertIfStatementToConditionalTernaryExpression
|
||||
if (MaxWidth > 0)
|
||||
// ReSharper restore ConvertIfStatementToConditionalTernaryExpression
|
||||
Bounds = new SRectF(-CBase.Settings.GetRenderW(), -CBase.Settings.GetRenderH(), MaxWidth, 3f * CBase.Settings.GetRenderH(), 0f);
|
||||
else
|
||||
Bounds = new SRectF(-CBase.Settings.GetRenderW(), -CBase.Settings.GetRenderH(), 3f * CBase.Settings.GetRenderW(), 3f * CBase.Settings.GetRenderH(), 0f);
|
||||
}
|
||||
return _ThemeLoaded;
|
||||
}
|
||||
|
||||
@@ -520,7 +475,7 @@ namespace VocaluxeLib.Menu
|
||||
|
||||
SColorF color = new SColorF(currentColor.R, currentColor.G, currentColor.B, currentColor.A * Alpha);
|
||||
|
||||
CBase.Fonts.DrawText(_Text, _DrawPosition.TextHeight, _DrawPosition.X, _DrawPosition.Y, Z, color);
|
||||
CBase.Fonts.DrawText(_Text, Rect.H, Rect.X, Rect.Y, Z, color);
|
||||
|
||||
if (ReflectionHeight > 0)
|
||||
{
|
||||
@@ -528,23 +483,23 @@ namespace VocaluxeLib.Menu
|
||||
switch (HAlign)
|
||||
{
|
||||
case EHAlignment.Top:
|
||||
factor = (Height - _DrawPosition.TextHeight) * 1.5f;
|
||||
factor = (Height - Rect.H) * 1.5f;
|
||||
break;
|
||||
case EHAlignment.Center:
|
||||
factor = (Height - _DrawPosition.TextHeight) * 1.0f;
|
||||
factor = (Height - Rect.H) * 1.0f;
|
||||
break;
|
||||
case EHAlignment.Bottom:
|
||||
factor = (Height - _DrawPosition.TextHeight) * 0.5f;
|
||||
factor = (Height - Rect.H) * 0.5f;
|
||||
break;
|
||||
}
|
||||
CBase.Fonts.DrawTextReflection(_Text, _DrawPosition.TextHeight, _DrawPosition.X, _DrawPosition.Y, Z, color, ReflectionSpace + factor, ReflectionHeight);
|
||||
CBase.Fonts.DrawTextReflection(_Text, Rect.H, Rect.X, Rect.Y, Z, color, ReflectionSpace + factor, ReflectionHeight);
|
||||
}
|
||||
|
||||
if (Selected && (CBase.Settings.GetGameState() == EGameState.EditTheme))
|
||||
{
|
||||
CBase.Drawing.DrawColor(
|
||||
new SColorF(0.5f, 1f, 0.5f, 0.5f * CBase.Graphics.GetGlobalAlpha()),
|
||||
new SRectF(_DrawPosition.X, _DrawPosition.Y, _DrawPosition.Width, _DrawPosition.Height, Z)
|
||||
new SRectF(Rect.X, Rect.Y, Rect.W, Rect.H, Z)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -599,9 +554,9 @@ namespace VocaluxeLib.Menu
|
||||
|
||||
RectangleF bounds = CBase.Fonts.GetTextBounds(this);
|
||||
|
||||
if (bounds.Width > Bounds.W && Bounds.W > 0f && bounds.Width > 0f)
|
||||
if (bounds.Width > MaxWidth && MaxWidth > 0f && bounds.Width > 0f)
|
||||
{
|
||||
float factor = Bounds.W / bounds.Width;
|
||||
float factor = MaxWidth / bounds.Width;
|
||||
float step = h * (1 - factor);
|
||||
h *= factor;
|
||||
switch (HAlign)
|
||||
@@ -693,9 +648,9 @@ namespace VocaluxeLib.Menu
|
||||
float y = Y;
|
||||
RectangleF bounds = CBase.Fonts.GetTextBounds(this);
|
||||
|
||||
if (bounds.Width > Bounds.W && Bounds.W > 0f && bounds.Width > 0f)
|
||||
if (bounds.Width > MaxWidth && MaxWidth > 0f && bounds.Width > 0f)
|
||||
{
|
||||
float factor = Bounds.W / bounds.Width;
|
||||
float factor = MaxWidth / bounds.Width;
|
||||
float step = h * (1 - factor);
|
||||
h *= factor;
|
||||
switch (HAlign)
|
||||
@@ -725,11 +680,10 @@ namespace VocaluxeLib.Menu
|
||||
break;
|
||||
}
|
||||
|
||||
_DrawPosition.X = x;
|
||||
_DrawPosition.Y = y;
|
||||
_DrawPosition.TextHeight = h;
|
||||
_DrawPosition.Width = bounds.Width;
|
||||
_DrawPosition.Height = bounds.Height;
|
||||
_Rect.X = x;
|
||||
_Rect.Y = y;
|
||||
_Rect.W = bounds.Width;
|
||||
_Rect.H = bounds.Height;
|
||||
|
||||
_PositionNeedsUpdate = false;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user