Code
UseJPEGImageDecoder()
h=LoadImage(100, "c:\Program Files\PureBasic\Examples\Sources\Data\clouds.jpg")
If OpenWindow(200, 0, 0, 256, 256, "2DDrawing Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ImageGadget(101,0,0,200,200, ImageID(100))
If CreateImage(102, 256, 256) And StartDrawing(ImageOutput(100))
DrawingMode(#PB_2DDrawing_Transparent)
For i = 1 To 30
DrawText(Random(200), Random(200), "Hello World!", RGB(Random(255), Random(255), Random(255)))
Next i
StopDrawing()
ImageGadget(111, 0, 0, 256, 256, ImageID(100))
EndIf
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
Code
Enumeration
#Window
EndEnumeration
Enumeration
#Gad_Image_1
#Button_End
#Button_New
#Button_Reset
EndEnumeration
Enumeration
#Image_1
#Image_2
EndEnumeration
Enumeration
#Font_1
EndEnumeration
Procedure MakeNewText( Text.s )
StartDrawing(ImageOutput(#Image_2))
DrawImage( ImageID(#Image_1), 0, 0 )
DrawingMode(#PB_2DDrawing_Transparent)
DrawingFont(FontID(#Font_1))
DrawText(250, 700, Text, $0000FF)
StopDrawing()
SetGadgetState( #Gad_Image_1, ImageID( #Image_2 ) )
If IsGadget(#Button_New) : InvalidateRect_(GadgetID(#Button_New), 0, 1) : EndIf
If IsGadget(#Button_End) : InvalidateRect_(GadgetID(#Button_End), 0, 1) : EndIf
If IsGadget(#Button_Reset) : InvalidateRect_(GadgetID(#Button_Reset), 0, 1) : EndIf
EndProcedure
LoadFont(#Font_1,"Arial",50, #PB_Font_Bold)
UseJPEGImageDecoder()
h=LoadImage(#Image_1, "c:\Program Files\PureBasic\Examples\Sources\Data\terrain_texture.jpg")
If OpenWindow(#Window, 0, 0, 1024, 1024, "2DDrawing Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ImageGadget(#Gad_Image_1,0,0,1024,1024, ImageID(#Image_1))
DisableGadget( #Gad_Image_1, 1 ) ; necessary for background imagegadgets
CreateImage(#Image_2, 1024, 1024)
MakeNewText( "Hello World!" )
ButtonGadget(#Button_End, 8, 150, 100,30,"End")
ButtonGadget(#Button_New, 136, 150, 100,30,"New")
ButtonGadget(#Button_Reset, 8, 190, 100,30,"Reset")
Repeat
Event = WaitWindowEvent()
EvGad = EventGadget()
Select Event
Case #PB_Event_Repaint
StartDrawing(WindowOutput(WinMain))
; Debug "Redrawing"
StopDrawing()
Case #PB_Event_Gadget
Select EvGad
Case #Button_New
counter +1
MakeNewText( "click no. "+Str(counter) )
Case #Button_Reset
counter=0
MakeNewText("Reset ... "+Str(counter))
Case #Button_End
EXIT = #True
EndSelect
Case #PB_Event_CloseWindow
EXIT = #True
EndSelect
Until EXIT
EndIf