Changeset 521 for GraphicTest/Packages/bgrabitmap/bgragradients.pas
- Timestamp:
- Apr 17, 2019, 12:58:41 AM (5 years ago)
- Location:
- GraphicTest
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GraphicTest
- Property svn:ignore
-
old new 8 8 GraphicTest.lps 9 9 GraphicTest.dbg 10 heaptrclog.trc
-
- Property svn:ignore
-
GraphicTest/Packages/bgrabitmap/bgragradients.pas
r494 r521 29 29 function nGradientInfo(StartColor, StopColor: TBGRAPixel; Direction: TGradientDirection; EndPercent: Single): TnGradientInfo; 30 30 31 function nGradientAlphaFill(ARect: TRect; ADir: TGradientDirection; const AGradient: array of TnGradientInfo): TBGRABitmap; 32 function nGradientAlphaFill(AWidth, AHeight: Integer; ADir: TGradientDirection; const AGradient: array of TnGradientInfo): TBGRABitmap; 33 procedure nGradientAlphaFill(ACanvas: TCanvas; ARect: TRect; ADir: TGradientDirection; const AGradient: array of TnGradientInfo); 34 procedure nGradientAlphaFill(ABitmap: TBGRABitmap; ARect: TRect; ADir: TGradientDirection; const AGradient: array of TnGradientInfo); 31 function nGradientAlphaFill(ARect: TRect; ADir: TGradientDirection; const AGradient: array of TnGradientInfo): TBGRABitmap; overload; 32 function nGradientAlphaFill(AWidth, AHeight: Integer; ADir: TGradientDirection; const AGradient: array of TnGradientInfo): TBGRABitmap; overload; 33 procedure nGradientAlphaFill(ACanvas: TCanvas; ARect: TRect; ADir: TGradientDirection; const AGradient: array of TnGradientInfo); overload; 34 procedure nGradientAlphaFill(ABitmap: TBGRABitmap; ARect: TRect; ADir: TGradientDirection; const AGradient: array of TnGradientInfo); overload; 35 35 36 36 function DoubleGradientAlphaFill(ARect: TRect; AStart1,AStop1,AStart2,AStop2: TBGRAPixel; 37 ADirection1,ADirection2,ADir: TGradientDirection; AValue: Single): TBGRABitmap; 37 ADirection1,ADirection2,ADir: TGradientDirection; AValue: Single): TBGRABitmap; overload; 38 38 function DoubleGradientAlphaFill(AWidth,AHeight: Integer; AStart1,AStop1,AStart2,AStop2: TBGRAPixel; 39 ADirection1,ADirection2,ADir: TGradientDirection; AValue: Single): TBGRABitmap; 39 ADirection1,ADirection2,ADir: TGradientDirection; AValue: Single): TBGRABitmap; overload; 40 40 procedure DoubleGradientAlphaFill(ACanvas: TCanvas; ARect: TRect; AStart1,AStop1,AStart2,AStop2: TBGRAPixel; 41 ADirection1,ADirection2,ADir: TGradientDirection; AValue: Single); 41 ADirection1,ADirection2,ADir: TGradientDirection; AValue: Single); overload; 42 42 procedure DoubleGradientAlphaFill(ABitmap: TBGRABitmap; ARect: TRect; AStart1,AStop1,AStart2,AStop2: TBGRAPixel; 43 ADirection1,ADirection2,ADir: TGradientDirection; AValue: Single); 43 ADirection1,ADirection2,ADir: TGradientDirection; AValue: Single); overload; 44 44 45 45 {----------------------------------------------------------------------} … … 155 155 { Create a precise height map for a rectangle height map with a border (not grayscale anymore but more precise) } 156 156 function CreateRectanglePreciseMap(width,height,border: integer; options: TRectangleMapOptions = []): TBGRABitmap; 157 function CreateRectanglePreciseMap(width, height, borderWidth, borderHeight: integer; options: TRectangleMapOptions): TBGRABitmap; 157 158 158 159 { Create a round rectangle height map with a border } … … 161 162 { Create a precise height map for a round rectangle height map with a border (not grayscale anymore but more precise) } 162 163 function CreateRoundRectanglePreciseMap(width,height,border: integer; options: TRectangleMapOptions = []): TBGRABitmap; 164 function CreateRoundRectanglePreciseMap(width,height,borderWidth,borderHeight: integer; options: TRectangleMapOptions = []): TBGRABitmap; 163 165 164 166 {---------- Perlin Noise -------------} … … 177 179 implementation 178 180 179 uses Types, SysUtils{$IFDEF BGRABITMAP_USE_LCL}, BGRATextFX{$ENDIF}; {GraphType unit used by phongdraw.inc}181 uses Types, Math, SysUtils{$IFDEF BGRABITMAP_USE_LCL}, BGRATextFX{$ENDIF}; {GraphType unit used by phongdraw.inc} 180 182 181 183 {$IFDEF BGRABITMAP_USE_LCL}function TextShadow(AWidth, AHeight: Integer; AText: String; … … 767 769 end; 768 770 771 procedure MapBorderLimit(width,height: integer; options: TRectangleMapOptions; var borderHoriz,borderVert: integer); 772 var maxHoriz,maxVert: integer; 773 begin 774 if [rmoNoLeftBorder,rmoNoRightBorder] <= options then maxHoriz := borderHoriz else 775 if [rmoNoLeftBorder,rmoNoRightBorder] * options = [] then maxHoriz := width div 2 else 776 maxHoriz := width; 777 if borderHoriz > maxHoriz then borderHoriz := maxHoriz; 778 779 if [rmoNoTopBorder,rmoNoBottomBorder] <= options then maxVert := borderVert else 780 if [rmoNoTopBorder,rmoNoBottomBorder] * options = [] then maxVert := height div 2 else 781 maxVert := height; 782 if borderVert > maxVert then borderVert := maxVert; 783 end; 784 769 785 function CreateSpherePreciseMap(width, height: integer): TBGRABitmap; 770 786 var cx,cy,rx,ry,d: single; … … 898 914 if rmoLinearBorder in options then h := h/border else 899 915 h := sin((h+1/2)/border*Pi/2); 916 917 p^ := MapHeightToBGRA(h,255); 918 919 inc(p); 920 end; 921 end; 922 923 RectangleMapRemoveCorners(result,options); 924 end; 925 926 function CreateRectanglePreciseMap(width, height, borderWidth, borderHeight: integer; 927 options: TRectangleMapOptions): TBGRABitmap; 928 var xb,yb, minBorder: integer; 929 p: PBGRAPixel; 930 h: single; 931 smallStep: single; 932 begin 933 MapBorderLimit(width,height,options,borderWidth,borderHeight); 934 935 minBorder := min(borderWidth,borderHeight); 936 if minBorder > 0 then smallStep := 1/minBorder else smallStep:= 0; 937 938 result := TBGRABitmap.Create(width,height); 939 for yb := 0 to height-1 do 940 begin 941 p := result.scanline[yb]; 942 for xb := 0 to width-1 do 943 begin 944 if not (rmoNoLeftBorder in options) and (xb < borderWidth) and (yb < borderHeight) then 945 h := min(xb/borderWidth, yb/borderHeight) else 946 if not (rmoNoRightBorder in options) and (xb > width-1-borderWidth) and (yb < borderHeight) then 947 h := min((width-1-xb)/borderWidth, yb/borderHeight) else 948 if not (rmoNoTopBorder in options) and (xb < borderWidth) and (yb > height-1-borderHeight) then 949 h := min(xb/borderWidth, (height-1-yb)/borderHeight) else 950 if not (rmoNoBottomBorder in options) and (xb > width-1-borderWidth) and (yb > height-1-borderHeight) then 951 h := min((width-1-xb)/borderWidth, (height-1-yb)/borderHeight) else 952 if not (rmoNoLeftBorder in options) and (xb < borderWidth) then h := xb/borderWidth else 953 if not (rmoNoRightBorder in options) and (xb > width-1-borderWidth) then h := (width-1-xb)/borderWidth else 954 if not (rmoNoTopBorder in options) and (yb < borderHeight) then h := yb/borderHeight else 955 if not (rmoNoBottomBorder in options) and (yb > height-1-borderHeight) then h := (height-1-yb)/borderHeight else 956 begin 957 p^ := BGRAWhite; 958 inc(p); 959 Continue; 960 end; 961 962 if not (rmoLinearBorder in options) then 963 h := sin((h+smallStep*0.5)*Pi*0.5); 900 964 901 965 p^ := MapHeightToBGRA(h,255); … … 1090 1154 end; 1091 1155 1156 function CreateRoundRectanglePreciseMap(width, height, borderWidth, 1157 borderHeight: integer; options: TRectangleMapOptions): TBGRABitmap; 1158 var d: single; 1159 xb,yb: integer; 1160 p: PBGRAPixel; 1161 h,smallStep,factor: single; 1162 minBorder: integer; 1163 begin 1164 MapBorderLimit(width,height,options,borderWidth,borderHeight); 1165 1166 minBorder := min(borderWidth,borderHeight); 1167 if minBorder > 0 then smallStep := 1/minBorder else smallStep:= 0; 1168 factor := minBorder/(minBorder+1); 1169 result := TBGRABitmap.Create(width,height); 1170 for yb := 0 to height-1 do 1171 begin 1172 p := result.scanline[yb]; 1173 for xb := 0 to width-1 do 1174 begin 1175 if not (rmoNoLeftBorder in options) and not (rmoNoTopBorder in options) and (xb < borderWidth) and (yb < borderHeight) then 1176 d := 1-sqrt(sqr((borderWidth-xb)/borderWidth)+sqr((borderHeight-yb)/borderHeight)) else 1177 if not (rmoNoLeftBorder in options) and not (rmoNoBottomBorder in options) and (xb < borderWidth) and (yb > height-1-borderHeight) then 1178 d := 1-sqrt(sqr((borderWidth-xb)/borderWidth)+sqr((borderHeight-(height-1-yb))/borderHeight)) else 1179 if not (rmoNoRightBorder in options) and not (rmoNoTopBorder in options) and (xb > width-1-borderWidth) and (yb < borderHeight) then 1180 d := 1-sqrt(sqr((borderWidth-(width-1-xb))/borderWidth)+sqr((borderHeight-yb)/borderHeight)) else 1181 if not (rmoNoRightBorder in options) and not (rmoNoBottomBorder in options) and (xb > width-1-borderWidth) and (yb > height-1-borderHeight) then 1182 d := 1-sqrt(sqr((borderWidth-(width-1-xb))/borderWidth)+sqr((borderHeight-(height-1-yb))/borderHeight)) else 1183 if not (rmoNoLeftBorder in options) and (xb < borderWidth) then d := xb/borderWidth else 1184 if not (rmoNoRightBorder in options) and (xb > width-1-borderWidth) then d := (width-1-xb)/borderWidth else 1185 if not (rmoNoTopBorder in options) and (yb < borderHeight) then d := yb/borderHeight else 1186 if not (rmoNoBottomBorder in options) and (yb > height-1-borderHeight) then d := (height-1-yb)/borderHeight else 1187 begin 1188 p^ := BGRAWhite; 1189 inc(p); 1190 Continue; 1191 end; 1192 1193 d := (d + smallStep)*factor; 1194 1195 if d < 0 then 1196 p^ := BGRAPixelTransparent else 1197 begin 1198 if rmoLinearBorder in options then h := d else 1199 h := sin((d+smallStep*0.5)*Pi*0.5); 1200 1201 if d < smallStep then p^:= MapHeightToBGRA(h,round(d/smallStep*255)) else 1202 p^ := MapHeightToBGRA(h,255); 1203 end; 1204 inc(p); 1205 end; 1206 end; 1207 end; 1208 1092 1209 initialization 1093 1210
Note:
See TracChangeset
for help on using the changeset viewer.