Change types int32 -> int per upstream render and ui library
This commit is contained in:
parent
c1353d1c0f
commit
0437adfbf8
|
@ -7,7 +7,7 @@ var (
|
||||||
Height = 768
|
Height = 768
|
||||||
|
|
||||||
// Speed to scroll a canvas with arrow keys in Edit Mode.
|
// Speed to scroll a canvas with arrow keys in Edit Mode.
|
||||||
CanvasScrollSpeed int32 = 8
|
CanvasScrollSpeed = 8
|
||||||
|
|
||||||
// Window scrolling behavior in Play Mode.
|
// Window scrolling behavior in Play Mode.
|
||||||
ScrollboxHoz = 256 // horizontal px from window border to start scrol
|
ScrollboxHoz = 256 // horizontal px from window border to start scrol
|
||||||
|
|
|
@ -8,7 +8,7 @@ var (
|
||||||
ShellBackgroundColor = render.RGBA(0, 20, 40, 200)
|
ShellBackgroundColor = render.RGBA(0, 20, 40, 200)
|
||||||
ShellForegroundColor = render.RGBA(0, 153, 255, 255)
|
ShellForegroundColor = render.RGBA(0, 153, 255, 255)
|
||||||
ShellPromptColor = render.White
|
ShellPromptColor = render.White
|
||||||
ShellPadding int32 = 8
|
ShellPadding = 8
|
||||||
ShellFontSize = 16
|
ShellFontSize = 16
|
||||||
ShellFontSizeSmall = 10
|
ShellFontSizeSmall = 10
|
||||||
ShellCursorBlinkRate uint64 = 20
|
ShellCursorBlinkRate uint64 = 20
|
||||||
|
|
|
@ -102,11 +102,11 @@ The returned CollisionBox uses absolute coordinates in the same space
|
||||||
as the passed-in rects.
|
as the passed-in rects.
|
||||||
*/
|
*/
|
||||||
func Overlap(a, b render.Rect) CollisionBox {
|
func Overlap(a, b render.Rect) CollisionBox {
|
||||||
max := func(x, y int32) int32 {
|
max := func(x, y int) int {
|
||||||
return int32(math.Max(float64(x), float64(y)))
|
return int(math.Max(float64(x), float64(y)))
|
||||||
}
|
}
|
||||||
min := func(x, y int32) int32 {
|
min := func(x, y int) int {
|
||||||
return int32(math.Min(float64(x), float64(y)))
|
return int(math.Min(float64(x), float64(y)))
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -3,9 +3,9 @@ package collision
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"git.kirsle.net/go/render"
|
|
||||||
"git.kirsle.net/apps/doodle/pkg/doodads"
|
"git.kirsle.net/apps/doodle/pkg/doodads"
|
||||||
"git.kirsle.net/apps/doodle/pkg/level"
|
"git.kirsle.net/apps/doodle/pkg/level"
|
||||||
|
"git.kirsle.net/go/render"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Collide describes how a collision occurred.
|
// Collide describes how a collision occurred.
|
||||||
|
@ -61,13 +61,13 @@ func CollidesWithGrid(d doodads.Actor, grid *level.Chunker, target render.Point)
|
||||||
result = &Collide{
|
result = &Collide{
|
||||||
MoveTo: P,
|
MoveTo: P,
|
||||||
}
|
}
|
||||||
ceiling bool // Has hit a ceiling?
|
ceiling bool // Has hit a ceiling?
|
||||||
capHeight int32 // Stop vertical movement thru a ceiling
|
capHeight int // Stop vertical movement thru a ceiling
|
||||||
capLeft int32 // Stop movement thru a wall
|
capLeft int // Stop movement thru a wall
|
||||||
capRight int32
|
capRight int
|
||||||
capFloor int32 // Stop movement thru the floor
|
capFloor int // Stop movement thru the floor
|
||||||
hitLeft bool // Has hit an obstacle on the left
|
hitLeft bool // Has hit an obstacle on the left
|
||||||
hitRight bool // or right
|
hitRight bool // or right
|
||||||
hitFloor bool
|
hitFloor bool
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,10 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.kirsle.net/go/render"
|
|
||||||
"git.kirsle.net/apps/doodle/pkg/collision"
|
"git.kirsle.net/apps/doodle/pkg/collision"
|
||||||
"git.kirsle.net/apps/doodle/pkg/doodads/dummy"
|
"git.kirsle.net/apps/doodle/pkg/doodads/dummy"
|
||||||
"git.kirsle.net/apps/doodle/pkg/level"
|
"git.kirsle.net/apps/doodle/pkg/level"
|
||||||
|
"git.kirsle.net/go/render"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCollisionFunctions(t *testing.T) {
|
func TestCollisionFunctions(t *testing.T) {
|
||||||
|
@ -21,12 +21,12 @@ func TestCollisionFunctions(t *testing.T) {
|
||||||
|
|
||||||
// with a solid platform at y=500 and x=0..1000
|
// with a solid platform at y=500 and x=0..1000
|
||||||
for i := 0; i < 1000; i++ {
|
for i := 0; i < 1000; i++ {
|
||||||
grid.Set(render.NewPoint(int32(i), 500), solid)
|
grid.Set(render.NewPoint(i, 500), solid)
|
||||||
}
|
}
|
||||||
|
|
||||||
// and a short wall in the middle of the platform
|
// and a short wall in the middle of the platform
|
||||||
for i := 480; i < 500; i++ {
|
for i := 480; i < 500; i++ {
|
||||||
grid.Set(render.NewPoint(500, int32(i)), solid)
|
grid.Set(render.NewPoint(500, i), solid)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make a dummy player character.
|
// Make a dummy player character.
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package doodads
|
package doodads
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.kirsle.net/go/render"
|
|
||||||
"git.kirsle.net/apps/doodle/pkg/balance"
|
"git.kirsle.net/apps/doodle/pkg/balance"
|
||||||
"git.kirsle.net/apps/doodle/pkg/level"
|
"git.kirsle.net/apps/doodle/pkg/level"
|
||||||
|
"git.kirsle.net/go/render"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Doodad is a reusable component for Levels that have scripts and graphics.
|
// Doodad is a reusable component for Levels that have scripts and graphics.
|
||||||
|
@ -53,8 +53,8 @@ func (d *Doodad) ChunkSize() int {
|
||||||
func (d *Doodad) Rect() render.Rect {
|
func (d *Doodad) Rect() render.Rect {
|
||||||
var size = d.ChunkSize()
|
var size = d.ChunkSize()
|
||||||
return render.Rect{
|
return render.Rect{
|
||||||
W: int32(size),
|
W: size,
|
||||||
H: int32(size),
|
H: size,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package doodads
|
package doodads
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.kirsle.net/go/render"
|
|
||||||
"git.kirsle.net/apps/doodle/pkg/level"
|
"git.kirsle.net/apps/doodle/pkg/level"
|
||||||
|
"git.kirsle.net/go/render"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewDummy creates a placeholder dummy doodad with a giant "X" across it.
|
// NewDummy creates a placeholder dummy doodad with a giant "X" across it.
|
||||||
|
@ -16,8 +16,8 @@ func NewDummy(size int) *Doodad {
|
||||||
dummy.Palette.Swatches = []*level.Swatch{red}
|
dummy.Palette.Swatches = []*level.Swatch{red}
|
||||||
|
|
||||||
for i := 0; i < size; i++ {
|
for i := 0; i < size; i++ {
|
||||||
left := render.NewPoint(int32(i), int32(i))
|
left := render.NewPoint(i, i)
|
||||||
right := render.NewPoint(int32(size-i), int32(i))
|
right := render.NewPoint(size-i, i)
|
||||||
|
|
||||||
// Draw the stroke 2 pixels thick
|
// Draw the stroke 2 pixels thick
|
||||||
dummy.Layers[0].Chunker.Set(left, red)
|
dummy.Layers[0].Chunker.Set(left, red)
|
||||||
|
|
|
@ -114,7 +114,7 @@ func (d *Doodle) Run() error {
|
||||||
// Poll for events.
|
// Poll for events.
|
||||||
ev, err := d.Engine.Poll()
|
ev, err := d.Engine.Poll()
|
||||||
// log.Error("Button1 is: %+v", ev.Button1)
|
// log.Error("Button1 is: %+v", ev.Button1)
|
||||||
shmem.Cursor = render.NewPoint(int32(ev.CursorX), int32(ev.CursorY))
|
shmem.Cursor = render.NewPoint(ev.CursorX, ev.CursorY)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("event poll error: %s", err)
|
log.Error("event poll error: %s", err)
|
||||||
d.running = false
|
d.running = false
|
||||||
|
|
|
@ -111,10 +111,10 @@ func (s *Stroke) IterThickPoints() chan render.Rect {
|
||||||
go func() {
|
go func() {
|
||||||
for pt := range s.IterPoints() {
|
for pt := range s.IterPoints() {
|
||||||
ch <- render.Rect{
|
ch <- render.Rect{
|
||||||
X: pt.X - int32(s.Thickness),
|
X: pt.X - s.Thickness,
|
||||||
Y: pt.Y - int32(s.Thickness),
|
Y: pt.Y - s.Thickness,
|
||||||
W: int32(s.Thickness) * 2,
|
W: s.Thickness * 2,
|
||||||
H: int32(s.Thickness) * 2,
|
H: s.Thickness * 2,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close(ch)
|
close(ch)
|
||||||
|
|
|
@ -6,8 +6,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.kirsle.net/go/render"
|
|
||||||
"git.kirsle.net/go/render/event"
|
|
||||||
"git.kirsle.net/apps/doodle/pkg/balance"
|
"git.kirsle.net/apps/doodle/pkg/balance"
|
||||||
"git.kirsle.net/apps/doodle/pkg/doodads"
|
"git.kirsle.net/apps/doodle/pkg/doodads"
|
||||||
"git.kirsle.net/apps/doodle/pkg/drawtool"
|
"git.kirsle.net/apps/doodle/pkg/drawtool"
|
||||||
|
@ -15,6 +13,8 @@ import (
|
||||||
"git.kirsle.net/apps/doodle/pkg/level"
|
"git.kirsle.net/apps/doodle/pkg/level"
|
||||||
"git.kirsle.net/apps/doodle/pkg/log"
|
"git.kirsle.net/apps/doodle/pkg/log"
|
||||||
"git.kirsle.net/apps/doodle/pkg/userdir"
|
"git.kirsle.net/apps/doodle/pkg/userdir"
|
||||||
|
"git.kirsle.net/go/render"
|
||||||
|
"git.kirsle.net/go/render/event"
|
||||||
)
|
)
|
||||||
|
|
||||||
// EditorScene manages the "Edit Level" game mode.
|
// EditorScene manages the "Edit Level" game mode.
|
||||||
|
@ -136,7 +136,7 @@ func (s *EditorScene) Setup(d *Doodle) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: move inside the UI. Just an approximate position for now.
|
// TODO: move inside the UI. Just an approximate position for now.
|
||||||
s.UI.Canvas.Resize(render.NewRect(int32(s.DoodadSize), int32(s.DoodadSize)))
|
s.UI.Canvas.Resize(render.NewRect(s.DoodadSize, s.DoodadSize))
|
||||||
s.UI.Canvas.ScrollTo(render.Origin)
|
s.UI.Canvas.ScrollTo(render.Origin)
|
||||||
s.UI.Canvas.Scrollable = false
|
s.UI.Canvas.Scrollable = false
|
||||||
s.UI.Workspace.Compute(d.Engine)
|
s.UI.Workspace.Compute(d.Engine)
|
||||||
|
|
|
@ -5,9 +5,6 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"git.kirsle.net/go/render"
|
|
||||||
"git.kirsle.net/go/render/event"
|
|
||||||
"git.kirsle.net/go/ui"
|
|
||||||
"git.kirsle.net/apps/doodle/pkg/balance"
|
"git.kirsle.net/apps/doodle/pkg/balance"
|
||||||
"git.kirsle.net/apps/doodle/pkg/branding"
|
"git.kirsle.net/apps/doodle/pkg/branding"
|
||||||
"git.kirsle.net/apps/doodle/pkg/drawtool"
|
"git.kirsle.net/apps/doodle/pkg/drawtool"
|
||||||
|
@ -15,10 +12,13 @@ import (
|
||||||
"git.kirsle.net/apps/doodle/pkg/level"
|
"git.kirsle.net/apps/doodle/pkg/level"
|
||||||
"git.kirsle.net/apps/doodle/pkg/log"
|
"git.kirsle.net/apps/doodle/pkg/log"
|
||||||
"git.kirsle.net/apps/doodle/pkg/uix"
|
"git.kirsle.net/apps/doodle/pkg/uix"
|
||||||
|
"git.kirsle.net/go/render"
|
||||||
|
"git.kirsle.net/go/render/event"
|
||||||
|
"git.kirsle.net/go/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Width of the panel frame.
|
// Width of the panel frame.
|
||||||
var paletteWidth int32 = 160
|
var paletteWidth = 160
|
||||||
|
|
||||||
// EditorUI manages the user interface for the Editor Scene.
|
// EditorUI manages the user interface for the Editor Scene.
|
||||||
type EditorUI struct {
|
type EditorUI struct {
|
||||||
|
@ -52,7 +52,7 @@ type EditorUI struct {
|
||||||
doodadSkip int
|
doodadSkip int
|
||||||
doodadRows []*ui.Frame
|
doodadRows []*ui.Frame
|
||||||
doodadPager *ui.Frame
|
doodadPager *ui.Frame
|
||||||
doodadButtonSize int32
|
doodadButtonSize int
|
||||||
doodadScroller *ui.Frame
|
doodadScroller *ui.Frame
|
||||||
|
|
||||||
// ToolBar window.
|
// ToolBar window.
|
||||||
|
@ -130,7 +130,7 @@ func (u *EditorUI) Resized(d *Doodle) {
|
||||||
// Menu Bar frame.
|
// Menu Bar frame.
|
||||||
{
|
{
|
||||||
u.MenuBar.Configure(ui.Config{
|
u.MenuBar.Configure(ui.Config{
|
||||||
Width: int32(d.width),
|
Width: d.width,
|
||||||
Background: render.Black,
|
Background: render.Black,
|
||||||
})
|
})
|
||||||
u.MenuBar.Compute(d.Engine)
|
u.MenuBar.Compute(d.Engine)
|
||||||
|
@ -139,11 +139,11 @@ func (u *EditorUI) Resized(d *Doodle) {
|
||||||
// Status Bar.
|
// Status Bar.
|
||||||
{
|
{
|
||||||
u.StatusBar.Configure(ui.Config{
|
u.StatusBar.Configure(ui.Config{
|
||||||
Width: int32(d.width),
|
Width: d.width,
|
||||||
})
|
})
|
||||||
u.StatusBar.MoveTo(render.Point{
|
u.StatusBar.MoveTo(render.Point{
|
||||||
X: 0,
|
X: 0,
|
||||||
Y: int32(d.height) - u.StatusBar.Size().H,
|
Y: d.height - u.StatusBar.Size().H,
|
||||||
})
|
})
|
||||||
u.StatusBar.Compute(d.Engine)
|
u.StatusBar.Compute(d.Engine)
|
||||||
}
|
}
|
||||||
|
@ -152,10 +152,10 @@ func (u *EditorUI) Resized(d *Doodle) {
|
||||||
{
|
{
|
||||||
u.Palette.Configure(ui.Config{
|
u.Palette.Configure(ui.Config{
|
||||||
Width: paletteWidth,
|
Width: paletteWidth,
|
||||||
Height: int32(u.d.height) - u.StatusBar.Size().H,
|
Height: u.d.height - u.StatusBar.Size().H,
|
||||||
})
|
})
|
||||||
u.Palette.MoveTo(render.NewPoint(
|
u.Palette.MoveTo(render.NewPoint(
|
||||||
int32(u.d.width)-u.Palette.BoxSize().W,
|
u.d.width-u.Palette.BoxSize().W,
|
||||||
u.MenuBar.BoxSize().H,
|
u.MenuBar.BoxSize().H,
|
||||||
))
|
))
|
||||||
u.Palette.Compute(d.Engine)
|
u.Palette.Compute(d.Engine)
|
||||||
|
@ -163,7 +163,7 @@ func (u *EditorUI) Resized(d *Doodle) {
|
||||||
u.scrollDoodadFrame(0)
|
u.scrollDoodadFrame(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
var innerHeight = int32(u.d.height) - u.MenuBar.Size().H - u.StatusBar.Size().H
|
var innerHeight = u.d.height - u.MenuBar.Size().H - u.StatusBar.Size().H
|
||||||
|
|
||||||
// Tool Bar.
|
// Tool Bar.
|
||||||
{
|
{
|
||||||
|
@ -187,8 +187,8 @@ func (u *EditorUI) Resized(d *Doodle) {
|
||||||
u.MenuBar.Size().H,
|
u.MenuBar.Size().H,
|
||||||
))
|
))
|
||||||
frame.Resize(render.NewRect(
|
frame.Resize(render.NewRect(
|
||||||
int32(d.width)-u.Palette.Size().W-u.ToolBar.Size().W,
|
d.width-u.Palette.Size().W-u.ToolBar.Size().W,
|
||||||
int32(d.height)-u.MenuBar.Size().H-u.StatusBar.Size().H,
|
d.height-u.MenuBar.Size().H-u.StatusBar.Size().H,
|
||||||
))
|
))
|
||||||
frame.Compute(d.Engine)
|
frame.Compute(d.Engine)
|
||||||
|
|
||||||
|
@ -201,10 +201,10 @@ func (u *EditorUI) Resized(d *Doodle) {
|
||||||
btn.Compute(d.Engine)
|
btn.Compute(d.Engine)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
wsP = u.Workspace.Point()
|
wsP = u.Workspace.Point()
|
||||||
wsSize = u.Workspace.Size()
|
wsSize = u.Workspace.Size()
|
||||||
btnSize = btn.Size()
|
btnSize = btn.Size()
|
||||||
padding int32 = 8
|
padding = 8
|
||||||
)
|
)
|
||||||
btn.MoveTo(render.NewPoint(
|
btn.MoveTo(render.NewPoint(
|
||||||
wsP.X+wsSize.W-btnSize.W-padding,
|
wsP.X+wsSize.W-btnSize.W-padding,
|
||||||
|
@ -215,7 +215,7 @@ func (u *EditorUI) Resized(d *Doodle) {
|
||||||
|
|
||||||
// Loop to process events and update the UI.
|
// Loop to process events and update the UI.
|
||||||
func (u *EditorUI) Loop(ev *event.State) error {
|
func (u *EditorUI) Loop(ev *event.State) error {
|
||||||
u.cursor = render.NewPoint(int32(ev.CursorX), int32(ev.CursorY))
|
u.cursor = render.NewPoint(ev.CursorX, ev.CursorY)
|
||||||
|
|
||||||
// Loop the UI and see whether we're told to stop event propagation.
|
// Loop the UI and see whether we're told to stop event propagation.
|
||||||
var stopPropagation bool
|
var stopPropagation bool
|
||||||
|
@ -537,7 +537,7 @@ func (u *EditorUI) SetupStatusBar(d *Doodle) *ui.Frame {
|
||||||
BorderSize: 1,
|
BorderSize: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
var labelHeight int32
|
var labelHeight int
|
||||||
for _, variable := range u.StatusBoxes {
|
for _, variable := range u.StatusBoxes {
|
||||||
label := ui.NewLabel(ui.Label{
|
label := ui.NewLabel(ui.Label{
|
||||||
TextVariable: variable,
|
TextVariable: variable,
|
||||||
|
@ -577,7 +577,7 @@ func (u *EditorUI) SetupStatusBar(d *Doodle) *ui.Frame {
|
||||||
// Set the initial good frame size to have the height secured,
|
// Set the initial good frame size to have the height secured,
|
||||||
// so when resizing the application window we can just adjust for width.
|
// so when resizing the application window we can just adjust for width.
|
||||||
frame.Resize(render.Rect{
|
frame.Resize(render.Rect{
|
||||||
W: int32(d.width),
|
W: d.width,
|
||||||
H: labelHeight + frame.BoxThickness(1),
|
H: labelHeight + frame.BoxThickness(1),
|
||||||
})
|
})
|
||||||
frame.Compute(d.Engine)
|
frame.Compute(d.Engine)
|
||||||
|
|
|
@ -7,13 +7,13 @@ package doodle
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.kirsle.net/go/render"
|
|
||||||
"git.kirsle.net/go/ui"
|
|
||||||
"git.kirsle.net/apps/doodle/pkg/balance"
|
"git.kirsle.net/apps/doodle/pkg/balance"
|
||||||
"git.kirsle.net/apps/doodle/pkg/doodads"
|
"git.kirsle.net/apps/doodle/pkg/doodads"
|
||||||
"git.kirsle.net/apps/doodle/pkg/level"
|
"git.kirsle.net/apps/doodle/pkg/level"
|
||||||
"git.kirsle.net/apps/doodle/pkg/log"
|
"git.kirsle.net/apps/doodle/pkg/log"
|
||||||
"git.kirsle.net/apps/doodle/pkg/uix"
|
"git.kirsle.net/apps/doodle/pkg/uix"
|
||||||
|
"git.kirsle.net/go/render"
|
||||||
|
"git.kirsle.net/go/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DraggableActor is a Doodad being dragged from the Doodad palette.
|
// DraggableActor is a Doodad being dragged from the Doodad palette.
|
||||||
|
@ -123,7 +123,7 @@ func (u *EditorUI) setupDoodadFrame(e render.Engine, window *ui.Window) (*ui.Fra
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
var buttonSize = (paletteWidth - window.BoxThickness(2)) / int32(perRow)
|
var buttonSize = (paletteWidth - window.BoxThickness(2)) / perRow
|
||||||
u.doodadButtonSize = buttonSize
|
u.doodadButtonSize = buttonSize
|
||||||
|
|
||||||
// Load all the doodads, skip hidden ones.
|
// Load all the doodads, skip hidden ones.
|
||||||
|
@ -218,8 +218,8 @@ func (u *EditorUI) scrollDoodadFrame(rows int) {
|
||||||
|
|
||||||
// Calculate about how many rows we can see given our current window size.
|
// Calculate about how many rows we can see given our current window size.
|
||||||
var (
|
var (
|
||||||
maxVisibleHeight = int32(u.d.height - 86)
|
maxVisibleHeight = u.d.height - 86
|
||||||
calculatedHeight int32
|
calculatedHeight int
|
||||||
rowsBefore int // count of rows hidden before
|
rowsBefore int // count of rows hidden before
|
||||||
rowsVisible int
|
rowsVisible int
|
||||||
rowsAfter int // count of rows hidden after
|
rowsAfter int // count of rows hidden after
|
||||||
|
@ -263,7 +263,7 @@ func (u *EditorUI) scrollDoodadFrame(rows int) {
|
||||||
|
|
||||||
var viewPercent = float64(rowsBefore+rowsVisible) / float64(len(u.doodadRows))
|
var viewPercent = float64(rowsBefore+rowsVisible) / float64(len(u.doodadRows))
|
||||||
u.doodadScroller.Configure(ui.Config{
|
u.doodadScroller.Configure(ui.Config{
|
||||||
Width: int32(float64(paletteWidth-50) * viewPercent), // TODO: hacky magic number
|
Width: int(float64(paletteWidth-50) * viewPercent), // TODO: hacky magic number
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
package doodle
|
package doodle
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.kirsle.net/go/render"
|
|
||||||
"git.kirsle.net/go/ui"
|
|
||||||
"git.kirsle.net/apps/doodle/pkg/balance"
|
"git.kirsle.net/apps/doodle/pkg/balance"
|
||||||
"git.kirsle.net/apps/doodle/pkg/drawtool"
|
"git.kirsle.net/apps/doodle/pkg/drawtool"
|
||||||
"git.kirsle.net/apps/doodle/pkg/sprites"
|
"git.kirsle.net/apps/doodle/pkg/sprites"
|
||||||
|
"git.kirsle.net/go/render"
|
||||||
|
"git.kirsle.net/go/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Width of the toolbar frame.
|
// Width of the toolbar frame.
|
||||||
var toolbarWidth int32 = 44 // 38px button (32px sprite + borders) + padding
|
var toolbarWidth = 44 // 38px button (32px sprite + borders) + padding
|
||||||
var toolbarSpriteSize int32 = 32 // 32x32 sprites.
|
var toolbarSpriteSize = 32 // 32x32 sprites.
|
||||||
|
|
||||||
// SetupToolbar configures the UI for the Tools panel.
|
// SetupToolbar configures the UI for the Tools panel.
|
||||||
func (u *EditorUI) SetupToolbar(d *Doodle) *ui.Frame {
|
func (u *EditorUI) SetupToolbar(d *Doodle) *ui.Frame {
|
||||||
|
@ -137,7 +137,7 @@ func (u *EditorUI) SetupToolbar(d *Doodle) *ui.Frame {
|
||||||
image,
|
image,
|
||||||
)
|
)
|
||||||
|
|
||||||
var btnSize int32 = btn.BoxThickness(2) + toolbarSpriteSize
|
var btnSize = btn.BoxThickness(2) + toolbarSpriteSize
|
||||||
btn.Resize(render.NewRect(btnSize, btnSize))
|
btn.Resize(render.NewRect(btnSize, btnSize))
|
||||||
|
|
||||||
btn.Handle(ui.Click, func(p render.Point) {
|
btn.Handle(ui.Click, func(p render.Point) {
|
||||||
|
|
22
pkg/fps.go
22
pkg/fps.go
|
@ -4,11 +4,11 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.kirsle.net/go/render"
|
|
||||||
"git.kirsle.net/go/ui"
|
|
||||||
"git.kirsle.net/apps/doodle/pkg/balance"
|
"git.kirsle.net/apps/doodle/pkg/balance"
|
||||||
"git.kirsle.net/apps/doodle/pkg/collision"
|
"git.kirsle.net/apps/doodle/pkg/collision"
|
||||||
"git.kirsle.net/apps/doodle/pkg/doodads"
|
"git.kirsle.net/apps/doodle/pkg/doodads"
|
||||||
|
"git.kirsle.net/go/render"
|
||||||
|
"git.kirsle.net/go/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Frames to cache for FPS calculation.
|
// Frames to cache for FPS calculation.
|
||||||
|
@ -20,11 +20,11 @@ var (
|
||||||
DebugOverlay = false
|
DebugOverlay = false
|
||||||
DebugCollision = false
|
DebugCollision = false
|
||||||
|
|
||||||
DebugTextPadding int32 = 8
|
DebugTextPadding = 8
|
||||||
DebugTextSize = 24
|
DebugTextSize = 24
|
||||||
DebugTextColor = render.SkyBlue
|
DebugTextColor = render.SkyBlue
|
||||||
DebugTextStroke = render.Grey
|
DebugTextStroke = render.Grey
|
||||||
DebugTextShadow = render.Black
|
DebugTextShadow = render.Black
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -57,10 +57,10 @@ func (d *Doodle) DrawDebugOverlay() {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
darken = balance.DebugStrokeDarken
|
darken = balance.DebugStrokeDarken
|
||||||
Yoffset int32 = 20 // leave room for the menu bar
|
Yoffset = 20 // leave room for the menu bar
|
||||||
Xoffset int32 = 20
|
Xoffset = 20
|
||||||
keys = []string{
|
keys = []string{
|
||||||
"FPS:",
|
"FPS:",
|
||||||
"Scene:",
|
"Scene:",
|
||||||
"Mouse:",
|
"Mouse:",
|
||||||
|
|
|
@ -3,12 +3,12 @@ package doodle
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.kirsle.net/go/render"
|
|
||||||
"git.kirsle.net/go/render/event"
|
|
||||||
"git.kirsle.net/go/ui"
|
|
||||||
"git.kirsle.net/apps/doodle/pkg/balance"
|
"git.kirsle.net/apps/doodle/pkg/balance"
|
||||||
"git.kirsle.net/apps/doodle/pkg/branding"
|
"git.kirsle.net/apps/doodle/pkg/branding"
|
||||||
"git.kirsle.net/apps/doodle/pkg/log"
|
"git.kirsle.net/apps/doodle/pkg/log"
|
||||||
|
"git.kirsle.net/go/render"
|
||||||
|
"git.kirsle.net/go/render/event"
|
||||||
|
"git.kirsle.net/go/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GUITestScene implements the main menu of Doodle.
|
// GUITestScene implements the main menu of Doodle.
|
||||||
|
@ -269,14 +269,14 @@ func (s *GUITestScene) Draw(d *Doodle) error {
|
||||||
})
|
})
|
||||||
label.Compute(d.Engine)
|
label.Compute(d.Engine)
|
||||||
label.MoveTo(render.Point{
|
label.MoveTo(render.Point{
|
||||||
X: (int32(d.width) / 2) - (label.Size().W / 2),
|
X: (d.width / 2) - (label.Size().W / 2),
|
||||||
Y: 40,
|
Y: 40,
|
||||||
})
|
})
|
||||||
label.Present(d.Engine, label.Point())
|
label.Present(d.Engine, label.Point())
|
||||||
|
|
||||||
s.Window.Compute(d.Engine)
|
s.Window.Compute(d.Engine)
|
||||||
s.Window.MoveTo(render.Point{
|
s.Window.MoveTo(render.Point{
|
||||||
X: (int32(d.width) / 2) - (s.Window.Size().W / 2),
|
X: (d.width / 2) - (s.Window.Size().W / 2),
|
||||||
Y: 100,
|
Y: 100,
|
||||||
})
|
})
|
||||||
s.Window.Present(d.Engine, s.Window.Point())
|
s.Window.Present(d.Engine, s.Window.Point())
|
||||||
|
|
|
@ -6,10 +6,10 @@ import (
|
||||||
"image"
|
"image"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"git.kirsle.net/go/render"
|
|
||||||
"git.kirsle.net/apps/doodle/pkg/balance"
|
"git.kirsle.net/apps/doodle/pkg/balance"
|
||||||
"git.kirsle.net/apps/doodle/pkg/log"
|
"git.kirsle.net/apps/doodle/pkg/log"
|
||||||
"git.kirsle.net/apps/doodle/pkg/shmem"
|
"git.kirsle.net/apps/doodle/pkg/shmem"
|
||||||
|
"git.kirsle.net/go/render"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/vmihailenco/msgpack"
|
"github.com/vmihailenco/msgpack"
|
||||||
)
|
)
|
||||||
|
@ -153,8 +153,8 @@ func (c *Chunk) ToBitmap(filename string, mask render.Color) (render.Texturer, e
|
||||||
// Pixel coordinate offset to map the Chunk World Position to the
|
// Pixel coordinate offset to map the Chunk World Position to the
|
||||||
// smaller image boundaries.
|
// smaller image boundaries.
|
||||||
pointOffset := render.Point{
|
pointOffset := render.Point{
|
||||||
X: int32(c.Point.X * int32(c.Size)),
|
X: c.Point.X * c.Size,
|
||||||
Y: int32(c.Point.Y * int32(c.Size)),
|
Y: c.Point.Y * c.Size,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Blot all the pixels onto it.
|
// Blot all the pixels onto it.
|
||||||
|
@ -169,8 +169,8 @@ func (c *Chunk) ToBitmap(filename string, mask render.Color) (render.Texturer, e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
img.Set(
|
img.Set(
|
||||||
int(px.X-pointOffset.X),
|
px.X-pointOffset.X,
|
||||||
int(px.Y-pointOffset.Y),
|
px.Y-pointOffset.Y,
|
||||||
color.ToColor(),
|
color.ToColor(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -229,8 +229,8 @@ func (c *Chunk) Rect() render.Rect {
|
||||||
func (c *Chunk) SizePositive() render.Rect {
|
func (c *Chunk) SizePositive() render.Rect {
|
||||||
S := c.Rect()
|
S := c.Rect()
|
||||||
return render.Rect{
|
return render.Rect{
|
||||||
W: int32(math.Abs(float64(S.X))) + S.W,
|
W: int(math.Abs(float64(S.X))) + S.W,
|
||||||
H: int32(math.Abs(float64(S.Y))) + S.H,
|
H: int(math.Abs(float64(S.Y))) + S.H,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"git.kirsle.net/go/render"
|
|
||||||
"git.kirsle.net/apps/doodle/pkg/log"
|
"git.kirsle.net/apps/doodle/pkg/log"
|
||||||
|
"git.kirsle.net/go/render"
|
||||||
"github.com/vmihailenco/msgpack"
|
"github.com/vmihailenco/msgpack"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -76,8 +76,8 @@ func (c *Chunker) IterViewportChunks(viewport render.Rect) <-chan render.Point {
|
||||||
go func() {
|
go func() {
|
||||||
sent := make(map[render.Point]interface{})
|
sent := make(map[render.Point]interface{})
|
||||||
|
|
||||||
for x := viewport.X; x < viewport.W; x += int32(c.Size / 4) {
|
for x := viewport.X; x < viewport.W; x += (c.Size / 4) {
|
||||||
for y := viewport.Y; y < viewport.H; y += int32(c.Size / 4) {
|
for y := viewport.Y; y < viewport.H; y += (c.Size / 4) {
|
||||||
|
|
||||||
// Constrain this chunksize step to a point within the bounds
|
// Constrain this chunksize step to a point within the bounds
|
||||||
// of the viewport. This can yield partial chunks on the edges
|
// of the viewport. This can yield partial chunks on the edges
|
||||||
|
@ -135,7 +135,7 @@ func (c *Chunker) WorldSize() render.Rect {
|
||||||
var (
|
var (
|
||||||
chunkLowest render.Point
|
chunkLowest render.Point
|
||||||
chunkHighest render.Point
|
chunkHighest render.Point
|
||||||
size = int32(c.Size)
|
size = c.Size
|
||||||
)
|
)
|
||||||
|
|
||||||
for coord := range c.Chunks {
|
for coord := range c.Chunks {
|
||||||
|
@ -169,8 +169,8 @@ func (c *Chunker) WorldSizePositive() render.Rect {
|
||||||
return render.Rect{
|
return render.Rect{
|
||||||
X: 0,
|
X: 0,
|
||||||
Y: 0,
|
Y: 0,
|
||||||
W: int32(math.Abs(float64(S.X))) + S.W,
|
W: int(math.Abs(float64(S.X))) + S.W,
|
||||||
H: int32(math.Abs(float64(S.Y))) + S.H,
|
H: int(math.Abs(float64(S.Y))) + S.H,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,8 +271,8 @@ func (c *Chunker) ChunkCoordinate(abs render.Point) render.Point {
|
||||||
|
|
||||||
size := float64(c.Size)
|
size := float64(c.Size)
|
||||||
return render.NewPoint(
|
return render.NewPoint(
|
||||||
int32(math.Floor(float64(abs.X)/size)),
|
int(math.Floor(float64(abs.X)/size)),
|
||||||
int32(math.Floor(float64(abs.Y)/size)),
|
int(math.Floor(float64(abs.Y)/size)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.kirsle.net/go/render"
|
|
||||||
"git.kirsle.net/apps/doodle/pkg/level"
|
"git.kirsle.net/apps/doodle/pkg/level"
|
||||||
|
"git.kirsle.net/go/render"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestWorldSize(t *testing.T) {
|
func TestWorldSize(t *testing.T) {
|
||||||
|
@ -86,8 +86,8 @@ func TestWorldSize(t *testing.T) {
|
||||||
|
|
||||||
func TestViewportChunks(t *testing.T) {
|
func TestViewportChunks(t *testing.T) {
|
||||||
// Initialize a 100 chunk image with 5x5 chunks.
|
// Initialize a 100 chunk image with 5x5 chunks.
|
||||||
var ChunkSize int32 = 100
|
var ChunkSize int = 100
|
||||||
var Offset int32 = 50
|
var Offset int = 50
|
||||||
c := level.NewChunker(int(ChunkSize))
|
c := level.NewChunker(int(ChunkSize))
|
||||||
sw := &level.Swatch{
|
sw := &level.Swatch{
|
||||||
Name: "solid",
|
Name: "solid",
|
||||||
|
@ -103,8 +103,8 @@ func TestViewportChunks(t *testing.T) {
|
||||||
// The chunk size is 100px so place a single pixel in each
|
// The chunk size is 100px so place a single pixel in each
|
||||||
// 100px quadrant.
|
// 100px quadrant.
|
||||||
fmt.Printf("size=%d offset=%d\n", ChunkSize, Offset)
|
fmt.Printf("size=%d offset=%d\n", ChunkSize, Offset)
|
||||||
for x := int32(-2); x <= 2; x++ {
|
for x := -2; x <= 2; x++ {
|
||||||
for y := int32(-2); y <= 2; y++ {
|
for y := -2; y <= 2; y++ {
|
||||||
point := render.NewPoint(
|
point := render.NewPoint(
|
||||||
x*ChunkSize+Offset,
|
x*ChunkSize+Offset,
|
||||||
y*ChunkSize+Offset,
|
y*ChunkSize+Offset,
|
||||||
|
|
|
@ -4,9 +4,9 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.kirsle.net/go/render"
|
|
||||||
"git.kirsle.net/apps/doodle/pkg/balance"
|
"git.kirsle.net/apps/doodle/pkg/balance"
|
||||||
"git.kirsle.net/apps/doodle/pkg/drawtool"
|
"git.kirsle.net/apps/doodle/pkg/drawtool"
|
||||||
|
"git.kirsle.net/go/render"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Useful variables.
|
// Useful variables.
|
||||||
|
@ -73,9 +73,9 @@ func New() *Level {
|
||||||
|
|
||||||
// Pixel associates a coordinate with a palette index.
|
// Pixel associates a coordinate with a palette index.
|
||||||
type Pixel struct {
|
type Pixel struct {
|
||||||
X int32 `json:"x"`
|
X int `json:"x"`
|
||||||
Y int32 `json:"y"`
|
Y int `json:"y"`
|
||||||
PaletteIndex int32 `json:"p"`
|
PaletteIndex int `json:"p"`
|
||||||
|
|
||||||
// Private runtime values.
|
// Private runtime values.
|
||||||
Swatch *Swatch `json:"-"` // pointer to its swatch, for when rendered.
|
Swatch *Swatch `json:"-"` // pointer to its swatch, for when rendered.
|
||||||
|
@ -103,7 +103,7 @@ func (p Pixel) MarshalJSON() ([]byte, error) {
|
||||||
|
|
||||||
// UnmarshalJSON loads a Pixel from JSON again.
|
// UnmarshalJSON loads a Pixel from JSON again.
|
||||||
func (p *Pixel) UnmarshalJSON(text []byte) error {
|
func (p *Pixel) UnmarshalJSON(text []byte) error {
|
||||||
var triplet []int32
|
var triplet []int
|
||||||
err := json.Unmarshal(text, &triplet)
|
err := json.Unmarshal(text, &triplet)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
package doodle
|
package doodle
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.kirsle.net/go/render"
|
|
||||||
"git.kirsle.net/go/render/event"
|
|
||||||
"git.kirsle.net/go/ui"
|
|
||||||
"git.kirsle.net/apps/doodle/pkg/balance"
|
"git.kirsle.net/apps/doodle/pkg/balance"
|
||||||
"git.kirsle.net/apps/doodle/pkg/branding"
|
"git.kirsle.net/apps/doodle/pkg/branding"
|
||||||
"git.kirsle.net/apps/doodle/pkg/level"
|
"git.kirsle.net/apps/doodle/pkg/level"
|
||||||
"git.kirsle.net/apps/doodle/pkg/log"
|
"git.kirsle.net/apps/doodle/pkg/log"
|
||||||
"git.kirsle.net/apps/doodle/pkg/scripting"
|
"git.kirsle.net/apps/doodle/pkg/scripting"
|
||||||
"git.kirsle.net/apps/doodle/pkg/uix"
|
"git.kirsle.net/apps/doodle/pkg/uix"
|
||||||
|
"git.kirsle.net/go/render"
|
||||||
|
"git.kirsle.net/go/render/event"
|
||||||
|
"git.kirsle.net/go/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MainScene implements the main menu of Doodle.
|
// MainScene implements the main menu of Doodle.
|
||||||
|
@ -84,8 +84,8 @@ func (s *MainScene) SetupDemoLevel(d *Doodle) error {
|
||||||
s.canvas = uix.NewCanvas(100, false)
|
s.canvas = uix.NewCanvas(100, false)
|
||||||
s.canvas.Scrollable = true
|
s.canvas.Scrollable = true
|
||||||
s.canvas.Resize(render.Rect{
|
s.canvas.Resize(render.Rect{
|
||||||
W: int32(d.width),
|
W: d.width,
|
||||||
H: int32(d.height),
|
H: d.height,
|
||||||
})
|
})
|
||||||
|
|
||||||
s.scripting = scripting.NewSupervisor()
|
s.scripting = scripting.NewSupervisor()
|
||||||
|
@ -128,8 +128,8 @@ func (s *MainScene) Loop(d *Doodle, ev *event.State) error {
|
||||||
d.height = h
|
d.height = h
|
||||||
log.Info("Resized to %dx%d", d.width, d.height)
|
log.Info("Resized to %dx%d", d.width, d.height)
|
||||||
s.canvas.Resize(render.Rect{
|
s.canvas.Resize(render.Rect{
|
||||||
W: int32(d.width),
|
W: d.width,
|
||||||
H: int32(d.height),
|
H: d.height,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,8 +147,8 @@ func (s *MainScene) Draw(d *Doodle) error {
|
||||||
d.Engine.DrawBox(render.RGBA(255, 255, 254, 128), render.Rect{
|
d.Engine.DrawBox(render.RGBA(255, 255, 254, 128), render.Rect{
|
||||||
X: 0,
|
X: 0,
|
||||||
Y: 0,
|
Y: 0,
|
||||||
W: int32(d.width),
|
W: d.width,
|
||||||
H: int32(d.height),
|
H: d.height,
|
||||||
})
|
})
|
||||||
|
|
||||||
label := ui.NewLabel(ui.Label{
|
label := ui.NewLabel(ui.Label{
|
||||||
|
@ -162,14 +162,14 @@ func (s *MainScene) Draw(d *Doodle) error {
|
||||||
})
|
})
|
||||||
label.Compute(d.Engine)
|
label.Compute(d.Engine)
|
||||||
label.MoveTo(render.Point{
|
label.MoveTo(render.Point{
|
||||||
X: (int32(d.width) / 2) - (label.Size().W / 2),
|
X: (d.width / 2) - (label.Size().W / 2),
|
||||||
Y: 120,
|
Y: 120,
|
||||||
})
|
})
|
||||||
label.Present(d.Engine, label.Point())
|
label.Present(d.Engine, label.Point())
|
||||||
|
|
||||||
s.frame.Compute(d.Engine)
|
s.frame.Compute(d.Engine)
|
||||||
s.frame.MoveTo(render.Point{
|
s.frame.MoveTo(render.Point{
|
||||||
X: (int32(d.width) / 2) - (s.frame.Size().W / 2),
|
X: (d.width / 2) - (s.frame.Size().W / 2),
|
||||||
Y: 260,
|
Y: 260,
|
||||||
})
|
})
|
||||||
s.frame.Present(d.Engine, s.frame.Point())
|
s.frame.Present(d.Engine, s.frame.Point())
|
||||||
|
|
|
@ -3,15 +3,15 @@ package doodle
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.kirsle.net/go/render"
|
|
||||||
"git.kirsle.net/go/render/event"
|
|
||||||
"git.kirsle.net/go/ui"
|
|
||||||
"git.kirsle.net/apps/doodle/pkg/balance"
|
"git.kirsle.net/apps/doodle/pkg/balance"
|
||||||
"git.kirsle.net/apps/doodle/pkg/enum"
|
"git.kirsle.net/apps/doodle/pkg/enum"
|
||||||
"git.kirsle.net/apps/doodle/pkg/level"
|
"git.kirsle.net/apps/doodle/pkg/level"
|
||||||
"git.kirsle.net/apps/doodle/pkg/log"
|
"git.kirsle.net/apps/doodle/pkg/log"
|
||||||
"git.kirsle.net/apps/doodle/pkg/uix"
|
"git.kirsle.net/apps/doodle/pkg/uix"
|
||||||
"git.kirsle.net/apps/doodle/pkg/userdir"
|
"git.kirsle.net/apps/doodle/pkg/userdir"
|
||||||
|
"git.kirsle.net/go/render"
|
||||||
|
"git.kirsle.net/go/render/event"
|
||||||
|
"git.kirsle.net/go/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -82,8 +82,8 @@ func (s *MenuScene) Setup(d *Doodle) error {
|
||||||
// Set up the background wallpaper canvas.
|
// Set up the background wallpaper canvas.
|
||||||
s.canvas = uix.NewCanvas(100, false)
|
s.canvas = uix.NewCanvas(100, false)
|
||||||
s.canvas.Resize(render.Rect{
|
s.canvas.Resize(render.Rect{
|
||||||
W: int32(d.width),
|
W: d.width,
|
||||||
H: int32(d.height),
|
H: d.height,
|
||||||
})
|
})
|
||||||
s.canvas.LoadLevel(d.Engine, &level.Level{
|
s.canvas.LoadLevel(d.Engine, &level.Level{
|
||||||
Chunker: level.NewChunker(100),
|
Chunker: level.NewChunker(100),
|
||||||
|
@ -127,8 +127,8 @@ func (s *MenuScene) setupNewWindow(d *Doodle) error {
|
||||||
|
|
||||||
window := ui.NewWindow("New Drawing")
|
window := ui.NewWindow("New Drawing")
|
||||||
window.Configure(ui.Config{
|
window.Configure(ui.Config{
|
||||||
Width: int32(float64(d.width) * 0.75),
|
Width: int(float64(d.width) * 0.75),
|
||||||
Height: int32(float64(d.height) * 0.75),
|
Height: int(float64(d.height) * 0.75),
|
||||||
Background: render.Grey,
|
Background: render.Grey,
|
||||||
})
|
})
|
||||||
window.Compute(d.Engine)
|
window.Compute(d.Engine)
|
||||||
|
@ -324,8 +324,8 @@ func (s *MenuScene) setupNewWindow(d *Doodle) error {
|
||||||
func (s *MenuScene) setupLoadWindow(d *Doodle) error {
|
func (s *MenuScene) setupLoadWindow(d *Doodle) error {
|
||||||
window := ui.NewWindow("Open Drawing")
|
window := ui.NewWindow("Open Drawing")
|
||||||
window.Configure(ui.Config{
|
window.Configure(ui.Config{
|
||||||
Width: int32(float64(d.width) * 0.75),
|
Width: int(float64(d.width) * 0.75),
|
||||||
Height: int32(float64(d.height) * 0.75),
|
Height: int(float64(d.height) * 0.75),
|
||||||
Background: render.Grey,
|
Background: render.Grey,
|
||||||
})
|
})
|
||||||
window.Compute(d.Engine)
|
window.Compute(d.Engine)
|
||||||
|
@ -508,7 +508,7 @@ func (s *MenuScene) Draw(d *Doodle) error {
|
||||||
|
|
||||||
s.window.Compute(d.Engine)
|
s.window.Compute(d.Engine)
|
||||||
s.window.MoveTo(render.Point{
|
s.window.MoveTo(render.Point{
|
||||||
X: (int32(d.width) / 2) - (s.window.Size().W / 2),
|
X: (d.width / 2) - (s.window.Size().W / 2),
|
||||||
Y: 60,
|
Y: 60,
|
||||||
})
|
})
|
||||||
s.window.Present(d.Engine, s.window.Point())
|
s.window.Present(d.Engine, s.window.Point())
|
||||||
|
|
|
@ -3,9 +3,6 @@ package doodle
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.kirsle.net/go/render"
|
|
||||||
"git.kirsle.net/go/render/event"
|
|
||||||
"git.kirsle.net/go/ui"
|
|
||||||
"git.kirsle.net/apps/doodle/pkg/balance"
|
"git.kirsle.net/apps/doodle/pkg/balance"
|
||||||
"git.kirsle.net/apps/doodle/pkg/collision"
|
"git.kirsle.net/apps/doodle/pkg/collision"
|
||||||
"git.kirsle.net/apps/doodle/pkg/doodads"
|
"git.kirsle.net/apps/doodle/pkg/doodads"
|
||||||
|
@ -13,6 +10,9 @@ import (
|
||||||
"git.kirsle.net/apps/doodle/pkg/log"
|
"git.kirsle.net/apps/doodle/pkg/log"
|
||||||
"git.kirsle.net/apps/doodle/pkg/scripting"
|
"git.kirsle.net/apps/doodle/pkg/scripting"
|
||||||
"git.kirsle.net/apps/doodle/pkg/uix"
|
"git.kirsle.net/apps/doodle/pkg/uix"
|
||||||
|
"git.kirsle.net/go/render"
|
||||||
|
"git.kirsle.net/go/render/event"
|
||||||
|
"git.kirsle.net/go/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PlayScene manages the "Edit Level" game mode.
|
// PlayScene manages the "Edit Level" game mode.
|
||||||
|
@ -114,7 +114,7 @@ func (s *PlayScene) Setup(d *Doodle) error {
|
||||||
s.drawing = uix.NewCanvas(balance.ChunkSize, false)
|
s.drawing = uix.NewCanvas(balance.ChunkSize, false)
|
||||||
s.drawing.Name = "play-canvas"
|
s.drawing.Name = "play-canvas"
|
||||||
s.drawing.MoveTo(render.Origin)
|
s.drawing.MoveTo(render.Origin)
|
||||||
s.drawing.Resize(render.NewRect(int32(d.width), int32(d.height)))
|
s.drawing.Resize(render.NewRect(d.width, d.height))
|
||||||
s.drawing.Compute(d.Engine)
|
s.drawing.Compute(d.Engine)
|
||||||
|
|
||||||
// Handler when an actor touches water or fire.
|
// Handler when an actor touches water or fire.
|
||||||
|
@ -305,7 +305,7 @@ func (s *PlayScene) DieByFire() {
|
||||||
// Loop the editor scene.
|
// Loop the editor scene.
|
||||||
func (s *PlayScene) Loop(d *Doodle, ev *event.State) error {
|
func (s *PlayScene) Loop(d *Doodle, ev *event.State) error {
|
||||||
// Update debug overlay values.
|
// Update debug overlay values.
|
||||||
*s.debWorldIndex = s.drawing.WorldIndexAt(render.NewPoint(int32(ev.CursorX), int32(ev.CursorY))).String()
|
*s.debWorldIndex = s.drawing.WorldIndexAt(render.NewPoint(ev.CursorX, ev.CursorY)).String()
|
||||||
*s.debPosition = s.Player.Position().String() + " vel " + s.Player.Velocity().String()
|
*s.debPosition = s.Player.Position().String() + " vel " + s.Player.Velocity().String()
|
||||||
*s.debViewport = s.drawing.Viewport().String()
|
*s.debViewport = s.drawing.Viewport().String()
|
||||||
*s.debScroll = s.drawing.Scroll.String()
|
*s.debScroll = s.drawing.Scroll.String()
|
||||||
|
@ -318,7 +318,7 @@ func (s *PlayScene) Loop(d *Doodle, ev *event.State) error {
|
||||||
if w != d.width || h != d.height {
|
if w != d.width || h != d.height {
|
||||||
d.width = w
|
d.width = w
|
||||||
d.height = h
|
d.height = h
|
||||||
s.drawing.Resize(render.NewRect(int32(d.width), int32(d.height)))
|
s.drawing.Resize(render.NewRect(d.width, d.height))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -358,9 +358,9 @@ func (s *PlayScene) Draw(d *Doodle) error {
|
||||||
|
|
||||||
// Draw the Edit button.
|
// Draw the Edit button.
|
||||||
var (
|
var (
|
||||||
canSize = s.drawing.Size()
|
canSize = s.drawing.Size()
|
||||||
size = s.editButton.Size()
|
size = s.editButton.Size()
|
||||||
padding int32 = 8
|
padding = 8
|
||||||
)
|
)
|
||||||
s.editButton.Present(d.Engine, render.Point{
|
s.editButton.Present(d.Engine, render.Point{
|
||||||
X: canSize.W - size.W - padding,
|
X: canSize.W - size.W - padding,
|
||||||
|
@ -371,8 +371,8 @@ func (s *PlayScene) Draw(d *Doodle) error {
|
||||||
if !s.alertBox.Hidden() {
|
if !s.alertBox.Hidden() {
|
||||||
s.alertBox.Compute(d.Engine)
|
s.alertBox.Compute(d.Engine)
|
||||||
s.alertBox.MoveTo(render.Point{
|
s.alertBox.MoveTo(render.Point{
|
||||||
X: int32(d.width/2) - (s.alertBox.Size().W / 2),
|
X: (d.width / 2) - (s.alertBox.Size().W / 2),
|
||||||
Y: int32(d.height/2) - (s.alertBox.Size().H / 2),
|
Y: (d.height / 2) - (s.alertBox.Size().H / 2),
|
||||||
})
|
})
|
||||||
s.alertBox.Present(d.Engine, s.alertBox.Point())
|
s.alertBox.Present(d.Engine, s.alertBox.Point())
|
||||||
}
|
}
|
||||||
|
@ -382,8 +382,7 @@ func (s *PlayScene) Draw(d *Doodle) error {
|
||||||
|
|
||||||
// movePlayer updates the player's X,Y coordinate based on key pressed.
|
// movePlayer updates the player's X,Y coordinate based on key pressed.
|
||||||
func (s *PlayScene) movePlayer(ev *event.State) {
|
func (s *PlayScene) movePlayer(ev *event.State) {
|
||||||
var playerSpeed = int32(balance.PlayerMaxVelocity)
|
var playerSpeed = balance.PlayerMaxVelocity
|
||||||
// var gravity = int32(balance.Gravity)
|
|
||||||
|
|
||||||
var velocity render.Point
|
var velocity render.Point
|
||||||
|
|
||||||
|
|
22
pkg/shell.go
22
pkg/shell.go
|
@ -5,12 +5,12 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.kirsle.net/go/render"
|
|
||||||
"git.kirsle.net/go/render/event"
|
|
||||||
"git.kirsle.net/go/ui"
|
|
||||||
"git.kirsle.net/apps/doodle/pkg/balance"
|
"git.kirsle.net/apps/doodle/pkg/balance"
|
||||||
"git.kirsle.net/apps/doodle/pkg/log"
|
"git.kirsle.net/apps/doodle/pkg/log"
|
||||||
"git.kirsle.net/apps/doodle/pkg/shmem"
|
"git.kirsle.net/apps/doodle/pkg/shmem"
|
||||||
|
"git.kirsle.net/go/render"
|
||||||
|
"git.kirsle.net/go/render/event"
|
||||||
|
"git.kirsle.net/go/ui"
|
||||||
"github.com/robertkrimen/otto"
|
"github.com/robertkrimen/otto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -278,21 +278,21 @@ func (s *Shell) Draw(d *Doodle, ev *event.State) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// How tall is the box?
|
// How tall is the box?
|
||||||
boxHeight := int32(lineHeight*(balance.ShellHistoryLineCount+1)) + balance.ShellPadding
|
boxHeight := (lineHeight * (balance.ShellHistoryLineCount + 1)) + balance.ShellPadding
|
||||||
|
|
||||||
// Draw the background color.
|
// Draw the background color.
|
||||||
d.Engine.DrawBox(
|
d.Engine.DrawBox(
|
||||||
balance.ShellBackgroundColor,
|
balance.ShellBackgroundColor,
|
||||||
render.Rect{
|
render.Rect{
|
||||||
X: 0,
|
X: 0,
|
||||||
Y: int32(d.height) - boxHeight,
|
Y: d.height - boxHeight,
|
||||||
W: int32(d.width),
|
W: d.width,
|
||||||
H: boxHeight,
|
H: boxHeight,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
// Draw the recent commands.
|
// Draw the recent commands.
|
||||||
outputY := int32(d.height - (lineHeight * 2))
|
outputY := d.height - (lineHeight * 2)
|
||||||
for i := 0; i < balance.ShellHistoryLineCount; i++ {
|
for i := 0; i < balance.ShellHistoryLineCount; i++ {
|
||||||
if len(s.Output) > i {
|
if len(s.Output) > i {
|
||||||
line := s.Output[len(s.Output)-1-i]
|
line := s.Output[len(s.Output)-1-i]
|
||||||
|
@ -309,7 +309,7 @@ func (s *Shell) Draw(d *Doodle, ev *event.State) error {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
outputY -= int32(lineHeight)
|
outputY -= lineHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw the command prompt.
|
// Draw the command prompt.
|
||||||
|
@ -322,14 +322,14 @@ func (s *Shell) Draw(d *Doodle, ev *event.State) error {
|
||||||
},
|
},
|
||||||
render.Point{
|
render.Point{
|
||||||
X: balance.ShellPadding,
|
X: balance.ShellPadding,
|
||||||
Y: int32(d.height-balance.ShellFontSize) - balance.ShellPadding,
|
Y: d.height - balance.ShellFontSize - balance.ShellPadding,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
} else if len(s.Flashes) > 0 {
|
} else if len(s.Flashes) > 0 {
|
||||||
// Otherwise, just draw flashed messages.
|
// Otherwise, just draw flashed messages.
|
||||||
valid := false // Did we actually draw any?
|
valid := false // Did we actually draw any?
|
||||||
|
|
||||||
outputY := int32(d.height - (lineHeight * 2) - 16)
|
outputY := d.height - (lineHeight * 2) - 16
|
||||||
for i := len(s.Flashes); i > 0; i-- {
|
for i := len(s.Flashes); i > 0; i-- {
|
||||||
flash := s.Flashes[i-1]
|
flash := s.Flashes[i-1]
|
||||||
if shmem.Tick >= flash.Expires {
|
if shmem.Tick >= flash.Expires {
|
||||||
|
@ -349,7 +349,7 @@ func (s *Shell) Draw(d *Doodle, ev *event.State) error {
|
||||||
Y: outputY,
|
Y: outputY,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
outputY -= int32(lineHeight)
|
outputY -= lineHeight
|
||||||
valid = true
|
valid = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,9 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.kirsle.net/go/render"
|
|
||||||
"git.kirsle.net/apps/doodle/pkg/doodads"
|
"git.kirsle.net/apps/doodle/pkg/doodads"
|
||||||
"git.kirsle.net/apps/doodle/pkg/level"
|
"git.kirsle.net/apps/doodle/pkg/level"
|
||||||
|
"git.kirsle.net/go/render"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/robertkrimen/otto"
|
"github.com/robertkrimen/otto"
|
||||||
)
|
)
|
||||||
|
@ -45,7 +45,7 @@ func NewActor(id string, levelActor *level.Actor, doodad *doodads.Doodad) *Actor
|
||||||
id = uuid.Must(uuid.NewRandom()).String()
|
id = uuid.Must(uuid.NewRandom()).String()
|
||||||
}
|
}
|
||||||
|
|
||||||
size := int32(doodad.Layers[0].Chunker.Size)
|
size := doodad.Layers[0].Chunker.Size
|
||||||
can := NewCanvas(int(size), false)
|
can := NewCanvas(int(size), false)
|
||||||
can.Name = id
|
can.Name = id
|
||||||
|
|
||||||
|
@ -83,10 +83,10 @@ func (a *Actor) GetBoundingRect() render.Rect {
|
||||||
// SetHitbox sets the actor's elected hitbox.
|
// SetHitbox sets the actor's elected hitbox.
|
||||||
func (a *Actor) SetHitbox(x, y, w, h int) {
|
func (a *Actor) SetHitbox(x, y, w, h int) {
|
||||||
a.hitbox = render.Rect{
|
a.hitbox = render.Rect{
|
||||||
X: int32(x),
|
X: x,
|
||||||
Y: int32(y),
|
Y: y,
|
||||||
W: int32(w),
|
W: w,
|
||||||
H: int32(h),
|
H: h,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,12 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.kirsle.net/go/render"
|
|
||||||
"git.kirsle.net/apps/doodle/pkg/balance"
|
"git.kirsle.net/apps/doodle/pkg/balance"
|
||||||
"git.kirsle.net/apps/doodle/pkg/collision"
|
"git.kirsle.net/apps/doodle/pkg/collision"
|
||||||
"git.kirsle.net/apps/doodle/pkg/doodads"
|
"git.kirsle.net/apps/doodle/pkg/doodads"
|
||||||
"git.kirsle.net/apps/doodle/pkg/log"
|
"git.kirsle.net/apps/doodle/pkg/log"
|
||||||
"git.kirsle.net/apps/doodle/pkg/scripting"
|
"git.kirsle.net/apps/doodle/pkg/scripting"
|
||||||
|
"git.kirsle.net/go/render"
|
||||||
"github.com/robertkrimen/otto"
|
"github.com/robertkrimen/otto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ func (w *Canvas) loopActorCollision() error {
|
||||||
// Get the actor's velocity to see if it's moving this tick.
|
// Get the actor's velocity to see if it's moving this tick.
|
||||||
v := a.Velocity()
|
v := a.Velocity()
|
||||||
if a.hasGravity {
|
if a.hasGravity {
|
||||||
v.Y += int32(balance.Gravity)
|
v.Y += balance.Gravity
|
||||||
}
|
}
|
||||||
|
|
||||||
// If not moving, grab the bounding box right now.
|
// If not moving, grab the bounding box right now.
|
||||||
|
@ -162,7 +162,7 @@ func (w *Canvas) loopActorCollision() error {
|
||||||
// he'd continue falling, so I had to move him up to stop it,
|
// he'd continue falling, so I had to move him up to stop it,
|
||||||
// turns out moving up by the -gravity is exactly the distance
|
// turns out moving up by the -gravity is exactly the distance
|
||||||
// to go. Don't know why.
|
// to go. Don't know why.
|
||||||
b.MoveBy(render.NewPoint(0, int32(-balance.Gravity)))
|
b.MoveBy(render.NewPoint(0, -balance.Gravity))
|
||||||
} else {
|
} else {
|
||||||
b.MoveTo(lastGoodBox.Point())
|
b.MoveTo(lastGoodBox.Point())
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,6 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.kirsle.net/go/render"
|
|
||||||
"git.kirsle.net/go/render/event"
|
|
||||||
"git.kirsle.net/go/ui"
|
|
||||||
"git.kirsle.net/apps/doodle/pkg/balance"
|
"git.kirsle.net/apps/doodle/pkg/balance"
|
||||||
"git.kirsle.net/apps/doodle/pkg/bindata"
|
"git.kirsle.net/apps/doodle/pkg/bindata"
|
||||||
"git.kirsle.net/apps/doodle/pkg/collision"
|
"git.kirsle.net/apps/doodle/pkg/collision"
|
||||||
|
@ -18,6 +15,9 @@ import (
|
||||||
"git.kirsle.net/apps/doodle/pkg/log"
|
"git.kirsle.net/apps/doodle/pkg/log"
|
||||||
"git.kirsle.net/apps/doodle/pkg/scripting"
|
"git.kirsle.net/apps/doodle/pkg/scripting"
|
||||||
"git.kirsle.net/apps/doodle/pkg/wallpaper"
|
"git.kirsle.net/apps/doodle/pkg/wallpaper"
|
||||||
|
"git.kirsle.net/go/render"
|
||||||
|
"git.kirsle.net/go/render/event"
|
||||||
|
"git.kirsle.net/go/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Canvas is a custom ui.Widget that manages a single drawing.
|
// Canvas is a custom ui.Widget that manages a single drawing.
|
||||||
|
@ -225,7 +225,7 @@ func (w *Canvas) Loop(ev *event.State) error {
|
||||||
|
|
||||||
// If the canvas is editable, only care if it's over our space.
|
// If the canvas is editable, only care if it's over our space.
|
||||||
if w.Editable {
|
if w.Editable {
|
||||||
cursor := render.NewPoint(int32(ev.CursorX), int32(ev.CursorY))
|
cursor := render.NewPoint(ev.CursorX, ev.CursorY)
|
||||||
if cursor.Inside(ui.AbsoluteRect(w)) {
|
if cursor.Inside(ui.AbsoluteRect(w)) {
|
||||||
return w.loopEditable(ev)
|
return w.loopEditable(ev)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package uix
|
package uix
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"git.kirsle.net/apps/doodle/pkg/shmem"
|
||||||
"git.kirsle.net/go/render"
|
"git.kirsle.net/go/render"
|
||||||
"git.kirsle.net/go/ui"
|
"git.kirsle.net/go/ui"
|
||||||
"git.kirsle.net/apps/doodle/pkg/shmem"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// IsCursorOver returns true if the mouse cursor is physically over top
|
// IsCursorOver returns true if the mouse cursor is physically over top
|
||||||
|
@ -33,7 +33,7 @@ func (w *Canvas) presentCursor(e render.Engine) {
|
||||||
|
|
||||||
// Are we editing with a thick brush?
|
// Are we editing with a thick brush?
|
||||||
if w.BrushSize > 0 {
|
if w.BrushSize > 0 {
|
||||||
var r = int32(w.BrushSize)
|
var r = w.BrushSize
|
||||||
rect := render.Rect{
|
rect := render.Rect{
|
||||||
X: shmem.Cursor.X - r,
|
X: shmem.Cursor.X - r,
|
||||||
Y: shmem.Cursor.Y - r,
|
Y: shmem.Cursor.Y - r,
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package uix
|
package uix
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"git.kirsle.net/apps/doodle/pkg/drawtool"
|
||||||
|
"git.kirsle.net/apps/doodle/pkg/level"
|
||||||
"git.kirsle.net/go/render"
|
"git.kirsle.net/go/render"
|
||||||
"git.kirsle.net/go/render/event"
|
"git.kirsle.net/go/render/event"
|
||||||
"git.kirsle.net/go/ui"
|
"git.kirsle.net/go/ui"
|
||||||
"git.kirsle.net/apps/doodle/pkg/drawtool"
|
|
||||||
"git.kirsle.net/apps/doodle/pkg/level"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// commitStroke is the common function that applies a stroke the user is
|
// commitStroke is the common function that applies a stroke the user is
|
||||||
|
@ -102,8 +102,8 @@ func (w *Canvas) loopEditable(ev *event.State) error {
|
||||||
var (
|
var (
|
||||||
P = ui.AbsolutePosition(w)
|
P = ui.AbsolutePosition(w)
|
||||||
cursor = render.Point{
|
cursor = render.Point{
|
||||||
X: int32(ev.CursorX) - P.X - w.Scroll.X,
|
X: ev.CursorX - P.X - w.Scroll.X,
|
||||||
Y: int32(ev.CursorY) - P.Y - w.Scroll.Y,
|
Y: ev.CursorY - P.Y - w.Scroll.Y,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,10 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.kirsle.net/go/render"
|
|
||||||
"git.kirsle.net/go/ui"
|
|
||||||
"git.kirsle.net/apps/doodle/pkg/balance"
|
"git.kirsle.net/apps/doodle/pkg/balance"
|
||||||
"git.kirsle.net/apps/doodle/pkg/log"
|
"git.kirsle.net/apps/doodle/pkg/log"
|
||||||
|
"git.kirsle.net/go/render"
|
||||||
|
"git.kirsle.net/go/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Present the canvas.
|
// Present the canvas.
|
||||||
|
@ -59,8 +59,8 @@ func (w *Canvas) Present(e render.Engine, p render.Point) {
|
||||||
}
|
}
|
||||||
|
|
||||||
dst := render.Rect{
|
dst := render.Rect{
|
||||||
X: p.X + w.Scroll.X + w.BoxThickness(1) + (coord.X * int32(chunk.Size)),
|
X: p.X + w.Scroll.X + w.BoxThickness(1) + (coord.X * chunk.Size),
|
||||||
Y: p.Y + w.Scroll.Y + w.BoxThickness(1) + (coord.Y * int32(chunk.Size)),
|
Y: p.Y + w.Scroll.Y + w.BoxThickness(1) + (coord.Y * chunk.Size),
|
||||||
|
|
||||||
// src.W and src.H will be AT MOST the full width and height of
|
// src.W and src.H will be AT MOST the full width and height of
|
||||||
// a Canvas widget. Subtract the scroll offset to keep it bounded
|
// a Canvas widget. Subtract the scroll offset to keep it bounded
|
||||||
|
|
|
@ -4,10 +4,10 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.kirsle.net/go/render"
|
|
||||||
"git.kirsle.net/go/render/event"
|
|
||||||
"git.kirsle.net/apps/doodle/pkg/balance"
|
"git.kirsle.net/apps/doodle/pkg/balance"
|
||||||
"git.kirsle.net/apps/doodle/pkg/level"
|
"git.kirsle.net/apps/doodle/pkg/level"
|
||||||
|
"git.kirsle.net/go/render"
|
||||||
|
"git.kirsle.net/go/render/event"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -73,8 +73,8 @@ func (w *Canvas) loopConstrainScroll() error {
|
||||||
w.wallpaper.maxWidth+w.wallpaper.maxHeight > 0 {
|
w.wallpaper.maxWidth+w.wallpaper.maxHeight > 0 {
|
||||||
var (
|
var (
|
||||||
// TODO: downcast from int64!
|
// TODO: downcast from int64!
|
||||||
mw = int32(w.wallpaper.maxWidth)
|
mw = int(w.wallpaper.maxWidth)
|
||||||
mh = int32(w.wallpaper.maxHeight)
|
mh = int(w.wallpaper.maxHeight)
|
||||||
Viewport = w.Viewport()
|
Viewport = w.Viewport()
|
||||||
)
|
)
|
||||||
if Viewport.W > mw {
|
if Viewport.W > mw {
|
||||||
|
@ -126,10 +126,10 @@ func (w *Canvas) loopFollowActor(ev *event.State) error {
|
||||||
)
|
)
|
||||||
|
|
||||||
// Scroll left
|
// Scroll left
|
||||||
if APosition.X-VP.X <= int32(balance.ScrollboxHoz) {
|
if APosition.X-VP.X <= balance.ScrollboxHoz {
|
||||||
var delta = APosition.X - VP.X
|
var delta = APosition.X - VP.X
|
||||||
if delta > int32(balance.ScrollMaxVelocity) {
|
if delta > balance.ScrollMaxVelocity {
|
||||||
delta = int32(balance.ScrollMaxVelocity)
|
delta = balance.ScrollMaxVelocity
|
||||||
}
|
}
|
||||||
|
|
||||||
if delta < 0 {
|
if delta < 0 {
|
||||||
|
@ -140,23 +140,23 @@ func (w *Canvas) loopFollowActor(ev *event.State) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scroll right
|
// Scroll right
|
||||||
if APosition.X >= VP.W-ASize.W-int32(balance.ScrollboxHoz) {
|
if APosition.X >= VP.W-ASize.W-balance.ScrollboxHoz {
|
||||||
var delta = VP.W - ASize.W - int32(balance.ScrollboxHoz)
|
var delta = VP.W - ASize.W - balance.ScrollboxHoz
|
||||||
if delta > int32(balance.ScrollMaxVelocity) {
|
if delta > balance.ScrollMaxVelocity {
|
||||||
delta = int32(balance.ScrollMaxVelocity)
|
delta = balance.ScrollMaxVelocity
|
||||||
}
|
}
|
||||||
scrollBy.X = -delta
|
scrollBy.X = -delta
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scroll up
|
// Scroll up
|
||||||
if APosition.Y-VP.Y <= int32(balance.ScrollboxVert) {
|
if APosition.Y-VP.Y <= balance.ScrollboxVert {
|
||||||
var delta = APosition.Y - VP.Y
|
var delta = APosition.Y - VP.Y
|
||||||
if delta > int32(balance.ScrollMaxVelocity) {
|
if delta > balance.ScrollMaxVelocity {
|
||||||
delta = int32(balance.ScrollMaxVelocity)
|
delta = balance.ScrollMaxVelocity
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add gravity to counteract jitters on scrolling vertically
|
// TODO: add gravity to counteract jitters on scrolling vertically
|
||||||
scrollBy.Y -= int32(balance.Gravity)
|
scrollBy.Y -= balance.Gravity
|
||||||
|
|
||||||
if delta < 0 {
|
if delta < 0 {
|
||||||
delta = -delta
|
delta = -delta
|
||||||
|
@ -165,15 +165,15 @@ func (w *Canvas) loopFollowActor(ev *event.State) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scroll down
|
// Scroll down
|
||||||
if APosition.Y >= VP.H-ASize.H-int32(balance.ScrollboxVert) {
|
if APosition.Y >= VP.H-ASize.H-balance.ScrollboxVert {
|
||||||
var delta = VP.H - ASize.H - int32(balance.ScrollboxVert)
|
var delta = VP.H - ASize.H - balance.ScrollboxVert
|
||||||
if delta > int32(balance.ScrollMaxVelocity) {
|
if delta > balance.ScrollMaxVelocity {
|
||||||
delta = int32(balance.ScrollMaxVelocity)
|
delta = balance.ScrollMaxVelocity
|
||||||
}
|
}
|
||||||
scrollBy.Y = -delta
|
scrollBy.Y = -delta
|
||||||
|
|
||||||
// TODO: add gravity to counteract jitters on scrolling vertically
|
// TODO: add gravity to counteract jitters on scrolling vertically
|
||||||
scrollBy.Y += int32(balance.Gravity * 3)
|
scrollBy.Y += balance.Gravity * 3
|
||||||
}
|
}
|
||||||
|
|
||||||
if scrollBy != render.Origin {
|
if scrollBy != render.Origin {
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package uix
|
package uix
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.kirsle.net/go/render"
|
|
||||||
"git.kirsle.net/apps/doodle/pkg/level"
|
"git.kirsle.net/apps/doodle/pkg/level"
|
||||||
"git.kirsle.net/apps/doodle/pkg/wallpaper"
|
"git.kirsle.net/apps/doodle/pkg/wallpaper"
|
||||||
|
"git.kirsle.net/go/render"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Wallpaper configures the wallpaper in a Canvas.
|
// Wallpaper configures the wallpaper in a Canvas.
|
||||||
|
@ -49,14 +49,14 @@ func (w *Canvas) loopContainActorsInsideLevel(a *Actor) {
|
||||||
if w.wallpaper.pageType >= level.Bounded {
|
if w.wallpaper.pageType >= level.Bounded {
|
||||||
if w.wallpaper.maxWidth > 0 {
|
if w.wallpaper.maxWidth > 0 {
|
||||||
if int64(orig.X+size.W) > w.wallpaper.maxWidth {
|
if int64(orig.X+size.W) > w.wallpaper.maxWidth {
|
||||||
var delta = int32(w.wallpaper.maxWidth - int64(orig.X+size.W))
|
var delta = w.wallpaper.maxWidth - int64(orig.X+size.W)
|
||||||
moveBy.X = delta
|
moveBy.X = int(delta)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if w.wallpaper.maxHeight > 0 {
|
if w.wallpaper.maxHeight > 0 {
|
||||||
if int64(orig.Y+size.H) > w.wallpaper.maxHeight {
|
if int64(orig.Y+size.H) > w.wallpaper.maxHeight {
|
||||||
var delta = int32(w.wallpaper.maxHeight - int64(orig.Y+size.H))
|
var delta = w.wallpaper.maxHeight - int64(orig.Y+size.H)
|
||||||
moveBy.Y = delta
|
moveBy.Y = int(delta)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ func (w *Canvas) PresentWallpaper(e render.Engine, p render.Point) error {
|
||||||
// For tiled textures, compute the offset amount. If we are scrolled away
|
// For tiled textures, compute the offset amount. If we are scrolled away
|
||||||
// from the Origin (0,0) we find out by how far (subtract full tile sizes)
|
// from the Origin (0,0) we find out by how far (subtract full tile sizes)
|
||||||
// and use the remainder as an offset for drawing the tiles.
|
// and use the remainder as an offset for drawing the tiles.
|
||||||
var dx, dy int32
|
var dx, dy int
|
||||||
if origin.X > p.X {
|
if origin.X > p.X {
|
||||||
for origin.X > p.X && origin.X > size.W {
|
for origin.X > p.X && origin.X > size.W {
|
||||||
origin.X -= size.W
|
origin.X -= size.W
|
||||||
|
|
Loading…
Reference in New Issue
Block a user