This repository was archived by the owner on Apr 23, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,7 @@ func (gctx *gcontext) run(setup, draw Func) error {
9191 Event .Mouse .Position .X = float64 (e .Position .X )
9292 Event .Mouse .Position .Y = float64 (e .Position .Y )
9393 }
94+ Event .Mouse .Buttons = Buttons (e .Buttons )
9495
9596 case system.FrameEvent :
9697 gctx .draw (e , draw )
Original file line number Diff line number Diff line change @@ -16,5 +16,21 @@ var Event struct {
1616 X float64
1717 Y float64
1818 }
19+ Buttons Buttons
1920 }
2021}
22+
23+ // Buttons is a set of mouse buttons.
24+ type Buttons uint8
25+
26+ // Contain reports whether the set b contains
27+ // all of the buttons.
28+ func (b Buttons ) Contain (buttons Buttons ) bool {
29+ return b & buttons == buttons
30+ }
31+
32+ const (
33+ ButtonLeft Buttons = 1 << iota
34+ ButtonRight
35+ ButtonMiddle
36+ )
Original file line number Diff line number Diff line change @@ -22,7 +22,9 @@ func setup() {
2222func draw () {
2323 switch {
2424 case p5 .Event .Mouse .Pressed :
25- p5 .Fill (color.RGBA {R : 255 , A : 255 })
25+ if p5 .Event .Mouse .Buttons .Contain (p5 .ButtonLeft ) {
26+ p5 .Fill (color.RGBA {R : 255 , A : 255 })
27+ }
2628 default :
2729 p5 .Fill (color .Transparent )
2830 }
You can’t perform that action at this time.
0 commit comments