|
|
|
@ -4,18 +4,51 @@ namespace DeathSocket
|
|
|
|
|
open ColourServices |
|
|
|
|
|
|
|
|
|
/// Provides functions which help draw gridded overlays onto images. |
|
|
|
|
/// Grid Painter, and all of Death Socket, uses the System.Drawing brushes/colours. |
|
|
|
|
/// If you are using System.Media brushes and colour, you will need to convert them. |
|
|
|
|
/// Death Socket, uses System.Drawing's brushes and colours. |
|
|
|
|
/// If you are using System.Media brushes and colour, you will need to |
|
|
|
|
/// convert them. Death Socket, also, uses SkiaSharp for cross platform |
|
|
|
|
/// functionality. If you are using Death Socket on Windows Desktop, use |
|
|
|
|
/// functions which do not include "Skia" in their name. If you are using |
|
|
|
|
/// Death Socket in a Xamarin/UWP project you should use the SkiaSharp |
|
|
|
|
/// functions. |
|
|
|
|
module GridPainter = |
|
|
|
|
|
|
|
|
|
open Validation |
|
|
|
|
open ImageServices |
|
|
|
|
|
|
|
|
|
// System.Drawing Functions |
|
|
|
|
// ======================================================================== |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Determines the (Pen) points needed to draw the appropriate number |
|
|
|
|
/// of horizontal lines (I.E. rows). Each item in the array includes a |
|
|
|
|
/// start and end co-ordinate (point) for each line. |
|
|
|
|
/// Use this function when targeting .Net/Mono). |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="width">The width of the image.</param> |
|
|
|
|
/// <param name="height">The height of the image.</param> |
|
|
|
|
/// <param name="rows">The number of rows the grid should have.</param> |
|
|
|
|
/// <remarks>You will probably only need these when dealing with GUI's.</remarks> |
|
|
|
|
let determineHorizontalLines (width: int) (height: int) (rows: int) = |
|
|
|
|
createHorizontalLines width height rows |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Determines the (Pen) points needed to draw the appropriate number |
|
|
|
|
/// of vertical lines (I.E. columns). Each item in the array includes a |
|
|
|
|
/// start and end co-ordinate (point) for each line. |
|
|
|
|
/// Use this function when targeting Windows Desktop (or Mono). |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="width">The width of the image.</param> |
|
|
|
|
/// <param name="height">The height of the image.</param> |
|
|
|
|
/// <param name="columns">The number of columns the grid should have.</param> |
|
|
|
|
/// <remarks>You will probably only need these when dealing with GUI's.</remarks> |
|
|
|
|
let determineVerticalLines (width: int) (height: int) (columns: int) = |
|
|
|
|
createVerticalLines width height columns |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Uses the information included in spec to create a gridded image. |
|
|
|
|
/// It then asynchronously saves it. |
|
|
|
|
/// Please stick to .bmp, .jpg or .png files. |
|
|
|
|
/// The other (image) file types have not been tested. |
|
|
|
|
/// It then asynchronously saves it. Uses .jpg or .png formats only. |
|
|
|
|
/// Use this function when targeting .Net/Mono). |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="spec"> |
|
|
|
|
/// The specification used to generate the new gridded image |
|
|
|
@ -33,7 +66,7 @@ namespace DeathSocket
|
|
|
|
|
async { |
|
|
|
|
try |
|
|
|
|
validateFilePath spec.originalPath |> ignore |
|
|
|
|
validatFileType spec.savePath |> ignore |
|
|
|
|
validateSaveFileType spec.savePath |> ignore |
|
|
|
|
drawBrushSpecGrid spec |> ignore |
|
|
|
|
with |
|
|
|
|
| :? FileNotFoundException as ex -> |
|
|
|
@ -42,8 +75,8 @@ namespace DeathSocket
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Uses the information included in spec to create a gridded image. It |
|
|
|
|
/// then asynchronously saves it. Please stick to .bmp, .jpg or .png |
|
|
|
|
/// files. The other (image) file types have not been tested. |
|
|
|
|
/// then asynchronously saves it. Uses .jpg or .png formats only. |
|
|
|
|
/// Use this function when targeting .Net/Mono). |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="spec"> |
|
|
|
|
/// The specification used to generate the gridded image. |
|
|
|
@ -61,7 +94,7 @@ namespace DeathSocket
|
|
|
|
|
async { |
|
|
|
|
try |
|
|
|
|
validateFilePath spec.originalPath |> ignore |
|
|
|
|
validatFileType spec.savePath |> ignore |
|
|
|
|
validateSaveFileType spec.savePath |> ignore |
|
|
|
|
drawRGBAGrid spec |
|
|
|
|
with |
|
|
|
|
| :? FileNotFoundException as ex -> |
|
|
|
@ -70,6 +103,7 @@ namespace DeathSocket
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Creates a Sytsem.Drawing SolidBrush from the individual RGBA values. |
|
|
|
|
/// Use this function when targeting .Net/Mono). |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="r">The red value.</param> |
|
|
|
|
/// <param name="g">The green value.</param> |
|
|
|
@ -79,10 +113,12 @@ namespace DeathSocket
|
|
|
|
|
/// Death Socket uses System.Drawing and not System.Media for colours |
|
|
|
|
/// and brushes. |
|
|
|
|
/// </remarks> |
|
|
|
|
let makeSolidBrushFromRGBA r g b a = makeBrushFromRGBA r g b a |
|
|
|
|
let makeSolidBrushFromRGBA (r: int) (g: int) (b:int) (a: int) = |
|
|
|
|
makeBrushFromRGBA r g b a |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Creates a System.Drawing SolidBrush from a RGBASpec. |
|
|
|
|
/// Use this function when targeting .Net/Mono). |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="spec"> |
|
|
|
|
///The specification which the brush is made from. |
|
|
|
@ -91,28 +127,97 @@ namespace DeathSocket
|
|
|
|
|
/// Death Socket uses System.Drawing and not System.Media for colours |
|
|
|
|
/// and brushes. |
|
|
|
|
/// </remarks> |
|
|
|
|
let makeSolidBrushFromRGBASpec spec = makeBrushFromRGBASpec spec |
|
|
|
|
let makeSolidBrushFromRGBASpec (spec: RGBASpec) = |
|
|
|
|
makeBrushFromRGBASpec spec |
|
|
|
|
|
|
|
|
|
// SkiaSharp Functions |
|
|
|
|
// ======================================================================== |
|
|
|
|
|
|
|
|
|
// NOT TESTED |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Determines the (Pen) points needed to draw the appropriate number of horizontal lines (I.E. rows). |
|
|
|
|
/// Each item in the array includes a start and end co-ordinate (point) for each line. |
|
|
|
|
/// Determines the (SKPoints) points needed to draw the appropriate |
|
|
|
|
/// number of horizontal lines (I.E. rows). Each item in the array |
|
|
|
|
/// included a start and end co-ordinate (SKPoint) for each line. |
|
|
|
|
/// Use this function when targeting Xamarin/UWP/.Net Core (SkiaSharp). |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="width">The width of the image.</param> |
|
|
|
|
/// <param name="height">The height of the image.</param> |
|
|
|
|
/// <param name="rows">The number of rows the grid should have.</param> |
|
|
|
|
/// <remarks>You will probably only need these when dealing with GUI's.</remarks> |
|
|
|
|
let determineHorizontalLines width height rows = |
|
|
|
|
createHorizontalLines width height rows |
|
|
|
|
/// <remarks>This function is part of the SkiaSharp functions provided |
|
|
|
|
/// by Death Socket.</remarks> |
|
|
|
|
let determineSKHorizontalLines (width: int) (height: int) (rows: int) = |
|
|
|
|
createSKHorizontalLines width height rows |
|
|
|
|
|
|
|
|
|
// NOT TESTED |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Determines the (Pen) points needed to draw the appropriate number of vertical lines (I.E. columns). |
|
|
|
|
/// Each item in the array includes a start and end co-ordinate (point) for each line. |
|
|
|
|
/// Determines the (SKPoints) points needed to draw the appropriate |
|
|
|
|
/// number of vertical lines (I.E. columns). Each item in the array |
|
|
|
|
/// included a start and end co-ordinate (SKPoint) for each line. |
|
|
|
|
/// Use this function when targeting Xamarin/UWP/.Net Core (SkiaSharp). |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="width">The width of the image.</param> |
|
|
|
|
/// <param name="height">The height of the image.</param> |
|
|
|
|
/// <param name="columns">The number of columns the grid should have.</param> |
|
|
|
|
/// <remarks>You will probably only need these when dealing with GUI's.</remarks> |
|
|
|
|
let determineVerticalLines width height columns = |
|
|
|
|
createVerticalLines width height columns |
|
|
|
|
/// <param name="columns">The number of columns the grid should have. |
|
|
|
|
/// </param> |
|
|
|
|
/// <remarks>This function is part of the SkiaSharp functions provided |
|
|
|
|
/// by Death Socket.</remarks> |
|
|
|
|
let determineSKVerticalLines (width: int) (height: int) (columns: int) = |
|
|
|
|
createSKVerticalLines width height columns |
|
|
|
|
|
|
|
|
|
// NOT TESTED |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Uses the information included in spec to create a gridded image. |
|
|
|
|
/// It then asynchronously saves it. Uses .jpg or .png formats only. |
|
|
|
|
/// Use this function when targeting Xamarin/UWP/.Net Core. |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="spec"> |
|
|
|
|
/// Used to note the orignial file's location and the |
|
|
|
|
/// changes the user would like to make to it (including the save |
|
|
|
|
/// location of the modified version). |
|
|
|
|
/// </param> |
|
|
|
|
/// <remarks> |
|
|
|
|
/// Make sure the image, which is having the overlay added to it, |
|
|
|
|
/// is not in use or needed by another program/process. |
|
|
|
|
/// This is because it is locked whilst in this function. |
|
|
|
|
/// </remarks> |
|
|
|
|
let applySkiaGridAsync (spec: SkiaSpec) = |
|
|
|
|
async { |
|
|
|
|
try |
|
|
|
|
validateFilePath spec.originalPath |> ignore |
|
|
|
|
validateSaveFileType spec.savePath |> ignore |
|
|
|
|
drawSkiaGrid spec |
|
|
|
|
with |
|
|
|
|
| :? FileNotFoundException as ex -> |
|
|
|
|
printfn "File could not be found at %s" ex.Message |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NOT TESTED |
|
|
|
|
|
|
|
|
|
let drawskia () = drawSkiaGrid () |
|
|
|
|
/// <summary> |
|
|
|
|
/// Uses the information included in spec to create a gridded image. |
|
|
|
|
/// It then asynchronously saves it. Uses .jpg or .png formats only. |
|
|
|
|
/// Use this function when targeting Xamarin/UWP/.Net Core. |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="spec"> |
|
|
|
|
/// Used to note the orignial file's location and the |
|
|
|
|
/// changes the user would like to make to it (including the save |
|
|
|
|
/// location of the modified version). |
|
|
|
|
/// </param> |
|
|
|
|
/// <remarks> |
|
|
|
|
/// Make sure the image, which is having the overlay added to it, |
|
|
|
|
/// is not in use or needed by another program/process. |
|
|
|
|
/// This is because it is locked whilst in this function. |
|
|
|
|
/// </remarks> |
|
|
|
|
let applySkiaRGBGridAsync (spec: SkiaRGBSpec) = |
|
|
|
|
async { |
|
|
|
|
try |
|
|
|
|
validateFilePath spec.originalPath |> ignore |
|
|
|
|
validateSaveFileType spec.savePath |> ignore |
|
|
|
|
drawSkiaRGBGrid spec |
|
|
|
|
with |
|
|
|
|
| :? FileNotFoundException as ex -> |
|
|
|
|
printfn "File could not be found at %s" ex.Message |
|
|
|
|
} |