From 3d143a01673f3e4f33cc27da83078ca2f9f2914e Mon Sep 17 00:00:00 2001 From: Dwayne Bent Date: Sun, 21 Jul 2013 18:06:20 -0400 Subject: [PATCH 1/3] Improve Monitor scaling Scaling is now done by scaling the texture rather than repeating pixels, and the user now has buttons to adjust the scaling in-game. --- Ketchup/Dcpu16Computer.cs | 26 ++++++++++++++++++++++---- Ketchup/Devices/Lem1802.cs | 21 +++++---------------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/Ketchup/Dcpu16Computer.cs b/Ketchup/Dcpu16Computer.cs index 6ed1132..03db266 100644 --- a/Ketchup/Dcpu16Computer.cs +++ b/Ketchup/Dcpu16Computer.cs @@ -26,6 +26,8 @@ public class Dcpu16Computer : PartModule private static bool _hasInitPosition; private static bool _hasInitStyles; + private static double _monitorImageScale = 1; + #endregion #region Devices @@ -177,7 +179,7 @@ private void OnWindow(int windowId) } } - var monitorImage = _lem1802.GetScreenImage(scale: 4); + var monitorImage = _lem1802.GetScreenImage(); var pressedStyle = new GUIStyle(_styleButton) { normal = _styleButton.active }; @@ -190,10 +192,12 @@ private void OnWindow(int windowId) var kbdButtonPressed = GUILayout.Button("KBD", _isKeyboardAttached ? pressedStyle : _styleButton, GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); - GUILayout.Label("Memory Image:", _styleLabel, GUILayout.Width(100)); + GUILayout.Label("Memory Image:", new GUIStyle(_styleLabel) { stretchWidth = true }); + GUILayout.EndHorizontal(); + GUILayout.BeginHorizontal(); if (_isPowerOn) { - GUILayout.Label(_program, _styleLabel, GUILayout.Width(400)); + GUILayout.Label(_program, new GUIStyle(_styleLabel) { stretchWidth = true }); } else { @@ -201,7 +205,15 @@ private void OnWindow(int windowId) } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); - GUILayout.Box(monitorImage, _styleBox, GUILayout.Width(monitorImage.width + 8), GUILayout.Height(monitorImage.height + 8)); + GUILayout.Box(String.Empty, _styleBox, GUILayout.Width((int)(monitorImage.width * _monitorImageScale)), GUILayout.Height((int)(monitorImage.height * _monitorImageScale))); + var imageRect = GUILayoutUtility.GetLastRect(); + GUI.DrawTexture(imageRect, monitorImage, ScaleMode.ScaleToFit); + GUILayout.EndHorizontal(); + GUILayout.BeginHorizontal(); + if (GUILayout.Button("1x", _styleButton)) { SetMonitorScale(1); } + if (GUILayout.Button("2x", _styleButton)) { SetMonitorScale(2); } + if (GUILayout.Button("3x", _styleButton)) { SetMonitorScale(3); } + if (GUILayout.Button("4x", _styleButton)) { SetMonitorScale(4); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label(actualClockSpeedFormatted, _styleLabel); @@ -277,5 +289,11 @@ private void OnPowerButtonPressed() _isPowerOn = true; } } + + private void SetMonitorScale(double scale) + { + _monitorImageScale = scale; + _windowPosition = new Rect(_windowPosition) { width = 0, height = 0 }; + } } } diff --git a/Ketchup/Devices/Lem1802.cs b/Ketchup/Devices/Lem1802.cs index f7aca23..123b23f 100644 --- a/Ketchup/Devices/Lem1802.cs +++ b/Ketchup/Devices/Lem1802.cs @@ -97,7 +97,7 @@ public override ushort Version public Lem1802() { - _screenTexture = new Texture2D(Width, Height); + _screenTexture = new Texture2D(Width, Height) { filterMode = FilterMode.Point }; _blinkTimer = new Timer(ToggleBlinker, null, BlinkRate, BlinkRate); } @@ -138,13 +138,8 @@ public override void Reset() _borderColorValue = 0; } - public Texture2D GetScreenImage(int scale = 1) + public Texture2D GetScreenImage() { - if (_screenTexture.width != Width * scale || _screenTexture.height != Height * scale) - { - _screenTexture = new Texture2D(Width * scale, Height * scale); - } - if (_screenMap == 0) { for (var x = 0; x < _screenTexture.width; x++) @@ -177,21 +172,15 @@ public Texture2D GetScreenImage(int scale = 1) { Color color; - var tx = (i / 8 + (x * CharWidth)) * scale; - var ty = Math.Abs((i % 8 + (y * CharHeight)) - (Height - 1)) * scale; + var tx = (i / 8 + (x * CharWidth)); + var ty = Math.Abs((i % 8 + (y * CharHeight)) - (Height - 1)); if ((fontValue & 1) == 0 || (((value & 0x80) == 0x80) && !_blinkOn)) color = background; else color = foreground; - for (var j = 0; j < scale; j++) - { - for (var k = 0; k < scale; k++) - { - _screenTexture.SetPixel(tx + j, ty + k, color); - } - } + _screenTexture.SetPixel(tx, ty, color); fontValue >>= 1; } From 1b1f598f4402b1dbc5d67904764b496474283c48 Mon Sep 17 00:00:00 2001 From: Dwayne Bent Date: Sun, 21 Jul 2013 18:47:04 -0400 Subject: [PATCH 2/3] Correct typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7a2b26c..99547db 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ the **ENIAK-16L Computer**, these "Mechanical Kerbal Brains" replace the **RC-00 guidance unit however. Construct a rocket normally with one of the new parts. When you're ready to launch you should see a new window with the name of the computer you added. In the text -field labelled "Memory Image" enter `helloworld.bin` and then click the **PWR** button. You should know see +field labelled "Memory Image" enter `helloworld.bin` and then click the **PWR** button. You should now see `Hello, world!` displayed on the monitor. You can write custom programs in DCPU-16 assembly and build them with an assembler, such as [Organic][organic]. Copy the built binary to the `GameData/Ketchup/Plugins/PluginData/Ketchup` directory, and you should be able to run it like `helloworld.bin`. From 21967300365dad8dcb52259b84577a70e1403903 Mon Sep 17 00:00:00 2001 From: Dwayne Bent Date: Sun, 21 Jul 2013 18:49:12 -0400 Subject: [PATCH 3/3] Add download information --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 99547db..097af07 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,10 @@ notably, there currently exist no devices capable of interacting with the vessel control is not currently possible. However, any program written for the DCPU-16 should be able to run within Kerbal Space Program. +Downloads +------------ +Release information and downloads may be found on the GitHub [releases][releases] page. + Building ------------ In order to build *Ketchup* two assemblies are required from your Kerbal Space Program installation. Because @@ -68,5 +72,6 @@ Name [monitor-spec]: http://dcpu.com/monitor/ [notch]: https://mojang.com/notch/ [organic]: https://github.com/SirCmpwn/organic +[releases]: https://github.com/dbent/Ketchup/releases [tomato]: https://github.com/SirCmpwn/Tomato [tomato-ksp-compat]: https://github.com/dbent/Tomato/tree/ksp-compat