Browse Source

Merge pull request #3 from CraigOates/0.2-p1

0.2 p1
master
Craig Oates 6 years ago committed by GitHub
parent
commit
d8136d4cd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      SmoulderingBeachBall.sln
  2. 31
      SmoulderingBeachBall/InternalServices.fs
  3. 6
      SmoulderingBeachBallCLI/App.config
  4. 1
      SmoulderingBeachBallCLI/AppIcon.rc
  5. BIN
      SmoulderingBeachBallCLI/AppIcon.res
  6. 41
      SmoulderingBeachBallCLI/AssemblyInfo.fs
  7. 114
      SmoulderingBeachBallCLI/ConsoleCommands.fs
  8. 7
      SmoulderingBeachBallCLI/Program.fs
  9. 96
      SmoulderingBeachBallCLI/SmoulderingBeachBallCLI.fsproj
  10. 85
      SmoulderingBeachBallCLI/Validation.fs
  11. BIN
      SmoulderingBeachBallCLI/cheat-sheet.pdf
  12. BIN
      SmoulderingBeachBallCLI/icon.ico
  13. 7
      SmoulderingBeachBallCLI/packages.config

8
SmoulderingBeachBall.sln

@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28010.2016
MinimumVisualStudioVersion = 10.0.40219.1
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "SmoulderingBeachBall", "SmoulderingBeachBall\SmoulderingBeachBall.fsproj", "{DFC3CBCA-3DA7-4CF4-A8BC-BCCB740FA6CD}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "SmoulderingBeachBall", "SmoulderingBeachBall\SmoulderingBeachBall.fsproj", "{DFC3CBCA-3DA7-4CF4-A8BC-BCCB740FA6CD}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "SmoulderingBeachBallCLI", "SmoulderingBeachBallCLI\SmoulderingBeachBallCLI.fsproj", "{5C00D583-EF09-4FE6-A3FE-EB01454C0607}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -15,6 +17,10 @@ Global
{DFC3CBCA-3DA7-4CF4-A8BC-BCCB740FA6CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DFC3CBCA-3DA7-4CF4-A8BC-BCCB740FA6CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DFC3CBCA-3DA7-4CF4-A8BC-BCCB740FA6CD}.Release|Any CPU.Build.0 = Release|Any CPU
{5C00D583-EF09-4FE6-A3FE-EB01454C0607}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5C00D583-EF09-4FE6-A3FE-EB01454C0607}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5C00D583-EF09-4FE6-A3FE-EB01454C0607}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5C00D583-EF09-4FE6-A3FE-EB01454C0607}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

31
SmoulderingBeachBall/InternalServices.fs

@ -9,21 +9,30 @@
let validateDimension dimension =
match dimension with
| dimension when dimension <= 0 ->
invalidArg "dimension" "The width and height must be greater than 0."
invalidArg "dimension" "[ERROR] The images height and width must be greater than 0."
| _ -> ()
let validateDirectory filePath =
let path = Path.GetDirectoryName filePath
match (Directory.Exists path) with
| false -> invalidArg "filePath" "Unable to save to the specified location because it does not exist."
| false ->
invalidArg "filePath" "[ERROR] Unable to save to the specified location because it could not be found."
| true -> ()
module Drawing =
open System.Text
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
let offset = penOffset penWidth
[|Point (0, offset); // Essentially (0, 0)
Point ((spec.width - offset), offset);
Point ((spec.width - offset), (spec.height - offset));
@ -47,11 +56,21 @@
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
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)
@ -60,6 +79,6 @@
match spec.overlay.IsSome with
| true -> addOverlayToImage graphics spec
| false -> printfn "[INFO.] No overlay specified. Creating image without one."
bitmap.Save (spec.filePath)
bitmap.Dispose()
bitmap.Save (Path.Combine (spec.filePath, (buildFileName spec)))
graphics.Dispose()
bitmap.Dispose()

6
SmoulderingBeachBallCLI/App.config

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1" />
</startup>
</configuration>

1
SmoulderingBeachBallCLI/AppIcon.rc

@ -0,0 +1 @@
1 ICON icon.ico

BIN
SmoulderingBeachBallCLI/AppIcon.res

Binary file not shown.

41
SmoulderingBeachBallCLI/AssemblyInfo.fs

@ -0,0 +1,41 @@
namespace SmoulderingBeachBallCLI.AssemblyInfo
open System.Reflection
open System.Runtime.CompilerServices
open System.Runtime.InteropServices
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[<assembly: AssemblyTitle("Smouldering Beach Ball CLI")>]
[<assembly: AssemblyDescription("")>]
[<assembly: AssemblyConfiguration("")>]
[<assembly: AssemblyCompany("")>]
[<assembly: AssemblyProduct("Smouldering Beach Ball CLI")>]
[<assembly: AssemblyCopyright("Copyright © 2018")>]
[<assembly: AssemblyTrademark("")>]
[<assembly: AssemblyCulture("")>]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[<assembly: ComVisible(false)>]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[<assembly: Guid("5c00d583-ef09-4fe6-a3fe-eb01454c0607")>]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [<assembly: AssemblyVersion("1.0.*")>]
[<assembly: AssemblyVersion("0.2.0.0")>]
[<assembly: AssemblyFileVersion("0.2.0.0")>]
do
()

114
SmoulderingBeachBallCLI/ConsoleCommands.fs

@ -0,0 +1,114 @@
namespace Commands
module ConsoleCommands =
open System
open Console.Waterworks
open Console.Waterworks.Attributes
open SmoulderingBeachBall.Services
open Validation
open System.IO
let showEndOfCommandMessage = "[INFO.] Execution completed."
[<ListCommand>]
[<Parameters "none">]
[<Description
"Display a text message indicating this program is running properly.">]
[<Usage "test">]
let test () = "[SUCCESS] Smouldering Beach Ball CLI seems to be working."
[<ListCommand>]
[<Parameters "none">]
[<Description "Displays a list of available commands provided by this program.">]
[<Usage "help">]
let help () = CW_Liaison().RequestHelpDocumentation("Commands")
[<ListCommand>]
[<Parameters "none">]
[<Description "Saves this program's cheat sheet to the desktop.">]
[<Usage "cheat">]
let cheat () =
try
printfn "[INFO] Attempting to save cheat sheet to the desktop..."
let cheatSheetPath = __SOURCE_DIRECTORY__ + "/cheat-sheet.pdf"
let savePath = getDesktopPath + "/smouldering-beach-ball-cheat-sheet.pdf"
File.Copy (cheatSheetPath, savePath, true)
showEndOfCommandMessage
with
| :? FileNotFoundException as ex -> ex.Message
| _ as ex -> ex.Message
[<ListCommand>]
[<Parameters "none">]
[<Description "Exits out of the program.">]
[<Usage "exit">]
let exit () = Environment.Exit (Environment.ExitCode)
[<ListCommand>]
[<Parameters "(image-width: int) (image-height: int)" >]
[<Description
("Saves an image to the desktop, using the default setting.\n" +
"The user must specify the width and the height of the image.")>]
[<Usage "draw-default 500 500">]
let ``draw-default`` imgWidth imgHeight =
try
buildDefaultSpec imgWidth imgHeight
|> makeImage
|> Async.RunSynchronously
showEndOfCommandMessage
with
| :? ArgumentException as ex -> ex.Message
| _ as ex -> ex.Message
[<ListCommand>]
[<Parameters
("(image-width: int) (image-height: int) (main-colour: string) " +
"(overlay-colour: string) (overlay-type:string) (file-path: string)")>]
[<Description
("\nCreates an image using the values specified by the user.\n" +
"To see a list of available colours use the 'list-colours' command.\n" +
"For the overlay-type you can enter either 'none', 'border' or 'full.'\n" +
"For the file path, you can enter 'desktop' to save to the desktop." +
"Otherwise, you must specify the whole path.")>]
[<Usage
("\ndraw-image 770 400 white black full desktop\n" +
"draw-image 600 400 purple gray border C:/work/project-folder/images\n" +
"draw-image 800 440 black - none D:/your-project/assets")>]
let ``draw-image`` imgWidth imgHeight mainColour oColour oType path =
try
buildSpec imgWidth imgHeight mainColour oColour oType path
|> makeImage
|> Async.RunSynchronously
showEndOfCommandMessage
with
| :? ArgumentException as ex -> ex.Message
| _ as ex -> ex.Message
[<ListCommand>]
[<Parameters "None">]
[<Description
"Lists out the colours this program uses to draw its images.">]
[<Usage "list-colours">]
let ``list-colours`` () =
printfn "[INFO.] Listing available colours..."
for item in colourList do
printfn "%s" item.Key
showEndOfCommandMessage
(* ALIASES
=======================================================================
These command-methods will not show up in the help section.
Before adding extra aliases, make sure the main version is as clear and
helpful to someone new to the program as possible. Aliases should be
treated as commands for experienced users and documented on the wiki,
hosted alongside the repository on GitHub.
URL: https://github.com/CraigOates/Smouldering-Beach-Ball/wiki *)
let dd imgWidth imgHeight =
``draw-default`` imgWidth imgHeight
let di imgWidth imgHeight mainColour oColour oType path =
``draw-image`` imgWidth imgHeight mainColour oColour oType path
let lc () = ``list-colours`` ()

7
SmoulderingBeachBallCLI/Program.fs

@ -0,0 +1,7 @@
open Console.Waterworks
[<EntryPoint>]
let main argv =
let liaison = new CW_Liaison ()
liaison.Run ("Commands", true)
0 // return an integer exit code

96
SmoulderingBeachBallCLI/SmoulderingBeachBallCLI.fsproj

@ -0,0 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>5c00d583-ef09-4fe6-a3fe-eb01454c0607</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>SmoulderingBeachBallCLI</RootNamespace>
<AssemblyName>SmoulderingBeachBallCLI</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<UseStandardResourceNames>true</UseStandardResourceNames>
<Name>SmoulderingBeachBallCLI</Name>
<Win32Resource>..\SmoulderingBeachBallCLI\AppIcon.res</Win32Resource>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<Tailcalls>false</Tailcalls>
<OutputPath>bin\$(Configuration)\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<PlatformTarget>AnyCPU</PlatformTarget>
<DocumentationFile>
</DocumentationFile>
<Prefer32Bit>false</Prefer32Bit>
<OtherFlags>
</OtherFlags>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<Tailcalls>true</Tailcalls>
<OutputPath>bin\$(Configuration)\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<PlatformTarget>AnyCPU</PlatformTarget>
<DocumentationFile>
</DocumentationFile>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(FSharpTargetsPath)' == '' AND Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets') ">
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
<Import Project="$(FSharpTargetsPath)" />
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="Validation.fs" />
<Compile Include="ConsoleCommands.fs" />
<Compile Include="Program.fs" />
<None Include="App.config" />
<Content Include="packages.config" />
<Content Include="icon.ico" />
<None Include="AppIcon.res" />
<None Include="cheat-sheet.pdf" />
</ItemGroup>
<ItemGroup>
<Reference Include="Console.Waterworks">
<HintPath>..\packages\Console.Waterworks.0.1.0.0-alpha1\lib\Console.Waterworks.dll</HintPath>
</Reference>
<Reference Include="FSharp.Core">
<HintPath>..\packages\FSharp.Core.4.5.2\lib\net45\FSharp.Core.dll</HintPath>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Drawing.Common">
<HintPath>..\packages\System.Drawing.Common.4.5.0\lib\net461\System.Drawing.Common.dll</HintPath>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.ValueTuple">
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SmoulderingBeachBall\SmoulderingBeachBall.fsproj">
<Name>SmoulderingBeachBall</Name>
<Project>{dfc3cbca-3da7-4cf4-a8bc-bccb740fa6cd}</Project>
<Private>True</Private>
</ProjectReference>
</ItemGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

85
SmoulderingBeachBallCLI/Validation.fs

@ -0,0 +1,85 @@
module internal Validation
open System.Drawing
open SmoulderingBeachBall.Domain.DomainTypes
open System
let colourList =
[ "blue", Brushes.AliceBlue;
"brown", Brushes.Brown;
"black", Brushes.Black;
"gray", Brushes.Gray;
"green", Brushes.Green;
"purple", Brushes.Purple;
"red", Brushes.Red;
"white", Brushes.White;
"yellow", Brushes.Yellow;]
|> Map.ofList
let isColourValid (colour: string) =
colourList
|> Map.containsKey (colour.ToLower())
let parseColour colour =
match (isColourValid colour) with
| true ->
colourList
|> Map.find (colour.ToLower())
| false ->
invalidArg "Colour"
(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") -> 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 parseOverlay (oType: string) =
match oType.ToLower() with
| "border" -> Border
| "b" -> Border
| "full" -> Full
| "f" -> Full
| _ -> invalidArg "Overlay Type" "The overlay type must be either 'border' or 'full'."
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 = 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

BIN
SmoulderingBeachBallCLI/cheat-sheet.pdf

Binary file not shown.

BIN
SmoulderingBeachBallCLI/icon.ico

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

7
SmoulderingBeachBallCLI/packages.config

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Console.Waterworks" version="0.1.0.0-alpha1" targetFramework="net471" />
<package id="FSharp.Core" version="4.5.2" targetFramework="net471" />
<package id="System.Drawing.Common" version="4.5.0" targetFramework="net471" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net471" />
</packages>
Loading…
Cancel
Save