From d17a8b69d4ea58d4787c40cbe446ad033e43ec4f Mon Sep 17 00:00:00 2001 From: Curtis Wensley Date: Sat, 30 Jan 2021 11:47:56 -0800 Subject: [PATCH] Allow user to set both width and height of canvas - update server version --- .../Formats/Character/Actions/SetWidth.cs | 22 +-- .../Formats/Character/Controls/WidthDialog.cs | 131 ++++++++++-------- Source/Pablo/Network/Server.cs | 2 +- 3 files changed, 84 insertions(+), 71 deletions(-) diff --git a/Source/Pablo/Formats/Character/Actions/SetWidth.cs b/Source/Pablo/Formats/Character/Actions/SetWidth.cs index f4eace2..cac33dc 100644 --- a/Source/Pablo/Formats/Character/Actions/SetWidth.cs +++ b/Source/Pablo/Formats/Character/Actions/SetWidth.cs @@ -13,9 +13,9 @@ public class SetWidth : PabloCommand public SetWidth (CharacterHandler handler) : base(handler) { ID = ActionID; - MenuText = "Set Canvas &Width..."; - ToolBarText = "Set Width"; - ToolTip = "Sets the canvas width"; + MenuText = "Set Canvas &Size..."; + ToolBarText = "Set Size"; + ToolTip = "Sets the canvas size"; Image = ImageCache.IconFromResource("Pablo.Icons.setwidth.ico"); } @@ -30,18 +30,18 @@ protected override void Execute (CommandExecuteArgs args) CharacterHandler handler = base.Handler as CharacterHandler; var size = handler.CurrentPage.Canvas.Size; var dialog = new WidthDialog (); - dialog.Width = size.Width; + dialog.CanvasSize = size; var result = dialog.ShowModal (handler.Viewer as Control); if (result == DialogResult.Ok) { - DoResize (dialog.Width); + DoResize (dialog.CanvasSize); } } - void DoResize(int width) + void DoResize(Size canvasSize) { CharacterHandler handler = base.Handler as CharacterHandler; var size = handler.CurrentPage.Canvas.Size; - size.Width = width; + size = canvasSize; handler.CurrentPage.Canvas.ResizeCanvas (size, true, true); var pos = handler.CursorPosition; @@ -57,10 +57,10 @@ public override bool Send (SendCommandArgs args) CharacterHandler handler = base.Handler as CharacterHandler; var size = handler.CurrentPage.Canvas.Size; var dialog = new WidthDialog (); - dialog.Width = size.Width; + dialog.CanvasSize = size; var result = dialog.ShowModal(handler.Viewer as Control); if (result == DialogResult.Ok) { - args.Message.WriteVariableInt32 (dialog.Width); + args.Message.Write (dialog.CanvasSize); return true; } else @@ -70,8 +70,8 @@ public override bool Send (SendCommandArgs args) public override void Receive (ReceiveCommandArgs args) { base.Receive (args); - int width = args.Message.ReadVariableInt32 (); - DoResize (width); + var size = args.Message.ReadSize (); + DoResize (size); } } } diff --git a/Source/Pablo/Formats/Character/Controls/WidthDialog.cs b/Source/Pablo/Formats/Character/Controls/WidthDialog.cs index 325cb07..5d03868 100644 --- a/Source/Pablo/Formats/Character/Controls/WidthDialog.cs +++ b/Source/Pablo/Formats/Character/Controls/WidthDialog.cs @@ -6,94 +6,107 @@ namespace Pablo.Formats.Character.Controls { public class WidthDialog : Dialog { - int width; - TextBox widthControl; - - Control WidthControl () + NumericStepper widthControl; + NumericStepper heightControl; + + Control WidthControl() { - widthControl = new TextBox (); - widthControl.TextChanged += delegate { - int.TryParse (widthControl.Text, out width); - }; + widthControl = new NumericStepper { MinValue = 1, MaxValue = 5000 }; return widthControl; } - - Control OkButton () + + Control HeightControl() + { + heightControl = new NumericStepper { MinValue = 1, MaxValue = 10000 }; + return heightControl; + } + + Control OkButton() { - var control = new Button{ + var control = new Button + { Text = "Ok" }; - control.Click += delegate { - if (int.TryParse (widthControl.Text, out width)) { - if (width > 0 && width <= 5000) { - Result = DialogResult.Ok; - Close (); - } else { - MessageBox.Show(this, "Width must be a numeric value between 1 and 5000"); - } - } + control.Click += delegate + { + Result = DialogResult.Ok; + Close(); }; this.DefaultButton = control; return control; } - - Control CancelButton () + + Control CancelButton() { - var control = new Button{ + var control = new Button + { Text = "Cancel" }; - control.Click += delegate { + control.Click += delegate + { Result = DialogResult.Cancel; - Close (); + Close(); }; base.AbortButton = control; return control; } - - Control Buttons () + + Control Buttons() { - var layout = new TableLayout (3, 1); - layout.Padding = Padding.Empty; - - layout.SetColumnScale (0); - - layout.Add (CancelButton (), 1, 0); - layout.Add (OkButton (), 2, 0); + var layout = new TableLayout(3, 1); + layout.Spacing = new Size(5, 5); + + layout.SetColumnScale(0); + + layout.Add(CancelButton(), 1, 0); + layout.Add(OkButton(), 2, 0); return layout; } - - public int Width { - get { return width; } - set { - width = value; - widthControl.Text = width.ToString (); + + public Size CanvasSize + { + get { return new Size((int)widthControl.Value, (int)heightControl.Value); } + set + { + widthControl.Value = value.Width; + heightControl.Value = value.Height; } } - - Control WidthRow () + + Control WidthRow() { - var layout = new TableLayout (2, 2); + var layout = new DynamicLayout(); layout.Padding = new Padding(20, 10, 20, 0); - - layout.Add (new Label{ Text = "Canvas Width", VerticalAlign = VerticalAlign.Middle }, 0, 0); - layout.Add (WidthControl (), 1, 0, true, false); + + layout.BeginHorizontal(); + layout.AddSpace(); + layout.Add(new Label { Text = "Canvas Size", VerticalAlignment = VerticalAlignment.Center }); + layout.Add(WidthControl()); + layout.Add(HeightControl()); + layout.AddSpace(); + + layout.EndHorizontal(); + return layout; } - - public WidthDialog () + + public WidthDialog() { //this.ClientSize = new Size (350, 160); - - var toplayout = new TableLayout (1, 3); - toplayout.Padding = new Padding (10); - - toplayout.Add (new Label{ - Text = "Set the width of the canvas.\nNote that ANSI and ASCII are usually maximum 80 columns,\nand BIN (Binary) files are usually 160 characters.\nAnything larger that 500 wide may cause PabloDraw to become slow or unresponsive.", - VerticalAlign = VerticalAlign.Middle, - HorizontalAlign = HorizontalAlign.Center - }, 0, 0, true, true); - toplayout.Add (WidthRow (), 0, 1); - toplayout.Add (Buttons (), 0, 2); + + var toplayout = new DynamicLayout(); + toplayout.Padding = new Padding(10); + toplayout.Spacing = new Size(5, 5); + + toplayout.Add(new Label + { + Text = "Set the size of the canvas.\nNote that ANSI and ASCII are usually maximum 80 columns,\nand BIN (Binary) files are usually 160 characters.\nAnything larger that 500 wide may cause PabloDraw to become slow or unresponsive.", + Wrap = WrapMode.Word, + VerticalAlignment = VerticalAlignment.Center, + TextAlignment = TextAlignment.Center + }, yscale: true); + toplayout.Add(WidthRow()); + toplayout.Add(Buttons()); Content = toplayout; } diff --git a/Source/Pablo/Network/Server.cs b/Source/Pablo/Network/Server.cs index 4483b7a..53a444d 100644 --- a/Source/Pablo/Network/Server.cs +++ b/Source/Pablo/Network/Server.cs @@ -15,7 +15,7 @@ namespace Pablo.Network { public class Server : Network { - public const int VERSION = 7; + public const int VERSION = 8; bool mappedPort; NetServer server; static INatDevice natdevice;