-
Notifications
You must be signed in to change notification settings - Fork 0
/
screen.go
125 lines (99 loc) · 3.68 KB
/
screen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright (c) 2018, The GoKi Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// based on golang.org/x/exp/shiny:
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package oswin
import (
"image"
"math"
"github.com/goki/ki/kit"
)
// note: fields obtained from QScreen in Qt
// Screen contains data about each physical and / or logical screen
type Screen struct {
// ScreenNumber is the index of this screen in the list of screens
// maintained under Screen.
ScreenNumber int
// Geometry contains the geometry of the screen in window manager
// size units, which may not be same as raw pixels
Geometry image.Rectangle
// DevicePixelRatio is a factor that scales the screen's
// "natural" pixel coordinates into actual device pixels.
// On OS-X it is backingScaleFactor = 2.0 on "retina"
DevicePixelRatio float32
// PixSize is the number of actual pixels in the screen
// computed as Size * DevicePixelRatio
PixSize image.Point
// PhysicalSize is the actual physical size of the screen, in mm.
PhysicalSize image.Point
// LogicalDPI is the logical dots per inch of the screen,
// which is used for all rendering -- subject to zooming
// effects etc -- see the gi/units package for translating
// into various other units.
LogicalDPI float32
// PhysicalDPI is the physical dots per inch of the screen,
// for generating true-to-physical-size output, for example
// see the gi/units package for translating into various other
// units.
PhysicalDPI float32
// Color depth of the screen, in bits.
Depth int
// Refresh rate in Hz
RefreshRate float32
// todo: not using these yet
// AvailableGeometry image.Rectangle
// VirtualGeometry image.Rectangle
// AvailableVirtualGeometry image.Rectangle
Orientation ScreenOrientation
NativeOrientation ScreenOrientation
PrimaryOrientation ScreenOrientation
Name string
Manufacturer string
Model string
SerialNumber string
}
// ScreenOrientation is the orientation of the device screen.
type ScreenOrientation int32
const (
// OrientationUnknown means device orientation cannot be determined.
//
// Equivalent on Android to Configuration.ORIENTATION_UNKNOWN
// and on iOS to:
// UIDeviceOrientationUnknown
// UIDeviceOrientationFaceUp
// UIDeviceOrientationFaceDown
OrientationUnknown ScreenOrientation = iota
// Portrait is a device oriented so it is tall and thin.
//
// Equivalent on Android to Configuration.ORIENTATION_PORTRAIT
// and on iOS to:
// UIDeviceOrientationPortrait
// UIDeviceOrientationPortraitUpsideDown
Portrait
// Landscape is a device oriented so it is short and wide.
//
// Equivalent on Android to Configuration.ORIENTATION_LANDSCAPE
// and on iOS to:
// UIDeviceOrientationLandscapeLeft
// UIDeviceOrientationLandscapeRight
Landscape
ScreenOrientationN
)
//go:generate stringer -type=ScreenOrientation
var KiT_ScreenOrientation = kit.Enums.AddEnum(ScreenOrientationN, kit.NotBitFlag, nil)
// LogicalFmPhysicalDPI computes the logical DPI used in actual screen scaling
// based on the given logical DPI scale factor (logScale), and also makes it a
// multiple of 6 to make normal font sizes look best.
func LogicalFmPhysicalDPI(logScale, pdpi float32) float32 {
idpi := int(math.Round(float64(pdpi * logScale)))
mdpi := idpi / 6
mdpi *= 6
return float32(mdpi)
}
// InitScreenLogicalDPIFunc is a function that can be set to initialize the
// screen LogicalDPI values based on user preferences etc. Called just before
// first window is opened.
var InitScreenLogicalDPIFunc func()