aboutsummaryrefslogtreecommitdiffstats
path: root/win
diff options
context:
space:
mode:
authorfaiface <faiface2202@gmail.com>2019-05-06 11:31:49 +0200
committerfaiface <faiface2202@gmail.com>2019-05-06 11:31:49 +0200
commiteb5229cff0852d1f0429b8b95d34526274959121 (patch)
tree616e54fc8220c44191de9143876e779e5be93ea6 /win
parent7dba175f7317e9ae0c5505863a4ccc353590d37c (diff)
downloadgui-eb5229cff0852d1f0429b8b95d34526274959121.zip
win: fix mouse position on hiDPI
Diffstat (limited to 'win')
-rw-r--r--win/win.go17
1 files changed, 9 insertions, 8 deletions
diff --git a/win/win.go b/win/win.go
index ede594d..4050da3 100644
--- a/win/win.go
+++ b/win/win.go
@@ -79,10 +79,10 @@ func New(opts ...Option) (*Win, error) {
mainthread.Call(func() {
// hiDPI hack
width, _ := w.w.GetFramebufferSize()
- ratioW := width / o.width
- if ratioW != 1 {
- o.width /= ratioW
- o.height /= ratioW
+ w.ratio = width / o.width
+ if w.ratio != 1 {
+ o.width /= w.ratio
+ o.height /= w.ratio
}
w.w.Destroy()
w.w, err = makeGLFWWin(&o)
@@ -155,8 +155,9 @@ type Win struct {
newSize chan image.Rectangle
finish chan struct{}
- w *glfw.Window
- img *image.RGBA
+ w *glfw.Window
+ img *image.RGBA
+ ratio int
}
// Events returns the events channel of the window.
@@ -209,9 +210,9 @@ func (w *Win) eventThread() {
}
switch action {
case glfw.Press:
- w.eventsIn <- gui.Eventf("mo/down/%d/%d/%s", moX, moY, b)
+ w.eventsIn <- gui.Eventf("mo/down/%d/%d/%s", moX*w.ratio, moY*w.ratio, b)
case glfw.Release:
- w.eventsIn <- gui.Eventf("mo/up/%d/%d/%s", moX, moY, b)
+ w.eventsIn <- gui.Eventf("mo/up/%d/%d/%s", moX*w.ratio, moY*w.ratio, b)
}
})