tvplanit: Fix scaling issues in printing of TVpDayView

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8459 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-09-07 18:01:52 +00:00
parent 41aeaea878
commit 1122864942
2 changed files with 29 additions and 31 deletions

View File

@ -25,9 +25,12 @@ type
TVpDayViewPainter = class(TVpBasePainter) TVpDayViewPainter = class(TVpBasePainter)
private private
FDayView: TVpDayView; FDayView: TVpDayView;
FScaledMinutesBorder: Integer;
FScaledMinutesHourDistance: Integer;
FScaledGutterWidth: Integer; FScaledGutterWidth: Integer;
FScaledIconMargin: Integer; FScaledIconMargin: Integer;
FScaledTickDist: Integer; FScaledTickDist: Integer;
FScaledTextMargin: Integer;
// local parameters of the old render procedure // local parameters of the old render procedure
ColHeadRect: TRect; ColHeadRect: TRect;
CellsRect: TRect; CellsRect: TRect;
@ -321,7 +324,7 @@ begin
// number of all day events for the range of days covered by the control. // number of all day events for the range of days covered by the control.
NumADEvents := 0; NumADEvents := 0;
txtMargin := FDayView.TextMargin; txtMargin := FScaledTextMargin;
AllDayWidth := RealWidth - RealRowHeadWidth - txtMargin - ScrollBarOffset; AllDayWidth := RealWidth - RealRowHeadWidth - txtMargin - ScrollBarOffset;
DayWidth := AllDayWidth div FDayView.NumDays; DayWidth := AllDayWidth div FDayView.NumDays;
@ -424,7 +427,7 @@ begin
TPSTextOut(RenderCanvas,Angle, RenderIn, TPSTextOut(RenderCanvas,Angle, RenderIn,
AdEvRect.Left + txtMargin, AdEvRect.Left + txtMargin,
AdEvRect.Top + txtDist, // AdEvRect.Bottom - ADTextHeight) div 2, //TextMargin, AdEvRect.Top + txtDist,
EventStr EventStr
); );
@ -667,15 +670,15 @@ begin
{ center and write the resource name in the first column } { center and write the resource name in the first column }
if (Col = 0) then begin if (Col = 0) then begin
X := TextRect.Left + wText div 2 - ResStrLen div 2; X := TextRect.Left + wText div 2 - ResStrLen div 2;
Y := TextRect.Top + FDayView.TextMargin; Y := TextRect.Top + FScaledTextMargin;
TPSTextOut(RenderCanvas, Angle, RenderIn, X, Y, FDayView.DataStore.Resource.Description); TPSTextOut(RenderCanvas, Angle, RenderIn, X, Y, FDayView.DataStore.Resource.Description);
end; end;
{ center the date string } { center the date string }
X := TextRect.Left + wText div 2 - DateStrLen div 2; X := TextRect.Left + wText div 2 - DateStrLen div 2;
Y := TextRect.Top + (FDayView.TextMargin * 2) + DateStrHt; Y := TextRect.Top + FScaledTextMargin * 2 + DateStrHt;
end else begin end else begin
{ center the date string } { center the date string }
Y := TextRect.Top + FDayView.TextMargin; Y := TextRect.Top + FScaledTextMargin;
X := TextRect.Left + wText div 2 - DateStrLen div 2; X := TextRect.Left + wText div 2 - DateStrLen div 2;
end; end;
{ Write the date string } { Write the date string }
@ -841,7 +844,7 @@ begin
{ Paint the gutter inside the EventRect of all events } { Paint the gutter inside the EventRect of all events }
if (AEventRec.Level = 0) then if (AEventRec.Level = 0) then
GutterRect.Left := EventRect.Left - Trunc(FDayView.GutterWidth * Scale) // wp: use FGutterWidth? It uses round, though... GutterRect.Left := EventRect.Left - FScaledGutterWidth
else else
GutterRect.Left := EventRect.Left; GutterRect.Left := EventRect.Left;
GutterRect.Right := GutterRect.Left + FScaledGutterWidth; GutterRect.Right := GutterRect.Left + FScaledGutterWidth;
@ -862,7 +865,7 @@ begin
IconRect := DetermineIconRect(EventRect); IconRect := DetermineIconRect(EventRect);
end else begin end else begin
tmpRect := EventRect; tmpRect := EventRect;
inc(tmpRect.Left, FDayView.GutterWidth); inc(tmpRect.Left, FScaledGutterWidth);
ScaleIcons(tmpRect); ScaleIcons(tmpRect);
IconRect := DetermineIconRect(tmpRect); IconRect := DetermineIconRect(tmpRect);
end; end;
@ -875,7 +878,7 @@ begin
if Assigned(FDayView.OnBeforeDrawEvent) then begin if Assigned(FDayView.OnBeforeDrawEvent) then begin
tmpRect := EventRect; tmpRect := EventRect;
if (AEventRec.Level <> 0) then if (AEventRec.Level <> 0) then
inc(tmpRect.Left, FDayView.GutterWidth); inc(tmpRect.Left, FScaledGutterWidth);
FDayView.OnBeforeDrawEvent(Self, AEvent, FDayView.ActiveEvent = AEvent, FDayView.OnBeforeDrawEvent(Self, AEvent, FDayView.ActiveEvent = AEvent,
RenderCanvas, GutterRect, tmpRect, IconRect); RenderCanvas, GutterRect, tmpRect, IconRect);
end; end;
@ -889,7 +892,7 @@ begin
{ If the string is longer than the availble space then chop off the end { If the string is longer than the availble space then chop off the end
and place those little '...'s at the end } and place those little '...'s at the end }
if FDayView.WrapStyle = wsNone then begin if FDayView.WrapStyle = wsNone then begin
maxW := EventRect.Right - IconRect.Right - FScaledGutterWidth - FDayView.TextMargin; maxW := EventRect.Right - IconRect.Right - FScaledGutterWidth - FScaledTextMargin;
if RenderCanvas.TextWidth(EventString) > maxW then if RenderCanvas.TextWidth(EventString) > maxW then
EventString := GetDisplayString(RenderCanvas, EventString, 0, maxW); EventString := GetDisplayString(RenderCanvas, EventString, 0, maxW);
end; end;
@ -915,7 +918,7 @@ begin
if Assigned(FDayView.OnAfterDrawEvent) then begin if Assigned(FDayView.OnAfterDrawEvent) then begin
tmpRect := EventRect; tmpRect := EventRect;
if (AEventRec.Level <> 0) then if (AEventRec.Level <> 0) then
inc(tmpRect.Left, FDayView.GutterWidth); inc(tmpRect.Left, FScaledGutterWidth);
FDayView.OnAfterDrawEvent(Self, AEvent, FDayView.ActiveEvent = AEvent, FDayView.OnAfterDrawEvent(Self, AEvent, FDayView.ActiveEvent = AEvent,
RenderCanvas, GutterRect, tmpRect, IconRect); RenderCanvas, GutterRect, tmpRect, IconRect);
end; end;
@ -1097,13 +1100,13 @@ begin
if FDayView.WrapStyle = wsIconFlow then if FDayView.WrapStyle = wsIconFlow then
begin begin
WorkRegion1 := CreateRectRgn(AIconRect.Right, AEventRect.Top, AEventRect.Right, AIconRect.Bottom); WorkRegion1 := CreateRectRgn(AIconRect.Right, AEventRect.Top, AEventRect.Right, AIconRect.Bottom);
WorkRegion2 := CreateRectRgn(AEventRect.Left + FDayView.GutterWidth, AIconRect.Bottom, AEventRect.Right, AEventRect.Bottom); WorkRegion2 := CreateRectRgn(AEventRect.Left + FScaledGutterWidth, AIconRect.Bottom, AEventRect.Right, AEventRect.Bottom);
TextRegion := CreateRectRgn(AIconRect.Right, AEventRect.Top, AEventRect.Right, AIconRect.Bottom); TextRegion := CreateRectRgn(AIconRect.Right, AEventRect.Top, AEventRect.Right, AIconRect.Bottom);
CombineRgn(TextRegion, WorkRegion1, WorkRegion2, RGN_OR); CombineRgn(TextRegion, WorkRegion1, WorkRegion2, RGN_OR);
end else end else
TextRegion := CreateRectRgn(AIconRect.Right, AEventRect.Top, AEventRect.Right, AEventRect.Bottom); TextRegion := CreateRectRgn(AIconRect.Right, AEventRect.Top, AEventRect.Right, AEventRect.Bottom);
end else end else
TextRegion := CreateRectRgn(AIconRect.Right + FDayView.GutterWidth, AEventRect.Top, AEventRect.Right, AEventRect.Bottom); TextRegion := CreateRectRgn(AIconRect.Right + FScaledGutterWidth, AEventRect.Top, AEventRect.Right, AEventRect.Bottom);
try try
CW := RenderTextToRegion(RenderCanvas, Angle, RenderIn, TextRegion, AText); CW := RenderTextToRegion(RenderCanvas, Angle, RenderIn, TextRegion, AText);
@ -1131,16 +1134,16 @@ begin
TPSTextOut(RenderCanvas, // wp: both cases are the same ?! TPSTextOut(RenderCanvas, // wp: both cases are the same ?!
Angle, Angle,
RenderIn, RenderIn,
AIconRect.Right + FDayView.GutterWidth + FDayView.TextMargin, AIconRect.Right + FScaledGutterWidth + FScaledTextMargin,
AEventRect.Top + FDayView.TextMargin, AEventRect.Top + FScaledTextMargin,
AText AText
) )
else else
TPSTextOut(RenderCanvas, TPSTextOut(RenderCanvas,
Angle, Angle,
RenderIn, RenderIn,
AIconRect.Right + FDayView.GutterWidth + FDayView.TextMargin, AIconRect.Right + FScaledGutterWidth + FScaledTextMargin,
AEventRect.Top + FDayView.TextMargin, AEventRect.Top + FScaledTextMargin,
AText AText
); );
end; end;
@ -1413,7 +1416,7 @@ begin
{$ENDIF} {$ENDIF}
timeStr := Format('%s:%s', [hourStr, minuteStr]); timeStr := Format('%s:%s', [hourStr, minuteStr]);
x := lineRect.Left + FScaledTickDist; x := lineRect.Left + FScaledTickDist;
TPSTextOut(RenderCanvas, Angle, RenderIn, x, y + FDayView.TextMargin, timeStr); TPSTextOut(RenderCanvas, Angle, RenderIn, x, y + FScaledTextMargin, timeStr);
end else end else
begin begin
// In all other cases, paint large hour and small minutes (or am/pm) // In all other cases, paint large hour and small minutes (or am/pm)
@ -1422,16 +1425,16 @@ begin
{$IF VP_LCL_SCALING = 0} {$IF VP_LCL_SCALING = 0}
RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI); RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI);
{$ENDIF} {$ENDIF}
x := lineRect.Right - RenderCanvas.TextWidth(MinuteStr) - MINUTES_BORDER; x := lineRect.Right - RenderCanvas.TextWidth(MinuteStr) - FScaledMinutesBorder;
TPSTextOut(RenderCanvas, Angle, RenderIn, x, y + FDayView.TextMargin, minuteStr); TPSTextOut(RenderCanvas, Angle, RenderIn, x, y + FScaledTextMargin, minuteStr);
// Draw hours // Draw hours
RenderCanvas.Font.Assign(FDayView.RowHeadAttributes.HourFont); RenderCanvas.Font.Assign(FDayView.RowHeadAttributes.HourFont);
{$IF VP_LCL_SCALING = 0} {$IF VP_LCL_SCALING = 0}
RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI); RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI);
{$ENDIF} {$ENDIF}
dec(x, RenderCanvas.TextWidth(HourStr) + MINUTES_HOUR_DISTANCE); dec(x, RenderCanvas.TextWidth(HourStr) + FScaledMinutesHourDistance);
TPSTextOut(RenderCanvas, Angle, RenderIn, x, y + FDayView.TextMargin{ - 2}, hourStr); TPSTextOut(RenderCanvas, Angle, RenderIn, x, y + FScaledTextMargin, hourStr);
end; end;
end; end;
@ -1464,7 +1467,7 @@ begin
{$IF VP_LCL_SCALING = 0} {$IF VP_LCL_SCALING = 0}
RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI); RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI);
{$ENDIF} {$ENDIF}
minutesLen := RenderCanvas.TextWidth('00') + MINUTES_BORDER + MINUTES_HOUR_DISTANCE div 2; minutesLen := RenderCanvas.TextWidth('00') + FScaledMinutesBorder + FScaledMinutesHourDistance div 2;
// Prepare pen // Prepare pen
RenderCanvas.Pen.Style := psSolid; RenderCanvas.Pen.Style := psSolid;
@ -1531,7 +1534,7 @@ end;
function TVpDayViewPainter.CalcRowHeadWidth: integer; function TVpDayViewPainter.CalcRowHeadWidth: integer;
begin begin
Result := 2 * MINUTES_BORDER + MINUTES_HOUR_DISTANCE; Result := 2 * (FScaledMinutesBorder + FScaledMinutesHourDistance);
RenderCanvas.Font.Assign(FDayView.RowHeadAttributes.MinuteFont); RenderCanvas.Font.Assign(FDayView.RowHeadAttributes.MinuteFont);
{$IF VP_LCL_SCALING = 0} {$IF VP_LCL_SCALING = 0}
RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI); RenderCanvas.Font.Size := ScaleY(RenderCanvas.Font.Size, DesignTimeDPI);
@ -2077,6 +2080,9 @@ begin
FScaledGutterWidth := Round(FDayView.GutterWidth * Scale); FScaledGutterWidth := Round(FDayView.GutterWidth * Scale);
FScaledIconMargin := Round(ICON_MARGIN * Scale); FScaledIconMargin := Round(ICON_MARGIN * Scale);
FScaledTickdist := Round(TICK_Dist * Scale); FScaledTickdist := Round(TICK_Dist * Scale);
FScaledMinutesBorder := Round(MINUTES_BORDER * Scale);
FScaledMinutesHourDistance := Round(MINUTES_HOUR_DISTANCE * Scale);
FScaledTextMargin := Round(FDayView.TextMargin * Scale);
end; end;
procedure TVpDayViewPainter.VerifyMaxWidthDevisors; procedure TVpDayViewPainter.VerifyMaxWidthDevisors;

View File

@ -895,14 +895,6 @@ begin
Result := m2 - m1 + 1 Result := m2 - m1 + 1
else else
Result := 13 - m1 + m2 + (y2 - y1 - 1)*12; Result := 13 - m1 + m2 + (y2 - y1 - 1)*12;
{
else
Result := (y2 - y1 - 1) * 12;
dm1 := trunc(StartOfTheMonth(FStartDate));
dm2 := trunc(StartOfTheMonth(FEndDate)) + 1;
writeln(datetostr(dm1), ' ', datetostr(dm2));
Result := MonthsBetween(dm1, dm2) + 1;
}
end else end else
Result := 0; Result := 0;
end; end;