Je me suis amusé à faire ça.
Publié : mar. 28/août/2007 19:29
Je me suis amusé à faire ce truc, mais alors faut pas me demander à quoi ça peut servir, j'en ai pas la moindre idée. 

Code : Tout sélectionner
Enumeration
#WinMain
EndEnumeration
Enumeration
#Spin_Taille
#Btn_Police
#Cmb_Caracteres
#Image
EndEnumeration
Macro ChangeSpin(Gadget, valeur)
a = Val(GetGadgetText(Gadget)) : a + valeur
SetGadgetState(Gadget, a)
SetGadgetText(Gadget, Str(GetGadgetState(Gadget)))
EndMacro
Procedure CreeImage(Font, Lettre.s, Couleur, Fond)
If CreateImage(0, 400, 400)
StartDrawing(ImageOutput(0))
Box(0, 0, GadgetWidth(#Image), GadgetHeight(#Image), RGB($FF,$FF,$FF))
DrawingMode(#PB_2DDrawing_Transparent)
DrawingFont(Font)
H = TextHeight(Lettre) : L = TextWidth(Lettre)
x = 200 - (L/2) : y = 200 - (H/2)
DrawText(x, y, Lettre, Couleur, Fond)
StopDrawing()
EndIf
SetGadgetState(#Image, ImageID(0))
EndProcedure
FontName.s = "Arial"
FontStyle = #PB_Font_Bold
FontSize = 100
FontColor = $000000
If OpenWindow(#WinMain, 0, 0, 515, 410, "ImageGadget", #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered )
If CreateGadgetList(WindowID(0))
ImageGadget(#Image, 5, 5, 400, 400, 0)
ComboBoxGadget(#Cmb_Caracteres, 410, 5, 45, 200)
ButtonGadget(#Btn_Police, 460, 5, 50, 20, "Police")
SpinGadget(#Spin_Taille, 410, 35, 100, 20, 0, 400)
EndIf
SetGadgetState(#Spin_Taille, FontSize)
SetGadgetText(#Spin_Taille, Str(GetGadgetState(#Spin_Taille)))
For i = '!' To 'ÿ'
If i <> 38 And i <> 127 And i <> 129 And i <> 141 And i <> 143 And i <> 144 And i <> 157
AddGadgetItem(#Cmb_Caracteres, -1, Chr(i))
EndIf
Next
SetGadgetState(#Cmb_Caracteres, 0)
Lettre.s = GetGadgetItemText(#Cmb_Caracteres, GetGadgetState(#Cmb_Caracteres),0)
LoadFont(0, FontName, FontSize, FontStyle)
CreeImage(FontID(0), Lettre, FontColor, RGB($FF,$FF,$FF))
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow : Quit = #True
Case #PB_Event_Gadget
Select EventGadget()
Case #Btn_Police
Font = FontRequester(FontName, GetGadgetState(#Spin_Taille), #PB_FontRequester_Effects, RGB($0,$0,$0))
If Font
FontName = SelectedFontName()
FontSize = SelectedFontSize()
FontStyle = SelectedFontStyle() : Debug FontStyle
FontColor = SelectedFontColor()
LoadFont(0, FontName, FontSize, FontStyle)
CreeImage(FontID(0), Lettre, FontColor, RGB($FF,$FF,$FF))
SetGadgetState(#Spin_Taille, FontSize)
SetGadgetText(#Spin_Taille, Str(GetGadgetState(#Spin_Taille)))
EndIf
Case #Spin_Taille
Select EventType()
Case -1
ChangeSpin(#Spin_Taille, -10)
LoadFont(0, FontName, GetGadgetState(#Spin_Taille), FontStyle)
CreeImage(FontID(0), Lettre, FontColor, RGB($FF,$FF,$FF))
Case 1
ChangeSpin(#Spin_Taille, 10)
LoadFont(0, FontName, GetGadgetState(#Spin_Taille), FontStyle)
CreeImage(FontID(0), Lettre, FontColor, RGB($FF,$FF,$FF))
EndSelect
Case #Cmb_Caracteres
If EventType() = #CBN_SELCHANGE
Lettre = GetGadgetItemText(#Cmb_Caracteres, GetGadgetState(#Cmb_Caracteres),0)
CreeImage(FontID(0), Lettre, FontColor, RGB($FF,$FF,$FF))
EndIf
EndSelect
EndSelect
Until Quit
EndIf
End
; jaPBe Version=3.7.8.661
; Build=0
; Language=0x0000 Language Neutral
; FirstLine=0
; CursorPosition=11
; EnableXP
; ExecutableFormat=Windows
; DontSaveDeclare
; EOF
; IDE Options = PureBasic Visual Designer v4.0 Alpha 15 build 651
; VD_UsePB_Any = 0
; VD_IncludeBinaryBitmaps = 1
; VD_IncludeXPskins = 0