diff options
author | Kevin Chabowski <kevin@kch42.de> | 2013-08-17 14:57:40 +0200 |
---|---|---|
committer | Kevin Chabowski <kevin@kch42.de> | 2013-08-17 14:57:40 +0200 |
commit | a12232f527666695c57a6014401c1a34c2fb6611 (patch) | |
tree | 76825b119d7862d16af962b94ca9d3499be689b6 | |
parent | a6990de0ba8260d1021188b862c38478f401c721 (diff) | |
download | biomed-a12232f527666695c57a6014401c1a34c2fb6611.tar.gz biomed-a12232f527666695c57a6014401c1a34c2fb6611.tar.bz2 biomed-a12232f527666695c57a6014401c1a34c2fb6611.zip |
GUI is now locked on slow operations (e.g. Filling).
-rw-r--r-- | main.go | 17 | ||||
-rw-r--r-- | mapwidget.go | 31 | ||||
-rw-r--r-- | tools.go | 3 |
3 files changed, 46 insertions, 5 deletions
@@ -15,6 +15,7 @@ type GUI struct { showbiomes *gtk.CheckButton statusContext uint + lastStatus string mapw *MapWidget } @@ -201,7 +202,7 @@ func (g *GUI) Init() { hbox := gtk.NewHBox(false, 0) - g.mapw = NewMapWidget(g.reportError, g.updateInfo) + g.mapw = NewMapWidget(g.reportError, g.updateInfo, g.setBusy) hbox.PackStart(g.mapw.DArea(), true, true, 3) sidebar := g.mkSidebar() @@ -221,6 +222,17 @@ func (g *GUI) Init() { g.setTool(NewFillTool()) } +func (g *GUI) setBusy(b bool) { + g.window.SetSensitive(!b) + g.statusbar.Pop(g.statusContext) + if b { + g.statusbar.Push(g.statusContext, "!!! PLEASE WAIT !!!") + + } else { + g.statusbar.Push(g.statusContext, g.lastStatus) + } +} + func (g *GUI) reportError(msg string) { dlg := gtk.NewMessageDialog(g.window, gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, msg) dlg.Run() @@ -229,8 +241,9 @@ func (g *GUI) reportError(msg string) { } func (g *GUI) updateInfo(x, z int, bio mcmap.Biome) { + g.lastStatus = fmt.Sprintf("X:%d, Z:%d, Biome:%s", x, z, bio) g.statusbar.Pop(g.statusContext) - g.statusbar.Push(g.statusContext, fmt.Sprintf("X:%d, Z:%d, Biome:%s", x, z, bio)) + g.statusbar.Push(g.statusContext, g.lastStatus) } func (g *GUI) mkUpdateToolFx(rb *gtk.RadioButton, t Tool) func() { diff --git a/mapwidget.go b/mapwidget.go index 29c5e0d..37a05d0 100644 --- a/mapwidget.go +++ b/mapwidget.go @@ -68,6 +68,9 @@ type MapWidget struct { reportFail func(msg string) updateInfo func(x, z int, bio mcmap.Biome) + setBusy func(bool) + + toolsEnabled bool isInit bool @@ -286,7 +289,27 @@ func (mw *MapWidget) compose() { } func (mw *MapWidget) useTool(x, z int) { - mw.tool.Do(mw.bio, mw, x, z) + gdk.ThreadsLeave() + defer gdk.ThreadsEnter() + + if !mw.toolsEnabled { + return + } + + if mw.tool.IsSlow() { + mw.toolsEnabled = false + mw.setBusy(true) + + go func() { + mw.tool.Do(mw.bio, mw, x, z) + mw.setBusy(false) + mw.toolsEnabled = true + + mw.redraw <- true + }() + } else { + mw.tool.Do(mw.bio, mw, x, z) + } } func (mw *MapWidget) movement(ctx *glib.CallbackContext) { @@ -475,15 +498,17 @@ func (mw *MapWidget) SetBiomeAt(x, z int, bio mcmap.Biome) { // Update tile if tile, ok := mw.biotiles[pos]; ok { + gdk.ThreadsEnter() drawable := tile.GetDrawable() gc := gdk.NewGC(drawable) gc.SetRgbFgColor(bioColors[bio]) drawable.DrawRectangle(gc, true, bx*zoom, bz*zoom, zoom, zoom) + gdk.ThreadsLeave() } } -func NewMapWidget(reportFail func(msg string), updateInfo func(x, z int, bio mcmap.Biome)) *MapWidget { - mw := &MapWidget{reportFail: reportFail, updateInfo: updateInfo} +func NewMapWidget(reportFail func(msg string), updateInfo func(x, z int, bio mcmap.Biome), setBusy func(bool)) *MapWidget { + mw := &MapWidget{reportFail: reportFail, updateInfo: updateInfo, setBusy: setBusy, toolsEnabled: true} mw.init() return mw } @@ -15,6 +15,7 @@ type XZPos struct { type Tool interface { SingleClick() bool // Whether only one click should be performed (true) or the action should be repeated, if the mouse is dragged + IsSlow() bool Do(bio mcmap.Biome, biogs BiomeGetSetter, x, z int) } @@ -23,6 +24,7 @@ type drawTool struct { } func (d *drawTool) SingleClick() bool { return false } +func (d *drawTool) IsSlow() bool { return false } func (d *drawTool) Do(bio mcmap.Biome, biogs BiomeGetSetter, x, z int) { rad := d.radGetter() @@ -44,6 +46,7 @@ func NewDrawTool(radGetter func() int) *drawTool { type fillTool struct{} func (f *fillTool) SingleClick() bool { return true } +func (f *fillTool) IsSlow() bool { return true } func chkBounds(x, z, xStart, zStart, xEnd, zEnd int) bool { return (x >= xStart) && (z >= zStart) && (x < xEnd) && (z < zEnd) |