--- /dev/null
+// OpenTween - Client of Twitter
+// Copyright (c) 2022 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
+// All rights reserved.
+//
+// This file is part of OpenTween.
+//
+// This program 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 3 of the License, or (at your option)
+// any later version.
+//
+// This program 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 program. If not, see <http://www.gnu.org/licenses/>, or write to
+// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+using System.Drawing;
+using Xunit;
+
+namespace OpenTween
+{
+ public class ThemeManagerTest
+ {
+ [Fact]
+ public void FontDefaultTest()
+ {
+ var settings = new SettingLocal();
+ using var themeManager = new ThemeManager(settings);
+ Assert.True(themeManager.FontDetail.IsSystemFont);
+ Assert.Equal(nameof(SystemFonts.DefaultFont), themeManager.FontDetail.SystemFontName);
+ }
+
+ [Fact]
+ public void FontCustomTest()
+ {
+ var settings = new SettingLocal
+ {
+ FontDetailStr = "Arial, 9pt",
+ };
+ using var themeManager = new ThemeManager(settings);
+ Assert.False(themeManager.FontDetail.IsSystemFont);
+ Assert.Equal("Arial", themeManager.FontDetail.OriginalFontName);
+ Assert.Equal(9, themeManager.FontDetail.SizeInPoints);
+ }
+
+ [Fact]
+ public void ColorDefaultTest()
+ {
+ var settings = new SettingLocal();
+ using var themeManager = new ThemeManager(settings);
+ Assert.True(themeManager.ColorDetail.IsSystemColor);
+ Assert.Equal(nameof(KnownColor.ControlText), themeManager.ColorDetail.Name);
+ }
+
+ [Fact]
+ public void ColorCustomTest()
+ {
+ var settings = new SettingLocal
+ {
+ ColorDetailStr = "0, 100, 200",
+ };
+ using var themeManager = new ThemeManager(settings);
+ Assert.False(themeManager.ColorDetail.IsSystemColor);
+ Assert.Equal(0, themeManager.ColorDetail.R);
+ Assert.Equal(100, themeManager.ColorDetail.G);
+ Assert.Equal(200, themeManager.ColorDetail.B);
+ }
+ }
+}
/// </summary>
private System.ComponentModel.IContainer components = null;
- /// <summary>
- /// 使用中のリソースをすべてクリーンアップします。
- /// </summary>
- /// <param name="disposing">マネージ リソースが破棄される場合 true、破棄されない場合は false です。</param>
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
-
#region コンポーネント デザイナーで生成されたコード
/// <summary>
{
public partial class FontPanel : SettingPanelBase
{
+ private readonly ThemeManager defaultTheme = new(new());
+ private ThemeManager currentTheme = new(new());
+
public FontPanel()
=> this.InitializeComponent();
public void LoadConfig(SettingLocal settingLocal)
{
- this.lblListFont.Font = settingLocal.FontRead;
- this.lblUnread.Font = settingLocal.FontUnread;
- this.lblUnread.ForeColor = settingLocal.ColorUnread;
- this.lblListFont.ForeColor = settingLocal.ColorRead;
- this.lblFav.ForeColor = settingLocal.ColorFav;
- this.lblOWL.ForeColor = settingLocal.ColorOWL;
- this.lblRetweet.ForeColor = settingLocal.ColorRetweet;
- this.lblDetail.Font = settingLocal.FontDetail;
- this.lblDetailBackcolor.BackColor = settingLocal.ColorDetailBackcolor;
- this.lblDetail.ForeColor = settingLocal.ColorDetail;
- this.lblDetailLink.ForeColor = settingLocal.ColorDetailLink;
+ this.UpdateTheme(settingLocal);
+
+ this.lblListFont.Font = this.currentTheme.FontReaded;
+ this.lblUnread.Font = this.currentTheme.FontUnread;
+ this.lblUnread.ForeColor = this.currentTheme.ColorUnread;
+ this.lblListFont.ForeColor = this.currentTheme.ColorRead;
+ this.lblFav.ForeColor = this.currentTheme.ColorFav;
+ this.lblOWL.ForeColor = this.currentTheme.ColorOWL;
+ this.lblRetweet.ForeColor = this.currentTheme.ColorRetweet;
+ this.lblDetail.Font = this.currentTheme.FontDetail;
+ this.lblDetailBackcolor.BackColor = this.currentTheme.ColorDetailBackcolor;
+ this.lblDetail.ForeColor = this.currentTheme.ColorDetail;
+ this.lblDetailLink.ForeColor = this.currentTheme.ColorDetailLink;
this.checkBoxUseTwemoji.Checked = settingLocal.UseTwemoji;
}
public void SaveConfig(SettingLocal settingLocal)
{
- settingLocal.FontUnread = this.lblUnread.Font; // 未使用
- settingLocal.ColorUnread = this.lblUnread.ForeColor;
- settingLocal.FontRead = this.lblListFont.Font; // リストフォントとして使用
- settingLocal.ColorRead = this.lblListFont.ForeColor;
- settingLocal.ColorFav = this.lblFav.ForeColor;
- settingLocal.ColorOWL = this.lblOWL.ForeColor;
- settingLocal.ColorRetweet = this.lblRetweet.ForeColor;
- settingLocal.FontDetail = this.lblDetail.Font;
- settingLocal.ColorDetailBackcolor = this.lblDetailBackcolor.BackColor;
- settingLocal.ColorDetail = this.lblDetail.ForeColor;
- settingLocal.ColorDetailLink = this.lblDetailLink.ForeColor;
+ var fontConverter = new FontConverter();
+ var colorConverter = new ColorConverter();
+
+ settingLocal.FontUnreadStr = ThemeManager.ConvertFontToString(fontConverter, this.lblUnread.Font, this.defaultTheme.FontUnread); // 未使用
+ settingLocal.ColorUnreadStr = ThemeManager.ConvertColorToString(colorConverter, this.lblUnread.ForeColor, this.defaultTheme.ColorUnread);
+ settingLocal.FontReadStr = ThemeManager.ConvertFontToString(fontConverter, this.lblListFont.Font, this.defaultTheme.FontReaded); // リストフォントとして使用
+ settingLocal.ColorReadStr = ThemeManager.ConvertColorToString(colorConverter, this.lblListFont.ForeColor, this.defaultTheme.ColorRead);
+ settingLocal.ColorFavStr = ThemeManager.ConvertColorToString(colorConverter, this.lblFav.ForeColor, this.defaultTheme.ColorFav);
+ settingLocal.ColorOWLStr = ThemeManager.ConvertColorToString(colorConverter, this.lblOWL.ForeColor, this.defaultTheme.ColorOWL);
+ settingLocal.ColorRetweetStr = ThemeManager.ConvertColorToString(colorConverter, this.lblRetweet.ForeColor, this.defaultTheme.ColorRetweet);
+ settingLocal.FontDetailStr = ThemeManager.ConvertFontToString(fontConverter, this.lblDetail.Font, this.defaultTheme.FontDetail);
+ settingLocal.ColorDetailBackcolorStr = ThemeManager.ConvertColorToString(colorConverter, this.lblDetailBackcolor.BackColor, this.defaultTheme.ColorDetailBackcolor);
+ settingLocal.ColorDetailStr = ThemeManager.ConvertColorToString(colorConverter, this.lblDetail.ForeColor, this.defaultTheme.ColorDetail);
+ settingLocal.ColorDetailLinkStr = ThemeManager.ConvertColorToString(colorConverter, this.lblDetailLink.ForeColor, this.defaultTheme.ColorDetailLink);
settingLocal.UseTwemoji = this.checkBoxUseTwemoji.Checked;
}
- private void ButtonBackToDefaultFontColor_Click(object sender, EventArgs e)
+ private void UpdateTheme(SettingLocal settingLocal)
{
- this.lblUnread.ForeColor = SystemColors.ControlText;
- this.lblUnread.Font = new Font(SystemFonts.DefaultFont, FontStyle.Bold | FontStyle.Underline);
-
- this.lblListFont.ForeColor = System.Drawing.SystemColors.ControlText;
- this.lblListFont.Font = System.Drawing.SystemFonts.DefaultFont;
+ var newTheme = new ThemeManager(settingLocal);
+ (var oldTheme, this.currentTheme) = (this.currentTheme, newTheme);
+ oldTheme.Dispose();
+ }
- this.lblDetail.ForeColor = Color.FromKnownColor(System.Drawing.KnownColor.ControlText);
- this.lblDetail.Font = System.Drawing.SystemFonts.DefaultFont;
+ private void ButtonBackToDefaultFontColor_Click(object sender, EventArgs e)
+ {
+ this.lblUnread.ForeColor = this.defaultTheme.ColorUnread;
+ this.lblUnread.Font = this.defaultTheme.FontUnread;
+ this.lblListFont.ForeColor = this.defaultTheme.ColorRead;
+ this.lblListFont.Font = this.defaultTheme.FontReaded;
+ this.lblDetail.ForeColor = this.defaultTheme.ColorDetail;
+ this.lblDetail.Font = this.defaultTheme.FontDetail;
this.checkBoxUseTwemoji.Checked = true;
-
- this.lblFav.ForeColor = Color.FromKnownColor(System.Drawing.KnownColor.Red);
-
- this.lblOWL.ForeColor = Color.FromKnownColor(System.Drawing.KnownColor.Blue);
-
- this.lblDetailBackcolor.BackColor = Color.FromKnownColor(System.Drawing.KnownColor.Window);
-
- this.lblDetailLink.ForeColor = Color.FromKnownColor(System.Drawing.KnownColor.Blue);
-
- this.lblRetweet.ForeColor = Color.FromKnownColor(System.Drawing.KnownColor.Green);
+ this.lblFav.ForeColor = this.defaultTheme.ColorFav;
+ this.lblOWL.ForeColor = this.defaultTheme.ColorOWL;
+ this.lblDetailBackcolor.BackColor = this.defaultTheme.ColorDetailBackcolor;
+ this.lblDetailLink.ForeColor = this.defaultTheme.ColorDetailLink;
+ this.lblRetweet.ForeColor = this.defaultTheme.ColorRetweet;
}
private void BtnListFont_Click(object sender, EventArgs e)
private void BtnDetailBack_Click(object sender, EventArgs e)
=> this.ShowBackColorDialog(this.lblDetailBackcolor);
+
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing)
+ {
+ this.components?.Dispose();
+ this.defaultTheme.Dispose();
+ this.currentTheme.Dispose();
+ }
+ base.Dispose(disposing);
+ }
}
}
/// </summary>
private System.ComponentModel.IContainer components = null;
- /// <summary>
- /// 使用中のリソースをすべてクリーンアップします。
- /// </summary>
- /// <param name="disposing">マネージ リソースが破棄される場合 true、破棄されない場合は false です。</param>
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
-
#region コンポーネント デザイナーで生成されたコード
/// <summary>
{
public partial class FontPanel2 : SettingPanelBase
{
+ private readonly ThemeManager defaultTheme = new(new());
+ private ThemeManager currentTheme = new(new());
+
public FontPanel2()
=> this.InitializeComponent();
public void LoadConfig(SettingLocal settingLocal)
{
- this.lblSelf.BackColor = settingLocal.ColorSelf;
- this.lblAtSelf.BackColor = settingLocal.ColorAtSelf;
- this.lblTarget.BackColor = settingLocal.ColorTarget;
- this.lblAtTarget.BackColor = settingLocal.ColorAtTarget;
- this.lblAtFromTarget.BackColor = settingLocal.ColorAtFromTarget;
- this.lblAtTo.BackColor = settingLocal.ColorAtTo;
- this.lblInputBackcolor.BackColor = settingLocal.ColorInputBackcolor;
- this.lblInputFont.ForeColor = settingLocal.ColorInputFont;
- this.lblInputFont.Font = settingLocal.FontInputFont;
- this.lblListBackcolor.BackColor = settingLocal.ColorListBackcolor;
+ this.UpdateTheme(settingLocal);
+
+ this.lblSelf.BackColor = this.currentTheme.ColorSelf;
+ this.lblAtSelf.BackColor = this.currentTheme.ColorAtSelf;
+ this.lblTarget.BackColor = this.currentTheme.ColorTarget;
+ this.lblAtTarget.BackColor = this.currentTheme.ColorAtTarget;
+ this.lblAtFromTarget.BackColor = this.currentTheme.ColorAtFromTarget;
+ this.lblAtTo.BackColor = this.currentTheme.ColorAtTo;
+ this.lblInputBackcolor.BackColor = this.currentTheme.ColorInputBackcolor;
+ this.lblInputFont.ForeColor = this.currentTheme.ColorInputFont;
+ this.lblInputFont.Font = this.currentTheme.FontInputFont;
+ this.lblListBackcolor.BackColor = this.currentTheme.ColorListBackcolor;
}
public void SaveConfig(SettingLocal settingLocal)
{
- settingLocal.ColorSelf = this.lblSelf.BackColor;
- settingLocal.ColorAtSelf = this.lblAtSelf.BackColor;
- settingLocal.ColorTarget = this.lblTarget.BackColor;
- settingLocal.ColorAtTarget = this.lblAtTarget.BackColor;
- settingLocal.ColorAtFromTarget = this.lblAtFromTarget.BackColor;
- settingLocal.ColorAtTo = this.lblAtTo.BackColor;
- settingLocal.ColorInputBackcolor = this.lblInputBackcolor.BackColor;
- settingLocal.ColorInputFont = this.lblInputFont.ForeColor;
- settingLocal.ColorListBackcolor = this.lblListBackcolor.BackColor;
- settingLocal.FontInputFont = this.lblInputFont.Font;
+ var fontConverter = new FontConverter();
+ var colorConverter = new ColorConverter();
+
+ settingLocal.ColorSelfStr = ThemeManager.ConvertColorToString(colorConverter, this.lblSelf.BackColor, this.defaultTheme.ColorSelf);
+ settingLocal.ColorAtSelfStr = ThemeManager.ConvertColorToString(colorConverter, this.lblAtSelf.BackColor, this.defaultTheme.ColorAtSelf);
+ settingLocal.ColorTargetStr = ThemeManager.ConvertColorToString(colorConverter, this.lblTarget.BackColor, this.defaultTheme.ColorTarget);
+ settingLocal.ColorAtTargetStr = ThemeManager.ConvertColorToString(colorConverter, this.lblAtTarget.BackColor, this.defaultTheme.ColorAtTarget);
+ settingLocal.ColorAtFromTargetStr = ThemeManager.ConvertColorToString(colorConverter, this.lblAtFromTarget.BackColor, this.defaultTheme.ColorAtFromTarget);
+ settingLocal.ColorAtToStr = ThemeManager.ConvertColorToString(colorConverter, this.lblAtTo.BackColor, this.defaultTheme.ColorAtTo);
+ settingLocal.ColorInputBackcolorStr = ThemeManager.ConvertColorToString(colorConverter, this.lblInputBackcolor.BackColor, this.defaultTheme.ColorInputBackcolor);
+ settingLocal.ColorInputFontStr = ThemeManager.ConvertColorToString(colorConverter, this.lblInputFont.ForeColor, this.defaultTheme.ColorInputFont);
+ settingLocal.ColorListBackcolorStr = ThemeManager.ConvertColorToString(colorConverter, this.lblListBackcolor.BackColor, this.defaultTheme.ColorListBackcolor);
+ settingLocal.FontInputFontStr = ThemeManager.ConvertFontToString(fontConverter, this.lblInputFont.Font, this.defaultTheme.FontInputFont);
}
- private void ButtonBackToDefaultFontColor2_Click(object sender, EventArgs e)
+ private void UpdateTheme(SettingLocal settingLocal)
{
- this.lblInputFont.ForeColor = Color.FromKnownColor(System.Drawing.KnownColor.ControlText);
- this.lblInputFont.Font = System.Drawing.SystemFonts.DefaultFont;
-
- this.lblSelf.BackColor = Color.FromKnownColor(System.Drawing.KnownColor.AliceBlue);
-
- this.lblAtSelf.BackColor = Color.FromKnownColor(System.Drawing.KnownColor.AntiqueWhite);
-
- this.lblTarget.BackColor = Color.FromKnownColor(System.Drawing.KnownColor.LemonChiffon);
-
- this.lblAtTarget.BackColor = Color.FromKnownColor(System.Drawing.KnownColor.LavenderBlush);
-
- this.lblAtFromTarget.BackColor = Color.FromKnownColor(System.Drawing.KnownColor.Honeydew);
-
- this.lblInputBackcolor.BackColor = Color.FromKnownColor(System.Drawing.KnownColor.LemonChiffon);
-
- this.lblAtTo.BackColor = Color.FromKnownColor(System.Drawing.KnownColor.Pink);
+ var newTheme = new ThemeManager(settingLocal);
+ (var oldTheme, this.currentTheme) = (this.currentTheme, newTheme);
+ oldTheme.Dispose();
+ }
- this.lblListBackcolor.BackColor = Color.FromKnownColor(System.Drawing.KnownColor.Window);
+ private void ButtonBackToDefaultFontColor2_Click(object sender, EventArgs e)
+ {
+ this.lblInputFont.ForeColor = this.defaultTheme.ColorInputFont;
+ this.lblInputFont.Font = this.defaultTheme.FontInputFont;
+ this.lblSelf.BackColor = this.defaultTheme.ColorSelf;
+ this.lblAtSelf.BackColor = this.defaultTheme.ColorAtSelf;
+ this.lblTarget.BackColor = this.defaultTheme.ColorTarget;
+ this.lblAtTarget.BackColor = this.defaultTheme.ColorAtTarget;
+ this.lblAtFromTarget.BackColor = this.defaultTheme.ColorAtFromTarget;
+ this.lblInputBackcolor.BackColor = this.defaultTheme.ColorInputBackcolor;
+ this.lblAtTo.BackColor = this.defaultTheme.ColorAtTo;
+ this.lblListBackcolor.BackColor = this.defaultTheme.ColorListBackcolor;
}
private void BtnSelf_Click(object sender, EventArgs e)
private void BtnInputFont_Click(object sender, EventArgs e)
=> this.ShowFontDialog(this.lblInputFont);
+
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing)
+ {
+ this.components?.Dispose();
+ this.defaultTheme.Dispose();
+ this.currentTheme.Dispose();
+ }
+ base.Dispose(disposing);
+ }
}
}
namespace OpenTween
{
- public class SettingLocal : SettingBase<SettingLocal>, IDisposable
+ public class SettingLocal : SettingBase<SettingLocal>
{
#region Settingクラス基本
public static SettingLocal Load()
public int StatusTextHeight = 38;
public int PreviewDistance = -1;
- [XmlIgnore]
- public Font FontUnread = new(SystemFonts.DefaultFont, FontStyle.Bold | FontStyle.Underline);
-
- public string FontUnreadStr
- {
- get => this.FontToString(this.FontUnread);
- set => this.FontUnread = this.StringToFont(value);
- }
-
- [XmlIgnore]
- public Color ColorUnread = System.Drawing.SystemColors.ControlText;
-
- public string ColorUnreadStr
- {
- get => this.ColorToString(this.ColorUnread);
- set => this.ColorUnread = this.StringToColor(value);
- }
-
- [XmlIgnore]
- public Font FontRead = System.Drawing.SystemFonts.DefaultFont;
-
- public string FontReadStr
- {
- get => this.FontToString(this.FontRead);
- set => this.FontRead = this.StringToFont(value);
- }
-
- [XmlIgnore]
- public Color ColorRead = System.Drawing.SystemColors.ControlText;
-
- public string ColorReadStr
- {
- get => this.ColorToString(this.ColorRead);
- set => this.ColorRead = this.StringToColor(value);
- }
-
- [XmlIgnore]
- public Color ColorFav = Color.FromKnownColor(System.Drawing.KnownColor.Red);
-
- public string ColorFavStr
- {
- get => this.ColorToString(this.ColorFav);
- set => this.ColorFav = this.StringToColor(value);
- }
-
- [XmlIgnore]
- public Color ColorOWL = Color.FromKnownColor(System.Drawing.KnownColor.Blue);
-
- public string ColorOWLStr
- {
- get => this.ColorToString(this.ColorOWL);
- set => this.ColorOWL = this.StringToColor(value);
- }
-
- [XmlIgnore]
- public Color ColorRetweet = Color.FromKnownColor(System.Drawing.KnownColor.Green);
-
- public string ColorRetweetStr
- {
- get => this.ColorToString(this.ColorRetweet);
- set => this.ColorRetweet = this.StringToColor(value);
- }
-
- [XmlIgnore]
- public Font FontDetail = System.Drawing.SystemFonts.DefaultFont;
-
- public string FontDetailStr
- {
- get => this.FontToString(this.FontDetail);
- set => this.FontDetail = this.StringToFont(value);
- }
-
- [XmlIgnore]
- public Color ColorSelf = Color.FromKnownColor(System.Drawing.KnownColor.AliceBlue);
-
- public string ColorSelfStr
- {
- get => this.ColorToString(this.ColorSelf);
- set => this.ColorSelf = this.StringToColor(value);
- }
-
- [XmlIgnore]
- public Color ColorAtSelf = Color.FromKnownColor(System.Drawing.KnownColor.AntiqueWhite);
-
- public string ColorAtSelfStr
- {
- get => this.ColorToString(this.ColorAtSelf);
- set => this.ColorAtSelf = this.StringToColor(value);
- }
-
- [XmlIgnore]
- public Color ColorTarget = Color.FromKnownColor(System.Drawing.KnownColor.LemonChiffon);
-
- public string ColorTargetStr
- {
- get => this.ColorToString(this.ColorTarget);
- set => this.ColorTarget = this.StringToColor(value);
- }
+ public string? FontUnreadStr { get; set; }
- [XmlIgnore]
- public Color ColorAtTarget = Color.FromKnownColor(System.Drawing.KnownColor.LavenderBlush);
+ public string? ColorUnreadStr { get; set; }
- public string ColorAtTargetStr
- {
- get => this.ColorToString(this.ColorAtTarget);
- set => this.ColorAtTarget = this.StringToColor(value);
- }
+ public string? FontReadStr { get; set; }
- [XmlIgnore]
- public Color ColorAtFromTarget = Color.FromKnownColor(System.Drawing.KnownColor.Honeydew);
+ public string? ColorReadStr { get; set; }
- public string ColorAtFromTargetStr
- {
- get => this.ColorToString(this.ColorAtFromTarget);
- set => this.ColorAtFromTarget = this.StringToColor(value);
- }
-
- [XmlIgnore]
- public Color ColorAtTo = Color.FromKnownColor(System.Drawing.KnownColor.Pink);
+ public string? ColorFavStr { get; set; }
- public string ColorAtToStr
- {
- get => this.ColorToString(this.ColorAtTo);
- set => this.ColorAtTo = this.StringToColor(value);
- }
+ public string? ColorOWLStr { get; set; }
- [XmlIgnore]
- public Color ColorInputBackcolor = Color.FromKnownColor(System.Drawing.KnownColor.LemonChiffon);
+ public string? ColorRetweetStr { get; set; }
- public string ColorInputBackcolorStr
- {
- get => this.ColorToString(this.ColorInputBackcolor);
- set => this.ColorInputBackcolor = this.StringToColor(value);
- }
+ public string? FontDetailStr { get; set; }
- [XmlIgnore]
- public Color ColorInputFont = Color.FromKnownColor(System.Drawing.KnownColor.ControlText);
+ public string? ColorSelfStr { get; set; }
- public string ColorInputFontStr
- {
- get => this.ColorToString(this.ColorInputFont);
- set => this.ColorInputFont = this.StringToColor(value);
- }
+ public string? ColorAtSelfStr { get; set; }
- [XmlIgnore]
- public Font FontInputFont = System.Drawing.SystemFonts.DefaultFont;
+ public string? ColorTargetStr { get; set; }
- public string FontInputFontStr
- {
- get => this.FontToString(this.FontInputFont);
- set => this.FontInputFont = this.StringToFont(value);
- }
+ public string? ColorAtTargetStr { get; set; }
- [XmlIgnore]
- public Color ColorListBackcolor = Color.FromKnownColor(System.Drawing.KnownColor.Window);
+ public string? ColorAtFromTargetStr { get; set; }
- public string ColorListBackcolorStr
- {
- get => this.ColorToString(this.ColorListBackcolor);
- set => this.ColorListBackcolor = this.StringToColor(value);
- }
+ public string? ColorAtToStr { get; set; }
- [XmlIgnore]
- public Color ColorDetailBackcolor = Color.FromKnownColor(System.Drawing.KnownColor.Window);
+ public string? ColorInputBackcolorStr { get; set; }
- public string ColorDetailBackcolorStr
- {
- get => this.ColorToString(this.ColorDetailBackcolor);
- set => this.ColorDetailBackcolor = this.StringToColor(value);
- }
+ public string? ColorInputFontStr { get; set; }
- [XmlIgnore]
- public Color ColorDetail = Color.FromKnownColor(System.Drawing.KnownColor.ControlText);
+ public string? FontInputFontStr { get; set; }
- public string ColorDetailStr
- {
- get => this.ColorToString(this.ColorDetail);
- set => this.ColorDetail = this.StringToColor(value);
- }
+ public string? ColorListBackcolorStr { get; set; }
- [XmlIgnore]
- public Color ColorDetailLink = Color.FromKnownColor(System.Drawing.KnownColor.Blue);
+ public string? ColorDetailBackcolorStr { get; set; }
- public string ColorDetailLinkStr
- {
- get => this.ColorToString(this.ColorDetailLink);
- set => this.ColorDetailLink = this.StringToColor(value);
- }
+ public string? ColorDetailStr { get; set; }
- [XmlIgnore]
- public Font? FontUIGlobal = null;
+ public string? ColorDetailLinkStr { get; set; }
/// <summary>
/// [隠し設定] UI フォントを指定します
/// <remarks>
/// フォントによっては一部レイアウトが崩れるためこっそり追加
/// </remarks>
- public string? FontUIGlobalStr
- {
- get => this.FontUIGlobal != null ? this.FontToString(this.FontUIGlobal) : null;
- set => this.FontUIGlobal = value != null ? this.StringToFont(value) : null;
- }
+ public string? FontUIGlobalStr { get; set; }
[XmlIgnore]
public string ProxyPassword = "";
/// </summary>
public bool UseTwemoji = true;
- [XmlIgnore]
- private readonly FontConverter fontConverter = new();
-
- protected string FontToString(Font font)
- => this.fontConverter.ConvertToString(font);
-
- protected Font StringToFont(string str)
- => (Font)this.fontConverter.ConvertFromString(str);
-
- [XmlIgnore]
- private readonly ColorConverter colorConverter = new();
-
- protected string ColorToString(Color color)
- => this.colorConverter.ConvertToString(color);
-
- protected Color StringToColor(string str)
- => (Color)this.colorConverter.ConvertFromString(str);
-
/// <summary>
/// 指定されたスケールと SettingLocal.ScaleDimension のスケールとの拡大比を返します
/// </summary>
=> new(
currentSizeDimension.Width / this.ScaleDimension.Width,
currentSizeDimension.Height / this.ScaleDimension.Height);
-
- public void Dispose()
- {
- this.Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- protected virtual void Dispose(bool disposing)
- {
- if (disposing)
- {
- this.FontUnread?.Dispose();
- this.FontRead?.Dispose();
- this.FontDetail?.Dispose();
- this.FontInputFont?.Dispose();
- }
- }
}
}
public ThemeManager(SettingLocal settingLocal)
{
- this.FontUnread = settingLocal.FontUnread;
- this.FontReaded = settingLocal.FontRead;
- this.FontDetail = settingLocal.FontDetail;
- this.FontInputFont = settingLocal.FontInputFont;
-
- this.ColorUnread = settingLocal.ColorUnread;
- this.ColorRead = settingLocal.ColorRead;
- this.ColorFav = settingLocal.ColorFav;
- this.ColorOWL = settingLocal.ColorOWL;
- this.ColorRetweet = settingLocal.ColorRetweet;
+ var fontConverter = new FontConverter();
+
+ this.FontUnread = ConvertStringToFont(fontConverter, settingLocal.FontUnreadStr)
+ ?? new(SystemFonts.DefaultFont, FontStyle.Bold | FontStyle.Underline);
+
+ this.FontReaded = ConvertStringToFont(fontConverter, settingLocal.FontReadStr)
+ ?? SystemFonts.DefaultFont;
+
+ this.FontDetail = ConvertStringToFont(fontConverter, settingLocal.FontDetailStr)
+ ?? SystemFonts.DefaultFont;
+
+ this.FontInputFont = ConvertStringToFont(fontConverter, settingLocal.FontInputFontStr)
+ ?? SystemFonts.DefaultFont;
+
+ var colorConverter = new ColorConverter();
+
+ this.ColorUnread = ConvertStringToColor(colorConverter, settingLocal.ColorUnreadStr)
+ ?? SystemColors.ControlText;
+
+ this.ColorRead = ConvertStringToColor(colorConverter, settingLocal.ColorReadStr)
+ ?? SystemColors.ControlText;
+
+ this.ColorFav = ConvertStringToColor(colorConverter, settingLocal.ColorFavStr)
+ ?? Color.FromKnownColor(KnownColor.Red);
+
+ this.ColorOWL = ConvertStringToColor(colorConverter, settingLocal.ColorOWLStr)
+ ?? Color.FromKnownColor(KnownColor.Blue);
+
+ this.ColorRetweet = ConvertStringToColor(colorConverter, settingLocal.ColorRetweetStr)
+ ?? Color.FromKnownColor(KnownColor.Green);
+
this.ColorHighLight = Color.FromKnownColor(KnownColor.HighlightText);
- this.ColorDetail = settingLocal.ColorDetail;
- this.ColorDetailLink = settingLocal.ColorDetailLink;
- this.ColorDetailBackcolor = settingLocal.ColorDetailBackcolor;
- this.ColorSelf = settingLocal.ColorSelf;
- this.ColorAtSelf = settingLocal.ColorAtSelf;
- this.ColorTarget = settingLocal.ColorTarget;
- this.ColorAtTarget = settingLocal.ColorAtTarget;
- this.ColorAtFromTarget = settingLocal.ColorAtFromTarget;
- this.ColorAtTo = settingLocal.ColorAtTo;
- this.ColorListBackcolor = settingLocal.ColorListBackcolor;
- this.ColorInputBackcolor = settingLocal.ColorInputBackcolor;
- this.ColorInputFont = settingLocal.ColorInputFont;
+
+ this.ColorDetail = ConvertStringToColor(colorConverter, settingLocal.ColorDetailStr)
+ ?? Color.FromKnownColor(KnownColor.ControlText);
+
+ this.ColorDetailLink = ConvertStringToColor(colorConverter, settingLocal.ColorDetailLinkStr)
+ ?? Color.FromKnownColor(KnownColor.Blue);
+
+ this.ColorDetailBackcolor = ConvertStringToColor(colorConverter, settingLocal.ColorDetailBackcolorStr)
+ ?? Color.FromKnownColor(KnownColor.Window);
+
+ this.ColorSelf = ConvertStringToColor(colorConverter, settingLocal.ColorSelfStr)
+ ?? Color.FromKnownColor(KnownColor.AliceBlue);
+
+ this.ColorAtSelf = ConvertStringToColor(colorConverter, settingLocal.ColorAtSelfStr)
+ ?? Color.FromKnownColor(KnownColor.AntiqueWhite);
+
+ this.ColorTarget = ConvertStringToColor(colorConverter, settingLocal.ColorTargetStr)
+ ?? Color.FromKnownColor(KnownColor.LemonChiffon);
+
+ this.ColorAtTarget = ConvertStringToColor(colorConverter, settingLocal.ColorAtTargetStr)
+ ?? Color.FromKnownColor(KnownColor.LavenderBlush);
+
+ this.ColorAtFromTarget = ConvertStringToColor(colorConverter, settingLocal.ColorAtFromTargetStr)
+ ?? Color.FromKnownColor(KnownColor.Honeydew);
+
+ this.ColorAtTo = ConvertStringToColor(colorConverter, settingLocal.ColorAtToStr)
+ ?? Color.FromKnownColor(KnownColor.Pink);
+
+ this.ColorListBackcolor = ConvertStringToColor(colorConverter, settingLocal.ColorListBackcolorStr)
+ ?? Color.FromKnownColor(KnownColor.Window);
+
+ this.ColorInputBackcolor = ConvertStringToColor(colorConverter, settingLocal.ColorInputBackcolorStr)
+ ?? Color.FromKnownColor(KnownColor.LemonChiffon);
+
+ this.ColorInputFont = ConvertStringToColor(colorConverter, settingLocal.ColorInputFontStr)
+ ?? Color.FromKnownColor(KnownColor.ControlText);
this.BrushSelf = new SolidBrush(this.ColorSelf);
this.BrushAtSelf = new SolidBrush(this.ColorAtSelf);
this.IsDisposed = true;
}
+ public static Font? ConvertStringToFont(FontConverter converter, string? fontStr)
+ {
+ if (MyCommon.IsNullOrEmpty(fontStr))
+ return null;
+
+ try
+ {
+ return (Font)converter.ConvertFromString(fontStr);
+ }
+ catch
+ {
+ return null;
+ }
+ }
+
+ public static string? ConvertFontToString(FontConverter converter, Font font, Font defaultValue)
+ {
+ static bool Equals(Font font1, Font font2)
+ => font1.Name == font2.Name && font1.Size == font2.Size && font1.Unit == font2.Unit && font1.Style == font2.Style;
+
+ if (Equals(font, defaultValue))
+ return null;
+
+ return converter.ConvertToString(font);
+ }
+
+ public static Color? ConvertStringToColor(ColorConverter converter, string? colorStr)
+ {
+ if (MyCommon.IsNullOrEmpty(colorStr))
+ return null;
+
+ try
+ {
+ return (Color)converter.ConvertFromString(colorStr);
+ }
+ catch
+ {
+ return null;
+ }
+ }
+
+ public static string? ConvertColorToString(ColorConverter converter, Color color, Color defaultValue)
+ {
+ if (color == defaultValue)
+ return null;
+
+ return converter.ConvertToString(color);
+ }
+
public static void ApplyGlobalUIFont(SettingLocal settingLocal)
{
- var font = settingLocal.FontUIGlobal;
+ var fontConverter = new FontConverter();
+ var font = ConvertStringToFont(fontConverter, settingLocal.FontUIGlobalStr);
if (font != null)
OTBaseForm.GlobalFont = font;
}