summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2013-08-17 12:51:43 +0200
committerKevin Chabowski <kevin@kch42.de>2013-08-17 12:51:43 +0200
commita6990de0ba8260d1021188b862c38478f401c721 (patch)
tree9c37846350ab91cf01bb3268b7f19b0c3f42c6bb
parent3eb5c63db2cb68bcd9765270b68893de649c4264 (diff)
downloadbiomed-a6990de0ba8260d1021188b862c38478f401c721.tar.gz
biomed-a6990de0ba8260d1021188b862c38478f401c721.tar.bz2
biomed-a6990de0ba8260d1021188b862c38478f401c721.zip
Better panning & some renames.
* Tiles are now redrawn after panning (makes panning smoother). * Renamed mouse status vars. * Added useTool
-rw-r--r--mapwidget.go34
1 files changed, 23 insertions, 11 deletions
diff --git a/mapwidget.go b/mapwidget.go
index e8b23b3..29c5e0d 100644
--- a/mapwidget.go
+++ b/mapwidget.go
@@ -73,9 +73,9 @@ type MapWidget struct {
showBiomes bool
- offX, offZ int
- mx1, mx2, my1, my2 int
- primMButton, middleMButton bool
+ offX, offZ int
+ mx1, mx2, my1, my2 int
+ continueTool, panning bool
pixmap *gdk.Pixmap
pixmapGC *gdk.GC
@@ -285,6 +285,10 @@ func (mw *MapWidget) compose() {
}
}
+func (mw *MapWidget) useTool(x, z int) {
+ mw.tool.Do(mw.bio, mw, x, z)
+}
+
func (mw *MapWidget) movement(ctx *glib.CallbackContext) {
if mw.gdkwin == nil {
mw.gdkwin = mw.dArea.GetWindow()
@@ -307,19 +311,19 @@ func (mw *MapWidget) movement(ctx *glib.CallbackContext) {
}
mw.updateInfo(x, z, bio)
- if mw.middleMButton {
+ if mw.panning {
if (mw.mx1 != -1) && (mw.my1 != -1) {
mw.offX += mw.mx1 - mw.mx2
mw.offZ += mw.my1 - mw.my2
gdk.ThreadsLeave()
- mw.tileCmds <- cmdUpdateTiles
+ mw.redraw <- true
gdk.ThreadsEnter()
}
}
- if mw.primMButton {
- mw.tool.Do(mw.bio, mw, x, z)
+ if mw.continueTool {
+ mw.useTool(x, z)
gdk.ThreadsLeave()
mw.redraw <- true
@@ -339,7 +343,15 @@ func (mw *MapWidget) buttonChanged(ctx *glib.CallbackContext) {
switch gdk.EventType(bev.Type) {
case gdk.BUTTON_RELEASE:
- mw.primMButton, mw.middleMButton = false, false
+ if mw.panning {
+ mw.panning = false
+
+ gdk.ThreadsLeave()
+ mw.tileCmds <- cmdUpdateTiles
+ gdk.ThreadsEnter()
+ }
+
+ mw.continueTool = false
case gdk.BUTTON_PRESS:
switch bev.Button {
case 1:
@@ -348,17 +360,17 @@ func (mw *MapWidget) buttonChanged(ctx *glib.CallbackContext) {
}
x := (mw.offX + int(bev.X)) / zoom
z := (mw.offZ + int(bev.Y)) / zoom
- mw.tool.Do(mw.bio, mw, x, z)
+ mw.useTool(x, z)
gdk.ThreadsLeave()
mw.redraw <- true
gdk.ThreadsEnter()
if !mw.tool.SingleClick() {
- mw.primMButton = true
+ mw.continueTool = true
}
case 2:
- mw.middleMButton = true
+ mw.panning = true
}
}
}