2015-07-10 00:14:03 +00:00
|
|
|
// Copyright 2010 The draw2d Authors. All rights reserved.
|
|
|
|
// created: 21/11/2010 by Laurent Le Goff, Stani Michiels
|
|
|
|
|
2015-07-10 19:50:07 +00:00
|
|
|
// Package helloworld displays multiple "Hello World" (one rotated)
|
|
|
|
// in a rounded rectangle.
|
2015-07-10 00:14:03 +00:00
|
|
|
package helloworld
|
|
|
|
|
|
|
|
import (
|
2015-07-10 19:50:07 +00:00
|
|
|
"fmt"
|
2015-07-10 00:14:03 +00:00
|
|
|
"image"
|
|
|
|
"image/color"
|
|
|
|
"math"
|
|
|
|
|
2016-12-13 14:35:47 +00:00
|
|
|
"gopkg.in/llgcode/draw2d.v1"
|
|
|
|
"gopkg.in/llgcode/draw2d.v1/samples"
|
2015-07-10 00:14:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Main draws "Hello World" and returns the filename. This should only be
|
|
|
|
// used during testing.
|
|
|
|
func Main(gc draw2d.GraphicContext, ext string) (string, error) {
|
|
|
|
// Draw hello world
|
2015-07-10 19:50:07 +00:00
|
|
|
Draw(gc, fmt.Sprintf("Hello World %d dpi", gc.GetDPI()))
|
2015-07-10 00:14:03 +00:00
|
|
|
|
|
|
|
// Return the output filename
|
|
|
|
return samples.Output("helloworld", ext), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw "Hello World"
|
2015-07-10 19:50:07 +00:00
|
|
|
func Draw(gc draw2d.GraphicContext, text string) {
|
2015-07-10 00:14:03 +00:00
|
|
|
// Draw a rounded rectangle using default colors
|
|
|
|
draw2d.RoundRect(gc, 5, 5, 292, 205, 10, 10)
|
|
|
|
gc.FillStroke()
|
|
|
|
|
|
|
|
// Set the font luximbi.ttf
|
|
|
|
gc.SetFontData(draw2d.FontData{
|
|
|
|
Name: "luxi",
|
|
|
|
Family: draw2d.FontFamilyMono,
|
|
|
|
Style: draw2d.FontStyleBold | draw2d.FontStyleItalic})
|
|
|
|
// Set the fill text color to black
|
|
|
|
gc.SetFillColor(image.Black)
|
|
|
|
gc.SetDPI(72)
|
|
|
|
gc.SetFontSize(14)
|
|
|
|
// Display Hello World
|
2015-07-12 18:47:35 +00:00
|
|
|
gc.SetStrokeColor(color.NRGBA{0x33, 0xFF, 0x33, 0xFF})
|
|
|
|
gc.MoveTo(8, 0)
|
|
|
|
gc.LineTo(8, 52)
|
|
|
|
gc.LineTo(297, 52)
|
|
|
|
gc.Stroke()
|
2015-07-10 19:50:07 +00:00
|
|
|
gc.FillString(text)
|
|
|
|
gc.FillStringAt(text, 8, 52)
|
2015-07-10 00:14:03 +00:00
|
|
|
|
|
|
|
gc.Save()
|
|
|
|
gc.SetFillColor(color.NRGBA{0xFF, 0x33, 0x33, 0xFF})
|
2015-07-12 00:34:34 +00:00
|
|
|
gc.SetStrokeColor(color.NRGBA{0xFF, 0x33, 0x33, 0xFF})
|
2015-07-10 19:50:07 +00:00
|
|
|
gc.Translate(145, 85)
|
|
|
|
gc.StrokeStringAt(text, -50, 0)
|
2015-07-10 00:14:03 +00:00
|
|
|
gc.Rotate(math.Pi / 4)
|
2015-07-10 19:50:07 +00:00
|
|
|
gc.SetFillColor(color.NRGBA{0x33, 0x33, 0xFF, 0xFF})
|
2015-07-12 00:34:34 +00:00
|
|
|
gc.SetStrokeColor(color.NRGBA{0x33, 0x33, 0xFF, 0xFF})
|
2015-07-10 19:50:07 +00:00
|
|
|
gc.StrokeString(text)
|
2015-07-10 00:14:03 +00:00
|
|
|
gc.Restore()
|
|
|
|
}
|