diff options
Diffstat (limited to 'selection')
| -rw-r--r-- | selection/selection.go | 32 |
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 { |
