Esempio n. 1
0
func createBitmap() *drawing.Bitmap {
	bounds := drawing.Rectangle{Width: 200, Height: 200}

	bmp, err := drawing.NewBitmap(bounds.Size())
	panicIfErr(err)

	surface, err := drawing.NewSurfaceFromImage(bmp)
	panicIfErr(err)
	defer surface.Dispose()

	brushBmp, err := drawing.NewBitmapFromFile("img/plus.png")
	panicIfErr(err)
	defer brushBmp.Dispose()

	brush, err := drawing.NewBitmapBrush(brushBmp)
	panicIfErr(err)
	defer brush.Dispose()

	panicIfErr(surface.FillRectangle(brush, bounds))

	font, err := drawing.NewFont("Times New Roman", 40, drawing.FontBold|drawing.FontItalic)
	panicIfErr(err)
	defer font.Dispose()

	panicIfErr(surface.DrawText("Runtime Created Bitmap", font, drawing.RGB(0, 0, 0), bounds, drawing.TextWordbreak))

	return bmp
}
Esempio n. 2
0
func runMainWindow() {
	mainWnd, err := gui.NewMainWindow()
	panicIfErr(err)
	defer mainWnd.Dispose()

	mw := &MainWindow{MainWindow: mainWnd}
	mw.ClientArea().SetLayout(gui.NewVBoxLayout())
	mw.updateTitle("")

	mw.imageView, err = gui.NewImageView(mw.ClientArea())
	panicIfErr(err)

	imageList, err := gui.NewImageList(drawing.Size{16, 16}, 0)
	panicIfErr(err)
	mw.ToolBar().SetImageList(imageList)

	fileMenu, err := gui.NewMenu()
	panicIfErr(err)
	_, fileMenuAction, err := mw.Menu().Actions().AddMenu(fileMenu)
	panicIfErr(err)
	fileMenuAction.SetText("File")

	openBmp, err := drawing.NewBitmapFromFile("img/open.png")
	panicIfErr(err)

	openAction := gui.NewAction()
	openAction.SetImage(openBmp)
	openAction.SetText("Open")
	openAction.AddTriggeredHandler(func(args gui.EventArgs) { mw.openImage() })
	fileMenu.Actions().Add(openAction)
	mw.ToolBar().Actions().Add(openAction)

	exitAction := gui.NewAction()
	exitAction.SetText("Exit")
	exitAction.AddTriggeredHandler(func(args gui.EventArgs) { gui.Exit(0) })
	fileMenu.Actions().Add(exitAction)

	helpMenu, err := gui.NewMenu()
	panicIfErr(err)
	_, helpMenuAction, err := mw.Menu().Actions().AddMenu(helpMenu)
	panicIfErr(err)
	helpMenuAction.SetText("Help")

	aboutAction := gui.NewAction()
	aboutAction.SetText("About")
	aboutAction.AddTriggeredHandler(func(args gui.EventArgs) {
		gui.MsgBox(mw, "About", "Walk Image Viewer Example", gui.MsgBoxOK|gui.MsgBoxIconInformation)
	})
	helpMenu.Actions().Add(aboutAction)

	panicIfErr(mw.SetMinSize(drawing.Size{320, 240}))
	panicIfErr(mw.SetSize(drawing.Size{800, 600}))
	mw.Show()

	panicIfErr(mw.RunMessageLoop())
}