[BMX] Draw Rectangle With GUI image

Started by Filax, April 08, 2025, 17:16:37

Previous topic - Next topic

Filax

SuperStrict

' Modules nécessaires
Import brl.max2d
Import brl.timer

' Constantes pour l'écran
Const SCREEN_WIDTH:Int = 1920
Const SCREEN_HEIGHT:Int = 1080

' Variables pour le calcul du FPS
Global frameCount:Int = 0
Global lastTime:Long = MilliSecs()
Global fps:Int = 0

' Variables pour le tweening
Global startX:Float = 100.0
Global startY:Float = 100.0
Global endX:Float = 700.0
Global endY:Float = 500.0
Global duration:Float = 2000.0  ' Durée en millisecondes
Global startTime:Long = 0
Global isAnimating:Int = False


Global Picture:TImage = LoadImage("Gui_Window.png")


' Fonction principale
Function Main()
    ' Ouvre une fenêtre graphique
    Graphics(SCREEN_WIDTH, SCREEN_HEIGHT)
    SetClsColor(0, 0, 0)  ' Fond noir
   
    ' Démarre l'animation
    startTime = MilliSecs()

   
    ' Boucle principale
    While Not KeyHit(KEY_ESCAPE)
        Cls
       
        ' Calcul du FPS
        frameCount :+ 1
        Local currentTime:Long = MilliSecs()
        If currentTime - lastTime >= 1000 Then
            fps = frameCount
            frameCount = 0
            lastTime = currentTime
        EndIf
       
SetBlend(ALPHABLEND)
SetColor 255, 255, 255

        ' Affichage du FPS
        DrawText("FPS: " + fps, 10, 10)
Gui_DrawBitmapRect(Picture, 400, 400, 650, 650)
Gui_DrawBitmapRect(Picture, 50, 50, MouseX() - 50, MouseY() - 50)
     


        Flip
    Wend
   
    ' Ferme la fenêtre
    EndGraphics()
End Function

Main()





Function Gui_DrawBitmapRect(Bitmap:TImage, Px:Int, Py:Int, Tx:Int, Ty:Int)

Local Width:Float = Bitmap.Width
Local Height:Float = Bitmap.Height

Local SliceX:Float = Width / 3
Local SliceY:Float = Height / 3

If Tx < Width Then Tx = Width
If Ty < Height Then Ty = Height


' Left Up
DrawSubImageRect(Bitmap, Px, Py, SliceX, SliceY, 0, 0, SliceX, SliceY)

' Center Up
DrawSubImageRect(Bitmap, Px + SliceX, Py, Tx - (SliceX * 2) , SliceY, SliceX, 0, SliceX, SliceY)

' Right Up
DrawSubImageRect(Bitmap, Px + Tx - SliceX, Py, SliceX, SliceY, SliceX * 2, 0, SliceX, SliceY)



' Middle Left
DrawSubImageRect(Bitmap, Px, Py + SliceY, SliceX, Ty - (SliceY * 2) , 0, SliceY, SliceX, SliceY)


' Center
DrawSubImageRect(Bitmap, Px + SliceX, Py + SliceY, SliceX + Tx - (SliceX * 3), SliceY + Ty - (SliceY * 3) , SliceX, SliceY, SliceX, SliceY)


' Middle Right
DrawSubImageRect(Bitmap, Px + Tx - SliceX, Py + SliceY, SliceX, Ty - (SliceY * 2) , SliceX * 2, SliceY, SliceX, SliceY)



' Left Down
DrawSubImageRect(Bitmap, Px, Py + Ty - SliceY, SliceX, SliceY, 0, SliceY * 2, SliceX, SliceY)

' Center Down
DrawSubImageRect(Bitmap, Px + SliceX, Py + Ty - SliceY, Tx - (SliceX * 2) , SliceY, SliceX, SliceY * 2, SliceX, SliceY)

' Right Down
DrawSubImageRect(Bitmap, Px + Tx - SliceX, Py + Ty - SliceY, SliceX, SliceY, SliceX * 2, SliceY * 2, SliceX, SliceY)

End Function