Skip to content

Commit 5a8fa45

Browse files
committed
Make piscope toolbar colors configurable
Users can now choose the toolbar background and foreground colors.
1 parent dc52911 commit 5a8fa45

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

piscope/internal/gui.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ func attachIconButton(parent *pigui.Element, icon pi.Sprite, x int) *IconButton
7979
if event.Pressed {
8080
y = 1
8181
}
82+
83+
prevColorTable := pi.ColorTables[0]
84+
defer func() {
85+
pi.ColorTables[0] = prevColorTable
86+
}()
87+
pi.Pal(0, *bgColor) // 0 is bg color in icons.png
88+
pi.Pal(1, *fgColor) // 1 is fg color in icons.png
8289
pi.Spr(iconBtn.Icon, 0, y)
8390
}
8491
return iconBtn

piscope/internal/icons.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,14 @@ var icons = struct {
2929
}{}
3030

3131
func init() {
32-
// TODO Decode palette
32+
prevPalette := pi.Palette
33+
defer func() {
34+
pi.Palette = prevPalette
35+
}()
36+
37+
pi.Palette = pi.DecodePalette(iconsPNG)
3338
iconsSheet := pi.DecodeCanvas(iconsPNG)
39+
3440
icons.AlignTop = pi.SpriteFrom(iconsSheet, 0, 0, 8, 8)
3541
icons.AlignBottom = pi.SpriteFrom(iconsSheet, 8, 0, 8, 8)
3642
icons.Screen = pi.SpriteFrom(iconsSheet, 16, 0, 8, 8)

piscope/internal/icons.png

-95 Bytes
Loading

piscope/internal/internal.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/elgopher/pi/pimouse"
1515
)
1616

17-
var bgColor *pi.Color
17+
var bgColor, fgColor *pi.Color
1818

1919
var consoleMode, pauseOnNextFrame bool
2020

@@ -25,8 +25,9 @@ var consoleMode, pauseOnNextFrame bool
2525
// używać conajmniej 2 kolorów.
2626
//
2727
// Pressing Ctrl+Shift+I will activate the tools in the game
28-
func Start(backgroundColor *pi.Color) {
28+
func Start(backgroundColor, foregroundColor *pi.Color) {
2929
bgColor = backgroundColor
30+
fgColor = foregroundColor
3031

3132
// TODO Handle screen size change event and redraw entire gui.
3233

piscope/piscope.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ import (
99
"github.com/elgopher/pi/piscope/internal"
1010
)
1111

12-
var BgColor pi.Color = 8 // toolbar background color
12+
// Toolbar colors
13+
var (
14+
BgColor pi.Color = 8 // toolbar background color
15+
FgColor pi.Color = 1 // toolbar foreground color
16+
)
1317

1418
// Start launches the developer tools.
1519
//
@@ -27,5 +31,5 @@ var BgColor pi.Color = 8 // toolbar background color
2731
// 128 pixels horizontally and 16 pixels vertically. Additionally, the game's
2832
// palette must use at least 2 colors.
2933
func Start() {
30-
internal.Start(&BgColor)
34+
internal.Start(&BgColor, &FgColor)
3135
}

0 commit comments

Comments
 (0)