Skip to content

Commit

Permalink
Allow user to set both width and height of canvas
Browse files Browse the repository at this point in the history
- update server version
  • Loading branch information
cwensley committed Jan 30, 2021
1 parent 358166f commit d17a8b6
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 71 deletions.
22 changes: 11 additions & 11 deletions Source/Pablo/Formats/Character/Actions/SetWidth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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);
}
}
}
Expand Down
131 changes: 72 additions & 59 deletions Source/Pablo/Formats/Character/Controls/WidthDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,94 +6,107 @@ namespace Pablo.Formats.Character.Controls
{
public class WidthDialog : Dialog<DialogResult>
{
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;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Pablo/Network/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d17a8b6

Please sign in to comment.