From c961973c581f9685e6a0e699bd20851d654eaf3e Mon Sep 17 00:00:00 2001 From: jimmyl <70376633+mc-oofert@users.noreply.github.com> Date: Sat, 29 Jul 2023 17:50:18 +0200 Subject: [PATCH 1/6] feature: add screenshot in selection adds a checkmark to the screenshot function that allows you to screenshot only the currently selected area --- .../wsmap/pmap/psettings/screenshot.go | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/internal/app/ui/cpwsarea/wsmap/pmap/psettings/screenshot.go b/internal/app/ui/cpwsarea/wsmap/pmap/psettings/screenshot.go index 0ec34c85..e5532df9 100644 --- a/internal/app/ui/cpwsarea/wsmap/pmap/psettings/screenshot.go +++ b/internal/app/ui/cpwsarea/wsmap/pmap/psettings/screenshot.go @@ -5,7 +5,8 @@ import ( "image/png" "os" "time" - + + "sdmm/internal/app/ui/cpwsarea/wsmap/tools" "sdmm/internal/app/render/bucket/level/chunk/unit" "sdmm/internal/app/ui/cpwsarea/wsmap/pmap/canvas" appdialog "sdmm/internal/app/ui/dialog" @@ -23,6 +24,7 @@ import ( type sessionScreenshot struct { saving bool + inselection bool } func (p *Panel) showScreenshot() { @@ -37,6 +39,8 @@ func (p *Panel) showScreenshot() { imgui.SetNextItemWidth(-1) imgui.InputText("##screenshot_dir", &cfg.ScreenshotDir) + + imgui.Checkbox("Screenshot in Selection", &p.sessionScreenshot.inselection) var createBtnLabel string if p.sessionScreenshot.saving { @@ -57,12 +61,28 @@ func (p *Panel) showScreenshot() { func (p *Panel) createScreenshot() { p.sessionScreenshot.saving = true - - width, height := p.editor.Dmm().MaxX*dmmap.WorldIconSize, p.editor.Dmm().MaxY*dmmap.WorldIconSize + toolSelect := tools.SetSelected(tools.TNGrab).(*tools.ToolGrab) + bounds := toolSelect.Bounds() + var width, height int + if p.sessionScreenshot.inselection && toolSelect.HasSelectedArea() { + width, height = (int(bounds.X2-bounds.X1)+1)*dmmap.WorldIconSize, (int(bounds.Y2-bounds.Y1)+1)*dmmap.WorldIconSize + } else if p.sessionScreenshot.inselection && !toolSelect.HasSelectedArea() { + appdialog.Open(appdialog.TypeInformation{ + Title: "Nothing selected!", + Information: "Screenshot in Selection is on, but you have nothing selected.", + }) + p.sessionScreenshot.saving = false + return + } else { + width, height = p.editor.Dmm().MaxX*dmmap.WorldIconSize, p.editor.Dmm().MaxY*dmmap.WorldIconSize + } c := canvas.New() c.ClearColor = canvas.Color{} // Empty clear color with no alpha c.Render().Camera.Level = p.editor.ActiveLevel() + if p.sessionScreenshot.inselection { + c.Render().Camera.Translate(-float32((int(bounds.X1) - 1) *dmmap.WorldIconSize), -float32((int(bounds.Y1) - 1) *dmmap.WorldIconSize)) + } c.Render().SetUnitProcessor(p) for level := 1; level <= p.editor.ActiveLevel(); level++ { c.Render().UpdateBucket(p.editor.Dmm(), level) // Prepare for render all available levels From bb2dad291cea025e40fd69230ec1cb2d8eb1300d Mon Sep 17 00:00:00 2001 From: jimmyl <70376633+mc-oofert@users.noreply.github.com> Date: Sat, 29 Jul 2023 20:34:17 +0200 Subject: [PATCH 2/6] supposedly linted properly --- .../wsmap/pmap/psettings/screenshot.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/internal/app/ui/cpwsarea/wsmap/pmap/psettings/screenshot.go b/internal/app/ui/cpwsarea/wsmap/pmap/psettings/screenshot.go index e5532df9..3b1c4c5b 100644 --- a/internal/app/ui/cpwsarea/wsmap/pmap/psettings/screenshot.go +++ b/internal/app/ui/cpwsarea/wsmap/pmap/psettings/screenshot.go @@ -5,10 +5,10 @@ import ( "image/png" "os" "time" - - "sdmm/internal/app/ui/cpwsarea/wsmap/tools" + "sdmm/internal/app/render/bucket/level/chunk/unit" "sdmm/internal/app/ui/cpwsarea/wsmap/pmap/canvas" + "sdmm/internal/app/ui/cpwsarea/wsmap/tools" appdialog "sdmm/internal/app/ui/dialog" "sdmm/internal/dmapi/dmmap" "sdmm/internal/imguiext" @@ -23,7 +23,7 @@ import ( ) type sessionScreenshot struct { - saving bool + saving bool inselection bool } @@ -39,7 +39,7 @@ func (p *Panel) showScreenshot() { imgui.SetNextItemWidth(-1) imgui.InputText("##screenshot_dir", &cfg.ScreenshotDir) - + imgui.Checkbox("Screenshot in Selection", &p.sessionScreenshot.inselection) var createBtnLabel string @@ -66,11 +66,11 @@ func (p *Panel) createScreenshot() { var width, height int if p.sessionScreenshot.inselection && toolSelect.HasSelectedArea() { width, height = (int(bounds.X2-bounds.X1)+1)*dmmap.WorldIconSize, (int(bounds.Y2-bounds.Y1)+1)*dmmap.WorldIconSize - } else if p.sessionScreenshot.inselection && !toolSelect.HasSelectedArea() { + } else if p.sessionScreenshot.inselection && !toolSelect.HasSelectedArea() { appdialog.Open(appdialog.TypeInformation{ - Title: "Nothing selected!", - Information: "Screenshot in Selection is on, but you have nothing selected.", - }) + Title: "Nothing selected!", + Information: "Screenshot in Selection is on, but you have nothing selected.", + }) p.sessionScreenshot.saving = false return } else { @@ -81,7 +81,7 @@ func (p *Panel) createScreenshot() { c.ClearColor = canvas.Color{} // Empty clear color with no alpha c.Render().Camera.Level = p.editor.ActiveLevel() if p.sessionScreenshot.inselection { - c.Render().Camera.Translate(-float32((int(bounds.X1) - 1) *dmmap.WorldIconSize), -float32((int(bounds.Y1) - 1) *dmmap.WorldIconSize)) + c.Render().Camera.Translate(-float32((int(bounds.X1)-1)*dmmap.WorldIconSize), -float32((int(bounds.Y1)-1)*dmmap.WorldIconSize)) } c.Render().SetUnitProcessor(p) for level := 1; level <= p.editor.ActiveLevel(); level++ { From 83dede73eb9b85d12a7b328abf36efa518e288b8 Mon Sep 17 00:00:00 2001 From: jimmyl <70376633+mc-oofert@users.noreply.github.com> Date: Sun, 30 Jul 2023 11:45:42 +0200 Subject: [PATCH 3/6] review stuff --- .../wsmap/pmap/psettings/screenshot.go | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/internal/app/ui/cpwsarea/wsmap/pmap/psettings/screenshot.go b/internal/app/ui/cpwsarea/wsmap/pmap/psettings/screenshot.go index 3b1c4c5b..7606f994 100644 --- a/internal/app/ui/cpwsarea/wsmap/pmap/psettings/screenshot.go +++ b/internal/app/ui/cpwsarea/wsmap/pmap/psettings/screenshot.go @@ -24,7 +24,7 @@ import ( type sessionScreenshot struct { saving bool - inselection bool + inSelectionMode bool } func (p *Panel) showScreenshot() { @@ -40,7 +40,9 @@ func (p *Panel) showScreenshot() { imgui.SetNextItemWidth(-1) imgui.InputText("##screenshot_dir", &cfg.ScreenshotDir) - imgui.Checkbox("Screenshot in Selection", &p.sessionScreenshot.inselection) + if imgui.Checkbox("Screenshot in Selection", &p.sessionScreenshot.inSelectionMode) { + tools.SetSelected(tools.TNGrab) + } var createBtnLabel string if p.sessionScreenshot.saving { @@ -61,15 +63,19 @@ func (p *Panel) showScreenshot() { func (p *Panel) createScreenshot() { p.sessionScreenshot.saving = true - toolSelect := tools.SetSelected(tools.TNGrab).(*tools.ToolGrab) - bounds := toolSelect.Bounds() + selectedTool := tools.Selected() + grabCurrentlySelected := selectedTool.Name() == tools.TNGrab + bounds := util.Bounds{X1: 0, Y1: 0, X2: 0, Y2: 0} var width, height int - if p.sessionScreenshot.inselection && toolSelect.HasSelectedArea() { + if p.sessionScreenshot.inSelectionMode && grabCurrentlySelected && selectedTool.(*tools.ToolGrab).HasSelectedArea() { + bounds = selectedTool.(*tools.ToolGrab).Bounds() //set us to the bounds of the select tool so we can calculate width and height width, height = (int(bounds.X2-bounds.X1)+1)*dmmap.WorldIconSize, (int(bounds.Y2-bounds.Y1)+1)*dmmap.WorldIconSize - } else if p.sessionScreenshot.inselection && !toolSelect.HasSelectedArea() { + bounds.X1 = -float32((int(bounds.X1)-1) * dmmap.WorldIconSize) //now change bounds so we can use them in Translate + bounds.Y1 = -float32((int(bounds.Y1)-1) * dmmap.WorldIconSize) + } else if p.sessionScreenshot.inSelectionMode && !grabCurrentlySelected || !selectedTool.(*tools.ToolGrab).HasSelectedArea() { appdialog.Open(appdialog.TypeInformation{ Title: "Nothing selected!", - Information: "Screenshot in Selection is on, but you have nothing selected.", + Information: "Screenshot in Selection is on, but you have nothing selected. Use the grab tool!", }) p.sessionScreenshot.saving = false return @@ -80,9 +86,7 @@ func (p *Panel) createScreenshot() { c := canvas.New() c.ClearColor = canvas.Color{} // Empty clear color with no alpha c.Render().Camera.Level = p.editor.ActiveLevel() - if p.sessionScreenshot.inselection { - c.Render().Camera.Translate(-float32((int(bounds.X1)-1)*dmmap.WorldIconSize), -float32((int(bounds.Y1)-1)*dmmap.WorldIconSize)) - } + c.Render().Camera.Translate(bounds.X1, bounds.Y1) c.Render().SetUnitProcessor(p) for level := 1; level <= p.editor.ActiveLevel(); level++ { c.Render().UpdateBucket(p.editor.Dmm(), level) // Prepare for render all available levels From a6686e9043d5bcddf25ea0cb696274cd9b468597 Mon Sep 17 00:00:00 2001 From: jimmyl <70376633+mc-oofert@users.noreply.github.com> Date: Sun, 30 Jul 2023 11:48:13 +0200 Subject: [PATCH 4/6] linter --- internal/app/ui/cpwsarea/wsmap/pmap/psettings/screenshot.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/app/ui/cpwsarea/wsmap/pmap/psettings/screenshot.go b/internal/app/ui/cpwsarea/wsmap/pmap/psettings/screenshot.go index 7606f994..8bfcb6de 100644 --- a/internal/app/ui/cpwsarea/wsmap/pmap/psettings/screenshot.go +++ b/internal/app/ui/cpwsarea/wsmap/pmap/psettings/screenshot.go @@ -23,7 +23,7 @@ import ( ) type sessionScreenshot struct { - saving bool + saving bool inSelectionMode bool } @@ -70,8 +70,8 @@ func (p *Panel) createScreenshot() { if p.sessionScreenshot.inSelectionMode && grabCurrentlySelected && selectedTool.(*tools.ToolGrab).HasSelectedArea() { bounds = selectedTool.(*tools.ToolGrab).Bounds() //set us to the bounds of the select tool so we can calculate width and height width, height = (int(bounds.X2-bounds.X1)+1)*dmmap.WorldIconSize, (int(bounds.Y2-bounds.Y1)+1)*dmmap.WorldIconSize - bounds.X1 = -float32((int(bounds.X1)-1) * dmmap.WorldIconSize) //now change bounds so we can use them in Translate - bounds.Y1 = -float32((int(bounds.Y1)-1) * dmmap.WorldIconSize) + bounds.X1 = -float32((int(bounds.X1) - 1) * dmmap.WorldIconSize) //now change bounds so we can use them in Translate + bounds.Y1 = -float32((int(bounds.Y1) - 1) * dmmap.WorldIconSize) } else if p.sessionScreenshot.inSelectionMode && !grabCurrentlySelected || !selectedTool.(*tools.ToolGrab).HasSelectedArea() { appdialog.Open(appdialog.TypeInformation{ Title: "Nothing selected!", From c358b365d54b1c1963a91aed631c42eb7bd1883c Mon Sep 17 00:00:00 2001 From: jimmyl <70376633+mc-oofert@users.noreply.github.com> Date: Sun, 30 Jul 2023 13:06:57 +0200 Subject: [PATCH 5/6] review change --- .../app/ui/cpwsarea/wsmap/pmap/psettings/screenshot.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/app/ui/cpwsarea/wsmap/pmap/psettings/screenshot.go b/internal/app/ui/cpwsarea/wsmap/pmap/psettings/screenshot.go index 8bfcb6de..48617f29 100644 --- a/internal/app/ui/cpwsarea/wsmap/pmap/psettings/screenshot.go +++ b/internal/app/ui/cpwsarea/wsmap/pmap/psettings/screenshot.go @@ -65,13 +65,13 @@ func (p *Panel) createScreenshot() { p.sessionScreenshot.saving = true selectedTool := tools.Selected() grabCurrentlySelected := selectedTool.Name() == tools.TNGrab - bounds := util.Bounds{X1: 0, Y1: 0, X2: 0, Y2: 0} + boundX, boundY := float32(0), float32(0) var width, height int if p.sessionScreenshot.inSelectionMode && grabCurrentlySelected && selectedTool.(*tools.ToolGrab).HasSelectedArea() { - bounds = selectedTool.(*tools.ToolGrab).Bounds() //set us to the bounds of the select tool so we can calculate width and height + bounds := selectedTool.(*tools.ToolGrab).Bounds() //get grab tool bounds so we can calculate boundX and boundY width, height = (int(bounds.X2-bounds.X1)+1)*dmmap.WorldIconSize, (int(bounds.Y2-bounds.Y1)+1)*dmmap.WorldIconSize - bounds.X1 = -float32((int(bounds.X1) - 1) * dmmap.WorldIconSize) //now change bounds so we can use them in Translate - bounds.Y1 = -float32((int(bounds.Y1) - 1) * dmmap.WorldIconSize) + boundX = -float32((int(bounds.X1) - 1) * dmmap.WorldIconSize) //now change bounds so we can use them in Translate + boundY = -float32((int(bounds.Y1) - 1) * dmmap.WorldIconSize) } else if p.sessionScreenshot.inSelectionMode && !grabCurrentlySelected || !selectedTool.(*tools.ToolGrab).HasSelectedArea() { appdialog.Open(appdialog.TypeInformation{ Title: "Nothing selected!", @@ -86,7 +86,7 @@ func (p *Panel) createScreenshot() { c := canvas.New() c.ClearColor = canvas.Color{} // Empty clear color with no alpha c.Render().Camera.Level = p.editor.ActiveLevel() - c.Render().Camera.Translate(bounds.X1, bounds.Y1) + c.Render().Camera.Translate(boundX, boundY) c.Render().SetUnitProcessor(p) for level := 1; level <= p.editor.ActiveLevel(); level++ { c.Render().UpdateBucket(p.editor.Dmm(), level) // Prepare for render all available levels From 6a263304b6a66c9d81ba91f98af4d45e52aaf219 Mon Sep 17 00:00:00 2001 From: jimmyl <70376633+mc-oofert@users.noreply.github.com> Date: Mon, 31 Jul 2023 10:09:26 +0200 Subject: [PATCH 6/6] review changes --- .../wsmap/pmap/psettings/screenshot.go | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/internal/app/ui/cpwsarea/wsmap/pmap/psettings/screenshot.go b/internal/app/ui/cpwsarea/wsmap/pmap/psettings/screenshot.go index 48617f29..9a53d267 100644 --- a/internal/app/ui/cpwsarea/wsmap/pmap/psettings/screenshot.go +++ b/internal/app/ui/cpwsarea/wsmap/pmap/psettings/screenshot.go @@ -67,18 +67,20 @@ func (p *Panel) createScreenshot() { grabCurrentlySelected := selectedTool.Name() == tools.TNGrab boundX, boundY := float32(0), float32(0) var width, height int - if p.sessionScreenshot.inSelectionMode && grabCurrentlySelected && selectedTool.(*tools.ToolGrab).HasSelectedArea() { - bounds := selectedTool.(*tools.ToolGrab).Bounds() //get grab tool bounds so we can calculate boundX and boundY - width, height = (int(bounds.X2-bounds.X1)+1)*dmmap.WorldIconSize, (int(bounds.Y2-bounds.Y1)+1)*dmmap.WorldIconSize - boundX = -float32((int(bounds.X1) - 1) * dmmap.WorldIconSize) //now change bounds so we can use them in Translate - boundY = -float32((int(bounds.Y1) - 1) * dmmap.WorldIconSize) - } else if p.sessionScreenshot.inSelectionMode && !grabCurrentlySelected || !selectedTool.(*tools.ToolGrab).HasSelectedArea() { - appdialog.Open(appdialog.TypeInformation{ - Title: "Nothing selected!", - Information: "Screenshot in Selection is on, but you have nothing selected. Use the grab tool!", - }) - p.sessionScreenshot.saving = false - return + if p.sessionScreenshot.inSelectionMode { + if !grabCurrentlySelected || !selectedTool.(*tools.ToolGrab).HasSelectedArea() { + appdialog.Open(appdialog.TypeInformation{ + Title: "Nothing selected!", + Information: "Screenshot in Selection is on, but you have nothing selected. Use the grab tool!", + }) + p.sessionScreenshot.saving = false + return + } else { + bounds := selectedTool.(*tools.ToolGrab).Bounds() //get grab tool bounds so we can calculate boundX and boundY + width, height = (int(bounds.X2-bounds.X1)+1)*dmmap.WorldIconSize, (int(bounds.Y2-bounds.Y1)+1)*dmmap.WorldIconSize + boundX = -float32((int(bounds.X1) - 1) * dmmap.WorldIconSize) //now change bounds so we can use them in Translate + boundY = -float32((int(bounds.Y1) - 1) * dmmap.WorldIconSize) + } } else { width, height = p.editor.Dmm().MaxX*dmmap.WorldIconSize, p.editor.Dmm().MaxY*dmmap.WorldIconSize }