-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Drawing module with Color and Bitmap classes and respective doc…
…umentation.
- Loading branch information
1 parent
a457357
commit 5ef5041
Showing
7 changed files
with
231 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
14
src/Hassium/Runtime/Objects/Drawing/HassiumDrawingModule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters