Skip to content

Commit

Permalink
add: add refresh UI when load palette in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerome Le Saux committed May 1, 2024
1 parent 6ca6857 commit 788d9c7
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 13 deletions.
22 changes: 22 additions & 0 deletions convert/screen/screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/jeromelesaux/martine/convert/palette"
"github.com/jeromelesaux/martine/convert/pixel"
"github.com/jeromelesaux/martine/export/ocpartstudio"
"github.com/jeromelesaux/martine/export/ocpartstudio/window"
"github.com/jeromelesaux/martine/export/png"
)

Expand Down Expand Up @@ -334,6 +335,27 @@ func setImageMode2(out *image.NRGBA, p color.Palette, d []byte, width, height in
return out
}

func WinToImg(path string, mode uint8, p color.Palette) (*image.NRGBA, error) {
footer, err := window.OpenWin(path)
if err != nil {
return nil, err
}
data, err := window.RawWin(path)
if err != nil {
return nil, err
}
out := image.NewNRGBA(image.Rectangle{
Min: image.Point{X: 0, Y: 0},
Max: image.Point{X: int(footer.Width), Y: int(footer.Height)}})
for w := 0; w < int(footer.Width); w++ {
for h := 0; h < int(footer.Height); h++ {
d := data[h+(w*int(footer.Width))]
out.Set(w, h, p[d])
}
}
return out, nil
}

// SrcToImg load the amstrad classical 17ko screen image to image.NRBGA
// using the mode and palette as arguments
func ScrToImg(scrPath string, mode uint8, p color.Palette) (*image.NRGBA, error) {
Expand Down
2 changes: 1 addition & 1 deletion ui/martine-ui/animate_tab.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (m *MartineUI) newAnimateTab(a *menu.AnimateMenu) *fyne.Container {
a.ImageMenu.SetWindow(m.window)
importOpen := newImportButton(m, a.ImageMenu)

paletteOpen := pal.NewOpenPaletteButton(a.ImageMenu, m.window)
paletteOpen := pal.NewOpenPaletteButton(a.ImageMenu, m.window, nil)

forcePalette := widget.NewCheck("use palette", func(b bool) {
a.UsePalette = b
Expand Down
2 changes: 1 addition & 1 deletion ui/martine-ui/egx_tab.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (m *MartineUI) newEgxImageTransfertTab(me *menu.ImageMenu) *fyne.Container
me.SetWindow(m.window)
importOpen := newImportButton(m, me)

paletteOpen := pal.NewOpenPaletteButton(me, m.window)
paletteOpen := pal.NewOpenPaletteButton(me, m.window, nil)

forcePalette := widget.NewCheck("use palette", func(b bool) {
me.UsePalette = b
Expand Down
1 change: 1 addition & 0 deletions ui/martine-ui/greetings.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func (m *MartineUI) newGreedings() *fyne.Container {
"\n - **Tronic**\n"+
"\n - **Siko**\n"+
"\n - **Roudoudou**\n"+
"\n - **Hwikaa**\n"+
"\n - and thanks a lot to all users^^\n"+
"\nfor more informations about this tool, go to [Martine's Github page](https://github.com/jeromelesaux/martine)\n"+
"\nfor more informations about my tool go to [github](https://github.com/jeromelesaux)\n"+
Expand Down
2 changes: 1 addition & 1 deletion ui/martine-ui/image_tab.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (m *MartineUI) newImageTransfertTab(me *menu.ImageMenu) *fyne.Container {
me.SetWindow(m.window)
importOpen := newImportButton(m, me)

paletteOpen := pal.NewOpenPaletteButton(me, m.window)
paletteOpen := pal.NewOpenPaletteButton(me, m.window, nil)

forcePalette := widget.NewCheck("use palette", func(b bool) {
me.UsePalette = b
Expand Down
2 changes: 1 addition & 1 deletion ui/martine-ui/menu/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (e *Editor) New(w fyne.Window) *fyne.Container {
container.New(
layout.NewHBoxLayout(),
e.im.NewImportButton(e.sel, e.refreshEditor),
palette.NewOpenPaletteButton(e.im, e.w),
palette.NewOpenPaletteButton(e.im, e.w, e.refreshEditor),
widget.NewCheck("CPC Plus", func(b bool) {
e.im.IsCpcPlus = b
if !b {
Expand Down
36 changes: 30 additions & 6 deletions ui/martine-ui/menu/image_menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type ImageMenu struct {
IsFullScreen bool
IsSprite bool
IsHardSprite bool
IsWin bool
Mode int
width *widget.Entry
height *widget.Entry
Expand Down Expand Up @@ -554,12 +555,26 @@ func (i *ImageMenu) NewImportButton(modeSelection *widget.Select, callBack func(
dialog.ShowError(errors.New("palette is empty, please import palette first, or select fullscreen option to open a fullscreen option"), i.w)
return
}
img, err := screen.ScrToImg(i.OriginalImagePath(), uint8(i.Mode), i.Palette())
if err != nil {
dialog.ShowError(err, i.w)
return
if i.IsWin {
img, err := screen.WinToImg(i.OriginalImagePath(), uint8(i.Mode), i.Palette())
if err != nil {
dialog.ShowError(err, i.w)
return
}
i.SetOriginalImage(img)
} else {
// loading classical screen
if len(i.Palette()) == 0 {
dialog.ShowError(errors.New("palette is empty, please import palette first, or select fullscreen option to open a fullscreen option"), i.w)
return
}
img, err := screen.ScrToImg(i.OriginalImagePath(), uint8(i.Mode), i.Palette())
if err != nil {
dialog.ShowError(err, i.w)
return
}
i.SetOriginalImage(img)
}
i.SetOriginalImage(img)
}
if callBack != nil {
callBack()
Expand All @@ -576,24 +591,33 @@ func (i *ImageMenu) NewImportButton(modeSelection *widget.Select, callBack func(
}

func (me *ImageMenu) NewFormatRadio() *widget.Select {
winFormat := widget.NewSelect([]string{"Normal", "Fullscreen", "Sprite", "Sprite Hard"}, func(s string) {
winFormat := widget.NewSelect([]string{"Normal", "Fullscreen", "Window", "Sprite", "Sprite Hard"}, func(s string) {
switch s {
case "Normal":
me.IsFullScreen = false
me.IsSprite = false
me.IsWin = false
me.IsHardSprite = false
case "Fullscreen":
me.IsFullScreen = true
me.IsSprite = false
me.IsWin = false
me.IsHardSprite = false
case "Sprite":
me.IsFullScreen = false
me.IsSprite = true
me.IsWin = false
me.IsHardSprite = false
case "Sprite Hard":
me.IsFullScreen = false
me.IsSprite = false
me.IsWin = false
me.IsHardSprite = true
case "Window":
me.IsFullScreen = false
me.IsSprite = false
me.IsHardSprite = false
me.IsWin = true
}
})
winFormat.SetSelected("Normal")
Expand Down
5 changes: 4 additions & 1 deletion ui/martine-ui/palette/palette_open_button.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type PaletteInterface interface {
SetPaletteImage(image.Image)
}

func NewOpenPaletteButton(m PaletteInterface, win fyne.Window) *widget.Button {
func NewOpenPaletteButton(m PaletteInterface, win fyne.Window, callback func()) *widget.Button {
return widget.NewButtonWithIcon("Palette", theme.ColorChromaticIcon(), func() {
d := dialog.NewFileOpen(func(reader fyne.URIReadCloser, err error) {
if err != nil {
Expand Down Expand Up @@ -52,6 +52,9 @@ func NewOpenPaletteButton(m PaletteInterface, win fyne.Window) *widget.Button {
m.SetPalette(p)
m.SetPaletteImage(png.PalToImage(p))
}
if callback != nil {
callback()
}
}, win)
path, err := directory.ImportDirectoryURI()
if err == nil {
Expand Down
2 changes: 1 addition & 1 deletion ui/martine-ui/sprite_tab.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (m *MartineUI) newSpriteTab(s *menu.SpriteMenu) *fyne.Container {
s.IsCpcPlus = b
})

paletteOpen := pal.NewOpenPaletteButton(s, m.window)
paletteOpen := pal.NewOpenPaletteButton(s, m.window, nil)
importOpen := ImportSpriteBoard(m)
gifOpen := applySpriteBoardFromGif(s, m)

Expand Down
2 changes: 1 addition & 1 deletion ui/martine-ui/tilemap_tab.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (m *MartineUI) newTilemapTab(tm *menu.TilemapMenu) *fyne.Container {
tm.IsSprite = true
importOpen := newImportButton(m, tm.ImageMenu)

paletteOpen := pal.NewOpenPaletteButton(tm.ImageMenu, m.window)
paletteOpen := pal.NewOpenPaletteButton(tm.ImageMenu, m.window, nil)

forcePalette := widget.NewCheck("use palette", func(b bool) {
tm.UsePalette = b
Expand Down

0 comments on commit 788d9c7

Please sign in to comment.