2019-04-10 00:35:44 +00:00
|
|
|
// Package sdl provides an SDL2 renderer for Doodle.
|
|
|
|
package sdl
|
|
|
|
|
|
|
|
import (
|
2019-12-22 23:53:52 +00:00
|
|
|
"git.kirsle.net/go/render"
|
2019-04-10 00:35:44 +00:00
|
|
|
"github.com/veandco/go-sdl2/sdl"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Clear the canvas and set this color.
|
|
|
|
func (r *Renderer) Clear(color render.Color) {
|
|
|
|
if color != r.lastColor {
|
|
|
|
r.renderer.SetDrawColor(color.Red, color.Green, color.Blue, color.Alpha)
|
|
|
|
}
|
|
|
|
r.renderer.Clear()
|
|
|
|
}
|
|
|
|
|
|
|
|
// DrawPoint puts a color at a pixel.
|
|
|
|
func (r *Renderer) DrawPoint(color render.Color, point render.Point) {
|
|
|
|
if color != r.lastColor {
|
|
|
|
r.renderer.SetDrawColor(color.Red, color.Green, color.Blue, color.Alpha)
|
|
|
|
}
|
2019-12-28 01:35:42 +00:00
|
|
|
r.renderer.DrawPoint(int32(point.X), int32(point.Y))
|
2019-04-10 00:35:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DrawLine draws a line between two points.
|
|
|
|
func (r *Renderer) DrawLine(color render.Color, a, b render.Point) {
|
|
|
|
if color != r.lastColor {
|
|
|
|
r.renderer.SetDrawColor(color.Red, color.Green, color.Blue, color.Alpha)
|
|
|
|
}
|
2019-12-28 01:35:42 +00:00
|
|
|
r.renderer.DrawLine(int32(a.X), int32(a.Y), int32(b.X), int32(b.Y))
|
2019-04-10 00:35:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DrawRect draws a rectangle.
|
|
|
|
func (r *Renderer) DrawRect(color render.Color, rect render.Rect) {
|
|
|
|
if color != r.lastColor {
|
|
|
|
r.renderer.SetDrawColor(color.Red, color.Green, color.Blue, color.Alpha)
|
|
|
|
}
|
|
|
|
r.renderer.DrawRect(&sdl.Rect{
|
2019-12-28 01:35:42 +00:00
|
|
|
X: int32(rect.X),
|
|
|
|
Y: int32(rect.Y),
|
|
|
|
W: int32(rect.W),
|
|
|
|
H: int32(rect.H),
|
2019-04-10 00:35:44 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// DrawBox draws a filled rectangle.
|
|
|
|
func (r *Renderer) DrawBox(color render.Color, rect render.Rect) {
|
|
|
|
if color != r.lastColor {
|
|
|
|
r.renderer.SetDrawColor(color.Red, color.Green, color.Blue, color.Alpha)
|
|
|
|
}
|
|
|
|
r.renderer.FillRect(&sdl.Rect{
|
2019-12-28 01:35:42 +00:00
|
|
|
X: int32(rect.X),
|
|
|
|
Y: int32(rect.Y),
|
|
|
|
W: int32(rect.W),
|
|
|
|
H: int32(rect.H),
|
2019-04-10 00:35:44 +00:00
|
|
|
})
|
|
|
|
}
|