tcell_ebiten

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: MIT Imports: 10 Imported by: 0

README

tcell Screen wrapper for ebiten

Easily add text components to your Ebiten game, leveraging the tcell library and its add-ons.

This library provides a ebiten/v2.Game interface that can be used as the entirety of the game loop for ebiten, or a sub-panel.

Usage

Convert tcell Application to ebiten Application

In your tcell program, add the following imports:

import (
    "github.com/ezrec/tcell_ebiten"
    "github.com/hajimehoshi/bitmapfont/v3"
    "github.com/hajimehoshi/ebiten/v2"
    "github.com/hajimehoshi/ebiten/v2/text/v2"
)

|  // Define a nominal window size.
|  const window_width = 640
|  const window_height = 480

func main() {
    app := &views.Application{}
    window = ... // your existing tcell program here..
    app.SetRootWidget(window)

|  // Define our ebiten window size, and enable resizes.
|  ebiten.SetWindowSize(window_width, window_height)
|  ebiten.SetWindowTitle("hbox demo")
|  ebiten.SetWindowResizeable(true)
|
|  // Select an ebiten/v2/text/v2 font to use. The letter 'O'
|  // from the font face is used to determine the nominal font cell.
|
|  var font_face text.Face
|  font_face = text.NewGoXFace(bitmapfont.Face)
|
|  // Create a proxy between the ebiten and tcell engines.
|  gs := tcell_ebiten.NewGameScreen(font_face)
|  gs.Init()
|  defer gs.Fini()
|
|  go func () {
|      app.SetScreen(gs)
       e := app.Run()
|      gs.Close()
       if e != nil {
          fmt.Fprintln(os.Stderr, e.Error())
          os.Exit(1)
       }
|  }
|  ebiten.RunGame(gs)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GameScreen

type GameScreen interface {
	tcell.Screen
	ebiten.Game

	// LayoutF supports High-DPI monitor situations.
	LayoutF(width, height float64) (screen_width, screen_height float64)

	// Close will cause ebiten.Run() to exit on the next Update()
	Close() error

	// SetHighDPI enables high-DPI mode (disable Ebiten automatic upscaling)
	SetHighDPI(enable bool)

	// SetCursorColor changes the color of the text 'hardware' cursor.
	SetCursorColor(color tcell.Color)

	// SetMouseCapture sets the ebiten image area where mouse events are captured.
	// If game is Empty, the entire ebiten game area's mouse events are captured.
	// If screen not Empty, game coordinates are mapped to screen cell coordinates.
	SetMouseCapture(game image.Rectangle, screen image.Rectangle)

	// SetKeyCapture sets the ebiten image area where key events are captured.
	// Default is all key events.
	SetKeyCapture(game image.Rectangle)

	// SetInputCapture set the ebiten image area where all input events are captured.
	// Default is all input events.
	// If game is Empty, the entire ebiten game area's events are captured.
	// If screen not Empty, game coordinates are mapped to screen cell coordinates.
	SetInputCapture(rect image.Rectangle, screen image.Rectangle)
}

GameScreen combines the interface of tcell.Screen and a ebiten.Game handler.

We are exceedingly lucky that tcell.Screen and ebiten.Game have no overlapping interfaces!

func NewGameScreen

func NewGameScreen(font_face text.Face) GameScreen

NewGameScreen creates a new GameScreen, suitable for both ebiten and tcell.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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