Skip to content

Commit

Permalink
Added Drawing module with Color and Bitmap classes and respective doc…
Browse files Browse the repository at this point in the history
…umentation.
  • Loading branch information
JacobMisirian committed Aug 28, 2016
1 parent a457357 commit 5ef5041
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 0 deletions.
33 changes: 33 additions & 0 deletions docs/Drawing/Bitmap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## ```class Bitmap```

### ```func new (path : string)```
Creates a new instance of the Bitmap class from the specified file path.
### ```func new (height : int, width : int)```
Creates a new instance of the Bitmap class from the specified height and width integers.

### ```func getPixel (x : int, y : int) : Color```
Returns the Color at the specified x and y coordinates.

### ```height { get { return this.height; } }```
Gets the integer value of the Bitmap height.

### ```horizontalResolution { get { return this.horizontalResolution; } }```
Gets the float value of the Bitmap horizontal resolution.

### ```func makeTransparent (color : Color) : null```
Makes the specified Color transparent in the Bitmap.

### ```func save (path : string) : null```
Saves the Bitmap to the specified file path.

### ```func setPixel (x : int, y : int, color : Color) : null```
Sets the pixel at the specified x and y coordinates to the specified Color.

### ```func setResolution (x : float, y : float) : null```
Sets the resolution of the bitmap to the specified x and y values.

### ```verticalResolution { get { return this.verticalResolution; } }```
Gets the float value of the Bitmap vertical resolution.

### ```width { get { return this.width; } }```
Gets the integer value of the Bitmap width.
25 changes: 25 additions & 0 deletions docs/Drawing/Color.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## ```class Color```

### ```func new (argb : int)```
Creates a new instance of the Color class using the specified argb value.
### ```func new (name : string)```
Creates a new instance of the Color class from the specified color string.
### ```func new (r : int, g : int, b : int)```
Creates a new instance of the Color class using the specified rgb values.
### ```func new (a : int, r : int, g : int, b : int)```
Creates a new instance of the Color class using the specified argb values.

### ```a { get { return this.a; } }```
Gets the alpha value of the Color.

### ```b { get { return this.b; } }```
Gets the blue value of the Color.

### ```func getArgb () : int```
Returns the argb value of the Color.

### ```g { get { return this.g; } }```
Gets the green value of the Color.

### ```r { get { return this.r; } }```
Gets the red value of the Color.
5 changes: 5 additions & 0 deletions src/Hassium/Hassium.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<Reference Include="System" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Web" />
<Reference Include="System.Drawing" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
Expand Down Expand Up @@ -157,6 +158,9 @@
<Compile Include="Runtime\Objects\Types\HassiumThread.cs" />
<Compile Include="Runtime\Objects\IO\HassiumDirectoryInfo.cs" />
<Compile Include="Runtime\VirtualMachine.cs" />
<Compile Include="Runtime\Objects\Drawing\HassiumColor.cs" />
<Compile Include="Runtime\Objects\Drawing\HassiumBitmap.cs" />
<Compile Include="Runtime\Objects\Drawing\HassiumDrawingModule.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
Expand All @@ -176,5 +180,6 @@
<Folder Include="Runtime\Objects\Util\" />
<Folder Include="Runtime\Objects\Reflection\" />
<Folder Include="HassiumBuilder\" />
<Folder Include="Runtime\Objects\Drawing\" />
</ItemGroup>
</Project>
85 changes: 85 additions & 0 deletions src/Hassium/Runtime/Objects/Drawing/HassiumBitmap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System;
using System.Drawing;

using Hassium.Runtime.Objects.Types;

namespace Hassium.Runtime.Objects.Drawing
{
public class HassiumBitmap: HassiumObject
{
public static new HassiumTypeDefinition TypeDefinition = new HassiumTypeDefinition("Bitmap");

public Bitmap Bitmap { get; set; }

public HassiumBitmap()
{
AddType(TypeDefinition);
AddAttribute(HassiumObject.INVOKE, _new, 1, 2);
}

public HassiumBitmap _new(VirtualMachine vm, params HassiumObject[] args)
{
HassiumBitmap bitmap = new HassiumBitmap();
switch (args.Length)
{
case 1:
bitmap.Bitmap = new Bitmap(args[0].ToString(vm).String);
break;
case 2:
bitmap.Bitmap = new Bitmap((int)args[0].ToInt(vm).Int, (int)args[1].ToInt(vm).Int);
break;
}
bitmap.AddAttribute("getPixel", bitmap.getPixel, 2);
bitmap.AddAttribute("height", new HassiumProperty(bitmap.get_height));
bitmap.AddAttribute("horizontalResolution", new HassiumProperty(bitmap.get_horizontalResolution));
bitmap.AddAttribute("makeTransparent", bitmap.makeTransparent, 1);
bitmap.AddAttribute("save", bitmap.save, 1);
bitmap.AddAttribute("setPixel", bitmap.setPixel, 3);
bitmap.AddAttribute("setResolution", bitmap.setResolution, 2);
bitmap.AddAttribute("verticalResolution", new HassiumProperty(bitmap.get_verticalResolution));
bitmap.AddAttribute("width", new HassiumProperty(bitmap.get_width));
return bitmap;
}

public HassiumColor getPixel(VirtualMachine vm, params HassiumObject[] args)
{
return new HassiumColor()._new(vm, new HassiumInt(Bitmap.GetPixel((int)args[0].ToInt(vm).Int, (int)args[1].ToInt(vm).Int).ToArgb()));
}
public HassiumInt get_height(VirtualMachine vm, params HassiumObject[] args)
{
return new HassiumInt(Bitmap.Height);
}
public HassiumFloat get_horizontalResolution(VirtualMachine vm, params HassiumObject[] args)
{
return new HassiumFloat(Bitmap.HorizontalResolution);
}
public HassiumNull makeTransparent(VirtualMachine vm, params HassiumObject[] args)
{
Bitmap.MakeTransparent(((HassiumColor)args[0]).Color);
return HassiumObject.Null;
}
public HassiumNull save(VirtualMachine vm, params HassiumObject[] args)
{
Bitmap.Save(args[0].ToString(vm).String);
return HassiumObject.Null;
}
public HassiumNull setPixel(VirtualMachine vm, params HassiumObject[] args)
{
Bitmap.SetPixel((int)args[0].ToInt(vm).Int, (int)args[1].ToInt(vm).Int, ((HassiumColor)args[2]).Color);
return HassiumObject.Null;
}
public HassiumNull setResolution(VirtualMachine vm, params HassiumObject[] args)
{
Bitmap.SetResolution((float)args[0].ToFloat(vm).Float, (float)args[1].ToFloat(vm).Float);
return HassiumObject.Null;
}
public HassiumFloat get_verticalResolution(VirtualMachine vm, params HassiumObject[] args)
{
return new HassiumFloat(Bitmap.VerticalResolution);
}
public HassiumInt get_width(VirtualMachine vm, params HassiumObject[] args)
{
return new HassiumInt(Bitmap.Width);
}
}
}
67 changes: 67 additions & 0 deletions src/Hassium/Runtime/Objects/Drawing/HassiumColor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Drawing;

using Hassium.Runtime.Objects.Types;

namespace Hassium.Runtime.Objects.Drawing
{
public class HassiumColor: HassiumObject
{
public static new HassiumTypeDefinition TypeDefinition = new HassiumTypeDefinition("Color");

public Color Color { get; set; }

public HassiumColor()
{
AddType(TypeDefinition);
AddAttribute(HassiumObject.INVOKE, _new, 1, 3, 4);
}

public HassiumColor _new(VirtualMachine vm, params HassiumObject[] args)
{
HassiumColor color = new HassiumColor();
switch (args.Length)
{
case 1:
if (args[0] is HassiumInt)
color.Color = Color.FromArgb((int)args[0].ToInt(vm).Int);
else
color.Color = Color.FromName(args[0].ToString(vm).String);
break;
case 3:
color.Color = Color.FromArgb((int)args[0].ToInt(vm).Int, (int)args[1].ToInt(vm).Int, (int)args[2].ToInt(vm).Int);
break;
case 4:
color.Color = Color.FromArgb((int)args[0].ToInt(vm).Int, (int)args[1].ToInt(vm).Int, (int)args[2].ToInt(vm).Int, (int)args[3].ToInt(vm).Int);
break;
}
color.AddAttribute("a", new HassiumProperty(color.get_a));
color.AddAttribute("b", new HassiumProperty(color.get_b));
color.AddAttribute("getArgb", color.getArgb, 0);
color.AddAttribute("g", new HassiumProperty(color.get_g));
color.AddAttribute("r", new HassiumProperty(color.get_r));
return color;
}

public HassiumInt get_a(VirtualMachine vm, params HassiumObject[] args)
{
return new HassiumInt(Color.A);
}
public HassiumInt get_b(VirtualMachine vm, params HassiumObject[] args)
{
return new HassiumInt(Color.B);
}
public HassiumInt getArgb(VirtualMachine vm, params HassiumObject[] args)
{
return new HassiumInt(Color.ToArgb());
}
public HassiumInt get_g(VirtualMachine vm, params HassiumObject[] args)
{
return new HassiumInt(Color.G);
}
public HassiumInt get_r(VirtualMachine vm, params HassiumObject[] args)
{
return new HassiumInt(Color.R);
}
}
}
14 changes: 14 additions & 0 deletions src/Hassium/Runtime/Objects/Drawing/HassiumDrawingModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace Hassium.Runtime.Objects.Drawing
{
public class HassiumDrawingModule: InternalModule
{
public HassiumDrawingModule() : base("Drawing")
{
AddAttribute("Bitmap", new HassiumBitmap());
AddAttribute("Color", new HassiumColor());
}
}
}

2 changes: 2 additions & 0 deletions src/Hassium/Runtime/Objects/InternalModule.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;

using Hassium.Runtime.Objects.Drawing;
using Hassium.Runtime.Objects.IO;
using Hassium.Runtime.Objects.Math;
using Hassium.Runtime.Objects.Net;
Expand All @@ -21,6 +22,7 @@ public InternalModule(string name)

public static Dictionary<string, InternalModule> InternalModules = new Dictionary<string, InternalModule>()
{
{ "Drawing", new HassiumDrawingModule() },
{ "IO", new HassiumIOModule() },
{ "Math", new HassiumMathModule() },
{ "Net", new HassiumNetModule() },
Expand Down

0 comments on commit 5ef5041

Please sign in to comment.