source: trunk/Packages/Graphics32/GR32_RepaintOpt.pas

Last change on this file was 2, checked in by chronos, 5 years ago
File size: 5.2 KB
Line 
1unit GR32_RepaintOpt;
2
3(* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1 or LGPL 2.1 with linking exception
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * Alternatively, the contents of this file may be used under the terms of the
17 * Free Pascal modified version of the GNU Lesser General Public License
18 * Version 2.1 (the "FPC modified LGPL License"), in which case the provisions
19 * of this license are applicable instead of those above.
20 * Please see the file LICENSE.txt for additional information concerning this
21 * license.
22 *
23 * The Original Code is Repaint Optimizer Extension for Graphics32
24 *
25 * The Initial Developer of the Original Code is
26 * Andre Beckedorf - metaException
27 * Andre@metaException.de
28 *
29 * Portions created by the Initial Developer are Copyright (C) 2005-2009
30 * the Initial Developer. All Rights Reserved.
31 *
32 * Contributor(s):
33 *
34 * ***** END LICENSE BLOCK ***** *)
35
36interface
37
38{$I GR32.inc}
39
40uses
41{$IFDEF FPC}
42 LCLIntf,
43{$ELSE}
44 Types, Windows,
45{$ENDIF}
46 Classes, SysUtils, GR32, GR32_Containers, GR32_Layers;
47
48type
49 { TCustomRepaintOptimizer }
50 TCustomRepaintOptimizer = class
51 private
52 FEnabled: Boolean;
53 FLayerCollections: TList;
54 FInvalidRects: TRectList;
55 FBuffer: TBitmap32;
56 protected
57 function GetEnabled: Boolean; virtual;
58 procedure SetEnabled(const Value: Boolean); virtual;
59 property LayerCollections: TList read FLayerCollections write FLayerCollections;
60 property Buffer: TBitmap32 read FBuffer write FBuffer;
61 property InvalidRects: TRectList read FInvalidRects write FInvalidRects;
62
63 // LayerCollection handler
64 procedure LayerCollectionNotifyHandler(Sender: TLayerCollection;
65 Action: TLayerListNotification; Layer: TCustomLayer; Index: Integer); virtual; abstract;
66 public
67 constructor Create(Buffer: TBitmap32; InvalidRects: TRectList); virtual;
68 destructor Destroy; override;
69
70 procedure RegisterLayerCollection(Layers: TLayerCollection); virtual;
71 procedure UnregisterLayerCollection(Layers: TLayerCollection); virtual;
72
73 procedure BeginPaint; virtual;
74 procedure EndPaint; virtual;
75 procedure BeginPaintBuffer; virtual;
76 procedure EndPaintBuffer; virtual;
77
78 procedure Reset; virtual; abstract;
79 function UpdatesAvailable: Boolean; virtual; abstract;
80 procedure PerformOptimization; virtual; abstract;
81
82 // handlers
83 procedure AreaUpdateHandler(Sender: TObject; const Area: TRect; const Info: Cardinal); virtual; abstract;
84 procedure LayerUpdateHandler(Sender: TObject; Layer: TCustomLayer); virtual; abstract;
85 procedure BufferResizedHandler(const NewWidth, NewHeight: Integer); virtual; abstract;
86
87 property Enabled: Boolean read GetEnabled write SetEnabled;
88 end;
89
90 TCustomRepaintOptimizerClass = class of TCustomRepaintOptimizer;
91
92// differs from InflateRect in the way that it does also handle negative rects
93procedure InflateArea(var Area: TRect; Dx, Dy: Integer);
94
95implementation
96
97procedure InflateArea(var Area: TRect; Dx, Dy: Integer);
98begin
99 if Area.Left > Area.Right then
100 Dx := -Dx;
101
102 if Area.Top > Area.Bottom then
103 Dy := -Dy;
104
105 Dec(Area.Left, Dx); Dec(Area.Top, Dy);
106 Inc(Area.Right, Dx); Inc(Area.Bottom, Dy);
107end;
108
109type
110 TLayerCollectionAccess = class(TLayerCollection);
111
112{ TCustomRepaintManager }
113
114constructor TCustomRepaintOptimizer.Create(Buffer: TBitmap32; InvalidRects: TRectList);
115begin
116 FLayerCollections := TList.Create;
117 FInvalidRects := InvalidRects;
118 FBuffer := Buffer;
119end;
120
121destructor TCustomRepaintOptimizer.Destroy;
122var
123 I: Integer;
124begin
125 for I := 0 to FLayerCollections.Count - 1 do
126 UnregisterLayerCollection(TLayerCollection(FLayerCollections[I]));
127
128 FLayerCollections.Free;
129 inherited;
130end;
131
132function TCustomRepaintOptimizer.GetEnabled: Boolean;
133begin
134 Result := FEnabled;
135end;
136
137procedure TCustomRepaintOptimizer.SetEnabled(const Value: Boolean);
138begin
139 FEnabled := Value;
140end;
141
142procedure TCustomRepaintOptimizer.RegisterLayerCollection(Layers: TLayerCollection);
143begin
144 if FLayerCollections.IndexOf(Layers) = -1 then
145 begin
146 FLayerCollections.Add(Layers);
147 TLayerCollectionAccess(Layers).OnListNotify := LayerCollectionNotifyHandler;
148 end;
149end;
150
151procedure TCustomRepaintOptimizer.UnregisterLayerCollection(Layers: TLayerCollection);
152begin
153 TLayerCollectionAccess(Layers).OnListNotify := nil;
154 FLayerCollections.Remove(Layers);
155end;
156
157procedure TCustomRepaintOptimizer.BeginPaint;
158begin
159 // do nothing by default
160end;
161
162procedure TCustomRepaintOptimizer.EndPaint;
163begin
164 // do nothing by default
165end;
166
167procedure TCustomRepaintOptimizer.BeginPaintBuffer;
168begin
169 // do nothing by default
170end;
171
172procedure TCustomRepaintOptimizer.EndPaintBuffer;
173begin
174 // do nothing by default
175end;
176
177end.
Note: See TracBrowser for help on using the repository browser.