Commit 348c97b

Nick Faro committed on
Really fugly way to ensure the cursor is in view in the scrollbox
commit 348c97b523a2b77715723b59bf7f2a0487091da9 parent 8fdb4f6
1 changed files +63−0
Modifiedsrc/trackergrid.pas +63−0
@@ -69,6 +69,7 @@ type
69 69
70 procedure RenderSelectedArea; 70 procedure RenderSelectedArea;
71 procedure ClampCursors; 71 procedure ClampCursors;
72 procedure EnsureCursorVisible;
72 procedure NormalizeCursors; 73 procedure NormalizeCursors;
73 74
74 procedure InputNote(Key: Word); 75 procedure InputNote(Key: Word);
@@ -589,6 +590,7 @@ begin
589 Other := Cursor; 590 Other := Cursor;
590 591
591 ClampCursors; 592 ClampCursors;
593 EnsureCursorVisible;
592 Invalidate; 594 Invalidate;
593 end; 595 end;
594 596
@@ -874,6 +876,67 @@ begin
874 Other.X := EnsureRange(Other.X, Low(TPatternGrid), (NumColumns-1)); 876 Other.X := EnsureRange(Other.X, Low(TPatternGrid), (NumColumns-1));
875 end; 877 end;
876 878
879 procedure TTrackerGrid.EnsureCursorVisible;
880 var
881 SB: TScrollBox;
882 CursorRect, SelRect: TRect;
883 VLeft, VRight, VTop, VBottom: Integer;
884 CLeft, CRight, CTop, CBottom: Integer;
885 PadLeft, PadRight, PadTop, PadBottom, I: Integer;
886 P, ClientW, ClientH: Integer;
887 Ctrl: TControl;
888 begin
889 if not (Parent is TScrollBox) then Exit;
890 SB := TScrollBox(Parent);
891
892 PadLeft := 0; PadRight := 0; PadTop := 0; PadBottom := 0;
893 for I := 0 to SB.ControlCount - 1 do begin
894 Ctrl := SB.Controls[I];
895 if Ctrl = Self then Continue;
896 case Ctrl.Align of
897 alLeft: Inc(PadLeft, Ctrl.Width);
898 alRight: Inc(PadRight, Ctrl.Width);
899 alTop: Inc(PadTop, Ctrl.Height);
900 alBottom: Inc(PadBottom, Ctrl.Height);
901 end;
902 end;
903
904 CursorRect := SelectionToRect(Cursor);
905 SelRect := SelectionsToRect(Cursor, Other);
906
907 // Convert grid-local coords to scrollbox virtual coords by adding Self.Left/Top.
908 VLeft := SelRect.Left + Self.Left;
909 VRight := SelRect.Right + Self.Left;
910 VTop := SelRect.Top + Self.Top;
911 VBottom := SelRect.Bottom + Self.Top;
912 CLeft := CursorRect.Left + Self.Left;
913 CRight := CursorRect.Right + Self.Left;
914 CTop := CursorRect.Top + Self.Top;
915 CBottom := CursorRect.Bottom + Self.Top;
916
917 ClientH := SB.ClientHeight;
918 if VBottom - VTop > ClientH - PadTop - PadBottom then begin
919 VTop := CTop;
920 VBottom := CBottom;
921 end;
922 P := SB.VertScrollBar.Position;
923 if VTop < P + PadTop then
924 SB.VertScrollBar.Position := VTop - PadTop
925 else if VBottom > P + ClientH - PadBottom then
926 SB.VertScrollBar.Position := VBottom - ClientH + PadBottom;
927
928 ClientW := SB.ClientWidth;
929 if VRight - VLeft > ClientW - PadLeft - PadRight then begin
930 VLeft := CLeft;
931 VRight := CRight;
932 end;
933 P := SB.HorzScrollBar.Position;
934 if VLeft < P + PadLeft then
935 SB.HorzScrollBar.Position := VLeft - PadLeft
936 else if VRight > P + ClientW - PadRight then
937 SB.HorzScrollBar.Position := VRight - ClientW + PadRight;
938 end;
939
877 procedure TTrackerGrid.NormalizeCursors; 940 procedure TTrackerGrid.NormalizeCursors;
878 var 941 var
879 TempI: Integer; 942 TempI: Integer;