mirror of
https://github.com/bloeys/gopad.git
synced 2025-12-29 06:58:21 +00:00
Init
This commit is contained in:
14
go.mod
Executable file
14
go.mod
Executable file
@ -0,0 +1,14 @@
|
||||
module github.com/bloeys/gopad
|
||||
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/bloeys/nmage v0.0.7-0.20220224025919-577e6250a8e5
|
||||
github.com/inkyblackness/imgui-go/v4 v4.3.0
|
||||
github.com/veandco/go-sdl2 v0.4.14
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/bloeys/gglm v0.3.1 // indirect
|
||||
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 // indirect
|
||||
)
|
||||
20
go.sum
Executable file
20
go.sum
Executable file
@ -0,0 +1,20 @@
|
||||
github.com/bloeys/assimp-go v0.4.2/go.mod h1:my3yRxT7CfOztmvi+0svmwbaqw0KFrxaHxncoyaEIP0=
|
||||
github.com/bloeys/gglm v0.3.1 h1:Sy9upW7SBsBfDXrSmEhid3aQ+7J7itej+upwcxOnPMQ=
|
||||
github.com/bloeys/gglm v0.3.1/go.mod h1:qwJQ0WzV191wAMwlGicbfbChbKoSedMk7gFFX6GnyOk=
|
||||
github.com/bloeys/nmage v0.0.7-0.20220224025919-577e6250a8e5 h1:stKgJ7DAhmmYy+meP0j7vyjmlfgrAO7jcz6+BwZAVbg=
|
||||
github.com/bloeys/nmage v0.0.7-0.20220224025919-577e6250a8e5/go.mod h1:4h2tKtMvk9ab8r/+rem4QonPXEBTho6VWvpCMm0M6iM=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/go-gl/gl v0.0.0-20211025173605-bda47ffaa784/go.mod h1:9YTyiznxEY1fVinfM7RvRcjRHbw2xLBJ3AAGIT0I4Nw=
|
||||
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 h1:zDw5v7qm4yH7N8C8uWd+8Ii9rROdgWxQuGoJ9WDXxfk=
|
||||
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6/go.mod h1:9YTyiznxEY1fVinfM7RvRcjRHbw2xLBJ3AAGIT0I4Nw=
|
||||
github.com/inkyblackness/imgui-go/v4 v4.3.0 h1:iyAzqWXq/dG5+6ckDPhGivtrIo6AywGQMvENKzun04s=
|
||||
github.com/inkyblackness/imgui-go/v4 v4.3.0/go.mod h1:g8SAGtOYUP7rYaOB2AsVKCEHmPMDmJKgt4z6d+flhb0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/veandco/go-sdl2 v0.4.10/go.mod h1:OROqMhHD43nT4/i9crJukyVecjPNYYuCofep6SNiAjY=
|
||||
github.com/veandco/go-sdl2 v0.4.14 h1:ShagETHJG8NCWVn9rwfZ9WLIaN4c2maw3gfFH+9DlOg=
|
||||
github.com/veandco/go-sdl2 v0.4.14/go.mod h1:OROqMhHD43nT4/i9crJukyVecjPNYYuCofep6SNiAjY=
|
||||
15
imgui.ini
Executable file
15
imgui.ini
Executable file
@ -0,0 +1,15 @@
|
||||
[Window][Debug##Default]
|
||||
Pos=496,94
|
||||
Size=400,400
|
||||
Collapsed=0
|
||||
|
||||
[Window][text]
|
||||
Pos=60,60
|
||||
Size=32,32
|
||||
Collapsed=0
|
||||
|
||||
[Window][sidebar]
|
||||
Pos=0,0
|
||||
Size=32,32
|
||||
Collapsed=0
|
||||
|
||||
132
main.go
Normal file
132
main.go
Normal file
@ -0,0 +1,132 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/bloeys/nmage/engine"
|
||||
"github.com/bloeys/nmage/input"
|
||||
"github.com/bloeys/nmage/logging"
|
||||
nmageimgui "github.com/bloeys/nmage/ui/imgui"
|
||||
"github.com/inkyblackness/imgui-go/v4"
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
)
|
||||
|
||||
type Gopad struct {
|
||||
Win *engine.Window
|
||||
ImGUIInfo nmageimgui.ImguiInfo
|
||||
Quitting bool
|
||||
|
||||
mainFont imgui.Font
|
||||
buffer []rune
|
||||
}
|
||||
|
||||
var ()
|
||||
|
||||
func main() {
|
||||
|
||||
if err := engine.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
window, err := engine.CreateOpenGLWindowCentered("nMage", 1280, 720, engine.WindowFlags_RESIZABLE)
|
||||
if err != nil {
|
||||
logging.ErrLog.Fatalln("Failed to create window. Err: ", err)
|
||||
}
|
||||
defer window.Destroy()
|
||||
|
||||
g := Gopad{
|
||||
Win: window,
|
||||
ImGUIInfo: nmageimgui.NewImGUI(),
|
||||
}
|
||||
|
||||
engine.Run(&g)
|
||||
}
|
||||
|
||||
func (g *Gopad) Init() {
|
||||
g.Win.EventCallbacks = append(g.Win.EventCallbacks, g.handleWindowEvents)
|
||||
g.mainFont = g.ImGUIInfo.AddFontTTF("./res/fonts/courier-new.ttf", 24)
|
||||
}
|
||||
|
||||
func (g *Gopad) handleWindowEvents(event sdl.Event) {
|
||||
|
||||
switch e := event.(type) {
|
||||
|
||||
case *sdl.TextEditingEvent:
|
||||
case *sdl.TextInputEvent:
|
||||
g.buffer = append(g.buffer, []rune(e.GetText())...)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Gopad) FrameStart() {
|
||||
}
|
||||
|
||||
func (g *Gopad) Update() {
|
||||
|
||||
if input.IsQuitClicked() {
|
||||
g.Quitting = true
|
||||
}
|
||||
|
||||
if x, y := input.GetMousePos(); x > 0 && y > 0 && input.MouseClicked(sdl.BUTTON_LEFT) {
|
||||
println("Start")
|
||||
sdl.StartTextInput()
|
||||
}
|
||||
|
||||
if input.KeyClicked(sdl.K_ESCAPE) {
|
||||
println("End")
|
||||
sdl.StopTextInput()
|
||||
}
|
||||
|
||||
if input.KeyClicked(sdl.K_BACKSPACE) && len(g.buffer) > 0 {
|
||||
g.buffer = g.buffer[:len(g.buffer)-1]
|
||||
}
|
||||
|
||||
if input.KeyClicked(sdl.K_RETURN) || input.KeyClicked(sdl.K_RETURN2) {
|
||||
g.buffer = append(g.buffer, rune('\n'))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (g *Gopad) Render() {
|
||||
|
||||
open := true
|
||||
w, h := g.Win.SDLWin.GetSize()
|
||||
sidebarSize := float32(w) * 0.25
|
||||
|
||||
//Global imgui settings
|
||||
imgui.PushStyleColor(imgui.StyleColorText, imgui.Vec4{X: 1, Y: 0, Z: 1, W: 1})
|
||||
imgui.PushFont(g.mainFont)
|
||||
|
||||
//Sidebar
|
||||
imgui.SetNextWindowPos(imgui.Vec2{X: 0, Y: 0})
|
||||
imgui.SetNextWindowSize(imgui.Vec2{X: sidebarSize, Y: float32(h)})
|
||||
imgui.BeginV("sidebar", &open, imgui.WindowFlagsNoCollapse|imgui.WindowFlagsNoDecoration|imgui.WindowFlagsNoMove)
|
||||
imgui.End()
|
||||
|
||||
//Text area
|
||||
imgui.SetNextWindowPos(imgui.Vec2{X: sidebarSize, Y: 0})
|
||||
imgui.SetNextWindowSize(imgui.Vec2{X: float32(w) - sidebarSize, Y: float32(h)})
|
||||
imgui.BeginV("editor", &open, imgui.WindowFlagsNoCollapse|imgui.WindowFlagsNoDecoration|imgui.WindowFlagsNoMove)
|
||||
imgui.Text(string(g.buffer))
|
||||
imgui.End()
|
||||
|
||||
imgui.PopFont()
|
||||
imgui.PopStyleColor()
|
||||
}
|
||||
|
||||
func (g *Gopad) FrameEnd() {
|
||||
|
||||
}
|
||||
|
||||
func (g *Gopad) ShouldRun() bool {
|
||||
return !g.Quitting
|
||||
}
|
||||
|
||||
func (g *Gopad) GetWindow() *engine.Window {
|
||||
return g.Win
|
||||
}
|
||||
|
||||
func (g *Gopad) GetImGUI() nmageimgui.ImguiInfo {
|
||||
return g.ImGUIInfo
|
||||
}
|
||||
|
||||
func (g *Gopad) Deinit() {
|
||||
g.Win.Destroy()
|
||||
}
|
||||
BIN
res/fonts/courier-new.ttf
Executable file
BIN
res/fonts/courier-new.ttf
Executable file
Binary file not shown.
13
res/shaders/imgui.frag.glsl
Executable file
13
res/shaders/imgui.frag.glsl
Executable file
@ -0,0 +1,13 @@
|
||||
#version 410
|
||||
|
||||
uniform sampler2D Texture;
|
||||
|
||||
in vec2 Frag_UV;
|
||||
in vec4 Frag_Color;
|
||||
|
||||
out vec4 Out_Color;
|
||||
|
||||
void main()
|
||||
{
|
||||
Out_Color = vec4(Frag_Color.rgb, Frag_Color.a * texture(Texture, Frag_UV.st).r);
|
||||
}
|
||||
17
res/shaders/imgui.vert.glsl
Executable file
17
res/shaders/imgui.vert.glsl
Executable file
@ -0,0 +1,17 @@
|
||||
#version 410
|
||||
|
||||
uniform mat4 ProjMtx;
|
||||
|
||||
in vec2 Position;
|
||||
in vec2 UV;
|
||||
in vec4 Color;
|
||||
|
||||
out vec2 Frag_UV;
|
||||
out vec4 Frag_Color;
|
||||
|
||||
void main()
|
||||
{
|
||||
Frag_UV = UV;
|
||||
Frag_Color = Color;
|
||||
gl_Position = ProjMtx * vec4(Position.xy, 0, 1);
|
||||
}
|
||||
31
windowflags.go
Executable file
31
windowflags.go
Executable file
@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
)
|
||||
|
||||
type WindowFlags int
|
||||
|
||||
const (
|
||||
WindowFlags_FULLSCREEN WindowFlags = sdl.WINDOW_FULLSCREEN
|
||||
WindowFlags_OPENGL WindowFlags = sdl.WINDOW_OPENGL
|
||||
WindowFlags_SHOWN WindowFlags = sdl.WINDOW_SHOWN
|
||||
WindowFlags_HIDDEN WindowFlags = sdl.WINDOW_HIDDEN
|
||||
WindowFlags_BORDERLESS WindowFlags = sdl.WINDOW_BORDERLESS
|
||||
WindowFlags_RESIZABLE WindowFlags = sdl.WINDOW_RESIZABLE
|
||||
WindowFlags_MINIMIZED WindowFlags = sdl.WINDOW_MINIMIZED
|
||||
WindowFlags_MAXIMIZED WindowFlags = sdl.WINDOW_MAXIMIZED
|
||||
WindowFlags_INPUT_GRABBED WindowFlags = sdl.WINDOW_INPUT_GRABBED
|
||||
WindowFlags_INPUT_FOCUS WindowFlags = sdl.WINDOW_INPUT_FOCUS
|
||||
WindowFlags_MOUSE_FOCUS WindowFlags = sdl.WINDOW_MOUSE_FOCUS
|
||||
WindowFlags_FULLSCREEN_DESKTOP WindowFlags = sdl.WINDOW_FULLSCREEN_DESKTOP
|
||||
WindowFlags_FOREIGN WindowFlags = sdl.WINDOW_FOREIGN
|
||||
WindowFlags_ALLOW_HIGHDPI WindowFlags = sdl.WINDOW_ALLOW_HIGHDPI
|
||||
WindowFlags_MOUSE_CAPTURE WindowFlags = sdl.WINDOW_MOUSE_CAPTURE
|
||||
WindowFlags_ALWAYS_ON_TOP WindowFlags = sdl.WINDOW_ALWAYS_ON_TOP
|
||||
WindowFlags_SKIP_TASKBAR WindowFlags = sdl.WINDOW_SKIP_TASKBAR
|
||||
WindowFlags_UTILITY WindowFlags = sdl.WINDOW_UTILITY
|
||||
WindowFlags_TOOLTIP WindowFlags = sdl.WINDOW_TOOLTIP
|
||||
WindowFlags_POPUP_MENU WindowFlags = sdl.WINDOW_POPUP_MENU
|
||||
// WindowFlags_VULKAN WindowFlags = sdl.WINDOW_VULKAN
|
||||
)
|
||||
Reference in New Issue
Block a user