draw2d/samples/helloworld/helloworld.go

41 lines
1.2 KiB
Go
Raw Normal View History

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"
2018-11-16 11:21:14 +00:00
"git.fromouter.space/crunchy-rocks/draw2d"
"git.fromouter.space/crunchy-rocks/draw2d/draw2dkit"
"git.fromouter.space/crunchy-rocks/draw2d/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
draw2dkit.RoundedRectangle(gc, 5, 5, 135, 95, 10, 10)
2015-07-10 00:14:03 +00:00
gc.FillStroke()
// Set the font luximbi.ttf
2015-08-14 20:38:18 +00:00
gc.SetFontData(draw2d.FontData{Name: "luxi", Family: draw2d.FontFamilyMono, Style: draw2d.FontStyleBold | draw2d.FontStyleItalic})
2015-07-10 00:14:03 +00:00
// Set the fill text color to black
gc.SetFillColor(image.Black)
gc.SetFontSize(14)
// Display Hello World
gc.FillStringAt("Hello World", 8, 52)
2015-07-10 00:14:03 +00:00
}