From e338efa5d5708d8797fc1bfd30c163415d48f3c7 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Thu, 15 Aug 2013 20:56:19 +0200 Subject: Added MapWidget It already draws the map and the biomes and can be moved with the middle mouse button. --- main.go | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 9d432db..4ea998d 100644 --- a/main.go +++ b/main.go @@ -3,8 +3,10 @@ package main import ( "fmt" "github.com/kch42/gomcmap/mcmap" + "github.com/mattn/go-gtk/gdk" "github.com/mattn/go-gtk/glib" "github.com/mattn/go-gtk/gtk" + "os" ) type GUI struct { @@ -12,6 +14,8 @@ type GUI struct { statusbar *gtk.Statusbar showbiomes *gtk.CheckButton + mapw *MapWidget + tool Tool } @@ -24,7 +28,14 @@ func (g *GUI) openWorldDlg() { } func (g *GUI) openWorld(path string) { - fmt.Println(path) + region, err := mcmap.OpenRegion(path, false) + if err != nil { + dlg := gtk.NewMessageDialog(g.window, gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, "Could not load world %s:\n%s", path, err.Error()) + dlg.Run() + dlg.Destroy() + } + + go g.mapw.setRegion(region) } func (g *GUI) aboutDlg() { @@ -185,7 +196,8 @@ func (g *GUI) Init() { hbox := gtk.NewHBox(false, 0) - // TODO: Drawing area thing missing... + g.mapw = NewMapWidget(g.reportError) + hbox.PackStart(g.mapw.DArea(), true, true, 3) toolbox := g.mkToolbox() hbox.PackEnd(toolbox, false, false, 3) @@ -201,6 +213,13 @@ func (g *GUI) Init() { g.window.Connect("destroy", g.exitApp) } +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() + dlg.Destroy() + os.Exit(1) +} + func (g *GUI) mkUpdateToolFx(rb *gtk.RadioButton, t Tool) func() { return func() { if rb.GetActive() { @@ -226,7 +245,7 @@ func (g *GUI) setBiome(bio mcmap.Biome) { } func (g *GUI) showbiomesToggled() { - fmt.Printf("Show biomes: %v\n", g.showbiomes.GetActive()) + g.mapw.SetShowBiomes(g.showbiomes.GetActive()) } func (g *GUI) undo() { @@ -242,6 +261,9 @@ func (g *GUI) exitApp() { } func main() { + glib.ThreadInit(nil) + gdk.ThreadsInit() + gdk.ThreadsEnter() gtk.Init(nil) gui := new(GUI) @@ -249,4 +271,5 @@ func main() { gui.Show() gtk.Main() + gdk.ThreadsLeave() } -- cgit v1.2.3-54-g00ecf