From 4fbe3969b55f72df3e7904e4d4d21ad2d4fee9b8 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Fri, 15 Jul 2016 12:29:06 +0000 Subject: [PATCH] tvplanit: Improved vertical text centering git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4977 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../tvplanit/examples/fulldemo/demomain.lfm | 2 ++ .../tvplanit/source/vpmonthviewpainter.pas | 2 +- components/tvplanit/source/vpweekview.pas | 2 +- .../tvplanit/source/vpweekviewpainter.pas | 26 ++++++++++--------- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/components/tvplanit/examples/fulldemo/demomain.lfm b/components/tvplanit/examples/fulldemo/demomain.lfm index f56f708db..98f323ed9 100644 --- a/components/tvplanit/examples/fulldemo/demomain.lfm +++ b/components/tvplanit/examples/fulldemo/demomain.lfm @@ -106,6 +106,7 @@ object MainForm: TMainForm TimeSlotColors.ActiveRange.RangeEnd = h_00 HeadAttributes.Color = clBtnFace RowHeadAttributes.HourFont.Height = -24 + RowHeadAttributes.MinuteFont.Height = -12 RowHeadAttributes.Color = clBtnFace IconAttributes.AlarmBitmap.Data = { 76020000424D760200000000000036000000280000000C0000000C0000000100 @@ -243,6 +244,7 @@ object MainForm: TMainForm DateLabelFormat = 'dddd, mmmm dd, yyyy' DayHeadAttributes.Color = clBtnFace DayHeadAttributes.DateFormat = 'dddd mmmm, dd' + DayHeadAttributes.Font.Height = -13 DayHeadAttributes.Bordered = True DrawingStyle = dsFlat HeadAttributes.Color = clBtnFace diff --git a/components/tvplanit/source/vpmonthviewpainter.pas b/components/tvplanit/source/vpmonthviewpainter.pas index f711a17d1..11cad96b6 100644 --- a/components/tvplanit/source/vpmonthviewpainter.pas +++ b/components/tvplanit/source/vpmonthviewpainter.pas @@ -785,7 +785,7 @@ begin Angle, RenderIn, RealLeft + TVpMonthViewOpener(FMonthView).mvSpinButtons.Width + TextMargin * 2, - HeadTextRect.Top, // + TextMargin, + HeadTextRect.Top, // this vertical position is already centered HeadStr ); end; diff --git a/components/tvplanit/source/vpweekview.pas b/components/tvplanit/source/vpweekview.pas index 2adc3587d..208f783e6 100644 --- a/components/tvplanit/source/vpweekview.pas +++ b/components/tvplanit/source/vpweekview.pas @@ -148,7 +148,7 @@ type wvClickTimer: TTimer; wvLoaded: Boolean; wvRowHeight: Integer; - wvDayHeadHeight: Integer; +// wvDayHeadHeight: Integer; wvHeaderHeight: Integer; wvStartDate: TDateTime; wvSpinButtons: TUpDown; diff --git a/components/tvplanit/source/vpweekviewpainter.pas b/components/tvplanit/source/vpweekviewpainter.pas index 60a2ebb8c..eb1857a02 100644 --- a/components/tvplanit/source/vpweekviewpainter.pas +++ b/components/tvplanit/source/vpweekviewpainter.pas @@ -12,6 +12,8 @@ type TVpWeekViewPainter = class(TVpBasePainter) private FWeekView: TVpWeekView; + FDayHeadHeight: Integer; + // local parameters of the old TVpWeekView method // HeadRect: TRect; DayRectHeight: Integer; @@ -264,7 +266,7 @@ begin then begin tmpRect := DayRect; InflateRect(tmpRect, -2, -2); - tmpRect.Top := tmpRect.Top + TVpWeekViewOpener(FWeekView).wvDayHeadHeight; + tmpRect.Top := tmpRect.Top + FDayHeadHeight; TPSDrawFocusRect(RenderCanvas, Angle, RenderIn, tmpRect); end; end; @@ -275,19 +277,19 @@ var TextRect: TRect; J: Integer; EventList: TList; - dayHeadHeight: Integer; +// dayHeadHeight: Integer; rowHeight: Integer; headerHeight: Integer; tmpRect: TRect; begin // Abbreviations - dayHeadHeight := TVpWeekviewOpener(FWeekView).wvDayHeadHeight; +// dayHeadHeight := TVpWeekviewOpener(FWeekView).wvDayHeadHeight; rowHeight := TVpWeekViewOpener(FWeekView).wvRowHeight; headerHeight := TVpWeekViewOpener(FWeekView).wvHeaderHeight; // Get header rectangle TextRect := DayRect; - TextRect.Bottom := DayRect.Top + dayHeadHeight; + TextRect.Bottom := DayRect.Top + FDayHeadHeight; // Draw day header tmpRect := TextRect; @@ -303,7 +305,7 @@ begin if (FWeekView.DataStore <> nil) and (FWeekView.DataStore.Resource <> nil) and (FWeekView.DataStore.Resource.Schedule.EventCountByDay(StartDate + ADayIndex) > 0) and - (HeightOf(DayRect) >= TextMargin * 2 + dayHeadHeight) + (HeightOf(DayRect) >= TextMargin * 2 + FDayHeadHeight) then begin // Events exist for this day EventList := TList.Create; @@ -317,7 +319,7 @@ begin // Initialize TextRect for this day TextRect := DayRect; - TextRect.Top := DayRect.Top + dayHeadHeight; + TextRect.Top := DayRect.Top + FDayHeadHeight; TextRect.Bottom := TextRect.Top + rowHeight; // Handle all-day events @@ -404,6 +406,7 @@ procedure TVpWeekViewPainter.DrawDayHeader(ADayIndex: Integer; var TextRect: TRe var dayStr: String; strWid: Integer; + strH: Integer; begin dayStr := FormatDateTime(FWeekView.DayHeadAttributes.DateFormat, StartDate + ADayIndex); {$IFDEF LCL} @@ -414,15 +417,15 @@ begin if strWid > WidthOf(TextRect) then dayStr := GetDisplayString(RenderCanvas, dayStr, 0, WidthOf(TextRect) - TextMargin); strWid := RenderCanvas.TextWidth(dayStr); + strH := RenderCanvas.TextHeight(dayStr); TextRect.Left := TextRect.Right - strWid - TextMargin; - TPSTextOut( RenderCanvas, Angle, RenderIn, TextRect.Left, - TextRect.Top + TextMargin - 1, + (TextRect.Top + TextRect.Bottom - strH) div 2, dayStr ); end; @@ -532,7 +535,7 @@ var HeadRect: TRect; HeadTextRect: TRect; HeadStr: string; - HeadStrLen : Integer; + HeadStrLen: Integer; weekNo: Integer; begin RenderCanvas.Brush.Color := RealHeadAttrColor; @@ -598,7 +601,7 @@ begin end; TPSTextOut(RenderCanvas, Angle, RenderIn, HeadTextRect.Left + TextMargin, - HeadTextRect.Top + TextMargin, + (HeadTextRect.Top + HeadTextRect.Bottom - RenderCanvas.TextHeight('Tg')) div 2, //HeadTextRect.Top + TextMargin, HeadStr ); end; @@ -694,8 +697,7 @@ begin StartDate := GetStartOfWeek(RenderDate, WeekStartsOn); RenderCanvas.Font.Assign(FWeekView.DayHeadAttributes.Font); - with TVpWeekViewOpener(FWeekView) do - wvDayHeadHeight := RenderCanvas.TextHeight(VpProductName) + TextMargin + 2 ; + FDayHeadHeight := RenderCanvas.TextHeight(VpProductName) + TextMargin + 2 ; RenderCanvas.Font.Assign(FWeekView.EventFont); with TVpWeekViewOpener(FWeekView) do wvRowHeight := RenderCanvas.TextHeight(VpProductName) + TextMargin div 2;