Skip to content

Commit

Permalink
Ui Text
Browse files Browse the repository at this point in the history
texto en Furia2D-Engine !!!!!
  • Loading branch information
Troxsoft committed Nov 30, 2023
1 parent 274c2f9 commit 5661a4c
Show file tree
Hide file tree
Showing 8 changed files with 241 additions and 1 deletion.
12 changes: 11 additions & 1 deletion engine/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package engine

import (
"errors"
"fmt"

rl "github.com/gen2brain/raylib-go/raylib"
"github.com/tawesoft/golib/v2/dialog"
)

var isRunning = false
Expand All @@ -28,11 +30,19 @@ func _update() {
instancesGameObjects[i].Draw()

}
for i := 0; i < len(ui_text); i++ {
//fmt.Println(rl.IsK)
ui_text[i].Draw()

}
}

func InitGame(title string, size Size, start func(*GameEvent), update func(*GameEvent)) {
isRunning = true

err := dialog.Init()
if err != nil {
fmt.Println(err)
}
rl.SetConfigFlags(rl.FlagVsyncHint)
rl.InitWindow(int32(size.W), int32(size.H), title)

Expand Down
185 changes: 185 additions & 0 deletions engine/ui.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
package engine

import (
rl "github.com/gen2brain/raylib-go/raylib"
"github.com/tawesoft/golib/v2/dialog"
)

var (
/* [ON] [ON] [ON] [ON] [ON]->DRAW NO
ui objects: UiButton - UiText - UiTextBox - UiSelect - UiMessageBox ->ALLS TYPES OF MESSAGEBOX
*/

//text
ui_text []*UiText
)

type UiText struct {
text string
pos Position
size uint16
font *string
color Color
hide bool
}

func NewUiText(text string, pos Position, size uint16) *UiText {
p := &UiText{
text: text,
pos: pos,
size: size,
font: nil,
color: NewColor2(255, 0, 0),
hide: false,
}
p = p.add()
return p
}

func NewUiTextWithFont(text string, font string, pos Position, size uint16) *UiText {
p := &UiText{
text: text,
pos: pos,
size: size,
font: &font,
color: NewColor2(255, 0, 0),
hide: false,
}
p = p.add()
return p
}
func (text *UiText) Hide() {
//rl.DrawRectangle
text.hide = true
}
func (text *UiText) Show() {
text.hide = false
}
func (text *UiText) Draw() {
if text.hide == false {

if text.font == nil {

rl.DrawText(text.text, text.pos.X, text.pos.Y, int32(text.size), ConvertColor(text.color))
} else {
rl.DrawTextEx(rl.LoadFont(text.FontName()), text.text, rl.NewVector2(float32(text.pos.X), float32(text.pos.Y)), float32(text.size), 0.5, ConvertColor(text.color))
}
}
}
func (text *UiText) add() *UiText {
ui_text = append(ui_text, text)
return ui_text[len(ui_text)-1]
}
func (text *UiText) SetColor(nColor Color) {
text.color = nColor
}
func (text *UiText) SetColor2(r, g, b, a uint8) {
text.color = NewColor(r, g, b, a)
}
func (text *UiText) SetColor3(r, g, b uint8) {
text.color = NewColor2(r, g, b)
}
func (text *UiText) Color() Color {
return text.color
}
func (text *UiText) SetFontName(font string) {
if font == "" || font == "default" {
text.font = nil
} else {
text.font = &font
}
}

func (text *UiText) FontName() string {
if text.font == nil {
return "default"
} else {
return *text.font
}
}
func (text *UiText) SetSize(nSize uint16) {
text.size = nSize
}
func (text *UiText) Size() uint16 {
return text.size
}
func (text *UiText) SetPosition(nPos Position) {
text.pos = nPos
}
func (text *UiText) Position() Position {
return text.pos
}
func (text *UiText) SetText(nText string) {
text.text = nText
}
func (text *UiText) Text() string {
return text.text
}

type UiMessageBoxAlert struct {
title string
message string
}

func ShowMessageBoxAlert(title, message string) {
NewMessageBoxAlert(title, message).Show()
}
func NewMessageBoxAlert(title, message string) *UiMessageBoxAlert {
return &UiMessageBoxAlert{
message: message,
title: title,
}
}
func (mb *UiMessageBoxAlert) Show() {
dialog.Message{
Title: mb.title,
Format: mb.message,
Icon: dialog.IconWarning,
}.Raise()
}

//info

type UiMessageBoxInfo struct {
title string
message string
}

func ShowMessageBoxInfo(title, message string) {
NewMessageBoxInfo(title, message).Show()
}
func NewMessageBoxInfo(title, message string) *UiMessageBoxInfo {
return &UiMessageBoxInfo{
message: message,
title: title,
}
}
func (mb *UiMessageBoxInfo) Show() {
dialog.Message{
Title: mb.title,
Format: mb.message,
Icon: dialog.IconInfo,
}.Raise()
}

type UiMessageBoxError struct {
title string
message string
}

func ShowMessageBoxError(title, message string) {
NewMessageBoxError(title, message).Show()
}
func NewMessageBoxError(title, message string) *UiMessageBoxError {
return &UiMessageBoxError{
message: message,
title: title,
}
}
func (mb *UiMessageBoxError) Show() {
dialog.Message{
Title: mb.title,
Format: mb.message,
Icon: dialog.IconError,
}.Raise()
}
Binary file modified example_physics_simply.exe
Binary file not shown.
Binary file added example_ui.exe
Binary file not shown.
1 change: 1 addition & 0 deletions examples/example_physics_simply.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func main() {
}
if ge.IsKeyDown(ge.KeyLeft) {
g.MoveTo(e.NewPosition(g.Position().X-10, g.Position().Y))
g.SetColor3(0, 0, 0)
}

})
Expand Down
32 changes: 32 additions & 0 deletions examples/example_ui.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"fmt"

e "github.com/Troxsoft/Furia2D-Engine/engine"
)

var text *e.UiText
var contador int = 0

func main() {
e.InitGame("Ejemplos de Gui en Furia2D-Engine :)", e.NewSize(500, 400), func(ge *e.GameEvent) {

e.ShowMessageBoxAlert("alerta", "empieza la diversion")
e.ShowMessageBoxError(":(", "mala")
e.ShowMessageBoxInfo(":)", "fue una broma")
text = e.NewUiText(fmt.Sprint(contador), e.NewPosition(50, 50), 20)

//fmt.Println(obj.F)
},
func(ge *e.GameEvent) {
contador += 1
text.SetText(fmt.Sprint(contador))
if contador > 400 {
text.Hide()
}
if contador > 800 {
text.Show()
}
})
}
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ module github.com/Troxsoft/Furia2D-Engine
go 1.21.4

require (
github.com/alessio/shellescape v1.4.1 // indirect
github.com/ebitengine/purego v0.6.0-alpha.2 // indirect
github.com/gen2brain/raylib-go/raylib v0.0.0-20231123174446-48309e2407b7 // indirect
github.com/tawesoft/golib/v2 v2.10.0 // indirect
golang.org/x/exp v0.0.0-20221208152030-732eee02a75a // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/text v0.3.8 // indirect
)
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVKJUX0=
github.com/alessio/shellescape v1.4.1/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30=
github.com/ebitengine/purego v0.6.0-alpha.2 h1:lYSvMtNBEjNGAzqPC5WP7bHUOxkFU3L+JZMdxK7krkw=
github.com/ebitengine/purego v0.6.0-alpha.2/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
github.com/gen2brain/raylib-go/raylib v0.0.0-20231123174446-48309e2407b7 h1:qu+EOzSIbZHZdlahUAZRGAjyiSjzSNEnIiucIEHCKYU=
github.com/gen2brain/raylib-go/raylib v0.0.0-20231123174446-48309e2407b7/go.mod h1:P/hDjVwz/9fhR0ww3+umzDpDA7Bf7Tce4xNChHIEFqE=
github.com/tawesoft/golib/v2 v2.10.0 h1:uvA5Cy+UV6NHrf3Qwg1+2Uvz6eKVW1t+KrJ9gZYSjag=
github.com/tawesoft/golib/v2 v2.10.0/go.mod h1:jGw0nDuOLpji2TW5QfSQLcWnZ4WtS4TizzRuXu3hZ/Y=
golang.org/x/exp v0.0.0-20221208152030-732eee02a75a h1:4iLhBPcpqFmylhnkbY3W0ONLUYYkDAW9xMFLfxgsvCw=
golang.org/x/exp v0.0.0-20221208152030-732eee02a75a/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=

0 comments on commit 5661a4c

Please sign in to comment.