示例#1
0
文件: drawing.go 项目: wiloe/walk
func createBitmap() *walk.Bitmap {
	bounds := walk.Rectangle{Width: 200, Height: 200}

	bmp, _ := walk.NewBitmap(bounds.Size())

	succeeded := false
	defer func() {
		if !succeeded {
			bmp.Dispose()
		}
	}()

	canvas, _ := walk.NewCanvasFromImage(bmp)
	defer canvas.Dispose()

	brushBmp, _ := walk.NewBitmapFromFile("../img/plus.png")
	defer brushBmp.Dispose()

	brush, _ := walk.NewBitmapBrush(brushBmp)
	defer brush.Dispose()

	canvas.FillRectangle(brush, bounds)

	font, _ := walk.NewFont("Times New Roman", 40, walk.FontBold|walk.FontItalic)
	defer font.Dispose()

	canvas.DrawText("Walk Drawing Example", font, walk.RGB(0, 0, 0), bounds, walk.TextWordbreak)

	succeeded = true
	return bmp
}
示例#2
0
文件: imageviewer.go 项目: wiloe/walk
func main() {
	walk.Initialize(walk.InitParams{PanicOnError: true})
	defer walk.Shutdown()

	mainWnd, _ := walk.NewMainWindow()

	mw := &MainWindow{MainWindow: mainWnd}
	mw.SetLayout(walk.NewVBoxLayout())
	mw.SetTitle("Walk Image Viewer Example")

	mw.tabWidget, _ = walk.NewTabWidget(mw)

	imageList, _ := walk.NewImageList(walk.Size{16, 16}, 0)
	mw.ToolBar().SetImageList(imageList)

	fileMenu, _ := walk.NewMenu()
	fileMenuAction, _ := mw.Menu().Actions().AddMenu(fileMenu)
	fileMenuAction.SetText("&File")

	openBmp, _ := walk.NewBitmapFromFile("../img/open.png")

	openAction := walk.NewAction()
	openAction.SetImage(openBmp)
	openAction.SetText("&Open")
	openAction.Triggered().Attach(func() { mw.openImage() })
	fileMenu.Actions().Add(openAction)
	mw.ToolBar().Actions().Add(openAction)

	exitAction := walk.NewAction()
	exitAction.SetText("E&xit")
	exitAction.Triggered().Attach(func() { walk.App().Exit(0) })
	fileMenu.Actions().Add(exitAction)

	helpMenu, _ := walk.NewMenu()
	helpMenuAction, _ := mw.Menu().Actions().AddMenu(helpMenu)
	helpMenuAction.SetText("&Help")

	aboutAction := walk.NewAction()
	aboutAction.SetText("&About")
	aboutAction.Triggered().Attach(func() {
		walk.MsgBox(mw, "About", "Walk Image Viewer Example", walk.MsgBoxOK|walk.MsgBoxIconInformation)
	})
	helpMenu.Actions().Add(aboutAction)

	mw.SetMinMaxSize(walk.Size{320, 240}, walk.Size{})
	mw.SetSize(walk.Size{800, 600})
	mw.Show()

	mw.Run()
}