summaryrefslogtreecommitdiff
path: root/objs/cursor.go
diff options
context:
space:
mode:
Diffstat (limited to 'objs/cursor.go')
-rw-r--r--objs/cursor.go23
1 files changed, 16 insertions, 7 deletions
diff --git a/objs/cursor.go b/objs/cursor.go
index 2a676fe..bf4d624 100644
--- a/objs/cursor.go
+++ b/objs/cursor.go
@@ -9,6 +9,12 @@ import (
type Cursor struct {
*ecs.GameObject
MaxX, MaxY float32
+ Trail []sdl.FPoint
+ Pressed bool
+}
+
+func (c *Cursor) ProcessMousePress(ev events.MousePress) {
+ c.Pressed = ev.IsPressed
}
func (c *Cursor) ProcessWindowChange(ev events.WindowChange) {
@@ -17,7 +23,12 @@ func (c *Cursor) ProcessWindowChange(ev events.WindowChange) {
}
func (c *Cursor) Render(renderer *sdl.Renderer) {
- renderer.SetDrawColor(255, 0, 0, 255)
+ if c.Pressed {
+ c.Trail = append(c.Trail, c.Position)
+ } else {
+ c.Trail = nil
+ }
+ c.Safe(renderer.SetDrawColor(255, 0, 0, 255))
size := float32(13)
r := &sdl.FRect{
X: c.Position.X - size/2,
@@ -25,7 +36,10 @@ func (c *Cursor) Render(renderer *sdl.Renderer) {
W: size,
H: size,
}
- renderer.RenderRect(r)
+ c.Safe(renderer.RenderRect(r))
+ if c.Trail != nil {
+ c.Safe(renderer.RenderLines(c.Trail))
+ }
}
func (c *Cursor) ProcessMouseMotion(ev events.MouseMotion) {
@@ -44,11 +58,6 @@ func (c *Cursor) ProcessMouseMotion(ev events.MouseMotion) {
c.Position.Y = c.MaxY
}
}
-
-func (c *Cursor) GO() *ecs.GameObject {
- return c.GameObject
-}
-
func NewCursor() ecs.IsGameObject {
return &Cursor{
GameObject: &ecs.GameObject{},