Skip to content

Commit

Permalink
Version 2.2
Browse files Browse the repository at this point in the history
Version 2.2
* JSON Support
* Background Opacity
* Seperated Text Color
* Improved Preview
* Quote Editor
  • Loading branch information
AMSoftwareNL committed Feb 23, 2020
1 parent 09f145c commit 670a341
Show file tree
Hide file tree
Showing 17 changed files with 1,049 additions and 263 deletions.
13 changes: 12 additions & 1 deletion AMSoftware.Quotes/AMSoftware.Quotes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.XML" />
</ItemGroup>
Expand All @@ -72,6 +73,12 @@
<Compile Include="ConfigForm.Designer.cs">
<DependentUpon>ConfigForm.cs</DependentUpon>
</Compile>
<Compile Include="EditForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="EditForm.Designer.cs">
<DependentUpon>EditForm.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Settings.Designer.cs">
Expand All @@ -80,13 +87,17 @@
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
<Compile Include="Quote.cs" />
<Compile Include="QuoteReader.cs" />
<Compile Include="QuoteManager.cs" />
<Compile Include="QuoteRenderer.cs" />
<Compile Include="RenderSettings.cs" />
<Compile Include="ScreensaverApplicationContext.cs" />
<Compile Include="_enums.cs" />
<EmbeddedResource Include="ConfigForm.resx">
<DependentUpon>ConfigForm.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="EditForm.resx">
<DependentUpon>EditForm.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
Expand Down
5 changes: 4 additions & 1 deletion AMSoftware.Quotes/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<value>Segoe UI Semibold, 12pt</value>
</setting>
<setting name="TextColor" serializeAs="String">
<value>White</value>
<value>WhiteSmoke</value>
</setting>
<setting name="BackgroundColor" serializeAs="String">
<value>Black</value>
Expand All @@ -34,6 +34,9 @@
<setting name="BackgroundAlignment" serializeAs="String">
<value>0</value>
</setting>
<setting name="BackgroundOpacity" serializeAs="String">
<value>1</value>
</setting>
</AMSoftware.Quotes.Properties.Settings>
</userSettings>
</configuration>
370 changes: 193 additions & 177 deletions AMSoftware.Quotes/ConfigForm.Designer.cs

Large diffs are not rendered by default.

159 changes: 109 additions & 50 deletions AMSoftware.Quotes/ConfigForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,24 @@ public ConfigForm()

_configSettings = Settings.Default;

// Source
pathTextBox.Text = _configSettings.SourcePath;
if (!string.IsNullOrWhiteSpace(_configSettings.SourcePath))
{
try
{
QuoteManager manager = QuoteManager.Create(openFileDialog.FileName);
editButton.Enabled = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Unexpected Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

fontTextBox.Text = $"{_configSettings.TextFont.FontFamily.Name}; {_configSettings.TextFont.Style}; {_configSettings.TextColor.Name}";
// Font
fontTextBox.Text = $"{_configSettings.TextFont.FontFamily.Name}; {_configSettings.TextFont.Style}";
textColorTextBox.Text = $"#{_configSettings.TextColor.R:X2}{_configSettings.TextColor.G:X2}{_configSettings.TextColor.B:X2}";
shrinkToFitCheckBox.Checked = _configSettings.TextShrinkToFit;

alignmentComboBox.DataSource = new ArrayList()
Expand All @@ -50,7 +65,8 @@ public ConfigForm()
alignmentComboBox.ValueMember = "Item1";
alignmentComboBox.SelectedValue = (TextAlignment)_configSettings.TextAlignment;

backgroundColorTextBox.Text = $"{_configSettings.BackgroundColor.Name}";
// Background
backgroundColorTextBox.Text = $"#{_configSettings.BackgroundColor.R:X2}{_configSettings.BackgroundColor.G:X2}{_configSettings.BackgroundColor.B:X2}";
backgroundImageTextBox.Text = _configSettings.BackgroundImagePath;

backgroundAlignmentComboBox.DataSource = new ArrayList()
Expand All @@ -63,24 +79,66 @@ public ConfigForm()
backgroundAlignmentComboBox.DisplayMember = "Item2";
backgroundAlignmentComboBox.ValueMember = "Item1";
backgroundAlignmentComboBox.SelectedValue = (BackgroundAlignment)_configSettings.BackgroundAlignment;

backgroundOpacityNumericUpDown.Value = _configSettings.BackgroundOpacity;
}

private void PathButton_Click(object sender, EventArgs e)
{
editButton.Enabled = false;

openFileDialog.Filter = "Quotes XML|*.xml|Quotes JSON|*.json|All files|*.*";
openFileDialog.Title = "Select quoute source";

openFileDialog.FileName = _configSettings.SourcePath;
if (openFileDialog.ShowDialog(this) == DialogResult.OK)
{
if (!string.IsNullOrWhiteSpace(openFileDialog.FileName))
{
try
{
QuoteManager manager = QuoteManager.Create(openFileDialog.FileName);

_configSettings.SourcePath = openFileDialog.FileName;
pathTextBox.Text = _configSettings.SourcePath;

applyButton.Enabled = true;
editButton.Enabled = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Unexpected Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

#region Font
private void FontButton_Click(object sender, EventArgs e)
{
fontDialog.Color = _configSettings.TextColor;
fontDialog.Font = _configSettings.TextFont;

if (fontDialog.ShowDialog(this) == DialogResult.OK)
{
_configSettings.TextFont = fontDialog.Font;
_configSettings.TextColor = fontDialog.Color;

fontTextBox.Text = $"{_configSettings.TextFont.FontFamily.Name}; {_configSettings.TextFont.Style}; {_configSettings.TextColor.Name}";
fontTextBox.Text = $"{_configSettings.TextFont.FontFamily.Name}; {_configSettings.TextFont.Style}";

applyButton.Enabled = true;
}
}

private void TextColorButton_Click(object sender, EventArgs e)
{
colorDialog.Color = _configSettings.TextColor;
if (colorDialog.ShowDialog(this) == DialogResult.OK)
{
_configSettings.TextColor = colorDialog.Color;
textColorTextBox.Text = $"#{_configSettings.TextColor.R:X2}{_configSettings.TextColor.G:X2}{_configSettings.TextColor.B:X2}";

applyButton.Enabled = true;
}
}

private void ShrinkToFitCheckBox_CheckedChanged(object sender, EventArgs e)
{
_configSettings.TextShrinkToFit = shrinkToFitCheckBox.Checked;
Expand All @@ -99,7 +157,9 @@ private void AlignmentComboBox_SelectedIndexChanged(object sender, EventArgs e)
}
}
}
#endregion

#region Background
private void BackgroundAlignmentComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (backgroundAlignmentComboBox.SelectedValue != null)
Expand All @@ -112,28 +172,13 @@ private void BackgroundAlignmentComboBox_SelectedIndexChanged(object sender, Eve
}
}

private void PathButton_Click(object sender, EventArgs e)
{
openFileDialog.Filter = "Quotes XML|*.xml|All files|*.*";
openFileDialog.Title = "Select quoute source";

openFileDialog.FileName = _configSettings.SourcePath;
if (openFileDialog.ShowDialog(this) == DialogResult.OK)
{
_configSettings.SourcePath = openFileDialog.FileName;
pathTextBox.Text = _configSettings.SourcePath;

applyButton.Enabled = true;
}
}

private void BackgroundColorButton_Click(object sender, EventArgs e)
{
colorDialog.Color = _configSettings.BackgroundColor;
if (colorDialog.ShowDialog(this) == DialogResult.OK)
{
_configSettings.BackgroundColor = colorDialog.Color;
backgroundColorTextBox.Text = $"{_configSettings.BackgroundColor.Name}";
backgroundColorTextBox.Text = $"#{_configSettings.BackgroundColor.R:X2}{_configSettings.BackgroundColor.G:X2}{_configSettings.BackgroundColor.B:X2}";

applyButton.Enabled = true;
}
Expand All @@ -154,6 +199,15 @@ private void BackgroundImageButton_Click(object sender, EventArgs e)
}
}

private void BackgroundOpacityNumericUpDown_ValueChanged(object sender, EventArgs e)
{
_configSettings.BackgroundOpacity = backgroundOpacityNumericUpDown.Value;

applyButton.Enabled = true;
}
#endregion

#region Form
private void ApplyButton_Click(object sender, EventArgs e)
{
_configSettings.Save();
Expand All @@ -173,30 +227,46 @@ private void OkButton_Click(object sender, EventArgs e)
this.Close();
}

private void PreviewPanel_Paint(object sender, PaintEventArgs e)
private void EditButton_Click(object sender, EventArgs e)
{
EditForm form = new EditForm()
{
Manager = QuoteManager.Create(_configSettings.SourcePath)
};

form.ShowDialog(this);
}

private void PreviewButton_Click(object sender, EventArgs e)
{
Form previewForm = new Form()
{
FormBorderStyle = FormBorderStyle.FixedDialog,
StartPosition = FormStartPosition.CenterScreen,
WindowState = FormWindowState.Maximized,
ShowInTaskbar = false,
TopMost = true,
Text = $"{this.Text} Preview"
};
previewForm.Paint += PreviewForm_Paint;

previewForm.ShowDialog(this);
}

private void PreviewForm_Paint(object sender, PaintEventArgs e)
{
Quote q = null;
if (string.IsNullOrWhiteSpace(_configSettings.SourcePath))
{
q = QuoteReader.Default;
q = QuoteManager.Default;
}
else
{
QuoteReader reader = QuoteReader.Create(_configSettings.SourcePath);
q = reader?.Read() ?? QuoteReader.Default;
}

if (!string.IsNullOrWhiteSpace(previewQuoteTextBox.Text))
{
q = new Quote()
{
QuoteText = previewQuoteTextBox.Lines,
Author = previewAuthorTextBox.Text,
Year = previewYearTextBox.Text
};
QuoteManager manager = QuoteManager.Create(_configSettings.SourcePath);
q = manager?.ReadRandom() ?? QuoteManager.Default;
}

using (Graphics g = previewPanel.CreateGraphics())
using (Graphics g = e.Graphics)
{
QuoteRenderer renderer = new QuoteRenderer(new RenderSettings()
{
Expand All @@ -207,22 +277,11 @@ private void PreviewPanel_Paint(object sender, PaintEventArgs e)
BackgroundColor = _configSettings.BackgroundColor,
BackgroundImagePath = _configSettings.BackgroundImagePath,
BackgroundAlignment = (BackgroundAlignment)_configSettings.BackgroundAlignment,
BackgroundOpacity = _configSettings.BackgroundOpacity
});
renderer.Render(q, g, Screen.FromControl(this).Bounds);
}
}

private void ConfigurationTabControl_SelectedIndexChanged(object sender, EventArgs e)
{
if (configurationTabControl.SelectedTab.Name == "previewTabPage")
{
previewPanel.Refresh();
}
}

private void PreviewTextBox_Leave(object sender, EventArgs e)
{
previewPanel.Refresh();
}
#endregion
}
}
Loading

0 comments on commit 670a341

Please sign in to comment.