Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Amos Wenger
committed
Apr 21, 2012
1 parent
87ee5d9
commit f8352db
Showing
4 changed files
with
67 additions
and
3 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 |
---|---|---|
|
@@ -38,7 +38,6 @@ Display: class { | |
sdlSurface@ w, sdlSurface@ h, sdlSurface@ pitch) | ||
|
||
cairoContext = Context new(cairoSurface) | ||
|
||
} | ||
|
||
} |
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,63 @@ | ||
|
||
/* | ||
* A sprite is, in the large sense, anything that can be drawn onto a display. | ||
*/ | ||
|
||
use cairo | ||
import cairo/Cairo | ||
|
||
import Math, Display | ||
|
||
Sprite: class { | ||
|
||
pos := vec2(0.0, 0.0) | ||
offset := vec2(0.0, 0.0) | ||
scale := vec2(1.0, 1.0) | ||
color := vec3(1.0, 0.0, 0.0) | ||
|
||
alpha := 1.0 | ||
visible := true | ||
|
||
init: func (pos: Vec2) { | ||
this pos set!(pos) | ||
} | ||
|
||
draw: func (display: Display) { | ||
if (!visible) return | ||
|
||
cr := display cairoContext | ||
|
||
cr save() | ||
cr translate(pos x + offset x, pos y + offset y) | ||
cr scale(scale x, scale y) | ||
cr setSourceRGBA(color x, color y, color z, alpha) | ||
|
||
paint(cr) | ||
cr restore() | ||
} | ||
|
||
/* | ||
* This is the function you want to overload | ||
* when you have custom sprites | ||
*/ | ||
paint: func (cr: Context) { | ||
cr setLineWidth(3) | ||
|
||
cr moveTo(0, 0) | ||
cr lineTo(0, 50) | ||
cr relLineTo(50, 0) | ||
cr closePath() | ||
cr stroke() | ||
} | ||
|
||
/* | ||
* Free resources | ||
*/ | ||
free: func { | ||
// nothing to do here, but for text sprites etc., might be useful | ||
} | ||
|
||
} | ||
|
||
|
||
|
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