From 1b92ea2328ece998b2462af04059aa6d2b48304c Mon Sep 17 00:00:00 2001 From: Jerome Le Saux Date: Tue, 23 Apr 2024 13:38:15 +0200 Subject: [PATCH] add: import editor in image tab --- go.mod | 2 +- go.sum | 2 ++ ui/martine-ui/image_tab.go | 26 ++++++++++++++++++++++++++ ui/martine-ui/menu/image_menu.go | 1 + 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 52ecbb4..ebc87ee 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/esimov/colorquant v1.0.0 github.com/esimov/dithergo v0.0.0-20210215145655-7f9ddf55e848 github.com/jeromelesaux/dsk v0.0.0-20230417191026-0e405580626b - github.com/jeromelesaux/fyne-io v0.0.0-20230824131551-ac61153d16f0 + github.com/jeromelesaux/fyne-io v0.0.0-20240423111224-537209164633 github.com/jeromelesaux/m4client v0.0.0-20230327092026-4e80fd2b1474 github.com/jeromelesaux/zx0 v0.0.0-20220922122216-619a0141f9e0 github.com/mccutchen/palettor v1.0.0 diff --git a/go.sum b/go.sum index 91020fd..30b71ba 100644 --- a/go.sum +++ b/go.sum @@ -226,6 +226,8 @@ github.com/jeromelesaux/dsk v0.0.0-20230417191026-0e405580626b h1:KMI+CK5VfgVD/k github.com/jeromelesaux/dsk v0.0.0-20230417191026-0e405580626b/go.mod h1:yF2+YgO/6yWlK932z+qKOU8wY5rrbtsYAPlSXHfxIS8= github.com/jeromelesaux/fyne-io v0.0.0-20230824131551-ac61153d16f0 h1:Wm1oY9bneRlXP4IEVWy7dlJjnt1DS26gST2BJdaDp8I= github.com/jeromelesaux/fyne-io v0.0.0-20230824131551-ac61153d16f0/go.mod h1:PHMS7sRywpN563NOk5OKuI4LS6dEo7dZFfvApM6z/AE= +github.com/jeromelesaux/fyne-io v0.0.0-20240423111224-537209164633 h1:czC/hKVAYNCay+4Bh/YdKHDD6RSX8IIcU6mKnalLOS4= +github.com/jeromelesaux/fyne-io v0.0.0-20240423111224-537209164633/go.mod h1:PHMS7sRywpN563NOk5OKuI4LS6dEo7dZFfvApM6z/AE= github.com/jeromelesaux/m4client v0.0.0-20200309212559-efb59c22369c/go.mod h1:JO0ijl8YXO6FxogJoC3yAFbBjSAnkwFquc8W6C7k94E= github.com/jeromelesaux/m4client v0.0.0-20230327092026-4e80fd2b1474 h1:CWtkpA4Q63pkhHWRrd/e98JD4YVZhk3SZu58bUkQsuI= github.com/jeromelesaux/m4client v0.0.0-20230327092026-4e80fd2b1474/go.mod h1:Xc0HzC2TZ7fbDWyB8LosvziBQ5QvvwVt3xxAIEavWRc= diff --git a/ui/martine-ui/image_tab.go b/ui/martine-ui/image_tab.go index 25fff55..2648eab 100644 --- a/ui/martine-ui/image_tab.go +++ b/ui/martine-ui/image_tab.go @@ -15,6 +15,7 @@ import ( "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" wgt "github.com/jeromelesaux/fyne-io/widget" + "github.com/jeromelesaux/fyne-io/widget/editor" "github.com/jeromelesaux/martine/constants" "github.com/jeromelesaux/martine/convert/image" "github.com/jeromelesaux/martine/export/amsdos" @@ -24,6 +25,8 @@ import ( "github.com/jeromelesaux/martine/export/m4" "github.com/jeromelesaux/martine/log" + im "image" + "github.com/jeromelesaux/martine/export/png" "github.com/jeromelesaux/martine/export/snapshot" "github.com/jeromelesaux/martine/gfx" @@ -201,6 +204,11 @@ func (m *MartineUI) ApplyOneImage(me *menu.ImageMenu) { me.SetPaletteImage(png.PalToImage(me.Palette())) } +func (m *MartineUI) syncImagePalette(i im.Image, p color.Palette) { + m.main.SetOriginalImage(i) + m.main.SetPalette(p) +} + // nolint: funlen func (m *MartineUI) newImageTransfertTab(me *menu.ImageMenu) *fyne.Container { importOpen := newImportButton(m, me) @@ -342,6 +350,23 @@ func (m *MartineUI) newImageTransfertTab(me *menu.ImageMenu) *fyne.Container { warningLabel := widget.NewLabel("Setting thoses parameters will affect your palette, you can't force palette.") warningLabel.TextStyle = fyne.TextStyle{Bold: true} + editButton := widget.NewButtonWithIcon("Edit", theme.DocumentCreateIcon(), func() { + p := constants.CpcOldPalette + if me.IsCpcPlus { + p = constants.CpcPlusPalette + } + edit := editor.NewEditor(me.OriginalImage().Image, + editor.MagnifyX2, + me.Palette(), + p, m.syncImagePalette) + + d := dialog.NewCustom("Editor", "Ok", edit.NewEditor(), m.window) + size := m.window.Content().Size() + size = fyne.Size{Width: size.Width, Height: size.Height} + d.Resize(size) + d.Show() + }) + return container.New( layout.NewGridLayoutWithColumns(2), container.New( @@ -360,6 +385,7 @@ func (m *MartineUI) newImageTransfertTab(me *menu.ImageMenu) *fyne.Container { applyButton, exportButton, importOpen, + editButton, ), container.New( layout.NewHBoxLayout(), diff --git a/ui/martine-ui/menu/image_menu.go b/ui/martine-ui/menu/image_menu.go index 22ed0bc..2adec4c 100644 --- a/ui/martine-ui/menu/image_menu.go +++ b/ui/martine-ui/menu/image_menu.go @@ -73,6 +73,7 @@ func NewImageMenu() *ImageMenu { func (i *ImageMenu) SetPalette(p color.Palette) { i.palette = p i.SetPaletteImage(png.PalToImage(i.Palette())) + i.paletteImage.Refresh() } func (i *ImageMenu) Palette() color.Palette {