예제 #1
0
파일: main.go 프로젝트: genbattle/Go2D
func start() {
	var err error
	image, err = go2d.NewImage("test.png")
	checkError(err)

	arial16, err = go2d.NewFont("arial.ttf", 16)
	checkError(err)
	arial16.SetStyle(true, false, false)
	arial16.SetColor(255, 255, 255)
}
예제 #2
0
파일: main.go 프로젝트: genbattle/Go2D
func start() {
	//Load up our default font for GUI text elements
	arial, err := go2d.NewFont("arial.ttf", 14)
	checkError(err)
	arial.SetStyle(true, false, false)
	arial.SetColor(255, 255, 255)

	//Initialize the GUI system (use whole window area)
	g_window = g_game.InitGUI(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, arial)

	//Set up some elements
	//A panel
	panel := go2d.NewPanel(20, 20, 200, 200)
	panel.SetBackgroundColor(80, 80, 255)

	//Another panel in the panel that gets clipped
	innerPanel := go2d.NewPanel(180, 180, 50, 50)
	innerPanel.SetBackgroundColor(255, 80, 80)
	panel.AddChild(innerPanel)

	//A label
	label := go2d.NewLabel(10, 10, "This is a test label")
	panel.AddChild(label)

	//A button
	button := go2d.NewButton(10, 40, 100, 30, "Click here")
	button.SetFontColor(80, 80, 80)
	button.SetBackgroundColor(80, 255, 80)
	button.SetOnClickListener(func(x, y int) {
		fmt.Println("Button clicked!")
	})
	panel.AddChild(button)

	//A textfield
	textfield := go2d.NewTextField(10, 80, 150, 30)
	textfield.SetFontColor(0, 0, 0)
	textfield.SetBackgroundColor(255, 255, 255)
	textfield.SetBorderColor(0, 0, 0)
	panel.AddChild(textfield)

	//A password textfield
	password := go2d.NewTextField(10, 120, 150, 30)
	password.SetPassword(true)
	password.SetFontColor(0, 0, 0)
	password.SetBackgroundColor(255, 255, 255)
	password.SetBorderColor(0, 0, 0)
	panel.AddChild(password)

	g_window.AddChild(panel)

	//A customized button
	customButton := go2d.NewButton(20, 240, 186, 52, "")
	loadedImage, err := go2d.NewImage("button_normal.png")
	checkError(err)
	customButton.SetImage(loadedImage)
	loadedImage, err = go2d.NewImage("button_hover.png")
	checkError(err)
	customButton.SetHoverImage(loadedImage)
	loadedImage, err = go2d.NewImage("button_down.png")
	checkError(err)
	customButton.SetMouseDownImage(loadedImage)
	customButton.SetOnClickListener(CustomButtonOnClick)
	g_window.AddChild(customButton)

	//A scrollbar
	scrollBar := go2d.NewScrollbar(300, 20, 20, 140, go2d.SCROLLBAR_VERTICAL)
	scrollBar.SetOnValueChangeListener(func(value int) {
		fmt.Printf("Scrollbar value: %d\n", value)
	})
	g_window.AddChild(scrollBar)
}