tvplanit: Use PointInRect function instead of huge "if" monsters

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4870 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-06-29 21:46:53 +00:00
parent 454c96067c
commit 3767e20c54
3 changed files with 17 additions and 40 deletions

View File

@ -193,11 +193,9 @@ begin
OnDrawItem(Self, RenderDate + NewIdx - OldIdx, clRowCol[R,C]) OnDrawItem(Self, RenderDate + NewIdx - OldIdx, clRowCol[R,C])
else else
if clRowCol[R, C].Top <> 0 then begin if clRowCol[R, C].Top <> 0 then begin
DrawRect := Rect (clRowCol[R, C].Left + RealLeft, DrawRect := clRowCol[R, C];
clRowCol[R, C].Top + RealTop, OffsetRect(DrawRect, RealLeft, RealTop);
clRowCol[R, C].Right + RealLeft, TH := RenderCanvas.TextHeight(S);
clRowCol[R, C].Bottom + RealTop);
TH := RenderCanvas.TextHeight (S);
if TH < DrawRect.Bottom - DrawRect.Top then if TH < DrawRect.Bottom - DrawRect.Top then
DrawRect.Top := DrawRect.Top + ((DrawRect.Bottom - DrawRect.Top) - TH) div 2; DrawRect.Top := DrawRect.Top + ((DrawRect.Bottom - DrawRect.Top) - TH) div 2;
TPSCenteredTextOut(RenderCanvas, Angle, RenderIn, DrawRect, S); TPSCenteredTextOut(RenderCanvas, Angle, RenderIn, DrawRect, S);

View File

@ -1818,11 +1818,8 @@ begin
for I := 0 to pred(Length(dvEventArray)) do begin for I := 0 to pred(Length(dvEventArray)) do begin
if dvEventArray[I].Event = nil then if dvEventArray[I].Event = nil then
Exit; Exit;
if (APoint.X > dvEventArray[I].Rec.Left) and if PointInRect(APoint, dvEventArray[I].Rec) then
(APoint.X < dvEventArray[I].Rec.Right) and begin
(APoint.Y > dvEventArray[I].Rec.Top) and
(APoint.Y < dvEventArray[I].Rec.Bottom)
then begin
FActiveEvent := TVpEvent(dvEventArray[I].Event); FActiveEvent := TVpEvent(dvEventArray[I].Event);
dvActiveEventRec := dvEventArray[I].Rec; dvActiveEventRec := dvEventArray[I].Rec;
dvActiveIconRec := dvEventArray[I].IconRect; dvActiveIconRec := dvEventArray[I].IconRect;
@ -1845,11 +1842,8 @@ begin
if dvEventArray[I].Event = nil then if dvEventArray[I].Event = nil then
{ we've hit the end of visible events without finding a match } { we've hit the end of visible events without finding a match }
Exit; Exit;
if (Point.X > dvEventArray[I].Rec.Left) and if PointInRect(Point, dvEventArray[I].Rec) then
(Point.X < dvEventArray[I].Rec.Right) and begin
(Point.Y > dvEventArray[I].Rec.Top) and
(Point.Y < dvEventArray[I].Rec.Bottom)
then begin
FActiveEvent := TVpEvent(dvEventArray[I].Event); FActiveEvent := TVpEvent(dvEventArray[I].Event);
dvActiveEventRec := dvEventArray[I].Rec; dvActiveEventRec := dvEventArray[I].Rec;
dvActiveIconRec := dvEventArray[I].IconRect; dvActiveIconRec := dvEventArray[I].IconRect;
@ -1869,11 +1863,8 @@ begin
for I := 0 to pred(Length(dvEventArray)) do begin for I := 0 to pred(Length(dvEventArray)) do begin
if dvEventArray[I].Event = nil then if dvEventArray[I].Event = nil then
Exit; Exit;
if (Point.X > dvEventArray[I].Rec.Left) and if PointInRect(Point, dvEventArray[I].Rec) then
(Point.X < dvEventArray[I].Rec.Right) and begin
(Point.Y > dvEventArray[I].Rec.Top) and
(Point.Y < dvEventArray[I].Rec.Bottom)
then begin
result := TVpEvent(dvEventArray[I].Event); result := TVpEvent(dvEventArray[I].Event);
Exit; Exit;
end; end;
@ -2174,11 +2165,8 @@ begin
ActiveRow := I; ActiveRow := I;
Exit; Exit;
end else end else
if (Pnt.x > dvLineMatrix[ActiveCol, I].Rec.Left) and if PointInRect(Pnt, dvLineMatrix[ActiveCol, I].Rec) then
(Pnt.x < dvLineMatrix[ActiveCol, I].Rec.Right) and begin
(Pnt.y <= dvLineMatrix[ActiveCol, I].Rec.Bottom) and
(Pnt.y > dvLineMatrix[ActiveCol, I].Rec.Top)
then begin
ActiveRow := I; ActiveRow := I;
Exit; Exit;
end; end;
@ -2191,11 +2179,8 @@ var
I : Integer; I : Integer;
begin begin
for I := 0 to pred(length(dvColRectArray)) do begin for I := 0 to pred(length(dvColRectArray)) do begin
if (Pnt.x > dvColRectArray[I].Rec.Left) and if PointInRect(Pnt, dvColRectArray[I].Rec) then
(Pnt.x < dvColRectArray[I].Rec.Right) and begin
(Pnt.y < dvColRectArray[I].Rec.Bottom) and
(Pnt.y > dvColRectArray[I].Rec.Top)
then begin
ActiveCol := I; ActiveCol := I;
Exit; Exit;
end; end;

View File

@ -1112,11 +1112,8 @@ var
I: Integer; I: Integer;
begin begin
for I := 0 to pred(Length(wvWeekdayArray)) do for I := 0 to pred(Length(wvWeekdayArray)) do
if (Point.X >= wvWeekdayArray[I].Rec.Left) and if PointInRect(Point, wvWeekdayArray[I].Rec) then
(Point.X <= wvWeekdayArray[I].Rec.Right) and begin
(Point.Y >= wvWeekdayArray[I].Rec.Top) and
(Point.Y <= wvWeekdayArray[I].Rec.Bottom)
then begin
Date := wvWeekdayArray[I].Day; Date := wvWeekdayArray[I].Day;
Invalidate; Invalidate;
Exit; Exit;
@ -1141,11 +1138,8 @@ begin
Exit; Exit;
end; end;
if (Pt.X > wvEventArray[I].Rec.Left) and if PointInRect(Pt, wvEventArray[I].Rec) then
(Pt.X < wvEventArray[I].Rec.Right) and begin
(Pt.Y > wvEventArray[I].Rec.Top) and
(Pt.Y < wvEventArray[I].Rec.Bottom)
then begin
{ point falls inside this event's rectangle } { point falls inside this event's rectangle }
wvHotPoint := Pt; wvHotPoint := Pt;
ActiveEvent := TVpEvent(wvEventArray[I].Event); ActiveEvent := TVpEvent(wvEventArray[I].Event);