private void AddRetreatBox() { // Calculations taken directly from Direct2DRenderer.cs double box_left = visualCustomize.ActualWidth / 32 * 23 - Direct2DRenderer.size_scale * visualCustomize.ActualWidth / 32 * 2 * Direct2DRenderer.size_scale; double box_top = visualCustomize.ActualHeight / 32 * 24 - visualCustomize.ActualHeight / 32 * 3 * Direct2DRenderer.size_scale; double box_right = box_left + visualCustomize.ActualWidth / 32 * 10 * Direct2DRenderer.size_scale; double box_bottom = box_top + visualCustomize.ActualHeight / 32 * 6 * Direct2DRenderer.size_scale; retreatBox = new OverlayBox { Width = box_right - box_left, MinWidth = 1, Height = box_bottom - box_top, MinHeight = 1, }; double retreatBoxX = box_left; double retreatBoxY = box_top; visualCustomize.AddBox( retreatBox, (int)Math.Round(retreatBoxX), (int)Math.Round(retreatBoxY)); retreatBox.Visibility = Visibility.Hidden; }
private void AddHealthGraphsBox() { // Calculations taken directly from Direct2DRenderer.cs double start_x = 0; double end_x = 250 / visualCustomize.ScreenWidth * visualCustomize.ActualWidth; double end_y = visualCustomize.ActualHeight / 2 + (-108 + 28) / visualCustomize.ScreenHeight * visualCustomize.ActualHeight; double start_y = visualCustomize.ActualHeight / 4; healthGraphsBox = new OverlayBox { Width = end_x - start_x, MinWidth = 1, Height = end_y - start_y, MinHeight = 1, }; double healthGraphsBoxX = start_x; double healthGraphsBoxY = start_y; visualCustomize.AddBox( healthGraphsBox, (int)Math.Round(healthGraphsBoxX), (int)Math.Round(healthGraphsBoxY)); healthGraphsBox.Visibility = Visibility.Hidden; }
private void AddHighlightBarBox() { // Calculations taken directly from Direct2DRenderer.cs double xInit = visualCustomize.ActualWidth / 4; double xEnd = 3 * visualCustomize.ActualWidth / 4; double positionY = 3 * visualCustomize.ActualHeight / 4; highlightBarBox = new OverlayBox { Width = xEnd - xInit, MinWidth = 1, Height = 2, MinHeight = 2, MaxHeight = 2, Name = "HighlightBarBox" }; double highlightBarBoxX = xInit; double highlightBarBoxY = positionY; visualCustomize.AddBox( highlightBarBox, (int)Math.Round(highlightBarBoxX), (int)Math.Round(highlightBarBoxY)); highlightBarBox.Visibility = Visibility.Hidden; }
private void AddHeroSelectionBox() { // Calculations taken directly from Direct2DRenderer.cs double box_left = (visualCustomize.ActualWidth / 32) * 24 - Direct2DRenderer.size_scale * (visualCustomize.ActualWidth / 32) * 3 - visualCustomize.ActualWidth / 32; double box_top = (visualCustomize.ActualHeight / 32) * 3 * 2 - (visualCustomize.ActualHeight / 32) * 4; double box_right = box_left + (visualCustomize.ActualWidth / 32) * 10; double box_bottom = box_top + (visualCustomize.ActualHeight / 32) * 24; heroSelectionBox = new OverlayBox { Width = box_right - box_left, MinWidth = 1, Height = box_bottom - box_top, MinHeight = 1, }; double heroSelectionBoxX = box_left; double heroSelectionBoxY = box_top; visualCustomize.AddBox( heroSelectionBox, (int)Math.Round(heroSelectionBoxX), (int)Math.Round(heroSelectionBoxY)); heroSelectionBox.Visibility = Visibility.Hidden; }
private void AddInitialInstructionsBox() { // Calculations taken directly from Direct2DRenderer.cs double box_left = visualCustomize.ActualWidth / 32 * 20 - Direct2DRenderer.size_scale * visualCustomize.ActualWidth / 32 * 3 + visualCustomize.ActualWidth / 32 * 2 * Direct2DRenderer.size_scale; double box_top = visualCustomize.ActualHeight / 32 * 6 - visualCustomize.ActualHeight / 32 * 4 * Direct2DRenderer.size_scale; double box_right = box_left + visualCustomize.ActualWidth / 32 * 12 * Direct2DRenderer.size_scale; double box_bottom = box_top + visualCustomize.ActualHeight / 32 * 12 * Direct2DRenderer.size_scale; initialInstructionsBox = new OverlayBox { Width = box_right - box_left, MinWidth = 1, Height = box_bottom - box_top, MinHeight = 1, }; double initialInstructionsBoxX = box_left; double initialInstructionsBoxY = box_top; visualCustomize.AddBox( initialInstructionsBox, (int)Math.Round(initialInstructionsBoxX), (int)Math.Round(initialInstructionsBoxY)); initialInstructionsBox.Visibility = Visibility.Visible; }
protected void SetBoxWidth(OverlayBox box, double width) { Application.Current.Dispatcher.Invoke( () => { box.Width = width * visualCustomize.ActualWidth / visualCustomize.ScreenWidth; } ); }
protected void SetBoxPosition(OverlayBox box, double posX, double posY) { Application.Current.Dispatcher.Invoke( () => { Canvas.SetLeft(box, posX * visualCustomize.ActualWidth / visualCustomize.ScreenWidth); Canvas.SetTop(box, posY * visualCustomize.ActualHeight / visualCustomize.ScreenHeight); } ); }
protected void GetBoxWidth(OverlayBox box, out double width) { double w = 0; Application.Current.Dispatcher.Invoke( () => { w = box.Width / visualCustomize.ActualWidth * visualCustomize.ScreenWidth; }); width = w; }
private void Box_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) { OverlayBox box = sender as OverlayBox; if (box.IsOverlayVisible) { box.IsOverlayVisible = false; } else { box.IsOverlayVisible = true; } }
protected void GetBoxPosition(OverlayBox box, out double positionX, out double positionY) { double posX = 0; double posY = 0; Application.Current.Dispatcher.Invoke( () => { posX = Canvas.GetLeft(box) / visualCustomize.ActualWidth * visualCustomize.ScreenWidth; posY = Canvas.GetTop(box) / visualCustomize.ActualHeight * visualCustomize.ScreenHeight; }); positionX = posX; positionY = posY; }
public void AddBox(OverlayBox box, int positionX, int positionY) { box.Template = FindResource("DesignerItemTemplate") as ControlTemplate; Rectangle rectangle = new Rectangle { Fill = new SolidColorBrush(Colors.Black), IsHitTestVisible = false }; box.Content = rectangle; box.MouseDoubleClick += Box_MouseDoubleClick; CustomizeCanvas.Children.Add(box); Canvas.SetLeft(box, positionX); Canvas.SetTop(box, positionY); }
protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) { double percentWidthChange = (sizeInfo.NewSize.Width - sizeInfo.PreviousSize.Width) / sizeInfo.PreviousSize.Width; double percentHeightChange = (sizeInfo.NewSize.Height - sizeInfo.PreviousSize.Height) / sizeInfo.PreviousSize.Height; double oldWidth = CustomizeCanvas.Width; double oldHeight = CustomizeCanvas.Height; if (ActualWidth * aspectRatio >= ActualHeight && Math.Abs(percentWidthChange) > Math.Abs(percentHeightChange)) { // Skip } else if (Math.Abs(percentWidthChange) > Math.Abs(percentHeightChange)) { if (WindowState == WindowState.Maximized) { oldWidth = CustomizeCanvas.Width; CustomizeCanvas.Height = ActualHeight; CustomizeCanvas.Width = ActualHeight / aspectRatio; percentWidthChange = (CustomizeCanvas.Width - oldWidth) / oldWidth; } else { CustomizeCanvas.Height = ActualWidth * aspectRatio; CustomizeCanvas.Width = ActualWidth; } foreach (var c in CustomizeCanvas.Children) { if (c.GetType() == typeof(OverlayBox)) { OverlayBox box = c as OverlayBox; double childAspectRatio = box.Height / box.Width; box.Width *= 1 + percentWidthChange; box.Height = box.Width * childAspectRatio; Canvas.SetLeft(box, Canvas.GetLeft(box) / oldWidth * CustomizeCanvas.Width); Canvas.SetTop(box, Canvas.GetTop(box) / oldHeight * CustomizeCanvas.Height); } } } else { CustomizeCanvas.Width = ActualHeight / aspectRatio; CustomizeCanvas.Height = ActualHeight; foreach (var c in CustomizeCanvas.Children) { if (c.GetType() == typeof(OverlayBox)) { OverlayBox box = c as OverlayBox; double childAspectRatio = box.Height / box.Width; box.Height *= 1 + percentHeightChange; box.Width = box.Height / childAspectRatio; Canvas.SetLeft(box, Canvas.GetLeft(box) / oldWidth * CustomizeCanvas.Width); Canvas.SetTop(box, Canvas.GetTop(box) / oldHeight * CustomizeCanvas.Height); } } } base.OnRenderSizeChanged(sizeInfo); }