Page 2 sur 2
Publié : jeu. 28/oct./2004 21:28
par Chris
Je sais qu'il y a une fonction du côté de l'api, mais je la cherches depuis un moment, et pas moyen de la retrouver.
Sinon, un Box() en mode 4 déssiné par-dessus ton image te fais un rectangle transparent, mais il faut encore povoir le redimensionner et le déplacer sur l'image.
Ca doit être faisable, même en utilisant uniquement les fonctions de Pure.
Publié : jeu. 28/oct./2004 22:29
par Backup
zapman avait trouvé ça !
Code : Tout sélectionner
Procedure Set_Rect (x1,y1,x2,y2, *FRect.Rect)
If x2<x1
mx = x1
x1 = x2
x2 = mx
EndIf
If y2<y1
my = y1
y1 = y2
y2 = my
EndIf
If x1<0 : x1 = 0 : EndIf
If y1<0 : y1 = 0 : EndIf
*FRect\left = x1
*FRect\Top = y1
*FRect\Right = x2
*FRect\Bottom = y2
EndProcedure
If OpenWindow(0,0,0,745,425,#PB_Window_SystemMenu|#PB_Window_ScreenCentered| #PB_Window_MinimizeGadget,"Démo Rectangle de sélection")
hdc = GetDC_(WindowID())
DraggingOn = 0
Repeat
EventID = WaitWindowEvent()
If EventID.l = #WM_LBUTTONDOWN
GetCursorPos_(@StartPos.Point) ; On mémorise la position de départ du curseur
GetWindowRect_(WindowID() ,@SDRect.RECT)
If PtInRect_(SDRect,StartPos\x,StartPos\y) ; On vérifie que le curseur est dans la fenêtre
StartPos\x - SDRect\Left-2 ; On récupère les coordonnées relatives
StartPos\y - SDRect\Top - 27
MPos.Point\x = StartPos\x
MPos\y = StartPos\y
DraggingOn = 1
Set_Rect(WindowX()+3,WindowY()+29,WindowX()+3+WindowWidth(),WindowY()+29+WindowHeight(),WRect.Rect)
ClipCursor_(WRect) ; on capture le curseur souris dans notre fenêtre pour être sûr de récupérer le #WM_LBUTTONUP
EndIf
EndIf
If GetAsyncKeyState_(#VK_LBUTTON) And DraggingOn ; Tant que le bouton est maintenu cliqué
GetCursorPos_(@OverPos.Point)
GetWindowRect_(WindowID() ,@SDRect.RECT)
If PtInRect_(SDRect,OverPos\x,OverPos\y) ; On vérifie que le curseur est dans la fenêtre
OverPos\x - SDRect\Left-2 ; On récupère les coordonnées relatives
OverPos\y - SDRect\Top - 27
If MPos.Point\x<>StartPos.Point\x Or MPos\y<>StartPos\y ; Si on s'est déplacé depuis le départ
Set_Rect (StartPos\x,StartPos\y,MPos.Point\x,MPos\y, FRect.Rect)
DrawFocusRect_(hdc,FRect) ; On efface la version précédente
EndIf
If MPos.Point\x<>OverPos\x Or MPos\y<>OverPos\y
Set_Rect (StartPos\x,StartPos\y,OverPos\x,OverPos\y, FRect.Rect)
MPos\x = OverPos\x ; On mémorise les coordonnées du nouveau tracé
MPos\y = OverPos\y
DrawFocusRect_(hdc,FRect) ; Et on le traçe
EndIf
EndIf
EndIf
If EventID.l = #WM_LBUTTONUP And DraggingOn
Set_Rect (StartPos\x,StartPos\y,MPos.Point\x,MPos\y, FRect.Rect)
DrawFocusRect_(hdc,FRect) ; On efface le dernier tracé
DraggingOn = 0
ClipCursor_(0) ; on libère le curseur
EndIf
Until EventID = #PB_Event_CloseWindow
ReleaseDC_(WindowID(),hdc)
EndIf