@@ -15,18 +15,16 @@ import (
15
15
16
16
var BgColor , FgColor byte
17
17
18
+ var pixelColorAtMouseCoords byte
19
+
18
20
func Draw () {
19
21
snapshot .Draw ()
20
-
21
- // I check the input in Draw function because only during Draw operation
22
- // I have access to screen restored from snapshot
23
- if pi .MouseBtnp (pi .MouseLeft ) {
24
- x , y := pi .MousePos ()
25
- fmt .Printf ("Screen pixel (%d, %d) with color %d selected\n " , x , y , pi .Pget (x , y ))
26
- }
27
-
22
+ pixelColorAtMouseCoords = pi .Pget (pi .MousePos ())
28
23
moveBarIfNeeded ()
29
24
drawBar ()
25
+
26
+ drawDistanceLine ()
27
+
30
28
drawPointer ()
31
29
}
32
30
@@ -39,9 +37,15 @@ func drawBar() {
39
37
40
38
pi .RectFill (0 , barY , vm .ScreenWidth , barY + 6 , BgColor )
41
39
42
- mostX := printCoords (mouseX , mouseY , 1 , barY + 1 )
43
- color := pi .Pget (mouseX , mouseY )
44
- printPixelColor (color , mostX + 4 , barY + 1 )
40
+ textX := 1
41
+ textY := barY + 1
42
+
43
+ if distance .measuring {
44
+ printDistance (textX , textY )
45
+ } else {
46
+ mostX := printCoords (mouseX , mouseY , textX , textY )
47
+ printPixelColor (pixelColorAtMouseCoords , mostX + 4 , textY )
48
+ }
45
49
}
46
50
47
51
func printCoords (mouseX int , mouseY int , x , y int ) int {
@@ -60,10 +64,27 @@ func drawPointer() {
60
64
}
61
65
62
66
func choosePointerColor (x , y int ) byte {
63
- c := pi . Pget ( x , y )
67
+ c := pixelColorAtMouseCoords
64
68
if rgb .BrightnessDelta (vm .Palette [FgColor ], vm .Palette [c ]) >= rgb .BrightnessDelta (vm .Palette [BgColor ], vm .Palette [c ]) {
65
69
return FgColor
66
70
}
67
71
68
72
return BgColor
69
73
}
74
+
75
+ func drawDistanceLine () {
76
+ if distance .measuring {
77
+ x , y := pi .MousePos ()
78
+ pi .Line (distance .startX , distance .startY , x , y , BgColor )
79
+ }
80
+ }
81
+
82
+ func printDistance (x , y int ) int {
83
+ if distance .measuring {
84
+ dist , width , height := calcDistance ()
85
+ text := fmt .Sprintf ("D: %.1f W: %d H: %d" , dist , width , height )
86
+ return pi .Print (text , x , y , FgColor )
87
+ }
88
+
89
+ return x
90
+ }
0 commit comments