summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-04-02 10:43:28 -0400
committerPietro Gagliardi <[email protected]>2014-04-02 10:43:28 -0400
commit43311a668f56353505632d12a9d749029800dcd7 (patch)
treeb6a9fe4dddd372a848f0c5cbbb10bc805c666cbb
parentfa880a71cce2e3d3fa6af4af0765a390b6478990 (diff)
Switched to calling the Windows MulDiv() function instead of reimplementing it ourselves in prefsize_windows.go.
-rw-r--r--prefsize_windows.go17
1 files changed, 11 insertions, 6 deletions
diff --git a/prefsize_windows.go b/prefsize_windows.go
index 68b54b9..4425f64 100644
--- a/prefsize_windows.go
+++ b/prefsize_windows.go
@@ -112,13 +112,18 @@ func (s *sysData) preferredSize() (width int, height int) {
return width, height
}
-// attempts to mimic the behavior of kernel32.MulDiv()
-// caling it directly would be better (TODO)
-// alternatively TODO make sure the rounding is correct
+var (
+ _mulDiv = kernel32.NewProc("MulDiv")
+)
+
func muldiv(ma int, mb int, div int) int {
- xa := int64(ma) * int64(mb)
- xa /= int64(div)
- return int(xa)
+ // div will not be 0 in the usages above
+ // we also ignore overflow; that isn't likely to happen for our use case anytime soon
+ r1, _, _ := _mulDiv.Call(
+ uintptr(int32(ma)),
+ uintptr(int32(mb)),
+ uintptr(int32(div)))
+ return int(int32(r1))
}
type _TEXTMETRICS struct {