
Messages : 459
GCPoints : 63647
|
Alors voila un petit code facile a utiliser pour créer ses fenêtres.
fonction:
Code :
Function Create_Window(WindowName as String, Width as Integer, Height as Integer, X as Integer , Y as Integer , Dynamic as Boolean)
Array Insert at Bottom Window()
aWin as Integer : aWin=Array Count(Window())
Window(aWin).Name=WindowName
Window(aWin).Hidden=0 : Window(aWin).Minimized=0
Window(aWin).X=X : Window(aWin).Y=Y
Window(aWin).Height=Height : Window(aWin).Width=Width
Window(aWin).Dynamic=Dynamic
Window(aWin).Bar=GetIDNumber() : Window(aWin).Body=GetIDNumber()
Window(aWin).CloseButton=GetIDNumber() : Window(aWin).MinButton=GetIDNumber()
Window(aWin).LockButton=GetIDNumber()
Create Bitmap 1, Screen Width(), Screen Height()
Set Current Bitmap 1
Set Text Font "Copperplate Gothic Light" : Set Text to Bold : Set Text Size 20
Ink RGB(2,2,2),1 : Box 0,0,Width,Height+30
Ink RGB(128,128,128),1 : Box 1,30+2,Width-1,Height+30-1
Ink RGB(1,1,1),1 : Box 2,30+3,Width-2,Height+30-2
Ink RGB(128,128,128),1 : Box 1,1,Width-1,30
Ink RGB(2,2,2),1 : Box 2,2,Width-2,30-1
Ink RGB(128,128,128),1 : Box (Width-67),6,(Width-51),20
Ink RGB(2,2,2),1 : Box (Width-66),7,(Width-52),19
Ink RGB(128,128,128),1 : Box (Width-47),6,(Width-31),20
Ink RGB(2,2,2),1 : Box (Width-46),7,(Width-32),19
Ink RGB(128,128,128),1 : Box (Width-27),6,(Width-11),20
Ink RGB(2,2,2),1 : Box (Width-26),7,(Width-12),19
Set Text Font "Copperplate Gothic Light" : Set Text to Bold : Set Text Size 12
Ink RGB(156,156,156),1 : Center Text (Width-20),6,"x"
Ink RGB(156,156,156),1 : Center Text (Width-39),6,"v"
circle (Width-60),11,2 : Box (Width-63),12,(Width-56),17
Set Text Font "Copperplate Gothic Light" : Set Text to Bold : Set Text Size 14
Ink RGB(156,156,156),1 : Center Text (Width/2),6, WindowName
Get Image Window(aWin).Body,0,30,Width,Height+30,1
SetColorAlpha(Window(aWin).Body,"1,1,1",150)
Sprite Window(aWin).Body,X,Y+27,Window(aWin).Body
Get Image Window(aWin).Bar,0,0,Width,30,1
Sprite Window(aWin).Bar,X,Y,Window(aWin).Bar
Get Image Window(aWin).LockButton, (Width-67),6,(Width-51),20,1
Sprite Window(aWin).LockButton,X+(Width-67),Y+6,Window(aWin).LockButton
Get Image Window(aWin).MinButton,(Width-47),6,(Width-31),20,1
Sprite Window(aWin).MinButton,X+(Width-47),Y+6,Window(aWin).MinButton
Get Image Window(aWin).CloseButton,(Width-27),6,(Width-11),20,1
Sprite Window(aWin).CloseButton,X+(Width-27),Y+6,Window(aWin).CloseButton
Set Current Bitmap 0
If Window(aWin).Dynamic=0
Hide Sprite Window(aWin).Bar
Hide Sprite Window(aWin).MinButton
Hide Sprite Window(aWin).CloseButton
Hide Sprite Window(aWin).LockButton
EndIf
EndFunction
Function UpdateWindows()
For aWin=Array Count(Window()) to 0 step -1
If Sprite Collision(Window(aWin).Bar,SPMouse)=1 and ButtonState="LeftPressed" and Window(aWin).Dynamic=1
For bWin=aWin to Array Count(Window())
If aWin<>bWin
If Sprite Collision(Window(bWin).Body,SPMouse)=1 and Sprite Visible(Window(bWin).Body)=1
goto ExitLoop
EndIF
EndIf
Next bWin
SetWindowtoTop(aWin) : goto ExitLoop
EndIf
Next aWin
ExitLoop:
if KeyState(15) = 1 then CurrentTab=1
if KeyState(15) = 0 then CurrentTab=0
Set Cursor 0,20 : print KeyState(15)
If LastTab=1 and CurrentTab=0 then SetWindowtoTop(0)
LastTab=CurrentTab
Local TopWindow as Integer : TopWindow = Array Count(Window())
If Window(TopWindow).Dynamic=1
If Sprite Collision(Window(TopWindow).Bar,SPMouse)=1 and Window(TopWindow).Locked = 0
If ButtonState="LeftPressed"
Global DistanceX as Integer : DistanceX=Window(TopWindow).X-Mousex()
Global DistanceY as Integer : DistanceY=Window(TopWindow).Y-Mousey()
EndIf
If ButtonState="LeftHeld"
Window(TopWindow).X = Mousex()+ DistanceX
Window(TopWindow).Y = Mousey()+ DistanceY
EndIf
If Window(TopWindow).X<0 then Window(TopWindow).X=0
If Window(TopWindow).Y<0 then Window(TopWindow).Y=0
If Window(TopWindow).X+Window(TopWindow).Width >Screen Width() then Window(TopWindow).X=Screen Width()-Window(TopWindow).Width
If Window(TopWindow).Y+30>Screen Height() then Window(TopWindow).Y=Screen Height()-30
Sprite Window(TopWindow).Bar,Window(TopWindow).X,Window(TopWindow).Y,Window(TopWindow).Bar
Sprite Window(TopWindow).Body,Window(TopWindow).X,Window(TopWindow).Y+27,Window(TopWindow).Body
Sprite Window(TopWindow).MinButton,Window(TopWindow).X+(Window(TopWindow).Width-47),Window(TopWindow).Y+6,Window(TopWindow).MinButton
Sprite Window(TopWindow).CloseButton,Window(TopWindow).X+(Window(TopWindow).Width-27),Window(TopWindow).Y+6,Window(TopWindow).CloseButton
Sprite Window(TopWindow).LockButton,Window(TopWindow).X+(Window(TopWindow).Width-67),Window(TopWindow).Y+6,Window(TopWindow).LockButton
EndIf
If Window(TopWindow).Locked=0
If Sprite Collision(Window(TopWindow).MinButton,SPMouse) and ButtonState="LeftPressed"
If Sprite Visible(Window(TopWindow).Body)=1
Hide Sprite Window(TopWindow).Body
Else
Show Sprite Window(TopWindow).Body
EndIf
EndIf
If Sprite Collision(Window(TopWindow).CloseButton,SPMouse) and ButtonState="LeftPressed"
Hide Sprite Window(TopWindow).Bar
Hide Sprite Window(TopWindow).Body
Hide Sprite Window(TopWindow).MinButton
Hide Sprite Window(TopWindow).CloseButton
Hide Sprite Window(TopWindow).LockButton
EndIf
EndIf
If Sprite Collision(Window(TopWindow).LockButton,SPMouse) and ButtonState="LeftPressed"
If Window(TopWindow).Locked=1
Window(TopWindow).Locked=0
DistanceX=Window(TopWindow).X-Mousex()
DistanceY=Window(TopWindow).Y-Mousey()
Set Sprite Diffuse Window(TopWindow).LockButton, 255,255,255
Else
Window(TopWindow).Locked=1
Set Sprite Diffuse Window(TopWindow).LockButton, 255, 0, 0
EndIf
EndIf
EndIf
EndFunction
Function SetWindowtoTop(aWindow as Integer)
Set Sprite Diffuse Window(Array Count(Window())).Bar, 255,255, 255
Set Sprite Diffuse Window(Array Count(Window())).Body, 255,255, 255
Local TempWin as Window
TempWin=Window(aWindow)
Array Delete Element Window(),aWindow
Array Insert At Bottom Window()
BottomWin=Array Count(Window())
Window(BottomWin)=TempWin
Set Sprite Diffuse Window(Array Count(Window())).Bar,0, 255,0
Set Sprite Diffuse Window(Array Count(Window())).Body, 0, 255, 0
For aWin=0 to Array Count(Window())
Set Sprite Priority Window(aWin).Bar ,(aWin+1)*100
Set Sprite Priority Window(aWin).Body ,(aWin+1)*100
Set Sprite Priority Window(aWin).MinButton ,(aWin+1.1)*100
Set Sprite Priority Window(aWin).CloseButton ,(aWin+1.1)*100
Set Sprite Priority Window(aWin).LockButton ,(aWin+1.1)*100
Next aWin
EndFunction
Function GetIDNumber()
If GetIDInit=0
Dim ID(0) as Integer
Global GetIDInit as Boolean : GetIDInit=1
EndIf
If Array Count(ID())>10000
End
EndIf
Local IDNum as Integer : IDNum =(Rnd(10000)+1)
Local Unique as Boolean
Repeat
If Unique=0
Unique=1
For aID=1 to Array Count(ID())
If ID(aID) = IDNum then IDNum=(Rnd(10000)+1) : Unique=0
Next aID
EndIf
Until Unique=1
Array Insert at Bottom ID()
ID(Array Count(ID())) = IDNum
EndFunction IDNum
Function UpdateMouse()
If MouseInit=0
Global SPMouse as Integer : SPMouse = GetIDNumber()
Get Image SPMouse,0,0,1,1 : Sprite SPMouse,Mousex(),Mousey(),SPMouse : Hide Sprite SPMouse
Global LastTab as Integer
Global LastMClick as Integer
Global MClick as Integer
Global ButtonState as String
Global MousePosX# as Integer
Global MousePosY# as Integer
Global MouseInit as Boolean
MouseInit=1
EndIf
LastMClick=MClick
MClick=MouseClick()
If MClick=0 and LastMClick=0 then ButtonState="NotPressed"
If MClick=1 and LastMClick=0 then ButtonState="LeftPressed"
If MClick=1 and LastMClick=1 then ButtonState="LeftHeld"
If MClick=0 and LastMClick=1 then ButtonState="LeftLifted"
If MClick=2 and LastMClick=0 then ButtonState="RightPressed"
If MClick=2 and LastMClick=2 then ButtonState="RightHeld"
If MClick=0 and LastMClick=2 then ButtonState="RightLifted"
Sprite SPMouse,MousePosX#,MousePosY#,SPMouse
MousePosX# = Mousex()
MousePosY# = Mousey()
Endfunction
Function SetColorAlpha(ImageNumber as Integer, Color as String, Transparency as Byte)
Make Memblock from Image 1,ImageNumber
Local Width as Dword : Width = Memblock Dword(1,0)
Local Height as Dword : Height = Memblock Dword(1,4)
Local Depth as Dword : Depth = Memblock Dword(1,8)
Local PixelPointer as Integer PixelPointer=12
For Y=1 to Height
For X=1 to Width
PixelColor as String
PixelColor=Str$(Memblock Byte(1 , PixelPointer+2)) + "," + Str$(Memblock Byte(1 , PixelPointer+1)) + "," + Str$(Memblock Byte(1 , PixelPointer))
If PixelColor=Color
Write Memblock Byte 1, PixelPointer+3,Transparency
EndIf
PixelPointer=PixelPointer+4
Next X
Next Y
Delete Image ImageNumber
Make Image From Memblock ImageNumber,1
EndFunction
un exemple :
Code :
Set Display Mode 1280,1024,32
Sync On
#Constant True 1
#Constant False 0
Type Window
Name as String
X as Integer
Y as Integer
Width as Integer
Height as Integer
Hidden as Boolean
Minimized as Boolean
Bar as Integer
Body as Integer
CloseButton as Integer
MinButton as Integer
LockButton as Integer
Locked as Boolean
Dynamic as Boolean
EndType : Dim Window(-1) as Window
`Make Sphere
AutoCam On
Make Object Sphere 1,5
Create_Window("Techniques",400,600,0,0, True)
Create_Window("Inventaire",300,500,0,0, True)
Create_Window("Character Profile",500,300,400,400, True)
Create_Window("Carte",500,300,0,800,True)
Create_Window("Attaques",Screen Width(),200,0,800,False)
Do
rotate object 1,object angle x(1)+0.1,object angle y(1)+0.1,object angle z(1)+0.1
UpdateMouse()
UpdateWindows()
Set Cursor 0,0 : Print "FPS:",Screen FPS()
Sync
Loop
Function Create_Window(WindowName as String, Width as Integer, Height as Integer, X as Integer , Y as Integer , Dynamic as Boolean)
Array Insert at Bottom Window()
aWin as Integer : aWin=Array Count(Window())
Window(aWin).Name=WindowName
Window(aWin).Hidden=0 : Window(aWin).Minimized=0
Window(aWin).X=X : Window(aWin).Y=Y
Window(aWin).Height=Height : Window(aWin).Width=Width
Window(aWin).Dynamic=Dynamic
Window(aWin).Bar=GetIDNumber() : Window(aWin).Body=GetIDNumber()
Window(aWin).CloseButton=GetIDNumber() : Window(aWin).MinButton=GetIDNumber()
Window(aWin).LockButton=GetIDNumber()
Create Bitmap 1, Screen Width(), Screen Height()
Set Current Bitmap 1
Set Text Font "Copperplate Gothic Light" : Set Text to Bold : Set Text Size 20
Ink RGB(2,2,2),1 : Box 0,0,Width,Height+30
Ink RGB(128,128,128),1 : Box 1,30+2,Width-1,Height+30-1
Ink RGB(1,1,1),1 : Box 2,30+3,Width-2,Height+30-2
Ink RGB(128,128,128),1 : Box 1,1,Width-1,30
Ink RGB(2,2,2),1 : Box 2,2,Width-2,30-1
Ink RGB(128,128,128),1 : Box (Width-67),6,(Width-51),20
Ink RGB(2,2,2),1 : Box (Width-66),7,(Width-52),19
Ink RGB(128,128,128),1 : Box (Width-47),6,(Width-31),20
Ink RGB(2,2,2),1 : Box (Width-46),7,(Width-32),19
Ink RGB(128,128,128),1 : Box (Width-27),6,(Width-11),20
Ink RGB(2,2,2),1 : Box (Width-26),7,(Width-12),19
Set Text Font "Copperplate Gothic Light" : Set Text to Bold : Set Text Size 12
Ink RGB(156,156,156),1 : Center Text (Width-20),6,"x"
Ink RGB(156,156,156),1 : Center Text (Width-39),6,"v"
circle (Width-60),11,2 : Box (Width-63),12,(Width-56),17
Set Text Font "Copperplate Gothic Light" : Set Text to Bold : Set Text Size 14
Ink RGB(156,156,156),1 : Center Text (Width/2),6, WindowName
Get Image Window(aWin).Body,0,30,Width,Height+30,1
SetColorAlpha(Window(aWin).Body,"1,1,1",150)
Sprite Window(aWin).Body,X,Y+27,Window(aWin).Body
Get Image Window(aWin).Bar,0,0,Width,30,1
Sprite Window(aWin).Bar,X,Y,Window(aWin).Bar
Get Image Window(aWin).LockButton, (Width-67),6,(Width-51),20,1
Sprite Window(aWin).LockButton,X+(Width-67),Y+6,Window(aWin).LockButton
Get Image Window(aWin).MinButton,(Width-47),6,(Width-31),20,1
Sprite Window(aWin).MinButton,X+(Width-47),Y+6,Window(aWin).MinButton
Get Image Window(aWin).CloseButton,(Width-27),6,(Width-11),20,1
Sprite Window(aWin).CloseButton,X+(Width-27),Y+6,Window(aWin).CloseButton
Set Current Bitmap 0
If Window(aWin).Dynamic=0
Hide Sprite Window(aWin).Bar
Hide Sprite Window(aWin).MinButton
Hide Sprite Window(aWin).CloseButton
Hide Sprite Window(aWin).LockButton
EndIf
EndFunction
Function UpdateWindows()
For aWin=Array Count(Window()) to 0 step -1
If Sprite Collision(Window(aWin).Bar,SPMouse)=1 and ButtonState="LeftPressed" and Window(aWin).Dynamic=1
For bWin=aWin to Array Count(Window())
If aWin<>bWin
If Sprite Collision(Window(bWin).Body,SPMouse)=1 and Sprite Visible(Window(bWin).Body)=1
goto ExitLoop
EndIF
EndIf
Next bWin
SetWindowtoTop(aWin) : goto ExitLoop
EndIf
Next aWin
ExitLoop:
if KeyState(15) = 1 then CurrentTab=1
if KeyState(15) = 0 then CurrentTab=0
Set Cursor 0,20 : print KeyState(15)
If LastTab=1 and CurrentTab=0 then SetWindowtoTop(0)
LastTab=CurrentTab
Local TopWindow as Integer : TopWindow = Array Count(Window())
If Window(TopWindow).Dynamic=1
If Sprite Collision(Window(TopWindow).Bar,SPMouse)=1 and Window(TopWindow).Locked = 0
If ButtonState="LeftPressed"
Global DistanceX as Integer : DistanceX=Window(TopWindow).X-Mousex()
Global DistanceY as Integer : DistanceY=Window(TopWindow).Y-Mousey()
EndIf
If ButtonState="LeftHeld"
Window(TopWindow).X = Mousex()+ DistanceX
Window(TopWindow).Y = Mousey()+ DistanceY
EndIf
If Window(TopWindow).X<0 then Window(TopWindow).X=0
If Window(TopWindow).Y<0 then Window(TopWindow).Y=0
If Window(TopWindow).X+Window(TopWindow).Width >Screen Width() then Window(TopWindow).X=Screen Width()-Window(TopWindow).Width
If Window(TopWindow).Y+30>Screen Height() then Window(TopWindow).Y=Screen Height()-30
Sprite Window(TopWindow).Bar,Window(TopWindow).X,Window(TopWindow).Y,Window(TopWindow).Bar
Sprite Window(TopWindow).Body,Window(TopWindow).X,Window(TopWindow).Y+27,Window(TopWindow).Body
Sprite Window(TopWindow).MinButton,Window(TopWindow).X+(Window(TopWindow).Width-47),Window(TopWindow).Y+6,Window(TopWindow).MinButton
Sprite Window(TopWindow).CloseButton,Window(TopWindow).X+(Window(TopWindow).Width-27),Window(TopWindow).Y+6,Window(TopWindow).CloseButton
Sprite Window(TopWindow).LockButton,Window(TopWindow).X+(Window(TopWindow).Width-67),Window(TopWindow).Y+6,Window(TopWindow).LockButton
EndIf
If Window(TopWindow).Locked=0
If Sprite Collision(Window(TopWindow).MinButton,SPMouse) and ButtonState="LeftPressed"
If Sprite Visible(Window(TopWindow).Body)=1
Hide Sprite Window(TopWindow).Body
Else
Show Sprite Window(TopWindow).Body
EndIf
EndIf
If Sprite Collision(Window(TopWindow).CloseButton,SPMouse) and ButtonState="LeftPressed"
Hide Sprite Window(TopWindow).Bar
Hide Sprite Window(TopWindow).Body
Hide Sprite Window(TopWindow).MinButton
Hide Sprite Window(TopWindow).CloseButton
Hide Sprite Window(TopWindow).LockButton
EndIf
EndIf
If Sprite Collision(Window(TopWindow).LockButton,SPMouse) and ButtonState="LeftPressed"
If Window(TopWindow).Locked=1
Window(TopWindow).Locked=0
DistanceX=Window(TopWindow).X-Mousex()
DistanceY=Window(TopWindow).Y-Mousey()
Set Sprite Diffuse Window(TopWindow).LockButton, 255,255,255
Else
Window(TopWindow).Locked=1
Set Sprite Diffuse Window(TopWindow).LockButton, 255, 0, 0
EndIf
EndIf
EndIf
EndFunction
Function SetWindowtoTop(aWindow as Integer)
Set Sprite Diffuse Window(Array Count(Window())).Bar, 255,255, 255
Set Sprite Diffuse Window(Array Count(Window())).Body, 255,255, 255
Local TempWin as Window
TempWin=Window(aWindow)
Array Delete Element Window(),aWindow
Array Insert At Bottom Window()
BottomWin=Array Count(Window())
Window(BottomWin)=TempWin
Set Sprite Diffuse Window(Array Count(Window())).Bar,0, 255,0
Set Sprite Diffuse Window(Array Count(Window())).Body, 0, 255, 0
For aWin=0 to Array Count(Window())
Set Sprite Priority Window(aWin).Bar ,(aWin+1)*100
Set Sprite Priority Window(aWin).Body ,(aWin+1)*100
Set Sprite Priority Window(aWin).MinButton ,(aWin+1.1)*100
Set Sprite Priority Window(aWin).CloseButton ,(aWin+1.1)*100
Set Sprite Priority Window(aWin).LockButton ,(aWin+1.1)*100
Next aWin
EndFunction
Function GetIDNumber()
If GetIDInit=0
Dim ID(0) as Integer
Global GetIDInit as Boolean : GetIDInit=1
EndIf
If Array Count(ID())>10000
End
EndIf
Local IDNum as Integer : IDNum =(Rnd(10000)+1)
Local Unique as Boolean
Repeat
If Unique=0
Unique=1
For aID=1 to Array Count(ID())
If ID(aID) = IDNum then IDNum=(Rnd(10000)+1) : Unique=0
Next aID
EndIf
Until Unique=1
Array Insert at Bottom ID()
ID(Array Count(ID())) = IDNum
EndFunction IDNum
Function UpdateMouse()
If MouseInit=0
Global SPMouse as Integer : SPMouse = GetIDNumber()
Get Image SPMouse,0,0,1,1 : Sprite SPMouse,Mousex(),Mousey(),SPMouse : Hide Sprite SPMouse
Global LastTab as Integer
Global LastMClick as Integer
Global MClick as Integer
Global ButtonState as String
Global MousePosX# as Integer
Global MousePosY# as Integer
Global MouseInit as Boolean
MouseInit=1
EndIf
LastMClick=MClick
MClick=MouseClick()
If MClick=0 and LastMClick=0 then ButtonState="NotPressed"
If MClick=1 and LastMClick=0 then ButtonState="LeftPressed"
If MClick=1 and LastMClick=1 then ButtonState="LeftHeld"
If MClick=0 and LastMClick=1 then ButtonState="LeftLifted"
If MClick=2 and LastMClick=0 then ButtonState="RightPressed"
If MClick=2 and LastMClick=2 then ButtonState="RightHeld"
If MClick=0 and LastMClick=2 then ButtonState="RightLifted"
Sprite SPMouse,MousePosX#,MousePosY#,SPMouse
MousePosX# = Mousex()
MousePosY# = Mousey()
Endfunction
Function SetColorAlpha(ImageNumber as Integer, Color as String, Transparency as Byte)
Make Memblock from Image 1,ImageNumber
Local Width as Dword : Width = Memblock Dword(1,0)
Local Height as Dword : Height = Memblock Dword(1,4)
Local Depth as Dword : Depth = Memblock Dword(1,8)
Local PixelPointer as Integer PixelPointer=12
For Y=1 to Height
For X=1 to Width
PixelColor as String
PixelColor=Str$(Memblock Byte(1 , PixelPointer+2)) + "," + Str$(Memblock Byte(1 , PixelPointer+1)) + "," + Str$(Memblock Byte(1 , PixelPointer))
If PixelColor=Color
Write Memblock Byte 1, PixelPointer+3,Transparency
EndIf
PixelPointer=PixelPointer+4
Next X
Next Y
Delete Image ImageNumber
Make Image From Memblock ImageNumber,1
EndFunction
|