Ejemplo n.º 1
0
Archivo: dmxd.go Proyecto: uvgroovy/dmx
func CreateGuiController() *GuiController {
	guiController := &GuiController{}
	guiController.buttons = make([]*gtk.Button, 0)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetPosition(gtk.WIN_POS_CENTER)
	window.SetTitle("GTK Go!")
	window.SetIconName("gtk-dialog-info")
	window.Connect("destroy", func(ctx *glib.CallbackContext) {
		fmt.Println("got destroy!", ctx.Data().(string))
		gtk.MainQuit()
	}, "foo")

	buttonsBox := gtk.NewHBox(false, 1)

	black := gdk.NewColorRGB(0, 0, 0)

	for i := 0; i < 8; i++ {
		button := gtk.NewButtonWithLabel(fmt.Sprint(i))

		button.ModifyBG(gtk.STATE_NORMAL, black)
		guiController.buttons = append(guiController.buttons, button)
		buttonsBox.Add(button)
	}

	window.Add(buttonsBox)
	window.SetSizeRequest(600, 600)
	window.ShowAll()

	return guiController
}
Ejemplo n.º 2
0
Archivo: dmxd.go Proyecto: uvgroovy/dmx
func (g *GuiController) Write(dmxUniverse *dmx.DMXUniverse) error {
	gdk.ThreadsEnter()
	for i := 0; i < 3*8; i += 3 {

		c := gdk.NewColorRGB(dmxUniverse.Channels[i], dmxUniverse.Channels[i+1], dmxUniverse.Channels[i+2])

		g.buttons[i/3].ModifyBG(gtk.STATE_NORMAL, c)
	}

	gdk.ThreadsLeave()

	return nil
}
Ejemplo n.º 3
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()
}
Ejemplo n.º 4
0
func main() {

	gtk.Init(nil)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle("test002 - clicker game stuff thingy")
	window.Connect("destroy", gtk.MainQuit)
	window.SetSizeRequest(800, 600)

	layout := gtk.NewLayout(nil, nil)
	layout.ModifyBG(gtk.STATE_NORMAL, gdk.NewColorRGB(200, 200, 200))

	menubar := createMenu()

	spielstand := spielstand{money: 10, spielfeld: [5][5]*haus{}, amountUpgrades: 0}

	label := gtk.NewLabel("")
	labelUpdate(label, &spielstand)

	for i := 0; i < len(spielstand.spielfeld); i++ {
		for j := 0; j < len(spielstand.spielfeld[0]); j++ {
			spielHaus := haus{state: -1}
			spielstand.spielfeld[i][j] = &spielHaus

			bild := gtk.NewImage()
			if i == 2 && j == 3 {
				spielHaus.state = 0
			}
			setImage(bild, spielHaus.state)

			// lambda für die weiterschaltung
			// Erhöhe den state nur wenn es kein upgrade gibt oder wenn wenn wir genug geld haben.
			// Und nur bei letzterem kaufe das upgrade.
			weiter := func(ctx *glib.CallbackContext) {
				if spielHaus.state == -1 && spielstand.amountUpgrades != 0 && spielstand.money >= spielstand.amountUpgrades*10 {
					spielHaus.state = 0
					setImage(bild, 0)
					spielstand.money -= spielstand.amountUpgrades * 10
				} else {
					if spielHaus.state < 6*5 && spielHaus.state != -1 {
						if (spielHaus.state+1)%5 != 0 {
							spielHaus.state += 1
						} else {
							if spielstand.money > 9 {
								spielHaus.state += 1
								setImage(bild, spielHaus.state/5)
								spielstand.money -= 10
								spielstand.amountUpgrades++
							}
						}
					}
				}

				labelUpdate(label, &spielstand)
			}

			// Ein bild kann ohne weiteres keine events, daher braucht man eine
			// EventBox drum rum um events zu haben
			eventBox := gtk.NewEventBox()
			eventBox.Add(bild)
			// das event kann nicht direkt auf das image gesetzt werden, deswegen
			// diese event box dafür.
			eventBox.Connect("button-press-event", weiter)
			eventBox.SetEvents(int(gdk.BUTTON_PRESS_MASK))
			layout.Put(eventBox, 100+i*100, 100+j*100)
		}
	}

	// start update routine
	go update(&spielstand, label)

	layout.Put(label, 300, 70)
	layout.Put(menubar, 0, 0)

	window.Add(layout)
	window.ShowAll()
	gtk.Main()
}