func (cb *CheckBox) Draw() { var img image.Image if cb.checked && cb.mouseIn { img = tk.cbCheckedHover } else if cb.checked && !cb.mouseIn { img = tk.cbChecked } else if !cb.checked && cb.mouseIn { img = tk.cbUncheckedHover } else if !cb.checked && !cb.mouseIn { img = tk.cbUnchecked } gfx.DrawOver(&cb.parent.Element, img, cb.Element.X, cb.Element.Y, cb.Element.Width, cb.Element.Height) if cb.txt != "" { w, h, _ := fonts.ExpectedSize(cb.Element.Font, cb.txt) voffsetTxt := cb.Element.Height/2 - int(h)/2 + 1 // FIXME: temp solution. instead, parent element should expose region redraw method bg := cb.parent.GetBG() gfx.RectFilled(cb.parent.Element.Buffer, cb.Element.X+cb.Element.Width+ICON_TEXT_SPACE, cb.Element.Y+voffsetTxt, cb.Element.X+cb.Element.Width+ICON_TEXT_SPACE+int(w), cb.Element.Y+voffsetTxt+int(h), cb.parent.Element.Width, bg.R, bg.G, bg.B, bg.A) fonts.Render(&cb.parent.Element, cb.txt, cb.Element.X+cb.Element.Width+ICON_TEXT_SPACE, cb.Element.Y+voffsetTxt, cb.parent.Element.Width-cb.Element.X-ICON_TEXT_SPACE-cb.Element.Width, cb.Element.Height, cb.Element.Font) } }
func (but *Button) Draw() { var r, g, b byte if but.pushed { r, g, b = 49, 80, 0 } else { r, g, b = 80, 130, 0 } gfx.RectFilled(but.parent.Element.Buffer, but.Element.X, but.Element.Y, but.Element.X+but.Element.Width, but.Element.Y+but.Element.Height, but.parent.Element.Width, r, g, b, gfx.A_OPAQUE) gfx.Rect(but.parent.Element.Buffer, but.Element.X, but.Element.Y, but.Element.X+but.Element.Width-1, but.Element.Y+but.Element.Height-1, but.parent.Element.Width, 0, 0, 0, gfx.A_OPAQUE) if but.style&BS_TEXT != 0 { w, h, _ := fonts.ExpectedSize(but.Element.Font, but.txt) hoffsetTxt := but.Element.Width/2 - int(w)/2 voffsetTxt := but.Element.Height/2 - int(h)/2 + 1 fonts.Render(&but.parent.Element, but.txt, but.Element.X+hoffsetTxt, but.Element.Y+voffsetTxt, but.Element.Width, but.Element.Height, but.Element.Font) } else if but.style&BS_ICON_TEXT != 0 { iw := but.icon.Bounds().Dx() ih := but.icon.Bounds().Dy() w, h, _ := fonts.ExpectedSize(but.Element.Font, but.txt) hoffsetIcon := but.Element.Width/2 - int(int(w)+iw+ICON_TEXT_SPACE)/2 voffsetTxt := but.Element.Height/2 - int(h)/2 + 1 voffsetIcon := but.Element.Height/2 - int(ih)/2 gfx.DrawOver(&but.parent.Element, but.icon, but.Element.X+hoffsetIcon, but.Element.Y+voffsetIcon, iw, ih) fonts.Render(&but.parent.Element, but.txt, but.Element.X+hoffsetIcon+iw+ICON_TEXT_SPACE, but.Element.Y+voffsetTxt, but.Element.Width, but.Element.Height, but.Element.Font) } else if but.style&BS_ICON != 0 { iw := but.icon.Bounds().Dx() ih := but.icon.Bounds().Dy() hoffsetIcon := but.Element.Width/2 - int(iw)/2 voffsetIcon := but.Element.Height/2 - int(ih)/2 gfx.DrawOver(&but.parent.Element, but.icon, but.Element.X+hoffsetIcon, but.Element.Y+voffsetIcon, iw, ih) } }
func (c *Compositor) Compose() { for { <-c.InvMsgPipe <-c.MouseWait // render desktop, windows, and child elements for v := c.WindowList.Back(); v != nil; v = v.Prev() { e := v.Value.(*base.Element) gfx.DrawSrc(c.fb, e, e.X, e.Y, e.Width, e.Height) } // render mouse pointer if c.mousePointer != nil { gfx.DrawOver(c.fb, c.mousePointer, c.mousePointer.X, c.mousePointer.Y, c.mousePointer.Width, c.mousePointer.Height) } flush(c) c.CompositorRelease <- false } }