368 lines
10 KiB
Plaintext
368 lines
10 KiB
Plaintext
;-NewBitmap
|
|
|
|
Structure myFontData
|
|
x.l
|
|
y.l
|
|
Width.l
|
|
Height.l
|
|
EndStructure
|
|
|
|
Structure BitmapFont
|
|
SpriteId.i
|
|
FirstClipSpriteId.l
|
|
AsciiStart.c
|
|
AsciiEnd.c
|
|
Array Tab.l(10)
|
|
Array FontData.myFontData(1)
|
|
EndStructure
|
|
|
|
Global NewList BitmapFont.BitmapFont()
|
|
|
|
Procedure.i CatchBitmapFont(FirstClipSpriteId.l,FontFileName.S)
|
|
Protected z.l
|
|
Protected *Mem,*Dat
|
|
*Mem=AddElement(BitmapFont())
|
|
BitmapFont()\FirstClipSpriteId=FirstClipSpriteId
|
|
|
|
*Dat=ReadDataPackage("Datas.pck",FontFileName+".dat")
|
|
BitmapFont()\AsciiStart=PeekB(*Dat)
|
|
BitmapFont()\AsciiEnd=PeekB(*Dat+1)
|
|
;Debug BitmapFont()\AsciiStart
|
|
;Debug BitmapFont()\AsciiEnd
|
|
;ShowMemoryViewer(*Dat,MemorySize(*Dat))
|
|
;End
|
|
ReDim BitmapFont()\FontData(BitmapFont()\AsciiEnd-BitmapFont()\AsciiStart)
|
|
CopyMemory(*Dat+2,@BitmapFont()\FontData(),SizeOf(myFontData)*ArraySize(BitmapFont()\FontData()))
|
|
FreeMemory(*Dat)
|
|
; If OpenFile(0,"Datas/"+FileName+".dat")
|
|
; BitmapFont()\AsciiStart=ReadCharacter(0,#PB_Ascii)
|
|
; BitmapFont()\AsciiEnd=ReadCharacter(0,#PB_Ascii)
|
|
; ReDim BitmapFont()\FontData(BitmapFont()\AsciiEnd-BitmapFont()\AsciiStart)
|
|
; ReadData(0,@BitmapFont()\FontData(),SizeOf(myFontData)*ArraySize(BitmapFont()\FontData()))
|
|
; CloseFile(0)
|
|
; EndIf
|
|
BitmapFont()\SpriteId=CatchSpriteFromPackage(#PB_Any,FontFileName+".png");LoadSprite(#PB_Any,"Datas/"+FileName+".png",#PB_Sprite_AlphaBlending)
|
|
If IsSprite(BitmapFont()\SpriteId)
|
|
For z=0 To ArraySize(BitmapFont()\FontData())
|
|
RecordSprite(FirstClipSpriteId+z,BitmapFont()\SpriteId,BitmapFont()\FontData(z)\x,BitmapFont()\FontData(z)\y,BitmapFont()\FontData(z)\Width,BitmapFont()\FontData(z)\Height,BitmapFont()\FontData(z)\Width/BitmapFont()\FontData(z)\Height, 1)
|
|
Next
|
|
Else
|
|
Debug "error load font"
|
|
End
|
|
EndIf
|
|
ProcedureReturn *Mem
|
|
EndProcedure
|
|
|
|
|
|
Procedure.i LoadBitmapFont(FirstClipSpriteId.l,FileName.s="MonoFont")
|
|
Protected z.l
|
|
Protected *Mem
|
|
*Mem=AddElement(BitmapFont())
|
|
BitmapFont()\FirstClipSpriteId=FirstClipSpriteId
|
|
If OpenFile(0,"Datas/"+FileName+".dat")
|
|
BitmapFont()\AsciiStart=ReadCharacter(0,#PB_Ascii)
|
|
BitmapFont()\AsciiEnd=ReadCharacter(0,#PB_Ascii)
|
|
ReDim BitmapFont()\FontData(BitmapFont()\AsciiEnd-BitmapFont()\AsciiStart)
|
|
ReadData(0,@BitmapFont()\FontData(),SizeOf(myFontData)*ArraySize(BitmapFont()\FontData()))
|
|
CloseFile(0)
|
|
EndIf
|
|
Debug FileName+".png"
|
|
BitmapFont()\SpriteId=LoadSprite(#PB_Any,"Datas/"+FileName+".png",#PB_Sprite_AlphaBlending)
|
|
If IsSprite(BitmapFont()\SpriteId)
|
|
For z=0 To ArraySize(BitmapFont()\FontData())
|
|
RecordSprite(FirstClipSpriteId+z,BitmapFont()\SpriteId,BitmapFont()\FontData(z)\x,BitmapFont()\FontData(z)\y,BitmapFont()\FontData(z)\Width,BitmapFont()\FontData(z)\Height,BitmapFont()\FontData(z)\Width/BitmapFont()\FontData(z)\Height, 1)
|
|
Next
|
|
Else
|
|
Debug "error load font"
|
|
End
|
|
EndIf
|
|
ProcedureReturn *Mem
|
|
EndProcedure
|
|
|
|
Procedure TextBitmapWidth(string.s)
|
|
Protected l.l,c.l,n.l,width.l,size.l=0
|
|
Protected tabIndex.l=0
|
|
For l=0 To Len(String)-1
|
|
c=Asc(Mid(String,l+1,1));-BitmapFont()\AsciiStart
|
|
width=0
|
|
If c=9 ; TAB
|
|
Width=BitmapFont()\Tab(tabIndex) -Size
|
|
tabIndex=tabIndex+1
|
|
ElseIf c=32; Espace and _
|
|
Width=GUI\HalfBlockSize
|
|
Else
|
|
c=c-BitmapFont()\AsciiStart
|
|
If c>=1 And c<BitmapFont()\AsciiEnd
|
|
Width=(BitmapFont()\FontData(c)\Width)*GUI\BlockSize/BitmapFont()\FontData(0)\Height*0.85
|
|
Else
|
|
|
|
Width=GUI\HalfBlockSize
|
|
EndIf
|
|
EndIf
|
|
size=size+Width
|
|
Next
|
|
ProcedureReturn size
|
|
EndProcedure
|
|
|
|
Procedure DrawingBitmapFont(FontId)
|
|
If FontId>-1 And FontID<ListSize(BitmapFont())
|
|
SelectElement(BitmapFont(),FontId)
|
|
EndIf
|
|
EndProcedure
|
|
|
|
Procedure DrawBitmapText(X.l,Y.l,String.s,Alpha.l=255)
|
|
Protected l.l,p.l,c.l,Spr.l,width.l
|
|
Protected tabIndex.l=0
|
|
For l=0 To Len(String)-1
|
|
c=Asc(Mid(String,l+1,1))
|
|
width=0
|
|
If c=9 ;TAB
|
|
Width=BitmapFont()\Tab(tabIndex) -X
|
|
tabIndex=tabIndex+1
|
|
ElseIf c=32; Espace
|
|
Width=GUI\HalfBlockSize
|
|
Else
|
|
c=c-BitmapFont()\AsciiStart
|
|
If c>=1 Or c<BitmapFont()\AsciiEnd
|
|
spr=BitmapFont()\FirstClipSpriteId+c
|
|
DisplayClipSprite(Spr,X ,Y,Alpha)
|
|
Width=(BitmapFont()\FontData(c)\Width) * GUI\BlockSize/BitmapFont()\FontData(0)\Height*0.85
|
|
Else
|
|
Width=GUI\HalfBlockSize
|
|
EndIf
|
|
EndIf
|
|
X=X+Width
|
|
Next
|
|
EndProcedure
|
|
|
|
Structure TextTitle
|
|
FondId.l
|
|
Text.s
|
|
Alpha.l
|
|
Selected.b
|
|
EndStructure
|
|
Structure Titles
|
|
List Title.TextTitle()
|
|
ScrollY.f ;Must be Float to scroll with low resolution
|
|
StartTime.q
|
|
LineSpacing.f
|
|
Alpha.f
|
|
Center.b ; #True center Text #False No center
|
|
Event.l ;
|
|
Speed.l ;6000
|
|
EndStructure
|
|
|
|
Structure TextData
|
|
FontId.l
|
|
String.s
|
|
X.l
|
|
Y.l
|
|
Width.l
|
|
Height.l
|
|
Opacity.l
|
|
Align.c
|
|
Depth.l
|
|
Autodestroy.b
|
|
EndStructure
|
|
|
|
Global NewList Texts.TextData()
|
|
|
|
Procedure NewText(FontId.l,String.s,X.l,Y.l,Opacity.l=255,Depth.l=#Spr_Depth_Front,Align=9)
|
|
Protected *Mem
|
|
*Mem=AddElement(Texts())
|
|
Texts()\FontId=FontId
|
|
Texts()\String=String
|
|
Texts()\X=X
|
|
Texts()\Y=Y
|
|
Texts()\Opacity=Opacity
|
|
Texts()\Depth=Depth
|
|
Texts()\Align=Align
|
|
DrawingBitmapFont(FontId)
|
|
Texts()\Width=TextBitmapWidth(String)
|
|
Texts()\Height=GUI\BlockSize
|
|
ProcedureReturn *Mem
|
|
EndProcedure
|
|
|
|
|
|
Procedure ChangeText(*TextData.TextData,String.s)
|
|
*TextData\String=String
|
|
DrawingBitmapFont(*TextData\FontId)
|
|
*TextData\Width=TextBitmapWidth(String)
|
|
EndProcedure
|
|
|
|
Procedure DisplayText(*Text.TextData)
|
|
Protected X.l
|
|
Protected Y.l
|
|
If *Text\Align & #Align_Hor_Left = #Align_Hor_Left
|
|
X=*Text\X
|
|
EndIf
|
|
|
|
If *Text\Align & #Align_Hor_Middle = #Align_Hor_Middle
|
|
X=*Text\X-*Text\Width/2;* Texts()\Size
|
|
EndIf
|
|
|
|
If *Text\Align & #Align_Hor_Right = #Align_Hor_Right
|
|
X=*Text\X-*Text\Width ;* Texts()\Size
|
|
EndIf
|
|
|
|
If *Text\Align & #Align_Ver_Top = #Align_Ver_Top
|
|
Y=*Text\Y
|
|
EndIf
|
|
|
|
If *Text\Align & #Align_Ver_Middle=#Align_Ver_Middle
|
|
Y=*Text\Y-*Text\Height/2;* Texts()\Size
|
|
EndIf
|
|
If *Text\Align & #Align_Ver_Bottom= #Align_Ver_Bottom
|
|
Y=*Text\Y-*Text\Height;* Texts()\Size
|
|
EndIf
|
|
DrawingBitmapFont(*Text\FontId)
|
|
DrawBitmapText(X,Y,*Text\String,*Text\Opacity)
|
|
;Debug Str(*Text\FontId)+" "+*Text\String
|
|
EndProcedure
|
|
|
|
Procedure DisplayTexts(Depth.l=#Spr_ALL)
|
|
|
|
Debug ListSize(Texts())
|
|
ForEach Texts()
|
|
If Depth=#Spr_ALL Or Texts()\Depth=Depth
|
|
DisplayText(Texts())
|
|
EndIf
|
|
Next
|
|
EndProcedure
|
|
|
|
Procedure ClearAllText()
|
|
ClearList(Texts())
|
|
EndProcedure
|
|
;-Tilte
|
|
|
|
Global Titles.Titles
|
|
|
|
Procedure ClearTitles()
|
|
ClearList(Titles\Title())
|
|
Titles\Event=-1
|
|
Titles\ScrollY=0
|
|
Titles\Speed=6000
|
|
Titles\StartTime=ElapsedMilliseconds()
|
|
EndProcedure
|
|
|
|
Procedure TitlesCenter(Center.b=#True)
|
|
Titles\Center=Center
|
|
EndProcedure
|
|
|
|
Procedure TitlesEvent(Event.l);todo Je suis rendu là
|
|
Titles\Event=Event
|
|
EndProcedure
|
|
|
|
Procedure AddTitle(Text.s,FontId=-1,Alpha.l=255,Selected.b=#False)
|
|
AddElement(Titles\Title())
|
|
Titles\Title()\Text=Text
|
|
Titles\Title()\FondId=FontId
|
|
Titles\Title()\Alpha=Alpha
|
|
Titles\Title()\Selected=Selected
|
|
EndProcedure
|
|
|
|
;-####################################
|
|
|
|
;AddElement(Title()):Title()="Copyright 1990 Software LTD"
|
|
|
|
Procedure DisplayTitles()
|
|
If Titles\StartTime=0:Titles\StartTime=ElapsedMilliseconds():EndIf
|
|
|
|
If ListSize(Titles\Title())>0
|
|
Protected RealLineSpacing=Titles\LineSpacing*GUI\BlockSize
|
|
Protected LineHeight.f=GUI\BlockSize+RealLineSpacing
|
|
|
|
Titles\ScrollY=Titles\ScrollY+ ScreenHeight()*(ElapsedMilliseconds()-Titles\StartTime)/Titles\Speed ;6000
|
|
If Titles\ScrollY>ScreenHeight()+ ListSize(Titles\Title())* LineHeight
|
|
If Titles\Event>-1:
|
|
PostEventGUI(Titles\Event)
|
|
EndIf
|
|
Titles\ScrollY=0
|
|
EndIf
|
|
ForEach Titles\Title()
|
|
DrawingBitmapFont(Titles\Title()\FondId)
|
|
Protected.l Y=ScreenHeight() + ListIndex(Titles\Title()) * LineHeight - Titles\ScrollY
|
|
If Y>-LineHeight And Y<ScreenHeight()
|
|
Protected X.l
|
|
If Titles\Center=#True
|
|
X=(ScreenWidth()-TextBitmapWidth(Titles\Title()\Text))/2
|
|
Else
|
|
X=0
|
|
EndIf
|
|
Protected Alpha.l
|
|
If Titles\Title()\Alpha=255
|
|
Alpha=Titles\Alpha
|
|
Else
|
|
Alpha=Titles\Title()\Alpha * Titles\Alpha / 255
|
|
EndIf
|
|
If Titles\Title()\Selected=#True
|
|
DisplayClipSprite(#Spr_White,0,Y,200,1,ScreenWidth(),GUI\BlockSize)
|
|
EndIf
|
|
DrawBitmapText(X,Y,Titles\Title()\Text,Alpha)
|
|
EndIf
|
|
Next
|
|
Titles\StartTime=ElapsedMilliseconds()
|
|
EndIf
|
|
EndProcedure
|
|
|
|
;- Message
|
|
|
|
Structure Message
|
|
String.s
|
|
Font.l
|
|
StartTime.q
|
|
Duration.l
|
|
FadeDuration.l
|
|
MessStep.l
|
|
EndStructure
|
|
|
|
Global NewList Message.Message()
|
|
|
|
Procedure NewMessage(String.s,Font.l=0,Duration.l=2000,FadeDuration.l=500)
|
|
AddElement(Message())
|
|
Message()\String=String
|
|
Message()\Font=Font
|
|
Message()\Duration=Duration
|
|
Message()\FadeDuration=FadeDuration
|
|
EndProcedure
|
|
|
|
Procedure DisplayMessage()
|
|
If FirstElement(Message())
|
|
Protected Fade.l
|
|
Select Message()\MessStep
|
|
Case 0;In
|
|
If Message()\StartTime=0:Message()\StartTime=ElapsedMilliseconds()+Message()\FadeDuration:EndIf
|
|
Fade=255-Int((Message()\StartTime-ElapsedMilliseconds())*255/Message()\FadeDuration)
|
|
If ElapsedMilliseconds()>Message()\StartTime
|
|
Message()\MessStep=Message()\MessStep+1
|
|
Message()\StartTime=0
|
|
EndIf
|
|
Case 1; Display
|
|
If Message()\StartTime=0:Message()\StartTime=ElapsedMilliseconds()+Message()\Duration:EndIf
|
|
If ElapsedMilliseconds()>Message()\StartTime
|
|
Message()\MessStep=Message()\MessStep+1
|
|
Message()\StartTime=0
|
|
EndIf
|
|
Fade=255
|
|
Case 2;
|
|
If Message()\StartTime=0:Message()\StartTime=ElapsedMilliseconds()+Message()\FadeDuration:EndIf
|
|
Fade=Int((Message()\StartTime-ElapsedMilliseconds())*255/Message()\FadeDuration)
|
|
If ElapsedMilliseconds()>Message()\StartTime
|
|
Message()\MessStep=Message()\MessStep+1
|
|
Message()\StartTime=0
|
|
EndIf
|
|
Case 3
|
|
EndSelect
|
|
DrawingBitmapFont(Message()\Font)
|
|
Protected Width.l=TextBitmapWidth(Message()\String)
|
|
DrawBitmapText((ScreenWidth()-Width)/2,GUI\BenchY+GUI\BenchHeight,Message()\String,Fade)
|
|
If Message()\MessStep=3
|
|
DeleteElement(Message())
|
|
EndIf
|
|
EndIf
|
|
EndProcedure
|
|
; IDE Options = PureBasic 6.11 LTS (Windows - x64)
|
|
; CursorPosition = 255
|
|
; FirstLine = 255
|
|
; Folding = ---
|
|
; EnableXP |