Browse Source

Merge pull request #2 from CraigOates/o.2-p2

O.2 p2
master
Craig Oates 6 years ago committed by GitHub
parent
commit
010b3e749c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      SmoulderingBeachBall/InternalServices.fs
  2. 22
      SmoulderingBeachBallCLI/ConsoleCommands.fs
  3. 54
      SmoulderingBeachBallCLI/Validation.fs

10
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) then
height * (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

22
SmoulderingBeachBallCLI/ConsoleCommands.fs

@ -12,16 +12,9 @@
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-image`` imgWidth imgHeight mainColour path =
let ``draw-default`` imgWidth imgHeight =
try
buildBasicSpec imgWidth imgHeight mainColour path
buildDefaultSpec imgWidth imgHeight
|> makeImage
|> Async.RunSynchronously
showEndOfCommandMessage
@ -29,9 +22,9 @@
| :? ArgumentException as ex -> ex.Message
| _ as ex -> ex.Message
let ``draw-borderedImage`` imgWidth imgHeight mainColour oColour oType path =
let ``draw-image`` imgWidth imgHeight mainColour oColour oType path =
try
buildOverlaySpec imgWidth imgHeight mainColour oColour oType path
buildSpec imgWidth imgHeight mainColour oColour oType path
|> makeImage
|> Async.RunSynchronously
showEndOfCommandMessage
@ -39,13 +32,6 @@
| :? 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

54
SmoulderingBeachBallCLI/Validation.fs

@ -30,21 +30,26 @@
(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 buildBasicSpec iWidth iHeight mainColour path =
let buildDefaultSpec iWidth iHeight =
let oSpec =
{ colour = Brushes.Black
overlayType = Full }
let spec =
{ width = iWidth;
height = iHeight;
colour = parseColour mainColour
filePath = parsePath path
overlay = None }
{ width = iWidth
height = iHeight
colour = Brushes.AntiqueWhite
filePath = getDesktopPath
overlay = Some oSpec
}
spec
let parseOverlay (oType: string) =
@ -55,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
{ 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

Loading…
Cancel
Save