| 1 | unit 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 |
|
|---|
| 36 | interface
|
|---|
| 37 |
|
|---|
| 38 | {$I GR32.inc}
|
|---|
| 39 |
|
|---|
| 40 | uses
|
|---|
| 41 | {$IFDEF FPC}
|
|---|
| 42 | LCLIntf,
|
|---|
| 43 | {$ELSE}
|
|---|
| 44 | Types, Windows,
|
|---|
| 45 | {$ENDIF}
|
|---|
| 46 | Classes, SysUtils, GR32, GR32_Containers, GR32_Layers;
|
|---|
| 47 |
|
|---|
| 48 | type
|
|---|
| 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
|
|---|
| 93 | procedure InflateArea(var Area: TRect; Dx, Dy: Integer);
|
|---|
| 94 |
|
|---|
| 95 | implementation
|
|---|
| 96 |
|
|---|
| 97 | procedure InflateArea(var Area: TRect; Dx, Dy: Integer);
|
|---|
| 98 | begin
|
|---|
| 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);
|
|---|
| 107 | end;
|
|---|
| 108 |
|
|---|
| 109 | type
|
|---|
| 110 | TLayerCollectionAccess = class(TLayerCollection);
|
|---|
| 111 |
|
|---|
| 112 | { TCustomRepaintManager }
|
|---|
| 113 |
|
|---|
| 114 | constructor TCustomRepaintOptimizer.Create(Buffer: TBitmap32; InvalidRects: TRectList);
|
|---|
| 115 | begin
|
|---|
| 116 | FLayerCollections := TList.Create;
|
|---|
| 117 | FInvalidRects := InvalidRects;
|
|---|
| 118 | FBuffer := Buffer;
|
|---|
| 119 | end;
|
|---|
| 120 |
|
|---|
| 121 | destructor TCustomRepaintOptimizer.Destroy;
|
|---|
| 122 | var
|
|---|
| 123 | I: Integer;
|
|---|
| 124 | begin
|
|---|
| 125 | for I := 0 to FLayerCollections.Count - 1 do
|
|---|
| 126 | UnregisterLayerCollection(TLayerCollection(FLayerCollections[I]));
|
|---|
| 127 |
|
|---|
| 128 | FLayerCollections.Free;
|
|---|
| 129 | inherited;
|
|---|
| 130 | end;
|
|---|
| 131 |
|
|---|
| 132 | function TCustomRepaintOptimizer.GetEnabled: Boolean;
|
|---|
| 133 | begin
|
|---|
| 134 | Result := FEnabled;
|
|---|
| 135 | end;
|
|---|
| 136 |
|
|---|
| 137 | procedure TCustomRepaintOptimizer.SetEnabled(const Value: Boolean);
|
|---|
| 138 | begin
|
|---|
| 139 | FEnabled := Value;
|
|---|
| 140 | end;
|
|---|
| 141 |
|
|---|
| 142 | procedure TCustomRepaintOptimizer.RegisterLayerCollection(Layers: TLayerCollection);
|
|---|
| 143 | begin
|
|---|
| 144 | if FLayerCollections.IndexOf(Layers) = -1 then
|
|---|
| 145 | begin
|
|---|
| 146 | FLayerCollections.Add(Layers);
|
|---|
| 147 | TLayerCollectionAccess(Layers).OnListNotify := LayerCollectionNotifyHandler;
|
|---|
| 148 | end;
|
|---|
| 149 | end;
|
|---|
| 150 |
|
|---|
| 151 | procedure TCustomRepaintOptimizer.UnregisterLayerCollection(Layers: TLayerCollection);
|
|---|
| 152 | begin
|
|---|
| 153 | TLayerCollectionAccess(Layers).OnListNotify := nil;
|
|---|
| 154 | FLayerCollections.Remove(Layers);
|
|---|
| 155 | end;
|
|---|
| 156 |
|
|---|
| 157 | procedure TCustomRepaintOptimizer.BeginPaint;
|
|---|
| 158 | begin
|
|---|
| 159 | // do nothing by default
|
|---|
| 160 | end;
|
|---|
| 161 |
|
|---|
| 162 | procedure TCustomRepaintOptimizer.EndPaint;
|
|---|
| 163 | begin
|
|---|
| 164 | // do nothing by default
|
|---|
| 165 | end;
|
|---|
| 166 |
|
|---|
| 167 | procedure TCustomRepaintOptimizer.BeginPaintBuffer;
|
|---|
| 168 | begin
|
|---|
| 169 | // do nothing by default
|
|---|
| 170 | end;
|
|---|
| 171 |
|
|---|
| 172 | procedure TCustomRepaintOptimizer.EndPaintBuffer;
|
|---|
| 173 | begin
|
|---|
| 174 | // do nothing by default
|
|---|
| 175 | end;
|
|---|
| 176 |
|
|---|
| 177 | end.
|
|---|