private void Window_Loaded(object sender, RoutedEventArgs e) { const double WIDTH = 45; const double HEIGHT = 30; try { trkDarkness_ValueChanged(this, null); chkOverlay1_Checked(this, null); chkOverlay2_Checked(this, null); #region Back Buttons foreach (FlagBackType backType in Enum.GetValues(typeof(FlagBackType))) { FlagProps props = new FlagProps() { BackType = backType, Back1 = "FFF", Back2 = "000", Back3 = "888", }; panelBacks.Children.Add(GetFlagButton(props, WIDTH, HEIGHT, backType)); } #endregion #region Overlay Buttons foreach (FlagOverlayType overlayType in Enum.GetValues(typeof(FlagOverlayType))) { FlagProps props = new FlagProps() { BackType = FlagBackType.Solid, Back1 = "FFF", Overlay1 = new FlagOverlay() { Type = overlayType, Color = "000", }, }; panelOverlays1.Children.Add(GetFlagButton(props, WIDTH, HEIGHT, overlayType)); panelOverlays2.Children.Add(GetFlagButton(props, WIDTH, HEIGHT, overlayType)); } #endregion panelBacks.Children[0].Effect = _selectEffect; panelOverlays1.Children[0].Effect = _selectEffect; panelOverlays2.Children[0].Effect = _selectEffect; RedrawFlag(); } catch (Exception ex) { MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error); } }
public static FlagProps GetRandomFlag() { var enums = GetRandomEnums(); var colors = GetRandomColors(); FlagProps retVal = new FlagProps() { BackType = enums.Item1, Back1 = colors[0].ToRGB().ToHex(false, false), Back2 = colors[1].ToRGB().ToHex(false, false), Back3 = colors[2].ToRGB().ToHex(false, false), }; if (enums.Item2 != null) { retVal.Overlay1 = new FlagOverlay() { Type = enums.Item2.Value, Color = colors[3].ToRGB().ToHex(false, false), }; } if (enums.Item3 != null) { retVal.Overlay2 = new FlagOverlay() { Type = enums.Item3.Value, Color = colors[4].ToRGB().ToHex(false, false), }; } return(retVal); }
public FlagVisual(double width, double height, FlagProps props) { this.FlagProps = props; _visual = new DrawingVisual(); using (DrawingContext dc = _visual.RenderOpen()) { Size size = new Size(width, height); DrawBackground(dc, size, props); if (props.Overlay1 != null) { DrawOverlay(dc, size, props.Overlay1); } if (props.Overlay2 != null) { DrawOverlay(dc, size, props.Overlay2); } } }
private static UIElement GetFlagButton(FlagProps props, double width, double height, Enum enumValue) { //NOTE: I couldn't get mouse events to fire. Finally, I put a transparent rectangle over the flag visual, and that works Grid retVal = new Grid() { Margin = new Thickness(3) }; retVal.Children.Add(new FlagVisual(width, height, props)); retVal.Children.Add(new Rectangle() { Width = width, Height = height, Fill = Brushes.Transparent, ToolTip = enumValue.ToString(), Tag = enumValue }); // store it in the tag to make things easier return retVal; }
private void RedrawFlag() { canvasDebug.Children.Clear(); canvasSmall.Children.Clear(); canvasMed.Children.Clear(); canvasLarge.Children.Clear(); lblError.Text = ""; lblError.Visibility = Visibility.Collapsed; try { FlagProps props = new FlagProps() { BackType = _backType, Back1 = txtBack1.Text, Back2 = txtBack2.Text, Back3 = txtBack3.Text, }; if (chkOverlay1.IsChecked.Value) { props.Overlay1 = new FlagOverlay() { Type = _overlayType1, Color = txtOverlay1.Text, }; } if (chkOverlay2.IsChecked.Value) { props.Overlay2 = new FlagOverlay() { Type = _overlayType2, Color = txtOverlay2.Text, }; } canvasSmall.Children.Add(new FlagVisual(canvasSmall.ActualWidth, canvasSmall.Height, props)); canvasMed.Children.Add(new FlagVisual(canvasMed.ActualWidth, canvasMed.Height, props)); canvasLarge.Children.Add(new FlagVisual(canvasLarge.ActualWidth, canvasLarge.Height, props)); } catch (Exception ex) { lblError.Text = ex.Message; lblError.Visibility = Visibility.Visible; } }
private static void DrawBackground(DrawingContext dc, Size size, FlagProps props) { double halfWidth = size.Width / 2d; double halfHeight = size.Height / 2d; Geometry geometry; switch (props.BackType) { case FlagBackType.Solid: #region Solid dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back1)), null, new Rect(size)); #endregion break; case FlagBackType.Horizontal_Two: #region Horizontal_Two dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back1)), null, new Rect(0, 0, size.Width, halfHeight)); dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back2)), null, new Rect(0, halfHeight, size.Width, halfHeight)); #endregion break; case FlagBackType.Horizontal_Three: #region Horizontal_Three double thirdHeight = size.Height / 3d; dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back1)), null, new Rect(0, 0, size.Width, thirdHeight)); dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back2)), null, new Rect(0, thirdHeight, size.Width, thirdHeight)); dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back3)), null, new Rect(0, thirdHeight * 2, size.Width, thirdHeight)); #endregion break; case FlagBackType.Horizontal_Three_Thin: #region Horizontal_Three_Thin double midHeight1 = size.Height * .17; double topBottHeight1 = (size.Height - midHeight1) / 2; dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back1)), null, new Rect(0, 0, size.Width, topBottHeight1)); dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back2)), null, new Rect(0, topBottHeight1, size.Width, midHeight1)); dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back3)), null, new Rect(0, topBottHeight1 + midHeight1, size.Width, topBottHeight1)); #endregion break; case FlagBackType.Horizontal_Three_Thick: #region Horizontal_Three_Thick double midHeight2 = size.Height * .55; double topBottHeight2 = (size.Height - midHeight2) / 2; dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back1)), null, new Rect(0, 0, size.Width, topBottHeight2)); dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back2)), null, new Rect(0, topBottHeight2, size.Width, midHeight2)); dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back3)), null, new Rect(0, topBottHeight2 + midHeight2, size.Width, topBottHeight2)); #endregion break; case FlagBackType.Vertical_Two: #region Vertical_Two dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back1)), null, new Rect(0, 0, halfWidth, size.Height)); dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back2)), null, new Rect(halfWidth, 0, halfWidth, size.Height)); #endregion break; case FlagBackType.Vertical_Three: #region Vertical_Three double thirdWidth = size.Width / 3d; dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back1)), null, new Rect(0, 0, thirdWidth, size.Height)); dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back2)), null, new Rect(thirdWidth, 0, thirdWidth, size.Height)); dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back3)), null, new Rect(thirdWidth * 2, 0, thirdWidth, size.Height)); #endregion break; case FlagBackType.Diagonal_Down: #region Diagonal_Down geometry = GetClosedGeometry(new[] { new Point(0, 0), new Point(size.Width, size.Height), new Point(0, size.Height), }); dc.DrawGeometry(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back1)), null, geometry); geometry = GetClosedGeometry(new[] { new Point(0, 0), new Point(size.Width, 0), new Point(size.Width, size.Height), }); dc.DrawGeometry(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back2)), null, geometry); #endregion break; case FlagBackType.Diagonal_Up: #region Diagonal_Up geometry = GetClosedGeometry(new[] { new Point(0, 0), new Point(size.Width, 0), new Point(0, size.Height), }); dc.DrawGeometry(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back1)), null, geometry); geometry = GetClosedGeometry(new[] { new Point(size.Width, size.Height), new Point(0, size.Height), new Point(size.Width, 0), }); dc.DrawGeometry(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back2)), null, geometry); #endregion break; case FlagBackType.FourSquare: #region FourSquare dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back1)), null, new Rect(0, 0, halfWidth, halfHeight)); // top left dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back1)), null, new Rect(halfWidth, halfHeight, halfWidth, halfHeight)); // bottom right dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back2)), null, new Rect(halfWidth, 0, halfWidth, halfHeight)); // top right dc.DrawRectangle(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back2)), null, new Rect(0, halfHeight, halfWidth, halfHeight)); // bottom left #endregion break; case FlagBackType.FourTriangle: #region FourTriangle // Top geometry = GetClosedGeometry(new[] { new Point(0, 0), new Point(size.Width, 0), new Point(halfWidth, halfHeight), }); dc.DrawGeometry(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back1)), null, geometry); // Bottom geometry = GetClosedGeometry(new[] { new Point(0, size.Height), new Point(size.Width, size.Height), new Point(halfWidth, halfHeight), }); dc.DrawGeometry(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back1)), null, geometry); // Left geometry = GetClosedGeometry(new[] { new Point(0, 0), new Point(halfWidth, halfHeight), new Point(0, size.Height), }); dc.DrawGeometry(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back2)), null, geometry); // Right geometry = GetClosedGeometry(new[] { new Point(size.Width, 0), new Point(size.Width, size.Height), new Point(halfWidth, halfHeight), }); dc.DrawGeometry(new SolidColorBrush(UtilityWPF.ColorFromHex(props.Back2)), null, geometry); // It's nice not needing to worry about the normal :) #endregion break; default: throw new ApplicationException("Unknown FlagBackType: " + props.BackType.ToString()); } }
public static FlagProps GetRandomFlag() { var enums = GetRandomEnums(); var colors = GetRandomColors(); FlagProps retVal = new FlagProps() { BackType = enums.Item1, Back1 = colors[0].ToRGB().ToHex(false, false), Back2 = colors[1].ToRGB().ToHex(false, false), Back3 = colors[2].ToRGB().ToHex(false, false), }; if (enums.Item2 != null) { retVal.Overlay1 = new FlagOverlay() { Type = enums.Item2.Value, Color = colors[3].ToRGB().ToHex(false, false), }; } if (enums.Item3 != null) { retVal.Overlay2 = new FlagOverlay() { Type = enums.Item3.Value, Color = colors[4].ToRGB().ToHex(false, false), }; } return retVal; }
private SpaceStation2D CreateSpaceStations_Build(Point3D position, FlagProps flag = null, int? purchasedVolume = null, Inventory[] playerInventory = null) { Vector3D axis = new Vector3D(0, 0, 1); Quaternion rotation = Math3D.GetRotation(axis, Math3D.GetRandomVector_Cone(axis, 30)); SpaceStation2D retVal = new SpaceStation2D(position, _world, _material_SpaceStation, rotation, flag); retVal.SpinDegreesPerSecond = Math1D.GetNearZeroValue(.33, 1.1); retVal.RandomizeInventory(true); if (purchasedVolume != null && purchasedVolume.Value > retVal.PurchasedVolume) { retVal.PurchasedVolume = purchasedVolume.Value; } if (playerInventory != null) { retVal.PlayerInventory.AddRange(playerInventory); } _map.AddItem(retVal); return retVal; }