-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathScreenMessage.xaml.cs
167 lines (145 loc) · 7.18 KB
/
ScreenMessage.xaml.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Presenter.App_Code;
using Presenter.Resources;
using System.Windows.Threading;
namespace Presenter
{
public partial class ScreenMessage : Window
{
public ScreenMessage()
{
InitializeComponent();
Background = new SolidColorBrush(Config.BackgroundColour);
for (double i = 20; i < 60; i += 2)
FontSizeList.Items.Add(i.ToString());
FontSizeList.SelectedValue = Config.MessengerFontSize.ToString();
foreach (FontFamily fontFamily in Fonts.SystemFontFamilies)
FontFamilyList.Items.Add(fontFamily.Source);
FontFamilyList.SelectedValue = Config.MessengerFontFamily.Source;
foreach (var color in typeof(Colors).GetProperties())
FontColorList.Items.Add(color.Name);
FontColorList.SelectedValue = Config.MessengerFontColourName;
foreach (string align in Enum.GetNames(typeof(HorizontalAlignment)))
if (align != "Stretch")
HorLocation.Items.Add(align);
HorLocation.SelectedValue = Config.MessengerHorizontalPosition.ToString();
foreach (string align in Enum.GetNames(typeof(VerticalAlignment)))
if (align != "Stretch")
VerLocation.Items.Add(align);
VerLocation.SelectedValue = Config.MessengerVerticalPosition.ToString();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
MessageValue.Focus();
}
private void Window_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyboardDevice.IsKeyDown(Key.Enter))
Show_Click(ShowBtn, null);
}
private void Show_Click(object sender, RoutedEventArgs e)
{
double size = Util.Parse<double>(FontSizeList.SelectedValue);
FontFamily family = new FontFamily(FontFamilyList.SelectedValue.ToString());
HorizontalAlignment posx = Util.Parse<HorizontalAlignment>(HorLocation.SelectedValue);
VerticalAlignment posy = Util.Parse<VerticalAlignment>(VerLocation.SelectedValue);
Config.SaveMessengerFont(size, family, (FontColorList.SelectedValue ?? "").ToString());
Config.SaveMessengerLocation(posy, posx);
if (MessageValue.Text == "" && !(TimerEnabled.IsChecked ?? false))
{
this.Close();
return;
}
StackPanel panel = new StackPanel();
string initMessage = MessageValue.Text.Trim();
TextBlock messageLabel = new TextBlock() { Text = initMessage, Foreground = new SolidColorBrush(Config.MessengerFontColour), FontSize = Config.MessengerFontSize, FontFamily = Config.MessengerFontFamily, TextWrapping = TextWrapping.Wrap };
panel.Children.Add(messageLabel);
MessageBox = new Window();
MessageBox.Content = panel;
MessageBox.MaxWidth = Config.ProjectorScreen.Bounds.Width;
MessageBox.Background = new SolidColorBrush(Color.FromRgb(0, 0, 0));
MessageBox.WindowStyle = WindowStyle.None;
MessageBox.SizeToContent = SizeToContent.WidthAndHeight;
MessageBox.Topmost = true;
MessageBox.ResizeMode = ResizeMode.NoResize;
MessageBox.ShowInTaskbar = false;
MessageBox.Show();
this.Focus(); //return focus to main program and not to message box
switch (Config.MessengerVerticalPosition)
{
case VerticalAlignment.Top:
MessageBox.Top = Config.ProjectorScreen.Bounds.Top + Config.MessengerMargin.Top;
break;
case VerticalAlignment.Bottom:
MessageBox.Top = Config.ProjectorScreen.Bounds.Bottom - MessageBox.ActualHeight - Config.MessengerMargin.Bottom;
break;
default:
MessageBox.Top = (Config.ProjectorScreen.Bounds.Height - MessageBox.ActualHeight) / 2 + Config.ProjectorScreen.Bounds.Top;
break;
}
switch (Config.MessengerHorizontalPosition)
{
case HorizontalAlignment.Left:
MessageBox.Left = Config.ProjectorScreen.Bounds.Left + Config.MessengerMargin.Left;
break;
case HorizontalAlignment.Right:
MessageBox.Left = Config.ProjectorScreen.Bounds.Right - MessageBox.ActualWidth - Config.MessengerMargin.Right;
break;
default:
MessageBox.Left = (Config.ProjectorScreen.Bounds.Width - MessageBox.ActualWidth) / 2 + Config.ProjectorScreen.Bounds.Left;
break;
}
Point dpi = Util.GetResolution(MessageBox);
MessageBox.Top /= (dpi.Y / 96);
MessageBox.Left /= (dpi.X / 96);
//add timer
if (TimerEnabled.IsChecked ?? false)
{
int elasped = 0;
int endTime = TimeValue.Text.Replace('.', ':').Contains(':') ? (int)Util.Parse<TimeSpan>(TimeValue.Text.Replace('.', ':')).TotalSeconds : Util.Parse<int>(TimeValue.Text);
bool countUp = (TimerType.SelectedIndex == 1);
if (!initMessage.Contains("{0}"))
initMessage += " {0}";
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += (sen, args) => {
elasped++;
messageLabel.Text = String.Format(initMessage, TimeSpan.FromSeconds(countUp ? elasped : endTime - elasped).FormatTimeSpan(false));
if (elasped >= endTime)
timer.Stop();
MessageBox.UpdateLayout();
};
timer.Start();
messageLabel.Text = String.Format(initMessage, TimeSpan.FromSeconds(countUp ? elasped : endTime - elasped).FormatTimeSpan(false));
}
this.Close();
}
private void Cancel_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (TimeDesc != null)
TimeDesc.Text = (TimerType.SelectedIndex == 0) ? Labels.ShowMessageAddTimerMiddle1 : Labels.ShowMessageAddTimerMiddle2;
}
private void TimerEnabled_Click(object sender, RoutedEventArgs e)
{
bool enabled = (TimerEnabled.IsChecked ?? false);
TimerType.IsEnabled = enabled;
TimeValue.IsEnabled = enabled;
}
public Window MessageBox { get; set; }
}
}