Esempio n. 1
0
func (iv *ImageView) drawImage(surface *drawing.Surface, updateBounds drawing.Rectangle) os.Error {
	if iv.image == nil {
		return nil
	}

	bounds, err := iv.ClientBounds()
	if err != nil {
		return err
	}

	return surface.DrawImageStretched(iv.image, bounds)
}
Esempio n. 2
0
func (mw *MainWindow) drawStuff(surface *drawing.Surface, updateBounds drawing.Rectangle) os.Error {
	bmp := createBitmap()
	defer bmp.Dispose()

	bounds, err := mw.paintWidget.ClientBounds()
	panicIfErr(err)

	rectPen, err := drawing.NewCosmeticPen(drawing.PenSolid, drawing.RGB(255, 0, 0))
	panicIfErr(err)
	defer rectPen.Dispose()

	panicIfErr(surface.DrawRectangle(rectPen, bounds))

	ellipseBrush, err := drawing.NewHatchBrush(drawing.RGB(0, 255, 0), drawing.HatchCross)
	panicIfErr(err)
	defer ellipseBrush.Dispose()

	panicIfErr(surface.FillEllipse(ellipseBrush, bounds))

	linesBrush, err := drawing.NewSolidColorBrush(drawing.RGB(0, 0, 255))
	panicIfErr(err)
	defer linesBrush.Dispose()

	linesPen, err := drawing.NewGeometricPen(drawing.PenDash, 8, linesBrush)
	panicIfErr(err)
	defer linesPen.Dispose()

	panicIfErr(surface.DrawLine(linesPen, drawing.Point{bounds.X, bounds.Y}, drawing.Point{bounds.Width, bounds.Height}))
	panicIfErr(surface.DrawLine(linesPen, drawing.Point{bounds.X, bounds.Height}, drawing.Point{bounds.Width, bounds.Y}))

	bmpSize := bmp.Size()
	panicIfErr(surface.DrawImage(bmp, drawing.Point{bounds.Width/2 - bmpSize.Width/2, bounds.Height/2 - bmpSize.Height/2}))

	return nil
}
Esempio n. 3
0
func (item *simpleTextItem) AddNewPart(surface *drawing.Surface, bounds drawing.Rectangle) (part part, more bool, err os.Error) {
	partCount := len(item.parts)
	var offset int
	if partCount > 0 {
		prevPart := item.parts[len(item.parts)-1]
		offset = prevPart.offset + prevPart.length
	}

	runeCount := item.text.RuneCount()
	text := item.text.Slice(offset, runeCount)

	fontHeight, err := surface.FontHeight(item.font)
	if err != nil {
		return
	}

	bounds.Height = (bounds.Height / fontHeight) * fontHeight
	if bounds.Height == 0 {
		more = true
		return
	}

	boundsMeasured, runesFitted, err := surface.MeasureText(text, item.font, bounds, item.format)
	if err != nil {
		return
	}

	p := &simpleTextPart{
		item:   item,
		offset: offset,
		length: runesFitted,
		bounds: boundsMeasured,
	}

	if partCount == cap(item.parts) {
		parts := make([]*simpleTextPart, partCount, partCount*2)
		copy(parts, item.parts)
		item.parts = parts
	}

	item.parts = item.parts[0 : partCount+1]
	item.parts[partCount] = p

	part = p
	more = p.offset+p.length < runeCount

	return
}
Esempio n. 4
0
func (part *simpleTextPart) Draw(surface *drawing.Surface) os.Error {
	item := part.item
	text := item.text.Slice(part.offset, part.offset+part.length)

	return surface.DrawText(text, item.font, item.color, part.bounds, item.format)
}