예제 #1
0
파일: state.go 프로젝트: egonelbre/spector
func (state *State) Render(window *glfw.Window) {
	if !state.Dirty {
		return
	}
	state.Dirty = false

	state.Reset(window)
	state.Time = time.Now()
	state.UpdateInput(window)

	hue := float32(state.Time.UnixNano()/1e6%360) / 360.0
	Highlight = ui.ColorHSLA(hue, 0.7, 0.7, 1.0)

	w, h := window.GetSize()
	root := &ui.Context{
		Backend: state.Backend,
		Input:   state.Input,
		Area:    ui.Block(0, 0, float32(w), float32(h)),
	}

	if root.Input.Mouse.Drag != nil {
		if !root.Input.Mouse.Drag(root) {
			root.Input.Mouse.Drag = nil
		}
	}

	state.Backend.SetBack(ui.ColorHex(0xEEEEEEFF))
	state.Backend.SetFore(ui.ColorHex(0xCCCCCCFF))
	state.Backend.SetFontColor(ui.ColorHex(0x000000FF))

	view := NewView(state, root, &state.Timeline)
	view.Render()
}
예제 #2
0
파일: state.go 프로젝트: egonelbre/spector
func (view *View) H(font *Font, format string, args ...interface{}) {
	view.Context.Backend.SetBack(ui.ColorHex(font.Background))
	view.Context.Backend.SetFontColor(ui.ColorHex(font.Foreground))
	bounds := ui.Block(0, view.Y, view.Size.X, font.Height)
	view.Context.Backend.Fill(bounds)
	text := fmt.Sprintf(format, args...)
	view.Context.Backend.Text(text, bounds)

	view.Y += font.Height
}
예제 #3
0
파일: ui.go 프로젝트: egonelbre/spector
func (state *State) Render(window *glfw.Window) {
	state.Reset(window)
	state.UpdateInput(window)

	w, h := window.GetSize()
	root := &ui.Context{
		Backend: state.Backend,
		Input:   state.Input,
		Area:    ui.Block(0, 0, float32(w), float32(h)),
	}

	if root.Input.Mouse.Drag != nil {
		if !root.Input.Mouse.Drag(root) {
			root.Input.Mouse.Drag = nil
		}
	}

	state.Backend.SetBack(ui.ColorHex(0xEEEEEEFF))
	state.Backend.SetFore(ui.ColorHex(0xCCCCCCFF))
	state.Backend.SetFontColor(ui.ColorHex(0x000000FF))

	mm := &MainMenu{}
	ui.Buttons{
		{"☺", mm.File},
		{"Load", mm.Load},
		{"Save", mm.Save},
		{"Quit", mm.Quit},
	}.DoDynamic(ui.LayoutToRight(50, root.Top(20).Panel()))

	boxbounds := ui.Bounds{
		state.Box,
		state.Box.Offset(ui.Point{30, 30})}

	runtime.ReadMemStats(&state.MemStats)
	root.Right(state.SidePanelSize).Reflect("Mem", &state.MemStats)

	ui.SplitterX(root.Right(5), func(delta float32) {
		state.SidePanelSize -= delta
	})

	box := root.Child(boxbounds)
	box.Backend.SetBack(ui.ColorHex(0xFF88EEFF))
	box.Backend.SetFore(ui.ColorHex(0xFF88EEFF))
	box.Backend.Fill(box.Area)
	box.Backend.Stroke(box.Area)

	ui.DoDragXY(box, func(dx, dy float32) {
		state.Box.X += dx
		state.Box.Y += dy
	})
}
예제 #4
0
파일: main.go 프로젝트: egonelbre/spector
func main() {
	flag.Parse()

	go func() {
		http.ListenAndServe("localhost:6060", nil)
	}()

	if err := glfw.Init(); err != nil {
		log.Fatalln("failed to initialize glfw:", err)
	}
	defer glfw.Terminate()

	glfw.WindowHint(glfw.Resizable, glfw.True)
	glfw.WindowHint(glfw.Visible, glfw.False) // do not steal focus

	glfw.WindowHint(glfw.ContextVersionMajor, 2)
	glfw.WindowHint(glfw.ContextVersionMinor, 1)

	window, err := glfw.CreateWindow(800, 600, "Spector", nil, nil)
	if err != nil {
		panic(err)
	}
	window.MakeContextCurrent()
	window.Restore()
	window.SetPos(32, 64)

	if err := gl.Init(); err != nil {
		panic(err)
	}

	state := NewState()
	for !window.ShouldClose() {
		if window.GetKey(glfw.KeyEscape) == glfw.Press {
			return
		}
		if window.GetKey(glfw.KeyR) == glfw.Press {
			state.Stop()
			state = NewState()
		}

		start := time.Now()
		state.Update(1.0 / 60.0)
		updateTime := time.Since(start)

		start = time.Now()
		state.Render(window)
		renderTime := time.Since(start)

		text := fmt.Sprintf("update: %.2fms render: %.2fms",
			float32(updateTime)/float32(time.Millisecond),
			float32(renderTime)/float32(time.Millisecond))
		w, h := window.GetSize()
		state.Backend.SetFontColor(ui.ColorHex(0xFF0000FF))
		size := state.Backend.Measure(text)
		state.Backend.Text(text, ui.Block(float32(w)-size.X, float32(h)-size.Y, size.X, size.Y))

		window.SwapBuffers()
		glfw.PollEvents()
	}
}