public AreaEditor(string unit, bool enableRotation = false) { this.DataContext = new AreaViewModel(); this.ContextMenu = new ContextMenu(); AreaDisplay = new AreaDisplay(unit) { Padding = new Padding(5) }; AreaDisplay.Bind(c => c.ViewModel.Width, ViewModel, m => m.Width); AreaDisplay.Bind(c => c.ViewModel.Height, ViewModel, m => m.Height); AreaDisplay.Bind(c => c.ViewModel.X, ViewModel, m => m.X); AreaDisplay.Bind(c => c.ViewModel.Y, ViewModel, m => m.Y); AreaDisplay.Bind(c => c.ViewModel.Rotation, ViewModel, m => m.Rotation); AreaDisplay.Bind(c => c.ViewModel.Background, ViewModel, m => m.Background); AreaDisplay.MouseDown += (sender, e) => BeginAreaDrag(e.Buttons); AreaDisplay.MouseUp += (sender, e) => EndAreaDrag(e.Buttons); widthBox = new TextBox { Width = 75, TextAlignment = TextAlignment.Right }; widthBox.TextBinding.Convert( s => ToFloat(s), v => $"{v}" ).BindDataContext(Eto.Forms.Binding.Property((AreaViewModel d) => d.Width)); heightBox = new TextBox { Width = 75, TextAlignment = TextAlignment.Right }; heightBox.TextBinding.Convert( s => ToFloat(s), v => $"{v}" ).BindDataContext(Eto.Forms.Binding.Property((AreaViewModel d) => d.Height)); xOffsetBox = new TextBox { Width = 75, TextAlignment = TextAlignment.Right }; xOffsetBox.TextBinding.Convert( s => ToFloat(s), v => $"{v}" ).BindDataContext(Eto.Forms.Binding.Property((AreaViewModel d) => d.X)); yOffsetBox = new TextBox { Width = 75, TextAlignment = TextAlignment.Right }; yOffsetBox.TextBinding.Convert( s => ToFloat(s), v => $"{v}" ).BindDataContext(Eto.Forms.Binding.Property((AreaViewModel d) => d.Y)); rotationBox = new TextBox { Width = 75, TextAlignment = TextAlignment.Right }; rotationBox.TextBinding.Convert( s => ToFloat(s), v => $"{v}" ).BindDataContext(Eto.Forms.Binding.Property((AreaViewModel d) => d.Rotation)); var stackLayout = new StackLayout { Orientation = Orientation.Horizontal, Spacing = 5, Items = { new Group { Text = "Width", Content = AppendUnit(widthBox, unit), ToolTip = $"Width of the area", Orientation = Orientation.Horizontal }, new Group { Text = "Height", Content = AppendUnit(heightBox, unit), ToolTip = $"Height of the area", Orientation = Orientation.Horizontal }, new Group { Text = "X Offset", Content = AppendUnit(xOffsetBox, unit), ToolTip = $"Center X coordinate of the area", Orientation = Orientation.Horizontal }, new Group { Text = "Y Offset", Content = AppendUnit(yOffsetBox, unit), ToolTip = $"Center Y coordinate of the area", Orientation = Orientation.Horizontal } } }; if (enableRotation) { stackLayout.Items.Add( new Group { Text = "Rotation", Content = AppendUnit(rotationBox, "°"), ToolTip = $"Rotation of the area about the center", Orientation = Orientation.Horizontal } ); } var scrollview = new Scrollable { Content = stackLayout, Border = BorderType.None }; Content = new StackLayout { Orientation = Orientation.Vertical, Items = { new StackLayoutItem(AreaDisplay, HorizontalAlignment.Stretch, true), new StackLayoutItem(scrollview, HorizontalAlignment.Center) } }; this.ContextMenu.Items.GetSubmenu("Align").Items.AddRange( new MenuItem[] { CreateMenuItem("Left", () => ViewModel.X = GetCenterOffset().X), CreateMenuItem("Right", () => ViewModel.X = ViewModel.FullBackground.Width - GetCenterOffset().X), CreateMenuItem("Top", () => ViewModel.Y = GetCenterOffset().Y), CreateMenuItem("Bottom", () => ViewModel.Y = ViewModel.FullBackground.Height - GetCenterOffset().Y), CreateMenuItem("Center", () => { ViewModel.X = ViewModel.FullBackground.Center.X; ViewModel.Y = ViewModel.FullBackground.Center.Y; } ) } ); this.ContextMenu.Items.GetSubmenu("Resize").Items.AddRange( new MenuItem[] { CreateMenuItem( "Full area", () => { ViewModel.Height = ViewModel.FullBackground.Height; ViewModel.Width = ViewModel.FullBackground.Width; ViewModel.Y = ViewModel.FullBackground.Center.Y; ViewModel.X = ViewModel.FullBackground.Center.X; } ), CreateMenuItem( "Quarter area", () => { ViewModel.Height = ViewModel.FullBackground.Height / 2; ViewModel.Width = ViewModel.FullBackground.Width / 2; } ) } ); this.ContextMenu.Items.GetSubmenu("Flip").Items.AddRange( new MenuItem[] { CreateMenuItem("Horizontal", () => ViewModel.X = ViewModel.FullBackground.Width - ViewModel.X), CreateMenuItem("Vertical", () => ViewModel.Y = ViewModel.FullBackground.Height - ViewModel.Y), } ); if (enableRotation) { this.ContextMenu.Items.GetSubmenu("Flip").Items.Add( CreateMenuItem("Handedness", () => { ViewModel.Rotation += 180; ViewModel.Rotation %= 360; ViewModel.X = ViewModel.FullBackground.Width - ViewModel.X; ViewModel.Y = ViewModel.FullBackground.Height - ViewModel.Y; } ) ); } AppendMenuItemSeparator(); this.MouseDown += (sender, e) => { if (e.Buttons.HasFlag(MouseButtons.Alternate)) { this.ContextMenu.Show(this); } }; }
public AreaEditor(string unit, bool enableRotation = false) { this.DataContext = new AreaViewModel(); this.ContextMenu = new ContextMenu(); areaDisplay = new AreaDisplay(unit) { Padding = new Padding(5) }; areaDisplay.Bind(c => c.ViewModel.Width, ViewModel, m => m.Width); areaDisplay.Bind(c => c.ViewModel.Height, ViewModel, m => m.Height); areaDisplay.Bind(c => c.ViewModel.X, ViewModel, m => m.X); areaDisplay.Bind(c => c.ViewModel.Y, ViewModel, m => m.Y); areaDisplay.Bind(c => c.ViewModel.Rotation, ViewModel, m => m.Rotation); areaDisplay.Bind(c => c.ViewModel.MaxWidth, ViewModel, m => m.MaxWidth); areaDisplay.Bind(c => c.ViewModel.MaxHeight, ViewModel, m => m.MaxHeight); widthBox = new TextBox(); widthBox.TextBinding.Convert( s => float.TryParse(s, out var v) ? v : 0, f => f.ToString()).BindDataContext( Binding.Property( (AreaViewModel d) => d.Width)); heightBox = new TextBox(); heightBox.TextBinding.Convert( s => float.TryParse(s, out var v) ? v : 0, f => f.ToString()).BindDataContext( Binding.Property( (AreaViewModel d) => d.Height)); xOffsetBox = new TextBox(); xOffsetBox.TextBinding.Convert( s => float.TryParse(s, out var v) ? v : 0, f => f.ToString()).BindDataContext( Binding.Property( (AreaViewModel d) => d.X)); yOffsetBox = new TextBox(); yOffsetBox.TextBinding.Convert( s => float.TryParse(s, out var v) ? v : 0, f => f.ToString()).BindDataContext( Binding.Property( (AreaViewModel d) => d.Y)); rotationBox = new TextBox(); rotationBox.TextBinding.Convert( s => float.TryParse(s, out var v) ? v : 0, f => f.ToString()).BindDataContext( Binding.Property( (AreaViewModel d) => d.Rotation)); var stackLayout = new StackLayout { Orientation = Orientation.Vertical, Spacing = 5, Items = { new GroupBox { Text = "Width", Content = AppendUnit(widthBox, unit) }, new GroupBox { Text = "Height", Content = AppendUnit(heightBox, unit) }, new GroupBox { Text = "X Offset", Content = AppendUnit(xOffsetBox, unit) }, new GroupBox { Text = "Y Offset", Content = AppendUnit(yOffsetBox, unit) }, new GroupBox { Text = "Rotation", Content = AppendUnit(rotationBox, "°"), Visible = enableRotation } } }; foreach (var item in stackLayout.Items) { if (item.Control is GroupBox groupBox) { groupBox.Padding = App.GroupBoxPadding; } } TableCell[] cells = { new TableCell(stackLayout), new TableCell(areaDisplay, true) }; Content = TableLayout.Horizontal(5, cells); this.ContextMenu.Items.GetSubmenu("Align").Items.AddRange( new MenuItem[] { CreateMenuItem("Left", () => ViewModel.X = ViewModel.Width / 2), CreateMenuItem("Right", () => ViewModel.X = ViewModel.MaxWidth - (ViewModel.Width / 2)), CreateMenuItem("Top", () => ViewModel.Y = ViewModel.Height / 2), CreateMenuItem("Bottom", () => ViewModel.Y = ViewModel.MaxHeight - (ViewModel.Height / 2)), CreateMenuItem("Center", () => { ViewModel.X = ViewModel.MaxWidth / 2; ViewModel.Y = ViewModel.MaxHeight / 2; } ) } ); this.ContextMenu.Items.GetSubmenu("Resize").Items.AddRange( new MenuItem[] { CreateMenuItem( "Full area", () => { ViewModel.Height = ViewModel.MaxHeight; ViewModel.Width = ViewModel.MaxWidth; ViewModel.Y = ViewModel.MaxHeight / 2; ViewModel.X = ViewModel.MaxWidth / 2; } ), CreateMenuItem( "Quarter area", () => { ViewModel.Height = ViewModel.MaxHeight / 2; ViewModel.Width = ViewModel.MaxWidth / 2; } ) } ); AppendMenuItemSeparator(); AppendCheckBoxMenuItem( "Lock to usable area", lockToMax => { if (lockToMax) { ViewModel.PropertyChanged += LimitArea; } else { ViewModel.PropertyChanged -= LimitArea; } }, defaultValue: true ); this.MouseDown += (sender, e) => { if (e.Buttons.HasFlag(MouseButtons.Alternate)) { this.ContextMenu.Show(this); } }; }
public AreaEditor(string unit, bool enableRotation = false) { this.DataContext = new AreaViewModel(); this.ContextMenu = new ContextMenu(); AreaDisplay = new AreaDisplay(unit) { Padding = new Padding(5) }; AreaDisplay.Bind(c => c.ViewModel.Width, ViewModel, m => m.Width); AreaDisplay.Bind(c => c.ViewModel.Height, ViewModel, m => m.Height); AreaDisplay.Bind(c => c.ViewModel.X, ViewModel, m => m.X); AreaDisplay.Bind(c => c.ViewModel.Y, ViewModel, m => m.Y); AreaDisplay.Bind(c => c.ViewModel.Rotation, ViewModel, m => m.Rotation); AreaDisplay.Bind(c => c.ViewModel.Background, ViewModel, m => m.Background); float parseFloat(string s) { return(!string.IsNullOrWhiteSpace(s) ? (float.TryParse(s, out var v) ? v : 1) : 0); } widthBox = new TextBox(); widthBox.TextBinding.Convert( s => parseFloat(s), v => $"{v}" ).BindDataContext(Eto.Forms.Binding.Property((AreaViewModel d) => d.Width)); heightBox = new TextBox(); heightBox.TextBinding.Convert( s => parseFloat(s), v => $"{v}" ).BindDataContext(Eto.Forms.Binding.Property((AreaViewModel d) => d.Height)); xOffsetBox = new TextBox(); xOffsetBox.TextBinding.Convert( s => parseFloat(s), v => $"{v}" ).BindDataContext(Eto.Forms.Binding.Property((AreaViewModel d) => d.X)); yOffsetBox = new TextBox(); yOffsetBox.TextBinding.Convert( s => parseFloat(s), v => $"{v}" ).BindDataContext(Eto.Forms.Binding.Property((AreaViewModel d) => d.Y)); rotationBox = new TextBox(); rotationBox.TextBinding.Convert( s => parseFloat(s), v => $"{v}" ).BindDataContext(Eto.Forms.Binding.Property((AreaViewModel d) => d.Rotation)); var stackLayout = new StackLayout { Orientation = Orientation.Horizontal, Spacing = 5, Items = { new GroupBox { Text = "Width", Content = AppendUnit(widthBox, unit), ToolTip = $"Width of the area" }, new GroupBox { Text = "Height", Content = AppendUnit(heightBox, unit), ToolTip = $"Height of the area" }, new GroupBox { Text = "X Offset", Content = AppendUnit(xOffsetBox, unit), ToolTip = $"Center X coordinate of the area" }, new GroupBox { Text = "Y Offset", Content = AppendUnit(yOffsetBox, unit), ToolTip = $"Center Y coordinate of the area" } } }; if (enableRotation) { stackLayout.Items.Add( new GroupBox { Text = "Rotation", Content = AppendUnit(rotationBox, "°"), ToolTip = $"Rotation of the area about the center" } ); } foreach (var item in stackLayout.Items) { if (item.Control is GroupBox groupBox) { groupBox.Padding = App.GroupBoxPadding; } } var scrollview = new Scrollable { Content = stackLayout, Border = BorderType.None }; Content = new StackLayout { Orientation = Orientation.Vertical, Items = { new StackLayoutItem(AreaDisplay, HorizontalAlignment.Stretch, true), new StackLayoutItem(scrollview, HorizontalAlignment.Center) } }; this.ContextMenu.Items.GetSubmenu("Align").Items.AddRange( new MenuItem[] { CreateMenuItem("Left", () => ViewModel.X = GetCenterOffset().X), CreateMenuItem("Right", () => ViewModel.X = ViewModel.FullBackground.Width - GetCenterOffset().X), CreateMenuItem("Top", () => ViewModel.Y = GetCenterOffset().Y), CreateMenuItem("Bottom", () => ViewModel.Y = ViewModel.FullBackground.Height - GetCenterOffset().Y), CreateMenuItem("Center", () => { ViewModel.X = ViewModel.FullBackground.Center.X; ViewModel.Y = ViewModel.FullBackground.Center.Y; } ) } ); this.ContextMenu.Items.GetSubmenu("Resize").Items.AddRange( new MenuItem[] { CreateMenuItem( "Full area", () => { ViewModel.Height = ViewModel.FullBackground.Height; ViewModel.Width = ViewModel.FullBackground.Width; ViewModel.Y = ViewModel.FullBackground.Center.Y; ViewModel.X = ViewModel.FullBackground.Center.X; } ), CreateMenuItem( "Quarter area", () => { ViewModel.Height = ViewModel.FullBackground.Height / 2; ViewModel.Width = ViewModel.FullBackground.Width / 2; } ) } ); AppendMenuItemSeparator(); AppendCheckBoxMenuItem( "Lock to usable area", lockToMax => { if (lockToMax) { ViewModel.PropertyChanged += LimitArea; } else { ViewModel.PropertyChanged -= LimitArea; } }, defaultValue: true ); this.MouseDown += (sender, e) => { if (e.Buttons.HasFlag(MouseButtons.Alternate)) { this.ContextMenu.Show(this); } }; }