mirror of
https://github.com/bloeys/nterm.git
synced 2025-12-29 14:38:19 +00:00
Windows DPI awareness
This commit is contained in:
BIN
.winres/icon.png
Executable file
BIN
.winres/icon.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 5.4 KiB |
54
.winres/winres.json
Executable file
54
.winres/winres.json
Executable file
@ -0,0 +1,54 @@
|
|||||||
|
{
|
||||||
|
"RT_GROUP_ICON": {
|
||||||
|
"APP": {
|
||||||
|
"0000": [
|
||||||
|
"icon.png"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"RT_MANIFEST": {
|
||||||
|
"#1": {
|
||||||
|
"0409": {
|
||||||
|
"identity": {},
|
||||||
|
"description": "",
|
||||||
|
"minimum-os": "win7",
|
||||||
|
"execution-level": "",
|
||||||
|
"ui-access": false,
|
||||||
|
"auto-elevate": false,
|
||||||
|
"dpi-aware": "true/pm",
|
||||||
|
"dpi-awareness": "per monitor v2",
|
||||||
|
"disable-theming": false,
|
||||||
|
"disable-window-filtering": false,
|
||||||
|
"high-resolution-scrolling-aware": false,
|
||||||
|
"ultra-high-resolution-scrolling-aware": false,
|
||||||
|
"long-path-aware": false,
|
||||||
|
"printer-driver-isolation": false,
|
||||||
|
"gdi-scaling": false,
|
||||||
|
"segment-heap": false,
|
||||||
|
"use-common-controls-v6": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"RT_VERSION": {
|
||||||
|
"#1": {
|
||||||
|
"0000": {
|
||||||
|
"info": {
|
||||||
|
"0409": {
|
||||||
|
"Comments": "",
|
||||||
|
"CompanyName": "",
|
||||||
|
"FileDescription": "",
|
||||||
|
"FileVersion": "",
|
||||||
|
"InternalName": "",
|
||||||
|
"LegalCopyright": "",
|
||||||
|
"LegalTrademarks": "",
|
||||||
|
"OriginalFilename": "",
|
||||||
|
"PrivateBuild": "",
|
||||||
|
"ProductName": "",
|
||||||
|
"ProductVersion": "",
|
||||||
|
"SpecialBuild": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
22
README.md
22
README.md
@ -1 +1,21 @@
|
|||||||
# nterm
|
# nTerm
|
||||||
|
|
||||||
|
## Developer Notes
|
||||||
|
|
||||||
|
To build without a CLI showing on Windows build with: `go build -ldflags -H=windowsgui .`.
|
||||||
|
|
||||||
|
### OS Manifests
|
||||||
|
|
||||||
|
To ensure we get proper configuration on each OS, we sometimes need extra files that are part of the compilation.
|
||||||
|
This ensures we do get things like icons and proper DPI awareness (which is important for crisp text).
|
||||||
|
|
||||||
|
Those manifests are turned into files (e.g. `*.syso`) that get detected and used by `go build` automatically.
|
||||||
|
|
||||||
|
#### Windows
|
||||||
|
|
||||||
|
The Windows manifest and icon are placed inside the `.winres` folder, which gets compiled into the required
|
||||||
|
`*.syso` files by running `go-winres make --in ./.winres/winres.json`.
|
||||||
|
|
||||||
|
`go-winres` can be installed using `go install github.com/tc-hib/go-winres@latest`.
|
||||||
|
|
||||||
|
**Note:** Any changes to things in `.winres` requires re-running the `go-winres` command and then recompiling the Go program.
|
||||||
|
|||||||
42
main.go
42
main.go
@ -115,6 +115,9 @@ const (
|
|||||||
|
|
||||||
// How many lines to move per scroll
|
// How many lines to move per scroll
|
||||||
defaultScrollSpd = 1
|
defaultScrollSpd = 1
|
||||||
|
|
||||||
|
unscaledWindowWidth = 1280
|
||||||
|
unscaledWindowHeight = 720
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -137,8 +140,11 @@ func main() {
|
|||||||
panic("Failed to init engine. Err: " + err.Error())
|
panic("Failed to init engine. Err: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This scaling lets us respect the user's request for zoomed-in programs
|
||||||
|
dpiScaling := getDpiScaling()
|
||||||
|
|
||||||
rend := rend3dgl.NewRend3DGL()
|
rend := rend3dgl.NewRend3DGL()
|
||||||
win, err := engine.CreateOpenGLWindowCentered("nTerm", 1280, 720, engine.WindowFlags_ALLOW_HIGHDPI|engine.WindowFlags_RESIZABLE, rend)
|
win, err := engine.CreateOpenGLWindowCentered("nTerm", int32(unscaledWindowWidth*dpiScaling), int32(unscaledWindowHeight*dpiScaling), engine.WindowFlags_ALLOW_HIGHDPI|engine.WindowFlags_RESIZABLE, rend)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("Failed to create window. Err: " + err.Error())
|
panic("Failed to create window. Err: " + err.Error())
|
||||||
}
|
}
|
||||||
@ -197,6 +203,40 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getDpiScaling() float32 {
|
||||||
|
|
||||||
|
// Great read on DPI here: https://nlguillemot.wordpress.com/2016/12/11/high-dpi-rendering/
|
||||||
|
|
||||||
|
// The no-scaling DPI on different platforms (e.g. when scale=100% on windows)
|
||||||
|
var defaultDpi float32 = 96
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
defaultDpi = 96
|
||||||
|
} else if runtime.GOOS == "darwin" {
|
||||||
|
defaultDpi = 72
|
||||||
|
}
|
||||||
|
|
||||||
|
// Current DPI of the monitor
|
||||||
|
_, dpiHorizontal, _, err := sdl.GetDisplayDPI(0)
|
||||||
|
if err != nil {
|
||||||
|
dpiHorizontal = defaultDpi
|
||||||
|
fmt.Printf("Failed to get DPI with error '%s'. Using default DPI of '%f'\n", err.Error(), defaultDpi)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scaling factor (e.g. will be 1.25 for 125% scaling on windows)
|
||||||
|
dpiScaling := dpiHorizontal / defaultDpi
|
||||||
|
|
||||||
|
fmt.Printf(
|
||||||
|
"Default DPI=%f\nHorizontal DPI=%f\nDPI scaling=%f\nUnscaled window size (width, height)=(%d, %d)\nScaled window size (width, height)=(%d, %d)\n\n",
|
||||||
|
defaultDpi,
|
||||||
|
dpiHorizontal,
|
||||||
|
dpiScaling,
|
||||||
|
unscaledWindowWidth, unscaledWindowHeight,
|
||||||
|
int32(unscaledWindowWidth*dpiScaling), int32(unscaledWindowHeight*dpiScaling),
|
||||||
|
)
|
||||||
|
|
||||||
|
return dpiScaling
|
||||||
|
}
|
||||||
|
|
||||||
func (nt *nterm) handleSDLEvent(e sdl.Event) {
|
func (nt *nterm) handleSDLEvent(e sdl.Event) {
|
||||||
|
|
||||||
switch e := e.(type) {
|
switch e := e.(type) {
|
||||||
|
|||||||
BIN
rsrc_windows_386.syso
Executable file
BIN
rsrc_windows_386.syso
Executable file
Binary file not shown.
BIN
rsrc_windows_amd64.syso
Executable file
BIN
rsrc_windows_amd64.syso
Executable file
Binary file not shown.
Reference in New Issue
Block a user