Browse Source

add function to append a file name to file path.

Add parsing function in the CLI project to quicklly enter the desktop as the save location.
master
Craig Oates 6 years ago
parent
commit
c8edd87f12
  1. 14
      SmoulderingBeachBall/InternalServices.fs
  2. 12
      SmoulderingBeachBallCLI/Validation.fs

14
SmoulderingBeachBall/InternalServices.fs

@ -19,6 +19,7 @@
| true -> ()
module Drawing =
open System.Text
let penOffset penWidth = int (penWidth / (float32 2))
@ -52,6 +53,15 @@
| Border -> drawBorder graphics pen spec
| Full -> drawFullOverlay graphics pen spec
let buildFileName spec =
let sb = new StringBuilder ()
sb.Append (spec.width.ToString ()) |> ignore
sb.Append "x" |> ignore
sb.Append (spec.height.ToString ()) |> ignore
sb.Append ".png" |> ignore
(sb.ToString ())
let drawImage spec =
let bitmap = new Bitmap (spec.width, spec.height)
let graphics = Graphics.FromImage (bitmap)
@ -59,7 +69,7 @@
graphics.FillRectangle (spec.colour, rectangle)
match spec.overlay.IsSome with
| true -> addOverlayToImage graphics spec
| false -> printfn "[INFO.] No overlay specified. Creating image withoutone."
bitmap.Save (spec.filePath)
| false -> printfn "[INFO.] No overlay specified. Creating image without one."
bitmap.Save (Path.Combine (spec.filePath, (buildFileName spec)))
graphics.Dispose()
bitmap.Dispose()

12
SmoulderingBeachBallCLI/Validation.fs

@ -2,6 +2,7 @@
open System.Drawing
open SmoulderingBeachBall.Domain.DomainTypes
open System
let colourList =
[ "blue", Brushes.AliceBlue;
@ -28,12 +29,21 @@
invalidArg "Colour" "The colour specifed is invalid."
// "Please use the ListAvailableColours command for a list"?
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
let buildBasicSpec iWidth iHeight mainColour path =
let brush = (parseColour mainColour)
let parsedPath = parsePath path
let spec =
{ width = iWidth;
height = iHeight;
colour = brush
filePath = path
filePath = parsedPath
overlay = None }
spec
Loading…
Cancel
Save