Browse Source

circular patch:
- InnerMargin property for label and button (so that it is possible to make it look as before by using value 0.5 for InnerMargin)
- for sprite animation, when loading a gif, to use the speed of the gif file
- for sprite animation, fixed some resource variable

lainz 10 years ago
parent
commit
c3b5b4b869
4 changed files with 42 additions and 9 deletions
  1. 14 1
      bcbutton.pas
  2. 13 1
      bclabel.pas
  3. 10 5
      bctools.pas
  4. 5 2
      bgraspriteanimation.pas

+ 14 - 1
bcbutton.pas

@@ -105,6 +105,7 @@ type
     FFlipArrow: boolean;
     FFlipArrow: boolean;
     FActiveButt: TBCButtonStyle;
     FActiveButt: TBCButtonStyle;
     FBGRANormal, FBGRAHover, FBGRAClick: TBGRABitmapEx;
     FBGRANormal, FBGRAHover, FBGRAClick: TBGRABitmapEx;
+    FInnerMargin: single;
     FMemoryUsage: TBCButtonMemoryUsage;
     FMemoryUsage: TBCButtonMemoryUsage;
     FRounding: TBCRounding;
     FRounding: TBCRounding;
     FRoundingDropDown: TBCRounding;
     FRoundingDropDown: TBCRounding;
@@ -158,6 +159,7 @@ type
     procedure SetGlyphMargin(const AValue: integer);
     procedure SetGlyphMargin(const AValue: integer);
     procedure SetImageIndex(AValue: integer);
     procedure SetImageIndex(AValue: integer);
     procedure SetImages(AValue: TCustomImageList);
     procedure SetImages(AValue: TCustomImageList);
+    procedure SetInnerMargin(AValue: single);
     procedure SetMemoryUsage(AValue: TBCButtonMemoryUsage);
     procedure SetMemoryUsage(AValue: TBCButtonMemoryUsage);
     procedure SetRounding(AValue: TBCRounding);
     procedure SetRounding(AValue: TBCRounding);
     procedure SetRoundingDropDown(AValue: TBCRounding);
     procedure SetRoundingDropDown(AValue: TBCRounding);
@@ -239,6 +241,7 @@ type
       read FOnAfterRenderBCButton write FOnAfterRenderBCButton;
       read FOnAfterRenderBCButton write FOnAfterRenderBCButton;
     property OnButtonClick: TNotifyEvent read FOnButtonClick write FOnButtonClick;
     property OnButtonClick: TNotifyEvent read FOnButtonClick write FOnButtonClick;
     property MemoryUsage: TBCButtonMemoryUsage read FMemoryUsage write SetMemoryUsage;
     property MemoryUsage: TBCButtonMemoryUsage read FMemoryUsage write SetMemoryUsage;
+    property InnerMargin: single read FInnerMargin write SetInnerMargin;
   public
   public
     { Constructor }
     { Constructor }
     constructor Create(AOwner: TComponent); override;
     constructor Create(AOwner: TComponent); override;
@@ -296,6 +299,7 @@ type
     { The margin of the glyph icon. }
     { The margin of the glyph icon. }
     property GlyphMargin;
     property GlyphMargin;
     property Hint;
     property Hint;
+    property InnerMargin;
     { Called when the button finish the render. Use it to add your own drawings to the button. }
     { Called when the button finish the render. Use it to add your own drawings to the button. }
     property OnAfterRenderBCButton;
     property OnAfterRenderBCButton;
     { Called when the button part is clicked, not the dropdown. }
     { Called when the button part is clicked, not the dropdown. }
@@ -810,7 +814,8 @@ end;
 procedure TCustomBCButton.RenderState(ABGRA: TBGRABitmapEx;
 procedure TCustomBCButton.RenderState(ABGRA: TBGRABitmapEx;
   AState: TBCButtonState; const ARect: TRect; ARounding: TBCRounding);
   AState: TBCButtonState; const ARect: TRect; ARounding: TBCRounding);
 begin
 begin
-  RenderBackgroundAndBorder(ARect, AState.FBackground, TBGRABitmap(ABGRA), ARounding, AState.FBorder);
+  RenderBackgroundAndBorder(ARect, AState.FBackground, TBGRABitmap(ABGRA),
+    ARounding, AState.FBorder, FInnerMargin);
 end;
 end;
 
 
 procedure TCustomBCButton.OnChangeGlyph(Sender: TObject);
 procedure TCustomBCButton.OnChangeGlyph(Sender: TObject);
@@ -993,6 +998,14 @@ begin
   Invalidate;
   Invalidate;
 end;
 end;
 
 
+procedure TCustomBCButton.SetInnerMargin(AValue: single);
+begin
+  if FInnerMargin=AValue then Exit;
+  FInnerMargin:=AValue;
+  RenderControl;
+  Invalidate;
+end;
+
 procedure TCustomBCButton.SetMemoryUsage(AValue: TBCButtonMemoryUsage);
 procedure TCustomBCButton.SetMemoryUsage(AValue: TBCButtonMemoryUsage);
 begin
 begin
   if FMemoryUsage=AValue then Exit;
   if FMemoryUsage=AValue then Exit;

+ 13 - 1
bclabel.pas

@@ -58,8 +58,10 @@ type
     FBGRA: TBGRABitmapEx;
     FBGRA: TBGRABitmapEx;
     FBorder: TBCBorder;
     FBorder: TBCBorder;
     FFontEx: TBCFont;
     FFontEx: TBCFont;
+    FInnerMargin: single;
     FRounding: TBCRounding;
     FRounding: TBCRounding;
     procedure Render;
     procedure Render;
+    procedure SetInnerMargin(AValue: single);
     procedure SetRounding(AValue: TBCRounding);
     procedure SetRounding(AValue: TBCRounding);
     procedure UpdateSize;
     procedure UpdateSize;
     procedure SetBackground(AValue: TBCBackground);
     procedure SetBackground(AValue: TBCBackground);
@@ -86,6 +88,7 @@ type
     property Border: TBCBorder read FBorder write SetBorder;
     property Border: TBCBorder read FBorder write SetBorder;
     property FontEx: TBCFont read FFontEx write SetFontEx;
     property FontEx: TBCFont read FFontEx write SetFontEx;
     property Rounding: TBCRounding read FRounding write SetRounding;
     property Rounding: TBCRounding read FRounding write SetRounding;
+    property InnerMargin: single read FInnerMargin write SetInnerMargin;
   public
   public
     { Public declarations }
     { Public declarations }
     constructor Create(AOwner: TComponent); override;
     constructor Create(AOwner: TComponent); override;
@@ -120,6 +123,7 @@ type
     property HelpKeyword;
     property HelpKeyword;
     property HelpType;
     property HelpType;
     property Hint;
     property Hint;
+    property InnerMargin;
     property Left;
     property Left;
     property PopupMenu;
     property PopupMenu;
     property Rounding;
     property Rounding;
@@ -167,7 +171,7 @@ begin
   r := FBGRA.ClipRect;
   r := FBGRA.ClipRect;
   CalculateBorderRect(FBorder,r);
   CalculateBorderRect(FBorder,r);
 
 
-  RenderBackgroundAndBorder(FBGRA.ClipRect, FBackground, TBGRABitmap(FBGRA), FRounding, FBorder);
+  RenderBackgroundAndBorder(FBGRA.ClipRect, FBackground, TBGRABitmap(FBGRA), FRounding, FBorder, FInnerMargin);
   RenderText(FBGRA.ClipRect, FFontEx, Caption, TBGRABitmap(FBGRA));
   RenderText(FBGRA.ClipRect, FFontEx, Caption, TBGRABitmap(FBGRA));
 
 
   {$IFDEF DEBUG}
   {$IFDEF DEBUG}
@@ -175,6 +179,14 @@ begin
   {$ENDIF}
   {$ENDIF}
 end;
 end;
 
 
+procedure TCustomBCLabel.SetInnerMargin(AValue: single);
+begin
+  if FInnerMargin=AValue then Exit;
+  FInnerMargin:=AValue;
+  RenderControl;
+  Invalidate;
+end;
+
 procedure TCustomBCLabel.SetRounding(AValue: TBCRounding);
 procedure TCustomBCLabel.SetRounding(AValue: TBCRounding);
 begin
 begin
   if FRounding = AValue then Exit;
   if FRounding = AValue then Exit;

+ 10 - 5
bctools.pas

@@ -60,7 +60,7 @@ procedure RenderBackground(const ARect: TRect; ABackground: TBCBackground;
 procedure RenderBackgroundF(x1,y1,x2,y2: single; ABackground: TBCBackground;
 procedure RenderBackgroundF(x1,y1,x2,y2: single; ABackground: TBCBackground;
   ATargetBGRA: TBGRABitmap; ARounding: TBCRounding = nil);
   ATargetBGRA: TBGRABitmap; ARounding: TBCRounding = nil);
 procedure RenderBackgroundAndBorder(const ARect: TRect; ABackground: TBCBackground;
 procedure RenderBackgroundAndBorder(const ARect: TRect; ABackground: TBCBackground;
-  ATargetBGRA: TBGRABitmap; ARounding: TBCRounding; ABorder: TBCBorder);
+  ATargetBGRA: TBGRABitmap; ARounding: TBCRounding; ABorder: TBCBorder; AInnerMargin: single = 0);
 // Render customizable border (used e.g. by TBCButton, TBCPanel, TBCLabel)
 // Render customizable border (used e.g. by TBCButton, TBCPanel, TBCLabel)
 procedure RenderBorder(const ARect: TRect; ABorder: TBCBorder;
 procedure RenderBorder(const ARect: TRect; ABorder: TBCBorder;
   ATargetBGRA: TBGRABitmap; ARounding: TBCRounding = nil);
   ATargetBGRA: TBGRABitmap; ARounding: TBCRounding = nil);
@@ -116,14 +116,18 @@ end;
 
 
 procedure RenderBackgroundAndBorder(const ARect: TRect;
 procedure RenderBackgroundAndBorder(const ARect: TRect;
   ABackground: TBCBackground; ATargetBGRA: TBGRABitmap;
   ABackground: TBCBackground; ATargetBGRA: TBGRABitmap;
-  ARounding: TBCRounding; ABorder: TBCBorder);
+  ARounding: TBCRounding; ABorder: TBCBorder; AInnerMargin: single);
 var w: single;
 var w: single;
 begin
 begin
   if ABorder.Style = bboNone then
   if ABorder.Style = bboNone then
-    RenderBackground(ARect,ABackground,ATargetBGRA,ARounding,True)
+  begin
+    w := AInnerMargin-0.5;
+    RenderBackgroundF(ARect.Left+w, ARect.Top+w, ARect.Right-1-w,
+          ARect.Bottom-1-w,ABackground,ATargetBGRA,ARounding);
+  end
   else
   else
   begin
   begin
-    w := (ABorder.Width-1)/2;
+    w := (ABorder.Width-1)/2+AInnerMargin;
     RenderBackgroundF(ARect.Left+w,ARect.Top+w,ARect.Right-1-w,ARect.Bottom-1-w,ABackground,ATargetBGRA,ARounding);
     RenderBackgroundF(ARect.Left+w,ARect.Top+w,ARect.Right-1-w,ARect.Bottom-1-w,ABackground,ATargetBGRA,ARounding);
     RenderBorderF(ARect.Left+w,ARect.Top+w,ARect.Right-1-w,ARect.Bottom-1-w,ABorder,ATargetBGRA,ARounding);
     RenderBorderF(ARect.Left+w,ARect.Top+w,ARect.Right-1-w,ARect.Bottom-1-w,ABorder,ATargetBGRA,ARounding);
   end;
   end;
@@ -143,6 +147,7 @@ var
   rx,ry: Byte;
   rx,ry: Byte;
   ropt: TRoundRectangleOptions;
   ropt: TRoundRectangleOptions;
 begin
 begin
+  if (x1>x2) or (y1>y2) then exit;
   if ABorder.Style=bboNone then Exit;
   if ABorder.Style=bboNone then Exit;
 
 
   if ARounding = nil then
   if ARounding = nil then
@@ -404,7 +409,7 @@ var
   rx,ry: Byte;
   rx,ry: Byte;
   ropt: TRoundRectangleOptions;
   ropt: TRoundRectangleOptions;
 begin
 begin
-
+  if (x1>=x2) or (y1>=y2) then exit;
   if ARounding = nil then
   if ARounding = nil then
   begin
   begin
     rx   := 0;
     rx   := 0;

+ 5 - 2
bgraspriteanimation.pas

@@ -527,13 +527,16 @@ var
   TempBitmap: TBGRABitmap;
   TempBitmap: TBGRABitmap;
   n: integer;
   n: integer;
 begin
 begin
-  TempBitmap := TBGRABitmap.Create(Gif.Width * Gif.Count, Gif.Height);
+  if Gif.Count = 0 then exit;
 
 
+  TempBitmap := TBGRABitmap.Create(Gif.Width * Gif.Count, Gif.Height);
   for n := 0 to Gif.Count do
   for n := 0 to Gif.Count do
   begin
   begin
     Gif.CurrentImage := n;
     Gif.CurrentImage := n;
     TempBitmap.BlendImage(Gif.Width * n, 0, Gif.MemBitmap, boLinearBlend);
     TempBitmap.BlendImage(Gif.Width * n, 0, Gif.MemBitmap, boLinearBlend);
   end;
   end;
+
+  AnimSpeed := Gif.TotalAnimationTimeMs div Gif.Count;
   FSpriteCount := Gif.Count;
   FSpriteCount := Gif.Count;
   FSprite.Width := Gif.Width * Gif.Count;
   FSprite.Width := Gif.Width * Gif.Count;
   FSprite.Height := Gif.Height;
   FSprite.Height := Gif.Height;
@@ -549,7 +552,7 @@ var
   TempGif: TBGRAAnimatedGif;
   TempGif: TBGRAAnimatedGif;
 begin
 begin
   TempGif := TBGRAAnimatedGif.Create;
   TempGif := TBGRAAnimatedGif.Create;
-  TempGif.LoadFromResourceName(HInstance, ResName);
+  TempGif.LoadFromResourceName(Instance, ResName);
 
 
   GifImageToSprite(TempGif);
   GifImageToSprite(TempGif);