Ok, just left click and move the mouse in the window.
// Project: Gui Bug
// Created: 2024-08-18
// show all errors
#renderer "Basic"
SetRawWritePath(GetReadPath())
SetErrorMode(2)
#option_explicit
// set window properties
SetWindowTitle( "Gui Bug" )
SetWindowSize( 1080, 1920, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1080, 1920 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
Type ViewType
Left As Float
Top As Float
Width As Float
Height As Float
Right As Float
Bottom As Float
EndType
Type GuiControlType
Area As ViewType
Sprite As Integer[128]
Text As Integer[128]
Colors As Integer[128]
SpriteShader As Integer
ParentX As Float
ParentY As Float
EndType
Global GuiControl As GuiControlType[128]
Global TotalControls As Integer
Global BaseWindow As Integer, ChildWindow As Integer, Label0 As Integer, Label1 As Integer, Button0 As Integer, Button1 As Integer
Global BaseImage As Integer
Global BaseSize As Float
#Constant SpriteVertexShader "sprite_window.vs"
#Constant SpritePixelShader "sprite_window.ps"
#Constant TextVertexShader "text_window.vs"
#Constant TextPixelShader "text_window.ps"
#Constant SpriteShaderWindowName "window"
#Constant TextShaderWindowName "window"
#Constant TextShaderColorName "ocolor"
Setup()
ShowGuiControl(BaseWindow)
ShowGuiControl(ChildWindow)
do
Print( ScreenFPS() )
If GetPointerState()
PositionBasWindow(GetPointerX(), GetPointerY())
EndIf
Sync()
loop
Function ShowGuiControl(C As Integer)
Local i As Integer, j As Float
For i = 0 To 127
j = GuiControl[C].Sprite[i]
If GetSpriteExists(j) = 0 Then Exit
SetSpriteVisible(j, 1)
Next
EndFunction
Function PositionBasWindow(X As Float, Y As Float)
PositionControl(BaseWindow, X, Y)
PositionControl(ChildWindow, GuiControl[ChildWindow].ParentX + X, GuiControl[ChildWindow].ParentY + Y)
EndFunction
Function PositionControl(C As Integer, X As Float, Y As Float)
Local Bx As Float, By As Float
Local Dx As Float, Dy As Float
Local i As Integer, j As Float
Dx = X - GuiControl[C].Area.Left
Dy = Y - GuiControl[C].Area.Top
GuiControl[C].Area.Left = X
GuiControl[C].Area.Top = Y
GuiControl[C].Area.Right = X + GuiControl[C].Area.Width
GuiControl[C].Area.Bottom = Y + GuiControl[C].Area.Width
Bx = GuiControl[C].ParentX
By = GuiControl[C].ParentY
SetShaderConstantByName(GuiControl[C].SpriteShader, SpriteShaderWindowName, GuiControl[C].Area.Left - Bx, GuiControl[C].Area.Top - By, GuiControl[C].Area.Right - Bx, GuiControl[C].Area.Bottom - By)
For i = 0 To 127
j = GuiControl[C].Sprite[i]
If GetSpriteExists(j) = 0 Then Exit
SetSpritePosition(j, GetSpriteX(j) + Dx, GetSpriteY(j) + Dy)
Next
EndFunction
Function Setup()
Local i As Integer, j As Integer, p As Integer, q As Integer, r As Integer, k As Integer, l As Integer, m As Integer, X As Integer, Y As Integer
Local Ax As Float, Bx As Float, Cx As Float, Dx As Float, Ex As Float, Fx As Float, Gx As Float, Hx As Float
Local Ay As Float, By As Float, Cy As Float, Dy As Float, Ey As Float, Fy As Float, Gy As Float, Hy As Float
Local S As String, E As String, N As String
BaseSize = 32
Drawbox(0, 0, BaseSize - 1, BaseSize - 1, -1, -1, -1, -1, 1)
Render()
BaseImage = GetImage(0, 0, BaseSize - 1, BaseSize - 1)
CreateShaders()
TotalControls = 0
Ax = 600
Ay = 900
Bx = 100
By = 100
Ex = 128
Ey = 128
GuiControl[TotalControls].ParentX = 0
GuiControl[TotalControls].ParentY = 0
GuiControl[TotalControls].Colors[0] = 0xFEFF0000
GuiControl[TotalControls].Area.Width = Ax
GuiControl[TotalControls].Area.Height = Ay
GuiControl[TotalControls].Area.Left = Bx
GuiControl[TotalControls].Area.Top = By
GuiControl[TotalControls].Area.Right = GuiControl[TotalControls].Area.Left + GuiControl[TotalControls].Area.Width
GuiControl[TotalControls].Area.Bottom = GuiControl[TotalControls].Area.Top + GuiControl[TotalControls].Area.Height
GuiControl[TotalControls].Area.Bottom = GuiControl[TotalControls].Area.Top + GuiControl[TotalControls].Area.Height
GuiControl[TotalControls].SpriteShader = LoadShader(SpriteVertexShader, SpritePixelShader)
SetShaderConstantByName(GuiControl[TotalControls].SpriteShader, SpriteShaderWindowName, GuiControl[TotalControls].Area.Left - Bx, GuiControl[TotalControls].Area.Top - By, GuiControl[TotalControls].Area.Right - Bx, GuiControl[TotalControls].Area.Bottom - By)
Cx = Floor(Ax/Ex) + 1
Cy = Floor(Ay/Ey) + 1
x = Cx
y = Cy
Cx = -((Cx * Ex) - Ax)/2
Cy = -((Cy * Ey) - Ay)/2
p = 0
Dy = Cy
For i = 0 To y - 1
Dx = Cx
For j = 0 To x - 1
GuiControl[TotalControls].Sprite[p] = CreateSprite(BaseImage)
SetSpriteSize(GuiControl[TotalControls].Sprite[p], Ex, Ey)
SetSpritePosition(GuiControl[TotalControls].Sprite[p], Dx, Dy)
SetSpriteShader(GuiControl[TotalControls].Sprite[p], GuiControl[TotalControls].SpriteShader)
SetSpriteColor(GuiControl[TotalControls].Sprite[p], ((GuiControl[TotalControls].Colors[0] >> 16) && 255), ((GuiControl[TotalControls].Colors[0] >> 8) && 255), ((GuiControl[TotalControls].Colors[0]) && 255), ((GuiControl[TotalControls].Colors[0] >> 24) && 255))
SetSpriteVisible(GuiControl[TotalControls].Sprite[p], 0)
Dx = Dx + Ex
p = P + 1
Next
Dy = Dy + Ey
Next
BaseWindow = TotalControls
TotalControls = TotalControls + 1
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Ax = 400
Ay = 400
Bx = -100
By = -100
Ex = 128
Ey = 128
GuiControl[TotalControls].ParentX = Bx
GuiControl[TotalControls].ParentY = By
GuiControl[TotalControls].Colors[0] = 0xFE00FF00
GuiControl[TotalControls].Area.Width = Ax
GuiControl[TotalControls].Area.Height = Ay
GuiControl[TotalControls].Area.Left = Bx
GuiControl[TotalControls].Area.Top = By
GuiControl[TotalControls].Area.Right = GuiControl[TotalControls].Area.Left + GuiControl[TotalControls].Area.Width
GuiControl[TotalControls].Area.Bottom = GuiControl[TotalControls].Area.Top + GuiControl[TotalControls].Area.Height
GuiControl[TotalControls].Area.Bottom = GuiControl[TotalControls].Area.Top + GuiControl[TotalControls].Area.Height
GuiControl[TotalControls].SpriteShader = LoadShader(SpriteVertexShader, SpritePixelShader)
SetShaderConstantByName(GuiControl[TotalControls].SpriteShader, SpriteShaderWindowName, GuiControl[TotalControls].Area.Left - Bx, GuiControl[TotalControls].Area.Top - By, GuiControl[TotalControls].Area.Right - Bx, GuiControl[TotalControls].Area.Bottom - By)
Cx = Floor(Ax/Ex) + 1
Cy = Floor(Ay/Ey) + 1
x = Cx
y = Cy
Cx = -((Cx * Ex) - Ax)/2
Cy = -((Cy * Ey) - Ay)/2
p = 0
Dy = Cy
For i = 0 To y - 1
Dx = Cx
For j = 0 To x - 1
GuiControl[TotalControls].Sprite[p] = CreateSprite(BaseImage)
SetSpriteSize(GuiControl[TotalControls].Sprite[p], Ex, Ey)
SetSpritePosition(GuiControl[TotalControls].Sprite[p], Dx, Dy)
SetSpriteShader(GuiControl[TotalControls].Sprite[p], GuiControl[TotalControls].SpriteShader)
SetSpriteColor(GuiControl[TotalControls].Sprite[p], ((GuiControl[TotalControls].Colors[0] >> 16) && 255), ((GuiControl[TotalControls].Colors[0] >> 8) && 255), ((GuiControl[TotalControls].Colors[0]) && 255), ((GuiControl[TotalControls].Colors[0] >> 24) && 255))
SetSpriteVisible(GuiControl[TotalControls].Sprite[p], 0)
Dx = Dx + Ex
p = P + 1
Next
Dy = Dy + Ey
Next
ChildWindow = TotalControls
TotalControls = TotalControls + 1
EndFunction
Function CreateShaders()
Local i As Integer, j As Integer, p As Integer, q As Integer, r As Integer, k As Integer, l As Integer, m As Integer
Local Ax As Float, Bx As Float, Cx As Float, Dx As Float, Ex As Float, Fx As Float, Gx As Float, Hx As Float
Local Ay As Float, By As Float, Cy As Float, Dy As Float, Ey As Float, Fy As Float, Gy As Float, Hy As Float
Local S As String, E As String, N As String
If GetFileExists(SpriteVertexShader) = 0
S = "attribute vec4 position;" + Chr(13) + Chr(10)
S = S + "attribute vec4 color;" + Chr(13) + Chr(10)
S = S + "attribute vec2 uv;" + Chr(13) + Chr(10)
S = S + "varying mediump vec2 uvVarying;" + Chr(13) + Chr(10)
S = S + "varying mediump vec2 posVarying;" + Chr(13) + Chr(10)
S = S + "varying mediump vec4 colorVarying;" + Chr(13) + Chr(10)
S = S + "uniform mat4 agk_Ortho;" + Chr(13) + Chr(10)
S = S + Chr(13) + Chr(10)
S = S + "void main()" + Chr(13) + Chr(10)
S = S + "{ " + Chr(13) + Chr(10)
S = S + "gl_Position = agk_Ortho * position;" + Chr(13) + Chr(10)
S = S + "posVarying = position.xy;" + Chr(13) + Chr(10)
S = S + "uvVarying = uv;" + Chr(13) + Chr(10)
S = S + "colorVarying = color;" + Chr(13) + Chr(10)
S = S + "} " + Chr(13) + Chr(10)
i = OpenToWrite(SpriteVertexShader)
WriteString(i, S)
CloseFile(i)
EndIf
If GetFileExists(SpritePixelShader) = 0
S = "uniform sampler2D texture0;" + Chr(13) + Chr(10)
S = S + "varying mediump vec2 uvVarying;" + Chr(13) + Chr(10)
S = S + "varying mediump vec2 posVarying;" + Chr(13) + Chr(10)
S = S + "varying mediump vec4 colorVarying;" + Chr(13) + Chr(10)
S = S + "uniform mediump vec4 " + SpriteShaderWindowName + ";" + Chr(13) + Chr(10)
S = S + "void main()" + Chr(13) + Chr(10)
S = S + "{" + Chr(13) + Chr(10)
S = S + "float x, y;" + Chr(13) + Chr(10)
S = S + "x = posVarying.x;" + Chr(13) + Chr(10)
S = S + "y = posVarying.y;" + Chr(13) + Chr(10)
S = S + "gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);" + Chr(13) + Chr(10)
S = S + "if(x >= " + SpriteShaderWindowName + ".x)" + Chr(13) + Chr(10)
S = S + "{" + Chr(13) + Chr(10)
S = S + "if(x <= " + SpriteShaderWindowName + ".z){if(y >= " + SpriteShaderWindowName +".y){if(y <= " + SpriteShaderWindowName + ".w)" + Chr(13) + Chr(10)
S = S + "{gl_FragColor = texture2D(texture0, uvVarying) * colorVarying ;}}}" + Chr(13) + Chr(10)
S = S + "}" + Chr(13) + Chr(10)
S = S + "} " + Chr(13) + Chr(10)
i = OpenToWrite(SpritePixelShader)
WriteString(i, S)
CloseFile(i)
EndIf
If GetFileExists(TextVertexShader) = 0
S = "attribute vec4 position;" + Chr(13) + Chr(10)
S = S + "attribute vec4 color;" + Chr(13) + Chr(10)
S = S + "attribute vec2 uv;" + Chr(13) + Chr(10)
S = S + "varying mediump vec2 uvVarying;" + Chr(13) + Chr(10)
S = S + "varying mediump vec2 posVarying;" + Chr(13) + Chr(10)
S = S + "varying mediump vec4 colorVarying;" + Chr(13) + Chr(10)
S = S + "uniform mat4 agk_Ortho;" + Chr(13) + Chr(10)
S = S + "void main()" + Chr(13) + Chr(10)
S = S + "{ " + Chr(13) + Chr(10)
S = S + "gl_Position = agk_Ortho * position;" + Chr(13) + Chr(10)
S = S + "posVarying = position.xy;" + Chr(13) + Chr(10)
S = S + "uvVarying = uv;" + Chr(13) + Chr(10)
S = S + "colorVarying = color;" + Chr(13) + Chr(10)
S = S + "}" + Chr(13) + Chr(10)
i = OpenToWrite(TextVertexShader)
WriteString(i, S)
CloseFile(i)
EndIf
If GetFileExists(TextPixelShader) = 0
S = "uniform sampler2D texture0;" + Chr(13) + Chr(10)
S = S + "varying mediump vec2 uvVarying;" + Chr(13) + Chr(10)
S = S + "varying mediump vec2 posVarying;" + Chr(13) + Chr(10)
S = S + "varying mediump vec4 colorVarying;" + Chr(13) + Chr(10)
S = S + "uniform mediump vec4 " + TextShaderWindowName + ";" + Chr(13) + Chr(10)
S = S + "uniform mediump vec4 " + TextShaderColorName + ";" + Chr(13) + Chr(10)
S = S + "void main()" + Chr(13) + Chr(10)
S = S + "{" + Chr(13) + Chr(10)
S = S + "float x, y;" + Chr(13) + Chr(10)
S = S + "vec4 v_0;" + Chr(13) + Chr(10)
S = S + "x = posVarying.x;" + Chr(13) + Chr(10)
S = S + "y = posVarying.y;" + Chr(13) + Chr(10)
S = S + "gl_FragColor = vec4(0, 0, 0, 0);" + Chr(13) + Chr(10)
S = S + "if(x >= " + TextShaderWindowName + ".x){" + Chr(13) + Chr(10)
S = S + "if(x <= " + TextShaderWindowName + ".z){" + Chr(13) + Chr(10)
S = S + "if(y >= " + TextShaderWindowName + ".y){" + Chr(13) + Chr(10)
S = S + "if(y <= " + TextShaderWindowName + ".w){" + Chr(13) + Chr(10)
S = S + "v_0 = texture2D(texture0, uvVarying) * colorVarying;" + Chr(13) + Chr(10)
S = S + "v_0.x = " + TextShaderColorName + ".x;" + Chr(13) + Chr(10)
S = S + "v_0.y = " + TextShaderColorName + ".y;" + Chr(13) + Chr(10)
S = S + "v_0.z = " + TextShaderColorName + ".z;" + Chr(13) + Chr(10)
S = S + "gl_FragColor = v_0;" + Chr(13) + Chr(10)
S = S + "}" + Chr(13) + Chr(10)
S = S + "}" + Chr(13) + Chr(10)
S = S + "}" + Chr(13) + Chr(10)
S = S + "}" + Chr(13) + Chr(10)
S = S + "}" + Chr(13) + Chr(10)
i = OpenToWrite(TextPixelShader)
WriteString(i, S)
CloseFile(i)
EndIf
EndFunction
Please be informed that my library is way more complex and has tons of attributes and abilities but this testing just matches positioning ability and even at this point, Studio fails. (Thank god for early fail)
Setting object depths and setting their shader constants are buggy. Bonus, opentoread & write is also buggy, it corrupts string space eventually, you may test it if you know what I mean. There are more bugs, to find way arounds but I stopped informing them years ago cuz nobody seems to check them.
Thanks for trying mates, I do appreciate very much...
Edit: Tested on Windows 11