goui

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2021 License: BSD-3-Clause Imports: 7 Imported by: 2

README

Go-ui

go-ui is a game builder lite using SDL2 veandco. It's not convention to compose a game, just proof of concept today.

The wrapper is implemented with goroutines.

I try to define a good architecture and simple of use. Inspired by Unity 3D (without interface home machine). I try to provide a good tool to creates models scenes / layout and objects.

I would be pleased to talk about that with you on mail: mohl.clauzade@gmail.com

Requirements

See official github to SDL2 binding for Go by veandco.

Installation

To install Golang see getting started

To get SDL2 wrapper see veandco

go get -v github.com/veandco/go-sdl2/{sdl,mix,img,ttf}

To get go-ui:

go get -v github.com/ymohl-cl/go-ui

OSX

Install SDL2:

brew install sdl2 sdl2_gfx sdl2_image sdl2_mixer sdl2_net sdl2_ttf

Example

You can view implementation example on this project gomoku game

Please, read godoc to know the specifications

package main

import (
	"github.com/ymohl-cl/go-ui/drivers"
	"github.com/ymohl-cl/go-ui/scripter"
	"github.com/ymohl-cl/gomoku/database"
	"github.com/ymohl-cl/gomoku/scenes/gomoku"
	"github.com/ymohl-cl/gomoku/scenes/loader"
	"github.com/ymohl-cl/gomoku/scenes/menu"
)

const (
	windowWidth = 800
	windowHeight = 600

	indexMenu = 1 << iota
	indexGomoku
)

func main() {
	var err error
	var d drivers.VSDL
	var data *database.Data

	// init drivers sdl from go-ui
	if d, err = drivers.Init(windowWidth, windowHeight, "Title of my windows"); err != nil {
		panic(err)
	}
	defer d.Destroy()

	// get your data app from your package, for the example, we used database package
	if data, err = database.Get(); err != nil {
		panic(err)
	}

	// get new scripter application from go-ui
	s := scripter.New()

	// get loader scene from my app
	var loaderScene *loader.Load
	if loaderScene, err = loader.New(nil, d.GetRenderer()); err != nil {
		panic(err)
	}
	// add scene on the scripter (go-ui)
	if err = s.AddLoader(loaderScene); err != nil {
		panic(err)
	}

	// get menu scene from my app
	var menuScene *menu.Menu
	if menuScene, err = menu.New(data, d.GetRenderer()); err != nil {
		panic(err)
	}
	// add scene on the scripter (go-ui)
	if err = s.AddScene(menuScene, indexMenu, true); err != nil {
		panic(err)
	}

	// get gomoku scene from my app
	var gameScene *gomoku.Gomoku
	if gameScene, err = gomoku.New(data, d.GetRenderer()); err != nil {
		panic(err)
	}
	// add scene on the scripter (go-ui)
	if err = s.AddScene(gameScene, indexGomoku, false); err != nil {
		panic(err)
	}

	// run application from go-ui
	s.Run(d)
}

FAQ

Why shaders aren't implemented ?

go-ui is a proof of concept for the moment. This lib provide that which are needest to make a simple project. If you need shaders, please contact us.

How do I contribute ?

Contact me by mail: mohl.clauzade@gmail.com

Acknowledgment

Thanks at veandco for their work.

License

go-ui is BSD 3-clause licensed.

Version

V-0.1.1: implement library go-ui

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigUI

type ConfigUI struct {
	Window Window
}

ConfigUI about ui

type GoUI added in v1.0.0

type GoUI interface {
	Close() error
	Renderer() Renderer
	Run(scene Scene) error
	// contains filtered or unexported methods
}

GoUI make the relation between sdl2 driver and the application service. Provide an easy way to setup application's ui or game'ui

func New

func New(c ConfigUI) (GoUI, error)

New configure a new gamebuilder instance and setup a sdl driver ready to use

type Layer added in v1.0.0

type Layer uint8

type Renderer

type Renderer interface {
	Close()
	Clear() error
	Draw()
	Driver() *sdl.Renderer
}

Renderer type to manage the drawing

func NewRenderer

func NewRenderer(c ConfigUI) (Renderer, error)

NewRenderer sdl

type Scene

type Scene interface {
	AddWidget(w widget.Widget, l Layer)
	Render(r *sdl.Renderer)
	NewEvent(e sdl.Event) error
	Close()
}

Scene is a interface and define the design model to your scenes

func NewScene added in v1.0.0

func NewScene() (Scene, error)

NewScene return the default scene to store your widget on 32 layers. On browse widget, if a layers represent an empty widget list, the browse action stop

type Window

type Window struct {
	Title  string
	Width  int32
	Height int32
}

Window configuration

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL