func (a *customAdapter) Create(theme gxui.Theme, index int) gxui.Control { phase := float32(index) / 1000 c := gxui.Color{ R: 0.5 + 0.5*math.Sinf(math.TwoPi*(phase+0.000)), G: 0.5 + 0.5*math.Sinf(math.TwoPi*(phase+0.333)), B: 0.5 + 0.5*math.Sinf(math.TwoPi*(phase+0.666)), A: 1.0, } i := theme.CreateImage() i.SetBackgroundBrush(gxui.CreateBrush(c)) i.SetMargin(math.Spacing{L: 3, T: 3, R: 3, B: 3}) i.OnMouseEnter(func(ev gxui.MouseEvent) { i.SetBorderPen(gxui.CreatePen(2, gxui.Gray80)) }) i.OnMouseExit(func(ev gxui.MouseEvent) { i.SetBorderPen(gxui.TransparentPen) }) i.OnMouseDown(func(ev gxui.MouseEvent) { i.SetBackgroundBrush(gxui.CreateBrush(c.MulRGB(0.7))) }) i.OnMouseUp(func(ev gxui.MouseEvent) { i.SetBackgroundBrush(gxui.CreateBrush(c)) }) return i }
// parts.DrawPaint overrides func (b *SplitterBar) Paint(c gxui.Canvas) { r := b.outer.Size().Rect() c.DrawRect(r, gxui.CreateBrush(b.backgroundColor)) if b.foregroundColor != b.backgroundColor { c.DrawRect(r.ContractI(1), gxui.CreateBrush(b.foregroundColor)) } }
func CreateProgressBar(theme *Theme) gxui.ProgressBar { b := &ProgressBar{} b.Init(b, theme) b.theme = theme b.chevronWidth = 10 b.OnAttach(func() { driver := theme.Driver() b.ticker = time.NewTicker(time.Millisecond * 50) go func() { for _ = range b.ticker.C { if !driver.Call(b.animationTick) { return } } }() }) b.OnDetach(func() { if b.chevrons != nil { b.chevrons.Release() b.chevrons = nil b.ticker.Stop() b.ticker = nil } }) b.SetBackgroundBrush(gxui.CreateBrush(gxui.Gray10)) b.SetBorderPen(gxui.CreatePen(1, gxui.Gray40)) return b }
func (b *ProgressBar) SetSize(size math.Size) { b.ProgressBar.SetSize(size) b.chevrons = nil if size.Area() > 0 { b.chevrons = b.theme.Driver().CreateCanvas(size) b.chevronWidth = size.H / 2 cw := b.chevronWidth for x := -cw * 2; x < size.W; x += cw * 2 { // x0 x2 // | x1 | x3 // | | // A-----B - y0 // \ \ // \ \ // F C - y1 // / / // / / // E-----D - y2 y0, y1, y2 := 0, size.H/2, size.H x0, x1 := x, x+cw/2 x2, x3 := x0+cw, x1+cw var chevron = gxui.Polygon{ /* A */ gxui.PolygonVertex{Position: math.Point{X: x0, Y: y0}}, /* B */ gxui.PolygonVertex{Position: math.Point{X: x2, Y: y0}}, /* C */ gxui.PolygonVertex{Position: math.Point{X: x3, Y: y1}}, /* D */ gxui.PolygonVertex{Position: math.Point{X: x2, Y: y2}}, /* E */ gxui.PolygonVertex{Position: math.Point{X: x0, Y: y2}}, /* F */ gxui.PolygonVertex{Position: math.Point{X: x1, Y: y1}}, } b.chevrons.DrawPolygon(chevron, gxui.TransparentPen, gxui.CreateBrush(gxui.Gray30)) } b.chevrons.Complete() } }
func buildMoon(theme gxui.Theme, center math.Point, radius float32) gxui.Image { c := 40 p := make(gxui.Polygon, c*2) for i := 0; i < c; i++ { frac := float32(i) / float32(c) α := math.Lerpf(math.Pi*1.2, math.Pi*-0.2, frac) p[i] = gxui.PolygonVertex{ Position: math.Point{ X: center.X + int(radius*math.Sinf(α)), Y: center.Y + int(radius*math.Cosf(α)), }, RoundedRadius: 0, } } for i := 0; i < c; i++ { frac := float32(i) / float32(c) α := math.Lerpf(math.Pi*-0.2, math.Pi*1.2, frac) r := math.Lerpf(radius, radius*0.5, math.Sinf(frac*math.Pi)) p[i+c] = gxui.PolygonVertex{ Position: math.Point{ X: center.X + int(r*math.Sinf(α)), Y: center.Y + int(r*math.Cosf(α)), }, RoundedRadius: 0, } } image := theme.CreateImage() image.SetPolygon(p, gxui.CreatePen(3, gxui.Gray80), gxui.CreateBrush(gxui.Gray40)) return image }
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) }
func CreateStyle(fontColor, brushColor, penColor gxui.Color, penWidth float32) Style { return Style{ FontColor: fontColor, Pen: gxui.CreatePen(penWidth, penColor), Brush: gxui.CreateBrush(brushColor), } }
func appMain(driver gxui.Driver) { theme := dark.CreateTheme(driver) window := theme.CreateWindow(500, 200, "Launch") window.SetBackgroundBrush(gxui.CreateBrush(gxui.Gray10)) layout := theme.CreateLinearLayout() layout.SetDirection(gxui.TopToBottom) searchBox := theme.CreateTextBox() searchBox.SetDesiredWidth(500) searchBox.SetMargin(math.Spacing{L: 4, T: 2, R: 4, B: 2}) layout.AddChild(searchBox) adapter := gxui.CreateDefaultAdapter() searchBox.OnKeyDown(func(ev gxui.KeyboardEvent) { res := search.Search(searchBox.Text()) adapter.SetItems(res.NameList()) }) droplist := theme.CreateDropDownList() droplist.SetAdapter(adapter) layout.AddChild(droplist) window.AddChild(layout) window.OnClose(driver.Terminate) }
func drawMoon(canvas gxui.Canvas, center math.Point, radius float32) { c := 40 p := make(gxui.Polygon, c*2) for i := 0; i < c; i++ { frac := float32(i) / float32(c) α := math.Lerpf(math.Pi*1.2, math.Pi*-0.2, frac) p[i] = gxui.PolygonVertex{ Position: math.Point{ X: center.X + int(radius*math.Sinf(α)), Y: center.Y + int(radius*math.Cosf(α)), }, RoundedRadius: 0, } } for i := 0; i < c; i++ { frac := float32(i) / float32(c) α := math.Lerpf(math.Pi*-0.2, math.Pi*1.2, frac) r := math.Lerpf(radius, radius*0.5, math.Sinf(frac*math.Pi)) p[i+c] = gxui.PolygonVertex{ Position: math.Point{ X: center.X + int(r*math.Sinf(α)), Y: center.Y + int(r*math.Cosf(α)), }, RoundedRadius: 0, } } canvas.DrawPolygon(p, gxui.CreatePen(3, gxui.Gray80), gxui.CreateBrush(gxui.Gray40)) }
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) }
func (b *ProgressBar) PaintProgress(c gxui.Canvas, r math.Rect, frac float32) { r.Max.X = math.Lerp(r.Min.X, r.Max.X, frac) c.DrawRect(r, gxui.CreateBrush(gxui.Gray50)) c.Push() c.AddClip(r) c.DrawCanvas(b.chevrons, math.Point{X: b.scroll}) c.Pop() }
func (treeControlCreator) Create(theme gxui.Theme, control gxui.Control, node *mixins.TreeToListNode) gxui.Control { img := theme.CreateImage() imgSize := math.Size{W: 10, H: 10} ll := theme.CreateLinearLayout() ll.SetDirection(gxui.LeftToRight) btn := theme.CreateButton() btn.SetBackgroundBrush(gxui.TransparentBrush) btn.SetBorderPen(gxui.CreatePen(1, gxui.Gray30)) btn.SetMargin(math.Spacing{L: 1, R: 1, T: 1, B: 1}) btn.OnClick(func(ev gxui.MouseEvent) { if ev.Button == gxui.MouseButtonLeft { node.ToggleExpanded() } }) btn.AddChild(img) update := func() { expanded := node.IsExpanded() canvas := theme.Driver().CreateCanvas(imgSize) btn.SetVisible(!node.IsLeaf()) switch { case !btn.IsMouseDown(gxui.MouseButtonLeft) && expanded: canvas.DrawPolygon(expandedPoly, gxui.TransparentPen, gxui.CreateBrush(gxui.Gray70)) case !btn.IsMouseDown(gxui.MouseButtonLeft) && !expanded: canvas.DrawPolygon(collapsedPoly, gxui.TransparentPen, gxui.CreateBrush(gxui.Gray70)) case expanded: canvas.DrawPolygon(expandedPoly, gxui.TransparentPen, gxui.CreateBrush(gxui.Gray30)) case !expanded: canvas.DrawPolygon(collapsedPoly, gxui.TransparentPen, gxui.CreateBrush(gxui.Gray30)) } canvas.Complete() img.SetCanvas(canvas) } btn.OnMouseDown(func(gxui.MouseEvent) { update() }) btn.OnMouseUp(func(gxui.MouseEvent) { update() }) update() gxui.WhileAttached(btn, node.OnChange, update) ll.AddChild(btn) ll.AddChild(control) ll.SetPadding(math.Spacing{L: 16 * node.Depth()}) return ll }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) label1 := theme.CreateLabel() label1.SetColor(gxui.White) label1.SetText("1x1") cell1x1 := theme.CreateLinearLayout() cell1x1.SetBackgroundBrush(gxui.CreateBrush(gxui.Blue40)) cell1x1.SetHorizontalAlignment(gxui.AlignCenter) cell1x1.AddChild(label1) label2 := theme.CreateLabel() label2.SetColor(gxui.White) label2.SetText("2x1") cell2x1 := theme.CreateLinearLayout() cell2x1.SetBackgroundBrush(gxui.CreateBrush(gxui.Green40)) cell2x1.SetHorizontalAlignment(gxui.AlignCenter) cell2x1.AddChild(label2) label3 := theme.CreateLabel() label3.SetColor(gxui.White) label3.SetText("1x2") cell1x2 := theme.CreateLinearLayout() cell1x2.SetBackgroundBrush(gxui.CreateBrush(gxui.Red40)) cell1x2.SetHorizontalAlignment(gxui.AlignCenter) cell1x2.AddChild(label3) table := theme.CreateTableLayout() table.SetGrid(3, 2) // columns, rows // row, column, horizontal span, vertical span table.SetChildAt(0, 0, 1, 1, cell1x1) table.SetChildAt(0, 1, 2, 1, cell2x1) table.SetChildAt(2, 0, 1, 2, cell1x2) window := theme.CreateWindow(800, 600, "Table") window.AddChild(table) window.OnClose(driver.Terminate) }
func (t *Tree) CreateExpandButton(theme gxui.Theme, node *mixins.TreeInternalNode) gxui.Button { img := theme.CreateImage() imgSize := math.Size{W: 10, H: 10} btn := theme.CreateButton() btn.SetBackgroundBrush(gxui.TransparentBrush) btn.SetBorderPen(gxui.CreatePen(1, gxui.Gray30)) btn.SetMargin(math.Spacing{L: 1, R: 1, T: 1, B: 1}) btn.OnClick(func(ev gxui.MouseEvent) { if ev.Button == gxui.MouseButtonLeft { if node.IsExpanded() { node.Collapse() } else { node.Expand() } } }) btn.AddChild(img) updateStyle := func() { canvas := theme.Driver().CreateCanvas(imgSize) switch { case !btn.IsMouseDown(gxui.MouseButtonLeft) && node.IsExpanded(): canvas.DrawPolygon(expandedPoly, gxui.TransparentPen, gxui.CreateBrush(gxui.Gray70)) case !btn.IsMouseDown(gxui.MouseButtonLeft) && !node.IsExpanded(): canvas.DrawPolygon(collapsedPoly, gxui.TransparentPen, gxui.CreateBrush(gxui.Gray70)) case node.IsExpanded(): canvas.DrawPolygon(expandedPoly, gxui.TransparentPen, gxui.CreateBrush(gxui.Gray30)) case !node.IsExpanded(): canvas.DrawPolygon(collapsedPoly, gxui.TransparentPen, gxui.CreateBrush(gxui.Gray30)) } canvas.Complete() img.SetCanvas(canvas) } btn.OnMouseDown(func(gxui.MouseEvent) { updateStyle() }) btn.OnMouseUp(func(gxui.MouseEvent) { updateStyle() }) node.OnExpandedChanged(func(e bool) { updateStyle() }) updateStyle() return btn }
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) }
func drawStar(canvas gxui.Canvas, center math.Point, radius, rotation float32, points int) { p := make(gxui.Polygon, points*2) for i := 0; i < points*2; i++ { frac := float32(i) / float32(points*2) α := frac*math.TwoPi + rotation r := []float32{radius, radius / 2}[i&1] p[i] = gxui.PolygonVertex{ Position: math.Point{ X: center.X + int(r*math.Cosf(α)), Y: center.Y + int(r*math.Sinf(α)), }, RoundedRadius: []float32{0, 50}[i&1], } } canvas.DrawPolygon(p, gxui.CreatePen(3, gxui.Red), gxui.CreateBrush(gxui.Yellow)) }
func buildStar(theme gxui.Theme, center math.Point, radius, rotation float32, points int) gxui.Image { p := make(gxui.Polygon, points*2) for i := 0; i < points*2; i++ { frac := float32(i) / float32(points*2) α := frac*math.TwoPi + rotation r := []float32{radius, radius / 2}[i&1] p[i] = gxui.PolygonVertex{ Position: math.Point{ X: center.X + int(r*math.Cosf(α)), Y: center.Y + int(r*math.Sinf(α)), }, RoundedRadius: []float32{0, 50}[i&1], } } image := theme.CreateImage() image.SetPolygon(p, gxui.CreatePen(3, gxui.Red), gxui.CreateBrush(gxui.Yellow)) return image }
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()) }) }
func appMain(driver gxui.Driver) { theDriver = driver theme = flags.CreateTheme(driver) window := theme.CreateWindow(winW, winH, "Window") window.OnClose(driver.Terminate) window.SetScale(flags.DefaultScaleFactor) layout := theme.CreateLinearLayout() layout.SetBackgroundBrush(gxui.CreateBrush(gxui.Black)) layout.SetDirection(gxui.LeftToRight) layout.SetVerticalAlignment(gxui.AlignBottom) layout.SetSizeMode(gxui.Fill) nums := common.GenerateRandomNumbers(numBars, 0, valNum) for _, n := range nums { child := createBar() setBarHeight(child, n) layout.AddChild(child) bars = append(bars, child) } window.AddChild(layout) delegate := &GUIDelegate{} go func() { <-time.After(1 * time.Second) fmt.Println("ExecuteSort...") // sorting.ExecuteSort(sorting.InsertionSort, nums, delegate) // sorting.ExecuteSort(sorting.BubbleSort, nums, delegate) // sorting.ExecuteSort(sorting.SelectionSort, nums, delegate) // sorting.ExecuteSort(sorting.ShellSort, nums, delegate) // sorting.ExecuteSort(sorting.MergeSort, nums, delegate) sorting.ExecuteSort(sorting.QuickSort, nums, delegate) // fmt.Println(result) }() }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) font, err := driver.CreateFont(gxfont.Default, 75) if err != nil { panic(err) } window := theme.CreateWindow(380, 100, "Hi") window.SetBackgroundBrush(gxui.CreateBrush(gxui.Gray50)) label := theme.CreateLabel() label.SetFont(font) label.SetText("Hello world") window.AddChild(label) ticker := time.NewTicker(time.Millisecond * 30) go func() { phase := float32(0) for _ = range ticker.C { c := gxui.Color{ R: 0.75 + 0.25*math.Cosf((phase+0.000)*math.TwoPi), G: 0.75 + 0.25*math.Cosf((phase+0.333)*math.TwoPi), B: 0.75 + 0.25*math.Cosf((phase+0.666)*math.TwoPi), A: 0.50 + 0.50*math.Cosf(phase*10), } phase += 0.01 driver.Call(func() { label.SetColor(c) }) } }() window.OnClose(ticker.Stop) window.OnClose(driver.Terminate) }
func AppMain(driver gxui.Driver) { theme := dark.CreateTheme(driver) layout := theme.CreateLinearLayout() label := theme.CreateLabel() label.SetFont(CreateFont(15, driver)) label.SetText("Path To Folder") layout.AddChild(label) textBox := theme.CreateTextBox() textBox.SetFont(CreateFont(15, driver)) textBox.SetDesiredWidth(300) layout.AddChild(textBox) button := theme.CreateButton() button.SetText("Parse Docs") action := func() { fmt.Println("What the heck") } button.OnClick(func(gxui.MouseEvent) { action() }) layout.AddChild(button) vSplitter := theme.CreateSplitterLayout() vSplitter.SetOrientation(gxui.Vertical) vSplitter.AddChild(layout) window := theme.CreateWindow(600, 400, "Office File Parser") window.SetBackgroundBrush(gxui.CreateBrush(gxui.Gray10)) window.AddChild(vSplitter) window.OnClose(driver.Terminate) }
func (l *List) PaintMouseOverBackground(c gxui.Canvas, r math.Rect) { c.DrawRoundedRect(r, 2.0, 2.0, 2.0, 2.0, gxui.TransparentPen, gxui.CreateBrush(gxui.Gray90)) }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) font, err := driver.CreateFont(gxfont.Default, H1_FONT_SIZE) catch(err) window := theme.CreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, APP_TITLE) window.SetBackgroundBrush(gxui.CreateBrush(gxui.White)) window.SetScale(flags.DefaultScaleFactor) window.SetPadding(math.Spacing{L: 10, R: 10, T: 10, B: 10}) layout := theme.CreateLinearLayout() layout.SetSizeMode(gxui.Fill) layout.SetHorizontalAlignment(gxui.AlignCenter) layout.HorizontalAlignment().AlignCenter() fullscreenButton := theme.CreateButton() fullscreenButton.SetText("Make Fullscreen") fullscreenButton.OnClick(func(ev gxui.MouseEvent) { fullscreen := !window.Fullscreen() window.SetFullscreen(fullscreen) if fullscreen { fullscreenButton.SetText("Make Windowed") } else { fullscreenButton.SetText("Make Fullscreen") } }) h1Title := theme.CreateLabel() h1Title.SetFont(font) h1Title.SetColor(gxui.Color{R: 0, G: 0, B: 0, A: 1}) KinopoiskLabel := theme.CreateLabel() KinopoiskLabel.SetFont(font) KinopoiskLabel.SetColor(gxui.Color{R: 0, G: 0, B: 0, A: 1}) ImdbLabel := theme.CreateLabel() ImdbLabel.SetFont(font) ImdbLabel.SetColor(gxui.Color{R: 0, G: 0, B: 0, A: 1}) // https://github.com/google/gxui/blob/master/samples/image_viewer/main.go img := theme.CreateImage() getFilmButton := theme.CreateButton() getFilmButton.SetText("Get Film!") getFilmButton.OnClick(func(ev gxui.MouseEvent) { getFilm(driver, h1Title, KinopoiskLabel, ImdbLabel, img) }) getFilm(driver, h1Title, KinopoiskLabel, ImdbLabel, img) layout.AddChild(fullscreenButton) layout.AddChild(h1Title) layout.AddChild(KinopoiskLabel) layout.AddChild(ImdbLabel) layout.AddChild(getFilmButton) layout.AddChild(img) window.AddChild(layout) window.OnClose(driver.Terminate) }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) window := theme.CreateWindow(800, 600, "navmesh") canvas := driver.CreateCanvas(math.Size{W: 800, H: 600}) // mouse isStart := true var src_id, dest_id int32 // source & dest triangle id var src, dest Point3 window.OnMouseDown(func(me gxui.MouseEvent) { pt := Point3{X: float32(me.Point.X) / SCALE_FACTOR, Y: float32(me.Point.Y) / SCALE_FACTOR} id := getTriangleId(pt) if isStart { src_id = id src = pt } else { dest_id = id dest = pt } if !isStart { if src_id != -1 && dest_id != -1 { canvas := route(driver, src_id, dest_id, src, dest) image := theme.CreateImage() image.SetCanvas(canvas) window.AddChild(image) } } isStart = !isStart }) // draw mesh for k := 0; k < len(triangles); k++ { poly := []gxui.PolygonVertex{ gxui.PolygonVertex{ Position: math.Point{ int(SCALE_FACTOR * vertices[triangles[k][0]].X), int(SCALE_FACTOR * vertices[triangles[k][0]].Y), }}, gxui.PolygonVertex{ Position: math.Point{ int(SCALE_FACTOR * vertices[triangles[k][1]].X), int(SCALE_FACTOR * vertices[triangles[k][1]].Y), }}, gxui.PolygonVertex{ Position: math.Point{ int(SCALE_FACTOR * vertices[triangles[k][2]].X), int(SCALE_FACTOR * vertices[triangles[k][2]].Y), }}, } canvas.DrawPolygon(poly, gxui.CreatePen(3, gxui.Gray80), gxui.CreateBrush(gxui.Gray40)) //canvas.DrawPolygon(poly, gxui.CreatePen(2, gxui.Red), gxui.CreateBrush(gxui.Yellow)) } canvas.Complete() image := theme.CreateImage() image.SetCanvas(canvas) window.AddChild(image) window.OnClose(driver.Terminate) }
func appMain(driver gxui.Driver) { theme := flags.CreateTheme(driver) font, err := driver.CreateFont(gxfont.Default, 75) if err != nil { panic(err) } window := theme.CreateWindow(800, 480, "Привет") window.SetBackgroundBrush(gxui.CreateBrush(gxui.Gray50)) window.SetBorderPen(gxui.Pen{Width: 5, Color: gxui.Yellow}) f, err := os.Open("wallpaper.jpg") if err != nil { fmt.Printf("Failed to open image %v\n", err) os.Exit(1) } source, _, err := image.Decode(f) if err != nil { fmt.Printf("Failed to open image %v\n", err) os.Exit(2) } wallpaper := theme.CreateImage() window.AddChild(wallpaper) // Copy the image to a RGBA format before handing to a gxui.Texture rgba := image.NewRGBA(source.Bounds()) draw.Draw(rgba, source.Bounds(), source, image.ZP, draw.Src) texture := driver.CreateTexture(rgba, 1) wallpaper.SetTexture(texture) layout := theme.CreateLinearLayout() layout.SetDirection(gxui.TopToBottom) window.AddChild(layout) label := theme.CreateLabel() label.SetFont(font) label.SetText("Здравствуй мир") label.OnMouseMove(func(e gxui.MouseEvent) { fmt.Printf("X=%d; Y=%d\n", e.Point.X, e.Point.Y) }) layout.AddChild(label) lTimer := theme.CreateLabel() lTimer.SetFont(font) lTimer.SetColor(gxui.Green30) layout.AddChild(lTimer) button := theme.CreateButton() button.SetText("Exit") button.SetPadding(math.Spacing{20, 10, 20, 10}) button.SetMargin(math.Spacing{20, 10, 20, 10}) button.OnClick(func(e gxui.MouseEvent) { window.Close() }) layout.AddChild(button) ticker := time.NewTicker(time.Millisecond * 30) go func() { phase := float32(0) for _ = range ticker.C { c := gxui.Color{ R: 0.75 + 0.25*math.Cosf((phase+0.000)*math.TwoPi), G: 0.75 + 0.25*math.Cosf((phase+0.333)*math.TwoPi), B: 0.75 + 0.25*math.Cosf((phase+0.666)*math.TwoPi), A: 0.50 + 0.50*math.Cosf(phase*10), } phase += 0.01 driver.Call(func() { label.SetColor(c) }) } }() ticker2 := time.NewTicker(time.Millisecond * 100) go func() { for t := range ticker.C { driver.Call(func() { lTimer.SetText(t.Format(time.Stamp)) }) } }() window.OnClose(ticker.Stop) window.OnClose(ticker2.Stop) window.OnClose(driver.Terminate) }
func (b *ProgressBar) PaintProgress(c gxui.Canvas, r math.Rect, frac float32) { r.Max.X = math.Lerp(r.Min.X, r.Max.X, frac) c.DrawRect(r, gxui.CreateBrush(gxui.Gray50)) }
"github.com/google/gxui" "github.com/google/gxui/drivers/gl" "github.com/google/gxui/math" "github.com/google/gxui/samples/flags" "github.com/xinhuang327/algorithms/common" "github.com/xinhuang327/algorithms/sorting" ) var theDriver gxui.Driver var theme gxui.Theme var winW = 1600 var winH = 1000 var numBars = 100 var valNum = 10000 var defaultBgBrush = gxui.CreateBrush(gxui.White) var markBgBrush = gxui.CreateBrush(gxui.Red) var setBgBrush = gxui.CreateBrush(gxui.Green) var swapABgBrush = gxui.CreateBrush(gxui.Blue) var swapBBgBrush = gxui.CreateBrush(gxui.Blue50) var bars []gxui.Button func createBar() gxui.Button { child := theme.CreateButton() child.SetBackgroundBrush(defaultBgBrush) w := winW / numBars if w < 1 { w = 1 } child.SetBorderPen(gxui.TransparentPen) child.SetPadding(math.Spacing{L: w, T: w})
func CreateWindow(theme *Theme, width, height int, title string) gxui.Window { w := &Window{} w.Window.Init(w, theme.Driver(), width, height, title) w.SetBackgroundBrush(gxui.CreateBrush(theme.WindowBackground)) return w }
func draw(p Pendulum, canvas gxui.Canvas, x, y int) { attachment := math.Point{X: ANIMATION_WIDTH/2 + x, Y: y} phi := p.GetPhi() ball := math.Point{X: x + ANIMATION_WIDTH/2 + math.Round(float32(l*omath.Sin(phi))), Y: y + math.Round(float32(l*omath.Cos(phi)))} line := gxui.Polygon{gxui.PolygonVertex{attachment, 0}, gxui.PolygonVertex{ball, 0}} canvas.DrawLines(line, gxui.DefaultPen) m := math.Point{int(BALL_RADIUS), int(BALL_RADIUS)} rect := math.Rect{ball.Sub(m), ball.Add(m)} canvas.DrawRoundedRect(rect, BALL_RADIUS, BALL_RADIUS, BALL_RADIUS, BALL_RADIUS, gxui.TransparentPen, gxui.CreateBrush(gxui.Yellow)) }
func MainWindow(driver gxui.Driver) { theme = dark.CreateTheme(driver) fontData, err := ioutil.ReadFile("./fonts/Microsoft Yahei.ttf") if err != nil { log.Fatalf("error reading font: %v", err) } font, err := driver.CreateFont(fontData, 20) if err != nil { panic(err) } theme.SetDefaultFont(font) headLayout := theme.CreateLinearLayout() headLayout.SetSizeMode(gxui.Fill) headLayout.SetHorizontalAlignment(gxui.AlignCenter) headLayout.SetDirection(gxui.TopToBottom) headLayout.SetSize(math.Size{W: 100, H: 50}) label := theme.CreateLabel() label.SetMargin(math.CreateSpacing(10)) label.SetText("豆瓣FM红心歌单下载") headLayout.AddChild(label) bodyLayout := theme.CreateLinearLayout() bodyLayout.SetSizeMode(gxui.Fill) bodyLayout.SetHorizontalAlignment(gxui.AlignCenter) bodyLayout.SetSize(math.Size{W: 100, H: 400}) bodyLayout.SetDirection(gxui.TopToBottom) // bodyLayout.SetMargin(math.Spacing{T: 50}) userHint := theme.CreateLabel() userHint.SetMargin(math.CreateSpacing(10)) userHint.SetText("用户名") bodyLayout.AddChild(userHint) usernameField := theme.CreateTextBox() bodyLayout.AddChild(usernameField) passHint := theme.CreateLabel() passHint.SetMargin(math.CreateSpacing(10)) passHint.SetText("密码") bodyLayout.AddChild(passHint) passwordField := theme.CreateTextBox() bodyLayout.AddChild(passwordField) footLayout := theme.CreateLinearLayout() footLayout.SetSizeMode(gxui.Fill) footLayout.SetHorizontalAlignment(gxui.AlignCenter) footLayout.SetDirection(gxui.TopToBottom) // footLayout.SetMargin(math.Spacing{T: 450}) button := theme.CreateButton() button.SetText("登录并下载") button.OnClick(func(gxui.MouseEvent) { user := usernameField.Text() password := passwordField.Text() if user == "" || password == "" { return } label.SetText(user + "&" + password) }) footLayout.AddChild(button) window := theme.CreateWindow(600, 800, "豆瓣FM下载器") window.SetBackgroundBrush(gxui.CreateBrush(gxui.White)) window.AddChild(headLayout) window.AddChild(bodyLayout) window.AddChild(footLayout) window.OnClose(driver.Terminate) window.SetPadding(math.Spacing{L: 10, T: 10, R: 10, B: 10}) }