コード例 #1
0
ファイル: web.go プロジェクト: shibukawa/nanogui-go
func (a *Application) init() {
	glfw.WindowHint(glfw.Samples, 4)
	a.screen = nanogui.NewScreen(1024, 768, "NanoGUI.Go Test", true, false)

	demo.ButtonDemo(a.screen)
	images := loadImageDirectory(a.screen.NVGContext(), "icons")
	imageButton, imagePanel, progressBar := demo.BasicWidgetsDemo(a.screen, images)
	a.progress = progressBar
	demo.SelectedImageDemo(a.screen, imageButton, imagePanel)
	demo.MiscWidgetsDemo(a.screen)
	demo.GridDemo(a.screen)

	a.screen.SetDrawContentsCallback(func() {
		a.progress.SetValue(float32(math.Mod(float64(nanogui.GetTime())/10, 1.0)))
	})

	a.screen.DebugPrint()

	a.screen.PerformLayout()

	/* All NanoGUI widgets are initialized at this point. Now
	create an OpenGL shader to draw the main window contents.

	NanoGUI comes with a simple Eigen-based wrapper around OpenGL 3,
	which eliminates most of the tedious and error-prone shader and
	buffer object management.
	*/
}
コード例 #2
0
ファイル: screen.go プロジェクト: shibukawa/nanogui-go
func NewScreen(width, height int, caption string, resizable, fullScreen bool) *Screen {
	screen := &Screen{
		//cursor:  glfw.CursorNormal,
		caption: caption,
	}

	if runtime.GOARCH == "js" {
		glfw.WindowHint(glfw.Hint(0x00021101), 1) // enable stencil for nanovgo
	}
	glfw.WindowHint(glfw.Samples, 4)
	//glfw.WindowHint(glfw.RedBits, 8)
	//glfw.WindowHint(glfw.GreenBits, 8)
	//glfw.WindowHint(glfw.BlueBits, 8)
	glfw.WindowHint(glfw.AlphaBits, 8)
	//glfw.WindowHint(glfw.StencilBits, 8)
	//glfw.WindowHint(glfw.DepthBits, 8)
	//glfw.WindowHint(glfw.Visible, 0)
	if resizable {
		//glfw.WindowHint(glfw.Resizable, 1)
	} else {
		//glfw.WindowHint(glfw.Resizable, 0)
	}

	var err error
	if fullScreen {
		monitor := glfw.GetPrimaryMonitor()
		mode := monitor.GetVideoMode()
		screen.window, err = glfw.CreateWindow(mode.Width, mode.Height, caption, monitor, nil)
	} else {
		screen.window, err = glfw.CreateWindow(width, height, caption, nil, nil)
	}
	if err != nil {
		panic(err)
	}
	screen.window.MakeContextCurrent()
	gl.Viewport(0, 0, screen.fbW, screen.fbH)
	gl.ClearColor(0, 0, 0, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT)
	glfw.SwapInterval(0)
	screen.window.SwapBuffers()

	/* Poll for events once before starting a potentially
	   lengthy loading process. This is needed to be
	   classified as "interactive" by other software such
	   as iTerm2 */

	if runtime.GOOS == "darwin" {
		glfw.PollEvents()
	}

	screen.window.SetCursorPosCallback(func(w *glfw.Window, xpos, ypos float64) {
		if screen, ok := nanoguiScreens[w]; ok {
			screen.cursorPositionCallbackEvent(xpos, ypos)
		}
	})

	screen.window.SetMouseButtonCallback(func(w *glfw.Window, button glfw.MouseButton, action glfw.Action, mods glfw.ModifierKey) {
		if screen, ok := nanoguiScreens[w]; ok {
			screen.mouseButtonCallbackEvent(button, action, mods)
		}
	})

	screen.window.SetKeyCallback(func(w *glfw.Window, key glfw.Key, scanCode int, action glfw.Action, mods glfw.ModifierKey) {
		if screen, ok := nanoguiScreens[w]; ok {
			screen.keyCallbackEvent(key, scanCode, action, mods)
		}
	})

	screen.window.SetCharCallback(func(w *glfw.Window, char rune) {
		if screen, ok := nanoguiScreens[w]; ok {
			screen.charCallbackEvent(char)
		}
	})

	screen.window.SetPreeditCallback(func(w *glfw.Window, text []rune, blocks []int, focusedBlock int) {
		if screen, ok := nanoguiScreens[w]; ok {
			screen.preeditCallbackEvent(text, blocks, focusedBlock)
		}
	})

	screen.window.SetIMEStatusCallback(func(w *glfw.Window) {
		if screen, ok := nanoguiScreens[w]; ok {
			screen.imeStatusCallbackEvent()
		}
	})

	screen.window.SetDropCallback(func(w *glfw.Window, names []string) {
		if screen, ok := nanoguiScreens[w]; ok {
			screen.dropCallbackEvent(names)
		}
	})

	screen.window.SetScrollCallback(func(w *glfw.Window, xoff float64, yoff float64) {
		if screen, ok := nanoguiScreens[w]; ok {
			screen.scrollCallbackEvent(float32(xoff), float32(yoff))
		}
	})

	screen.window.SetFramebufferSizeCallback(func(w *glfw.Window, width int, height int) {
		if screen, ok := nanoguiScreens[w]; ok {
			screen.resizeCallbackEvent(width, height)
		}
	})

	screen.Initialize(screen.window, true)
	InitWidget(screen, nil)
	return screen
}