tvplanit: Refactor painting code of TVpDayView (new helper unit TVpDayViewPainter)

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4804 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-06-22 14:43:43 +00:00
parent 38be775a00
commit 705a6878ac
3 changed files with 1875 additions and 26 deletions

View File

@ -32,7 +32,7 @@ Portions created by TurboPower Software Inc. are Copyright (C) 2002 TurboPower S
Contributor(s): "/> Contributor(s): "/>
<Version Major="1" Release="4"/> <Version Major="1" Release="4"/>
<Files Count="64"> <Files Count="65">
<Item1> <Item1>
<Filename Value="../source/vpalarmdlg.lfm"/> <Filename Value="../source/vpalarmdlg.lfm"/>
<Type Value="LFM"/> <Type Value="LFM"/>
@ -290,6 +290,10 @@ Contributor(s): "/>
<Filename Value="../source/vpbufds.pas"/> <Filename Value="../source/vpbufds.pas"/>
<UnitName Value="VpBufDS"/> <UnitName Value="VpBufDS"/>
</Item64> </Item64>
<Item65>
<Filename Value="../source/vpdayviewpainter.pas"/>
<UnitName Value="VpDayViewPainter"/>
</Item65>
</Files> </Files>
<i18n> <i18n>
<EnableI18N Value="True"/> <EnableI18N Value="True"/>

View File

@ -489,7 +489,7 @@ type
implementation implementation
uses uses
SysUtils, Math, Forms, Dialogs, VpEvntEditDlg; SysUtils, Math, Forms, Dialogs, VpEvntEditDlg, VpDayViewPainter;
(*****************************************************************************) (*****************************************************************************)
{ TVpTGInPlaceEdit } { TVpTGInPlaceEdit }
@ -2265,6 +2265,21 @@ end;
procedure TVpDayView.RenderToCanvas(RenderCanvas: TCanvas; RenderIn: TRect; procedure TVpDayView.RenderToCanvas(RenderCanvas: TCanvas; RenderIn: TRect;
Angle: TVpRotationAngle; Scale: Extended; RenderDate: TDateTime; Angle: TVpRotationAngle; Scale: Extended; RenderDate: TDateTime;
StartLine, StopLine: Integer; UseGran: TVpGranularity; DisplayOnly: Boolean); StartLine, StopLine: Integer; UseGran: TVpGranularity; DisplayOnly: Boolean);
var
painter: TVpDayViewPainter;
begin
dvPainting := true;
painter := TVpDayviewPainter.Create(Self, RenderCanvas);
try
painter.RenderToCanvas(RenderIn, Angle, Scale, RenderDate, StartLine,
StopLine, UseGran, DisplayOnly);
finally
painter.Free;
dvPainting := false;
end;
end;
(*
var var
TextWidth: Integer; TextWidth: Integer;
ColHeadRect: TRect; ColHeadRect: TRect;
@ -2674,8 +2689,8 @@ var
end; end;
end; end;
(* original version { original version
{ Draws the all-day events at the top of the DayView in a special manner } // Draws the all-day events at the top of the DayView in a special manner
procedure DrawAllDayEvents; procedure DrawAllDayEvents;
var var
ADEventsList : TList; ADEventsList : TList;
@ -2693,8 +2708,8 @@ var
if (DataStore = nil) or (DataStore.Resource = nil) then if (DataStore = nil) or (DataStore.Resource = nil) then
Exit; Exit;
{ Collect all of the events for this range and determine the maximum } // Collect all of the events for this range and determine the maximum
{ 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.
MaxADEvents := 0; MaxADEvents := 0;
ADEventsList := TList.Create; ADEventsList := TList.Create;
@ -2702,17 +2717,17 @@ var
TempList := TList.Create; TempList := TList.Create;
try try
for I := 0 to pred(RealNumDays) do begin for I := 0 to pred(RealNumDays) do begin
{ skip weekends } // skip weekends
if ((DayOfWeek (RenderDate + i) = 1) or if ((DayOfWeek (RenderDate + i) = 1) or
(DayOfWeek (RenderDate + i) = 7)) and (DayOfWeek (RenderDate + i) = 7)) and
(not FIncludeWeekends) then (not FIncludeWeekends) then
Continue; Continue;
{ get the all day events for the day specified by RenderDate + I } // get the all day events for the day specified by RenderDate + I
DataStore.Resource.Schedule.AllDayEventsByDate(RenderDate + I, DataStore.Resource.Schedule.AllDayEventsByDate(RenderDate + I,
TempList); TempList);
{ Iterate through these events and place them in ADEventsList } // Iterate through these events and place them in ADEventsList
Skip := false; Skip := false;
for J := 0 to pred(TempList.Count) do begin for J := 0 to pred(TempList.Count) do begin
if AdEventsList.Count > 0 then begin if AdEventsList.Count > 0 then begin
@ -2736,31 +2751,31 @@ var
end; end;
if MaxADEvents > 0 then begin if MaxADEvents > 0 then begin
{ Set attributes } // Set attributes
RenderCanvas.Brush.Color := RealADEventBkgColor; RenderCanvas.Brush.Color := RealADEventBkgColor;
RenderCanvas.Font.Assign (AllDayEventAttributes.Font); RenderCanvas.Font.Assign (AllDayEventAttributes.Font);
{ Measure the AllDayEvent TextHeight } // Measure the AllDayEvent TextHeight
ADTextHeight := RenderCanvas.TextHeight(VpProductName) + TextMargin; ADTextHeight := RenderCanvas.TextHeight(VpProductName) + TextMargin;
{ Build the AllDayEvent rect based on the value of MaxADEvents } // Build the AllDayEvent rect based on the value of MaxADEvents
ADEventsRect.Bottom := AdEventsRect.Top ADEventsRect.Bottom := AdEventsRect.Top
+ (MaxADEvents * ADTextHeight) + TextMargin * 2; + (MaxADEvents * ADTextHeight) + TextMargin * 2;
{ Clear the AllDayEvents area } // Clear the AllDayEvents area
TpsFillRect(RenderCanvas, Angle, RenderIn, ADEventsRect); TpsFillRect(RenderCanvas, Angle, RenderIn, ADEventsRect);
StartsBeforeRange := false; StartsBeforeRange := false;
{ Cycle through the all day events and draw them appropriately } // Cycle through the all day events and draw them appropriately
for I := 0 to pred(ADEventsList.Count) do begin for I := 0 to pred(ADEventsList.Count) do begin
Event := ADEventsList[I]; Event := ADEventsList[I];
{ set the top of the event's rect } // set the top of the event's rect
AdEventRect.Top := ADEventsRect.Top + TextMargin AdEventRect.Top := ADEventsRect.Top + TextMargin
+ (I * ADTextHeight); + (I * ADTextHeight);
{ see if the event began before the start of the range } // see if the event began before the start of the range
if (Event.StartTime < trunc(RenderDate)) then if (Event.StartTime < trunc(RenderDate)) then
StartsBeforeRange := true; StartsBeforeRange := true;
@ -2793,14 +2808,14 @@ var
ADEventRect.Bottom); ADEventRect.Bottom);
dvEventArray[EventCount].Event := Event; dvEventArray[EventCount].Event := Event;
Inc (EventCount); Inc (EventCount);
end; { for I := 0 to pred(ADEventsList.Count) do ... } end; // for I := 0 to pred(ADEventsList.Count) do ...
end; { if MaxADEvents > 0 } end; // if MaxADEvents > 0
finally finally
ADEventsList.Free; ADEventsList.Free;
end; end;
end; *) end; }
procedure DrawEvents(RenderDate: TDateTime; Col: Integer); procedure DrawEvents(RenderDate: TDateTime; Col: Integer);
@ -2861,12 +2876,12 @@ var
Event2 := EventArray[K].Event; Event2 := EventArray[K].Event;
{ if the Tmp event overlaps with Event, then check it's Width divisor } { if the Tmp event overlaps with Event, then check it's Width divisor }
(* -- original {-- original
if (TimeInRange(Event2.StartTime, Event1.StartTime, Event1.EndTime, false) if (TimeInRange(Event2.StartTime, Event1.StartTime, Event1.EndTime, false)
or TimeInRange(Event2.EndTime, Event1.StartTime, Event1.EndTime, false)) or TimeInRange(Event2.EndTime, Event1.StartTime, Event1.EndTime, false))
or ((Event2.StartTime <= Event1.StartTime) or ((Event2.StartTime <= Event1.StartTime)
and (Event2.EndTime >= Event1.EndTime)) and (Event2.EndTime >= Event1.EndTime))
*) }
if TimeInRange(frac(Event2.StartTime), frac(Event1.StartTime), frac(Event1.EndTime), false) or if TimeInRange(frac(Event2.StartTime), frac(Event1.StartTime), frac(Event1.EndTime), false) or
TimeInRange(frac(Event2.EndTime), frac(Event1.StartTime), frac(Event1.EndTime), false) or TimeInRange(frac(Event2.EndTime), frac(Event1.StartTime), frac(Event1.EndTime), false) or
((frac(Event2.StartTime) <= frac(Event1.StartTime)) and (frac(Event2.EndTime) >= frac(Event1.EndTime))) ((frac(Event2.StartTime) <= frac(Event1.StartTime)) and (frac(Event2.EndTime) >= frac(Event1.EndTime)))
@ -3225,8 +3240,8 @@ var
{ if we have hit the end of the events, then bail out } { if we have hit the end of the events, then bail out }
if Event = nil then if Event = nil then
Break; Break;
(* -- original { -- original
{ remove the date portion from the start and end times } // remove the date portion from the start and end times
EventSTime := Event.StartTime; EventSTime := Event.StartTime;
EventETime := Event.EndTime; EventETime := Event.EndTime;
if trunc(EventSTime) < trunc(RenderDate) then //First Event if trunc(EventSTime) < trunc(RenderDate) then //First Event
@ -3235,12 +3250,12 @@ var
EventETime := 0.999+trunc(RenderDate); EventETime := 0.999+trunc(RenderDate);
EventSTime := EventSTime - RenderDate; EventSTime := EventSTime - RenderDate;
EventETime := EventETime - RenderDate; EventETime := EventETime - RenderDate;
{ Find the line on which this event starts } // Find the line on which this event starts
EventSLine := GetStartLine(EventSTime, Granularity); EventSLine := GetStartLine(EventSTime, Granularity);
{ Handle End Times of Midnight } // Handle End Times of Midnight
if EventETime = 0 then if EventETime = 0 then
EventETime := EncodeTime (23, 59, 59, 0); EventETime := EncodeTime (23, 59, 59, 0);
*) }
{ remove the date portion from the start and end times } { remove the date portion from the start and end times }
EventSTime := Event.StartTime; EventSTime := Event.StartTime;
@ -3992,6 +4007,7 @@ begin
dvPainting := false; dvPainting := false;
end; end;
*)
{=====} {=====}
{.$IFNDEF LCL} {.$IFNDEF LCL}

File diff suppressed because it is too large Load Diff