Permalink
Browse files

text & drawing api

  • Loading branch information...
1 parent f95f4d2 commit dfb97980c8f1529c6cba502ba73070b271c6e2f6 @TheHippo committed Mar 25, 2010
Showing with 480 additions and 76 deletions.
  1. +16 −28 Test1.hx
  2. +1 −0 build.hxml
  3. +54 −1 hxGD/Color.hx
  4. +120 −27 hxGD/Graphics.hx
  5. +184 −17 hxGD/Image.hx
  6. +60 −0 hxGD/Loader.hx
  7. +39 −1 hxGD/Polygon.hx
  8. +6 −2 makefile
View
@@ -5,45 +5,33 @@ import hxGD.Loader;
import hxGD.Color;
import hxGD.Polygon;
import hxGD.Graphics;
+import hxGD.Animation;
class Test1 {
public function new() {
- var img:Image = Loader.createFromJpeg("test.jpg");
+ var anim:Animation = new Animation("out.gif",25,true);
- trace("width: "+img.width+" height: "+img.height);
+ for (i in 0...5) {
+ var img:Image = Loader.createFromPng("test.png");
+ img.graphics.color = Color.ofRGB(0xFF0000);
+ img.string("/home/hippo/imagetest/google/svn/trunk/fonts/Agency.ttf",42.0,Math.round(img.width/2),Math.round(img.height/2),"i"+i,StringAlign.CenterMiddle);
+ img.saveImage("image"+i+".gif",FileType.Gif);
+ //neko.vm.Gc.run(true);
+ anim.addImage(img);
+
+ }
+ anim.render();
- //img.graphics.setBrush(brush);
-
-
- img.graphics.color = Color.ofRGB(0xFF0000);
-
- /* var ca:Array<Color> = new Array<Color>();
- ca.push(new Color(255,0,0));
- ca.push(new Color(255,0,0));
- ca.push(new Color(0,255,0));
- ca.push(new Color(0,255,0));
- ca.push(new Color(0,0,255));
- ca.push(new Color(0,0,255));
-
- img.graphics.setStyle(ca); */
- img.graphics.thickness = 5;
- img.graphics.color = Color.ofRGBA(0xFF000055);
-
- img.graphics.imageLine(0,0,img.width,img.height,false);
- img.graphics.imageCircle(150,150,130);
-
-
-
- img.saveImage("test2.png",FileType.Png);
+ //img.saveImage("test2.png",FileType.Png);
}
public static function main() {
- //for (i in 0...5000) {
+ //for (i in 0...100) {
new Test1();
- // if (i % 10 == 0)
- // neko.vm.Gc.run(true);
+// if (i % 10 == 0)
+ // neko.vm.Gc.run(true);
//}
}
View
@@ -1,2 +1,3 @@
-main Test1
-neko test1.n
+
View
@@ -1,13 +1,56 @@
+/*
+ * hxGD.Color.hx
+ *
+ * Copyright 2009 Philipp Klose <hippo@byteanvil.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
package hxGD;
class Color {
- public var gd(gdColor,null):Int;
+ /**
+ * internal gd representation of a color
+ */
+ public var gd(gdColor, null):Int;
+ /**
+ * red channel 0-255
+ */
public var red:Int;
+ /**
+ * green channel 0-255
+ */
public var green:Int;
+ /**
+ * blue channel 0-255
+ */
public var blue:Int;
+ /**
+ * alpha channel 0-255 0 = transparent; 255 = opaque
+ */
public var alpha:Int;
+ /**
+ * create a new color representation
+ * @param red red channel 0-255
+ * @param green green channel 0-255
+ * @param blue blue channel 0-255
+ * @param ?alpha alpha channel 0-255 0 = transparent; 255 = opaque
+ */
public function new(red:Int,green:Int,blue:Int,?alpha:Int=255) {
this.red = red;
this.green = green;
@@ -16,11 +59,21 @@ class Color {
// trace(this);
}
+ /**
+ * creates a new color out of a integer (no alpha channel)
+ * @param color 0xRRGGBB
+ * @return Color
+ */
public static inline function ofRGB(color:Int):Color {
//0xRRGGBB
return new Color(((color & 0xFF0000) >> 16),((color & 0x00FF00) >> 8),(color & 0x0000FF));
}
+ /**
+ * creates a new color out of a integer with alpha channel
+ * @param color 0xRRGGBBAA
+ * @return Color
+ */
public static inline function ofRGBA(color:Int):Color {
//0xRRGGBBAA
return new Color(((color & 0xFF000000) >> 24),((color & 0x00FF0000) >> 16) ,((color & 0x0000FF00) >> 8),(color & 0x000000FF));
View
@@ -1,3 +1,23 @@
+/*
+ * hxGD.Graphics.hx
+ *
+ * Copyright 2009 Philipp Klose <hippo@byteanvil.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
package hxGD;
@@ -14,23 +34,48 @@ enum ArcFillType {
class Graphics {
+ /**
+ * default drawing color
+ */
public static var defaultColor:Color = Color.ofRGB(0x000000);
+ /**
+ * default drawing thickness. if different from 1 antialiasing setting will be ignored
+ */
public static var defaultThickness:Int = 1;
+ /**
+ * default antialiasing settings
+ */
public static var defaultAntiAliasing:Bool = true;
+ /**
+ * stores the neko abstract image data
+ */
private var img:Void;
+ /**
+ * drawing color
+ */
public var color(getColor,setColor):Color;
private var _color:Color;
+ /**
+ * Drawing thickness. If it is different from 1 antialiasing settings will be ignored
+ */
public var thickness(getThickness,setThickness):Int;
private var _thickness:Int;
+ /**
+ * Should all drawing operations be antialiased? Ignored if thickness if not 1
+ */
public var antiAliasing(getAntiAliasing,setAntiAliasing):Bool;
private var _antiAliasing:Bool;
+ /**
+ * creates a new graphics canvas
+ * @param img neko abstract data
+ */
public function new(img:Void) {
this.img = img;
setColor(Graphics.defaultColor);
@@ -47,6 +92,11 @@ class Graphics {
} */
+ /**
+ * setting style for drawing options.
+ * Example: colors = [redColor,transparentColor] will make a red dotted line
+ * @param colors Array with all colors
+ */
public inline function setStyle(colors:Array<Color>):Void {
var ca:Array<Int> = new Array<Int>();
for (c in colors)
@@ -89,48 +139,83 @@ class Graphics {
gd_setPixel(img,x,y);
}
- public inline function imageLine(x1:Int,y1:Int,x2:Int,y2:Int,?dashed:Bool=false):Void {
+ /**
+ * draws a line on the canvas
+ * @param x1 startpostion x
+ * @param y1 startposition y
+ * @param x2 endposition x
+ * @param y2 endposition y
+ * @param ?dashed simple dashed line?
+ */
+ public inline function line(x1:Int,y1:Int,x2:Int,y2:Int,?dashed:Bool=false):Void {
if (dashed)
gd_imageDashedLine(img,x1,y1,x2,y2);
else
gd_imageLine(img,x1,y1,x2,y2);
}
- public inline function imagePolygon(poly:Polygon,?open:Bool=false,?filled:Bool=false):Void {
- if (open)
- if (filled)
- gd_imageFilledPolygon(img,poly.x,poly.y);
- else
- gd_imageOpenPolygon(img,poly.x,poly.y);
- else
- if (filled)
- gd_imageFilledPolygon(img,poly.x,poly.y);
- else
- gd_imagePolygon(img,poly.x,poly.y);
+ /**
+ * draws a polygon with at least 3 points
+ * @param poly the polygon
+ * @param ?open open polygon
+ * @param ?filled filled polygon (only if polygon is not open!)
+ */
+ public inline function polygon(poly:Polygon,?open:Bool=false,?filled:Bool=false):Void {
+ gd_imagePolygon(img,poly.x,poly.y,open,filled);
}
- public inline function imageRectangle(x:Int,y:Int,width:Int,height:Int,?filled:Bool=false):Void {
- if (filled)
- gd_imageFilledRectangle(img,x,y,width,height);
- else
- gd_imageRectangle(img,x,y,width,height);
+ /**
+ * draws a rectangle
+ * @param x upper left corner x position
+ * @param y upper left corner y position
+ * @param width
+ * @param height
+ * @param ?filled
+ */
+ public inline function rectangle(x:Int,y:Int,width:Int,height:Int,?filled:Bool=false):Void {
+ gd_imageRectangle(img,x,y,width,height,filled);
}
- public inline function imageEllipse(x:Int, y:Int, width:Int,height:Int,?filled:Bool=false):Void {
+ /**
+ * draws a ellipse
+ * @param x center x position
+ * @param y center y position
+ * @param width
+ * @param height
+ * @param ?filled
+ */
+ public inline function ellipse(x:Int, y:Int, width:Int,height:Int,?filled:Bool=false):Void {
if (filled)
gd_imageFilledEllipse(img,x,y,width,height);
else
gd_imageArc(img,x,y,width,height,0,360);
}
- public inline function imageCircle(x:Int, y:Int, radius:Int,?filled:Bool=false):Void {
+ /**
+ * draws a circle
+ * @param x center x position
+ * @param y center y position
+ * @param radius
+ * @param ?filled
+ */
+ public inline function circle(x:Int, y:Int, radius:Int,?filled:Bool=false):Void {
if (filled)
gd_imageFilledArc(img,x,y,radius*2,radius*2,0,360,0);
else
gd_imageArc(img,x,y,radius*2,radius*2,0,360);
}
- public inline function imageArc(x:Int,y:Int, width:Int,height:Int, start:Int, end:Int, fillType:ArcFillType):Void {
+ /**
+ * draws a arc
+ * @param x center x position
+ * @param y center y position
+ * @param width
+ * @param height
+ * @param start starting degree of arc 0-360 smaller then end
+ * @param end ending degree of arc 0-360 larger then start
+ * @param fillType see ArcFillType
+ */
+ public inline function arc(x:Int,y:Int, width:Int,height:Int, start:Int, end:Int, fillType:ArcFillType):Void {
switch (fillType) {
case ArcFilled: gd_imageFilledArc(img,x,y,width,height,start,end,0);
case ArcOutline: gd_imageFilledArc(img,x,y,width,height,start,end,2);
@@ -141,11 +226,22 @@ class Graphics {
}
}
- public inline function imageFillToBorder(x:Int,y:Int, borderColor:Color):Void {
+ /**
+ * start to fill the image from the given position in all directions until the borderColor is reached
+ * @param x
+ * @param y
+ * @param borderColor
+ */
+ public inline function fillToBorder(x:Int,y:Int, borderColor:Color):Void {
gd_imageFillToBorder(img,x,y,borderColor.gd);
}
- public inline function imageFill(x:Int, y:Int) {
+ /**
+ * fills the image from starting point into all directions as long the current pixel color matches the pixel color of the starting point
+ * @param x
+ * @param y
+ */
+ public inline function fill(x:Int, y:Int) {
gd_imageFill(img,x,y);
}
@@ -155,11 +251,8 @@ class Graphics {
private static var gd_setPixel = Lib.load("nGD","SetPixel",3);
private static var gd_imageLine = Lib.load("nGD","ImageLine",5);
private static var gd_imageDashedLine = Lib.load("nGD","ImageDashedLine",5);
- private static var gd_imagePolygon = Lib.load("nGD","ImagePolygon",3);
- private static var gd_imageFilledPolygon = Lib.load("nGD","ImageFilledPolygon",3);
- private static var gd_imageOpenPolygon = Lib.load("nGD","ImageOpenPolygon",3);
- private static var gd_imageRectangle = Lib.load("nGD","ImageRectangle",5);
- private static var gd_imageFilledRectangle = Lib.load("nGD","ImageFilledRectangle",5);
+ private static var gd_imagePolygon = Lib.load("nGD","ImagePolygon",5);
+ private static var gd_imageRectangle = Lib.load("nGD","ImageRectangle",-1);
private static var gd_imageFilledEllipse = Lib.load("nGD","ImageFilledEllipse",5);
private static var gd_imageArc = Lib.load("nGD","ImageArc",-1);
private static var gd_imageFilledArc = Lib.load("nGD","ImageFilledArc",-1);
Oops, something went wrong.

0 comments on commit dfb9798

Please sign in to comment.