Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand TextMacros in descriptions' 2ndary titles. #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 25 additions & 35 deletions src/PurplePen/DescriptionFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,22 +175,16 @@ private string GetTitleLine2()
// Given the text, create descriptions line for a title line with that text. Lines are split by vertical bars.
private DescriptionLine[] GetTitleLineFromText(DescriptionLineKind kind, string text)
{
string[] texts = text.Split(new char[] { '|' });
int lineCount = texts.Length;

DescriptionLine[] lines = new DescriptionLine[lineCount];
for (int index = 0; index < lineCount; ++index) {
DescriptionLine line = new DescriptionLine();

line.kind = kind;
line.boxes = new object[1];
line.boxes[0] = texts[index];
line.textual = texts[index];

lines[index] = line;
}

return lines;
return text.Split(new char[] { '|' })
.ConvertAll(t =>
{
DescriptionLine line = new DescriptionLine();
line.kind = kind;
line.boxes = new object[1];
line.boxes[0] = t;
line.textual = CourseFormatter.ExpandText(eventDB, courseView, t);
return line;
});
}

// Create a description line for a normal header line: name, length, climb
Expand Down Expand Up @@ -274,23 +268,19 @@ private DescriptionLine GetScoreHeaderLine()
// Given the text, create one or more text lines for that text. Lines are split by vertical bars.
private DescriptionLine[] GetTextLineFromText(string text, Id<CourseControl> courseControlId, Id<ControlPoint> controlId, DescriptionLine.TextLineKind textLineKind)
{
string[] texts = text.Split(new char[] { '|' });
int lineCount = texts.Length;

DescriptionLine[] lines = new DescriptionLine[lineCount];
for (int index = 0; index < lineCount; ++index) {
DescriptionLine line = new DescriptionLine();
line.kind = DescriptionLineKind.Text;
line.boxes = new object[1];
line.boxes[0] = texts[index];
line.textual = texts[index];
line.courseControlId = courseControlId;
line.controlId = controlId;
line.textLineKind = textLineKind;
lines[index] = line;
}

return lines;
return text.Split(new char[] { '|' })
.ConvertAll(t =>
{
DescriptionLine line = new DescriptionLine();
line.kind = DescriptionLineKind.Text;
line.boxes = new object[1];
line.boxes[0] = t;
line.textual = CourseFormatter.ExpandText(eventDB, courseView, t);
line.courseControlId = courseControlId;
line.controlId = controlId;
line.textLineKind = textLineKind;
return line;
});
}

// Given some text, a text line for it to a list if the text is non-empty.
Expand Down Expand Up @@ -608,7 +598,7 @@ public DescriptionLine[] CreateDescription(bool createKey)
DescriptionLine line;
DescriptionLine[] lines;
Dictionary<string, string> descriptionKey = new Dictionary<string, string>(); // dictionary for any symbols encountered with custom text.

// Get the first title line.
text = GetTitleLine1();
Debug.Assert(text != null);
Expand All @@ -618,7 +608,7 @@ public DescriptionLine[] CreateDescription(bool createKey)
// Get the second title line.
text = GetTitleLine2();
if (text != null) {
lines = GetTitleLineFromText(DescriptionLineKind.SecondaryTitle, text);
lines = GetTitleLineFromText(DescriptionLineKind.SecondaryTitle, CourseFormatter.ExpandText(eventDB, courseView, text));
list.AddRange(lines);
}

Expand Down
6 changes: 3 additions & 3 deletions src/PurplePen/DescriptionRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -719,11 +719,11 @@ private void RenderLine(IRenderer renderer, DescriptionLine descriptionLine, Des

switch (descriptionLine.kind) {
case DescriptionLineKind.Title:
RenderSingleLineText(renderer, TITLE_FONT, StringAlignment.Center, (string) (descriptionLine.boxes[0]), 0, 0, fullWidth, 100, clipRect);
RenderSingleLineText(renderer, TITLE_FONT, StringAlignment.Center, (string) (descriptionLine.textual), 0, 0, fullWidth, 100, clipRect);
break;

case DescriptionLineKind.SecondaryTitle:
RenderSingleLineText(renderer, TITLE_FONT, StringAlignment.Center, (string) (descriptionLine.boxes[0]), 0, 0, fullWidth, 100, clipRect);
RenderSingleLineText(renderer, TITLE_FONT, StringAlignment.Center, (string) (descriptionLine.textual), 0, 0, fullWidth, 100, clipRect);
break;

case DescriptionLineKind.Header2Box:
Expand Down Expand Up @@ -810,7 +810,7 @@ private void RenderLine(IRenderer renderer, DescriptionLine descriptionLine, Des
break;

case DescriptionLineKind.Text:
RenderWrappedText(renderer, TEXTLINE_FONT, StringAlignment.Near, (string) (descriptionLine.boxes[0]), 20, 0, fullWidth, 100, clipRect);
RenderWrappedText(renderer, TEXTLINE_FONT, StringAlignment.Near, (string) (descriptionLine.textual), 20, 0, fullWidth, 100, clipRect);
break;

default:
Expand Down
2 changes: 2 additions & 0 deletions src/PurplePen/PurplePen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
<DependentUpon>ChangeText.cs</DependentUpon>
</Compile>
<Compile Include="CircleGap.cs" />
<Compile Include="SystemExtensions.cs" />
<Compile Include="ColorChooserDialog.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -1500,6 +1501,7 @@
<EmbeddedResource Include="CommandNameText.pl.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>CommandNameText.pl.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="CommandNameText.resx">
<Generator>ResXFileCodeGenerator</Generator>
Expand Down
12 changes: 12 additions & 0 deletions src/PurplePen/SystemExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace PurplePen
{
public static class SystemExtensions
{
public static TResult[] ConvertAll<TSource, TResult>(this TSource[] _, Converter<TSource, TResult> converter)
{
return Array.ConvertAll(_, converter);
}
}
}