aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-04-30 19:28:09 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-04-30 20:19:50 +0200
commit865eb76f4d67764711e72da56e2601229cd92d8d (patch)
treea83c3d3c6dd00c84b86fed3dc58d2f64b95c7a6f
parentui: fix log closure variable (diff)
downloadwireguard-windows-865eb76f4d67764711e72da56e2601229cd92d8d.tar.xz
wireguard-windows-865eb76f4d67764711e72da56e2601229cd92d8d.zip
ui: incorrectly adjust icon provider to new dpi awareness
-rw-r--r--ui/iconprovider.go22
-rw-r--r--ui/managewindow.go5
-rw-r--r--ui/ui.go6
3 files changed, 20 insertions, 13 deletions
diff --git a/ui/iconprovider.go b/ui/iconprovider.go
index bff02625..02dcebed 100644
--- a/ui/iconprovider.go
+++ b/ui/iconprovider.go
@@ -27,6 +27,7 @@ type IconProvider struct {
startingPen *walk.CosmeticPen
startedPen *walk.CosmeticPen
updateAvailableImage *walk.Bitmap
+ scale float64
}
const (
@@ -108,10 +109,11 @@ func darkColor(c walk.Color) walk.Color {
return walk.Color((uint32(r*255) << 16) | (uint32(g*255) << 8) | (uint32(b*255) << 0))
}
-func NewIconProvider() (*IconProvider, error) {
+func NewIconProvider(dpi int) (*IconProvider, error) {
tsip := &IconProvider{
imagesByRectAndState: make(map[rectAndState]*walk.Bitmap),
iconsByState: make(map[service.TunnelState]*walk.Icon),
+ scale: float64(dpi) / 96.0,
}
var err error
@@ -154,7 +156,7 @@ func NewIconProvider() (*IconProvider, error) {
}
disposables.Add(tsip.startedPen)
- if tsip.updateAvailableImage, err = tsip.drawUpdateAvailableImage(16); err != nil {
+ if tsip.updateAvailableImage, err = tsip.drawUpdateAvailableImage(16 /* This should be scaled for DPI, but isn't because of walk bug. */); err != nil {
return nil, err
}
disposables.Add(tsip.updateAvailableImage)
@@ -210,6 +212,10 @@ func (tsip *IconProvider) Dispose() {
}
}
+func (tsip *IconProvider) scaleForDPI(i int) int {
+ return int(tsip.scale * float64(i))
+}
+
func (tsip *IconProvider) drawUpdateAvailableImage(size int) (*walk.Bitmap, error) {
updateAvailableBrush, err := walk.NewSolidColorBrush(hexColor(colorUpdateAvailable))
if err != nil {
@@ -234,7 +240,8 @@ func (tsip *IconProvider) drawUpdateAvailableImage(size int) (*walk.Bitmap, erro
}
defer canvas.Dispose()
- rect := walk.Rectangle{0, 0, size, size}
+ margin := 2 // This should be scaled for DPI but isn't, because of walk bug.
+ rect := walk.Rectangle{margin, margin, size - margin*2, size - margin*2}
if err := canvas.FillEllipse(updateAvailableBrush, rect); err != nil {
img.Dispose()
@@ -308,7 +315,8 @@ func (tsip *IconProvider) IconWithOverlayForState(state service.TunnelState) (*w
w := int(float64(size.Width) * 0.75)
h := int(float64(size.Height) * 0.75)
- bounds := walk.Rectangle{4 + size.Width - w, 4 + size.Height - h, w, h}
+ margin := tsip.scaleForDPI(2)
+ bounds := walk.Rectangle{margin + size.Width - w, margin + size.Height - h, w, h}
if err := tsip.PaintForState(state, canvas, bounds); err != nil {
return nil, err
@@ -357,9 +365,9 @@ func (tsip *IconProvider) PaintForState(state service.TunnelState, canvas *walk.
b := bounds
- b.X += 4
- b.Y += 4
- b.Height -= 8
+ b.X += tsip.scaleForDPI(2)
+ b.Y += tsip.scaleForDPI(2)
+ b.Height -= tsip.scaleForDPI(4)
b.Width = b.Height
if err := canvas.FillEllipse(brush, b); err != nil {
diff --git a/ui/managewindow.go b/ui/managewindow.go
index b3e0c832..dc062117 100644
--- a/ui/managewindow.go
+++ b/ui/managewindow.go
@@ -36,6 +36,11 @@ func NewManageTunnelsWindow() (*ManageTunnelsWindow, error) {
}
disposables.Add(mtw)
+ iconProvider, err = NewIconProvider(mtw.DPI())
+ if err != nil {
+ return nil, err
+ }
+
mtw.SetIcon(iconProvider.baseIcon)
mtw.SetTitle("WireGuard")
font, err := walk.NewFont("Segoe UI", 9, 0)
diff --git a/ui/ui.go b/ui/ui.go
index 6c36a100..03ebfc7d 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -34,12 +34,6 @@ func RunUI() {
var err error
- iconProvider, err = NewIconProvider()
- if err != nil {
- walk.MsgBox(nil, "Unable to initialize icon provider", fmt.Sprint(err), walk.MsgBoxIconError)
- return
- }
-
var (
mtw *ManageTunnelsWindow
tray *Tray