Skip to content

Commit

Permalink
Added integer scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
donmor committed Jun 17, 2022
1 parent 500c8ba commit 204b64a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
6 changes: 6 additions & 0 deletions menu/scene_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ var incrCallbacks = map[string]callbackIncrement{
menu.ContextReset()
settings.Save()
},
"VideoIntScaling": func(f *structs.Field, direction int) {
v := f.Value().(bool)
v = !v
f.Set(v)
settings.Save()
},
"VideoMonitorIndex": func(f *structs.Field, direction int) {
v := f.Value().(int)
v += direction
Expand Down
1 change: 1 addition & 0 deletions settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
// Widget sets the graphical representation of the value.
type Settings struct {
VideoFullscreen bool `hide:"ludos" toml:"video_fullscreen" label:"Video Fullscreen" fmt:"%t" widget:"switch"`
VideoIntScaling bool `toml:"video_int_scaling" label:"Video Integer Scaling" fmt:"%t" widget:"switch"`
VideoMonitorIndex int `toml:"video_monitor_index" label:"Video Monitor Index" fmt:"%d"`
VideoFilter string `toml:"video_filter" label:"Video Filter" fmt:"<%s>"`
VideoDarkMode bool `toml:"video_dark_mode" label:"Video Dark Mode" fmt:"%t" widget:"switch"`
Expand Down
42 changes: 37 additions & 5 deletions video/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,41 @@ func (video *Video) coreRatioViewport(fbWidth int, fbHeight int) (x, y, w, h flo
aspectRatio = float32(video.Geom.BaseWidth) / float32(video.Geom.BaseHeight)
}

h = fbh
w = fbh * aspectRatio
if w > fbw {
h = fbw / aspectRatio
w = fbw
// (C) donmor 2022 patch-1 BEGIN
if settings.Current.VideoIntScaling {
gh := video.Geom.BaseHeight
if gh == 0 {
gh = fbHeight
}
scale := fbHeight / gh
h = float32(gh * scale)
if scale == 0 {
h = fbh
}
w = h * aspectRatio
if w > fbw {
gw := video.Geom.BaseWidth
if gw == 0 {
gw = fbWidth
}
scale = fbWidth / int(float32(gh)*aspectRatio)
h = float32(gh * scale)
if scale == 0 {
h = fbw / aspectRatio
w = fbw
} else {
w = h * aspectRatio
}
}
} else {
h = fbh
w = fbh * aspectRatio
if w > fbw {
h = fbw / aspectRatio
w = fbw
}
}
// (C) donmor 2022 patch-1 END

// Place the content in the middle of the window.
x = (fbw - w) / 2
Expand Down Expand Up @@ -350,7 +379,10 @@ func (video *Video) Render() {
return
}

// (C) donmor 2022 patch-1 BEGIN
// fbw, fbh := video.Window.GetFramebufferSize()
fbw, fbh := video.Window.GetFramebufferSize()
// (C) donmor 2022 patch-1 END
_, _, w, h := video.coreRatioViewport(fbw, fbh)

gl.UseProgram(video.program)
Expand Down

0 comments on commit 204b64a

Please sign in to comment.