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

[New Feature] Integer scaling and super resolution #485

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/kr/text v0.2.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0
github.com/mholt/archiver/v3 v3.5.1
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
github.com/nwaples/rardecode v1.1.2 // indirect
github.com/pelletier/go-toml v1.9.4
github.com/pierrec/lz4/v4 v4.1.12 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mholt/archiver/v3 v3.5.1 h1:rDjOBX9JSF5BvoJGvjqK479aL70qh9DIpZCl+k7Clwo=
github.com/mholt/archiver/v3 v3.5.1/go.mod h1:e3dqJ7H78uzsRSEACH1joayhuSyhnonssnDhppzS1L4=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
github.com/nwaples/rardecode v1.1.0/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0=
github.com/nwaples/rardecode v1.1.2 h1:Cj0yZY6T1Zx1R7AhTbyGSALm44/Mmq+BAPc4B/p/d3M=
github.com/nwaples/rardecode v1.1.2/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0=
Expand Down
4 changes: 2 additions & 2 deletions menu/hints.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
func stackHint(stack *float32, icon uint32, label string, h int) {
menu.Font.SetColor(darkGrey)
*stack += 30 * menu.ratio
menu.DrawImage(icon, *stack, float32(h)-70*menu.ratio, 70*menu.ratio, 70*menu.ratio, 1.0, darkGrey)
menu.DrawImage(icon, *stack, float32(h)-70*menu.ratio2, 70*menu.ratio, 70*menu.ratio2, 1.0, darkGrey)
*stack += 70 * menu.ratio
menu.Font.Printf(*stack, float32(h)-23*menu.ratio, 0.4*menu.ratio, label)
menu.Font.Printf(*stack, float32(h)-23*menu.ratio2, 0.4*menu.ratio2, label)
*stack += menu.Font.Width(0.4*menu.ratio, label)
}

Expand Down
21 changes: 20 additions & 1 deletion menu/menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Menu struct {
tweens Tweens
scroll float32
ratio float32
ratio2 float32
t float64

*video.Video // we embbed video here to have direct access to drawing functions
Expand All @@ -30,13 +31,23 @@ type Menu struct {
// If a game is already running, it will warp the user to the quick menu.
// If not, it will display the menu tabs.
func Init(v *video.Video) *Menu {
w, _ := v.GetFramebufferSize()
// donmor: Now the h value is getting in use
w, h := v.GetFramebufferSize()

menu = &Menu{}
menu.Video = v
menu.stack = []Scene{}
menu.tweens = make(Tweens)
menu.ratio = float32(w) / 1920
// donmor: Added ratio2 for all HEIGHT values if we are under superres and using aspect correction
if settings.Current.VideoSuperRes == "16:9" {
menu.ratio2 = float32(h) / 1080
} else if settings.Current.VideoSuperRes == "4:3" {
menu.ratio2 = float32(h) / 1440
} else {
// donmor: Just give a same value if aspect correction is disabled
menu.ratio2 = menu.ratio
}
menu.icons = map[string]uint32{}

menu.Push(buildTabs())
Expand All @@ -63,6 +74,14 @@ func (m *Menu) Render(dt float32) {
m.t += float64(dt * 8)
w, h := m.GetFramebufferSize()
m.ratio = float32(w) / 1920
// donmor: Don't forget the recalculation :)
if settings.Current.VideoSuperRes == "16:9" {
menu.ratio2 = float32(h) / 1080
} else if settings.Current.VideoSuperRes == "4:3" {
menu.ratio2 = float32(h) / 1440
} else {
menu.ratio2 = menu.ratio
}

if state.CoreRunning {
m.DrawRect(0, 0, float32(w), float32(h), 0, bgColor.Alpha(0.85))
Expand Down
8 changes: 4 additions & 4 deletions menu/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ func (m *Menu) RenderNotifications() {
bg := severityBgColor[n.Severity]
m.DrawRect(
25*m.ratio,
(stack+offset-46)*m.ratio,
lw+40*m.ratio,
(stack+offset-46)*m.ratio2,
lw+40*m.ratio2,
70*m.ratio,
0.25,
bg.Alpha(fading),
)
m.Font.SetColor(fg.Alpha(fading))
m.Font.Printf(
45*m.ratio,
(stack+offset)*m.ratio,
0.5*m.ratio,
(stack+offset)*m.ratio2,
0.5*m.ratio2,
n.Message,
)
stack += h + offset
Expand Down
28 changes: 14 additions & 14 deletions menu/scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,23 +152,23 @@ func genericSegueNext(list *entry) {
func genericDrawCursor(list *entry) {
w, h := menu.GetFramebufferSize()
menu.DrawImage(menu.icons["arrow"],
530*menu.ratio, float32(h)*list.cursor.yp-35*menu.ratio,
70*menu.ratio, 70*menu.ratio, 1, cursorBg.Alpha(list.cursor.alpha))
530*menu.ratio, float32(h)*list.cursor.yp-35*menu.ratio2,
70*menu.ratio, 70*menu.ratio2, 1, cursorBg.Alpha(list.cursor.alpha))
menu.DrawRect(
550*menu.ratio, float32(h)*list.cursor.yp-50*menu.ratio,
float32(w)-630*menu.ratio, 100*menu.ratio, 1, cursorBg.Alpha(list.cursor.alpha))
550*menu.ratio, float32(h)*list.cursor.yp-50*menu.ratio2,
float32(w)-630*menu.ratio, 100*menu.ratio2, 1, cursorBg.Alpha(list.cursor.alpha))
}

// thumbnailDrawCursor draws the blinking rectangular background of the active
// menu entry when there is a thumbnail
func thumbnailDrawCursor(list *entry) {
w, h := menu.GetFramebufferSize()
menu.DrawImage(menu.icons["arrow"],
500*menu.ratio, float32(h)*list.cursor.yp-50*menu.ratio,
100*menu.ratio, 100*menu.ratio, 1, cursorBg.Alpha(list.cursor.alpha))
500*menu.ratio, float32(h)*list.cursor.yp-50*menu.ratio2,
100*menu.ratio, 100*menu.ratio2, 1, cursorBg.Alpha(list.cursor.alpha))
menu.DrawRect(
530*menu.ratio, float32(h)*list.cursor.yp-120*menu.ratio,
float32(w)-630*menu.ratio, 240*menu.ratio, 0.2, cursorBg.Alpha(list.cursor.alpha))
530*menu.ratio, float32(h)*list.cursor.yp-120*menu.ratio2,
float32(w)-630*menu.ratio, 240*menu.ratio2, 0.2, cursorBg.Alpha(list.cursor.alpha))
}

// genericRender renders a vertical list of menu entries
Expand All @@ -185,20 +185,20 @@ func genericRender(list *entry) {
continue
}

fontOffset := 64 * 0.7 * menu.ratio * 0.3
fontOffset := 64 * 0.7 * menu.ratio2 * 0.3

menu.DrawImage(menu.icons[e.icon],
610*menu.ratio-64*0.5*menu.ratio,
float32(h)*e.yp-14*menu.ratio-64*0.5*menu.ratio+fontOffset,
128*menu.ratio, 128*menu.ratio,
float32(h)*e.yp-14*menu.ratio2-64*0.5*menu.ratio2+fontOffset,
128*menu.ratio, 128*menu.ratio2,
0.5, textColor.Alpha(e.iconAlpha))

if e.labelAlpha > 0 {
menu.Font.SetColor(textColor.Alpha(e.labelAlpha))
menu.Font.Printf(
670*menu.ratio,
float32(h)*e.yp+fontOffset,
0.5*menu.ratio, e.label)
0.5*menu.ratio2, e.label)

if e.widget != nil {
e.widget(&e)
Expand All @@ -207,7 +207,7 @@ func genericRender(list *entry) {
menu.Font.Printf(
float32(w)-lw-128*menu.ratio,
float32(h)*e.yp+fontOffset,
0.5*menu.ratio, e.stringValue())
0.5*menu.ratio2, e.stringValue())
}
}
}
Expand Down Expand Up @@ -264,7 +264,7 @@ func askDeleteSavestateConfirmation(cb func()) {

func genericDrawHintBar() {
w, h := menu.GetFramebufferSize()
menu.DrawRect(0, float32(h)-70*menu.ratio, float32(w), 70*menu.ratio, 0, lightGrey)
menu.DrawRect(0, float32(h)-70*menu.ratio2, float32(w), 70*menu.ratio2, 0, lightGrey)

_, upDown, _, a, b, _, _, _, _, guide := hintIcons()

Expand Down
2 changes: 1 addition & 1 deletion menu/scene_core_disk_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (s *sceneCoreDiskControl) render() {

func (s *sceneCoreDiskControl) drawHintBar() {
w, h := menu.GetFramebufferSize()
menu.DrawRect(0, float32(h)-70*menu.ratio, float32(w), 70*menu.ratio, 0, lightGrey)
menu.DrawRect(0, float32(h)-70*menu.ratio2, float32(w), 70*menu.ratio2, 0, lightGrey)

_, upDown, leftRight, _, b, _, _, _, _, guide := hintIcons()

Expand Down
2 changes: 1 addition & 1 deletion menu/scene_core_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (s *sceneCoreOptions) render() {

func (s *sceneCoreOptions) drawHintBar() {
w, h := menu.GetFramebufferSize()
menu.DrawRect(0, float32(h)-70*menu.ratio, float32(w), 70*menu.ratio, 0, lightGrey)
menu.DrawRect(0, float32(h)-70*menu.ratio2, float32(w), 70*menu.ratio2, 0, lightGrey)

_, upDown, leftRight, _, b, _, _, _, _, guide := hintIcons()

Expand Down
26 changes: 13 additions & 13 deletions menu/scene_dialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,21 @@ func (s *sceneDialog) render() {

menu.DrawRect(
fw/2-width/2*menu.ratio,
fh/2-height/2*menu.ratio,
fh/2-height/2*menu.ratio2,
width*menu.ratio,
height*menu.ratio,
height*menu.ratio2,
0.05,
white,
)

menu.Font.SetColor(orange)
lw1 := menu.Font.Width(0.7*menu.ratio, s.title)
menu.Font.Printf(fw/2-lw1/2, fh/2-120*menu.ratio+20*menu.ratio, 0.7*menu.ratio, s.title)
menu.Font.Printf(fw/2-lw1/2, fh/2-120*menu.ratio2+20*menu.ratio2, 0.7*menu.ratio2, s.title)
menu.Font.SetColor(black)
lw2 := menu.Font.Width(0.5*menu.ratio, s.line1)
menu.Font.Printf(fw/2-lw2/2, fh/2-30*menu.ratio+20*menu.ratio, 0.5*menu.ratio, s.line1)
menu.Font.Printf(fw/2-lw2/2, fh/2-30*menu.ratio2+20*menu.ratio2, 0.5*menu.ratio2, s.line1)
lw3 := menu.Font.Width(0.5*menu.ratio, s.line2)
menu.Font.Printf(fw/2-lw3/2, fh/2+30*menu.ratio+20*menu.ratio, 0.5*menu.ratio, s.line2)
menu.Font.Printf(fw/2-lw3/2, fh/2+30*menu.ratio2+20*menu.ratio2, 0.5*menu.ratio2, s.line2)

menu.Font.SetColor(darkGrey)

Expand All @@ -88,23 +88,23 @@ func (s *sceneDialog) render() {
menu.DrawImage(
b,
fw/2-width/2*menu.ratio+margin*menu.ratio,
fh/2+height/2*menu.ratio-70*menu.ratio-margin*menu.ratio,
70*menu.ratio, 70*menu.ratio, 1.0, darkGrey)
fh/2+height/2*menu.ratio2-70*menu.ratio2-margin*menu.ratio2,
70*menu.ratio, 70*menu.ratio2, 1.0, darkGrey)
menu.Font.Printf(
fw/2-width/2*menu.ratio+margin*menu.ratio+70*menu.ratio,
fh/2+height/2*menu.ratio-23*menu.ratio-margin*menu.ratio,
0.4*menu.ratio,
fh/2+height/2*menu.ratio2-23*menu.ratio2-margin*menu.ratio2,
0.4*menu.ratio2,
"NO")

menu.DrawImage(
a,
fw/2+width/2*menu.ratio-150*menu.ratio-margin*menu.ratio,
fh/2+height/2*menu.ratio-70*menu.ratio-margin*menu.ratio,
70*menu.ratio, 70*menu.ratio, 1.0, darkGrey)
fh/2+height/2*menu.ratio2-70*menu.ratio2-margin*menu.ratio2,
70*menu.ratio, 70*menu.ratio2, 1.0, darkGrey)
menu.Font.Printf(
fw/2+width/2*menu.ratio-150*menu.ratio-margin*menu.ratio+70*menu.ratio,
fh/2+height/2*menu.ratio-23*menu.ratio-margin*menu.ratio,
0.4*menu.ratio,
fh/2+height/2*menu.ratio2-23*menu.ratio2-margin*menu.ratio2,
0.4*menu.ratio2,
"YES")
}

Expand Down
38 changes: 20 additions & 18 deletions menu/scene_history.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package menu

import (
"math"
"os"
"path/filepath"

Expand Down Expand Up @@ -163,47 +164,48 @@ func (s *sceneHistory) render() {
continue
}

fontOffset := 64 * 0.7 * menu.ratio * 0.3
fontOffset := 64 * 0.7 * menu.ratio2 * 0.3

if e.labelAlpha > 0 {
drawThumbnail(
list, i,
e.system, e.gameName,
680*menu.ratio-85*e.scale*menu.ratio,
float32(h)*e.yp-14*menu.ratio-64*e.scale*menu.ratio+fontOffset,
170*menu.ratio, 128*menu.ratio,
float32(h)*e.yp-14*menu.ratio2-64*e.scale*menu.ratio2+fontOffset,
170*menu.ratio, 128*menu.ratio2,
e.scale, white.Alpha(e.iconAlpha),
)
menu.DrawBorder(
680*menu.ratio-85*e.scale*menu.ratio,
float32(h)*e.yp-14*menu.ratio-64*e.scale*menu.ratio+fontOffset,
170*menu.ratio*e.scale, 128*menu.ratio*e.scale, 0.02/e.scale,
float32(h)*e.yp-14*menu.ratio2-64*e.scale*menu.ratio2+fontOffset,
170*menu.ratio*e.scale, 128*menu.ratio2*e.scale, 0.02/e.scale,
textColor.Alpha(e.iconAlpha))
if e.path == state.GamePath && e.path != "" {
// donmor: TODO: Does anyone know how to draw an oval here?
menu.DrawCircle(
680*menu.ratio,
float32(h)*e.yp-14*menu.ratio+fontOffset,
90*menu.ratio*e.scale,
float32(h)*e.yp-14*menu.ratio2+fontOffset,
90*float32(math.Sqrt(float64(menu.ratio*menu.ratio2)))*e.scale,
black.Alpha(e.iconAlpha))
menu.DrawImage(menu.icons["resume"],
680*menu.ratio-25*e.scale*menu.ratio,
float32(h)*e.yp-14*menu.ratio-25*e.scale*menu.ratio+fontOffset,
50*menu.ratio, 50*menu.ratio,
float32(h)*e.yp-14*menu.ratio2-25*e.scale*menu.ratio2+fontOffset,
50*menu.ratio, 50*menu.ratio2,
e.scale, white.Alpha(e.iconAlpha))
}

// Offset on Y to vertically center label + sublabel if there is a sublabel
slOffset := float32(0)
if e.subLabel != "" {
slOffset = 30 * menu.ratio * e.subLabelAlpha
slOffset = 30 * menu.ratio2 * e.subLabelAlpha
}

menu.Font.SetColor(textColor.Alpha(e.labelAlpha))
stack := 840 * menu.ratio
menu.Font.Printf(
840*menu.ratio,
float32(h)*e.yp+fontOffset-slOffset,
0.5*menu.ratio, e.label)
0.5*menu.ratio2, e.label)
stack += float32(int(menu.Font.Width(0.5*menu.ratio, e.label)))
stack += 10

Expand All @@ -212,19 +214,19 @@ func (s *sceneHistory) render() {
stack += 20
menu.DrawImage(
menu.icons[tag],
stack, float32(h)*e.yp-22*menu.ratio-slOffset,
60*menu.ratio, 44*menu.ratio, 1.0, white.Alpha(e.tagAlpha))
menu.DrawBorder(stack, float32(h)*e.yp-22*menu.ratio-slOffset,
60*menu.ratio, 44*menu.ratio, 0.05/menu.ratio, black.Alpha(e.tagAlpha/4))
stack, float32(h)*e.yp-22*menu.ratio2-slOffset,
60*menu.ratio, 44*menu.ratio2, 1.0, white.Alpha(e.tagAlpha))
menu.DrawBorder(stack, float32(h)*e.yp-22*menu.ratio2-slOffset,
60*menu.ratio, 44*menu.ratio2, 0.05/menu.ratio, black.Alpha(e.tagAlpha/4))
stack += 60 * menu.ratio
}
}

menu.Font.SetColor(mediumGrey.Alpha(e.subLabelAlpha))
menu.Font.Printf(
840*menu.ratio,
float32(h)*e.yp+fontOffset+60*menu.ratio-slOffset,
0.5*menu.ratio, e.subLabel)
float32(h)*e.yp+fontOffset+60*menu.ratio2-slOffset,
0.5*menu.ratio2, e.subLabel)
}
}

Expand All @@ -233,7 +235,7 @@ func (s *sceneHistory) render() {

func (s *sceneHistory) drawHintBar() {
w, h := menu.GetFramebufferSize()
menu.DrawRect(0, float32(h)-70*menu.ratio, float32(w), 70*menu.ratio, 0, lightGrey)
menu.DrawRect(0, float32(h)-70*menu.ratio2, float32(w), 70*menu.ratio2, 0, lightGrey)

_, upDown, _, a, b, x, _, _, _, guide := hintIcons()

Expand Down
4 changes: 2 additions & 2 deletions menu/scene_keyboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (s *sceneKeyboard) render() {
w, h := menu.GetFramebufferSize()
lines := float32(4)
kbh := float32(h) * 0.6
ksp := (kbh - (50 * menu.ratio)) / (lines + 1)
ksp := (kbh - (50 * menu.ratio2)) / (lines + 1)
ksz := ksp * 0.9
ttw := 10 * ksp

Expand Down Expand Up @@ -205,7 +205,7 @@ func (s *sceneKeyboard) render() {

func (s *sceneKeyboard) drawHintBar() {
w, h := menu.GetFramebufferSize()
menu.DrawRect(0, float32(h)-70*menu.ratio, float32(w), 70*menu.ratio, 0, lightGrey)
menu.DrawRect(0, float32(h)-70*menu.ratio2, float32(w), 70*menu.ratio2, 0, lightGrey)

arrows, _, _, a, b, x, y, start, _, _ := hintIcons()

Expand Down
Loading