1 // OpenTween - Client of Twitter
2 // Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
3 // (c) 2008-2011 Moz (@syo68k)
4 // (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
5 // (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
6 // (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
7 // (c) 2011 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
8 // All rights reserved.
10 // This file is part of OpenTween.
12 // This program is free software; you can redistribute it and/or modify it
13 // under the terms of the GNU General public License as published by the Free
14 // Software Foundation; either version 3 of the License, or (at your option)
17 // This program is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General public License
22 // You should have received a copy of the GNU General public License along
23 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
24 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
25 // Boston, MA 02110-1301, USA.
34 public sealed class ThemeManager : IDisposable
36 public bool IsDisposed { get; private set; } = false;
38 /// <summary>未読用フォント</summary>
39 public Font FontUnread { get; }
41 public Font FontUnreadBold { get; }
43 /// <summary>既読用フォント</summary>
44 public Font FontReaded { get; }
46 public Font FontReadedBold { get; }
48 /// <summary>発言詳細部用フォント</summary>
49 public Font FontDetail { get; }
51 /// <summary>入力欄フォント</summary>
52 public Font FontInputFont { get; }
54 /// <summary>未読用文字色</summary>
55 public Color ColorUnread { get; }
57 /// <summary>既読用文字色</summary>
58 public Color ColorRead { get; }
60 /// <summary>Fav用文字色</summary>
61 public Color ColorFav { get; }
63 /// <summary>片思い用文字色</summary>
64 public Color ColorOWL { get; }
66 /// <summary>Retweet用文字色</summary>
67 public Color ColorRetweet { get; }
69 /// <summary>選択中の行用文字色</summary>
70 public Color ColorHighLight { get; }
72 /// <summary>発言詳細部用色</summary>
73 public Color ColorDetail { get; }
75 /// <summary>発言詳細部用リンク文字色</summary>
76 public Color ColorDetailLink { get; }
78 /// <summary>発言詳細部用背景色</summary>
79 public Color ColorDetailBackcolor { get; }
81 /// <summary>自分の発言用背景色</summary>
82 public Color ColorSelf { get; }
84 /// <summary>自分宛返信用背景色</summary>
85 public Color ColorAtSelf { get; }
87 /// <summary>選択発言者の他の発言用背景色</summary>
88 public Color ColorTarget { get; }
90 /// <summary>選択発言中の返信先用背景色</summary>
91 public Color ColorAtTarget { get; }
93 /// <summary>選択発言者への返信発言用背景色</summary>
94 public Color ColorAtFromTarget { get; }
96 /// <summary>選択発言の唯一@先</summary>
97 public Color ColorAtTo { get; }
99 /// <summary>リスト部通常発言背景色</summary>
100 public Color ColorListBackcolor { get; }
102 /// <summary>入力欄背景色</summary>
103 public Color ColorInputBackcolor { get; }
105 /// <summary>入力欄文字色</summary>
106 public Color ColorInputFont { get; }
108 public Brush BrushSelf { get; }
110 public Brush BrushAtSelf { get; }
112 public Brush BrushTarget { get; }
114 public Brush BrushAtTarget { get; }
116 public Brush BrushAtFromTarget { get; }
118 public Brush BrushAtTo { get; }
120 public Brush BrushListBackcolor { get; }
122 public Brush BrushHighLight { get; }
124 /// <summary>Listにフォーカスがないときの選択行の背景色</summary>
125 public Brush BrushDeactiveSelection { get; }
127 public ThemeManager(SettingLocal settingLocal)
129 var fontConverter = new FontConverter();
131 this.FontUnread = ConvertStringToFont(fontConverter, settingLocal.FontUnreadStr)
132 ?? new(SystemFonts.DefaultFont, FontStyle.Bold | FontStyle.Underline);
134 this.FontUnreadBold = new(this.FontUnread, FontStyle.Bold);
136 this.FontReaded = ConvertStringToFont(fontConverter, settingLocal.FontReadStr)
137 ?? SystemFonts.DefaultFont;
139 this.FontReadedBold = new(this.FontReaded, FontStyle.Bold);
141 this.FontDetail = ConvertStringToFont(fontConverter, settingLocal.FontDetailStr)
142 ?? SystemFonts.DefaultFont;
144 this.FontInputFont = ConvertStringToFont(fontConverter, settingLocal.FontInputFontStr)
145 ?? SystemFonts.DefaultFont;
147 var colorConverter = new ColorConverter();
149 this.ColorUnread = ConvertStringToColor(colorConverter, settingLocal.ColorUnreadStr)
150 ?? SystemColors.ControlText;
152 this.ColorRead = ConvertStringToColor(colorConverter, settingLocal.ColorReadStr)
153 ?? SystemColors.ControlText;
155 this.ColorFav = ConvertStringToColor(colorConverter, settingLocal.ColorFavStr)
156 ?? Color.FromKnownColor(KnownColor.Red);
158 this.ColorOWL = ConvertStringToColor(colorConverter, settingLocal.ColorOWLStr)
159 ?? Color.FromKnownColor(KnownColor.Blue);
161 this.ColorRetweet = ConvertStringToColor(colorConverter, settingLocal.ColorRetweetStr)
162 ?? Color.FromKnownColor(KnownColor.Green);
164 this.ColorHighLight = Color.FromKnownColor(KnownColor.HighlightText);
166 this.ColorDetail = ConvertStringToColor(colorConverter, settingLocal.ColorDetailStr)
167 ?? Color.FromKnownColor(KnownColor.ControlText);
169 this.ColorDetailLink = ConvertStringToColor(colorConverter, settingLocal.ColorDetailLinkStr)
170 ?? Color.FromKnownColor(KnownColor.Blue);
172 this.ColorDetailBackcolor = ConvertStringToColor(colorConverter, settingLocal.ColorDetailBackcolorStr)
173 ?? Color.FromKnownColor(KnownColor.Window);
175 this.ColorSelf = ConvertStringToColor(colorConverter, settingLocal.ColorSelfStr)
176 ?? Color.FromKnownColor(KnownColor.AliceBlue);
178 this.ColorAtSelf = ConvertStringToColor(colorConverter, settingLocal.ColorAtSelfStr)
179 ?? Color.FromKnownColor(KnownColor.AntiqueWhite);
181 this.ColorTarget = ConvertStringToColor(colorConverter, settingLocal.ColorTargetStr)
182 ?? Color.FromKnownColor(KnownColor.LemonChiffon);
184 this.ColorAtTarget = ConvertStringToColor(colorConverter, settingLocal.ColorAtTargetStr)
185 ?? Color.FromKnownColor(KnownColor.LavenderBlush);
187 this.ColorAtFromTarget = ConvertStringToColor(colorConverter, settingLocal.ColorAtFromTargetStr)
188 ?? Color.FromKnownColor(KnownColor.Honeydew);
190 this.ColorAtTo = ConvertStringToColor(colorConverter, settingLocal.ColorAtToStr)
191 ?? Color.FromKnownColor(KnownColor.Pink);
193 this.ColorListBackcolor = ConvertStringToColor(colorConverter, settingLocal.ColorListBackcolorStr)
194 ?? Color.FromKnownColor(KnownColor.Window);
196 this.ColorInputBackcolor = ConvertStringToColor(colorConverter, settingLocal.ColorInputBackcolorStr)
197 ?? Color.FromKnownColor(KnownColor.LemonChiffon);
199 this.ColorInputFont = ConvertStringToColor(colorConverter, settingLocal.ColorInputFontStr)
200 ?? Color.FromKnownColor(KnownColor.ControlText);
202 this.BrushSelf = new SolidBrush(this.ColorSelf);
203 this.BrushAtSelf = new SolidBrush(this.ColorAtSelf);
204 this.BrushTarget = new SolidBrush(this.ColorTarget);
205 this.BrushAtTarget = new SolidBrush(this.ColorAtTarget);
206 this.BrushAtFromTarget = new SolidBrush(this.ColorAtFromTarget);
207 this.BrushAtTo = new SolidBrush(this.ColorAtTo);
208 this.BrushListBackcolor = new SolidBrush(this.ColorListBackcolor);
209 this.BrushHighLight = new SolidBrush(Color.FromKnownColor(KnownColor.Highlight));
210 this.BrushDeactiveSelection = new SolidBrush(Color.FromKnownColor(KnownColor.ButtonFace));
213 public void Dispose()
218 this.FontUnread.Dispose();
219 this.FontUnreadBold.Dispose();
220 this.FontReaded.Dispose();
221 this.FontReadedBold.Dispose();
222 this.FontDetail.Dispose();
223 this.FontInputFont.Dispose();
224 this.BrushSelf.Dispose();
225 this.BrushAtSelf.Dispose();
226 this.BrushTarget.Dispose();
227 this.BrushAtTarget.Dispose();
228 this.BrushAtFromTarget.Dispose();
229 this.BrushAtTo.Dispose();
230 this.BrushListBackcolor.Dispose();
231 this.BrushHighLight.Dispose();
232 this.BrushDeactiveSelection.Dispose();
234 this.IsDisposed = true;
237 public static Font? ConvertStringToFont(FontConverter converter, string? fontStr)
239 if (MyCommon.IsNullOrEmpty(fontStr))
244 return (Font)converter.ConvertFromString(fontStr);
252 public static string? ConvertFontToString(FontConverter converter, Font font, Font defaultValue)
254 static bool Equals(Font font1, Font font2)
255 => font1.Name == font2.Name && font1.Size == font2.Size && font1.Unit == font2.Unit && font1.Style == font2.Style;
257 if (Equals(font, defaultValue))
260 return converter.ConvertToString(font);
263 public static Color? ConvertStringToColor(ColorConverter converter, string? colorStr)
265 if (MyCommon.IsNullOrEmpty(colorStr))
270 return (Color)converter.ConvertFromString(colorStr);
278 public static string? ConvertColorToString(ColorConverter converter, Color color, Color defaultValue)
280 if (color == defaultValue)
283 return converter.ConvertToString(color);
286 public static void ApplyGlobalUIFont(SettingLocal settingLocal)
288 var fontConverter = new FontConverter();
289 var font = ConvertStringToFont(fontConverter, settingLocal.FontUIGlobalStr);
291 OTBaseForm.GlobalFont = font;