From 7723d54b702a433fbbd039957d7839c0b6b4a899 Mon Sep 17 00:00:00 2001 From: "OPTIMUS-PRIME\\craig" Date: Mon, 3 Sep 2018 16:20:55 +0100 Subject: [PATCH 1/5] add draw-default command-method. Add function for building a default image spec in CLI. --- SmoulderingBeachBallCLI/ConsoleCommands.fs | 10 ++++++++++ SmoulderingBeachBallCLI/Validation.fs | 22 ++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/SmoulderingBeachBallCLI/ConsoleCommands.fs b/SmoulderingBeachBallCLI/ConsoleCommands.fs index 1499555..a8479b8 100644 --- a/SmoulderingBeachBallCLI/ConsoleCommands.fs +++ b/SmoulderingBeachBallCLI/ConsoleCommands.fs @@ -19,6 +19,16 @@ |> makeImage *) + let ``draw-default`` imgWidth imgHeight = + try + buildDefaultSpec imgWidth imgHeight + |> makeImage + |> Async.RunSynchronously + showEndOfCommandMessage + with + | :? ArgumentException as ex -> ex.Message + | _ as ex -> ex.Message + let ``draw-image`` imgWidth imgHeight mainColour path = try buildBasicSpec imgWidth imgHeight mainColour path diff --git a/SmoulderingBeachBallCLI/Validation.fs b/SmoulderingBeachBallCLI/Validation.fs index c897477..ea1d4a9 100644 --- a/SmoulderingBeachBallCLI/Validation.fs +++ b/SmoulderingBeachBallCLI/Validation.fs @@ -30,14 +30,28 @@ (String.Concat("[ERROR] The colour specifed is invalid.\n", "Please use the 'list-colours' command to see what you can use.")) + let getDesktopPath = + Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + let parsePath (path: string) = match path with - | path when ((path.ToLower()).Equals "desktop") -> - Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) - | path when ((path.ToLower()).Equals "d") -> - Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + | path when ((path.ToLower()).Equals "desktop") -> getDesktopPath + | path when ((path.ToLower()).Equals "d") -> getDesktopPath | _ -> path + let buildDefaultSpec iWidth iHeight = + let oSpec = + { colour = Brushes.Black + overlayType = Full } + let spec = + { width = iWidth + height = iHeight + colour = Brushes.AntiqueWhite + filePath = getDesktopPath + overlay = Some oSpec + } + spec + let buildBasicSpec iWidth iHeight mainColour path = let spec = { width = iWidth; From 9049607887afbeaed78d908f24c2a67721429a43 Mon Sep 17 00:00:00 2001 From: "OPTIMUS-PRIME\\craig" Date: Mon, 3 Sep 2018 16:46:29 +0100 Subject: [PATCH 2/5] set pen width dynamically. It takes the images dimensions as the reference point. --- SmoulderingBeachBall/InternalServices.fs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/SmoulderingBeachBall/InternalServices.fs b/SmoulderingBeachBall/InternalServices.fs index 8c7dee1..b2ecfc8 100644 --- a/SmoulderingBeachBall/InternalServices.fs +++ b/SmoulderingBeachBall/InternalServices.fs @@ -24,6 +24,13 @@ let penOffset penWidth = int (penWidth / (float32 2)) + let setPenWidth imgWidth imgHeight = + let width = float32 imgWidth + let height = float32 imgHeight + if (width > height) || (width = height) then + width * (float32 0.05) + else width * (float32 0.05) + let createBorderPath penWidth spec = let offset = penOffset penWidth [|Point (0, offset); // Essentially (0, 0) @@ -49,7 +56,8 @@ let addOverlayToImage graphics spec = let overlay = spec.overlay.Value - let pen = new Pen (overlay.colour, Width = 10.0f) + let pen = + new Pen (overlay.colour, width = (setPenWidth spec.width spec.height)) match overlay.overlayType with | Border -> drawBorder graphics pen spec | Full -> drawFullOverlay graphics pen spec From ba12095b0a24b8278d74a181d3f9db668b4017fe Mon Sep 17 00:00:00 2001 From: "OPTIMUS-PRIME\\craig" Date: Mon, 3 Sep 2018 16:51:49 +0100 Subject: [PATCH 3/5] fix setPenWidth bug -- use height when it is the longer side. --- SmoulderingBeachBall/InternalServices.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SmoulderingBeachBall/InternalServices.fs b/SmoulderingBeachBall/InternalServices.fs index b2ecfc8..5844f54 100644 --- a/SmoulderingBeachBall/InternalServices.fs +++ b/SmoulderingBeachBall/InternalServices.fs @@ -27,9 +27,9 @@ let setPenWidth imgWidth imgHeight = let width = float32 imgWidth let height = float32 imgHeight - if (width > height) || (width = height) then + if (width >= height) then width * (float32 0.05) - else width * (float32 0.05) + else height * (float32 0.05) let createBorderPath penWidth spec = let offset = penOffset penWidth From 7bd8670a2759635b7d1a010d6c5e98582fe63c65 Mon Sep 17 00:00:00 2001 From: "OPTIMUS-PRIME\\craig" Date: Mon, 3 Sep 2018 16:54:23 +0100 Subject: [PATCH 4/5] switch setPenWidth values around. The image renders better. --- SmoulderingBeachBall/InternalServices.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SmoulderingBeachBall/InternalServices.fs b/SmoulderingBeachBall/InternalServices.fs index 5844f54..96e11f2 100644 --- a/SmoulderingBeachBall/InternalServices.fs +++ b/SmoulderingBeachBall/InternalServices.fs @@ -28,8 +28,8 @@ let width = float32 imgWidth let height = float32 imgHeight if (width >= height) then - width * (float32 0.05) - else height * (float32 0.05) + height * (float32 0.05) + else width * (float32 0.05) let createBorderPath penWidth spec = let offset = penOffset penWidth From 220a6c724864350cc3e85ec4e312589d212ba500 Mon Sep 17 00:00:00 2001 From: "OPTIMUS-PRIME\\craig" Date: Mon, 3 Sep 2018 17:53:57 +0100 Subject: [PATCH 5/5] refactor draw-image to parse the overlay param's. --- SmoulderingBeachBallCLI/ConsoleCommands.fs | 28 ++-------------- SmoulderingBeachBallCLI/Validation.fs | 38 +++++++++++----------- 2 files changed, 21 insertions(+), 45 deletions(-) diff --git a/SmoulderingBeachBallCLI/ConsoleCommands.fs b/SmoulderingBeachBallCLI/ConsoleCommands.fs index a8479b8..3d35c43 100644 --- a/SmoulderingBeachBallCLI/ConsoleCommands.fs +++ b/SmoulderingBeachBallCLI/ConsoleCommands.fs @@ -12,13 +12,6 @@ let exit () = Environment.Exit (Environment.ExitCode) - (* possibe function -- save to desktop and almost set to "default"? - might be to goto for most command calls... - let `draw-basic` imgWidth imgHeight = - buildSimpleSpec - |> makeImage - *) - let ``draw-default`` imgWidth imgHeight = try buildDefaultSpec imgWidth imgHeight @@ -29,9 +22,9 @@ | :? ArgumentException as ex -> ex.Message | _ as ex -> ex.Message - let ``draw-image`` imgWidth imgHeight mainColour path = + let ``draw-image`` imgWidth imgHeight mainColour oColour oType path = try - buildBasicSpec imgWidth imgHeight mainColour path + buildSpec imgWidth imgHeight mainColour oColour oType path |> makeImage |> Async.RunSynchronously showEndOfCommandMessage @@ -39,23 +32,6 @@ | :? ArgumentException as ex -> ex.Message | _ as ex -> ex.Message - let ``draw-borderedImage`` imgWidth imgHeight mainColour oColour oType path = - try - buildOverlaySpec imgWidth imgHeight mainColour oColour oType path - |> makeImage - |> Async.RunSynchronously - showEndOfCommandMessage - with - | :? ArgumentException as ex -> ex.Message - | _ as ex -> ex.Message - - let ``draw-overlayedImage`` () = - try - showEndOfCommandMessage - with - | :? ArgumentException as ex -> ex.Message - | _ as ex -> ex.Message - let ``list-colours`` () = printfn "[INFO.] Listing available colours..." for item in colourList do diff --git a/SmoulderingBeachBallCLI/Validation.fs b/SmoulderingBeachBallCLI/Validation.fs index ea1d4a9..3820173 100644 --- a/SmoulderingBeachBallCLI/Validation.fs +++ b/SmoulderingBeachBallCLI/Validation.fs @@ -52,15 +52,6 @@ } spec - let buildBasicSpec iWidth iHeight mainColour path = - let spec = - { width = iWidth; - height = iHeight; - colour = parseColour mainColour - filePath = parsePath path - overlay = None } - spec - let parseOverlay (oType: string) = match oType.ToLower() with | "border" -> Border @@ -69,17 +60,26 @@ | "f" -> Full | _ -> invalidArg "Overlay Type" "The overlay type must be either 'border' or 'full'." - // Need to think about building the two spec's seperately and bring them together in one place. - // I'm repeating myself a little too much here. - // Also, need to adjust pen width to match the image size (in library proj.). - let buildOverlaySpec iWidth iHeight mainColour oColour oType path = + let buildOverlaySpec oColour (oType: string) = let oSpec = { colour = parseColour oColour; overlayType = parseOverlay oType } + oSpec + + let buildMainSpec iWidth iHeight mainColour path oSpec = let spec = - {width = iWidth; - height = iHeight; - colour = parseColour mainColour; - filePath = parsePath path; - overlay = Some oSpec } - spec \ No newline at end of file + { width = iWidth; + height = iHeight; + colour = parseColour mainColour + filePath = parsePath path + overlay = oSpec } + spec + + let buildSpec iWidth iHeight mainColour oColour (oType: string) path = + let spec = + match oType.ToLower() with + | "none" | "n" -> buildMainSpec iWidth iHeight mainColour path option.None + | _ -> + let oSpec = buildOverlaySpec oColour oType + buildMainSpec iWidth iHeight mainColour path (Some oSpec) + spec