Exemple #1
0
// mixin.List overrides
func (l *List) Paint(c gxui.Canvas) {
	l.List.Paint(c)
	if l.HasFocus() {
		r := l.Size().Rect().ContractI(1)
		c.DrawRoundedRect(r, 3.0, 3.0, 3.0, 3.0, l.theme.FocusedStyle.Pen, l.theme.FocusedStyle.Brush)
	}
}
Exemple #2
0
// 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))
	}
}
Exemple #3
0
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))
}
Exemple #4
0
func (p *PanelHolder) Paint(c gxui.Canvas) {
	panel := p.SelectedPanel()
	if panel != nil {
		bounds := p.Children().Find(panel).Bounds()
		c.DrawRoundedRect(bounds, 0.0, 0.0, 3.0, 3.0, p.theme.PanelBackgroundStyle.Pen, p.theme.PanelBackgroundStyle.Brush)
	}
	p.PanelHolder.Paint(c)
}
Exemple #5
0
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()
}
Exemple #6
0
// mixins.CodeEditor overrides
func (t *CodeEditor) Paint(c gxui.Canvas) {
	t.CodeEditor.Paint(c)

	if t.HasFocus() {
		r := t.Size().Rect()
		c.DrawRoundedRect(r, 3, 3, 3, 3, t.theme.FocusedStyle.Pen, t.theme.FocusedStyle.Brush)
	}
}
Exemple #7
0
// mixins.TextBox overrides
func (t *TextBox) Paint(c gxui.Canvas) {
	t.TextBox.Paint(c)

	if t.HasFocus() {
		r := t.Size().Rect()
		s := t.theme.FocusedStyle
		c.DrawRoundedRect(r, 3, 3, 3, 3, s.Pen, s.Brush)
	}
}
Exemple #8
0
func (i *Image) SetCanvas(canvas gxui.Canvas) {
	if !canvas.IsComplete() {
		panic("SetCanvas() called with an incomplete canvas")
	}

	if i.canvas != canvas {
		i.canvas = canvas
		i.texture = nil
		i.outer.Relayout()
	}
}
Exemple #9
0
func (i *Image) Paint(c gxui.Canvas) {
	r := i.outer.Size().Rect()
	i.PaintBackground(c, r)
	switch {
	case i.texture != nil:
		c.DrawTexture(i.texture, i.calculateDrawRect())
	case i.canvas != nil:
		c.DrawCanvas(i.canvas, math.ZeroPoint)
	}
	i.PaintBorder(c, r)
}
Exemple #10
0
func (t *DefaultTextBoxLine) PaintText(c gxui.Canvas) {
	runes := []rune(t.textbox.controller.Line(t.lineIndex))
	f := t.textbox.font
	offsets := f.Layout(&gxui.TextBlock{
		Runes:     runes,
		AlignRect: t.Size().Rect().OffsetX(t.caretWidth),
		H:         gxui.AlignLeft,
		V:         gxui.AlignBottom,
	})
	c.DrawRunes(f, runes, offsets, t.textbox.textColor)
}
Exemple #11
0
func (t *CodeEditorLine) PaintBorders(c gxui.Canvas, info CodeEditorLinePaintInfo) {
	start, _ := info.LineSpan.Span()
	offsets := info.GlyphOffsets
	for _, l := range t.ce.layers {
		if l != nil && l.BorderColor() != nil {
			color := *l.BorderColor()
			interval.Visit(l.Spans(), info.LineSpan, func(vs, ve uint64, _ int) {
				s, e := vs-start, ve-start
				r := math.CreateRect(offsets[s].X, 0, offsets[e-1].X+info.GlyphWidth, info.LineHeight)
				c.DrawRoundedRect(r, 3, 3, 3, 3, gxui.CreatePen(0.5, color), gxui.TransparentBrush)
			})
		}
	}
}
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))
}
Exemple #13
0
// parts.DrawPaint overrides
func (l *Label) Paint(c gxui.Canvas) {
	r := l.outer.Size().Rect()
	t := l.text
	if !l.multiline {
		t = strings.Replace(t, "\n", " ", -1)
	}

	runes := []rune(t)
	offsets := l.font.Layout(&gxui.TextBlock{
		Runes:     runes,
		AlignRect: r,
		H:         l.horizontalAlignment,
		V:         l.verticalAlignment,
	})
	c.DrawRunes(l.font, runes, offsets, l.color)
}
Exemple #14
0
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))
}
Exemple #15
0
func (t *CodeEditorLine) PaintBackgroundSpans(c gxui.Canvas, info CodeEditorLinePaintInfo) {
	start, _ := info.LineSpan.Span()
	offsets := info.GlyphOffsets
	remaining := interval.IntDataList{info.LineSpan}
	for _, l := range t.ce.layers {
		if l != nil && l.BackgroundColor() != nil {
			color := *l.BackgroundColor()
			for _, span := range l.Spans().Overlaps(info.LineSpan) {
				interval.Visit(&remaining, span, func(vs, ve uint64, _ int) {
					s, e := vs-start, ve-start
					r := math.CreateRect(offsets[s].X, 0, offsets[e-1].X+info.GlyphWidth, info.LineHeight)
					c.DrawRoundedRect(r, 3, 3, 3, 3, gxui.TransparentPen, gxui.Brush{Color: color})
				})
				interval.Remove(&remaining, span)
			}
		}
	}
}
Exemple #16
0
func drawTimeAxis(canvas gxui.Canvas) {
	p := gxui.Polygon{
		gxui.PolygonVertex{
			Position: math.Point{
				X: 0,
				Y: 400,
			},
			RoundedRadius: 0,
		},
		gxui.PolygonVertex{
			Position: math.Point{
				X: 400,
				Y: 400,
			},
			RoundedRadius: 0,
		},
	}

	canvas.DrawLines(p, gxui.CreatePen(1.0, gxui.White))
}
Exemple #17
0
func (t *PanelTab) Paint(c gxui.Canvas) {
	s := t.Size()
	var style Style
	switch {
	case t.IsMouseDown(gxui.MouseButtonLeft) && t.IsMouseOver():
		style = t.theme.TabPressedStyle
	case t.IsMouseOver():
		style = t.theme.TabOverStyle
	default:
		style = t.theme.TabDefaultStyle
	}
	if l := t.Label(); l != nil {
		l.SetColor(style.FontColor)
	}

	c.DrawRoundedRect(s.Rect(), 5.0, 5.0, 0.0, 0.0, style.Pen, style.Brush)

	if t.HasFocus() {
		style = t.theme.FocusedStyle
		r := math.CreateRect(1, 1, s.W-1, s.H-1)
		c.DrawRoundedRect(r, 4.0, 4.0, 0.0, 0.0, style.Pen, style.Brush)
	}

	if t.active {
		style = t.theme.TabActiveHighlightStyle
		r := math.CreateRect(1, s.H-1, s.W-1, s.H)
		c.DrawRect(r, style.Brush)
	}

	t.Button.Paint(c)
}
Exemple #18
0
func (t *CodeEditorLine) PaintGlyphs(c gxui.Canvas, info CodeEditorLinePaintInfo) {
	start, _ := info.LineSpan.Span()
	runes, offsets, font := info.Runes, info.GlyphOffsets, info.Font
	remaining := interval.IntDataList{info.LineSpan}
	for _, l := range t.ce.layers {
		if l != nil && l.Color() != nil {
			color := *l.Color()
			for _, span := range l.Spans().Overlaps(info.LineSpan) {
				interval.Visit(&remaining, span, func(vs, ve uint64, _ int) {
					s, e := vs-start, ve-start
					c.DrawRunes(font, runes[s:e], offsets[s:e], color)
				})
				interval.Remove(&remaining, span)
			}
		}
	}
	for _, span := range remaining {
		s, e := span.Span()
		s, e = s-start, e-start
		c.DrawRunes(font, runes[s:e], offsets[s:e], t.ce.textColor)
	}
}
Exemple #19
0
func (f Field) drawHorizontalLines(canvas gxui.Canvas) {
	for y := f.cellHeight; y < f.height; y += f.cellHeight {
		p := make(gxui.Polygon, 2)

		p[0] = gxui.PolygonVertex{
			Position: math.Point{
				X: 0,
				Y: y,
			},
			RoundedRadius: 0,
		}

		p[1] = gxui.PolygonVertex{
			Position: math.Point{
				X: f.width,
				Y: y,
			},
			RoundedRadius: 0,
		}

		canvas.DrawLines(p, gxui.CreatePen(1, gxui.Gray80))
	}
}
Exemple #20
0
func (f Field) drawVerticalLines(canvas gxui.Canvas) {
	for x := f.cellWidth; x < f.width; x += f.cellWidth {
		p := make(gxui.Polygon, 2)

		p[0] = gxui.PolygonVertex{
			Position: math.Point{
				X: x,
				Y: 0,
			},
			RoundedRadius: 0,
		}

		p[1] = gxui.PolygonVertex{
			Position: math.Point{
				X: x,
				Y: f.height,
			},
			RoundedRadius: 0,
		}

		canvas.DrawLines(p, gxui.CreatePen(1, gxui.Gray80))
	}
}
Exemple #21
0
func (s Snake) Draw(canvas gxui.Canvas) {
	bendCount := len(s.bends)
	p := make(gxui.Polygon, 2+bendCount)

	p[0] = gxui.PolygonVertex{
		Position:      s.head,
		RoundedRadius: 0,
	}

	for i, bend := range s.bends {
		p[i+1] = gxui.PolygonVertex{
			Position:      bend.point,
			RoundedRadius: 0,
		}
	}

	p[bendCount+1] = gxui.PolygonVertex{
		Position:      s.tail,
		RoundedRadius: 0,
	}

	canvas.DrawLines(p, gxui.CreatePen(float32(s.width), gxui.Green70))
}
Exemple #22
0
func (p *PaintChildren) Paint(c gxui.Canvas) {
	for i, v := range p.outer.Children() {
		if v.Control.IsVisible() {
			c.Push()
			c.AddClip(v.Control.Size().Rect().Offset(v.Offset))
			p.outer.PaintChild(c, v, i)
			c.Pop()
		}
	}
}
Exemple #23
0
// Button internal overrides
func (b *Button) Paint(c gxui.Canvas) {
	pen := b.Button.BorderPen()
	brush := b.Button.BackgroundBrush()
	fontColor := b.theme.ButtonDefaultStyle.FontColor

	switch {
	case b.IsMouseDown(gxui.MouseButtonLeft) && b.IsMouseOver():
		pen = b.theme.ButtonPressedStyle.Pen
		brush = b.theme.ButtonPressedStyle.Brush
		fontColor = b.theme.ButtonPressedStyle.FontColor
	case b.IsMouseOver():
		pen = b.theme.ButtonOverStyle.Pen
		brush = b.theme.ButtonOverStyle.Brush
		fontColor = b.theme.ButtonOverStyle.FontColor
	}

	if l := b.Label(); l != nil {
		l.SetColor(fontColor)
	}

	r := b.Size().Rect()

	c.DrawRoundedRect(r, 2, 2, 2, 2, gxui.TransparentPen, brush)

	b.PaintChildren.Paint(c)

	c.DrawRoundedRect(r, 2, 2, 2, 2, pen, gxui.TransparentBrush)

	if b.IsChecked() {
		pen = b.theme.HighlightStyle.Pen
		brush = b.theme.HighlightStyle.Brush
		c.DrawRoundedRect(r, 2.0, 2.0, 2.0, 2.0, pen, brush)
	}

	if b.HasFocus() {
		pen = b.theme.FocusedStyle.Pen
		brush = b.theme.FocusedStyle.Brush
		c.DrawRoundedRect(r.ContractI(int(pen.Width)), 3.0, 3.0, 3.0, 3.0, pen, brush)
	}
}
Exemple #24
0
func (s *ScrollBar) Paint(c gxui.Canvas) {
	c.DrawRoundedRect(s.outer.Size().Rect(), 3, 3, 3, 3, s.railPen, s.railBrush)
	c.DrawRoundedRect(s.barRect, 3, 3, 3, 3, s.barPen, s.barBrush)
}
Exemple #25
0
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))
}
Exemple #26
0
func (l *List) PaintSelection(c gxui.Canvas, r math.Rect) {
	c.DrawRoundedRect(r, 2.0, 2.0, 2.0, 2.0, gxui.WhitePen, gxui.TransparentBrush)
}
Exemple #27
0
func (o *BubbleOverlay) Paint(c gxui.Canvas) {
	if !o.IsVisible() {
		return
	}
	for _, child := range o.outer.Children() {
		b := child.Bounds().Expand(o.outer.Padding())
		t := o.targetPoint
		a := o.arrowWidth / 2
		var p gxui.Polygon

		switch {
		case t.X < b.Min.X:
			/*
			    A-----------------B
			    G                 |
			 F                    |
			    E                 |
			    D-----------------C
			*/
			p = gxui.Polygon{
				/*A*/ {Position: b.TL(), RoundedRadius: 5},
				/*B*/ {Position: b.TR(), RoundedRadius: 5},
				/*C*/ {Position: b.BR(), RoundedRadius: 5},
				/*D*/ {Position: b.BL(), RoundedRadius: 5},
				/*E*/ {Position: math.Point{X: b.Min.X, Y: math.Clamp(t.Y+a, b.Min.Y+a, b.Max.Y)}, RoundedRadius: 0},
				/*F*/ {Position: t, RoundedRadius: 0},
				/*G*/ {Position: math.Point{X: b.Min.X, Y: math.Clamp(t.Y-a, b.Min.Y, b.Max.Y-a)}, RoundedRadius: 0},
			}
			// fmt.Printf("A: %+v\n", p)
		case t.X > b.Max.X:
			/*
			   A-----------------B
			   |                 C
			   |                    D
			   |                 E
			   G-----------------F
			*/
			p = gxui.Polygon{
				/*A*/ {Position: b.TL(), RoundedRadius: 5},
				/*B*/ {Position: b.TR(), RoundedRadius: 5},
				/*C*/ {Position: math.Point{X: b.Max.X, Y: math.Clamp(t.Y-a, b.Min.Y, b.Max.Y-a)}, RoundedRadius: 0},
				/*D*/ {Position: t, RoundedRadius: 0},
				/*E*/ {Position: math.Point{X: b.Max.X, Y: math.Clamp(t.Y+a, b.Min.Y+a, b.Max.Y)}, RoundedRadius: 0},
				/*F*/ {Position: b.BR(), RoundedRadius: 5},
				/*G*/ {Position: b.BL(), RoundedRadius: 5},
			}
			// fmt.Printf("B: %+v\n", p)
		case t.Y < b.Min.Y:
			/*
			                 C
			                / \
			   A-----------B   D-E
			   |                 |
			   |                 |
			   G-----------------F
			*/
			p = gxui.Polygon{
				/*A*/ {Position: b.TL(), RoundedRadius: 5},
				/*B*/ {Position: math.Point{X: math.Clamp(t.X-a, b.Min.X, b.Max.X-a), Y: b.Min.Y}, RoundedRadius: 0},
				/*C*/ {Position: t, RoundedRadius: 0},
				/*D*/ {Position: math.Point{X: math.Clamp(t.X+a, b.Min.X+a, b.Max.X), Y: b.Min.Y}, RoundedRadius: 0},
				/*E*/ {Position: b.TR(), RoundedRadius: 5},
				/*F*/ {Position: b.BR(), RoundedRadius: 5},
				/*G*/ {Position: b.BL(), RoundedRadius: 5},
			}
			// fmt.Printf("C: %+v\n", p)
		default:
			/*
			   A-----------------B
			   |                 |
			   |                 |
			   G-----------F   D-C
			                \ /
			                 E
			*/
			p = gxui.Polygon{
				/*A*/ {Position: b.TL(), RoundedRadius: 5},
				/*B*/ {Position: b.TR(), RoundedRadius: 5},
				/*C*/ {Position: b.BR(), RoundedRadius: 5},
				/*D*/ {Position: math.Point{X: math.Clamp(t.X+a, b.Min.X+a, b.Max.X), Y: b.Max.Y}, RoundedRadius: 0},
				/*E*/ {Position: t, RoundedRadius: 0},
				/*F*/ {Position: math.Point{X: math.Clamp(t.X-a, b.Min.X, b.Max.X-a), Y: b.Max.Y}, RoundedRadius: 0},
				/*G*/ {Position: b.BL(), RoundedRadius: 5},
			}
			// fmt.Printf("D: %+v\n", p)
		}
		c.DrawPolygon(p, o.pen, o.brush)
	}
	o.PaintChildren.Paint(c)
}
Exemple #28
0
func (l *List) PaintSelection(c gxui.Canvas, r math.Rect) {
	c.DrawRoundedRect(r, 2.0, 2.0, 2.0, 2.0, l.theme.HighlightStyle.Pen, l.theme.HighlightStyle.Brush)
}
Exemple #29
0
func (t *Tree) PaintUnexpandedSelection(c gxui.Canvas, r math.Rect) {
	c.DrawRoundedRect(r, 2.0, 2.0, 2.0, 2.0, gxui.CreatePen(1, gxui.Gray50), gxui.TransparentBrush)
}
func (b *BackgroundBorderPainter) PaintBorder(c gxui.Canvas, r math.Rect) {
	if b.pen.Color.A != 0 && b.pen.Width != 0 {
		w := b.pen.Width
		c.DrawRoundedRect(r, w, w, w, w, b.pen, gxui.TransparentBrush)
	}
}