func (cfg *Config) Texture(rend *sdl.Renderer, key string) *sdl.Texture { surface := sdl.Load(cfg.data[key]) if surface == nil { log.Fatal("Failed to load " + cfg.data[key]) } defer surface.Free() return rend.CreateTextureFromSurface(surface) }
func (node *Node) DrawLink(rend *sdl.Renderer) { if node.next != nil { rend.SetDrawColor(hexcolor(0x15f0e1)) p0 := node.Pos p1 := node.next.Pos rend.DrawLine(p0.X+p0.W/2, p0.Y+p0.H/2, p1.X+p1.W/2, p1.Y+p1.H/2) } }
func (button *Button) Draw(rend *sdl.Renderer) { w := button.Pos.W state := button.State if state > 2 { state = 2 } rend.Copy(button.texture, &sdl.Rect{int32(state) * w, 0, button.Pos.W, button.Pos.H}, &button.Pos) }
func RenderTextToTexture(r *sdl.Renderer, f *ttf.Font, text string, color sdl.Color) (*sdl.Texture, int, int) { textw, texth, err := f.SizeText(text) if err != nil { log.Fatal(err) } txt_surface := f.RenderText_Blended(text, color) txt_tex := r.CreateTextureFromSurface(txt_surface) txt_surface.Free() return txt_tex, textw, texth }
func (label *Label) Update(rend *sdl.Renderer) { textw, texth, err := label.Font.SizeText(label.Text) if err != nil { log.Fatal(err) } txt_surface := label.Font.RenderText_Blended(label.Text, label.Color) if label.texture != nil { label.texture.Destroy() } label.texture = rend.CreateTextureFromSurface(txt_surface) txt_surface.Free() label.texwidth = int32(textw) label.texheight = int32(texth) }
func studioUpdate(window *sdl.Window, rend *sdl.Renderer, screen *Screen) bool { var event sdl.Event running := true for (&event).Poll() { switch e := (&event).Get().(type) { case sdl.QuitEvent: running = false case sdl.KeyboardEvent: if e.Keysym.Keycode == sdl.K_ESCAPE { running = false } case sdl.MouseMotionEvent: screen.stack.OnMouseMotionEvent(&e) case sdl.MouseButtonEvent: screen.stack.OnMouseButtonEvent(&e) } } neww, newh := window.GetSize() screen.UpdateLayout(sdl.Rect{0, 0, int32(neww), int32(newh)}) //screen.UpdateAnimations(framerate.Delta()) rend.SetDrawBlendMode(sdl.BLENDMODE_NONE) rend.SetDrawColor(screen.rsc.BackgroundColor) rend.Clear() rend.SetDrawBlendMode(sdl.BLENDMODE_BLEND) screen.Draw(rend) rend.Present() screen.framerate.FramerateDelay() return running }
func (node *Node) Draw(rend *sdl.Renderer) { if node.dragging { node.curr.X += (node.goal.X - node.curr.X) * (15.0 / 30.0) node.curr.Y += (node.goal.Y - node.curr.Y) * (15.0 / 30.0) node.Pos.X = int32(node.curr.X) node.Pos.Y = int32(node.curr.Y) node.label.Pos = node.Pos } clr := node.color if !node.dragging { rend.SetDrawColor(clr) rend.FillRect(&node.Pos) } rend.SetDrawColor(lighten(clr, 19)) rend.DrawRect(&node.Pos) node.label.Draw(rend) if node.menu.Visible { node.menu.Draw(rend) } }
func (canvas *CanvasPane) Draw(rend *sdl.Renderer) { for _, n := range canvas.nodes { n.DrawLink(rend) } for _, n := range canvas.nodes { n.Draw(rend) } canvas.menu.Draw(rend) if canvas.new_link != nil { _, x, y := sdl.GetMouseState() n0 := canvas.nodes[*canvas.new_link] rend.SetDrawColor(hexcolor(0xffffff)) pos := n0.GetPos() rend.DrawRect(&pos) rend.SetDrawColor(hexcolor(0x694ae9)) rend.DrawLine(n0.GetPos().X+n0.GetPos().W/2, n0.GetPos().Y+n0.GetPos().H/2, int32(x), int32(y)) } }
func (tb *TopBar) Draw(rend *sdl.Renderer) { rend.SetDrawColor(tb.BackgroundColor) rend.FillRect(&tb.Pos) rend.SetDrawColor(lighten(tb.BackgroundColor, 9)) rend.DrawLine(tb.Pos.X, tb.Pos.Y+tb.Pos.H-1, tb.Pos.X+tb.Pos.W, tb.Pos.Y+tb.Pos.H-1) rend.SetDrawColor(darken(tb.BackgroundColor, 9)) rend.DrawLine(tb.Pos.X, tb.Pos.Y+tb.Pos.H, tb.Pos.X+tb.Pos.W, tb.Pos.Y+tb.Pos.H) for _, w := range tb.elements_left { w.Draw(rend) } if tb.element_center != nil { tb.element_center.Draw(rend) } for _, w := range tb.elements_right { w.Draw(rend) } }
// Draw a popup menu func (menu *PopupMenu) Draw(rend *sdl.Renderer) { if !menu.Visible { return } rend.SetDrawColor(hexcolor(0x303030)) rend.FillRect(&menu.Pos) rend.SetDrawColor(hexcolor(0x363636)) rend.DrawRect(&menu.Pos) if menu.hover != -1 && menu.hover < len(menu.entries) { rend.SetDrawColor(hexcolor(0x406f40)) rend.FillRect(&menu.entries[menu.hover].label.Pos) } for _, e := range menu.entries { e.Draw(rend) } }
func (label *Label) Draw(rend *sdl.Renderer) { pos := sdl.Rect{label.Pos.X + (label.Pos.W-label.texwidth)/2, label.Pos.Y + (label.Pos.H-label.texheight)/2, label.texwidth, label.texheight} rend.Copy(label.texture, nil, &pos) }