Beispiel #1
0
/*
 * Erzeugt die ganzen Events für das drawing area mittels lambdas.
 *
 * Parameter:
 *     drawingarea - Die drawing area auf der gezeichnet werden soll
 *
 * Zu den Schnittstellenkommentaren: Leider gibts das anscheinend nicht direkt
 *                                   in go (jedenfall kein @param etc.) :/
 */
func createEvents(drawingarea *gtk.DrawingArea) {
	// Wir brauchen ne pixmap in der wir die Pixeldaten speichern
	var pixmap *gdk.Pixmap
	// gdk.GC ist einfach eine Sammlung an Eigenschaften und Einstellungen zum zeichnen
	var gc *gdk.GC
	p := point{x: -1, y: -1}

	drawingarea.Connect("configure-event", func() {
		// wenns schon ne pixmap gibt, lösche diese
		if pixmap != nil {
			pixmap.Unref()
		}

		// hole pixmap und stuff
		allocation := drawingarea.GetAllocation()
		pixmap = gdk.NewPixmap(drawingarea.GetWindow().GetDrawable(), allocation.Width, allocation.Height, 24)

		// weißen Hintergrund zeichnen:
		gc = gdk.NewGC(pixmap.GetDrawable())
		gc.SetRgbFgColor(gdk.NewColor("white"))
		pixmap.GetDrawable().DrawRectangle(gc, true, 0, 0, -1, -1)

		// Vorder- und Hintergrundfarbe setzen
		gc.SetRgbFgColor(gdk.NewColor("black"))
		gc.SetRgbBgColor(gdk.NewColor("red"))
	})

	// dieses event wird ausgeführt wenn auf das widget geklickt wurde
	drawingarea.Connect("button-press-event", func(ctx *glib.CallbackContext) {
		// Argumente holen
		arg := ctx.Args(0)
		// irgend son pointer auf ein objekt holen in dem mehr Infos stehen
		mev := *(**gdk.EventMotion)(unsafe.Pointer(&arg))
		// Position ausgeben
		fmt.Println("Geklickte Position: ", p)

		// hier ist meine eigene Logik:
		// Wenn noch kein Klick registriert wurde ist p.x == p.y == -1 und da soll noch nichts gezeichnet werden
		// erst wenn der zweite klick kommt soll zwischen diesem und dem alten eine Linie gezeichnet werden
		p_neu := point{x: int(mev.X), y: int(mev.Y)}
		if p.x != -1 && p.y != -1 {
			pixmap.GetDrawable().DrawLine(gc, p.x, p.y, p_neu.x, p_neu.y)
			drawingarea.GetWindow().Invalidate(nil, false)
		}
		// Position des neuen klicks speichern, es ist also der neue startpunkt der nächsten linie
		p = p_neu
	})

	// dieses event wird ausgeführt wenn drawingarea.GetWindow().Invalidate(nil, false) aufgerufen wird
	drawingarea.Connect("expose-event", func() {
		if pixmap != nil {
			drawingarea.GetWindow().GetDrawable().DrawDrawable(gc, pixmap.GetDrawable(), 0, 0, 0, 0, -1, -1)
		}
	})

	// Events müssen manuell spezifiziert werden.
	// Hier werden immer MASKs übergeben, hier also eben die BUTTON_PRESS_MASK,
	// welche erst in einen int gecastet werden muss
	drawingarea.SetEvents(int(gdk.BUTTON_PRESS_MASK))
}
Beispiel #2
0
func display_init_grid(gc *gdk.GC, pixmap *gdk.Pixmap) {
	gc.SetRgbFgColor(gdk.NewColor("grey"))
	pixmap.GetDrawable().DrawRectangle(gc, true, 0, 0, -1, -1)
	for x := 0; x < 19; x++ {
		for y := 0; y < 19; y++ {
			gc.SetRgbFgColor(gdk.NewColor("grey"))
			draw_square(gc, pixmap, x, y)
		}
	}
	gc.SetRgbFgColor(gdk.NewColor("black"))
	pixmap.GetDrawable().DrawArc(gc, true, (4*INTER)-(CIRCLE/2), (4*INTER)-(CIRCLE/2),
		CIRCLE, CIRCLE, 0, 64*360)
	pixmap.GetDrawable().DrawArc(gc, true, (10*INTER)-(CIRCLE/2), (4*INTER)-(CIRCLE/2),
		CIRCLE, CIRCLE, 0, 64*360)
	pixmap.GetDrawable().DrawArc(gc, true, (16*INTER)-(CIRCLE/2), (4*INTER)-(CIRCLE/2),
		CIRCLE, CIRCLE, 0, 64*360)
	pixmap.GetDrawable().DrawArc(gc, true, (4*INTER)-(CIRCLE/2), (10*INTER)-(CIRCLE/2),
		CIRCLE, CIRCLE, 0, 64*360)
	pixmap.GetDrawable().DrawArc(gc, true, (10*INTER)-(CIRCLE/2), (10*INTER)-(CIRCLE/2),
		CIRCLE, CIRCLE, 0, 64*360)
	pixmap.GetDrawable().DrawArc(gc, true, (16*INTER)-(CIRCLE/2), (10*INTER)-(CIRCLE/2),
		CIRCLE, CIRCLE, 0, 64*360)
	pixmap.GetDrawable().DrawArc(gc, true, (4*INTER)-(CIRCLE/2), (16*INTER)-(CIRCLE/2),
		CIRCLE, CIRCLE, 0, 64*360)
	pixmap.GetDrawable().DrawArc(gc, true, (10*INTER)-(CIRCLE/2), (16*INTER)-(CIRCLE/2),
		CIRCLE, CIRCLE, 0, 64*360)
	pixmap.GetDrawable().DrawArc(gc, true, (16*INTER)-(CIRCLE/2), (16*INTER)-(CIRCLE/2),
		CIRCLE, CIRCLE, 0, 64*360)
}
Beispiel #3
0
func draw_square(gc *gdk.GC, pixmap *gdk.Pixmap, x, y int) {
	gc.SetRgbFgColor(gdk.NewColor("grey"))
	pixmap.GetDrawable().DrawRectangle(gc, true,
		x*INTER+DEC,
		y*INTER+DEC,
		40,
		40)
	gc.SetRgbFgColor(gdk.NewColor("black"))
	pixmap.GetDrawable().DrawLine(gc,
		x*INTER+INTER/2+DEC,
		y*INTER+DEC,
		x*INTER+INTER/2+DEC,
		y*INTER+INTER+DEC)
	pixmap.GetDrawable().DrawLine(gc,
		x*INTER+DEC,
		y*INTER+INTER/2+DEC,
		x*INTER+INTER+DEC,
		y*INTER+INTER/2+DEC)
	if x == 0 {
		clean_side(gc, pixmap, 0, y*INTER+DEC, INTER, INTER) // LEFT
	} else if x == 18 {
		clean_side(gc, pixmap, HEIGHT-INTER+1, y*INTER+DEC, -1, INTER) // RIGHT
	}
	if y == 0 {
		clean_side(gc, pixmap, x*INTER+DEC, 0, x*INTER+INTER+DEC, INTER) // TOP
	} else if y == 18 {
		clean_side(gc, pixmap, x*INTER+DEC, HEIGHT-INTER+1, INTER, -1) // BOT
	}
}
Beispiel #4
0
func (g *Graph) plotGrid() {

	// First draw the minor grid
	g.gc.SetRgbFgColor(gdk.NewColor("grey"))
	g.drawGrid(g.xMinorInterval, g.yMinorInterval)

	// And the major grid
	g.gc.SetRgbFgColor(gdk.NewColor("black"))
	g.drawGrid(g.xMajorInterval, g.yMajorInterval)
}
Beispiel #5
0
func clean_side(gc *gdk.GC, pixmap *gdk.Pixmap, x1, y1, x2, y2 int) {
	gc.SetRgbFgColor(gdk.NewColor("grey"))
	pixmap.GetDrawable().DrawRectangle(gc, true,
		x1,
		y1,
		x2,
		y2)
}
Beispiel #6
0
func (cb ColorBuffer) Color(name string) *gdk.Color {
	if col, ok := cb[name]; ok {
		return col
	}

	col := gdk.NewColor(name)
	cb[name] = col
	return col
}
Beispiel #7
0
func (g *Graph) plot() {
	g.clear()
	g.plotGrid()

	g.gc.SetRgbFgColor(gdk.NewColor("blue"))
	g.gc.S

	s := signal.Step{-3, complex128(1.25)}
	for x := -20; x <= 20; x++ {
		g.drawLineScaled(float64(x), 0, float64(x), real(s.Get(x)))
	}
}
Beispiel #8
0
func calc_hint() {
	for {
		select {
		case <-calcHint:
			if stopGame == false && stopClick == false {
				info.SetLabel(fmt.Sprintf("Hint: calculating..."))
				hintx, hinty = IATurn(&game)
				xx := hintx*INTER + INTER
				yy := hinty*INTER + INTER
				gc.SetRgbFgColor(gdk.NewColor("green"))
				pixmap.GetDrawable().DrawArc(gc, true, xx-(STONE/2), yy-(STONE/2), STONE, STONE, 0, 64*360)
				info.SetLabel(fmt.Sprintf("Hint: %d/%d", hintx+1, hinty+1))
				drawingarea.GetWindow().Invalidate(nil, false)
			}
		}
	}
}
Beispiel #9
0
func (g *GUI) updateBiomeInfo() {
	vbox := gtk.NewVBox(false, 0)
	var grp *glib.SList

	for _, biome := range g.biomes {
		biohbox := gtk.NewHBox(false, 0)
		cbox := colorBox(gdk.NewColor(biome.Color))
		cbox.SetSizeRequest(20, 20)
		biohbox.PackStart(cbox, false, false, 3)
		rbutton := gtk.NewRadioButtonWithLabel(grp, biome.Name)
		grp = rbutton.GetGroup()
		rbutton.Connect("toggled", g.mkUpdateBiomeFx(rbutton, biome.ID))
		biohbox.PackEnd(rbutton, true, true, 3)
		vbox.PackStart(biohbox, false, false, 3)
	}

	g.bioVBoxWrap.Remove(g.bioVBox)
	g.bioVBoxWrap.PackStart(vbox, false, false, 3)
	vbox.ShowAll()
	g.bioVBox = vbox

	g.mapw.updateBioLookup(MkBiomeLookup(g.biomes))
}
Beispiel #10
0
func (rw *RegionWrapper) renderTile(chunk *mcmap.Chunk) (maptile, biotile *gdk.Pixmap, biocache []mcmap.Biome) {
	maptile = emptyPixmap(tileSize, tileSize, 24)
	mtDrawable := maptile.GetDrawable()
	mtGC := gdk.NewGC(mtDrawable)

	biotile = emptyPixmap(tileSize, tileSize, 24)
	btDrawable := biotile.GetDrawable()
	btGC := gdk.NewGC(btDrawable)

	biocache = make([]mcmap.Biome, mcmap.ChunkRectXZ)

	i := 0
	for z := 0; z < mcmap.ChunkSizeXZ; z++ {
	scanX:
		for x := 0; x < mcmap.ChunkSizeXZ; x++ {
			bio := chunk.Biome(x, z)
			btGC.SetRgbFgColor(rw.bioLookup.Color(bio))
			btDrawable.DrawRectangle(btGC, true, x*zoom, z*zoom, zoom, zoom)

			biocache[i] = bio
			i++

			for y := chunk.Height(x, z); y >= 0; y-- {
				if col, ok := blockColors[chunk.Block(x, y, z).ID]; ok {
					mtGC.SetRgbFgColor(col)
					mtDrawable.DrawRectangle(mtGC, true, x*zoom, z*zoom, zoom, zoom)
					continue scanX
				}
			}

			mtGC.SetRgbFgColor(gdk.NewColor("#ffffff"))
			mtDrawable.DrawRectangle(mtGC, true, x*zoom, z*zoom, zoom, zoom)
		}
	}

	return
}
Beispiel #11
0
func main() {
	gtk.Init(&os.Args)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle("GTK DrawingArea")
	window.Connect("destroy", gtk.MainQuit)

	vbox := gtk.NewVBox(true, 0)
	vbox.SetBorderWidth(5)
	drawingarea := gtk.NewDrawingArea()

	var p1, p2 point
	var gdkwin *gdk.Window
	var pixmap *gdk.Pixmap
	var gc *gdk.GC
	p1.x = -1
	p1.y = -1
	colors := []string{
		"black",
		"gray",
		"blue",
		"purple",
		"red",
		"orange",
		"yellow",
		"green",
		"darkgreen",
	}

	drawingarea.Connect("configure-event", func() {
		if pixmap != nil {
			pixmap.Unref()
		}
		allocation := drawingarea.GetAllocation()
		pixmap = gdk.NewPixmap(drawingarea.GetWindow().GetDrawable(), allocation.Width, allocation.Height, 24)
		gc = gdk.NewGC(pixmap.GetDrawable())
		gc.SetRgbFgColor(gdk.NewColor("white"))
		pixmap.GetDrawable().DrawRectangle(gc, true, 0, 0, -1, -1)
		gc.SetRgbFgColor(gdk.NewColor(colors[0]))
		gc.SetRgbBgColor(gdk.NewColor("white"))
	})

	drawingarea.Connect("motion-notify-event", func(ctx *glib.CallbackContext) {
		arg := ctx.Args(0)
		mev := *(**gdk.EventMotion)(unsafe.Pointer(&arg))
		var mt gdk.ModifierType
		if mev.IsHint != 0 {
			gdkwin.GetPointer(&p2.x, &p2.y, &mt)
		} else {
			p2.x, p2.y = int(mev.X), int(mev.Y)
		}
		if p1.x != -1 && p2.x != -1 && (gdk.EventMask(mt)&gdk.BUTTON_PRESS_MASK) != 0 {
			pixmap.GetDrawable().DrawLine(gc, p1.x, p1.y, p2.x, p2.y)
			gdkwin.Invalidate(nil, false)
		}
		colors = append(colors[1:], colors[0])
		gc.SetRgbFgColor(gdk.NewColor(colors[0]))
		p1 = p2
	})

	drawingarea.Connect("expose-event", func() {
		if pixmap == nil {
			return
		}
		gdkwin.GetDrawable().DrawDrawable(gc, pixmap.GetDrawable(), 0, 0, 0, 0, -1, -1)
	})

	drawingarea.SetEvents(int(gdk.POINTER_MOTION_MASK | gdk.POINTER_MOTION_HINT_MASK | gdk.BUTTON_PRESS_MASK))
	vbox.Add(drawingarea)

	window.Add(vbox)
	window.SetSizeRequest(400, 400)
	window.ShowAll()

	gdkwin = drawingarea.GetWindow()

	gtk.Main()
}
Beispiel #12
0
func main() {
	var autoupdating bool = false
	var autoticker *time.Ticker
	var entries [][]*gtk.Entry = make([][]*gtk.Entry, entitylimit)
	for i := 0; i < entitylimit; i++ {
		entries[i] = make([]*gtk.Entry, entityfields)
	}
	var entities []*physics.Entity = initentities(entries)

	// Initialize gtk
	gtk.Init(nil)

	// WINDOW
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetPosition(gtk.WIN_POS_CENTER)
	window.SetTitle("Gravity Visualization")

	// Connect top window closing to gtk main loop closing
	window.Connect("destroy", func(ctx *glib.CallbackContext) {
		gtk.MainQuit()
	})

	// TOP VERTICAL BOX
	topvbox := gtk.NewVBox(false, 1)

	// NOTEBOOK FOR TABS
	notebook := gtk.NewNotebook()

	// DRAWING AREA VERTICAL BOX
	davbox := gtk.NewVBox(false, 1)

	// DRAWING AREA
	drawingarea = gtk.NewDrawingArea()
	drawingarea.SetSizeRequest(width, height)
	drawingarea.ModifyBG(gtk.STATE_NORMAL, gdk.NewColor("white"))
	drawingarea.Connect("expose_event", func() {
		drawentities(entities)
	})
	davbox.PackStart(drawingarea, true, true, 0)

	// TICK SPEED SLIDER
	ticksliderhbox := gtk.NewHBox(false, 1)

	ticksliderlabel := gtk.NewLabel("Time between ticks (ms)")
	ticksliderhbox.Add(ticksliderlabel)

	tickslider := gtk.NewHScaleWithRange(1, 1000, 100)
	// Default value of 10 ms
	tickslider.SetValue(10)
	ticksliderhbox.Add(tickslider)
	davbox.Add(ticksliderhbox)

	// BUTTONS
	buttons := gtk.NewHBox(false, 1)

	// RESET MENU ITEM
	resetbutton := gtk.NewButtonWithLabel("Reset")
	resetbutton.Clicked(func() {
		entities = initentities(entries)
		drawingarea.QueueDraw()
	})
	buttons.Add(resetbutton)

	// TICK MENU ITEM
	tickbutton := gtk.NewButtonWithLabel("Tick")
	tickbutton.Clicked(func() {
		updateentities(entities)
	})
	buttons.Add(tickbutton)

	// AUTOUPDATE MENU ITEM
	autotickbutton := gtk.NewToggleButtonWithLabel("AutoUpdate")
	autotickbutton.Clicked(func() {
		// Stop the previous ticker if it exists
		if autoticker != nil {
			autoticker.Stop()
		}

		if autoupdating {
			// Toggle autoupdating state
			autoupdating = false
		} else {
			// Start the ticker
			autoticker = time.NewTicker(time.Duration(tickslider.GetValue()) * time.Millisecond)

			// Spawn a goroutine that will run update entities every tick
			go func() {
				for _ = range autoticker.C {
					updateentities(entities)
				}
			}()

			// Toggle autoupdating state
			autoupdating = true
		}
	})
	buttons.Add(autotickbutton)
	davbox.Add(buttons)

	notebook.AppendPage(davbox, gtk.NewLabel("Simulation"))

	// INITIALIZE PANEL
	entitiesvbox := gtk.NewVBox(false, 1)

	// INITIALIZE LABELS FOR TABLE
	titles := gtk.NewHBox(false, 1)
	titles.Add(gtk.NewLabel("Mass"))
	titles.Add(gtk.NewLabel("X-Pos"))
	titles.Add(gtk.NewLabel("Y-Pos"))
	titles.Add(gtk.NewLabel("X-Vel"))
	titles.Add(gtk.NewLabel("Y-Vel"))
	titles.Add(gtk.NewLabel("X-Acc"))
	titles.Add(gtk.NewLabel("Y-Acc"))
	entitiesvbox.Add(titles)

	// INITIALIZE ENTRIES IN ROWS FOR TABLE
	for row := 0; row < entitylimit; row++ {
		rowbox := gtk.NewHBox(false, 1)
		for col := 0; col < entityfields; col++ {
			textfield := gtk.NewEntry()
			// Hold reference to text field in entries 2d array
			entries[row][col] = textfield
			rowbox.Add(textfield)
		}
		entitiesvbox.Add(rowbox)
	}

	// CLEAR ENTITIES BUTTON
	clearentitiesbutton := gtk.NewButtonWithLabel("Clear Entries")
	clearentitiesbutton.Clicked(func() {
		for row := 0; row < entitylimit; row++ {
			for col := 0; col < entityfields; col++ {
				entries[row][col].SetText("")
			}
		}
	})
	entitiesvbox.Add(clearentitiesbutton)

	// Limit the size of the entitiesvbox and add to notebook
	entitiesvbox.SetSizeRequest(width, height)
	notebook.AppendPage(entitiesvbox, gtk.NewLabel("Entities"))

	// FINISH PACKING COMPONENTS
	topvbox.PackStart(notebook, false, false, 0)

	// FINISH PACKING WINDOW
	window.Add(topvbox)

	// Show the GUI
	window.ShowAll()

	// Grab the drawable and initialize graphics context now that they are initialized
	drawable = drawingarea.GetWindow().GetDrawable()
	blackgc = gdk.NewGC(drawable)
	redgc = gdk.NewGC(drawable)
	redgc.SetRgbFgColor(gdk.NewColorRGB(255, 0, 0))
	bluegc = gdk.NewGC(drawable)
	bluegc.SetRgbFgColor(gdk.NewColorRGB(0, 0, 255))

	gtk.Main()
}
Beispiel #13
0
	return biomes, nil
}

func WriteBiomeInfos(biomes []BiomeInfo, w io.Writer) error {
	for _, bio := range biomes {
		if _, err := fmt.Fprintf(w, "%d\t%d\t%s\t%s\n", bio.ID, bio.SnowLine, bio.Color, bio.Name); err != nil {
			return err
		}
	}

	return nil
}

type BiomeLookup map[mcmap.Biome]BiomeInfo

var colBlack = gdk.NewColor("#000000")
var colBuf = make(ColorBuffer)

func (bl BiomeLookup) Color(bio mcmap.Biome) *gdk.Color {
	if info, ok := bl[bio]; ok {
		return colBuf.Color(info.Color)
	}

	return colBlack
}

func (bl BiomeLookup) SnowLine(bio mcmap.Biome) int {
	if info, ok := bl[bio]; ok {
		return info.SnowLine
	}
Beispiel #14
0
func menu_bar(vbox *gtk.VBox) {
	menubar := gtk.NewMenuBar()
	vbox.PackStart(menubar, false, false, 0)

	buttons := gtk.NewAlignment(0, 0, 0, 0)
	checkbox := gtk.NewAlignment(1, 0, 0, 0)
	newPlayerGameButton := gtk.NewButtonWithLabel("Player vs Player")
	newIaGameButton := gtk.NewButtonWithLabel("Player vs AI")
	info = gtk.NewLabel("Hint: Not yet")
	threeCheckBox := gtk.NewCheckButtonWithLabel("Three and three")
	endCheckBox := gtk.NewCheckButtonWithLabel("Unbreakable end")
	hintCheckBox := gtk.NewCheckButtonWithLabel("Hint")
	hbox := gtk.NewHBox(false, 1)
	hbox0 := gtk.NewHBox(false, 1)
	hbox1 := gtk.NewHBox(false, 1)
	hbox0.Add(newPlayerGameButton)
	hbox0.Add(newIaGameButton)
	hbox1.Add(hintCheckBox)
	hbox1.Add(threeCheckBox)
	hbox1.Add(endCheckBox)
	buttons.Add(hbox0)
	checkbox.Add(hbox1)
	hbox.Add(buttons)
	hbox.Add(info)
	hbox.Add(checkbox)
	vbox.PackStart(hbox, false, true, 0)

	cascademenu := gtk.NewMenuItemWithMnemonic("_Game")
	menubar.Append(cascademenu)
	submenu := gtk.NewMenu()
	cascademenu.SetSubmenu(submenu)
	playermenuitem := gtk.NewMenuItemWithMnemonic("_Player Vs Player")
	playermenuitem.Connect("activate", func() {
		gc.SetRgbFgColor(gdk.NewColor("grey"))
		pixmap.GetDrawable().DrawRectangle(gc, true, 0, 0, -1, -1)
		game = Gomoku{make([]int, 361), true, game.endgameTake, game.doubleThree, 1, [2]int{10, 10}, 0}
		player = 1
		countTake = 0
		iamode = false
		display_init_grid(gc, pixmap)
		drawingarea.Hide()
		drawingarea.Show()
		stopGame = false
		stopClick = false
		context_id := statusbar.GetContextId("go-gtk")
		statusbar.Push(context_id, "(not so) Proudly propulsed by the inglorious Gomoku Project, with love, and Golang!")
	})
	submenu.Append(playermenuitem)
	newPlayerGameButton.Clicked(func() {
		playermenuitem.Activate()
	})
	iamenuitem := gtk.NewMenuItemWithMnemonic("_Player Vs AI")
	iamenuitem.Connect("activate", func() {
		gc.SetRgbFgColor(gdk.NewColor("grey"))
		pixmap.GetDrawable().DrawRectangle(gc, true, 0, 0, -1, -1)
		game = Gomoku{make([]int, 361), true, game.endgameTake, game.doubleThree, 1, [2]int{10, 10}, 0}
		player = 1
		countTake = 0
		iamode = true
		display_init_grid(gc, pixmap)
		drawingarea.Hide()
		drawingarea.Show()
		stopGame = false
		stopClick = false
		context_id := statusbar.GetContextId("go-gtk")
		statusbar.Push(context_id, "(not so) Proudly propulsed by the inglorious Gomoku Project, with love, and Golang!")
	})
	submenu.Append(iamenuitem)
	newIaGameButton.Clicked(func() {
		iamenuitem.Activate()
	})
	menuitem = gtk.NewMenuItemWithMnemonic("E_xit")
	menuitem.Connect("activate", func() {
		gtk.MainQuit()
	})
	submenu.Append(menuitem)

	threeCheckBox.Connect("toggled", func() {
		if game.doubleThree == false {
			game.doubleThree = true
		} else {
			game.doubleThree = false
		}
	})

	endCheckBox.Connect("toggled", func() {
		if game.endgameTake == false {
			game.endgameTake = true
		} else {
			game.endgameTake = false
		}
	})

	hintCheckBox.Connect("toggled", func() {
		if hint == false {
			hint = true
			calcHint <- true
		} else {
			hint = false
		}
	})

}
Beispiel #15
0
func event_play(x, y int) (bool, int) {
	vic, stones, err := game.Play(x, y)
	if err != nil {
		return false, vic
	}
	context_id := statusbar.GetContextId("go-gtk")
	statusbar.Push(context_id, fmt.Sprintf("[Player 1/2 : %d/%d stone before death] Last move is Player %d : %d/%d",
		game.countTake[1], game.countTake[0], player, x+1, y+1))
	if (hintx != lastx || hinty != lasty) && (hintx >= 0 && hinty >= 0) {
		draw_square(gc, pixmap, hintx, hinty)
	}
	for _, stone := range stones {
		countTake++
		if countTake > 19 {
			break
		}
		draw_square(gc, pixmap, stone[0], stone[1])
		if player == 1 {
			gc.SetRgbFgColor(gdk.NewColor("white"))
		} else {
			gc.SetRgbFgColor(gdk.NewColor("black"))
		}
		tmpx := 800
		tmpy := countTake * INTER
		tmpx = ((tmpx-INTER/2)/INTER)*INTER + INTER
		tmpy = ((tmpy-INTER/2)/INTER)*INTER + INTER
		pixmap.GetDrawable().DrawArc(gc, true, tmpx-(STONE/2)+10,
			tmpy-(STONE/2), STONE, STONE, 0, 64*360)
	}
	if player == 1 {
		gc.SetRgbFgColor(gdk.NewColor("black"))
		player = 2
	} else {
		gc.SetRgbFgColor(gdk.NewColor("white"))
		player = 1
	}
	lastx = x
	lasty = y
	x = x*INTER + INTER
	y = y*INTER + INTER
	pixmap.GetDrawable().DrawArc(gc, true, x-(STONE/2), y-(STONE/2), STONE, STONE, 0, 64*360)
	if vic != 0 {
		WINNER = fmt.Sprintf("And the winner is \"Player %d\"!", vic)
		context_id := statusbar.GetContextId("go-gtk")
		statusbar.Push(context_id, WINNER)
		stopGame = true
	}
	drawingarea.GetWindow().Invalidate(nil, false)
	if vic != 0 {
		messagedialog := gtk.NewMessageDialog(
			statusbar.GetTopLevelAsWindow(),
			gtk.DIALOG_MODAL,
			gtk.MESSAGE_INFO,
			gtk.BUTTONS_OK,
			WINNER)
		messagedialog.Response(func() {
			messagedialog.Destroy()
		})
		messagedialog.Run()
	}
	return true, vic
}
Beispiel #16
0
func (frm *biomeEditFrame) setBiomeInfo(info BiomeInfo) {
	frm.colorInput.SetColor(gdk.NewColor(info.Color))
	frm.idInput.SetText(strconv.FormatInt(int64(info.ID), 10))
	frm.snowLineInput.SetText(strconv.FormatInt(int64(info.SnowLine), 10))
	frm.nameInput.SetText(info.Name)
}
Beispiel #17
0
package main

import (
	"github.com/mattn/go-gtk/gdk"
	"github.com/silvasur/gomcmap/mcmap"
)

var blockColors = map[mcmap.BlockID]*gdk.Color{
	mcmap.BlkStone:                      gdk.NewColor("#666666"),
	mcmap.BlkGrassBlock:                 gdk.NewColor("#00aa00"),
	mcmap.BlkDirt:                       gdk.NewColor("#644804"),
	mcmap.BlkCobblestone:                gdk.NewColor("#7a7a7a"),
	mcmap.BlkWoodPlanks:                 gdk.NewColor("#a4721c"),
	mcmap.BlkBedrock:                    gdk.NewColor("#111111"),
	mcmap.BlkWater:                      gdk.NewColor("#0000ff"),
	mcmap.BlkStationaryWater:            gdk.NewColor("#0000ff"),
	mcmap.BlkLava:                       gdk.NewColor("#ff4400"),
	mcmap.BlkStationaryLava:             gdk.NewColor("#ff4400"),
	mcmap.BlkSand:                       gdk.NewColor("#f1ee85"),
	mcmap.BlkGravel:                     gdk.NewColor("#9ba3a9"),
	mcmap.BlkGoldOre:                    gdk.NewColor("#ffa200"),
	mcmap.BlkIronOre:                    gdk.NewColor("#e1e1e1"),
	mcmap.BlkCoalOre:                    gdk.NewColor("#333333"),
	mcmap.BlkWood:                       gdk.NewColor("#a4721c"),
	mcmap.BlkLeaves:                     gdk.NewColor("#57a100"),
	mcmap.BlkGlass:                      gdk.NewColor("#eeeeff"),
	mcmap.BlkLapisLazuliOre:             gdk.NewColor("#3114e3"),
	mcmap.BlkLapisLazuliBlock:           gdk.NewColor("#3114e3"),
	mcmap.BlkDispenser:                  gdk.NewColor("#7a7a7a"),
	mcmap.BlkSandstone:                  gdk.NewColor("#f1ee85"),
	mcmap.BlkNoteBlock:                  gdk.NewColor("#a4721c"),
func Init(title string) {
	gtk.Init(nil)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetPosition(gtk.WIN_POS_CENTER)
	window.SetTitle(title)
	window.SetIconName("gtk-dialog-info")
	window.Connect("destroy", func(ctx *glib.CallbackContext) {
		fmt.Println("got destroy!", ctx.Data().(string))
		gtk.MainQuit()
	}, "foo")

	//--------------------------------------------------------
	// GtkVBox
	//--------------------------------------------------------
	vbox := gtk.NewVBox(false, 1)

	//--------------------------------------------------------
	// GtkMenuBar
	//--------------------------------------------------------
	menubar := gtk.NewMenuBar()
	vbox.PackStart(menubar, false, false, 0)

	//--------------------------------------------------------
	// GtkDrawable
	//--------------------------------------------------------

	drawingarea := gtk.NewDrawingArea()
	//var gdkwin *gdk.Window
	var pixmap *gdk.Pixmap
	var gc *gdk.GC
	drawingarea.Connect("configure-event", func() {
		println("Configuring drawingArea!")
		if pixmap != nil {
			pixmap.Unref()
		}
		allocation := drawingarea.GetAllocation()
		pixmap = gdk.NewPixmap(drawingarea.GetWindow().GetDrawable(), allocation.Width, allocation.Height, 24)
		gc = gdk.NewGC(pixmap.GetDrawable())
		gc.SetRgbFgColor(gdk.NewColor("white"))
		pixmap.GetDrawable().DrawRectangle(gc, true, 0, 0, -1, -1)
		gc.SetRgbFgColor(gdk.NewColor("black"))
		gc.SetRgbBgColor(gdk.NewColor("white"))
		pixmap.GetDrawable().DrawRectangle(gc, false, 0, 0, 10, 10)
	})

	drawingarea.Connect("expose-event", func() {
		println("Exposing DrawingArea!")
		if pixmap != nil {
			drawingarea.GetWindow().GetDrawable().DrawDrawable(gc, pixmap.GetDrawable(), 0, 0, 0, 0, -1, -1)
		}
	})

	vbox.Add(drawingarea)

	//--------------------------------------------------------
	// GtkScale
	//--------------------------------------------------------
	scale := gtk.NewHScaleWithRange(0, 100, 1)
	scale.Connect("value-changed", func() {
		//fmt.Println("scale:", int(scale.GetValue()))
	})
	vbox.Add(scale)

	window.Add(vbox)
	window.SetSizeRequest(600, 600)
	window.ShowAll()
	gtk.Main()
}
Beispiel #19
0
func (g *Graph) clear() {
	g.gc.SetRgbFgColor(gdk.NewColor("white"))
	g.pixmap.GetDrawable().DrawRectangle(g.gc, true, 0, 0, -1, -1)
	g.gc.SetRgbBgColor(gdk.NewColor("white"))
}
Beispiel #20
0
			z := (mw.offZ + int(bev.Y)) / zoom
			mw.regWrap.UseTool(x, z)

			mw.updateGUI()

			if !mw.regWrap.ToolSingleClick() {
				mw.continueTool = true
			}
		case 2:
			mw.panning = true
		}
	}
}

var (
	checker1 = gdk.NewColor("#222222")
	checker2 = gdk.NewColor("#444444")
)

func (mw *MapWidget) drawBg() {
	if mw.bg != nil {
		mw.bg.Unref()
	}

	mw.bg = emptyPixmap(mw.w, mw.h, 24)
	drawable := mw.bg.GetDrawable()
	gc := gdk.NewGC(drawable)

	w := int(math.Ceil(float64(mw.w) / 32))
	h := int(math.Ceil(float64(mw.h) / 32))