Comment afficher un curseur personnaliser dans un canevas sans utiliser d'API ?
Ensuite n'y à t-il pas plus simple que ceci ?:
Code : Tout sélectionner
; Créate by Stargate 13/08/2020.
Enumeration
#Window
#Gadget
#Image
EndEnumeration
Procedure SetGadgetCursorImage(Gadget.i, Image.i, HotSpotX.i=0, HotSpotY.i=0)
Protected *Handle = GetGadgetAttribute(Gadget, #PB_Canvas_CustomCursor)
Protected FileName.s = GetTemporaryDirectory()+"cursor.cur"
Protected BitmapInfoHeader.BITMAPINFOHEADER
Protected Width.i = 32, Height = 32
If *Handle
DestroyCursor_(*Handle)
EndIf
File = CreateFile(#PB_Any, FileName)
If File
WriteWord(File, 0) ; Reserved
WriteWord(File, 2) ; Image type (2 = cursor)
WriteWord(File, 1) ; Number of images
; Layer
WriteAsciiCharacter(File, Width) ; Width
WriteAsciiCharacter(File, Height) ; Height
WriteAsciiCharacter(File, 0) ; Colors
WriteAsciiCharacter(File, 0) ; Reserved
WriteWord(File, HotSpotX) ; Color planes
WriteWord(File, HotSpotY) ; Bits per pixel
WriteLong(File, SizeOf(BITMAPINFOHEADER)+Width*Height*4)
WriteLong(File, Loc(File)+4) ; Data location
; Datas
With BitmapInfoHeader
\biSize = SizeOf(BITMAPINFOHEADER)
\biWidth = Width
\biHeight = Height*2
\biPlanes = 1
\biBitCount = 32
EndWith
WriteData(File, BitmapInfoHeader, SizeOf(BitmapInfoHeader))
If StartDrawing(ImageOutput(Image))
DrawingMode(#PB_2DDrawing_AllChannels)
For Y = Height-1 To 0 Step -1
For X = 0 To Width-1
If Y < ImageHeight(Image) And X < ImageWidth(Image)
Color = Point(X, Y)
Else
Color = $00000000
EndIf
WriteLong(File, Color&$FF00FF00|((Color&$FF)<<16)|((Color>>16)&$FF))
Next
Next
StopDrawing()
EndIf
CloseFile(File)
EndIf
SetGadgetAttribute(Gadget, #PB_Canvas_CustomCursor, LoadCursorFromFile_(@FileName))
EndProcedure
Debug #PB_Compiler_Home
OpenWindow(#Window, 0, 0, 800, 450, "Vector Canvas Gadget", #PB_Window_MaximizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
CanvasGadget(#Gadget, 0, 0, WindowWidth(#Window), WindowHeight(#Window), #PB_Canvas_Keyboard)
UsePNGImageDecoder()
LoadImage(#Image, #PB_Compiler_Home+"Examples\Sources\Data\world.png") ; Load your image
SetGadgetCursorImage(#Gadget, #Image, 8, 8) ; Last two parameters are the hot spot of the cursor
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver
End