Voila un potentiomètre circulaire, j'ai commencer le mouvement mais cela ne me convient pas. Au moins cela montre ce que cela donnera, une fois fini. Mais c'est encore en test et donc le code est pas très propre (voir sale).

En gros je voudrais arriver a suivre le mouvement de la souris en rotation (mais la, j'y arrive pas encore).
Le code :
Code : Tout sélectionner
; +======================================================+
; | |
; +------------------------------------------------------+
; | COPYRIGHT(C)2007-2015, ALL RIGHT RESERVED KOAKDESIGN |
; +--------------+---------------------------------------+
; | Program/Vers | PUREBASIC 5.31 |
; +--------------+---------------------------------------+
; | VER & REV | 0.0.1 |
; +--------------+---------------------------------------+
; | Program name | |
; +======================================================+
; +======================================================+
; | Original Version: 0.0.1 |
; +--------------+---------------------------------------+
; | Created by | |
; | Graphix by | |
; +--------------+---------------------------------------+
; | Comments: | |
; +--------------+ |
; | |
; | |
; | |
; +======================================================+
; +======================================================+
; | Système d'Exploitation |
; +--------------+---------------------------------------+
; | Window | Oui |
; | Linux | Oui |
; | MacOS | Oui |
; +======================================================+
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; +--------------------------------------------------------------------------+
; | |
; +--------------------------------------------------------------------------+
EnableExplicit
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; +--------------------------------------------------------------------------+
; | |
; +--------------------------------------------------------------------------+
Enumeration
#Window
#Canvas
EndEnumeration
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; +--------------------------------------------------------------------------+
; | |
; +--------------------------------------------------------------------------+
Global precalc.f = 2 * #PI / 360
Procedure.f GSin(angle.f)
; CALCUL DU PRECALCUL DES SINUS.
ProcedureReturn Sin(angle * precalc)
EndProcedure
Procedure.f GCos(angle.f)
; CALCUL DU PRECALCUL DES COSINUS.
ProcedureReturn Cos(angle * precalc)
EndProcedure
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; +--------------------------------------------------------------------------+
; | |
; +--------------------------------------------------------------------------+
Procedure ACircle(x.i, y.i, radius.d, antilenh.d, color.i)
;
Define.l lR, lG, lB
Define.d dNormal, dValue
If radius <= 0
radius = 0.00001
EndIf
If antilenh <= 0
antilenh = 0.00001
EndIf
ResetGradientColors()
DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Gradient)
lR = Red (color)
lG = Green(color)
lB = Blue (color)
dNormal = 1 / radius
dValue = 1.0 - antilenh * dNormal
GradientColor( 0 , RGBA(lR, lG, lB, 255))
GradientColor(dValue, RGBA(lR, lG, lB, 255))
GradientColor( 1 , RGBA(lR, lG, lB, 0 ))
CircularGradient(x, y, radius)
Circle (x, y, radius)
EndProcedure
Procedure DrawValue(x.l, y.l, rayonx, rayony .l, segment.l, ilen.l, ldensity.l, value)
; ROUTINE DE TRACAGE D'UN CERCLE EN X SEGMENTS.
Define i.l
Define new_x.l
Define new_y.l
If segment < 4
segment = 4
EndIf
DrawingMode(#PB_2DDrawing_Transparent)
For i = 20 To 340 Step 20
new_x = x + GSin(i + 180) * (rayonx - ilen)
new_y = y - GCos(i + 180) * (rayony - ilen)
If i < value
ACircle(new_x, new_y, 8, 8, RGB(255,0,0))
ACircle(new_x, new_y, 3, 2, RGB(0,0,0))
ACircle(new_x, new_y, 5, 2, RGB(255,0,0))
ACircle(new_x, new_y, 2, 2, RGB(255,100,100))
Else
ACircle(new_x, new_y, 3, 2, RGB(0,0,0))
ACircle(new_x, new_y, 5, 2, RGB(100,0,0))
ACircle(new_x, new_y, 2, 2, RGB(200,0,0))
EndIf
Next i
EndProcedure
Procedure DrawCircular(WindowW, WindowH, x, y)
;
Define ircircle = WindowW / 7
Define idensity = WindowW / 100
Define dx = x - (WindowW * 0.5)
Define dy = y - (WindowW * 0.5)
Define F = Degree(ATan2(dx, dy))
Define new_x = (WindowW * 0.5) - GCos(F + 180) * ((ircircle * 2) - ircircle + 15)
Define new_y = (WindowH * 0.5) - GSin(F + 180) * ((ircircle * 2) - ircircle + 15)
F - 90
If F < 0
F = 360 + F
EndIf
StartDrawing(CanvasOutput(#Canvas))
;Box(0, 0, WindowW, WindowH, $f0f0f0)
Box(0, 0, WindowW, WindowH, RGB(0,255,255))
ACircle(WindowW*0.5, WindowH*0.5, WindowW * 0.5 - ircircle + 21, 2, RGB(0,0,0))
ACircle(WindowW*0.5, WindowH*0.5, WindowW * 0.5 - ircircle + 20, 2, RGB(60,60,60))
ACircle(WindowW*0.5 + 6, WindowH*0.5 + 10, WindowW * 0.5 - ircircle + 0, 2, RGB(50,50,50))
ACircle(WindowW*0.5 + 4, WindowH*0.5 + 8, WindowW * 0.5 - ircircle + 0, 2, RGB(40,40,40))
ACircle(WindowW*0.5 + 2, WindowH*0.5 + 6, WindowW * 0.5 - ircircle + 0, 2, RGB(30,30,30))
DrawValue(WindowW*0.5, WindowH*0.5, WindowW * 0.5 - (ircircle / 2) + 9, WindowW * 0.5 - (ircircle / 2) + 9, 100, ircircle / 2, idensity, F)
ACircle(WindowW*0.5, WindowH*0.5, WindowW * 0.5 - ircircle, 2, RGB(0,0,0))
ACircle(WindowW*0.5, WindowH*0.5, WindowW * 0.5 - ircircle - 1, 2, RGB(255,255,255))
ACircle(WindowW*0.5, WindowH*0.5, WindowW * 0.5 - ircircle - 3, 2, RGB(200,200,200))
ACircle(WindowW*0.5, WindowH*0.5, WindowW * 0.5 - ircircle - 5, 2, RGB(230,230,230))
ACircle(new_x, new_y, ircircle - 5, 2, RGB(0,0,0))
ACircle(new_x, new_y, ircircle - 6, 2, RGB(160,160,160))
ACircle(new_x, new_y, ircircle - 7, 2, RGB(180,180,180))
ACircle(new_x, new_y, ircircle - 10, 2, RGB(200,200,200))
StopDrawing()
EndProcedure
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; ****************************************************************************
; +--------------------------------------------------------------------------+
; | |
; +--------------------------------------------------------------------------+
Define.i event, eveng, evenp, WindowW = 200, WindowH = 200
If OpenWindow(#Window, 0, 0, WindowW, WindowH, "potentiomètre circulaire", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(#Canvas, 0, 0, WindowW, WindowH, #PB_Canvas_Keyboard)
DrawCircular(WindowW, WindowH, WindowW * 0.5, WindowH)
Repeat
event = WaitWindowEvent()
evenp = EventType()
eveng = EventGadget()
If eveng = #Canvas
;Debug "pass"
If evenp = #PB_EventType_MouseWheel
;Debug GetGadgetAttribute(#Canvas, #PB_Canvas_WheelDelta)
EndIf
If evenp = #PB_EventType_LeftButtonDown Or (evenp = #PB_EventType_MouseMove And GetGadgetAttribute(#Canvas, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
DrawCircular(WindowW, WindowH, GetGadgetAttribute(#Canvas, #PB_Canvas_MouseX), GetGadgetAttribute(#Canvas, #PB_Canvas_MouseY))
EndIf
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
End
GallyHC