Noah Petherbridge
e1cbff8c3f
* Add ui.Window to easily create reusable windows with titles. * Add a palette window (panel) to the right edge of the Edit Mode. * Has Radio Buttons listing the colors available in the palette. * Add palette support to Edit Mode so when you draw pixels, they take on the color and attributes of the currently selected Swatch in your palette. * Revise the on-disk format to better serialize the Palette object to JSON. * Break Play Mode: collision detection fails because the Grid key elements are now full Pixel objects (which retain their Palette and Swatch properties). * The Grid will need to be re-worked to separate X,Y coordinates from the Pixel metadata to just test "is something there, and what is it?"
58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
// Package sdl provides an SDL2 renderer for Doodle.
|
|
package sdl
|
|
|
|
import (
|
|
"git.kirsle.net/apps/doodle/render"
|
|
"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.Blue, color.Green, 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)
|
|
}
|
|
r.renderer.DrawPoint(point.X, point.Y)
|
|
}
|
|
|
|
// 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)
|
|
}
|
|
r.renderer.DrawLine(a.X, a.Y, b.X, b.Y)
|
|
}
|
|
|
|
// 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{
|
|
X: rect.X,
|
|
Y: rect.Y,
|
|
W: rect.W,
|
|
H: rect.H,
|
|
})
|
|
}
|
|
|
|
// 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{
|
|
X: rect.X,
|
|
Y: rect.Y,
|
|
W: rect.W,
|
|
H: rect.H,
|
|
})
|
|
}
|