J'avais commencé une GUI, que je n'ai pas eu le temps de finir par manque de temps, il permet de créer des boutons avec du texte créé avec une fonte fraphique et affiche aussi des fenêtres avec possibilité de fading
Code : Tout sélectionner
; Defined constant for saving png or not
#savepng = 0
;- Structures
Structure CS_Gadget
ID.i
Type.i
X.i
Y.i
Width.i
Height.i
Text.s
Flags.i
Color.i
ParentID.i
EndStructure
Structure CS_Window
X.i
Y.i
Width.i
Height.i
Title.s
Flags.i
Color.i
Alpha.i
ParentID.i
EndStructure
;- Constantes
Enumeration
#MAIN_WIN
#SPR_MOUSE
#IMG_FONT
#IMG_FONT_OUT
; GS_TextGadget need to use SPR_FONT_OUT
#SPR_FONT_OUT
EndEnumeration
Enumeration 500
#GADGET_Window
#GADGET_Button
#GADGET_Button_Toggle
#GADGET_Text
#GADGET_String
EndEnumeration
Enumeration 1000
#GS_FONT_WIDTH
#GS_FONT_HEIGHT
#GS_FONT_CHAR_BY_LINE
#GS_FONT_OUT_WIDTH
#GS_FONT_OUT_HEIGHT
#GS_FONT_OUT_CHAR_BY_LINE
EndEnumeration
Enumeration
#GS_Windows_TitleBar = 1 << 0
#GS_Windows_Minimize = 1 << 1
#GS_Windows_Maximize = 1 << 2
#GS_Windows_Close = 1 << 3
#GS_Windows_BorderLess = 1 << 4
#GS_Windows_Border_simple = 1 << 5
#GS_Windows_Border_Double = 1 << 6
#GS_Windows_Border_Triple = 1 << 7
EndEnumeration
Enumeration
#GS_Text_Left = 1 << 0
#GS_Text_Right = 1 << 1
#GS_Text_Center = 1 << 2
EndEnumeration
Enumeration
#GS_Button_Enabled = 1 << 0
#GS_Button_Pushed = 1 << 1
#GS_Button_Disabled = 1 << 2
EndEnumeration
Enumeration ;For iLastEvent
#GS_EventType_MouseOver = 1 << 0
#GS_EventType_MouseUp = 1 << 1
#GS_EventType_MouseDown = 1 << 2
#GS_EventType_LeftClick = 1 << 3 ; Left mouse button click
#GS_EventType_MiddleClick = 1 << 4 ; Middle mouse button click
#GS_EventType_RightClick = 1 << 5 ; Right mouse button click
#GS_EventType_Focus = 1 << 6 ; Get the focus
#GS_EventType_LostFocus = 1 << 7 ; Lost the focus
EndEnumeration
#FONT_OUT_HEIGHT = 10
#FONT_OUT_WIDTH = 7
#NB_CHAR_OUT_BY_LINE = 28 ; 28 Char by Line inside Font Image
#FONT_HEIGHT = 8
#FONT_WIDTH = 6
#NB_CHAR_BY_LINE = 28 ; 28 Char by Line inside Font Image
#BORDER_SIMPLE = 1
#BORDER_DOUBLE = 2
#BORDER_TRIPLE = 4
#SCREEN_Width = 280*2
#SCREEN_Height = 192*2
#GS_VERSION = "0.14"
#Val_INCR = 5
;- Globals
Global NewList GadgetButton.CS_Gadget()
Global NewMap GadgetWindow.CS_Window()
;- Global Event vars
Global.i iPosX, iPosY
Global.i iBut_left, iBut_middle, iBut_right
Global.i iLastEvent, iLastGadgetEvent, iMouseStatus
Global.i iNewID = 2222 ; Les ID commencent à ...
Global.i iTestWin1, iTestWin2, iTestWin3 ; 5 Windows Test
Global.i iTestWin4, iTestWin5
Global.i iButtonQuit
;- Déclarations
Declare GS_Init()
Declare.i GS_WindowID(__Window.i)
Declare.i GS_WindowHeight(__Window.i)
Declare.i GS_WindowWidth(__Window.i)
Declare.i GS_WindowX(__Window.i)
Declare.i GS_WindowY(__Window.i)
Declare GS_TextGadget(__X.i,__Y.i,__sText.s, __ParentID.i = -1)
Declare GS_DrawGadget()
Declare.i GS_ButtonGadget(__ID.i, __X.i, __Y.i, __Width.i, __Height.i, __sText.s, __Color.i = $EFEFEF, __Flags.i = #GS_Button_Enabled)
Declare.i GS_OpenWindow(__ID.i, __X.i, __Y.i, __Width.i, __Height.i, __sTitle.s = "", __Color.i = $FFFFFF, __Alpha.i = 255, __Flags.i = #GS_Windows_BorderLess)
Declare.i GS_DrawWindow(__ID.i, __X.i, __Y.i, __Alpha.i = -1)
;
Declare.i GS_EventGadget()
Declare.i GS_EventType()
;- Datasection
DataSection
_DS_IMG_Font: IncludeBinary "Img_Spr\IMG_FONT.png"
_DS_IMG_Font_Out: IncludeBinary "Img_Spr\IMG_FONT_OUT.png"
_DS_SPR_Font_Out: IncludeBinary "Img_Spr\SPR_FONT_OUT.png"
_DS_SPR_CURSOR_DATA:IncludeBinary "Img_Spr\SPR_MOUSE.png"
EndDataSection
;- Procedures Internes
Procedure.i GetIDGadget()
iNewID + 1
ProcedureReturn iNewID
EndProcedure
Procedure.i GetFontAttribute(__FontID.i, __Attribute.i)
Protected.i _iResult = 1
Select __FontID
Case #IMG_FONT
Select __Attribute
Case #GS_FONT_WIDTH
_iResult = #FONT_WIDTH
Case #GS_FONT_HEIGHT
_iResult = #FONT_HEIGHT
Case #GS_FONT_CHAR_BY_LINE
_iResult = #NB_CHAR_BY_LINE
EndSelect
Case #IMG_FONT_OUT
Select __Attribute
Case #GS_FONT_OUT_WIDTH
_iResult = #FONT_OUT_WIDTH
Case #GS_FONT_OUT_HEIGHT
_iResult = #FONT_OUT_HEIGHT
Case #GS_FONT_OUT_CHAR_BY_LINE
_iResult = #NB_CHAR_OUT_BY_LINE
EndSelect
EndSelect
ProcedureReturn _iResult
EndProcedure
Procedure MakeImgText(__FontID.i, __PosX.i, __Width.i, __PosY.i, __Height.i, __sText.s, __Flags.i = #GS_Text_Left)
Protected.i _iLen, _iPosX, _iPosY
Protected.s _sChar
Protected.i _sAscii, _iFontLine, _iClipX, _iClipY
Protected.i _iIndex, _iImgTmp
Protected.i _iFontWidth = GetFontAttribute(__FontID, #GS_FONT_WIDTH)
Protected.i _iFontHeight = GetFontAttribute(__FontID, #GS_FONT_HEIGHT)
Protected.i _iFontCBLine = GetFontAttribute(__FontID, #GS_FONT_CHAR_BY_LINE)
_iLen = Len(__sText)
If __Flags & #GS_Text_Center
_iPosX = (__Width - (_iLen * _iFontWidth)) / 2
_iPosY = (__Height - _iFontHeight) / 2
Else
_iPosX = __Width - __PosX
_iPosY = __Height
EndIf
For _iIndex = 1 To _iLen
_sChar = Mid(__sText,_iIndex,1)
_sAscii = Asc(_sChar) - 32
_iClipX = (_sAscii % _iFontCBLine) * _iFontWidth
_iClipY = (_sAscii / _iFontCBLine) * _iFontHeight
_iImgTmp = GrabImage(__FontID, #PB_Any, _iClipX, _iClipY, _iFontWidth, _iFontHeight)
DrawAlphaImage(ImageID(_iImgTmp), __PosX + _iPosX, __PosY + _iPosY)
_iPosX + _iFontWidth
Next
EndProcedure
Procedure.i DoRGB(__Color.i, __Value.i)
Protected.i _Red = Red(__Color) + __Value
Protected.i _Green = Green(__Color) + __Value
Protected.i _Blue = Blue(__Color) + __Value
If _Red < 0 : _Red = 0 : EndIf
If _Green < 0 : _Green = 0 : EndIf
If _Blue < 0 : _Blue = 0 : EndIf
If _Red > 255 : _Red = 255 : EndIf
If _Green > 255 : _Green = 255 : EndIf
If _Blue > 255 : _Blue = 255 : EndIf
ProcedureReturn RGB(_Red, _Green, _Blue)
EndProcedure
Procedure.i Make_GadgetButton(__ID.i, __X.i, __Y.i, __Width.i, __Height.i, __sText.s, __Color.i = $EFEFEF, __Flags.i = #GS_Button_Enabled)
Protected.i _iIndex, _iResult = -1
Protected.i _HV_HG_1, _HV_HG_2, _HV_BD_1, _HV_BD_2
_HV_HG_1 = DoRGB(__Color, $10)
_HV_HG_2 = DoRGB(__Color, -$0C)
_HV_BD_1 = DoRGB(__Color, -$86)
_HV_BD_2 = DoRGB(__Color, -$4F)
If Not IsSprite(__ID)
If CreateSprite(__ID, __Width * 3, __Height)
StartDrawing(SpriteOutput(__ID))
Box(0, 0, __Width * 3, __Height, __Color)
For _iIndex = 0 To 2
x1 = __Width * _iIndex
x2 = __Width * (_iIndex + 1)
Select _iIndex
Case 0
;Ligne haut horizontale et gauche verticale 1
;Blanche
LineXY(x1,0,x2-1,0,_HV_HG_1);$FFFFFF)
LineXY(x1,0,x1,__Height,_HV_HG_1);$FFFFFF)
;line haut horizontale et gauche verticale 2
;Gris clair
LineXY(x1+1,1,x2-2,1,_HV_HG_2);$E3E3E3)
LineXY(x1+1,1,x1+1,__Height-1,_HV_HG_2);$E3E3E3)
;ligne bas droite verticale et bas horizontale 1
;Gris 1
LineXY(x2-2,1,x2-2,__Height-2,_HV_BD_2);$A0A0A0)
LineXY(x1+1,__Height-2,x2-2,__Height-2,_HV_BD_2);$A0A0A0)
;ligne bas droite verticale et bas horizontale 1
;Gris 2
LineXY(x2-1,0,x2-1,__Height-1,_HV_BD_1);$696969)
LineXY(x1,__Height-1,x2-1,__Height-1,_HV_BD_1);$696969)
MakeImgText(#IMG_FONT,x1,__Width,0,__Height,__sText, #GS_Text_Center)
Case 1
;Ligne haut horizontale et gauche verticale 1
;Gris 2
LineXY(x1,0,x2-1,0,_HV_BD_1);$696969)
LineXY(x1,0,x1,__Height,_HV_BD_1);$696969)
;line haut horizontale et gauche verticale 2
;Gris 1
LineXY(x1+1,1,x2-2,1,_HV_BD_2);$A0A0A0)
LineXY(x1+1,1,x1+1,__Height-1,_HV_BD_2);$A0A0A0)
;ligne bas droite verticale et bas horizontale 1
;Gris clair
LineXY(x2-2,1,x2-2,__Height-2,_HV_HG_2);$E3E3E3)
LineXY(x1+1,__Height-2,x2-2,__Height-2,_HV_HG_2);$E3E3E3)
;ligne bas droite verticale et bas horizontale 1
;Blanche
LineXY(x2-1,0,x2-1,__Height-1,_HV_HG_1);$FFFFFF)
LineXY(x1,__Height-1,x2-1,__Height-1,_HV_HG_1);$FFFFFF)
MakeImgText(#IMG_FONT,x1+1,__Width,1,__Height,__sText, #GS_Text_Center)
Case 2
;Ligne haut horizontale et gauche verticale 1
;Blanche
LineXY(x1,0,x2-1,0,_HV_HG_1);$FFFFFF)
LineXY(x1,0,x1,__Height,_HV_HG_1);$FFFFFF)
;line haut horizontale et gauche verticale 2
;Gris clair
LineXY(x1+1,1,x2-2,1,_HV_HG_2);$E3E3E3)
LineXY(x1+1,1,x1+1,__Height-1,_HV_HG_2);$E3E3E3)
;ligne bas droite verticale et bas horizontale 1
;Gris 1
LineXY(x2-2,1,x2-2,__Height-2,_HV_BD_2);$A0A0A0)
LineXY(x1+1,__Height-2,x2-2,__Height-2,_HV_BD_2);$A0A0A0)
;ligne bas droite verticale et bas horizontale 1
;Gris 2
LineXY(x2-1,0,x2-1,__Height-1,_HV_BD_1);$696969)
LineXY(x1,__Height-1,x2-1,__Height-1,_HV_BD_1);$696969)
MakeImgText(#IMG_FONT,x1,__Width,0,__Height,__sText, #GS_Text_Center)
MakeImgText(#IMG_FONT,x1+1,__Width,1,__Height,__sText, #GS_Text_Center)
EndSelect
Next
StopDrawing()
CompilerIf Defined(savepng, #PB_Constant) = #True
SaveSprite(__ID,"SPR_GUI_"+Str(__ID)+".PNG",#PB_ImagePlugin_PNG)
CompilerEndIf
AddElement(GadgetButton())
GadgetButton()\ID = __ID
GadgetButton()\Type = #GADGET_Button
GadgetButton()\X = __X
GadgetButton()\Y = __Y
GadgetButton()\Width = __Width
GadgetButton()\Height = __Height
GadgetButton()\Text = __sText
GadgetButton()\Flags = __Flags
GadgetButton()\Color = __Color
GadgetButton()\ParentID = -1
_iResult = __ID
Else
_iResult = -1
EndIf
Else
_iResult = -1
EndIf
ProcedureReturn _iResult
EndProcedure
Procedure SetMouseStatus(__Value.i)
iMouseStatus = __Value
EndProcedure
Procedure.i GetMouseStatus()
ProcedureReturn iMouseStatus
EndProcedure
;- Procédures GUI
Procedure GS_Init()
UsePNGImageDecoder()
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
MessageRequester("Error", "Can't open the sprite system", 0)
End
EndIf
EndProcedure
Procedure.i GS_WindowID(__Window.i)
Protected.i _iResult = -1
If FindMapElement(GadgetWindow(), Str(__Window))
_iResult = Val(MapKey(GadgetWindow()))
;GS_DrawText(1, #SCREEN_Height - (#FONT_OUT_HEIGHT*3), "Window ID = "+Str(_iResult))
Else
MessageRequester("Bad WindowID", "Cannot open Window ID :"+Str(__Window))
End
EndIf
ProcedureReturn _iResult
EndProcedure
Procedure.i GS_WindowHeight(__Window.i)
Protected.i _iResult = -1
If FindMapElement(GadgetWindow(), Str(__Window))
_iResult = GadgetWindow()\Height
Else
MessageRequester("Bad WindowID", "Cannot open Window ID :"+Str(__Window))
End
EndIf
ProcedureReturn _iResult
EndProcedure
Procedure.i GS_WindowWidth(__Window.i)
Protected.i _iResult = -1
If FindMapElement(GadgetWindow(), Str(__Window))
_iResult = GadgetWindow()\Width
Else
MessageRequester("Bad WindowID", "Cannot open Window ID :"+Str(__Window))
End
EndIf
ProcedureReturn _iResult
EndProcedure
Procedure.i GS_WindowX(__Window.i)
Protected.i _iResult = -1
If FindMapElement(GadgetWindow(), Str(__Window))
_iResult = GadgetWindow()\X
Else
MessageRequester("Bad WindowID", "Cannot open Window ID :"+Str(__Window))
End
EndIf
ProcedureReturn _iResult
EndProcedure
Procedure.i GS_WindowY(__Window.i)
Protected.i _iResult = -1
If FindMapElement(GadgetWindow(), Str(__Window))
_iResult = GadgetWindow()\Y
Else
MessageRequester("Bad WindowID", "Cannot open Window ID :"+Str(__Window))
End
EndIf
ProcedureReturn _iResult
EndProcedure
Procedure GS_TextGadget(__X.i,__Y.i,__sText.s, __ParentID.i = -1)
Protected.i _iLen = Len(__sText)
Protected.s _sChar
Protected.i _sAscii, _iFontLine, _iClipX, _iClipY
Protected.i _iIndex
Protected.i _x = __X, _y = __Y
If __ParentID <> -1
If FindMapElement(GadgetWindow(), Str(__ParentID))
_x = GadgetWindow()\X + __X
_y = GadgetWindow()\Y + __Y
If GadgetWindow()\Flags & #GS_Windows_Border_simple = #GS_Windows_Border_simple
_x + #BORDER_SIMPLE
_y + #BORDER_SIMPLE
EndIf
If GadgetWindow()\Flags & #GS_Windows_Border_Double = #GS_Windows_Border_Double
_x + #BORDER_DOUBLE
_y + #BORDER_DOUBLE
EndIf
If GadgetWindow()\Flags & #GS_Windows_Border_Triple = #GS_Windows_Border_Triple
_x + #BORDER_TRIPLE
_y + #BORDER_TRIPLE
EndIf
Else
MessageRequester("Bad WindowID", "Cannot open Window ID :"+Str(__ID))
End
EndIf
EndIf
For _iIndex = 1 To _iLen
_sChar = Mid(__sText,_iIndex,1)
_sAscii = Asc(_sChar) - 32
_iClipX = (_sAscii % #NB_CHAR_OUT_BY_LINE) * #FONT_OUT_WIDTH
_iClipY = (_sAscii / #NB_CHAR_OUT_BY_LINE) * #FONT_OUT_HEIGHT
ClipSprite(#SPR_FONT_OUT, _iClipX, _iClipY, #FONT_OUT_WIDTH, #FONT_OUT_HEIGHT)
DisplayTransparentSprite(#SPR_FONT_OUT, _x, _y)
_x + #FONT_OUT_WIDTH
Next
EndProcedure
Procedure.i GS_OpenWindow(__ID.i, __X.i, __Y.i, __Width.i, __Height.i, __sTitle.s = "", __Color.i = $FFFFFF, __Alpha.i = 255, __Flags.i = #GS_Windows_BorderLess)
If __ID = #PB_Any
__ID = GetIDGadget()
EndIf
; Si le sprite Window existe déjà pas la peine de le créer une nouvelle fois
If Not IsSprite(__ID)
CreateSprite(__ID, __Width, __Height)
AddMapElement(GadgetWindow(), Str(__ID))
GadgetWindow()\X = __X
GadgetWindow()\Y = __Y
GadgetWindow()\Width = __Width
GadgetWindow()\Height = __Height
GadgetWindow()\Title = __sTitle
GadgetWindow()\Flags = __Flags
GadgetWindow()\Color = __Color
GadgetWindow()\Alpha = __Alpha
GadgetWindow()\ParentID = -1
EndIf
StartDrawing(SpriteOutput(__ID))
If __Color = 0 : __Color = 1 : EndIf
;_ColorRGBA = RGBA(Red(__Color), Green(__Color), Blue(__Color), __Alpha)
Box(0,0,__Width,__Height,__Color)
;Box(0,0,__Width,__Height,_ColorRGBA)
If __Flags & #GS_Windows_TitleBar = #GS_Windows_TitleBar
Box(0,0,__Width, #FONT_OUT_HEIGHT+4, RGBA(1,1,1,0))
MakeImgText(#IMG_FONT_OUT, 5, 10, 0, 2, "Title")
EndIf
If __Flags & #GS_Windows_Border_simple = #GS_Windows_Border_simple
Box(0,0,__Width,__Height,$FFFFFF)
Box(#BORDER_SIMPLE,#BORDER_SIMPLE,__Width-(#BORDER_SIMPLE*2),__Height-(#BORDER_SIMPLE*2),__Color)
EndIf
If __Flags & #GS_Windows_Border_Double = #GS_Windows_Border_Double
Box(0,0,__Width,__Height,$FFFFFF)
Box(#BORDER_DOUBLE,#BORDER_DOUBLE,__Width-(#BORDER_DOUBLE*2),__Height-(#BORDER_DOUBLE*2),__Color)
EndIf
If __Flags & #GS_Windows_Border_Triple = #GS_Windows_Border_Triple
Box(0,0,__Width,__Height,$FFFFFF)
Box(#BORDER_TRIPLE,#BORDER_TRIPLE,__Width-(#BORDER_TRIPLE*2),__Height-(#BORDER_TRIPLE*2),__Color)
EndIf
StopDrawing()
ProcedureReturn __ID
EndProcedure
Procedure.i GS_DrawWindow(__ID.i, __X.i, __Y.i, __Alpha.i = -1)
If FindMapElement(GadgetWindow(), Str(__ID))
GadgetWindow()\X = __X
GadgetWindow()\Y = __Y
If __Alpha = -1 : __Alpha = GadgetWindow()\Alpha : EndIf
StartSpecialFX()
DisplayTranslucentSprite(__ID.i, __X.i, __Y.i, __Alpha)
StopSpecialFX()
;DisplayTransparentSprite(__ID.i, __X.i, __Y.i)
Else
MessageRequester("Bad WindowID", "Cannot open Window ID :"+Str(__ID))
End
EndIf
EndProcedure
Procedure.i GS_ButtonGadget(__ID.i, __X.i, __Y.i, __Width.i, __Height.i, __sText.s, __Color.i = $EFEFEF, __Flags.i = #GS_Button_Enabled)
Protected.i _iResult = -1
If __ID = #PB_Any
__ID = GetIDGadget()
EndIf
_iResult = Make_GadgetButton(__ID, __X, __Y, __Width, __Height, __sText, __Color, __Flags)
ProcedureReturn _iResult
EndProcedure
Procedure GS_DrawGadget()
Protected.i _iClipPos = 0
ForEach GadgetButton()
With GadgetButton()
If \Flags = #GS_Button_Enabled : _iClipPos = \Width * 0 : EndIf
If \Flags = #GS_Button_Disabled : _iClipPos = \Width * 1 : EndIf
If \Flags = #GS_Button_Pushed : _iClipPos = \Width * 2 : EndIf
ClipSprite(\ID,_iClipPos,0,\Width,\Height)
DisplaySprite(\ID,\X,\Y)
EndWith
Next
EndProcedure
;- Event Gadgets
Procedure.i GS_EventGadget()
Protected.i _x1, _x2, _y1, _y2
Protected.i _iClipPos, _iResult = -1
ForEach GadgetButton()
_x1 = GadgetButton()\X
_x2 = _x1 + GadgetButton()\Width - 1 ; -1 obligatoire
_y1 = GadgetButton()\Y
_y2 = _y1 + GadgetButton()\Height - 1 ; -1 obligatoire
SetMouseStatus(GetMouseStatus() | #GS_EventType_LostFocus | #GS_EventType_MouseUp)
If iPosX >= _x1 And iPosX <= _x2 And iPosY >= _y1 And iPosY <= _y2
; If iMouseStatus & #GS_EventType_MouseOver : Debug "#GS_EventType_MouseOver" : EndIf
; If iMouseStatus & #GS_EventType_MouseUp : Debug "#GS_EventType_MouseUp" : EndIf
; If iMouseStatus & #GS_EventType_MouseDown : Debug "#GS_EventType_MouseDown" : EndIf
; If iMouseStatus & #GS_EventType_LeftClick : Debug "#GS_EventType_LeftClick" : EndIf
; ; If iMouseStatus & #GS_EventType_MiddleClick : Debug "#GS_EventType_MiddleClick" : EndIf
; If iMouseStatus & #GS_EventType_RightClick : Debug "#GS_EventType_RightClick" : EndIf
; ; If iMouseStatus & #GS_EventType_Focus : Debug "#GS_EventType_Focus" : EndIf
; ; If iMouseStatus & #GS_EventType_LostFocus : Debug "#GS_EventType_LostFocus" : EndIf
SetMouseStatus(GetMouseStatus() | #GS_EventType_MouseOver)
If iBut_left = #False And GetMouseStatus() & #GS_EventType_LeftClick = #GS_EventType_LeftClick
SetMouseStatus(#GS_EventType_Focus | #GS_EventType_MouseUp)
_iResult = GadgetButton()\ID
iLastEvent = #GS_EventType_LeftClick
EndIf
If iBut_left
;Debug "Displaying sprite #"+Str(GadgetButton()\ID)
SetMouseStatus(#GS_EventType_LeftClick | #GS_EventType_MouseDown | #GS_EventType_MouseOver)
ClipSprite(GadgetButton()\ID,GadgetButton()\Width*1,0,GadgetButton()\Width,GadgetButton()\Height)
DisplaySprite(GadgetButton()\ID,_x1,_y1)
EndIf
Else
_iResult = -1
iLastEvent = GetMouseStatus()
EndIf
Next
ProcedureReturn _iResult
EndProcedure
Procedure.i GS_EventType()
ProcedureReturn iLastEvent
EndProcedure
;- Création Gadgets
Procedure CreateGadget()
GS_ButtonGadget(#PB_Any, 10, 20, 100, 25, "Hello There !")
GS_ButtonGadget(#PB_Any, 20, 60, 100, 50, "OK")
GS_ButtonGadget(#PB_Any, 120, 60, 100, 50, "Cancel")
iButtonQuit = GS_ButtonGadget(#PB_Any, 450, 320, 100, 50, "Quit", $FAEAAA)
; iTestWin = GS_OpenWindow(#PB_Any, 15, 20, 300, 200, "", RGB(128,128,255), 64, #GS_Windows_TitleBar)
; iTestWin = GS_OpenWindow(#PB_Any, 15, 20, 300, 200, "", RGB(128,128,255), 64, #GS_Windows_BorderLess)
iTestWin1 = GS_OpenWindow(#PB_Any, 0, 0, 300, 200, "", RGB(128,128,255), 64, #GS_Windows_Border_Triple)
iTestWin2 = GS_OpenWindow(#PB_Any, 0, 0, 120, 100, "", RGB(128,255,128), 64, #GS_Windows_Border_simple)
iTestWin3 = GS_OpenWindow(#PB_Any, 0, 0, 80, 60, "", RGB(255,128,100), 255)
; pour les fades
; Black
iTestWin4 = GS_OpenWindow(#PB_Any, 0, 0, #SCREEN_Width/2, #SCREEN_Height/2, "", RGB(0,0,0), 0)
; White
iTestWin5 = GS_OpenWindow(#PB_Any, 0, 0, #SCREEN_Width/2, #SCREEN_Height/2, "", RGB(255,100,100), 0)
EndProcedure
Procedure Draw_MainWindow()
If OpenWindow(#MAIN_WIN, 0, 0, #SCREEN_Width, #SCREEN_Height, "GOSE GUI V#"+#GS_VERSION, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
If OpenWindowedScreen(WindowID(#MAIN_WIN), 0, 0, #SCREEN_Width, #SCREEN_Height, 0, 0, 0)
; Sprite Font Out
CatchSprite(#SPR_FONT_OUT, ?_DS_SPR_Font_Out)
TransparentSpriteColor(#SPR_FONT_OUT, $FF00FF)
; Image Font & Font Out
CatchImage(#IMG_FONT, ?_DS_IMG_Font)
CatchImage(#IMG_FONT_OUT, ?_DS_IMG_Font_Out)
; Création du sprite de la souris
CatchSprite(#SPR_MOUSE, ?_DS_SPR_CURSOR_DATA)
TransparentSpriteColor(#SPR_MOUSE,$FF00FF)
; SaveSprite(#SPR_MOUSE,"Img_Spr\SPR_MOUSE.png",#PB_ImagePlugin_PNG)
; Création des gadgets
CreateGadget()
Else
MessageRequester("Error", "Can't open windowed screen!", 0)
End
EndIf
EndIf
EndProcedure
Procedure ProcessEvent()
Protected.i _iInside = #False
Protected.i _iQuit = 0
Protected.i _iEventWindow, _iEventGadget
Protected.i _iMousePosX, _iMousePosY ;, _iPosX, _iPosY
Protected.i _iElement ;_iBut_left, _iBut_middle, _iBut_right
Protected.i _iFade = 0, _iSens = 1
Repeat
Repeat
_iEventWindow = WaitWindowEvent(5)
Select _iEventWindow
Case #PB_Event_CloseWindow
_iQuit = 1
EndSelect
Until _iEventWindow = 0
FlipBuffers()
If _iInside = #True : ExamineMouse() : EndIf
iBut_left = MouseButton(#PB_MouseButton_Left)
iBut_middle = MouseButton(#PB_MouseButton_Middle)
iBut_right = MouseButton(#PB_MouseButton_Right)
If _iInside
; Verification si en dehors de la fenêtre de "screen"
If MouseX() >= #SCREEN_Width - 1 Or MouseY() >= #SCREEN_Height - 1 Or MouseX() < 1 Or MouseY() < 1
ReleaseMouse(1)
_iInside = #False
EndIf
Else
_iMousePosX = WindowMouseX(#MAIN_WIN) : _iMousePosY = WindowMouseY(#MAIN_WIN)
; Verification si on se retrouve à l'intérieur de la fenêtre de "screen"
If _iMousePosX < #SCREEN_Width And _iMousePosX > 0 And _iMousePosY > 0 And _iMousePosY < #SCREEN_Height
ReleaseMouse(0)
MouseLocate(_iMousePosX, _iMousePosY) ;Obligatoire car ReleaseMouse(0) remet les coordonées de la souris à 0,0
_iInside = #True
EndIf
EndIf
ExamineKeyboard()
iPosX = MouseX() : iPosY = MouseY()
; Efface le screen
ClearScreen(RGB(200,200,200))
GS_DrawGadget()
_iEventGadget = GS_EventGadget()
Select _iEventGadget
Case iButtonQuit
; Select GS_EventType()
; Case #GS_EventType_LeftClick ; Left mouse button click
; Case #GS_EventType_RightClick ; right mouse button click
; Case #GS_EventType_LeftDoubleClick ; Left mouse button double click
; Case #GS_EventType_RightDoubleClick; Right mouse button double click
; Case #GS_EventType_Focus ; Get the focus.
; Case #GS_EventType_LostFocus ; Lose the focus.
Select GS_EventType()
Case #GS_EventType_LeftClick
_iQuit = #True
EndSelect
EndSelect
GS_DrawWindow(iTestWin1, 170, 70, 200):GS_TextGadget(0,0,"TestWin 1",GS_WindowID(iTestWin1))
GS_TextGadget(1,GS_WindowHeight(iTestWin1) - #FONT_OUT_HEIGHT - 8,"Coucou les gens ! Comment ca-va bien ?",GS_WindowID(iTestWin1))
GS_DrawWindow(iTestWin2, 210, 90, 128):GS_TextGadget(0,0,"TestWin 2",GS_WindowID(iTestWin2))
GS_DrawWindow(iTestWin3, 260, 60, 200):GS_TextGadget(0,0,"TestWin 3",GS_WindowID(iTestWin3))
GS_DrawWindow(iTestWin4, 0, 0, _iFade)
GS_DrawWindow(iTestWin5, #SCREEN_Width/2, #SCREEN_Height/2, _iFade)
GS_TextGadget(1, #SCREEN_Height - #FONT_OUT_HEIGHT, "Mouse X: "+Str(iPosX)+" - Mouse Y: "+Str(iPosY))
; Affiche la souris ssi à l'intérieur du screen
If _iInside = #True : DisplayTransparentSprite(#SPR_MOUSE, iPosX, iPosY) : EndIf
; Vérification si appuie sur touche 'Esc'
If KeyboardPushed(#PB_Key_Escape)
_iQuit = #True
EndIf
If _iFade >= 255
_iSens = -#Val_INCR
EndIf
If _iFade <= 0
_iSens = #Val_INCR
EndIf
_iFade + _iSens
Until _iQuit
EndProcedure
;---- Main ---
CompilerIf Defined(savepng, #PB_Constant) = #True
UsePNGImageEncoder()
CompilerEndIf
GS_Init()
Draw_MainWindow()
ProcessEvent()
End