ebimgui

package module
v3.0.10 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: MIT Imports: 9 Imported by: 0

README

Dear ImGui for Ebitengine

A renderer of cimgui-go for Ebitengine!

preview

Usage:

package main

import (
	"fmt"
	"image/color"

	"github.com/damntourists/ebiten-imgui/v3/imcolor"
	ebimgui "github.com/damntourists/ebiten-imgui/v3"
	"github.com/hajimehoshi/ebiten/v2"
	"github.com/hajimehoshi/ebiten/v2/ebitenutil"
	imgui "github.com/damntourists/cimgui-go"
)

func main() {
	gg := &G{
		name:       "Hello, Dear ImGui",
		clearColor: [3]float32{0,0,0},
	}

	ebiten.SetWindowSize(800, 600)
	ebiten.SetWindowTitle(gg.name)

	ebiten.RunGame(gg)
}

type G struct {
	clearColor [3]float32
	floatVal   float32
	counter    int
	name       string
}

func (g *G) Draw(screen *ebiten.Image) {
	screen.Fill(color.RGBA{uint8(g.clearColor[0] * 255), uint8(g.clearColor[1] * 255), uint8(g.clearColor[2] * 255), 255})
	ebitenutil.DebugPrint(screen, fmt.Sprintf("TPS: %.2f", ebiten.CurrentTPS()))
	ebimgui.Draw(screen)
}

func InputText(label string, buf *string) bool {
	return imgui.InputTextWithHint(label, "", buf, 0, nil)
}

func (g *G) Update() error {
	ebimgui.Update(1.0 / 60.0)
	ebimgui.BeginFrame()
	defer ebimgui.EndFrame()

	imgui.Text("ภาษาไทย测试조선말")                        // To display these, you'll need to register a compatible font
	imgui.Text("Hello, world!")                       // Display some text
	imgui.SliderFloat("float", &g.floatVal, 0.0, 1.0) // Edit 1 float using a slider from 0.0f to 1.0f
	imgui.ColorEdit3("clear color", &g.clearColor)     // Edit 3 floats representing a color

	//imgui.Checkbox("Demo Window", &showDemoWindow) // Edit bools storing our window open/close state
	//imgui.Checkbox("Go Demo Window", &showGoDemoWindow)
	//imgui.Checkbox("Another Window", &showAnotherWindow)

	if imgui.Button("Button") { // Buttons return true when clicked (most widgets return true when edited/activated)
		g.counter++
	}
	imgui.SameLine()
	imgui.Text(fmt.Sprintf("counter = %d", g.counter))

	if InputText("Window title", &g.name) {
		ebiten.SetWindowTitle(g.name)
	}

	xcol := imcolor.ToVec4(color.RGBA{
		R: 0xFF,
		G: 0x00,
		B: 0xFF,
		A: 0x99,
	})

	imgui.PushStyleColor_Vec4(imgui.ImGuiCol_Text, xcol)
	imgui.Text(fmt.Sprintf("fps = %f", ebiten.CurrentFPS()))
	imgui.PopStyleColor()
	return nil
}

func (g *G) Layout(outsideWidth, outsideHeight int) (int, int) {
	ebimgui.SetDisplaySize(float32(800), float32(600))
	return 800, 600
}

Documentation

Overview

Package ebimgui contains a renderer of ImGui for Ebitengine

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BeginFrame

func BeginFrame()

BeginFrame needs to be called on every frame, before cimgui-go calls. This is usually called inside the game's Update() function.

func ClipMask

func ClipMask() bool

ClipMask returns if clipmask is enabled or not.

func Draw

func Draw(screen *ebiten.Image)

Draw draws the generated imgui frame to the screen. This is usually called inside the game's Draw() function.

func EndFrame

func EndFrame()

EndFrame needs to be called on every frame, after cimgui-go calls. This is usually called inside the game's Update() function.

func Render

func Render(target *ebiten.Image, drawData *imgui.DrawData, txcache TextureCache, dfilter ebiten.Filter)

Render the ImGui drawData into the target *ebiten.Image

func RenderMasked

func RenderMasked(target *ebiten.Image, mask *ebiten.Image, drawData *imgui.DrawData, txcache TextureCache, dfilter ebiten.Filter)

RenderMasked renders the ImGui drawData into the target *ebiten.Image with ebiten.CompositeModeCopy for masking

func SetClipMask

func SetClipMask(value bool)

SetClipMask sets if clipmask is enabled or not. This is usually called for debugging purposes.

func SetDisplaySize

func SetDisplaySize(width, height float32)

SetDisplaySize sets the display size for imgui. This is usually called inside the game's Layout() function.

func Update

func Update(delta float32)

Update needs to be called on every frame, before cimgui-go calls. This is usually called inside the game's Update() function. delta is the time in seconds since the last frame.

Types

type GetCursorFn

type GetCursorFn func() (x, y float32)

type Manager

type Manager struct {
	Filter ebiten.Filter
	Cache  TextureCache

	GetCursor          GetCursorFn
	SyncInputsFn       func()
	SyncCursor         bool
	SyncInputs         bool
	ControlCursorShape bool

	ClipMask bool
	// contains filtered or unexported fields
}

func GlobalManager

func GlobalManager() *Manager

GlobalManager returns the global manager instance.

func NewManager

func NewManager(fontAtlas *imgui.FontAtlas) *Manager

func NewManagerWithContext

func NewManagerWithContext(ctx *imgui.Context) *Manager

func (*Manager) BeginFrame

func (m *Manager) BeginFrame()

func (*Manager) Draw

func (m *Manager) Draw(screen *ebiten.Image)

func (*Manager) EndFrame

func (m *Manager) EndFrame()

func (*Manager) SetDisplaySize

func (m *Manager) SetDisplaySize(width, height float32)

func (*Manager) SetText

func (m *Manager) SetText(text string)

SetText implements imgui clipboard

func (*Manager) Text

func (m *Manager) Text() (string, error)

Text implements imgui clipboard

func (*Manager) Update

func (m *Manager) Update(delta float32)

type TextureCache

type TextureCache interface {
	FontAtlasTextureID() imgui.TextureID
	SetFontAtlasTextureID(id imgui.TextureID)
	GetTexture(id imgui.TextureID) *ebiten.Image
	SetTexture(id imgui.TextureID, img *ebiten.Image)
	RemoveTexture(id imgui.TextureID)
	ResetFontAtlasCache(filter ebiten.Filter)
}

func NewCache

func NewCache() TextureCache

Directories

Path Synopsis
Package imcolor is a utility package to convert between color.Color and imgui.Vec4.
Package imcolor is a utility package to convert between color.Color and imgui.Vec4.
internal

Jump to

Keyboard shortcuts

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