@@ -15,18 +15,16 @@ import (
1515
1616var BgColor , FgColor byte
1717
18+ var pixelColorAtMouseCoords byte
19+
1820func Draw () {
1921 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 ())
2823 moveBarIfNeeded ()
2924 drawBar ()
25+
26+ drawDistanceLine ()
27+
3028 drawPointer ()
3129}
3230
@@ -39,9 +37,15 @@ func drawBar() {
3937
4038 pi .RectFill (0 , barY , vm .ScreenWidth , barY + 6 , BgColor )
4139
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+ }
4549}
4650
4751func printCoords (mouseX int , mouseY int , x , y int ) int {
@@ -60,10 +64,27 @@ func drawPointer() {
6064}
6165
6266func choosePointerColor (x , y int ) byte {
63- c := pi . Pget ( x , y )
67+ c := pixelColorAtMouseCoords
6468 if rgb .BrightnessDelta (vm .Palette [FgColor ], vm .Palette [c ]) >= rgb .BrightnessDelta (vm .Palette [BgColor ], vm .Palette [c ]) {
6569 return FgColor
6670 }
6771
6872 return BgColor
6973}
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