Ejemplo n.º 1
0
Archivo: main.go Proyecto: langxj/gxui
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
}
Ejemplo n.º 2
0
func (b *blitter) blitGlyph(ctx *context, tc *textureContext, c gxui.Color, srcRect, dstRect math.Rect, ds *drawState) {
	dstRect = dstRect.Offset(ds.OriginPixels)

	if b.glyphBatch.GlyphPage != tc {
		b.commitGlyphs(ctx)
		b.glyphBatch.GlyphPage = tc
	}
	i := uint16(len(b.glyphBatch.DstRects)) / 2
	clip := []float32{
		float32(ds.ClipPixels.Min.X),
		float32(ds.ClipPixels.Min.Y),
		float32(ds.ClipPixels.Max.X),
		float32(ds.ClipPixels.Max.Y),
	}
	b.glyphBatch.DstRects = append(b.glyphBatch.DstRects,
		float32(dstRect.Min.X), float32(dstRect.Min.Y),
		float32(dstRect.Max.X), float32(dstRect.Min.Y),
		float32(dstRect.Min.X), float32(dstRect.Max.Y),
		float32(dstRect.Max.X), float32(dstRect.Max.Y),
	)
	b.glyphBatch.SrcRects = append(b.glyphBatch.SrcRects,
		float32(srcRect.Min.X), float32(srcRect.Min.Y),
		float32(srcRect.Max.X), float32(srcRect.Min.Y),
		float32(srcRect.Min.X), float32(srcRect.Max.Y),
		float32(srcRect.Max.X), float32(srcRect.Max.Y),
	)
	b.glyphBatch.ClipRects = append(b.glyphBatch.ClipRects,
		clip[0], clip[1], clip[2], clip[3],
		clip[0], clip[1], clip[2], clip[3],
		clip[0], clip[1], clip[2], clip[3],
		clip[0], clip[1], clip[2], clip[3],
	)

	c = c.MulRGB(c.A) // PMA
	b.glyphBatch.Colors = append(b.glyphBatch.Colors,
		c.R, c.G, c.B, c.A,
		c.R, c.G, c.B, c.A,
		c.R, c.G, c.B, c.A,
		c.R, c.G, c.B, c.A,
	)
	b.glyphBatch.Indices = append(b.glyphBatch.Indices,
		i, i+1, i+2,
		i+2, i+1, i+3,
	)
}