tvplanit: Improved drawing styles of MonthView

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4894 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-07-02 12:20:11 +00:00
parent 5cd2174610
commit dd215650bc
4 changed files with 76 additions and 93 deletions

View File

@ -682,8 +682,7 @@ begin
clBtnNextYear.Visible := (cdoShowNavBtns in FOptions); clBtnNextYear.Visible := (cdoShowNavBtns in FOptions);
clBtnPrevYear.Visible := (cdoShowNavBtns in FOptions); clBtnPrevYear.Visible := (cdoShowNavBtns in FOptions);
CalculateSizes (Canvas, ra0, Rect (0, 0, Width, Height), Row, Col, CalculateSizes(Canvas, ra0, Rect (0, 0, Width, Height), Row, Col, DisplayOnly);
DisplayOnly);
{position and size the left and right month buttons} {position and size the left and right month buttons}
{position and size the next and prev year buttons} {position and size the next and prev year buttons}

View File

@ -40,7 +40,7 @@ type
procedure DrawFocusBox; procedure DrawFocusBox;
procedure DrawLine; procedure DrawLine;
procedure InitColors; procedure InitColors;
procedure SetMeasurements; procedure SetMeasurements; override;
public public
constructor Create(ACalendar: TVpCustomCalendar; ARenderCanvas: TCanvas); constructor Create(ACalendar: TVpCustomCalendar; ARenderCanvas: TCanvas);
@ -118,6 +118,17 @@ var
R: TRect; R: TRect;
S: string; S: string;
begin begin
// Calculate size of available rectangle
with TVpCalendarOpener(FCalendar) do begin
R := Rect(clRowCol[0, 1].Left + RealLeft,
clRowCol[0, 1].Top + RealTop,
clRowCol[0, 1].Right + RealLeft,
clRowCol[0, 1].Bottom + RealTop
);
R.Right := clRowCol[0, 6].Left + RealLeft;
end;
// Calculate string to be displayed
if FCalendar.DateFormat = dfLong then if FCalendar.DateFormat = dfLong then
if cdoShowYear in FCalendar.Options then if cdoShowYear in FCalendar.Options then
S := FormatDateTime('mmmm yyyy', RenderDate) S := FormatDateTime('mmmm yyyy', RenderDate)
@ -129,21 +140,10 @@ begin
else else
S := FormatDateTime('mmm', RenderDate); S := FormatDateTime('mmm', RenderDate);
with TVpCalendarOpener(FCalendar) do begin // switch to short date format if string won't fit
R := Rect(clRowCol[0, 1].Left + RealLeft,
clRowCol[0, 1].Top + RealTop,
clRowCol[0, 1].Right + RealLeft,
clRowCol[0, 1].Bottom + RealTop
);
R.Right := clRowCol[0, 6].Left + RealLeft;
end;
{switch to short date format if string won't fit}
if FCalendar.DateFormat = dfLong then if FCalendar.DateFormat = dfLong then
if RenderCanvas.TextWidth(S) > R.Right - R.Left then if RenderCanvas.TextWidth(S) > R.Right - R.Left then
begin
S := FormatDateTime('mmm yyyy', RenderDate); S := FormatDateTime('mmm yyyy', RenderDate);
end;
{$IF FPC_FULLVERSION < 30000} {$IF FPC_FULLVERSION < 30000}
S := SysToUTF8(S); S := SysToUTF8(S);
@ -399,6 +399,7 @@ begin
if not Assigned(FCalendar.OnDrawItem) then if not Assigned(FCalendar.OnDrawItem) then
if not (cdoHideActive in FCalendar.Options) then if not (cdoHideActive in FCalendar.Options) then
DrawFocusBox; DrawFocusBox;
finally finally
RenderCanvas.Unlock; RenderCanvas.Unlock;
end; end;

View File

@ -1191,7 +1191,6 @@ begin
TW := FCanvas.TextWidth(AText); TW := FCanvas.TextWidth(AText);
if TW < ARect.Right - ARect.Left then if TW < ARect.Right - ARect.Left then
// ARect.Left := ARect.Left +((ARect.Right - ARect.Left - TW) div 2);
ARect.Left := (ARect.Left + ARect.Right - TW) div 2; ARect.Left := (ARect.Left + ARect.Right - TW) div 2;
TPSTextOut(FCanvas, Angle, ViewPort, ARect.Left, ARect.Top, AText); TPSTextOut(FCanvas, Angle, ViewPort, ARect.Left, ARect.Top, AText);

View File

@ -99,7 +99,7 @@ end;
procedure TVpMonthViewPainter.DrawDayHead; procedure TVpMonthViewPainter.DrawDayHead;
var var
dhRect: TRect; dhRect, R: TRect;
I: Integer; I: Integer;
DayTag: Integer; DayTag: Integer;
Str: string; Str: string;
@ -111,42 +111,40 @@ begin
{ build rect } { build rect }
if FMonthView.DrawingStyle = ds3D then begin if FMonthView.DrawingStyle = ds3D then begin
dhRect.Left := RealLeft + 1; dhRect.Left := RealLeft + 2;
dhRect.Top := RealTop + TVpMonthViewOpener(FMonthView).mvDayHeadHeight + 3; dhRect.Top := RealTop + TVpMonthViewOpener(FMonthView).mvDayHeadHeight + 3;
dhRect.Right := RealRight - 3; dhRect.Right := RealRight - 3;
dhRect.Bottom := dhRect.Top + TVpMonthViewOpener(FMonthView).mvDayHeadHeight; dhRect.Bottom := dhRect.Top + TVpMonthViewOpener(FMonthView).mvDayHeadHeight;
TPSFillRect(RenderCanvas, Angle, RenderIn, dhRect); TPSFillRect(RenderCanvas, Angle, RenderIn, dhRect);
DrawBevelRect( R := TPSRotateRectangle(Angle, RenderIn, dhRect);
RenderCanvas, DrawBevelRect(RenderCanvas, R, BevelHighlight, BevelDarkShadow);
TPSRotateRectangle(Angle, RenderIn, dhRect),
BevelHighlight,
BevelDarkShadow
);
end else begin end else begin
dhRect.Left := RealLeft + 1; dhRect.Left := RealLeft;
dhRect.Top := RealTop + TVpMonthViewOpener(FMonthView).mvDayHeadHeight + 2; dhRect.Top := RealTop + TVpMonthViewOpener(FMonthView).mvDayHeadHeight;
dhRect.Right := RealRight - 1; dhRect.Right := RealRight;
dhRect.Bottom := dhRect.Top + TVpMonthViewOpener(FMonthView).mvDayHeadHeight; dhRect.Bottom := dhRect.Top + TVpMonthViewOpener(FMonthView).mvDayHeadHeight;
TPSFillRect(RenderCanvas, Angle, RenderIn, dhRect); TPSFillRect(RenderCanvas, Angle, RenderIn, dhRect);
DrawBevelRect( R := TPSRotateRectangle(Angle, RenderIn, dhRect);
RenderCanvas, DrawBevelRect(RenderCanvas, R, BevelShadow, BevelShadow);
TPSRotateRectangle(Angle, RenderIn, dhRect),
BevelHighlight,
BevelShadow
);
end; end;
DayTag := Ord(FMonthView.WeekStartsOn); DayTag := Ord(FMonthView.WeekStartsOn);
dhRect.Right := dhRect.Left + TVpMonthViewOpener(FMonthView).mvColWidth; dhRect.Right := dhRect.Left + TVpMonthViewOpener(FMonthView).mvColWidth;
for I := 0 to 6 do begin for I := 0 to 6 do begin
{ draw the little vertical lines between each day } { draw the little vertical lines between each day }
if I < 6 then if I < 6 then begin
DrawBevelRect( if FMonthView.DrawingStyle = ds3d then
RenderCanvas, begin
TPSRotateRectangle(Angle, RenderIn, Rect(dhRect.Right, dhRect.Top + 3, dhRect.Right + 1, dhRect.Bottom - 3)), R := Rect(dhRect.Right-1, dhRect.Top + 3, dhRect.Right, dhRect.Bottom - 3);
BevelShadow, R := TPSRotateRectangle(Angle, RenderIn, R);
BevelHighlight DrawBevelRect(RenderCanvas, TPSRotateRectangle(Angle, RenderIn, R), BevelShadow, BevelHighlight);
); end else
begin
TPSMoveTo(RenderCanvas, Angle, RenderIn, dhRect.Right + 1, dhRect.Top + 4);
TPSLineTo(RenderCanvas, Angle, RenderIn, dhRect.Right + 1, dhRect.Bottom - 3);
end;
end;
{$IFDEF LCL} {$IFDEF LCL}
case FMonthView.DayNameStyle of case FMonthView.DayNameStyle of
@ -202,7 +200,7 @@ begin
RenderCanvas, RenderCanvas,
Angle, Angle,
RenderIn, RenderIn,
dhRect.Left + (dhRect.Right - dhRect.Left) div 2 - Strl div 2, (dhRect.Left + dhRect.Right - StrL) div 2,
dhRect.Top + TextMargin - 1, dhRect.Top + TextMargin - 1,
Str Str
); );
@ -211,6 +209,7 @@ begin
DayTag := 0 DayTag := 0
else else
Inc(DayTag); Inc(DayTag);
dhRect.Left := dhRect.Right; dhRect.Left := dhRect.Right;
dhRect.Right := dhRect.Left + TVpMonthViewOpener(FMonthView).mvColWidth; dhRect.Right := dhRect.Left + TVpMonthViewOpener(FMonthView).mvColWidth;
end; end;
@ -249,15 +248,16 @@ begin
RenderCanvas.Brush.Color := RealColor; RenderCanvas.Brush.Color := RealColor;
with TVpMonthViewOpener(FMonthView) do begin with TVpMonthViewOpener(FMonthView) do begin
if DrawingStyle = ds3d then
begin
mvRowHeight := (RealHeight - mvDayHeadHeight * 2 - 4) div 6; mvRowHeight := (RealHeight - mvDayHeadHeight * 2 - 4) div 6;
TextRect.TopLeft := Point( TextRect.TopLeft := Point(RealLeft + 1, RealTop + mvDayHeadHeight * 2 + 4);
RealLeft + 1, end else
RealTop + mvDayHeadHeight * 2 + 4 begin
); mvRowHeight := (RealHeight - mvDayHeadHeight * 2) div 6;
TextRect.BottomRight := Point( TextRect.TopLeft := Point(RealLeft + 1, RealTop + mvDayHeadHeight * 2);
TextRect.Left + mvColWidth, end;
TextRect.Top + mvRowHeight TextRect.BottomRight := Point(TextRect.Left + mvColWidth, TextRect.Top + mvRowHeight);
);
end; end;
{ Determine the starting date and offset } { Determine the starting date and offset }
@ -710,59 +710,49 @@ begin
dayHeadHeight := TVpMonthViewOpener(FMonthView).mvDayHeadHeight; dayHeadHeight := TVpMonthViewOpener(FMonthView).mvDayHeadHeight;
HeadRect := Rect(RealLeft + 1, RealTop + 1, RealRight - 1, RealTop + dayHeadHeight); HeadRect := Rect(RealLeft, RealTop, RealRight, RealTop + dayHeadHeight);
{ draw the header cell and borders } { Draw the header cell and borders }
if FMonthView.DrawingStyle = dsFlat then begin if FMonthView.DrawingStyle = dsFlat then begin
{ draw an outer and inner bevel } // draw a flat rectanbular border
{
HeadRect.Left := RealLeft + 1;
HeadRect.Top := RealTop + 1;
HeadRect.Right := RealRight - 1;
HeadRect.Bottom := RealTop + dayHeadHeight;
}
TPSFillRect(RenderCanvas, Angle, RenderIn, HeadRect); TPSFillRect(RenderCanvas, Angle, RenderIn, HeadRect);
R := TPSRotateRectangle(Angle, RenderIn, HeadRect); R := TPSRotateRectangle(Angle, RenderIn, HeadRect);
DrawBevelRect(RenderCanvas, R, BevelShadow, BevelShadow); DrawBevelRect(RenderCanvas, R, BevelShadow, BevelShadow);
end else end else
if FMonthView.DrawingStyle = ds3d then begin if FMonthView.DrawingStyle = ds3d then begin
{ draw a 3d bevel } // draw a 3d bevel
InflateRect(HeadRect, -1, -1); InflateRect(HeadRect, -2, -2);
dec(HeadRect.Right);
HeadRect.Bottom := HeadRect.Top + dayHeadHeight; HeadRect.Bottom := HeadRect.Top + dayHeadHeight;
{
AHeadRect.Left := RealLeft + 2;
AHeadRect.Top := RealTop + 2;
AHeadRect.Right := RealRight - 3;
AHeadRect.Bottom := RealTop + dayHeadHeight;
}
TPSFillRect(RenderCanvas, Angle, RenderIn, HeadRect); TPSFillRect(RenderCanvas, Angle, RenderIn, HeadRect);
R := TPSRotateRectangle(Angle, RenderIn, HeadRect); R := TPSRotateRectangle(Angle, RenderIn, HeadRect);
DrawBevelRect(RenderCanvas, R, BevelHighlight, BevelDarkShadow); DrawBevelRect(RenderCanvas, R, BevelHighlight, BevelDarkShadow);
end; end;
{ Position the spinner }
with TVpMonthViewOpener(FMonthView) do begin
mvSpinButtons.Height := dayHeadHeight - 3;
mvSpinButtons.Width := mvSpinButtons.Height * 2;
mvSpinButtons.Left := TextMargin;
mvSpinButtons.Top := HeadRect.Top + (dayHeadHeight - mvSpinButtons.Height) div 2 + 1;
end;
{ Acquire startdate and end date } { Acquire startdate and end date }
HeadStr := FormatDateTime(FMonthView.DateLabelFormat, DisplayDate); HeadStr := FormatDateTime(FMonthView.DateLabelFormat, DisplayDate);
{$IF FPC_FULLVERSION < 30000} {$IF FPC_FULLVERSION < 30000}
HeadStr := SysToUTF8(HeadStr); HeadStr := SysToUTF8(HeadStr);
{$ENDIF} {$ENDIF}
{ draw the text } { Calculate the text rectangle }
RenderCanvas.Font.Assign(FMonthView.DayHeadAttributes.Font);
if DisplayOnly and (RenderCanvas.TextWidth(HeadStr) >= RealWidth) then if DisplayOnly and (RenderCanvas.TextWidth(HeadStr) >= RealWidth) then
HeadTextRect.TopLeft:= Point( HeadTextRect.Left:= RealLeft + TextMargin * 2
RealLeft + TextMargin * 2,
HeadRect.Top
)
else else
if DisplayOnly then if DisplayOnly then
HeadTextRect.TopLeft := Point( HeadTextRect.Left := RealLeft + (RealWidth - RenderCanvas.TextWidth(HeadStr)) div 2
RealLeft + (RealWidth - RenderCanvas.TextWidth(HeadStr)) div 2,
HeadRect.Top
)
else else
HeadTextRect.TopLeft := Point( HeadTextRect.Left := RealLeft + 30 + TextMargin * 2;
RealLeft + 30 + TextMargin * 2, HeadTextRect.Top := (HeadRect.Top + HeadRect.Bottom - RenderCanvas.TextHeight('Tg')) div 2;
HeadRect.Top
);
HeadTextRect.BottomRight := HeadRect.BottomRight; HeadTextRect.BottomRight := HeadRect.BottomRight;
{ Fix Header String } { Fix Header String }
@ -777,23 +767,17 @@ begin
); );
end; end;
{ position the spinner } // Draw the text
with TVpMonthViewOpener(FMonthView) do begin
mvSpinButtons.Height := Trunc(mvDayHeadHeight * 0.8);
mvSpinButtons.Width := mvSpinButtons.Height * 2;
mvSpinButtons.Left := TextMargin;
mvSpinButtons.Top := (mvDayHeadHeight - mvSpinButtons.Height) div 2 + 2;
end;
RenderCanvas.Font.Assign(FMonthView.DayHeadAttributes.Font); RenderCanvas.Font.Assign(FMonthView.DayHeadAttributes.Font);
TPSTextOut( TPSTextOut(
RenderCanvas, RenderCanvas,
Angle, Angle,
RenderIn, RenderIn,
RealLeft + TVpMonthViewOpener(FMonthView).mvSpinButtons.Width + TextMargin * 2, RealLeft + TVpMonthViewOpener(FMonthView).mvSpinButtons.Width + TextMargin * 2,
HeadTextRect.Top + TextMargin, HeadTextRect.Top, // + TextMargin,
HeadStr HeadStr
); );
end; end;
procedure TVpMonthViewPainter.InitColors; procedure TVpMonthViewPainter.InitColors;