-
Notifications
You must be signed in to change notification settings - Fork 0
/
microui_render.go
44 lines (38 loc) · 990 Bytes
/
microui_render.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package microui
/*
#include "microui.h"
#include <stdlib.h>
*/
import "C"
import "unsafe"
func ensureBuf(slc *[]byte, size int32) {
for len(*slc) < int(size) {
*slc = append(*slc, make([]byte, 1024)...)
}
}
func (ctx *Context) SetBeginRender(fn func()) {
ctx.beginRender = fn
}
func (ctx *Context) SetRenderCommand(fn func(cmd *Command)) {
ctx.renderCommand = fn
}
func (ctx *Context) SetEndRender(fn func()) {
ctx.endRender = fn
}
func (ctx *Context) Render() {
var cmd *C.mu_Command
gocmd := &Command{
data: ctx.lastcmdbuf,
}
ctx.beginRender()
for C.mu_next_command(ctx.parent, &cmd) == 1 {
gocmd.ctype = CommandType(*(*int32)(unsafe.Pointer(cmd)))
gocmd.size = *(*int32)(unsafe.Pointer(uintptr(unsafe.Pointer(cmd)) + 4))
ensureBuf(&ctx.cmdbuf, gocmd.size)
copy(ctx.cmdbuf, (*[1 << 30]byte)(unsafe.Pointer(cmd))[:gocmd.size:gocmd.size])
ensureBuf(&gocmd.data, gocmd.size-8)
copy(gocmd.data, ctx.cmdbuf[8:])
ctx.renderCommand(gocmd)
}
ctx.endRender()
}