Skip to content

Commit

Permalink
add: import editor in image tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerome Le Saux committed Apr 23, 2024
1 parent 8b567e8 commit 1b92ea2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
26 changes: 26 additions & 0 deletions ui/martine-ui/image_tab.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand All @@ -360,6 +385,7 @@ func (m *MartineUI) newImageTransfertTab(me *menu.ImageMenu) *fyne.Container {
applyButton,
exportButton,
importOpen,
editButton,
),
container.New(
layout.NewHBoxLayout(),
Expand Down
1 change: 1 addition & 0 deletions ui/martine-ui/menu/image_menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1b92ea2

Please sign in to comment.