Skip to content

Commit

Permalink
[KMS] CharaSim: Ellipsis itemName in SetItemTooltipRender (Fix #23)
Browse files Browse the repository at this point in the history
  • Loading branch information
KENNYSOFT committed Jan 1, 2021
1 parent 269f133 commit ad6a27c
Showing 1 changed file with 47 additions and 4 deletions.
51 changes: 47 additions & 4 deletions WzComparerR2/CharaSimControl/SetItemTooltipRender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ private Bitmap RenderSetItem(bool specialPetSetEffectName, out int picHeight)
Brush brush = setItemPart.Value.Enabled ? Brushes.White : GearGraphics.GrayBrush2;
if (!cash)
{
TextRenderer.DrawText(g, itemName, GearGraphics.EquipDetailFont2, new Point(10, picHeight), ((SolidBrush)brush).Color, TextFormatFlags.NoPadding);
TextRenderer.DrawText(g, typeName, GearGraphics.EquipDetailFont2, new Point(261 - 10 - TextRenderer.MeasureText(g, typeName, GearGraphics.EquipDetailFont2, new Size(int.MaxValue, int.MaxValue), TextFormatFlags.NoPadding).Width, picHeight), ((SolidBrush)brush).Color, TextFormatFlags.NoPadding);
int typeWidth = TextRenderer.MeasureText(g, typeName, GearGraphics.EquipDetailFont2, new Size(int.MaxValue, int.MaxValue), TextFormatFlags.NoPadding).Width;
TextRenderer.DrawText(g, typeName, GearGraphics.EquipDetailFont2, new Point(261 - 10 - typeWidth, picHeight), ((SolidBrush)brush).Color, TextFormatFlags.NoPadding);
TextRenderer.DrawText(g, Compact(g, itemName, 261 - 10 - typeWidth - 10), GearGraphics.EquipDetailFont2, new Point(10, picHeight), ((SolidBrush)brush).Color, TextFormatFlags.NoPadding);
picHeight += 18;
}
else
Expand All @@ -233,8 +234,9 @@ private Bitmap RenderSetItem(bool specialPetSetEffectName, out int picHeight)
g.DrawImage(icon.Bitmap, 10 + 2 - icon.Origin.X, picHeight + 2 + 32 - icon.Origin.Y);
}
g.DrawImage(Resource.CashItem_0, 10 + 2 + 20, picHeight + 2 + 32 - 12);
TextRenderer.DrawText(g, itemName, GearGraphics.EquipDetailFont2, new Point(52, picHeight), ((SolidBrush)brush).Color, TextFormatFlags.NoPadding);
TextRenderer.DrawText(g, typeName, GearGraphics.EquipDetailFont2, new Point(261 - 10 - TextRenderer.MeasureText(g, typeName, GearGraphics.EquipDetailFont2, new Size(int.MaxValue, int.MaxValue), TextFormatFlags.NoPadding).Width, picHeight), ((SolidBrush)brush).Color, TextFormatFlags.NoPadding);
int typeWidth = TextRenderer.MeasureText(g, typeName, GearGraphics.EquipDetailFont2, new Size(int.MaxValue, int.MaxValue), TextFormatFlags.NoPadding).Width;
TextRenderer.DrawText(g, typeName, GearGraphics.EquipDetailFont2, new Point(261 - 10 - typeWidth, picHeight), ((SolidBrush)brush).Color, TextFormatFlags.NoPadding);
TextRenderer.DrawText(g, Compact(g, itemName, 261 - 10 - typeWidth - 52), GearGraphics.EquipDetailFont2, new Point(52, picHeight), ((SolidBrush)brush).Color, TextFormatFlags.NoPadding);
if (setItemPart.Value.ByGender)
{
picHeight += 18;
Expand Down Expand Up @@ -297,6 +299,47 @@ private Bitmap RenderSetItem(bool specialPetSetEffectName, out int picHeight)
return setBitmap;
}

private static string Compact(Graphics g, string text, int width) // https://www.codeproject.com/Articles/37503/Auto-Ellipsis
{
Size s = TextRenderer.MeasureText(g, text, GearGraphics.EquipDetailFont2, new Size(int.MaxValue, int.MaxValue), TextFormatFlags.NoPadding);

// control is large enough to display the whole text
if (s.Width <= width)
return text;

int len = 0;
int seg = text.Length;
string fit = "";

// find the longest string that fits into
// the control boundaries using bisection method
while (seg > 1)
{
seg -= seg / 2;

int left = len + seg;

if (left > text.Length)
continue;

// build and measure a candidate string with ellipsis
string tst = text.Substring(0, left) + "..";

s = TextRenderer.MeasureText(g, tst, GearGraphics.EquipDetailFont2, new Size(int.MaxValue, int.MaxValue), TextFormatFlags.NoPadding);

// candidate string fits into control boundaries,
// try a longer string
// stop when seg <= 1
if (s.Width <= width)
{
len += seg;
fit = tst;
}
}

return fit;
}

private Bitmap RenderEffectPart(bool specialPetSetEffectName, out int picHeight)
{
Bitmap effBitmap = new Bitmap(261, DefaultPicHeight);
Expand Down

0 comments on commit ad6a27c

Please sign in to comment.