Пример #1
0
func (c *Checkbox) draw(gc draw2d.GraphicContext) {
	gc.Clear()
	gc.SetStrokeColor(color.Black)
	if c.pressed {
		gc.SetFillColor(color.RGBA{155, 0, 0, 255})
	} else {
		gc.SetFillColor(color.RGBA{255, 0, 0, 255})
	}

	// Draw background rect
	x, y := gc.LastPoint()
	gc.MoveTo(0, 0)
	gc.LineTo(c.Size.X, 0)
	gc.LineTo(c.Size.X, c.Size.Y)
	gc.LineTo(0, c.Size.Y)
	gc.Close()
	gc.FillStroke()

	// Draw inner rect
	if c.state {
		gc.SetFillColor(color.Black)
		gc.MoveTo(5, 5)
		gc.LineTo(c.Size.X-5, 5)
		gc.LineTo(c.Size.X-5, c.Size.Y-5)
		gc.LineTo(5, c.Size.Y-5)
		gc.Close()
		gc.FillStroke()
	}

	gc.MoveTo(x, y)
}
Пример #2
0
func (l *Label) draw(gc draw2d.GraphicContext) {
	gc.Clear()
	tw := float64(l.tbuf.Bounds().Max.X - l.tbuf.Bounds().Min.X)
	th := float64(l.tbuf.Bounds().Max.Y - l.tbuf.Bounds().Min.Y)
	gc.Translate((l.Size.X-tw)/2, (l.Size.Y-th)/2)
	gc.DrawImage(l.tbuf)
}
Пример #3
0
func ClearPaint(gc draw2d.GraphicContext) {
	if true {
		gc.Clear()
		gc.SetFillColor(color.RGBA{155, 0, 0, 255})
		gc.Fill()
	}
}
Пример #4
0
func (e *Entry) draw(gc draw2d.GraphicContext) {
	if e.textOffset+e.runeOffsets[e.cursor] < 5 {
		e.textOffset = 5 - e.runeOffsets[e.cursor]
	}
	if e.textOffset+e.runeOffsets[e.cursor] > e.Size.X-5 {
		e.textOffset = e.Size.X - 5 - e.runeOffsets[e.cursor]
	}

	gc.Clear()
	if e.HasKeyFocus {
		gc.SetFillColor(color.RGBA{150, 150, 150, 255})
		safeRect(gc, geom.Coord{0, 0}, e.Size)
		gc.Fill()
	}
	th := float64(e.textBuffer.Bounds().Max.Y - e.textBuffer.Bounds().Min.Y)
	gc.Save()
	gc.Translate(e.textOffset, 0)

	if e.selecting {
		start := e.runeOffsets[e.cursor]
		end := e.runeOffsets[e.selectCursor]
		if start > end {
			start, end = end, start
		}
		gc.SetFillColor(color.RGBA{200, 200, 200, 255})
		safeRect(gc, geom.Coord{start, 0}, geom.Coord{end, e.Size.Y})
		gc.Fill()
	}

	gc.Translate(0, (e.Size.Y-th)/2)

	gc.DrawImage(e.textBuffer)
	gc.Restore()
	if e.HasKeyFocus {
		un := time.Duration(time.Now().UnixNano())
		ms := un / time.Millisecond
		ms = ms % 750
		var intensity uint8 = 255
		if ms > 550 {
			diff := 650 - ms
			if diff < 0 {
				diff *= -1
			}
			intensity = uint8((diff * 255) / 200)
		}
		offset := float64(int(e.runeOffsets[e.cursor] + e.textOffset))
		gc.SetStrokeColor(color.RGBA{A: intensity})
		gc.MoveTo(offset, 0)
		gc.LineTo(offset, e.Size.Y)
		gc.Stroke()
		e.Invalidate(geom.Rect{
			Min: geom.Coord{offset - 1, 0},
			Max: geom.Coord{offset + 1, e.Size.Y},
		})
	}
}
Пример #5
0
func (b *Button) draw(gc draw2d.GraphicContext) {
	gc.Clear()
	gc.SetStrokeColor(color.Black)
	if b.pressed {
		gc.SetFillColor(color.RGBA{150, 150, 150, 255})
	} else {
		gc.SetFillColor(color.White)
	}
	safeRect(gc, geom.Coord{0, 0}, b.Size)
	gc.FillStroke()
}
Пример #6
0
func (l *KeyGrab) draw(gc draw2d.GraphicContext) {
	gc.Clear()
	if l.HasKeyFocus {
		gc.SetFillColor(color.RGBA{150, 150, 150, 255})
		safeRect(gc, geom.Coord{0, 0}, l.Size)
		gc.FillStroke()
	}
	tw := float64(l.kbuf.Bounds().Max.X - l.kbuf.Bounds().Min.X)
	th := float64(l.kbuf.Bounds().Max.Y - l.kbuf.Bounds().Min.Y)
	gc.Translate((l.Size.X-tw)/2, (l.Size.Y-th)/2)
	gc.DrawImage(l.kbuf)
}
Пример #7
0
func (g *Grid) draw(gc draw2d.GraphicContext) {
	gc.Clear()
	gc.SetFillColor(color.RGBA{150, 150, 150, 255})
	safeRect(gc, geom.Coord{0, 0}, g.Size)
	gc.FillStroke()

	g.reflex()

	_, minXs, _ := g.hflex.constrain(g.Size.X)
	for _, x := range minXs[1:] {
		gc.MoveTo(x, 0)
		gc.LineTo(x, g.Size.Y)

	}
	_, minYs, _ := g.vflex.constrain(g.Size.Y)
	for _, y := range minYs[1:] {
		gc.MoveTo(0, y)
		gc.LineTo(g.Size.X, y)

	}
	gc.Stroke()
	// _, _, maxYs := g.vflex.constrain(g.Size.Y)
}
Пример #8
0
func ClearPaint(gc draw2d.GraphicContext) {
	gc.Clear()
}
Пример #9
0
func (g *Grid) draw(gc draw2d.GraphicContext) {
	gc.Clear()
	gc.SetFillColor(color.RGBA{150, 150, 150, 255})
	safeRect(gc, geom.Coord{0, 0}, g.Size)
	gc.FillStroke()
}
Пример #10
0
func drawBackground(gc draw2d.GraphicContext) {
	gc.SetFillColor(color.RGBA{0xFF, 0xFF, 0xFF, 0xFF})
	gc.Clear()
}