private void TextBoxTitleColor_TextChanged(object sender, TextChangedEventArgs e) { if (TextBoxTitleColor.Text.Count() == 6) { RectangleTitleColor.Fill = MiscConverter.IntToSolidColorBrush(MiscConverter.StringToIntColor(TextBoxTitleColor.Text)); } }
// Thread threadRemote; public void GetTitleColor() { try { titleColor = MiscConverter.IntToSolidColorBrush(MiscConverter.StringToIntColor(Setting.GetAttribute("titleColor"))); } catch (Exception ex) { Console.WriteLine(ex.Message); titleColor = MiscConverter.IntToSolidColorBrush(0xffff00); } if (freePresentationText != null) { // free text presentation: don't change contents UpdateFree(); } if (WrapPanelPageList != null && WrapPanelPageList.Children.Count > 1) { // if a text file is open, the minimum of Count is 2 int len = textList.Count; for (int i = 1; i < len; i++) { if (isTitleList[i]) { (WrapPanelPageList.Children[i - 1] as Button).Foreground = titleColor; } } } if (isTitleList != null) { if (PgmContent != null && isTitleList[pgmManager.PageNumber]) { PgmContent.Foreground = titleColor; if (pw != null) { pw.LabelPresenterText.Foreground = titleColor; } } if (PvwContent != null && isTitleList[pvwManager.PageNumber]) { PvwContent.Foreground = titleColor; } } }
public void ApplySettings() { /* 여기서 다룰 항목 * FontFamily * FontSize * TextBlock.LineHeight * TextBlock.TextAlignment * Foreground * HorizontalAlignment * VerticalAlignment */ int textPosition, textAlign; double marginBasic, marginOverflow, fontSize, lineHeight, screenRatioSimulationWidth, screenRatioSimulationHeight; bool screenRatioSimulation, fontWeightBold = false, fontStyleItalic = false; string fontFamily; // load and apply properties /* * if (!int.TryParse(Setting.GetAttribute("presenterScreen"), out presenterScreen)) { * presenterScreen = System.Windows.Forms.Screen.AllScreens.Length; * } */ if (!double.TryParse(Setting.GetAttribute("marginBasic"), out marginBasic) || marginBasic < 0) { marginBasic = 5; } if (!double.TryParse(Setting.GetAttribute("marginOverflow"), out marginOverflow) || marginOverflow < 0) { marginOverflow = 1; } if (!int.TryParse(Setting.GetAttribute("textPosition"), out textPosition) || textPosition < 1 || textPosition > 9) { textPosition = 5; } if (!int.TryParse(Setting.GetAttribute("textAlign"), out textAlign) || textAlign < 1 || textAlign > 3) { textAlign = 2; } if ((fontFamily = Setting.GetAttribute("fontFamily")) == null) { fontFamily = "Malgun Gothic"; } if (Setting.GetAttribute("fontWeight").Equals("bold")) { fontWeightBold = true; } if (Setting.GetAttribute("fontStyle").Equals("italic")) { fontStyleItalic = true; } if (!double.TryParse(Setting.GetAttribute("fontSize"), out fontSize) || fontSize <= 0) { fontSize = 8.75; } if (!double.TryParse(Setting.GetAttribute("lineHeight"), out lineHeight) || lineHeight < 0) { lineHeight = 140; } if (!bool.TryParse(Setting.GetAttribute("screenRatioSimulation"), out screenRatioSimulation)) { screenRatioSimulation = false; } if (!double.TryParse(Setting.GetAttribute("screenRatioSimulationWidth"), out screenRatioSimulationWidth) || screenRatioSimulationWidth <= 0) { screenRatioSimulationWidth = 4; } if (!double.TryParse(Setting.GetAttribute("screenRatioSimulationHeight"), out screenRatioSimulationHeight) || screenRatioSimulationHeight <= 0) { screenRatioSimulationHeight = 3; } // Screen ratio simulation if (screenRatioSimulation) { double currentRatio = (double)sc[presenterScreen - 1].Bounds.Width / sc[presenterScreen - 1].Bounds.Height; double simulationRatio = screenRatioSimulationWidth / screenRatioSimulationHeight; double ratio = currentRatio / simulationRatio; if (ratio < 1) // < 1: wider simulation ratio { GridExCol1.Width = zeroPixels; GridExCol2.Width = oneStar; GridExCol3.Width = zeroPixels; GridExRow1.Height = oneStar; GridExRow2.Height = new GridLength(sc[presenterScreen - 1].Bounds.Height * ratio, GridUnitType.Pixel); GridExRow3.Height = oneStar; fontSize = fontSize * ratio; } else { GridExCol1.Width = oneStar; GridExCol2.Width = new GridLength(sc[presenterScreen - 1].Bounds.Width / ratio, GridUnitType.Pixel); GridExCol3.Width = oneStar; GridExRow1.Height = zeroPixels; GridExRow2.Height = oneStar; GridExRow3.Height = zeroPixels; } } else { GridExCol1.Width = zeroPixels; GridExCol2.Width = oneStar; GridExCol3.Width = zeroPixels; GridExRow1.Height = zeroPixels; GridExRow2.Height = oneStar; GridExRow3.Height = zeroPixels; } // unit correction fontSize /= 100; lineHeight /= 100; // FontFamily try { LabelPresenterText.FontFamily = new FontFamily(fontFamily); } catch (Exception e) { Console.WriteLine(e.Message); LabelPresenterText.FontFamily = new FontFamily("Malgun Gothic"); } LabelPresenterText.FontWeight = fontWeightBold ? FontWeights.Bold : FontWeights.Regular; LabelPresenterText.FontStyle = fontStyleItalic ? FontStyles.Italic : FontStyles.Normal; // FontSize LabelPresenterText.FontSize = MiscConverter.RelativeToAbsolute(fontSize, Height); // TextBlock.LineHeight LabelPresenterText.SetValue(TextBlock.LineHeightProperty, MiscConverter.RelativeToAbsolute(fontSize * lineHeight, Height)); // TextBlock.TextAlignment switch (textAlign) { case 1: // Left LabelPresenterText.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Left); break; case 3: // Right LabelPresenterText.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Right); break; default: // 2 or invalid value -> Center LabelPresenterText.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center); break; } // Foreground LabelPresenterText.Foreground = Brushes.White; // Alignment if ((textPosition - 1) / 3 == 0) { // 1, 2, 3 -> Top LabelPresenterText.VerticalAlignment = VerticalAlignment.Top; GridRow1.Height = new GridLength(marginBasic, GridUnitType.Star); GridRow2.Height = new GridLength(100 - marginBasic - marginOverflow, GridUnitType.Star); GridRow3.Height = new GridLength(marginOverflow, GridUnitType.Star); } else if ((textPosition - 1) / 3 == 2) { // 7, 8, 9 -> Bottom LabelPresenterText.VerticalAlignment = VerticalAlignment.Bottom; GridRow1.Height = new GridLength(marginOverflow, GridUnitType.Star); GridRow2.Height = new GridLength(100 - marginBasic - marginOverflow, GridUnitType.Star); GridRow3.Height = new GridLength(marginBasic, GridUnitType.Star); } else { // 4, 5, 6, invalid value -> Center LabelPresenterText.VerticalAlignment = VerticalAlignment.Center; GridRow1.Height = new GridLength(marginOverflow, GridUnitType.Star); GridRow2.Height = new GridLength(100 - 2 * marginOverflow, GridUnitType.Star); GridRow3.Height = new GridLength(marginOverflow, GridUnitType.Star); } if (textPosition % 3 == 1) { // 1, 4, 7 -> Left LabelPresenterText.HorizontalAlignment = HorizontalAlignment.Left; GridCol1.Width = new GridLength(marginBasic, GridUnitType.Star); GridCol2.Width = new GridLength(100 - marginBasic - marginOverflow, GridUnitType.Star); GridCol3.Width = new GridLength(marginOverflow, GridUnitType.Star); } else if (textPosition % 3 == 0) { // 3, 6, 9 -> Right LabelPresenterText.HorizontalAlignment = HorizontalAlignment.Right; GridCol1.Width = new GridLength(marginOverflow, GridUnitType.Star); GridCol2.Width = new GridLength(100 - marginBasic - marginOverflow, GridUnitType.Star); GridCol3.Width = new GridLength(marginBasic, GridUnitType.Star); } else { // 2, 5, 8, invalid value -> Center LabelPresenterText.HorizontalAlignment = HorizontalAlignment.Center; GridCol1.Width = new GridLength(marginOverflow, GridUnitType.Star); GridCol2.Width = new GridLength(100 - 2 * marginOverflow, GridUnitType.Star); GridCol3.Width = new GridLength(marginOverflow, GridUnitType.Star); } }
// Load current settings from Setting class private void GetSettings() { if (!int.TryParse(Setting.GetAttribute("presenterScreen"), out presenterScreen)) { presenterScreen = System.Windows.Forms.Screen.AllScreens.Length; } if (!int.TryParse(Setting.GetAttribute("textEncoding"), out textEncoding)) { textEncoding = 0; } switch (textEncoding) { case 0: // default case 1200: // UTF-16 LE case 1201: // UTF-16 BE case 65001: // UTF-8 break; default: textEncoding = 0; break; } if (!decimal.TryParse(Setting.GetAttribute("marginBasic"), out marginBasic) || marginBasic < 0) { marginBasic = 5; } if (!decimal.TryParse(Setting.GetAttribute("marginOverflow"), out marginOverflow) || marginOverflow < 0) { marginOverflow = 1; } if (!int.TryParse(Setting.GetAttribute("textPosition"), out textPosition) || textPosition < 1 || textPosition > 9) { textPosition = 5; } if (!int.TryParse(Setting.GetAttribute("textAlign"), out textAlign) || textAlign < 1 || textAlign > 3) { textAlign = 2; } if ((fontFamily = Setting.GetAttribute("fontFamily")) == null) { fontFamily = "Malgun Gothic"; } if (Setting.GetAttribute("fontWeight").Equals("bold")) { fontWeightBold = true; } if (Setting.GetAttribute("fontStyle").Equals("italic")) { fontStyleItalic = true; } if (!decimal.TryParse(Setting.GetAttribute("fontSize"), out fontSize) || fontSize <= 0) { fontSize = 8.75m; } try { string tempTitleColor = Setting.GetAttribute("titleColor"); if (tempTitleColor == null) { titleColor = 0xffff00; } else { titleColor = MiscConverter.StringToIntColor(tempTitleColor); } } catch (Exception ex) { // invalid color format Console.WriteLine(ex.Message); titleColor = 0xffff00; } if (!decimal.TryParse(Setting.GetAttribute("lineHeight"), out lineHeight) || lineHeight < 0) { lineHeight = 140; } if (!bool.TryParse(Setting.GetAttribute("screenRatioSimulation"), out screenRatioSimulation)) { screenRatioSimulation = false; } if (!int.TryParse(Setting.GetAttribute("screenRatioSimulationWidth"), out screenRatioSimulationWidth) || screenRatioSimulationWidth <= 0) { screenRatioSimulationWidth = 4; } if (!int.TryParse(Setting.GetAttribute("screenRatioSimulationHeight"), out screenRatioSimulationHeight) || screenRatioSimulationHeight <= 0) { screenRatioSimulationHeight = 3; } }
// Get and apply settings from Setting class to SettingWindow controls private void SettingToControl() { System.Windows.Forms.Screen[] sc = System.Windows.Forms.Screen.AllScreens; int numOfScreen = sc.Length; double fullWidth = 0, fullHeight = 0, offsetX = 0, offsetY = 0; double dpiX = PresentationSource.FromVisual(Application.Current.MainWindow).CompositionTarget.TransformToDevice.M11; double dpiY = PresentationSource.FromVisual(Application.Current.MainWindow).CompositionTarget.TransformToDevice.M22; double threshold = 6.25; // 500 / 80 = 6.25 double multiplyFactor = 1.0; List <ScreenRect> actualScreenRectList = new List <ScreenRect>(numOfScreen); GetSettings(); // for drawing screen map // get full size of all of the monitors // and get x, y offsets for negative positions for (int i = 0; i < numOfScreen; i++) { System.Drawing.Rectangle r = sc[i].Bounds; if (sc[i].Primary) { if (offsetX > r.X) { offsetX = r.X; } if (offsetY > r.Y) { offsetY = r.Y; } if (fullWidth < r.Width) { fullWidth = r.X + r.Width; } if (fullHeight < r.Height) { fullHeight = r.Y + r.Height; } actualScreenRectList.Add(new ScreenRect(r.X, r.Y, r.Width, r.Height)); } else { double ithX = r.X / dpiX; double ithY = r.Y / dpiY; double ithWidth = r.Width / dpiX; double ithHeight = r.Height / dpiY; double ithFullWidth = ithX + ithWidth; double ithFullHeight = ithY + ithHeight; if (offsetX > ithX) { offsetX = ithX; } if (offsetY > ithY) { offsetY = ithY; } if (fullWidth < ithFullWidth) { fullWidth = ithFullWidth; } if (fullHeight < ithFullHeight) { fullHeight = ithFullHeight; } actualScreenRectList.Add(new ScreenRect(ithX, ithY, ithWidth, ithHeight)); } } offsetX *= -1; offsetY *= -1; fullWidth += offsetX; fullHeight += offsetY; // calculate multiply factor if (fullWidth / fullHeight <= threshold) { multiplyFactor = 80.0 / fullHeight; } else { multiplyFactor = 500.0 / fullWidth; } // construct screen combo box and draw screen map ComboBoxPresenterScreen.Items.Clear(); CanvasScreens.Children.Clear(); for (int i = 0; i < numOfScreen; i++) { System.Drawing.Rectangle r = sc[i].Bounds; double ithWidth = actualScreenRectList[i].width; double ithHeight = actualScreenRectList[i].height; double ithX = actualScreenRectList[i].x; double ithY = actualScreenRectList[i].y; // combo box item ComboBoxItem cbi = new ComboBoxItem { Content = "(" + (i + 1).ToString() + ") " + sc[i].DeviceName + ": " + ithWidth.ToString() + "×" + ithHeight.ToString() + " (" + ithX.ToString() + "," + ithY.ToString() + ")" }; ComboBoxPresenterScreen.Items.Add(cbi); // screen map item as button Style screenBorderStyle = FindResource("ScreenBorder") as Style; System.Windows.Controls.Primitives.ToggleButton btn = new System.Windows.Controls.Primitives.ToggleButton { Style = screenBorderStyle, Content = (i + 1).ToString(), Width = ithWidth * multiplyFactor, Height = ithHeight * multiplyFactor, Tag = i, }; btn.Click += ScreenBorder_Click; Canvas.SetLeft(btn, 5 + (ithX + offsetX) * multiplyFactor); Canvas.SetTop(btn, 5 + (ithY + offsetY) * multiplyFactor); CanvasScreens.Children.Add(btn); } if (presenterScreen <= numOfScreen) { ComboBoxPresenterScreen.SelectedIndex = presenterScreen - 1; } else { ComboBoxPresenterScreen.SelectedIndex = numOfScreen - 1; } (CanvasScreens.Children[ComboBoxPresenterScreen.SelectedIndex] as System.Windows.Controls.Primitives.ToggleButton).IsChecked = true; // textEncoding = ComboBoxTextEncoding.SelectedIndex; switch (textEncoding) { case 1200: // UTF-16 LE ComboBoxTextEncoding.SelectedIndex = 2; break; case 1201: // UTF-16 BE ComboBoxTextEncoding.SelectedIndex = 3; break; case 65001: // UTF-8 ComboBoxTextEncoding.SelectedIndex = 1; break; default: ComboBoxTextEncoding.SelectedIndex = 0; break; } switch (textPosition) { case 1: RadioButtonTextPosition1.IsChecked = true; break; case 2: RadioButtonTextPosition2.IsChecked = true; break; case 3: RadioButtonTextPosition3.IsChecked = true; break; case 4: RadioButtonTextPosition4.IsChecked = true; break; case 5: RadioButtonTextPosition5.IsChecked = true; break; case 6: RadioButtonTextPosition6.IsChecked = true; break; case 7: RadioButtonTextPosition7.IsChecked = true; break; case 8: RadioButtonTextPosition8.IsChecked = true; break; case 9: RadioButtonTextPosition9.IsChecked = true; break; } CheckBoxScreenRatioSimulation.IsChecked = screenRatioSimulation; TextBoxScreenWidth.Text = screenRatioSimulationWidth.ToString(); TextBoxScreenHeight.Text = screenRatioSimulationHeight.ToString(); ComboBoxTextAlign.SelectedIndex = textAlign - 1; UpdateButtonChangeFont(); TextBoxFontSize.Text = fontSize.ToString(); TextBoxTitleColor.Text = titleColor.ToString("X6"); RectangleTitleColor.Fill = MiscConverter.IntToSolidColorBrush(titleColor); TextBoxLineHeight.Text = lineHeight.ToString(); TextBoxMarginBasic.Text = marginBasic.ToString(); TextBoxMarginOverflow.Text = marginOverflow.ToString(); }