Ignore:
Timestamp:
Apr 17, 2019, 10:42:18 AM (5 years ago)
Author:
chronos
Message:
  • Modified: Updated Graphics32 library.
Location:
GraphicTest/Packages/Graphics32
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • GraphicTest/Packages/Graphics32

    • Property svn:ignore set to
      lib
  • GraphicTest/Packages/Graphics32/GR32_Image.pas

    r450 r522  
    4949{$ENDIF}
    5050  Graphics, Controls, Forms,
    51   Classes, SysUtils, GR32, GR32_Layers, GR32_RangeBars, GR32_LowLevel,
    52   GR32_System, GR32_Containers, GR32_RepaintOpt;
     51  Classes, SysUtils, GR32, GR32_Layers, GR32_RangeBars, GR32_Containers,
     52  GR32_RepaintOpt;
    5353
    5454const
     
    118118    procedure CMMouseEnter(var Message: TLMessage); message LM_MOUSEENTER;
    119119    procedure CMMouseLeave(var Message: TLMessage); message LM_MOUSELEAVE;
    120     procedure CMInvalidate(var Message: TLMessage); message CM_INVALIDATE;
    121120{$ELSE}
    122121    procedure WMEraseBkgnd(var Message: TWmEraseBkgnd); message WM_ERASEBKGND;
     
    278277    procedure InvalidateCache;
    279278    function  InvalidRectsAvailable: Boolean; override;
    280     procedure DblClick; override;
    281279    procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); overload; override;
    282280    procedure MouseMove(Shift: TShiftState; X, Y: Integer); overload; override;
     
    366364    property OnClick;
    367365    property OnChange;
     366    property OnContextPopup;
    368367    property OnDblClick;
    369368    property OnGDIOverlay;
     
    653652{ TCustomPaintBox32 }
    654653
    655 {$IFDEF FPC}
    656 procedure TCustomPaintBox32.CMInvalidate(var Message: TLMessage);
    657 begin
    658   if CustomRepaint and HandleAllocated then
    659     PostMessage(Handle, LM_PAINT, 0, 0)
    660   else
    661     inherited;
    662 end;
    663 {$ELSE}
    664 
     654{$IFNDEF FPC}
    665655procedure TCustomPaintBox32.CMInvalidate(var Message: TMessage);
    666656begin
     
    848838end;
    849839
    850 procedure TCustomPaintBox32.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
     840procedure TCustomPaintBox32.MouseDown(Button: TMouseButton; Shift: TShiftState;
     841  X, Y: Integer);
    851842begin
    852843  if (pboAutoFocus in Options) and CanFocus then SetFocus;
     
    874865
    875866  if FRepaintOptimizer.Enabled then
    876   begin
    877867    FRepaintOptimizer.BeginPaint;
    878   end;
    879868
    880869  if not FBufferValid then
     
    984973procedure TCustomPaintBox32.WMGetDlgCode(var Msg: {$IFDEF FPC}TLMessage{$ELSE}TWmGetDlgCode{$ENDIF});
    985974begin
    986   with Msg do if pboWantArrowKeys in Options then
    987     Result:= Result or DLGC_WANTARROWS
    988   else
    989     Result:= Result and not DLGC_WANTARROWS;
     975  with Msg do
     976    if pboWantArrowKeys in Options then
     977      Result:= Result or DLGC_WANTARROWS
     978    else
     979      Result:= Result and not DLGC_WANTARROWS;
    990980end;
    991981
     
    10501040{ TCustomImage32 }
    10511041
     1042constructor TCustomImage32.Create(AOwner: TComponent);
     1043begin
     1044  inherited;
     1045  ControlStyle := [csAcceptsControls, csCaptureMouse, csClickEvents,
     1046    csDoubleClicks, csReplicatable, csOpaque];
     1047  FBitmap := TBitmap32.Create;
     1048  FBitmap.OnResize := BitmapResizeHandler;
     1049
     1050  FLayers := TLayerCollection.Create(Self);
     1051  with TLayerCollectionAccess(FLayers) do
     1052  begin
     1053    OnChange := LayerCollectionChangeHandler;
     1054    OnGDIUpdate := LayerCollectionGDIUpdateHandler;
     1055    OnGetViewportScale := LayerCollectionGetViewportScaleHandler;
     1056    OnGetViewportShift := LayerCollectionGetViewportShiftHandler;
     1057  end;
     1058
     1059  FRepaintOptimizer.RegisterLayerCollection(FLayers);
     1060  RepaintMode := rmFull;
     1061
     1062  FPaintStages := TPaintStages.Create;
     1063  FScaleX := 1;
     1064  FScaleY := 1;
     1065  SetXForm(0, 0, 1, 1);
     1066
     1067  InitDefaultStages;
     1068end;
     1069
     1070destructor TCustomImage32.Destroy;
     1071begin
     1072  BeginUpdate;
     1073  FPaintStages.Free;
     1074  FRepaintOptimizer.UnregisterLayerCollection(FLayers);
     1075  FLayers.Free;
     1076  FBitmap.Free;
     1077  inherited;
     1078end;
     1079
    10521080procedure TCustomImage32.BeginUpdate;
    10531081begin
     
    11041132end;
    11051133
    1106 function TCustomImage32.CanAutoSize(var NewWidth, NewHeight: Integer): Boolean;
    1107 var
    1108   W, H: Integer;
    1109 begin
    1110   InvalidateCache;
    1111   Result := True;
    1112   W := Bitmap.Width;
    1113   H := Bitmap.Height;
    1114   if ScaleMode = smScale then
    1115   begin
    1116     W := Round(W * Scale);
    1117     H := Round(H * Scale);
    1118   end;
    1119   if not (csDesigning in ComponentState) or (W > 0) and (H > 0) then
    1120   begin
    1121     if Align in [alNone, alLeft, alRight] then NewWidth := W;
    1122     if Align in [alNone, alTop, alBottom] then NewHeight := H;
    1123   end;
    1124 end;
    1125 
    1126 procedure TCustomImage32.Changed;
    1127 begin
    1128   if FUpdateCount = 0 then
    1129   begin
    1130     Invalidate;
    1131     if Assigned(FOnChange) then FOnChange(Self);
    1132   end;
    1133 end;
    1134 
    1135 procedure TCustomImage32.Update(const Rect: TRect);
    1136 begin
    1137   if FRepaintOptimizer.Enabled then
    1138     FRepaintOptimizer.AreaUpdateHandler(Self, Rect, AREAINFO_RECT);
    1139 end;
    1140 
    11411134procedure TCustomImage32.BitmapResizeHandler(Sender: TObject);
    11421135begin
     
    11501143end;
    11511144
    1152 procedure TCustomImage32.BitmapAreaChangeHandler(Sender: TObject; const Area: TRect; const Info: Cardinal);
     1145procedure TCustomImage32.BitmapAreaChangeHandler(Sender: TObject;
     1146  const Area: TRect; const Info: Cardinal);
    11531147var
    11541148  T, R: TRect;
     
    11851179end;
    11861180
    1187 procedure TCustomImage32.BitmapDirectAreaChangeHandler(Sender: TObject; const Area: TRect; const Info: Cardinal);
     1181procedure TCustomImage32.BitmapDirectAreaChangeHandler(Sender: TObject;
     1182  const Area: TRect; const Info: Cardinal);
    11881183var
    11891184  T, R: TRect;
     
    12241219end;
    12251220
    1226 procedure TCustomImage32.LayerCollectionChangeHandler(Sender: TObject);
    1227 begin
    1228   Changed;
    1229 end;
    1230 
    1231 procedure TCustomImage32.LayerCollectionGDIUpdateHandler(Sender: TObject);
    1232 begin
    1233   Paint;
    1234 end;
    1235 
    1236 procedure TCustomImage32.LayerCollectionGetViewportScaleHandler(Sender: TObject;
    1237   out ScaleX, ScaleY: TFloat);
    1238 begin
    1239   UpdateCache;
    1240   ScaleX := CachedScaleX;
    1241   ScaleY := CachedScaleY;
    1242 end;
    1243 
    1244 procedure TCustomImage32.LayerCollectionGetViewportShiftHandler(Sender: TObject;
    1245   out ShiftX, ShiftY: TFloat);
    1246 begin
    1247   UpdateCache;
    1248   ShiftX := CachedShiftX;
    1249   ShiftY := CachedShiftY;
     1221function TCustomImage32.CanAutoSize(var NewWidth, NewHeight: Integer): Boolean;
     1222var
     1223  W, H: Integer;
     1224begin
     1225  InvalidateCache;
     1226  Result := True;
     1227  W := Bitmap.Width;
     1228  H := Bitmap.Height;
     1229  if ScaleMode = smScale then
     1230  begin
     1231    W := Round(W * Scale);
     1232    H := Round(H * Scale);
     1233  end;
     1234  if not (csDesigning in ComponentState) or (W > 0) and (H > 0) then
     1235  begin
     1236    if Align in [alNone, alLeft, alRight] then NewWidth := W;
     1237    if Align in [alNone, alTop, alBottom] then NewHeight := H;
     1238  end;
     1239end;
     1240
     1241procedure TCustomImage32.Changed;
     1242begin
     1243  if FUpdateCount = 0 then
     1244  begin
     1245    Invalidate;
     1246    if Assigned(FOnChange) then FOnChange(Self);
     1247  end;
    12501248end;
    12511249
     
    12851283      Result.Y := (Y - CachedShiftY) * CachedRecScaleY;
    12861284  end;
    1287 end;
    1288 
    1289 
    1290 constructor TCustomImage32.Create(AOwner: TComponent);
    1291 begin
    1292   inherited;
    1293   ControlStyle := [csAcceptsControls, csCaptureMouse, csClickEvents,
    1294     csDoubleClicks, csReplicatable, csOpaque];
    1295   FBitmap := TBitmap32.Create;
    1296   FBitmap.OnResize := BitmapResizeHandler;
    1297 
    1298   FLayers := TLayerCollection.Create(Self);
    1299   with TLayerCollectionAccess(FLayers) do
    1300   begin
    1301     OnChange := LayerCollectionChangeHandler;
    1302     OnGDIUpdate := LayerCollectionGDIUpdateHandler;
    1303     OnGetViewportScale := LayerCollectionGetViewportScaleHandler;
    1304     OnGetViewportShift := LayerCollectionGetViewportShiftHandler;
    1305   end;
    1306 
    1307   FRepaintOptimizer.RegisterLayerCollection(FLayers);
    1308   RepaintMode := rmFull;
    1309 
    1310   FPaintStages := TPaintStages.Create;
    1311   FScaleX := 1;
    1312   FScaleY := 1;
    1313   SetXForm(0, 0, 1, 1);
    1314 
    1315   InitDefaultStages;
    1316 end;
    1317 
    1318 procedure TCustomImage32.DblClick;
    1319 begin
    1320   Layers.MouseListener := nil;
    1321   MouseUp(mbLeft, [], 0, 0);
    1322   inherited;
    1323 end;
    1324 
    1325 destructor TCustomImage32.Destroy;
    1326 begin
    1327   BeginUpdate;
    1328   FPaintStages.Free;
    1329   FRepaintOptimizer.UnregisterLayerCollection(FLayers);
    1330   FLayers.Free;
    1331   FBitmap.Free;
    1332   inherited;
    13331285end;
    13341286
     
    16741626procedure TCustomImage32.InvalidateCache;
    16751627begin
    1676   if FRepaintOptimizer.Enabled then FRepaintOptimizer.Reset;
     1628  if FRepaintOptimizer.Enabled and CacheValid then
     1629    FRepaintOptimizer.Reset;
    16771630  CacheValid := False;
    16781631end;
    16791632
     1633function TCustomImage32.InvalidRectsAvailable: Boolean;
     1634begin
     1635  // avoid calling inherited, we have a totally different behaviour here...
     1636  DoPrepareInvalidRects;
     1637  Result := FInvalidRects.Count > 0;
     1638end;
     1639
     1640procedure TCustomImage32.LayerCollectionChangeHandler(Sender: TObject);
     1641begin
     1642  Changed;
     1643end;
     1644
     1645procedure TCustomImage32.LayerCollectionGDIUpdateHandler(Sender: TObject);
     1646begin
     1647  Paint;
     1648end;
     1649
     1650procedure TCustomImage32.LayerCollectionGetViewportScaleHandler(Sender: TObject;
     1651  out ScaleX, ScaleY: TFloat);
     1652begin
     1653  UpdateCache;
     1654  ScaleX := CachedScaleX;
     1655  ScaleY := CachedScaleY;
     1656end;
     1657
     1658procedure TCustomImage32.LayerCollectionGetViewportShiftHandler(Sender: TObject;
     1659  out ShiftX, ShiftY: TFloat);
     1660begin
     1661  UpdateCache;
     1662  ShiftX := CachedShiftX;
     1663  ShiftY := CachedShiftY;
     1664end;
     1665
    16801666procedure TCustomImage32.Loaded;
    16811667begin
     
    16911677
    16921678  if TabStop and CanFocus then SetFocus;
    1693  
     1679
    16941680  if Layers.MouseEvents then
    16951681    Layer := TLayerCollectionAccess(Layers).MouseDown(Button, Shift, X, Y)
     
    17201706var
    17211707  Layer: TCustomLayer;
    1722 begin
     1708  MouseListener: TCustomLayer;
     1709begin
     1710  MouseListener := TLayerCollectionAccess(Layers).MouseListener;
     1711
    17231712  if Layers.MouseEvents then
    17241713    Layer := TLayerCollectionAccess(Layers).MouseUp(Button, Shift, X, Y)
     
    17271716
    17281717  // unlock the capture using same criteria as was used to acquire it
    1729   if (Button = mbLeft) or (TLayerCollectionAccess(Layers).MouseListener <> nil) then
     1718  if (Button = mbLeft) or ((MouseListener <> nil) and (TLayerCollectionAccess(Layers).MouseListener = nil)) then
    17301719    MouseCapture := False;
    17311720
     
    17361725  Shift: TShiftState; X, Y: Integer; Layer: TCustomLayer);
    17371726begin
    1738   if Assigned(FOnMouseDown) then FOnMouseDown(Self, Button, Shift, X, Y, Layer);
     1727  if Assigned(FOnMouseDown) then
     1728    FOnMouseDown(Self, Button, Shift, X, Y, Layer);
    17391729end;
    17401730
     
    17421732  Layer: TCustomLayer);
    17431733begin
    1744   if Assigned(FOnMouseMove) then FOnMouseMove(Self, Shift, X, Y, Layer);
     1734  if Assigned(FOnMouseMove) then
     1735    FOnMouseMove(Self, Shift, X, Y, Layer);
    17451736end;
    17461737
     
    17481739  X, Y: Integer; Layer: TCustomLayer);
    17491740begin
    1750   if Assigned(FOnMouseUp) then FOnMouseUp(Self, Button, Shift, X, Y, Layer);
     1741  if Assigned(FOnMouseUp) then
     1742    FOnMouseUp(Self, Button, Shift, X, Y, Layer);
    17511743end;
    17521744
     
    19331925end;
    19341926
    1935 procedure TCustomImage32.UpdateCache;
    1936 begin
    1937   if CacheValid then Exit;
    1938   CachedBitmapRect := GetBitmapRect;
    1939 
    1940   if Bitmap.Empty then
    1941     SetXForm(0, 0, 1, 1)
    1942   else
    1943     SetXForm(
    1944       CachedBitmapRect.Left, CachedBitmapRect.Top,
    1945       (CachedBitmapRect.Right - CachedBitmapRect.Left) / Bitmap.Width,
    1946       (CachedBitmapRect.Bottom - CachedBitmapRect.Top) / Bitmap.Height
    1947     );
    1948 
    1949   CacheValid := True;
    1950 end;
    1951 
    1952 function TCustomImage32.InvalidRectsAvailable: Boolean;
    1953 begin
    1954   // avoid calling inherited, we have a totally different behaviour here...
    1955   DoPrepareInvalidRects;
    1956   Result := FInvalidRects.Count > 0;
    1957 end;
    1958 
    19591927procedure TCustomImage32.SetRepaintMode(const Value: TRepaintMode);
    19601928begin
     
    19771945  end;
    19781946end;
     1947
     1948procedure TCustomImage32.Update(const Rect: TRect);
     1949begin
     1950  if FRepaintOptimizer.Enabled then
     1951    FRepaintOptimizer.AreaUpdateHandler(Self, Rect, AREAINFO_RECT);
     1952end;
     1953
     1954procedure TCustomImage32.UpdateCache;
     1955begin
     1956  if CacheValid then Exit;
     1957  CachedBitmapRect := GetBitmapRect;
     1958
     1959  if Bitmap.Empty then
     1960    SetXForm(0, 0, 1, 1)
     1961  else
     1962    SetXForm(
     1963      CachedBitmapRect.Left, CachedBitmapRect.Top,
     1964      (CachedBitmapRect.Right - CachedBitmapRect.Left) / Bitmap.Width,
     1965      (CachedBitmapRect.Bottom - CachedBitmapRect.Top) / Bitmap.Height
     1966    );
     1967
     1968  CacheValid := True;
     1969end;
     1970
    19791971
    19801972{ TIVScrollProperties }
     
    24042396  begin
    24052397    if W > Sz.Cx + 2 * ScaledOversize then // Viewport is bigger than scaled Bitmap
    2406       OffsetHorz := (W - Sz.Cx) / 2
     2398      OffsetHorz := (W - Sz.Cx) * 0.5
    24072399    else
    24082400      OffsetHorz := -HScroll.Position + ScaledOversize;
    24092401
    24102402    if H > Sz.Cy + 2 * ScaledOversize then // Viewport is bigger than scaled Bitmap
    2411       OffsetVert := (H - Sz.Cy) / 2
     2403      OffsetVert := (H - Sz.Cy) * 0.5
    24122404    else
    24132405      OffsetVert := -VScroll.Position + ScaledOversize;
Note: See TracChangeset for help on using the changeset viewer.