aboutsummaryrefslogtreecommitdiff
path: root/selection
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2025-09-25 22:15:45 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2025-09-25 22:15:45 +0200
commitbd750fa2605eecd14ab821f630a7c1b51c48c982 (patch)
treed6974c0d5bf1ffad274dce070a5ce979d887425d /selection
parent4f2217d74d1fa39235ffd9e3d378099d20c5cc56 (diff)
Improve selection code
Diffstat (limited to 'selection')
-rw-r--r--selection/selection.go32
1 files changed, 29 insertions, 3 deletions
diff --git a/selection/selection.go b/selection/selection.go
index eb12c91..d4b8cd9 100644
--- a/selection/selection.go
+++ b/selection/selection.go
@@ -1,11 +1,14 @@
package selection
import (
+ "image/color"
+ "math"
+
"age_of_empires/ecs"
"age_of_empires/physics"
- "math"
"github.com/hajimehoshi/ebiten/v2"
+ "github.com/hajimehoshi/ebiten/v2/vector"
)
const HaloWidth = 10
@@ -18,8 +21,31 @@ const (
)
type GlobalSelection struct {
- IsActive bool
- Start physics.Point
+ isActive bool
+ start physics.Point
+}
+
+func (s GlobalSelection) IsActive(cursor physics.Point) bool {
+ return s.isActive && physics.Distance(s.start, cursor) > 10
+}
+
+func (s *GlobalSelection) Clear() {
+ s.isActive = false
+ s.start = physics.Point{}
+}
+
+func (s *GlobalSelection) Start(point physics.Point) {
+ s.isActive = true
+ s.start = point
+}
+
+func (s *GlobalSelection) Select(cursor physics.Point) Multiple {
+ s.isActive = false
+ return NewMultiple(s.start, cursor)
+}
+
+func (s *GlobalSelection) Draw(dst *ebiten.Image, cursor physics.Point) {
+ vector.StrokeRect(dst, float32(s.start.X), float32(s.start.Y), float32(cursor.X-s.start.X), float32(cursor.Y-s.start.Y), 10.0, color.RGBA{256 * 3 / 16, 256 * 3 / 16, 256 * 3 / 16, 256 / 4}, true)
}
type Selection struct {