Skip to content

Commit

Permalink
Fix backward label align issue
Browse files Browse the repository at this point in the history
  • Loading branch information
vbousquet committed Jul 30, 2023
1 parent 7b624ea commit b4ff9f7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
17 changes: 13 additions & 4 deletions FlexDMD/Actors/Label.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@ namespace FlexDMD
// [Guid("BCAC5C64-9E46-431A-860C-DDBE38195965"), ComVisible(true), ClassInterface(ClassInterfaceType.None)]
public class Label : Actor, ILabelActor
{
private readonly IFlexDMD _flex;
private Font _font;
private string _text;
private string[] _lines;
private float _textWidth, _textHeight;

public Label(IFlexDMD flex)
{
_flex = flex;
AutoPack = flex.RuntimeVersion <= 1008;
}

public Label(IFlexDMD flex, Font font, string text)
{
_flex = flex;
AutoPack = flex.RuntimeVersion <= 1008;
_font = font;
Text = text;
Expand All @@ -45,7 +48,7 @@ public Label(IFlexDMD flex, Font font, string text)

public override float PrefHeight { get => _textHeight; }

public bool AutoPack { get; set; } = false;
public bool AutoPack { get; set; }

public string Text
{
Expand Down Expand Up @@ -99,19 +102,25 @@ public override void Draw(Graphics graphics)
{
if (_lines.Length > 1 && Alignment != Alignment.Left && Alignment != Alignment.BottomLeft && Alignment != Alignment.TopLeft)
{
// For multiple lines with cneter or right aligne, we must perform the alignment line by line
// For multiple lines with center or right align, we must perform the alignment line by line
Layout.Align(Alignment, PrefWidth, PrefHeight, Width, Height, out float x, out float y);
foreach (string line in _lines)
{
Layout.Align(Alignment, _font.MeasureFont(line).Width, PrefHeight, Width, Height, out float lx, out float ly);
_font.DrawText(graphics, (int)Math.Floor(X + lx), (int)Math.Floor (Y + y), line);
if (_flex.RuntimeVersion <= 1008)
_font.DrawText(graphics, (int)(X + lx), (int)(Y + y), line);
else
_font.DrawText(graphics, (int)Math.Floor(X + lx), (int)Math.Floor (Y + y), line);
y += _font.BitmapFont.LineHeight;
}
}
else
{
Layout.Align(Alignment, PrefWidth, PrefHeight, Width, Height, out float x, out float y);
_font.DrawText(graphics, (int)Math.Floor(X + x), (int)Math.Floor(Y + y), _text);
if (_flex.RuntimeVersion <= 1008)
_font.DrawText(graphics, (int)(X + x), (int)(Y + y), _text);
else
_font.DrawText(graphics, (int)Math.Floor(X + x), (int)Math.Floor(Y + y), _text);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions FlexDMD/IFlexDMD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,9 @@ public interface IFlexDMD

/// <summary>
/// Runtime version.
/// This version number allow backward comaptibility. The default is to run with the lower runtime compatibility, that is to say 1008:
/// - 0 to 1008: initial fatures
/// - 1009 to ...: searching for nodes changed
/// This version number allow backward compatibility. The default is to run with the lower runtime compatibility, that is to say 1008:
/// - 0 to 1008: initial features
/// - 1009 to ...: new nodes searching, changed label packing,...
/// </summary>
int RuntimeVersion { get; set; }

Expand Down

0 comments on commit b4ff9f7

Please sign in to comment.