|
| 1 | +// (c) 2022 Jacek Olszak |
| 2 | +// This code is licensed under MIT license (see LICENSE for details) |
| 3 | + |
| 4 | +package devtools |
| 5 | + |
| 6 | +import ( |
| 7 | + "fmt" |
| 8 | + |
| 9 | + "github.com/elgopher/pi" |
| 10 | + "github.com/elgopher/pi/devtools/internal/icons" |
| 11 | + "github.com/elgopher/pi/devtools/internal/snapshot" |
| 12 | + "github.com/elgopher/pi/vm" |
| 13 | +) |
| 14 | + |
| 15 | +func drawDevTools() { |
| 16 | + snapshot.Draw() |
| 17 | + drawBar() |
| 18 | + drawPointer() |
| 19 | +} |
| 20 | + |
| 21 | +func drawBar() { |
| 22 | + mouseX, mouseY := pi.MousePos() |
| 23 | + barY := vm.ScreenHeight - 7 |
| 24 | + if mouseY > vm.ScreenHeight/2 { |
| 25 | + barY = 0 |
| 26 | + } |
| 27 | + |
| 28 | + pi.RectFill(0, barY, vm.ScreenWidth, barY+6, BgColor) |
| 29 | + |
| 30 | + mostX := printCoords(mouseX, mouseY, 1, barY+1) |
| 31 | + color := pi.Pget(mouseX, mouseY) |
| 32 | + printPixelColor(color, mostX+4, barY+1) |
| 33 | +} |
| 34 | + |
| 35 | +func printCoords(mouseX int, mouseY int, x, y int) int { |
| 36 | + coords := fmt.Sprintf("%d %d", mouseX, mouseY) |
| 37 | + return pi.Print(coords, x, y, FgColor) |
| 38 | +} |
| 39 | + |
| 40 | +func printPixelColor(color byte, x int, y int) int { |
| 41 | + c := fmt.Sprintf("%d", color) |
| 42 | + return pi.Print(c, x, y, color) |
| 43 | +} |
| 44 | + |
| 45 | +func drawPointer() { |
| 46 | + x, y := pi.MousePos() |
| 47 | + icons.Draw(icons.Pointer, x, y, FgColor) |
| 48 | +} |
0 commit comments