Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds "Screenshot in Selection" checkbox to screenshot tool #216

Merged
merged 6 commits into from
Jul 31, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions internal/app/ui/cpwsarea/wsmap/pmap/psettings/screenshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"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"
Expand All @@ -22,7 +23,8 @@ import (
)

type sessionScreenshot struct {
saving bool
saving bool
inselection bool
SpaiR marked this conversation as resolved.
Show resolved Hide resolved
}

func (p *Panel) showScreenshot() {
Expand All @@ -38,6 +40,8 @@ func (p *Panel) showScreenshot() {
imgui.SetNextItemWidth(-1)
imgui.InputText("##screenshot_dir", &cfg.ScreenshotDir)

imgui.Checkbox("Screenshot in Selection", &p.sessionScreenshot.inselection)
SpaiR marked this conversation as resolved.
Show resolved Hide resolved

var createBtnLabel string
if p.sessionScreenshot.saving {
createBtnLabel = "Creating" + []string{".", "..", "...", "...."}[int(imgui.Time()/.25)&3] + "###create"
Expand All @@ -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)
SpaiR marked this conversation as resolved.
Show resolved Hide resolved
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))
}
SpaiR marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down