コード例 #1
0
ファイル: graph.go プロジェクト: ntwyman/go-dsp
func NewGraph() *Graph {
	graph := &Graph{*gtk.NewDrawingArea(), nil, nil, -20.0, 20.0, -2.0, 2.0, 1, 10.0, 0.1, 1.0, nil, nil}
	graph.Connect("expose_event", func() {
		if graph.pixmap != nil {
			graph.GetWindow().GetDrawable().DrawDrawable(graph.gc, graph.pixmap.GetDrawable(), 0, 0, 0, 0, -1, -1)
		}
	})

	graph.Connect("configure_event", func(ctx *glib.CallbackContext) {
		if graph.pixmap != nil {
			graph.pixmap.Unref()
		}
		allocation := graph.GetAllocation()
		graph.pixmap = gdk.NewPixmap(graph.GetWindow().GetDrawable(),
			allocation.Width,
			allocation.Height,
			-1)
		graph.gc = gdk.NewGC(graph.pixmap.GetDrawable())
		graph.setScale()
		graph.plot()
	})

	graph.SetEvents(int(gdk.EXPOSE | gdk.CONFIGURE))
	return graph
}
コード例 #2
0
ファイル: display.go プロジェクト: Khady/gomoku
func configure_board(vbox *gtk.VBox) {
	drawingarea = gtk.NewDrawingArea()
	drawingarea.Connect("configure-event", func() {
		if pixmap != nil {
			pixmap.Unref()
		}
		var allocation gtk.Allocation
		drawingarea.GetAllocation(&allocation)
		pixmap = gdk.NewPixmap(drawingarea.GetWindow().GetDrawable(), allocation.Width, allocation.Height, 24)
		gc = gdk.NewGC(pixmap.GetDrawable())
		display_init_grid(gc, pixmap)
	})

	drawingarea.Connect("button-press-event", func(ctx *glib.CallbackContext) {
		// Check if the game is running and if player click in the goban
		if stopGame == true || stopClick == true {
			return
		}
		if gdkwin == nil {
			gdkwin = drawingarea.GetWindow()
		}
		arg := ctx.Args(0)
		mev := *(**gdk.EventMotion)(unsafe.Pointer(&arg))
		var mt gdk.ModifierType
		var x, y int
		if mev.IsHint != 0 {
			gdkwin.GetPointer(&x, &y, &mt)
		} else {
			x, y = int(mev.X), int(mev.Y)
		}
		x = ((x - INTER/2) / INTER)
		y = ((y - INTER/2) / INTER)
		if x < 0 || x >= 19 || y < 0 || y >= 19 {
			return
		}
		// end check
		good, vic := event_play(x, y)
		if good && iamode && stopGame == false && stopClick == false && vic == 0 {
			calc_ai()
		}
		if good && !iamode && stopGame == false && stopClick == false && hint {
			calcHint <- true
		}
	})

	drawingarea.Connect("expose-event", func() {
		if pixmap != nil {
			drawingarea.GetWindow().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)
}
コード例 #3
0
ファイル: colorbox.go プロジェクト: kch42/biomed
func colorBox(c *gdk.Color) *gtk.DrawingArea {
	dArea := gtk.NewDrawingArea()
	var pixmap *gdk.Pixmap
	var gc *gdk.GC

	dArea.Connect("configure-event", func() {
		if pixmap != nil {
			pixmap.Unref()
		}
		alloc := dArea.GetAllocation()
		pixmap = gdk.NewPixmap(dArea.GetWindow().GetDrawable(), alloc.Width, alloc.Height, 24)
		gc = gdk.NewGC(pixmap.GetDrawable())
		gc.SetRgbFgColor(c)
		pixmap.GetDrawable().DrawRectangle(gc, true, 0, 0, -1, -1)
	})

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

	return dArea
}
コード例 #4
0
ファイル: mapwidget.go プロジェクト: kch42/biomed
func NewMapWidget(guicbs GUICallbacks, bioLookup BiomeLookup) *MapWidget {
	dArea := gtk.NewDrawingArea()

	mw := &MapWidget{
		dArea:      dArea,
		guicbs:     guicbs,
		showBiomes: true,
		mx1:        -1,
		my1:        -1,
		bioLookup:  bioLookup,
	}

	mw.regWrap = NewRegionWrapper(mw.updateGUI, guicbs)
	mw.regWrap.bioLookup = bioLookup

	dArea.Connect("configure-event", mw.configure)
	dArea.Connect("expose-event", mw.expose)
	dArea.Connect("motion-notify-event", mw.movement)
	dArea.Connect("button-press-event", mw.buttonChanged)
	dArea.Connect("button-release-event", mw.buttonChanged)
	dArea.SetEvents(int(gdk.POINTER_MOTION_MASK | gdk.POINTER_MOTION_HINT_MASK | gdk.BUTTON_PRESS_MASK | gdk.BUTTON_RELEASE_MASK))

	return mw
}
コード例 #5
0
ファイル: gui.go プロジェクト: fffilimonov/BW_CCC
func guiMain(confglobal string, conflocal string) {
	var CallID string
	ch := make(chan string, 100)
	Config := ReadConfig(confglobal)
	Configlocal := ReadConfiglocal(conflocal)
	owner := Configlocal.Main.Owner

	//prepare config for XSI
	var xsiConfig xsi.ConfigT
	xsiConfig.Main.User = Configlocal.Main.Owner
	xsiConfig.Main.Password = Configlocal.Main.Password
	xsiConfig.Main.Host = Config.Main.Host
	xsiConfig.Main.HTTPHost = Config.Main.HTTPHost
	xsiConfig.Main.HTTPPort = Config.Main.HTTPPort
	def := xsi.MakeDef(xsiConfig)

	//start main client
	go clientMain(ch, Config)

	//prepare config for OCI
	var ociConfig ocip.ConfigT
	ociConfig.Main.User = Configlocal.Main.Owner
	ociConfig.Main.Password = Configlocal.Main.Password
	ociConfig.Main.Host = Config.Main.Host
	ociConfig.Main.OCIPPort = Config.Main.OCIPPort
	//set unavailable at start app
	ocip.OCIPsend(ociConfig, "UserCallCenterModifyRequest19", ConcatStr("", "userId=", owner), "agentACDState=Unavailable")
	//prepare timer
	timer := time.NewTimer(time.Second)
	timer.Stop()

	//init gthreads
	glib.ThreadInit(nil)
	gdk.ThreadsInit()
	gdk.ThreadsEnter()
	gtk.Init(nil)

	//names
	names := make(map[string]string)
	for iter, target := range Config.Main.TargetID {
		names[target] = Config.Main.Name[iter]
	}

	//icons to pixbuf map
	pix := make(map[string]*gdkpixbuf.Pixbuf)
	im_call := gtk.NewImageFromFile("ico/Call-Ringing-48.ico")
	pix["call"] = im_call.GetPixbuf()
	im_blank := gtk.NewImageFromFile("ico/Empty-48.ico")
	pix["blank"] = im_blank.GetPixbuf()
	im_green := gtk.NewImageFromFile("ico/Green-ball-48.ico")
	pix["green"] = im_green.GetPixbuf()
	im_grey := gtk.NewImageFromFile("ico/Grey-ball-48.ico")
	pix["grey"] = im_grey.GetPixbuf()
	im_yellow := gtk.NewImageFromFile("ico/Yellow-ball-48.ico")
	pix["yellow"] = im_yellow.GetPixbuf()

	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle("Call Center")
	window.SetIcon(pix["call"])
	window.SetPosition(gtk.WIN_POS_CENTER)
	window.SetSizeRequest(350, 500)
	window.SetDecorated(false)
	window.SetResizable(true)
	window.Connect("destroy", gtk.MainQuit)

	swin := gtk.NewScrolledWindow(nil, nil)
	swin.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
	swin.SetShadowType(gtk.SHADOW_IN)

	//owner
	owner1 := gtk.NewLabel(names[owner])
	owner2 := gtk.NewLabel("")
	owner3 := gtk.NewImage()

	//qstatus
	qlabel1 := gtk.NewLabel("В очереди:")
	qlabel2 := gtk.NewLabel("")

	//buttons
	b_av := gtk.NewButtonWithLabel("Доступен")
	b_av.SetCanFocus(false)
	b_av.Connect("clicked", func() {
		ocip.OCIPsend(ociConfig, "UserCallCenterModifyRequest19", ConcatStr("", "userId=", owner), "agentACDState=Available")
	})
	b_un := gtk.NewButtonWithLabel("Недоступен")
	b_un.SetCanFocus(false)
	b_un.Connect("clicked", func() {
		ocip.OCIPsend(ociConfig, "UserCallCenterModifyRequest19", ConcatStr("", "userId=", owner), "agentACDState=Unavailable")
	})
	b_wr := gtk.NewButtonWithLabel("Дообработка")
	b_wr.SetCanFocus(false)
	b_wr.Connect("clicked", func() {
		ocip.OCIPsend(ociConfig, "UserCallCenterModifyRequest19", ConcatStr("", "userId=", owner), "agentACDState=Wrap-Up")
	})

	//main table
	table := gtk.NewTable(3, 3, false)
	table.Attach(owner1, 0, 1, 0, 1, gtk.FILL, gtk.FILL, 1, 1)
	table.Attach(owner3, 1, 2, 0, 1, gtk.FILL, gtk.FILL, 1, 1)
	table.Attach(owner2, 2, 3, 0, 1, gtk.FILL, gtk.FILL, 1, 1)
	table.Attach(b_av, 0, 1, 1, 2, gtk.FILL, gtk.FILL, 1, 1)
	table.Attach(b_un, 1, 2, 1, 2, gtk.FILL, gtk.FILL, 1, 1)
	table.Attach(b_wr, 2, 3, 1, 2, gtk.FILL, gtk.FILL, 1, 1)
	table.Attach(qlabel1, 0, 1, 2, 3, gtk.FILL, gtk.FILL, 1, 1)
	table.Attach(qlabel2, 1, 2, 2, 3, gtk.FILL, gtk.FILL, 1, 1)

	//menu buttons
	btnclose := gtk.NewToolButtonFromStock(gtk.STOCK_STOP)
	btnclose.SetCanFocus(false)
	btnclose.OnClicked(gtk.MainQuit)

	btnhide := gtk.NewToolButtonFromStock(gtk.STOCK_REMOVE)
	btnhide.SetCanFocus(false)
	btnhide.OnClicked(window.Iconify)

	//move window
	var p2, p1 point
	var gdkwin *gdk.Window
	p1.x = -1
	p2.y = -1
	var x int = 0
	var y int = 0
	var diffx int = 0
	var diffy int = 0
	px := &x
	py := &y
	movearea := gtk.NewDrawingArea()
	movearea.Connect("motion-notify-event", func(ctx *glib.CallbackContext) {
		if gdkwin == nil {
			gdkwin = movearea.GetWindow()
		}
		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)
		}
		if (gdk.EventMask(mt) & gdk.BUTTON_PRESS_MASK) != 0 {
			if p1.x != -1 && p1.y != -1 {
				window.GetPosition(px, py)
				diffx = p2.x - p1.x
				diffy = p2.y - p1.y
				window.Move(x+diffx, y+diffy)
			}
			p1.x = p2.x - diffx
			p1.y = p2.y - diffy
		} else {
			p1.x = -1
			p2.y = -1
		}
	})
	movearea.SetEvents(int(gdk.POINTER_MOTION_MASK | gdk.POINTER_MOTION_HINT_MASK | gdk.BUTTON_PRESS_MASK))

	//resize window
	var p2r, p1r point
	var gdkwinr *gdk.Window
	p1r.x = -1
	p2r.y = -1
	var xr int = 0
	var yr int = 0
	var diffxr int = 0
	var diffyr int = 0
	pxr := &xr
	pyr := &yr

	resizearea := gtk.NewDrawingArea()
	resizearea.SetSizeRequest(10, 10)
	resizearea.Connect("motion-notify-event", func(ctx *glib.CallbackContext) {
		if gdkwinr == nil {
			gdkwinr = resizearea.GetWindow()
		}
		argr := ctx.Args(0)
		mevr := *(**gdk.EventMotion)(unsafe.Pointer(&argr))
		var mtr gdk.ModifierType
		if mevr.IsHint != 0 {
			gdkwinr.GetPointer(&p2r.x, &p2r.y, &mtr)
		}
		if (gdk.EventMask(mtr) & gdk.BUTTON_PRESS_MASK) != 0 {
			if p1r.x != -1 && p1r.y != -1 {
				diffxr = p2r.x - p1r.x
				diffyr = p2r.y - p1r.y
				window.GetSize(pxr, pyr)
				window.Resize(xr+diffxr, yr+diffyr)
			}
		}
		p1r = p2r
	})
	resizearea.SetEvents(int(gdk.POINTER_MOTION_MASK | gdk.POINTER_MOTION_HINT_MASK | gdk.BUTTON_PRESS_MASK))

	//menu
	menutable := gtk.NewTable(1, 8, true)
	menutable.Attach(movearea, 0, 6, 0, 1, gtk.FILL, gtk.FILL, 0, 0)
	menutable.Attach(btnhide, 6, 7, 0, 1, gtk.EXPAND, gtk.EXPAND, 0, 0)
	menutable.Attach(btnclose, 7, 8, 0, 1, gtk.EXPAND, gtk.EXPAND, 0, 0)

	//agents
	dlabel1 := make(map[string]*gtk.Label)
	dlabel2 := make(map[string]*gtk.Image)
	dlabel3 := make(map[string]*gtk.Image)
	b_tr := make(map[string]*gtk.Button)

	var count uint = 0
	for _, target := range Config.Main.TargetID {
		if target != owner {
			count = count + 1
			dlabel1[target] = gtk.NewLabel(names[target])
			dlabel2[target] = gtk.NewImage()
			dlabel3[target] = gtk.NewImage()
			tmp := gtk.NewButtonWithLabel("Перевод")
			tmp.SetCanFocus(false)
			tmptarget := target
			tmp.Connect("clicked", func() {
				xsi.XSITransfer(xsiConfig, def, owner, CallID, tmptarget)
			})
			b_tr[target] = tmp
		}
	}

	table_ag := gtk.NewTable(4, count+1, false)
	var place uint = 0
	for _, target := range Config.Main.TargetID {
		if target != owner {
			place = place + 1
			table_ag.Attach(dlabel1[target], 0, 1, place, place+1, gtk.FILL, gtk.FILL, 1, 1)
			table_ag.Attach(dlabel3[target], 2, 3, place, place+1, gtk.FILL, gtk.FILL, 1, 1)
			table_ag.Attach(dlabel2[target], 1, 2, place, place+1, gtk.FILL, gtk.FILL, 1, 1)
			table_ag.Attach(b_tr[target], 3, 4, place, place+1, gtk.FILL, gtk.FILL, 1, 1)
		}
	}

	//calls
	table_cl := gtk.NewTable(2, 15, false)
	dlabel4 := make(map[uint]*gtk.Label)
	dlabel5 := make(map[uint]*gtk.Label)
	var i uint
	for i = 0; i < 15; i++ {
		dlabel4[i] = gtk.NewLabel("")
		table_cl.Attach(dlabel4[i], 0, 1, i, i+1, gtk.FILL, gtk.FILL, 1, 1)
		dlabel5[i] = gtk.NewLabel("")
		table_cl.Attach(dlabel5[i], 1, 2, i, i+1, gtk.FILL, gtk.FILL, 1, 1)
	}

	//tabs
	notebook := gtk.NewNotebook()
	notebook.AppendPage(table_ag, gtk.NewLabel("Агенты"))
	notebook.AppendPage(table_cl, gtk.NewLabel("Звонки"))

	//add all to window
	vbox := gtk.NewVBox(false, 1)
	vbox.Add(menutable)
	vbox.Add(table)
	vbox.Add(notebook)
	vbox.Add(resizearea)

	swin.AddWithViewPort(vbox)
	window.Add(swin)
	window.ShowAll()

	//main func for update
	go func() {
		for {
			select {
			case data := <-ch:
				cinfo := strings.Split(strings.Trim(data, "\n"), ";")
				//owner
				if cinfo[0] == owner && cinfo[1] == "state" {
					if cinfo[4] != "" {
						CallID = cinfo[5]
						gdk.ThreadsEnter()
						owner2.SetLabel(strings.Trim(cinfo[4], "tel:"))
						gdk.ThreadsLeave()
					} else {
						CallID = ""
						gdk.ThreadsEnter()
						owner2.SetLabel("")
						gdk.ThreadsLeave()
					}
					if cinfo[3] == "Available" {
						gdk.ThreadsEnter()
						owner3.SetFromPixbuf(pix["green"])
						gdk.ThreadsLeave()
					} else if cinfo[3] == "Wrap-Up" {
						gdk.ThreadsEnter()
						owner3.SetFromPixbuf(pix["yellow"])
						gdk.ThreadsLeave()
						timer.Reset(time.Second * Config.Main.Wraptime)
					} else {
						gdk.ThreadsEnter()
						owner3.SetFromPixbuf(pix["grey"])
						gdk.ThreadsLeave()
					}
				}
				//CC q
				if cinfo[0] == Config.Main.CCID && cinfo[1] == "state" {
					if cinfo[6] != "" {
						gdk.ThreadsEnter()
						qlabel2.SetLabel(cinfo[6])
						gdk.ThreadsLeave()
					}
				}
				//CC calls
				if cinfo[0] == Config.Main.CCID && cinfo[1] == "calls" {
					if cinfo[3] != "" {
						var i, j uint
						j = 2
						for i = 0; i < 15; i++ {
							if cinfo[j] != "" {
								date, _ := strconv.Atoi(cinfo[j])
								date = date / 1000
								j++
								Addr := strings.Trim(cinfo[j], "tel:")
								j++
								Time := time.Unix(int64(date), 0)
								gdk.ThreadsEnter()
								tmp4 := dlabel4[i]
								tmp4.SetLabel(Time.Format(time.Stamp))
								tmp5 := dlabel5[i]
								tmp5.SetLabel(Addr)
								dlabel4[i] = tmp4
								dlabel5[i] = tmp5
								gdk.ThreadsLeave()
							}
						}
					}
				}
				//Targets
				if cinfo[0] != owner && cinfo[0] != Config.Main.CCID && cinfo[1] == "state" {
					if cinfo[2] == "On-Hook" {
						gdk.ThreadsEnter()
						tmp := dlabel3[cinfo[0]]
						tmp.SetFromPixbuf(pix["blank"])
						dlabel3[cinfo[0]] = tmp
						gdk.ThreadsLeave()
					}
					if cinfo[2] == "Off-Hook" {
						gdk.ThreadsEnter()
						tmp := dlabel3[cinfo[0]]
						tmp.SetFromPixbuf(pix["call"])
						dlabel3[cinfo[0]] = tmp
						gdk.ThreadsLeave()
					}
					if cinfo[3] == "Available" {
						gdk.ThreadsEnter()
						tmp := dlabel2[cinfo[0]]
						tmp.SetFromPixbuf(pix["green"])
						dlabel2[cinfo[0]] = tmp
						gdk.ThreadsLeave()
					} else if cinfo[3] == "Wrap-Up" {
						gdk.ThreadsEnter()
						tmp := dlabel2[cinfo[0]]
						tmp.SetFromPixbuf(pix["yellow"])
						dlabel2[cinfo[0]] = tmp
						gdk.ThreadsLeave()
					} else {
						gdk.ThreadsEnter()
						tmp := dlabel2[cinfo[0]]
						tmp.SetFromPixbuf(pix["grey"])
						dlabel2[cinfo[0]] = tmp
						gdk.ThreadsLeave()
					}
				}
				//timer for wrap-up
			case <-timer.C:
				ocip.OCIPsend(ociConfig, "UserCallCenterModifyRequest19", ConcatStr("", "userId=", owner), "agentACDState=Available")
			}
		}
	}()
	gtk.Main()
}
コード例 #6
0
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()
}
コード例 #7
0
ファイル: drawable.go プロジェクト: mattn/go-gtk
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()
}
コード例 #8
0
ファイル: app.go プロジェクト: tkajder/gtk-gravitysimulation
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()
}
コード例 #9
0
ファイル: test001.go プロジェクト: paua-app/curly-octo-moo
func main() {
	//--------------------------------------------------------
	//
	// GTK initialization + Window creation
	//
	//--------------------------------------------------------
	// Initialisiert gtk für den gebraucht und erzeugt das Fenster.
	//--------------------------------------------------------
	// gtk muss einmal initialisiert werden
	gtk.Init(nil)

	// Neues Fenster erstellen, rest ist trivial
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetPosition(gtk.WIN_POS_CENTER)
	window.SetSizeRequest(600, 600)
	window.SetTitle("GTK Go!")
	// man kann icons aus /usr/share/icons/<Dein-aktuelles-theme>/... angeben
	window.SetIconName("user-images")
	// das schlißene-event
	window.Connect("destroy", gtk.MainQuit)

	//--------------------------------------------------------
	//
	// Gtk VBox
	//
	//--------------------------------------------------------
	// Ein vertikales design. Hier ists relativ egal welches man nimmt.
	//--------------------------------------------------------

	vbox := gtk.NewVBox(true, 1)
	// funktioniert genauso gut:
	//	vbox := gtk.NewHBox(true, 1)

	// kleinen Rand drum rum
	// wenn man außerhalb des weißen Bereiches (also der drawingarea) klickt sieht man,
	// dass auch das Click-Event nicht ausgeführt wird. Dazu unten mehr
	vbox.SetBorderWidth(13)

	//--------------------------------------------------------
	//
	// Drawing Area + Events
	//
	//--------------------------------------------------------
	// Eine art Panel auf dem man zeichnen kann.
	// Erzeugt alle Event mittels lambdas (aka anonyme Funktionen aka anonymous functions)
	// Alle Events werden aus der Hauptschleife aufgerufen (s.u.)
	//--------------------------------------------------------
	drawingarea := gtk.NewDrawingArea()
	// trivial :D
	createEvents(drawingarea)

	//--------------------------------------------------------
	//
	// Final stuff
	//
	//--------------------------------------------------------
	// Fügt alles dem Fenster hinzu und zeigt es an.
	//--------------------------------------------------------

	// die drawingarea dem vbox hinzufügen
	vbox.Add(drawingarea)

	window.Add(vbox)
	window.ShowAll()
	// geht in die gtk Hauptschleife für alle Events etc.
	gtk.Main()
}