/*
* ConfigForm.cs - Configuration dialog for colors, fonts and graphics.
*
* Copyright (C) 2004 - 2011 Andreas Scherrer
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*/
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace Level9
{
///
/// Configuration dialog for colors, fonts and graphics.
///
public partial class ConfigForm : Form
{
// -- Attributes -----------------------------------------------------
///
/// A list view button for the 'Font' configuration.
///
private SimpleListViewItem listViewButtonFont;
///
/// A list view button for the 'Graphics' configuration.
///
private SimpleListViewItem listViewButtonGraphics;
///
/// A list view button for the 'Colors' configuration.
///
private SimpleListViewItem listViewButtonColors;
// -- Constructors ---------------------------------------------------
///
/// Initializes a new instance of the ConfigForm class.
///
public ConfigForm()
{
//
// The InitializeComponent() call is required for Windows Forms
// designer support.
//
InitializeComponent();
//
// Set button icons
//
buttonOK.Image = Images.Get(Images.Stock.Accept_16x16);
buttonCancel.Image = Images.Get(Images.Stock.Close_16x16);
//
// Set list view icons
//
listViewButtonColors = new SimpleListViewItem(
Images.Get(Images.Stock.Colors_48x48), "Colors");
listViewButtonFont = new SimpleListViewItem(
Images.Get(Images.Stock.Font_48x48), "Font");
listViewButtonGraphics = new SimpleListViewItem(
Images.Get(Images.Stock.Graphics_48x48), "Graphics");
//
// Add buttons to the list view
//
simpleListView.AddListViewItem(listViewButtonColors);
simpleListView.AddListViewItem(listViewButtonFont);
simpleListView.AddListViewItem(listViewButtonGraphics);
simpleListView.SetSelectedItem(listViewButtonColors);
//
// Bitmap font panel initialization
//
string titleBarText = "Emerald Isle";
List paragraphs = new List();
AttributedText text = new AttributedText("You are in the topmost "
+ "branches of a mangrove. The only exit is down. Your "
+ "parachute is snagged on a branch and you swing from it, "
+ "unable to move, dangling high above the jungle floor.");
paragraphs.Add(text);
text = new AttributedText("What next? go down");
text.AddAttribute(AttributedText.ATTR_INPUT_START,
text.GetLength() - 8);
text.AddAttribute(AttributedText.ATTR_INPUT_END,
text.GetLength() - 1);
paragraphs.Add(text);
bitmapFontPanelColors.Paragraphs = paragraphs;
bitmapFontPanelFont.Paragraphs = paragraphs;
bitmapFontPanelColors.TitleBarText = titleBarText;
bitmapFontPanelFont.TitleBarText = titleBarText;
//
// Import configuration.
//
SetConfigurationValues();
}
// -- Event handling -------------------------------------------------
///
/// Invoked when a button has been pressed on the list view.
///
/// the object that originated the event
///
/// a ListViewButtonClickedEventArgs that contains the event data
///
void SimpleListViewButtonClicked(object sender,
ListViewItemClickedEventArgs e)
{
if (e.Item == listViewButtonColors) {
if (!panelColors.Visible) {
panelGraphics.Visible = false;
panelFont.Visible = false;
panelColors.Visible = true;
}
}
else if (e.Item == listViewButtonGraphics) {
if (!panelGraphics.Visible) {
panelGraphics.Visible = true;
panelFont.Visible = false;
panelColors.Visible = false;
}
}
else if (e.Item == listViewButtonFont) {
if (!panelFont.Visible) {
panelGraphics.Visible = false;
panelFont.Visible = true;
panelColors.Visible = false;
}
}
}
///
/// Invoked when the 'OK' button has been pressed.
///
/// the object that originated the event
/// an EventArgs that contains the event data
void ButtonOKClick(object sender, EventArgs e)
{
StoreConfig();
this.DialogResult = DialogResult.OK;
this.Close();
Config.Instance.FireConfigChanged();
}
///
/// Invoked when the 'Cancel' button has been pressed.
///
/// the object that originated the event
/// an EventArgs that contains the event data
void ButtonCancelClick(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
///
/// Invoked when a text color has been clicked.
///
/// the object that originated the event
/// an EventArgs that contains the event data
void LabelTextColorPreviewClick(object sender, EventArgs e)
{
Label label = (Label)sender;
ColorDialog colorDialog = new ColorDialog();
colorDialog.FullOpen = true;
colorDialog.Color = label.BackColor;
if (colorDialog.ShowDialog() == DialogResult.OK) {
if (label.Equals(labelFgColorPreview)) {
labelFgColorPreview.BackColor = colorDialog.Color;
bitmapFontPanelColors.ForeColor = colorDialog.Color;
bitmapFontPanelFont.ForeColor = colorDialog.Color;
}
else if (label.Equals(labelBgColorPreview)) {
labelBgColorPreview.BackColor = colorDialog.Color;
bitmapFontPanelColors.BackColor = colorDialog.Color;
bitmapFontPanelFont.BackColor = colorDialog.Color;
}
else if (label.Equals(labelTitleStatusFgPreview)) {
labelTitleStatusFgPreview.BackColor = colorDialog.Color;
bitmapFontPanelColors.TitleBarForeColor = colorDialog.Color;
bitmapFontPanelFont.TitleBarForeColor = colorDialog.Color;
}
else if (label.Equals(labelTitleStatusBgPreview)) {
labelTitleStatusBgPreview.BackColor = colorDialog.Color;
bitmapFontPanelColors.TitleBarBackColor = colorDialog.Color;
bitmapFontPanelFont.TitleBarBackColor = colorDialog.Color;
}
else if (label.Equals(labelInputColorPreview)) {
labelInputColorPreview.BackColor = colorDialog.Color;
bitmapFontPanelColors.InputColor = colorDialog.Color;
bitmapFontPanelFont.InputColor = colorDialog.Color;
}
}
}
///
/// Invoked when a font type has been selected.
///
/// the object that originated the event
/// an EventArgs that contains the event data
void ComboBoxFontTypeSelectedIndexChanged(object sender, EventArgs e)
{
string fontType = (string)comboBoxFontType.SelectedItem;
int fontScaling = (int)domainUpDownFontScaling.SelectedItem;
BitmapFont font = BitmapFonts.Get(fontType, fontScaling);
bitmapFontPanelColors.BitmapFont = font;
bitmapFontPanelFont.BitmapFont = font;
}
///
/// Invoked when the font scaling factor has been changed.
///
/// the object that originated the event
/// an EventArgs that contains the event data
void DomainUpDownFontScalingSelectedItemChanged(object sender,
EventArgs e)
{
string fontType = (string)comboBoxFontType.SelectedItem;
int fontScaling = (int)domainUpDownFontScaling.SelectedItem;
BitmapFont font = BitmapFonts.Get(fontType, fontScaling);
bitmapFontPanelColors.BitmapFont = font;
bitmapFontPanelFont.BitmapFont = font;
}
///
/// Invoked when the line spacing has been changed.
///
/// the object that originated the event
/// an EventArgs that contains the event data
void DomainUpDownLineSpacingSelectedItemChanged(object sender,
EventArgs e)
{
int lineSpacing = (int)domainUpDownLineSpacing.SelectedItem;
bitmapFontPanelColors.LineSpacing = lineSpacing;
bitmapFontPanelFont.LineSpacing = lineSpacing;
}
///
/// Invoked when a user defined color for line drawn graphics has been
/// clicked.
///
/// the object that originated the event
/// an EventArgs that contains the event data
void LabelUserColorClick(object sender, EventArgs e)
{
Label label = (Label)sender;
ColorDialog colorDialog = new ColorDialog();
colorDialog.FullOpen = true;
colorDialog.Color = label.BackColor;
if (colorDialog.ShowDialog() == DialogResult.OK) {
if (label.Equals(labelUserColor0)) {
labelUserColor0.BackColor = colorDialog.Color;
}
else if (label.Equals(labelUserColor1)) {
labelUserColor1.BackColor = colorDialog.Color;
}
else if (label.Equals(labelUserColor2)) {
labelUserColor2.BackColor = colorDialog.Color;
}
else if (label.Equals(labelUserColor3)) {
labelUserColor3.BackColor = colorDialog.Color;
}
else if (label.Equals(labelUserColor4)) {
labelUserColor4.BackColor = colorDialog.Color;
}
else if (label.Equals(labelUserColor5)) {
labelUserColor5.BackColor = colorDialog.Color;
}
else if (label.Equals(labelUserColor6)) {
labelUserColor6.BackColor = colorDialog.Color;
}
else if (label.Equals(labelUserColor7)) {
labelUserColor7.BackColor = colorDialog.Color;
}
}
}
// -- Methods --------------------------------------------------------
///
/// Imports configuration values from a Config instance.
///
void SetConfigurationValues()
{
//
// Text color
//
labelFgColorPreview.BackColor = Config.Instance.TextColor;
bitmapFontPanelColors.ForeColor = Config.Instance.TextColor;
bitmapFontPanelFont.ForeColor = Config.Instance.TextColor;
//
// Background color
//
labelBgColorPreview.BackColor = Config.Instance.BackColor;
bitmapFontPanelColors.BackColor = Config.Instance.BackColor;
bitmapFontPanelFont.BackColor = Config.Instance.BackColor;
//
// Input color
//
labelInputColorPreview.BackColor = Config.Instance.InputColor;
bitmapFontPanelColors.InputColor = Config.Instance.InputColor;
bitmapFontPanelFont.InputColor = Config.Instance.InputColor;
//
// Title/Status bar text color
//
labelTitleStatusFgPreview.BackColor = Config.Instance.BarTextColor;
bitmapFontPanelColors.TitleBarForeColor =
Config.Instance.BarTextColor;
bitmapFontPanelFont.TitleBarForeColor =
Config.Instance.BarTextColor;
//
// Title/Status bar background color
//
labelTitleStatusBgPreview.BackColor = Config.Instance.BarBackColor;
bitmapFontPanelColors.TitleBarBackColor =
Config.Instance.BarBackColor;
bitmapFontPanelFont.TitleBarBackColor =
Config.Instance.BarBackColor;
//
// Bitmap font
//
bitmapFontPanelColors.BitmapFont = Config.Instance.Font;
bitmapFontPanelFont.BitmapFont = Config.Instance.Font;
//
// Font scalings
//
int[] fontScalings = BitmapFonts.FontScalings;
for (int i = fontScalings.Length - 1; i >= 0; i--) {
domainUpDownFontScaling.Items.Add(fontScalings[i]);
}
domainUpDownFontScaling.SelectedItem = Config.Instance.FontScaling;
//
// Line spacings
//
int[] lineSpacings = Config.Instance.LineSpacings;
for (int i = lineSpacings.Length - 1; i >= 0; i--) {
domainUpDownLineSpacing.Items.Add(lineSpacings[i]);
}
domainUpDownLineSpacing.SelectedItem = Config.Instance.LineSpacing;
//
// Font types
//
string[] fontTypes = BitmapFonts.FontTypes;
for (int i = 0; i < fontTypes.Length; i++) {
comboBoxFontType.Items.Add(fontTypes[i]);
}
comboBoxFontType.SelectedItem = Config.Instance.Font.Type;
//
// Amiga palette
//
labelAmigaColor0.BackColor = Config.Instance.AmigaPalette[0];
labelAmigaColor1.BackColor = Config.Instance.AmigaPalette[1];
labelAmigaColor2.BackColor = Config.Instance.AmigaPalette[2];
labelAmigaColor3.BackColor = Config.Instance.AmigaPalette[3];
labelAmigaColor4.BackColor = Config.Instance.AmigaPalette[4];
labelAmigaColor5.BackColor = Config.Instance.AmigaPalette[5];
labelAmigaColor6.BackColor = Config.Instance.AmigaPalette[6];
labelAmigaColor7.BackColor = Config.Instance.AmigaPalette[7];
//
// Spectrum palette
//
labelSpectrumColor0.BackColor = Config.Instance.SpectrumPalette[0];
labelSpectrumColor1.BackColor = Config.Instance.SpectrumPalette[1];
labelSpectrumColor2.BackColor = Config.Instance.SpectrumPalette[2];
labelSpectrumColor3.BackColor = Config.Instance.SpectrumPalette[3];
labelSpectrumColor4.BackColor = Config.Instance.SpectrumPalette[4];
labelSpectrumColor5.BackColor = Config.Instance.SpectrumPalette[5];
labelSpectrumColor6.BackColor = Config.Instance.SpectrumPalette[6];
labelSpectrumColor7.BackColor = Config.Instance.SpectrumPalette[7];
//
// User palette
//
labelUserColor0.BackColor = Config.Instance.UserPalette[0];
labelUserColor1.BackColor = Config.Instance.UserPalette[1];
labelUserColor2.BackColor = Config.Instance.UserPalette[2];
labelUserColor3.BackColor = Config.Instance.UserPalette[3];
labelUserColor4.BackColor = Config.Instance.UserPalette[4];
labelUserColor5.BackColor = Config.Instance.UserPalette[5];
labelUserColor6.BackColor = Config.Instance.UserPalette[6];
labelUserColor7.BackColor = Config.Instance.UserPalette[7];
//
// Palette selection
//
switch (Config.Instance.PaletteSelection) {
case (Config.Palette.Amiga):
radioButtonAmigaPalette.Select();
break;
case (Config.Palette.Spectrum):
radioButtonSpectrumPalette.Select();
break;
case (Config.Palette.UserDefined):
radioButtonUserPalette.Select();
break;
}
//
// Image scaling
//
int[] imageScalings = Config.Instance.ImageScalings;
for (int i = imageScalings.Length - 1; i >= 0; i--) {
domainUpDownImageScaling.Items.Add(imageScalings[i]);
}
domainUpDownImageScaling.SelectedItem =
Config.Instance.ImageScaling;
}
///
/// Sets the configuration values of a Config instance according to the
/// dialog settings.
///
void StoreConfig()
{
//
// Text color
//
Config.Instance.TextColor = labelFgColorPreview.BackColor;
//
// Background color
//
Config.Instance.BackColor = labelBgColorPreview.BackColor;
//
// Input color
//
Config.Instance.InputColor = labelInputColorPreview.BackColor;
//
// Title/Status bar text color
//
Config.Instance.BarTextColor = labelTitleStatusFgPreview.BackColor;
//
// Title/Status bar background color
//
Config.Instance.BarBackColor = labelTitleStatusBgPreview.BackColor;
//
// Font scaling
//
Config.Instance.FontScaling =
(int)domainUpDownFontScaling.SelectedItem;
//
// Font
//
Config.Instance.Font = bitmapFontPanelFont.BitmapFont;
//
// Line spacing
//
Config.Instance.LineSpacing =
(int)domainUpDownLineSpacing.SelectedItem;
//
// User palette
//
Config.Instance.UserPalette[0] = labelUserColor0.BackColor;
Config.Instance.UserPalette[1] = labelUserColor1.BackColor;
Config.Instance.UserPalette[2] = labelUserColor2.BackColor;
Config.Instance.UserPalette[3] = labelUserColor3.BackColor;
Config.Instance.UserPalette[4] = labelUserColor4.BackColor;
Config.Instance.UserPalette[5] = labelUserColor5.BackColor;
Config.Instance.UserPalette[6] = labelUserColor6.BackColor;
Config.Instance.UserPalette[7] = labelUserColor7.BackColor;
//
// Palette selection
//
if (radioButtonAmigaPalette.Checked) {
Config.Instance.PaletteSelection = Config.Palette.Amiga;
} else if (radioButtonSpectrumPalette.Checked) {
Config.Instance.PaletteSelection = Config.Palette.Spectrum;
} else if (radioButtonUserPalette.Checked) {
Config.Instance.PaletteSelection = Config.Palette.UserDefined;
}
//
// Image scaling
//
Config.Instance.ImageScaling =
(int)domainUpDownImageScaling.SelectedItem;
}
}
}