示例#1
0
文件: main.go 项目: walesey/go-engine
func createWindow(controllerManager *glfwController.ControllerManager) (window *ui.Window, content *ui.Container) {
	// Create window with size
	window = ui.NewWindow()
	window.SetScale(mgl32.Vec2{300, 0}.Vec3(0))

	// create a click and drag tab
	tab := ui.NewContainer()
	tab.SetBackgroundColor(70, 70, 170, 255)
	tab.SetHeight(40)

	// create a content container
	content = ui.NewContainer()
	content.SetBackgroundColor(200, 200, 200, 255)
	content.SetPadding(ui.NewMargin(10))

	// Add all the containers to the window
	mainContainer := ui.NewContainer()
	mainContainer.AddChildren(tab, content)
	window.SetElement(mainContainer)

	// create uiController
	uiController := ui.NewUiController(window)
	controllerManager.AddController(uiController.(glfwController.Controller))
	ui.ClickAndDragWindow(window, tab.Hitbox, uiController)

	return
}
示例#2
0
func (engine *EngineImpl) InitFpsDial() {
	window := ui.NewWindow()
	window.SetTranslation(mgl32.Vec3{10, 10, 1})
	window.SetScale(mgl32.Vec3{400, 0, 1})
	window.SetBackgroundColor(0, 0, 0, 0)

	container := ui.NewContainer()
	container.SetBackgroundColor(0, 0, 0, 0)
	window.SetElement(container)

	text := ui.NewTextElement("0", color.RGBA{255, 0, 0, 255}, 18, nil)
	container.AddChildren(text)
	engine.AddUpdatable(UpdatableFunc(func(dt float64) {
		fps := engine.FPS()
		text.SetText(fmt.Sprintf("%v", int(fps)))
		switch {
		case fps < 20:
			text.SetTextColor(color.RGBA{255, 0, 0, 255})
		case fps < 30:
			text.SetTextColor(color.RGBA{255, 90, 0, 255})
		case fps < 50:
			text.SetTextColor(color.RGBA{255, 255, 0, 255})
		default:
			text.SetTextColor(color.RGBA{0, 255, 0, 255})
		}
		text.ReRender()
	}))

	window.Render()
	engine.AddOrtho(window)
}
示例#3
0
文件: ui.go 项目: walesey/go-engine
func (e *Editor) defaultWindow() (window *ui.Window, container *ui.Container, tab *ui.Container) {
	window = ui.NewWindow()

	tab = ui.NewContainer()
	tab.SetBackgroundColor(70, 70, 70, 255)
	tab.SetHeight(40)

	mainContainer := ui.NewContainer()
	window.SetElement(mainContainer)
	container = ui.NewContainer()
	container.SetBackgroundColor(200, 200, 200, 255)
	mainContainer.AddChildren(tab, container)
	ui.ClickAndDragWindow(window, tab.Hitbox, e.customController)

	return
}
示例#4
0
文件: main.go 项目: walesey/go-engine
func populateContent(content *ui.Container) []ui.Activatable {
	// example text title
	textElement := ui.NewTextElement("UI EXAMPLE!", color.Black, 16, nil)

	// example image element
	img, _ := assets.ImportImageCached("resources/cubemap.png")
	imageElement := ui.NewImageElement(img)
	imageElement.SetWidth(200)

	// example text field
	tf := ui.NewTextField("", color.Black, 16, nil)
	tf.SetPlaceholder("this is a placeholder")
	tf.SetBackgroundColor(255, 255, 255, 255)
	tf.SetMargin(ui.Margin{10, 0, 10, 0})

	// example hidden text field
	passwordTf := ui.NewTextField("", color.Black, 16, nil)
	passwordTf.SetHidden(true)
	passwordTf.SetBackgroundColor(255, 255, 255, 255)
	passwordTf.SetMargin(ui.Margin{0, 0, 10, 0})

	// example button
	button := ui.NewContainer()
	button.SetBackgroundColor(160, 0, 0, 254)
	button.SetPadding(ui.NewMargin(20))

	// button on click event
	button.Hitbox.AddOnClick(func(button int, release bool, position mgl32.Vec2) {
		if release {
			textElement.SetText("release").SetTextColor(color.NRGBA{254, 0, 0, 254}).ReRender()
		} else {
			textElement.SetText("click").SetTextColor(color.NRGBA{0, 254, 0, 254}).ReRender()
		}
	})

	// button on hover event
	button.Hitbox.AddOnHover(func() {
		button.SetBackgroundColor(210, 100, 100, 254)
	})
	button.Hitbox.AddOnUnHover(func() {
		button.SetBackgroundColor(160, 0, 0, 254)
	})

	// add everything to the content container
	content.AddChildren(textElement, imageElement, tf, passwordTf, button)

	// return everything that should be included in the Tabs order
	return []ui.Activatable{tf, passwordTf}
}
示例#5
0
func (e *Editor) openProgressBar() {
	if e.progressBar == nil {
		window := ui.NewWindow()
		window.SetTranslation(mgl32.Vec3{500, 0, 0})
		window.SetScale(mgl32.Vec3{330, 0, 1})

		container := ui.NewContainer()
		container.SetBackgroundColor(200, 200, 200, 255)
		window.SetElement(container)

		e.controllerManager.AddController(ui.NewUiController(window).(glfwController.Controller))
		ui.LoadHTML(container, strings.NewReader(progressBarHtml), strings.NewReader(globalCss), e.uiAssets)
		window.Render()

		e.progressBar = window
	}
	e.gameEngine.AddOrtho(e.progressBar)
}
示例#6
0
func (o *Overview) updateTree(mapModel *editorModels.MapModel) {
	var updateNode func(model *editorModels.NodeModel, container *ui.Container)
	updateNode = func(model *editorModels.NodeModel, container *ui.Container) {

		//TODO: add native html support for selecting deselecting from a list
		onclickName := fmt.Sprintf("onClickMapNode_%v", model.Id)
		o.assets.AddCallback(onclickName, func(element ui.Element, args ...interface{}) {
			if len(args) >= 2 && !args[1].(bool) { // not on release
				if o.selectedNodeId == model.Id {
					o.openNodes[model.Id] = !o.openNodes[model.Id]
				}
				o.selectedNodeId = model.Id
				o.updateTree(mapModel)
			}
		})

		isOpen := o.openNodes[model.Id]

		iconImg := "planetClosed"
		if isOpen {
			iconImg = "planetOpen"
		}
		if model.Reference != nil {
			iconImg = "reference"
		}

		html := fmt.Sprintf("<div onclick=%v><img src=%v></img><p>%v", onclickName, iconImg, model.Id)
		for _, class := range model.Classes {
			html = fmt.Sprintf("%v :: %v", html, class)
		}
		html = fmt.Sprintf("%v</p></div>", html)
		css := `
		p { font-size: 12px; width: 80%; padding: 0 0 0 5px; }
		img { width: 16px; height: 16px; }
		div { margin: 0 0 5px 0; }
		`
		if model.Id == o.selectedNodeId {
			css = fmt.Sprintf("%v div { background-color: #ff5 }", css)
		}
		if !isOpen {
			css = fmt.Sprintf("%v p { color: #999 }", css)
		}
		ui.LoadHTML(container, strings.NewReader(html), strings.NewReader(css), o.assets)

		if isOpen {
			for _, childModel := range model.Children {
				nodeContainer := ui.NewContainer()
				container.AddChildren(nodeContainer)
				nodeContainer.SetPadding(ui.Margin{0, 0, 0, 20})
				updateNode(childModel, nodeContainer)
			}
		}
	}

	container, ok := o.window.ElementById("overviewTree").(*ui.Container)
	if ok {
		container.RemoveAllChildren()
		updateNode(mapModel.Root, container)
		o.window.Render()
	}
}