Changeset 522 for GraphicTest/Packages/Graphics32/GR32_Image.pas
- Timestamp:
- Apr 17, 2019, 10:42:18 AM (5 years ago)
- Location:
- GraphicTest/Packages/Graphics32
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GraphicTest/Packages/Graphics32
-
Property svn:ignore
set to
lib
-
Property svn:ignore
set to
-
GraphicTest/Packages/Graphics32/GR32_Image.pas
r450 r522 49 49 {$ENDIF} 50 50 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; 53 53 54 54 const … … 118 118 procedure CMMouseEnter(var Message: TLMessage); message LM_MOUSEENTER; 119 119 procedure CMMouseLeave(var Message: TLMessage); message LM_MOUSELEAVE; 120 procedure CMInvalidate(var Message: TLMessage); message CM_INVALIDATE;121 120 {$ELSE} 122 121 procedure WMEraseBkgnd(var Message: TWmEraseBkgnd); message WM_ERASEBKGND; … … 278 277 procedure InvalidateCache; 279 278 function InvalidRectsAvailable: Boolean; override; 280 procedure DblClick; override;281 279 procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); overload; override; 282 280 procedure MouseMove(Shift: TShiftState; X, Y: Integer); overload; override; … … 366 364 property OnClick; 367 365 property OnChange; 366 property OnContextPopup; 368 367 property OnDblClick; 369 368 property OnGDIOverlay; … … 653 652 { TCustomPaintBox32 } 654 653 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} 665 655 procedure TCustomPaintBox32.CMInvalidate(var Message: TMessage); 666 656 begin … … 848 838 end; 849 839 850 procedure TCustomPaintBox32.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); 840 procedure TCustomPaintBox32.MouseDown(Button: TMouseButton; Shift: TShiftState; 841 X, Y: Integer); 851 842 begin 852 843 if (pboAutoFocus in Options) and CanFocus then SetFocus; … … 874 865 875 866 if FRepaintOptimizer.Enabled then 876 begin877 867 FRepaintOptimizer.BeginPaint; 878 end;879 868 880 869 if not FBufferValid then … … 984 973 procedure TCustomPaintBox32.WMGetDlgCode(var Msg: {$IFDEF FPC}TLMessage{$ELSE}TWmGetDlgCode{$ENDIF}); 985 974 begin 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; 990 980 end; 991 981 … … 1050 1040 { TCustomImage32 } 1051 1041 1042 constructor TCustomImage32.Create(AOwner: TComponent); 1043 begin 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; 1068 end; 1069 1070 destructor TCustomImage32.Destroy; 1071 begin 1072 BeginUpdate; 1073 FPaintStages.Free; 1074 FRepaintOptimizer.UnregisterLayerCollection(FLayers); 1075 FLayers.Free; 1076 FBitmap.Free; 1077 inherited; 1078 end; 1079 1052 1080 procedure TCustomImage32.BeginUpdate; 1053 1081 begin … … 1104 1132 end; 1105 1133 1106 function TCustomImage32.CanAutoSize(var NewWidth, NewHeight: Integer): Boolean;1107 var1108 W, H: Integer;1109 begin1110 InvalidateCache;1111 Result := True;1112 W := Bitmap.Width;1113 H := Bitmap.Height;1114 if ScaleMode = smScale then1115 begin1116 W := Round(W * Scale);1117 H := Round(H * Scale);1118 end;1119 if not (csDesigning in ComponentState) or (W > 0) and (H > 0) then1120 begin1121 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 begin1128 if FUpdateCount = 0 then1129 begin1130 Invalidate;1131 if Assigned(FOnChange) then FOnChange(Self);1132 end;1133 end;1134 1135 procedure TCustomImage32.Update(const Rect: TRect);1136 begin1137 if FRepaintOptimizer.Enabled then1138 FRepaintOptimizer.AreaUpdateHandler(Self, Rect, AREAINFO_RECT);1139 end;1140 1141 1134 procedure TCustomImage32.BitmapResizeHandler(Sender: TObject); 1142 1135 begin … … 1150 1143 end; 1151 1144 1152 procedure TCustomImage32.BitmapAreaChangeHandler(Sender: TObject; const Area: TRect; const Info: Cardinal); 1145 procedure TCustomImage32.BitmapAreaChangeHandler(Sender: TObject; 1146 const Area: TRect; const Info: Cardinal); 1153 1147 var 1154 1148 T, R: TRect; … … 1185 1179 end; 1186 1180 1187 procedure TCustomImage32.BitmapDirectAreaChangeHandler(Sender: TObject; const Area: TRect; const Info: Cardinal); 1181 procedure TCustomImage32.BitmapDirectAreaChangeHandler(Sender: TObject; 1182 const Area: TRect; const Info: Cardinal); 1188 1183 var 1189 1184 T, R: TRect; … … 1224 1219 end; 1225 1220 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; 1221 function TCustomImage32.CanAutoSize(var NewWidth, NewHeight: Integer): Boolean; 1222 var 1223 W, H: Integer; 1224 begin 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; 1239 end; 1240 1241 procedure TCustomImage32.Changed; 1242 begin 1243 if FUpdateCount = 0 then 1244 begin 1245 Invalidate; 1246 if Assigned(FOnChange) then FOnChange(Self); 1247 end; 1250 1248 end; 1251 1249 … … 1285 1283 Result.Y := (Y - CachedShiftY) * CachedRecScaleY; 1286 1284 end; 1287 end;1288 1289 1290 constructor TCustomImage32.Create(AOwner: TComponent);1291 begin1292 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) do1300 begin1301 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 begin1320 Layers.MouseListener := nil;1321 MouseUp(mbLeft, [], 0, 0);1322 inherited;1323 end;1324 1325 destructor TCustomImage32.Destroy;1326 begin1327 BeginUpdate;1328 FPaintStages.Free;1329 FRepaintOptimizer.UnregisterLayerCollection(FLayers);1330 FLayers.Free;1331 FBitmap.Free;1332 inherited;1333 1285 end; 1334 1286 … … 1674 1626 procedure TCustomImage32.InvalidateCache; 1675 1627 begin 1676 if FRepaintOptimizer.Enabled then FRepaintOptimizer.Reset; 1628 if FRepaintOptimizer.Enabled and CacheValid then 1629 FRepaintOptimizer.Reset; 1677 1630 CacheValid := False; 1678 1631 end; 1679 1632 1633 function TCustomImage32.InvalidRectsAvailable: Boolean; 1634 begin 1635 // avoid calling inherited, we have a totally different behaviour here... 1636 DoPrepareInvalidRects; 1637 Result := FInvalidRects.Count > 0; 1638 end; 1639 1640 procedure TCustomImage32.LayerCollectionChangeHandler(Sender: TObject); 1641 begin 1642 Changed; 1643 end; 1644 1645 procedure TCustomImage32.LayerCollectionGDIUpdateHandler(Sender: TObject); 1646 begin 1647 Paint; 1648 end; 1649 1650 procedure TCustomImage32.LayerCollectionGetViewportScaleHandler(Sender: TObject; 1651 out ScaleX, ScaleY: TFloat); 1652 begin 1653 UpdateCache; 1654 ScaleX := CachedScaleX; 1655 ScaleY := CachedScaleY; 1656 end; 1657 1658 procedure TCustomImage32.LayerCollectionGetViewportShiftHandler(Sender: TObject; 1659 out ShiftX, ShiftY: TFloat); 1660 begin 1661 UpdateCache; 1662 ShiftX := CachedShiftX; 1663 ShiftY := CachedShiftY; 1664 end; 1665 1680 1666 procedure TCustomImage32.Loaded; 1681 1667 begin … … 1691 1677 1692 1678 if TabStop and CanFocus then SetFocus; 1693 1679 1694 1680 if Layers.MouseEvents then 1695 1681 Layer := TLayerCollectionAccess(Layers).MouseDown(Button, Shift, X, Y) … … 1720 1706 var 1721 1707 Layer: TCustomLayer; 1722 begin 1708 MouseListener: TCustomLayer; 1709 begin 1710 MouseListener := TLayerCollectionAccess(Layers).MouseListener; 1711 1723 1712 if Layers.MouseEvents then 1724 1713 Layer := TLayerCollectionAccess(Layers).MouseUp(Button, Shift, X, Y) … … 1727 1716 1728 1717 // unlock the capture using same criteria as was used to acquire it 1729 if (Button = mbLeft) or ( TLayerCollectionAccess(Layers).MouseListener <> nil) then1718 if (Button = mbLeft) or ((MouseListener <> nil) and (TLayerCollectionAccess(Layers).MouseListener = nil)) then 1730 1719 MouseCapture := False; 1731 1720 … … 1736 1725 Shift: TShiftState; X, Y: Integer; Layer: TCustomLayer); 1737 1726 begin 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); 1739 1729 end; 1740 1730 … … 1742 1732 Layer: TCustomLayer); 1743 1733 begin 1744 if Assigned(FOnMouseMove) then FOnMouseMove(Self, Shift, X, Y, Layer); 1734 if Assigned(FOnMouseMove) then 1735 FOnMouseMove(Self, Shift, X, Y, Layer); 1745 1736 end; 1746 1737 … … 1748 1739 X, Y: Integer; Layer: TCustomLayer); 1749 1740 begin 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); 1751 1743 end; 1752 1744 … … 1933 1925 end; 1934 1926 1935 procedure TCustomImage32.UpdateCache;1936 begin1937 if CacheValid then Exit;1938 CachedBitmapRect := GetBitmapRect;1939 1940 if Bitmap.Empty then1941 SetXForm(0, 0, 1, 1)1942 else1943 SetXForm(1944 CachedBitmapRect.Left, CachedBitmapRect.Top,1945 (CachedBitmapRect.Right - CachedBitmapRect.Left) / Bitmap.Width,1946 (CachedBitmapRect.Bottom - CachedBitmapRect.Top) / Bitmap.Height1947 );1948 1949 CacheValid := True;1950 end;1951 1952 function TCustomImage32.InvalidRectsAvailable: Boolean;1953 begin1954 // avoid calling inherited, we have a totally different behaviour here...1955 DoPrepareInvalidRects;1956 Result := FInvalidRects.Count > 0;1957 end;1958 1959 1927 procedure TCustomImage32.SetRepaintMode(const Value: TRepaintMode); 1960 1928 begin … … 1977 1945 end; 1978 1946 end; 1947 1948 procedure TCustomImage32.Update(const Rect: TRect); 1949 begin 1950 if FRepaintOptimizer.Enabled then 1951 FRepaintOptimizer.AreaUpdateHandler(Self, Rect, AREAINFO_RECT); 1952 end; 1953 1954 procedure TCustomImage32.UpdateCache; 1955 begin 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; 1969 end; 1970 1979 1971 1980 1972 { TIVScrollProperties } … … 2404 2396 begin 2405 2397 if W > Sz.Cx + 2 * ScaledOversize then // Viewport is bigger than scaled Bitmap 2406 OffsetHorz := (W - Sz.Cx) / 22398 OffsetHorz := (W - Sz.Cx) * 0.5 2407 2399 else 2408 2400 OffsetHorz := -HScroll.Position + ScaledOversize; 2409 2401 2410 2402 if H > Sz.Cy + 2 * ScaledOversize then // Viewport is bigger than scaled Bitmap 2411 OffsetVert := (H - Sz.Cy) / 22403 OffsetVert := (H - Sz.Cy) * 0.5 2412 2404 else 2413 2405 OffsetVert := -VScroll.Position + ScaledOversize;
Note:
See TracChangeset
for help on using the changeset viewer.