-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
168 lines (152 loc) · 5.22 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WinFiglet
{
public partial class Form1 : Form
{
const string figFontsPath = @"Fonts/";
bool coloringDark = true;
public Form1()
{
InitializeComponent();
InitFonts();
tbFigOut.Clear();
DoFig(tbInput.Text);
pbCharacterError.Hide();
}
// METHODS
void InitFonts()
{
var fonts = Directory.GetFiles(figFontsPath, "*.flf");
ddlFontList.Items.Clear();
foreach (var font in fonts)
{
ddlFontList.Items.Add(Path.GetFileName(font));
}
if (ddlFontList.Items.Count != 0)
ddlFontList.SelectedIndex = 0;
SetTitle(ddlFontList.Items.Count);
ddlFontList.SelectedItem = "Fraktur.flf";
}
private void SetTitle(int fontsCount)
{
Version version = Assembly.GetExecutingAssembly().GetName().Version;
string versionString = $"v{version.Major}.{version.Minor}";
Text = $"{Text} {versionString} ({ddlFontList.Items.Count} Fonts loaded)";
}
private void ChangeColoring(bool changeColor = false)
{
if (changeColor)
coloringDark = !coloringDark;
// Update Button
if (coloringDark)
{
tbFigOut.ForeColor = Color.LawnGreen;
tbFigOut.BackColor = Color.Black;
btnColoring.Text = "☀️";
toolTip1.SetToolTip(btnColoring, "Switch to Light Figlet");
}
else
{
tbFigOut.ForeColor = Color.Black;
tbFigOut.BackColor = SystemColors.Control;
btnColoring.Text = "☽︎";
toolTip1.SetToolTip(btnColoring, "Switch to dark Figlet");
}
}
private void DoFig(string text)
{
pbCharacterError.Hide();
if (string.IsNullOrWhiteSpace(text))
return;
var fontFile = ddlFontList.SelectedItem.ToString();
if (!String.IsNullOrWhiteSpace(fontFile))
{
var fig = new Figlet();
FigletResult result = null;
try
{
//Load specific font (Figlet format)
fig.LoadFont(figFontsPath + fontFile);
}
catch (Exception)
{
var str = $"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!{Environment.NewLine}" +
$"Error loading font: {figFontsPath}{fontFile}{Environment.NewLine}" +
$"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!{Environment.NewLine}";
result = new FigletResult(str, true);
}
//Generate ASCII-Art Text (if no error)
if (result == null)
{
result = fig.ToAsciiArt(text);
}
tbFigOut.Clear();
tbFigOut.AppendText(result.String);
if (result.CharacterError)
{
pbCharacterError.Show();
}
}
}
// EVENTS
private void btnFiglet_Click(object sender, EventArgs e)
{
DoFig(tbInput.Text);
tbInput.Focus();
}
private void btnClear_Click(object sender, EventArgs e)
{
tbInput.Clear();
tbFigOut.Clear();
tbInput.Focus();
pbCharacterError.Hide();
}
private void ddlFontList_SelectedIndexChanged(object sender, EventArgs e)
{
DoFig(tbInput.Text);
}
private void linkLabelGit_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("https://github.com/SiL3NC3/WinFiglet");
tbInput.Focus();
}
private void Form1_Shown(object sender, EventArgs e)
{
ChangeColoring();
tbInput.Focus();
}
private void btnFontDown_Click(object sender, EventArgs e)
{
if (ddlFontList.Items.Count > ddlFontList.SelectedIndex + 1)
ddlFontList.SelectedIndex = ddlFontList.SelectedIndex + 1;
tbInput.Focus();
}
private void btnFontUp_Click(object sender, EventArgs e)
{
if (ddlFontList.SelectedIndex - 1 >= 0)
ddlFontList.SelectedIndex = ddlFontList.SelectedIndex - 1;
tbInput.Focus();
}
private void btnClipboard_Click(object sender, EventArgs e)
{
if (!string.IsNullOrWhiteSpace(tbFigOut.Text))
Clipboard.SetText(tbFigOut.Text);
tbInput.Focus();
}
private void btnColoring_Click(object sender, EventArgs e)
{
ChangeColoring(true);
tbInput.Focus();
}
}
}