ce n'est pas tout a fait finit, mais voilà je partage le code.
vous pouvez modifier les courbes en déplaçant les points verts.
Code : Tout sélectionner
Structure SpeedGadgetParam
Gadget.l
Image.l
Slct.l ;selection du point
Sx.l
Sy.l
P1x.l
P1y.l
P2x.l
P2y.l
Ex.l
Ey.l
EndStructure
Global NewList SpeedGadgetParam.SpeedGadgetParam()
Procedure WindowMouseButton(Wnd, ButtonNr)
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
;Linux Version
Protected gdkWnd.l, x.l, y.l, mask.l
If Wnd
*Window.GTKWindow = Wnd
gdkWnd = *Window\bin\child\window
gdk_window_get_pointer_(gdkWnd, @x, @y, @mask)
Select ButtonNr
Case 0
If (mask & #GDK_BUTTON1_MASK)
ProcedureReturn 1
EndIf
Case 1
If (mask & #GDK_BUTTON3_MASK)
ProcedureReturn 1
EndIf
Case 2
If (mask & #GDK_BUTTON2_MASK)
ProcedureReturn 1
EndIf
EndSelect
EndIf
CompilerElse
;Windows Version
If Wnd And GetForegroundWindow_() = Wnd
Select ButtonNr
Case 0
If GetAsyncKeyState_(#VK_LBUTTON) > 0
ProcedureReturn 1
EndIf
Case 1
If GetAsyncKeyState_(#VK_RBUTTON) > 0
ProcedureReturn 1
EndIf
Case 2
If GetAsyncKeyState_(#VK_MBUTTON) > 0
ProcedureReturn 1
EndIf
EndSelect
EndIf
CompilerEndIf
ProcedureReturn 0
EndProcedure
Procedure FastTrace()
With SpeedGadgetParam()
old_x=\Sx
old_y=\Sy
Esp.l=10
For Bt=0 To Esp
t.f=Bt/Esp
x = \Sx*Pow((1-t),3) + 3*\P1x*Pow((1-t),2)*t + 3*\P2x*(1-t)*Pow(t,2) + \Ex*Pow(t,3)
y = \Sy*Pow((1-t),3) + 3*\P1y*Pow((1-t),2)*t + 3*\P2y*(1-t)*Pow(t,2) + \Ey*Pow(t,3)
LineXY(x,y,old_x,old_y,#White)
old_x=x
old_y=y
Next
EndWith
EndProcedure
Procedure RenderSpeedGadget()
Static OldMouseX.l,OldMouseY.l
ResetList(SpeedGadgetParam())
With SpeedGadgetParam()
While NextElement(SpeedGadgetParam())
If WindowMouseButton(WindowID(0), 0);EventType()=#PB_EventType_LeftClick EventGadget()=\Gadget
x=WindowMouseX(0)-GadgetX(\Gadget)
y=WindowMouseY(0)-GadgetY(\Gadget)
If OldMouseX=0:OldMouseX=x:EndIf
If OldMouseY=0:OldMouseY=y:EndIf
DeltaMX=x-OldMouseX:OldMouseX=x
DeltaMY=y-OldMouseY:OldMouseY=y
;If DeltaMX0 And DeltaMY<>0
\Slct=0
If x>\Sx-3 And x<\Sx+3 And y>\Sy-3 And y<\Sy+3
\Slct=1
ElseIf x>\P1x-9 And x<\P1x+9 And y>\P1y-9 And y<\P1y+9
\Slct=2
ElseIf x>\P2x-9 And x<\P2x+9 And y>\P2y-9 And y<\P2y+9
\Slct=3
ElseIf x>\Ex-3 And x<\Ex+3 And y>\Ey-3 And y<\Ey+3
\Slct=4
EndIf
;Else
Select \Slct
Case 1:
Case 2
\P1x=x
\P1y=y
Case 3:
\P2x=x
\P2y=y
Case 4:
EndSelect
;EndIf
EndIf
StartDrawing(ImageOutput(\Image))
Box(0,0,ImageWidth(\Image),ImageHeight(\Image),#Black)
FastTrace()
Circle(x,y,c,RGB(255,0,255))
Circle(\Sx,\Sy,5,#Red)
Circle(\P1x,\P1y,5,#Green)
Circle(\P2x,\P2y,5,#Green)
Circle(\Ex,\Ey,5,#Red)
StopDrawing()
SetGadgetState(\Gadget,ImageID(\Image))
Wend
EndWith
EndProcedure
Procedure SpeedGadget(Gadget.l, x.l, y.l, Largeur.l, Hauteur.l)
i=CreateImage(#PB_Any,Largeur.l,Hauteur.l)
ImageGadget(Gadget, x, y, Largeur, Hauteur, ImageID(i), #PB_Image_Border)
AddElement(SpeedGadgetParam())
SpeedGadgetParam()\Gadget=Gadget
SpeedGadgetParam()\Image=i
SpeedGadgetParam()\Sx=0
SpeedGadgetParam()\Sy=Int(Hauteur/2)
SpeedGadgetParam()\P1x=Int(Largeur/3)
SpeedGadgetParam()\P1y=Int(Hauteur/2)
SpeedGadgetParam()\P2x=Int(Largeur/3)*2
SpeedGadgetParam()\P2y=Int(Hauteur/2)
SpeedGadgetParam()\Ex=Largeur
SpeedGadgetParam()\Ey=Int(Hauteur/2)
RenderSpeedGadget()
EndProcedure
If OpenWindow(0, 100, 250, 300, 300, "PureBasic Window", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
CreateGadgetList(WindowID(0))
SpeedGadget(1, 20, 20, 200, 100)
SpeedGadget(2, 20, 150, 200, 100)
Repeat
EventID = WaitWindowEvent()
RenderSpeedGadget()
If EventID = #PB_Event_CloseWindow ; If the user has pressed on the close button
Quit = 1
EndIf
Until Quit = 1
EndIf