EVEN MORE TESTING

This commit is contained in:
Caleb Gardner
2025-01-11 14:29:50 -06:00
parent 6e8d97f29b
commit 50105c242a
2 changed files with 40 additions and 36 deletions
+32 -31
View File
@@ -1,8 +1,6 @@
package ui package ui
import ( import (
"fmt"
"image"
"image/color" "image/color"
"time" "time"
@@ -160,7 +158,6 @@ func (r *Rect) Draw() {
if curRect.h != r.h { if curRect.h != r.h {
updateTex = true updateTex = true
} }
fmt.Println("h", curRect.h, r.h)
if tween.Ended() { if tween.Ended() {
r.h = curRect.h r.h = curRect.h
delete(r.curTweens, "h") delete(r.curTweens, "h")
@@ -172,7 +169,6 @@ func (r *Rect) Draw() {
if curRect.w != r.w { if curRect.w != r.w {
updateTex = true updateTex = true
} }
fmt.Println("w", curRect.w, r.w)
if tween.Ended() { if tween.Ended() {
r.w = curRect.w r.w = curRect.w
delete(r.curTweens, "w") delete(r.curTweens, "w")
@@ -208,52 +204,57 @@ func (r *Rect) Draw() {
// r.tex = rl.LoadTextureFromImage(curRect.buildImage()) // r.tex = rl.LoadTextureFromImage(curRect.buildImage())
// rl.UpdateTexture(r.tex, rl.LoadImageColors(curRect.buildImage())) // rl.UpdateTexture(r.tex, rl.LoadImageColors(curRect.buildImage()))
rl.BeginTextureMode(r.tex) rl.BeginTextureMode(r.tex)
rl.UpdateTextureRec(r.tex.Texture, rl.NewRectangle(0, 0, float32(curRect.w), float32(curRect.h)), rl.LoadImageColors(curRect.buildImage())) curRect.drawTexture()
rl.EndTextureMode() rl.EndTextureMode()
} }
rl.DrawTextureEx(r.tex.Texture, rl.NewVector2(float32(curRect.x), float32(curRect.y)), 0, 1, rl.White) rl.DrawTexturePro(r.tex.Texture, rl.NewRectangle(0, 0, float32(curRect.w), float32(curRect.h)), rl.NewRectangle(float32(curRect.x), float32(curRect.y), float32(curRect.w), float32(curRect.h)), rl.NewVector2(0, 0), 0, rl.White)
// rl.DrawTextureEx(r.tex.Texture, rl.NewVector2(float32(curRect.x), float32(curRect.y)), 0, 1, rl.White)
r.reload = false r.reload = false
} }
func (r Rect) buildImage() *rl.Image { func (r Rect) drawTexture() {
// Create image at 16x resolution then resize down so it looks better rl.ClearBackground(rl.Blank)
img := rl.NewImageFromImage(image.NewAlpha(image.Rect(0, 0, int(r.w), int(r.h))))
// Filled areas // Filled areas
if r.fillColor != rl.Blank { if r.fillColor != rl.Blank {
rl.ImageDrawRectangle(img, r.radius, 0, (r.w - (2 * r.radius)), r.h, r.fillColor) rl.DrawRectangle(r.radius, 0, (r.w - (2 * r.radius)), r.h, r.fillColor)
if r.radius > 0 { if r.radius > 0 {
rl.ImageDrawRectangle(img, (r.w - r.radius), r.radius, r.radius, (r.h - (2 * r.radius)), r.fillColor) rl.DrawRectangle((r.w - r.radius), r.radius, r.radius, (r.h - (2 * r.radius)), r.fillColor)
rl.ImageDrawRectangle(img, 0, r.radius, r.radius, (r.h - (2 * r.radius)), r.fillColor) rl.DrawRectangle(0, r.radius, r.radius, (r.h - (2 * r.radius)), r.fillColor)
} }
} }
if r.borderColor != rl.Blank { if r.borderColor != rl.Blank {
// Horizontal lines // Horizontal lines
rl.ImageDrawRectangle(img, r.radius, 0, (r.w - (2 * r.radius)), r.borderWidth, r.borderColor) rl.DrawRectangle(r.radius, 0, (r.w - (2 * r.radius)), r.borderWidth, r.borderColor)
rl.ImageDrawRectangle(img, r.radius, (r.h)-(r.borderWidth), (r.w - (2 * r.radius)), r.borderWidth, r.borderColor) rl.DrawRectangle(r.radius, (r.h)-(r.borderWidth), (r.w - (2 * r.radius)), r.borderWidth, r.borderColor)
// Vertical lines // Vertical lines
rl.ImageDrawRectangle(img, 0, r.radius, r.borderWidth, (r.h - (2 * r.radius)), r.borderColor) rl.DrawRectangle(0, r.radius, r.borderWidth, (r.h - (2 * r.radius)), r.borderColor)
rl.ImageDrawRectangle(img, (r.w)-(r.borderWidth), r.radius, r.borderWidth, (r.h - (2 * r.radius)), r.borderColor) rl.DrawRectangle((r.w)-(r.borderWidth), r.radius, r.borderWidth, (r.h - (2 * r.radius)), r.borderColor)
} }
if r.radius > 0 { if r.radius > 0 {
r.placeCorners(r.radius, img) r.placeCorners()
} }
return img
} }
func (r Rect) placeCorners(radius int32, img *rl.Image) { func (r Rect) placeCorners() {
// Setup corner //bl
corner := rl.NewImageFromImage(image.NewAlpha(image.Rect(0, 0, int(radius), int(radius))))
if r.borderWidth > 0 { if r.borderWidth > 0 {
rl.ImageDrawCircle(corner, radius, radius, radius, r.borderColor) rl.DrawRing(rl.NewVector2(float32(r.radius), float32(r.radius)), float32(r.radius-r.borderWidth), float32(r.radius), 180, 270, 20, r.borderColor)
} }
rl.ImageDrawCircle(corner, radius, radius, (radius)-(r.borderWidth), r.fillColor) rl.DrawCircleSector(rl.NewVector2(float32(r.radius), float32(r.radius)), float32(r.radius-r.borderWidth), 180, 270, 20, r.fillColor)
// Add corners to actual image //tl
rl.ImageDraw(img, corner, rl.NewRectangle(0, 0, float32(corner.Width), float32(corner.Height)), rl.NewRectangle(0, 0, float32(corner.Width), float32(corner.Height)), rl.White) if r.borderWidth > 0 {
rl.ImageRotateCW(corner) rl.DrawRing(rl.NewVector2(float32(r.radius), float32(r.h-r.radius)), float32(r.radius-r.borderWidth), float32(r.radius), 90, 180, 20, r.borderColor)
rl.ImageDraw(img, corner, rl.NewRectangle(0, 0, float32(corner.Width), float32(corner.Height)), rl.NewRectangle(float32((r.w-radius)), 0, float32(corner.Width), float32(corner.Height)), rl.White) }
rl.ImageRotateCW(corner) rl.DrawCircleSector(rl.NewVector2(float32(r.radius), float32(r.h-r.radius)), float32(r.radius-r.borderWidth), 90, 180, 20, r.fillColor)
rl.ImageDraw(img, corner, rl.NewRectangle(0, 0, float32(corner.Width), float32(corner.Height)), rl.NewRectangle(float32((r.w-radius)), float32((r.h-radius)), float32(corner.Width), float32(corner.Height)), rl.White) //tr
rl.ImageRotateCW(corner) if r.borderWidth > 0 {
rl.ImageDraw(img, corner, rl.NewRectangle(0, 0, float32(corner.Width), float32(corner.Height)), rl.NewRectangle(0, float32((r.h-radius)), float32(corner.Width), float32(corner.Height)), rl.White) rl.DrawRing(rl.NewVector2(float32(r.w-r.radius), float32(r.h-r.radius)), float32(r.radius-r.borderWidth), float32(r.radius), 0, 90, 20, r.borderColor)
}
rl.DrawCircleSector(rl.NewVector2(float32(r.w-r.radius), float32(r.h-r.radius)), float32(r.radius-r.borderWidth), 0, 90, 20, r.fillColor)
//br
if r.borderWidth > 0 {
rl.DrawRing(rl.NewVector2(float32(r.w-r.radius), float32(r.radius)), float32(r.radius-r.borderWidth), float32(r.radius), 270, 360, 20, r.borderColor)
}
rl.DrawCircleSector(rl.NewVector2(float32(r.w-r.radius), float32(r.radius)), float32(r.radius-r.borderWidth), 270, 360, 20, r.fillColor)
} }
+8 -5
View File
@@ -9,24 +9,27 @@ import (
type Window struct{} type Window struct{}
func Test() { func Test() {
rl.SetConfigFlags(rl.FlagWindowResizable | rl.FlagWindowHighdpi | rl.FlagVsyncHint | rl.FlagMsaa4xHint)
rl.InitWindow(800, 450, "raylib [core] example - basic window") rl.InitWindow(800, 450, "raylib [core] example - basic window")
rl.SetWindowState(rl.FlagWindowResizable | rl.FlagWindowHighdpi | rl.FlagVsyncHint)
rl.SetConfigFlags(rl.FlagMsaa4xHint)
defer rl.CloseWindow() defer rl.CloseWindow()
rl.Scalef(2, 2, 2) rl.SetTargetFPS(60)
noto := rl.LoadFont("./noto-sans.ttf") noto := rl.LoadFont("./noto-sans.ttf")
txtImg := rl.ImageTextEx(noto, "Hello World!", 50, 0, rl.Black) txtImg := rl.ImageTextEx(noto, "Hello World!", 50, 0, rl.Black)
// rl.ImageResize(txtImg, 450, 200)
txt := rl.LoadTextureFromImage(txtImg) txt := rl.LoadTextureFromImage(txtImg)
tmpRect := NewRect(10, 10, 250, 500) tmpRect := NewRect(10, 10, 250, 500)
tmpRect.SetBorderRadius(25) tmpRect.SetBorderRadius(25)
go func() { go func() {
for { for {
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
tmpRect.SetSize(200, 400) // tmpRect.SetBorderRadius(0)
// tmpRect.SetPosition(100, 100)
tmpRect.SetSize(400, 700)
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
// tmpRect.SetBorderRadius(25)
// tmpRect.SetPosition(10, 10)
tmpRect.SetSize(250, 500) tmpRect.SetSize(250, 500)
} }
}() }()