I've been contemplating over some more advanced features in user experience for the GUI. I have a special list I'm making - a message log rather which replicates the SMS text messages on an iPhone. I have another post in this forum related to this project, but different subject. In the iPhone's control, if you glide your finger up/down the list and quickly let go, the list continues scrolling in the direction you moved it and gradually gets slower and slower until it stops, or until you tap your finger on it again, which stops it.
I have put the ability to use the mouse to drag/scroll in this list. I'm utilizing OnMouseDown, OnMouseUp, and OnMouseMove to make this possible. Everything is working inside a TScrollBox control. When scrolling, I change TScrollBox.VertScrollBar.Position depending on how far the Y position has moved since the mouse button was first pressed. Only part missing is how to keep the box scrolling once the user releases the mouse button. The speed of movement should also depend on how quickly the user moved the mouse before letting go of the button. After releasing the mouse button, the list should continue scrolling (in this case the TScrollBox.VertScrollBar) and gradually slow down until it comes to a halt, or until the user clicks somewhere in the control again. If the user released the mouse button after the mouse had already stopped moving, then it should not continue moving (still mouse upon release means continuing speed of 0).
I know later versions of Delphi have touch screen capabilities, but I'm in D7, which doesn't. I'm building this on a form, not inside a component. However, I will eventually like to wrap all this functionality into a component once I have it perfected. Here's the relevant code to what I already have working (as far as drag-to-scroll)...
JD Solutions
I have put the ability to use the mouse to drag/scroll in this list. I'm utilizing OnMouseDown, OnMouseUp, and OnMouseMove to make this possible. Everything is working inside a TScrollBox control. When scrolling, I change TScrollBox.VertScrollBar.Position depending on how far the Y position has moved since the mouse button was first pressed. Only part missing is how to keep the box scrolling once the user releases the mouse button. The speed of movement should also depend on how quickly the user moved the mouse before letting go of the button. After releasing the mouse button, the list should continue scrolling (in this case the TScrollBox.VertScrollBar) and gradually slow down until it comes to a halt, or until the user clicks somewhere in the control again. If the user released the mouse button after the mouse had already stopped moving, then it should not continue moving (still mouse upon release means continuing speed of 0).
I know later versions of Delphi have touch screen capabilities, but I'm in D7, which doesn't. I'm building this on a form, not inside a component. However, I will eventually like to wrap all this functionality into a component once I have it perfected. Here's the relevant code to what I already have working (as far as drag-to-scroll)...
Code:
//Lst: TDrawGrid = placed within TScrollBox (no scroll bar - control is larger than TScrollBox)
//Box: TScrollBox = (showing vertical scroll bar to be scrolled)
//fMouseStart: Integer = Starting Y position of mouse when mouse button is clicked
//fScrollStart: Integer = Starting Y position of scroll bar when mouse button is clicked
//fMouseDown: Bool = Master flag to determine if TScrollBox shall scroll upon mouse movement
procedure TfrmConversation.LstMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
fMouseStart:= Y; //Record starting Y position
fScrollStart:= Box.VertScrollBar.Position; //Record starting scroll bar position
fMouseDown:= True; //Record event of mouse button being held down
Screen.Cursor:= crSizeAll; //Change cursor to sizing icon to show user is in drag-to-scroll mode
end;
procedure TfrmConversation.LstMouseUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
fMouseDown:= False; //Record event of mouse button being released (no longer held down)
Screen.Cursor:= crDefault; //Change cursor back to default icon to show user is no longer in drag-to-scroll mode
end;
procedure TfrmConversation.LstMouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
begin
if fMouseDown then begin //Only continue if user is currently in drag-to-scroll mode
Box.VertScrollBar.Position:= Box.VertScrollBar.Position + (fMouseStart - Y); //Move scroll bar by mouse distance
end;
end;
JD Solutions