static void DrawFlags( Graphics gfx, Color color, float x, FlagDirection direction, ChordLayout chord, float length, float y_start, float slope, int flags_tied, int flags_free, NoteStemDirection stemdirection, NoteStemSide side, SheetMusicRenderSettings settings, int width, bool past2nd ) { var diff = stemdirection == NoteStemDirection.Down ? -1 : 1; var dir_scale = direction == FlagDirection.Left ? -1 : 1; var startX = x; // line / vpx -> px[y] / px[x] // multiply by (px/line) / (px/vpx) if (side == NoteStemSide.Left) { startX -= settings.NoteHeadRadius; } else if (side == NoteStemSide.Right) { startX += settings.NoteHeadRadius; } if (past2nd) { if (side == NoteStemSide.Left) { length += settings.NoteHeadRadius / width; } else if (side == NoteStemSide.Right) { length -= settings.NoteHeadRadius / width; } } if (flags_tied > 0) { for (int i = 0; i < flags_tied + flags_free; i++) { gfx.DrawLine( new Pen(color, 5.0f), startX, y_start + diff * i * settings.LinesBetweenFlags * settings.PixelsPerLine, x + length * dir_scale * width, y_start + diff * i * settings.LinesBetweenFlags * settings.PixelsPerLine + 0.5f * (slope * settings.PixelsPerLine) * ((startX - (x + length * dir_scale * width)) / width) ); if (i == flags_free && past2nd) { if (chord.LastLengthClass < chord.Length.Length) { length /= 2f; } } } } else if (flags_free > 0) { for (int i = 0; i < flags_free; i++) { gfx.DrawLine( new Pen(color, 5.0f), startX, y_start + diff * i * settings.LinesBetweenFlags * settings.PixelsPerLine, startX + diff * 15, y_start + diff * i * settings.LinesBetweenFlags * settings.PixelsPerLine + diff * 15 ); } } }
public TwoColorFlag(int scale, FlagDirection type) : base(scale, type) { }
private void DrawFlag(Point point, FlagDirection flagDirection) { var flagUp = false; if (flagDirection == FlagDirection.Up) { flagUp = true; } // add "flag" var flag = new Grid { HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = flagUp ? VerticalAlignment.Top : VerticalAlignment.Bottom, Margin = new Thickness(point.X - 0.3, point.Y, 0, 0), Height = 7, Children = { // flagpole new Border { Background = AssociatedObject.Foreground, Width = 0.6, HorizontalAlignment = HorizontalAlignment.Left, UseLayoutRounding = false }, // Actual flag new Border { Margin = new Thickness(0, 0, 0, -0.2), VerticalAlignment = flagUp ? VerticalAlignment.Bottom : VerticalAlignment.Top, RenderTransform = new ScaleTransform { ScaleY = -1.0 }, RenderTransformOrigin = new Point(0.5, 0.5), Background = AssociatedObject.Foreground, Child = new StackPanel{ Orientation = Orientation.Vertical, Children = { // flag content new TextBlock { Text = Convert.ToString(Math.Round(point.Y, 2)), FontSize = 2.5, Foreground = new SolidColorBrush(Colors.White), HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center, }, // flag label new TextBlock { Text = flagDirection == FlagDirection.Up ? FlagUpLabel : FlagDownLabel, FontSize = 1.5, Foreground = new SolidColorBrush(Colors.White), HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center, }, } }, }, } }; // add red point to highlight sparkline var flagPoint = new Path { Cursor = Cursors.Hand, Fill = new SolidColorBrush(Colors.Red), Stroke = new SolidColorBrush(Colors.White), StrokeThickness = 0.2, Data = new EllipseGeometry { Center = point, RadiusX = 0.5, RadiusY = 0.5 } }; // Fix up flag for pointing down ... var border = (Border)flag.Children[1]; var stackpanel = (StackPanel)border.Child; if (!flagUp) { flag.Margin = new Thickness(point.X - 0.2, 0, 0, _panel.Height - point.Y); border.Margin = new Thickness(0, -0.2, 0, 0); var children = stackpanel.Children; var label = children[1]; children.RemoveAt(1); children.Insert(0, label); } if (_flags.Count > 0) { _flags.Last().Visibility = Visibility.Collapsed; } _panel.Children.Add(flag); _panel.Children.Add(flagPoint); _flags.Add(flag); flagPoint.MouseLeftButtonDown += (s, e) => { foreach (var f in _flags.Where((ff, i) => i != _flags.Count - 1 && ff != flag)) // all flags but the last one and this one ... { f.Visibility = Visibility.Collapsed; } flag.Visibility = flag.Visibility == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible; if (flag.Visibility == Visibility.Visible) { #if SILVERLIGHT flag.SetValue(Canvas.ZIndexProperty, _panel.Children.Count); flagPoint.SetValue(Canvas.ZIndexProperty, _panel.Children.Count + 1); #else Panel.SetZIndex(flag, _panel.Children.Count); Panel.SetZIndex(flagPoint, _panel.Children.Count + 1); #endif } e.Handled = true; }; }
public Flag(int scale, FlagDirection type = FlagDirection.None) { this.Height = scale; this.Type = type; }
private static void Start() { bool run = true; while (run) { Flag flag; FlagType flagType = (FlagType)Menu.ShowMenu("What kind of flag would you like to create?", Enum.GetNames(typeof(FlagType))); Console.Clear(); FlagDirection direction = FlagDirection.None; if (flagType != FlagType.Cross) { direction = (FlagDirection)Menu.ShowMenu("What direction should the flag be?", new string[] { "Horizontal", "Vertical" }); } Console.Clear(); Console.WriteLine("Input flag size (ie 9 will be 9 rows & 9 * 2 columns)"); int size; while (!(int.TryParse(Console.ReadLine(), out size))) { Console.WriteLine("Invalid input, try again!"); } Console.Clear(); ConsoleColor[] colors = new ConsoleColor[0]; switch (flagType) { case FlagType.TriColor: colors = AskForColors(3); flag = new TriColorFlag(size, direction); flag.SetColors(colors); flag.DrawFlag(); break; case FlagType.TwoColor: colors = AskForColors(2); flag = new TwoColorFlag(size, direction); flag.SetColors(colors); flag.DrawFlag(); break; case FlagType.Cross: colors = AskForColors(2); flag = new CrossFlag(size); flag.SetColors(colors); flag.DrawFlag(); break; } Console.WriteLine(); Console.ResetColor(); int exit = Menu.ShowMenu("Do you want to draw another flag?", new string[] { "Yes", "No", }); run = exit == 0; Console.Clear(); } }