Exemplo n.º 1
0
Arquivo: utils.go Projeto: langxj/gxui
func ChildToParent(coord math.Point, from Control, to Parent) math.Point {
	c := from
	for {
		p := c.Parent()
		if p == nil {
			panic(fmt.Errorf("Control detached: %s", Path(c)))
		}
		child := p.Children().Find(c)
		if child == nil {
			Dump(p)
			panic(fmt.Errorf("Control's parent (%p %T) did not contain control (%p %T).", &p, p, &c, c))
		}
		coord = coord.Add(child.Offset)
		if p == to {
			return coord
		}

		if control, ok := p.(Control); ok {
			c = control
		} else {
			Dump(p)
			panic(fmt.Errorf("ChildToParent (%p %T) -> (%p %T) reached non-control parent (%p %T).",
				&from, from, &to, to, &p, p))
		}
	}
}
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))
}
Exemplo n.º 3
0
func (t *DefaultTextBoxLine) PaintCarets(c gxui.Canvas) {
	controller := t.textbox.controller
	for i, cnt := 0, controller.SelectionCount(); i < cnt; i++ {
		e := controller.Caret(i)
		l := controller.LineIndex(e)
		if l == t.lineIndex {
			s := controller.LineStart(l)
			m := t.outer.MeasureRunes(s, e)
			top := math.Point{X: t.caretWidth + m.W, Y: 0}
			bottom := top.Add(math.Point{X: 0, Y: t.Size().H})
			t.outer.PaintCaret(c, top, bottom)
		}
	}
}
Exemplo n.º 4
0
func (t *DefaultTextBoxLine) PaintSelections(c gxui.Canvas) {
	controller := t.textbox.controller

	ls, le := controller.LineStart(t.lineIndex), controller.LineEnd(t.lineIndex)

	selections := controller.Selections()
	if t.textbox.selectionDragging {
		interval.Replace(&selections, t.textbox.selectionDrag)
	}
	interval.Visit(&selections, gxui.CreateTextSelection(ls, le, false), func(s, e uint64, _ int) {
		if s < e {
			x := t.outer.MeasureRunes(ls, int(s)).W
			m := t.outer.MeasureRunes(int(s), int(e))
			top := math.Point{X: t.caretWidth + x, Y: 0}
			bottom := top.Add(m.Point())
			t.outer.PaintSelection(c, top, bottom)
		}
	})
}