本文整理汇总了Golang中github.com/google/gxui.Driver类的典型用法代码示例。如果您正苦于以下问题:Golang Driver类的具体用法?Golang Driver怎么用?Golang Driver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Driver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CreateFont
func CreateFont(size int, driver gxui.Driver) gxui.Font {
font, err := driver.CreateFont(gxfont.Monospace, size)
if err != nil {
panic(err)
}
return font
}
示例2: appMain
func appMain(driver gxui.Driver) {
theme := dark.CreateTheme(driver)
label := theme.CreateLabel()
label.SetText("This is a progress bar:")
progressBar := theme.CreateProgressBar()
progressBar.SetDesiredSize(math.Size{W: 400, H: 20})
progressBar.SetTarget(100)
layout := theme.CreateLinearLayout()
layout.AddChild(label)
layout.AddChild(progressBar)
layout.SetHorizontalAlignment(gxui.AlignCenter)
window := theme.CreateWindow(800, 600, "Progress bar")
window.SetScale(flags.DefaultScaleFactor)
window.AddChild(layout)
window.OnClose(driver.Terminate)
progress := 0
pause := time.Millisecond * 500
var timer *time.Timer
timer = time.AfterFunc(pause, func() {
driver.Call(func() {
progress = (progress + 3) % progressBar.Target()
progressBar.SetProgress(progress)
timer.Reset(pause)
})
})
}
示例3: appMain
func appMain(driver gxui.Driver) {
theme := dark.CreateTheme(driver)
img := theme.CreateImage()
// mx := source.Bounds().Max
// fmt.Println(mx)
window := theme.CreateWindow(500, 500, "Screenshot")
size := window.Viewport().SizePixels()
fmt.Println(size)
window.SetScale(flags.DefaultScaleFactor)
window.AddChild(img)
go func() {
for {
source, err := goss.Capture()
if err != nil {
fmt.Fprintln(os.Stderr, "Failed to capture screenshot.")
os.Exit(1)
}
rgba := image.NewRGBA(source.Bounds())
draw.Draw(rgba, source.Bounds(), source, image.ZP, draw.Src)
texture := driver.CreateTexture(rgba, 1)
img.SetTexture(texture)
}
}()
window.OnClose(driver.Terminate)
}
示例4: appMain
func appMain(driver gxui.Driver) {
theme := dark.CreateTheme(driver)
window := theme.CreateWindow(ANIMATION_WIDTH, 2*ANIMATION_HEIGHT, "Pendulum")
window.SetBackgroundBrush(gxui.CreateBrush(gxui.Gray50))
image := theme.CreateImage()
ticker := time.NewTicker(time.Millisecond * 15)
pendulum := &mathematicalPendulum{}
pendulum2 := &numericalPendulum{PHI_ZERO, 0.0, 0.0, time.Time{}}
go func() {
for _ = range ticker.C {
canvas := driver.CreateCanvas(math.Size{ANIMATION_WIDTH, 2 * ANIMATION_HEIGHT})
canvas.Clear(gxui.White)
draw(pendulum, canvas, 0, 0)
draw(pendulum2, canvas, 0, ANIMATION_HEIGHT)
canvas.Complete()
driver.Call(func() {
image.SetCanvas(canvas)
})
}
}()
window.AddChild(image)
window.OnClose(ticker.Stop)
window.OnClose(driver.Terminate)
}
示例5: drawWalkPath
//画行走路线
func drawWalkPath(window gxui.Window, theme gxui.Theme, driver gxui.Driver, x1, y1, x2, y2 int64) {
ps, isWalk := nm.FindPath(nmastar, x1, y1, x2, y2)
if !isWalk {
return
}
canvas := driver.CreateCanvas(math.Size{W: int(nmj.Width), H: int(nmj.Heigth)})
var polys []gxui.PolygonVertex
for i := 0; i < len(ps); i++ {
polys = append(polys,
gxui.PolygonVertex{
Position: math.Point{
int(ps[i].X),
int(ps[i].Y),
}})
}
canvas.DrawLines(polys, gxui.CreatePen(2, gxui.Green))
canvas.Complete()
image := theme.CreateImage()
image.SetCanvas(canvas)
window.AddChild(image)
}
示例6: appMain
func appMain(driver gxui.Driver) {
theme := dark.CreateTheme(driver)
window := theme.CreateWindow(800, 600, "Hi")
window.SetBackgroundBrush(gxui.CreateBrush(gxui.Gray50))
fontData, err := ioutil.ReadFile(sysFont("幼圆")) //this font comes from windows
if err != nil {
log.Fatalf("error reading font: %v", err)
}
font, err := driver.CreateFont(fontData, 50)
if err != nil {
panic(err)
}
label := theme.CreateLabel()
label.SetFont(font)
label.SetColor(gxui.Red50)
label.SetText("支持一下中文")
button := theme.CreateButton()
button.SetText("点我一下")
window.AddChild(label)
window.AddChild(button)
window.OnClose(driver.Terminate)
}
示例7: appMain
func appMain(driver gxui.Driver) {
file := "./img/block.bmp"
f, err := os.Open(file)
if err != nil {
fmt.Printf("Failed to open image '%s': %v\n", file, err)
os.Exit(1)
}
source, _, err := image.Decode(f)
if err != nil {
fmt.Printf("Failed to read image '%s': %v\n", file, err)
os.Exit(1)
}
theme := flags.CreateTheme(driver)
img := theme.CreateImage()
//mx := source.Bounds().Max
window := theme.CreateWindow(1000, 1000, "Tetris")
window.SetScale(flags.DefaultScaleFactor)
window.AddChild(img)
rgba := image.NewRGBA(source.Bounds())
draw.Draw(rgba, source.Bounds(), source, image.ZP, draw.Src)
texture := driver.CreateTexture(rgba, 1)
img.SetTexture(texture)
window.OnClose(driver.Terminate)
}
示例8: route
func route(driver gxui.Driver, src_id, dest_id int32, src, dest Point3) (canvas gxui.Canvas) {
defer func() {
canvas.Complete()
}()
canvas = driver.CreateCanvas(math.Size{W: 800, H: 600})
t0 := time.Now()
// Phase 1. Use Dijkstra to find shortest path on Triangles
path := dijkstra.Run(src_id)
// Phase 2. construct path indices
// Check if this path include src & dest
path_triangle := [][3]int32{triangles[dest_id]}
prev_id := dest_id
for {
cur_id, ok := path[prev_id]
if !ok {
return canvas
}
path_triangle = append([][3]int32{triangles[cur_id]}, path_triangle...)
if cur_id == src_id {
break
}
prev_id = cur_id
}
// Phase 3. use Navmesh to construct line
start, end := &Point3{X: src.X, Y: src.Y}, &Point3{X: dest.X, Y: dest.Y}
nm := NavMesh{}
trilist := TriangleList{vertices, path_triangle}
r, _ := nm.Route(trilist, start, end)
log.Println("navmesh time:", time.Now().Sub(t0))
var poly []gxui.PolygonVertex
poly = append(poly,
gxui.PolygonVertex{
Position: math.Point{
int(SCALE_FACTOR * start.X),
int(SCALE_FACTOR * start.Y),
}})
for k := range r.Line {
poly = append(poly,
gxui.PolygonVertex{
Position: math.Point{
int(SCALE_FACTOR * r.Line[k].X),
int(SCALE_FACTOR * r.Line[k].Y),
}})
}
poly = append(poly,
gxui.PolygonVertex{
Position: math.Point{
int(SCALE_FACTOR * end.X),
int(SCALE_FACTOR * end.Y),
}})
canvas.DrawLines(poly, gxui.CreatePen(2, gxui.Green))
return
}
示例9: CreateTheme
func CreateTheme(driver gxui.Driver) gxui.Theme {
defaultFont, err := driver.CreateFont(gxfont.Default, 12)
if err == nil {
defaultFont.LoadGlyphs(32, 126)
} else {
fmt.Printf("Warning: Failed to load default font - %v\n", err)
}
defaultMonospaceFont, err := driver.CreateFont(gxfont.Monospace, 12)
if err == nil {
defaultFont.LoadGlyphs(32, 126)
} else {
fmt.Printf("Warning: Failed to load default monospace font - %v\n", err)
}
scrollBarRailDefaultBg := gxui.Black
scrollBarRailDefaultBg.A = 0.7
scrollBarRailOverBg := gxui.Gray20
scrollBarRailOverBg.A = 0.7
neonBlue := gxui.ColorFromHex(0xFF5C8CFF)
focus := gxui.ColorFromHex(0xA0C4D6FF)
return &basic.Theme{
DriverInfo: driver,
DefaultFontInfo: defaultFont,
DefaultMonospaceFontInfo: defaultMonospaceFont,
WindowBackground: gxui.Black,
// fontColor brushColor penColor
BubbleOverlayStyle: basic.CreateStyle(gxui.Gray80, gxui.Gray20, gxui.Gray40, 1.0),
ButtonDefaultStyle: basic.CreateStyle(gxui.Gray80, gxui.Gray10, gxui.Gray20, 1.0),
ButtonOverStyle: basic.CreateStyle(gxui.Gray90, gxui.Gray15, gxui.Gray50, 1.0),
ButtonPressedStyle: basic.CreateStyle(gxui.Gray20, gxui.Gray70, gxui.Gray30, 1.0),
CodeSuggestionListStyle: basic.CreateStyle(gxui.Gray80, gxui.Gray20, gxui.Gray10, 1.0),
DropDownListDefaultStyle: basic.CreateStyle(gxui.Gray80, gxui.Gray10, gxui.Gray20, 1.0),
DropDownListOverStyle: basic.CreateStyle(gxui.Gray80, gxui.Gray15, gxui.Gray50, 1.0),
FocusedStyle: basic.CreateStyle(gxui.Gray80, gxui.Transparent, focus, 1.0),
HighlightStyle: basic.CreateStyle(gxui.Gray80, gxui.Transparent, neonBlue, 2.0),
LabelStyle: basic.CreateStyle(gxui.Gray80, gxui.Transparent, gxui.Transparent, 0.0),
PanelBackgroundStyle: basic.CreateStyle(gxui.Gray80, gxui.Gray10, gxui.Gray15, 1.0),
ScrollBarBarDefaultStyle: basic.CreateStyle(gxui.Gray80, gxui.Gray30, gxui.Gray40, 1.0),
ScrollBarBarOverStyle: basic.CreateStyle(gxui.Gray80, gxui.Gray50, gxui.Gray60, 1.0),
ScrollBarRailDefaultStyle: basic.CreateStyle(gxui.Gray80, scrollBarRailDefaultBg, gxui.Transparent, 1.0),
ScrollBarRailOverStyle: basic.CreateStyle(gxui.Gray80, scrollBarRailOverBg, gxui.Gray20, 1.0),
SplitterBarDefaultStyle: basic.CreateStyle(gxui.Gray80, gxui.Gray10, gxui.Gray10, 1.0),
SplitterBarOverStyle: basic.CreateStyle(gxui.Gray80, gxui.Gray10, gxui.Gray50, 1.0),
TabActiveHighlightStyle: basic.CreateStyle(gxui.Gray90, neonBlue, neonBlue, 0.0),
TabDefaultStyle: basic.CreateStyle(gxui.Gray80, gxui.Gray30, gxui.Gray40, 1.0),
TabOverStyle: basic.CreateStyle(gxui.Gray90, gxui.Gray30, gxui.Gray50, 1.0),
TabPressedStyle: basic.CreateStyle(gxui.Gray20, gxui.Gray70, gxui.Gray30, 1.0),
TextBoxDefaultStyle: basic.CreateStyle(gxui.Gray80, gxui.Gray10, gxui.Gray20, 1.0),
TextBoxOverStyle: basic.CreateStyle(gxui.Gray80, gxui.Gray10, gxui.Gray50, 1.0),
}
}
示例10: appMain
func appMain(driver gxui.Driver) {
theme = light.CreateTheme(driver)
window = theme.CreateWindow(800, 600, "Snake")
playGround = field.Create(800, 600, 20, 20)
sn = snake.Create(math.Point{X: 380, Y: 200}, math.Point{X: 380, Y: 280}, 20)
drawScene(driver)
fmt.Println(sn.Direction())
window.OnKeyUp(func(event gxui.KeyboardEvent) {
dir := sn.Direction()
key := event.Key
switch {
case key == gxui.KeyRight && dir == snake.Top:
sn.TurnRight()
case key == gxui.KeyRight && dir == snake.Bottom:
sn.TurnLeft()
case key == gxui.KeyLeft && dir == snake.Top:
sn.TurnLeft()
case key == gxui.KeyLeft && dir == snake.Bottom:
sn.TurnRight()
case key == gxui.KeyUp && dir == snake.Left:
sn.TurnRight()
case key == gxui.KeyUp && dir == snake.Right:
sn.TurnLeft()
case key == gxui.KeyDown && dir == snake.Left:
sn.TurnLeft()
case key == gxui.KeyDown && dir == snake.Right:
sn.TurnRight()
}
})
ticker := time.NewTicker(time.Millisecond * 200)
go func() {
for _ = range ticker.C {
driver.Call(func() {
(&sn).Move()
drawScene(driver)
})
}
}()
window.OnClose(func() {
driver.Terminate()
ticker.Stop()
})
}
示例11: drawScene
func drawScene(driver gxui.Driver) {
window.RemoveAll()
canvas = driver.CreateCanvas(math.Size{W: 800, H: 600})
sn.Draw(canvas)
playGround.Draw(canvas)
canvas.Complete()
image := theme.CreateImage()
image.SetCanvas(canvas)
window.AddChild(image)
}
示例12: appMain
func appMain(driver gxui.Driver) {
theme := flags.CreateTheme(driver)
width := int(nmj.Width)
height := int(nmj.Heigth)
window := theme.CreateWindow(width, height, "navmesh")
canvas := driver.CreateCanvas(math.Size{W: width, H: height})
ps := nmj.Points
// mouse
isStart := true
x1, y1, x2, y2 := int64(0), int64(0), int64(0), int64(0)
window.OnMouseDown(func(me gxui.MouseEvent) {
if nm.IsWalkOfPoint(navmesh.Point{X: int64(me.Point.X), Y: int64(me.Point.Y)}) {
if isStart {
x1 = int64(me.Point.X)
y1 = int64(me.Point.Y)
} else {
x2 = int64(me.Point.X)
y2 = int64(me.Point.Y)
}
if !isStart {
drawWalkPath(window, theme, driver, x1, y1, x2, y2)
}
isStart = !isStart
}
})
// draw mesh
for i := 0; i < len(ps); i++ {
polys := make([]gxui.PolygonVertex, 0, len(ps[i]))
for j := 0; j < len(ps[i]); j++ {
polys = append(polys, gxui.PolygonVertex{
Position: math.Point{
int(ps[i][j].X),
int(ps[i][j].Y),
}})
}
// canvas.DrawPolygon(polys, gxui.CreatePen(2, gxui.Gray80), gxui.CreateBrush(gxui.Gray40))
canvas.DrawPolygon(polys, gxui.CreatePen(2, gxui.Red), gxui.CreateBrush(gxui.Yellow))
}
canvas.Complete()
image := theme.CreateImage()
image.SetCanvas(canvas)
window.AddChild(image)
window.OnClose(driver.Terminate)
}
示例13: appMain
func appMain(driver gxui.Driver) {
theme := flags.CreateTheme(driver)
// ┌───────┐║┌───────┐
// │ │║│ │
// │ A │║│ B │
// │ │║│ │
// └───────┘║└───────┘
// ═══════════════════
// ┌───────┐║┌───────┐
// │ │║│ │
// │ C │║│ D │
// │ │║│ │
// └───────┘║└───────┘
ftData, err := ioutil.ReadFile("static/font/simhei.ttf")
if err != nil {
log.Println(err)
}
ft, err := driver.CreateFont(ftData, 20)
if err != nil {
log.Println(err)
}
menu := theme.CreateLinearLayout()
menu.SetDirection(gxui.LeftToRight)
logo_label := theme.CreateLabel()
logo_label.SetColor(gxui.White)
logo_label.SetFont(ft)
logo_label.SetText("百度盘")
logo_label.SetSize(math.Size{300, 200})
menu.AddChild(logo_label)
splitterCD := theme.CreateSplitterLayout()
splitterCD.SetOrientation(gxui.Horizontal)
splitterCD.AddChild(panelHolder("C", theme))
splitterCD.AddChild(panelHolder("D", theme))
vSplitter := theme.CreateSplitterLayout()
vSplitter.SetOrientation(gxui.Vertical)
vSplitter.AddChild(menu)
vSplitter.AddChild(splitterCD)
window := theme.CreateWindow(800, 600, "百度盘")
window.SetScale(flags.DefaultScaleFactor)
window.AddChild(vSplitter)
window.OnClose(driver.Terminate)
}
示例14: Init
func (w *Window) Init(outer WindowOuter, driver gxui.Driver, width, height int, title string) {
w.Attachable.Init(outer)
w.BackgroundBorderPainter.Init(outer)
w.Container.Init(outer)
w.Paddable.Init(outer)
w.PaintChildren.Init(outer)
w.outer = outer
w.driver = driver
w.onClose = gxui.CreateEvent(func() {})
w.onResize = gxui.CreateEvent(func() {})
w.onMouseMove = gxui.CreateEvent(func(gxui.MouseEvent) {})
w.onMouseEnter = gxui.CreateEvent(func(gxui.MouseEvent) {})
w.onMouseExit = gxui.CreateEvent(func(gxui.MouseEvent) {})
w.onMouseDown = gxui.CreateEvent(func(gxui.MouseEvent) {})
w.onMouseUp = gxui.CreateEvent(func(gxui.MouseEvent) {})
w.onMouseScroll = gxui.CreateEvent(func(gxui.MouseEvent) {})
w.onKeyDown = gxui.CreateEvent(func(gxui.KeyboardEvent) {})
w.onKeyUp = gxui.CreateEvent(func(gxui.KeyboardEvent) {})
w.onKeyRepeat = gxui.CreateEvent(func(gxui.KeyboardEvent) {})
w.onKeyStroke = gxui.CreateEvent(func(gxui.KeyStrokeEvent) {})
w.onClick = gxui.CreateEvent(func(gxui.MouseEvent) {})
w.onDoubleClick = gxui.CreateEvent(func(gxui.MouseEvent) {})
w.focusController = gxui.CreateFocusController(outer)
w.mouseController = gxui.CreateMouseController(outer, w.focusController)
w.keyboardController = gxui.CreateKeyboardController(outer)
w.onResize.Listen(func() {
w.outer.LayoutChildren()
w.Draw()
})
w.SetBorderPen(gxui.TransparentPen)
w.setViewport(driver.CreateWindowedViewport(width, height, title))
// Window starts shown
w.Attach()
// Interface compliance test
_ = gxui.Window(w)
}
示例15: appMain
func appMain(driver gxui.Driver) {
theme := flags.CreateTheme(driver)
canvas := driver.CreateCanvas(math.Size{W: 500, H: 300})
layout := theme.CreateLinearLayout()
layout.SetSizeMode(gxui.Fill)
layout.SetDirection(gxui.TopToBottom)
buttonsLayout := theme.CreateLinearLayout()
buttonsLayout.SetSizeMode(gxui.Fill)
buttonsLayout.SetDirection(gxui.LeftToRight)
button := func(name string, action func()) gxui.Button {
b := theme.CreateButton()
b.SetText(name)
b.OnClick(func(gxui.MouseEvent) { action() })
return b
}
okayButton := button("Okay", func() { log.Println("Okay") })
buttonsLayout.AddChild(okayButton)
cancelButton := button("Cancel", func() { log.Println("Cancel") })
buttonsLayout.AddChild(cancelButton)
drawPlot(canvas)
canvas.Complete()
image := theme.CreateImage()
image.SetCanvas(canvas)
window := theme.CreateWindow(800, 600, "bview")
window.SetBackgroundBrush(gxui.CreateBrush(gxui.Gray50))
layout.AddChild(buttonsLayout)
layout.AddChild(image)
window.AddChild(layout)
window.OnClose(driver.Terminate)
window.SetPadding(math.Spacing{L: 10, T: 10, R: 10, B: 10})
window.OnResize(func() { log.Println(layout.Children().String()) })
}