Lazarus
Programming => Graphics => Graphics and Multimedia => BGRABitmap and LazPaint => Topic started by: helix2001 on April 18, 2014, 07:39:11 pm
-
Is there any option to have the speedbutton resize the glyph automatically to the control's dimensions ?
Thanks
Paulo
-
Try to use bcimagebutton maybe is the thing you are looking. In test folder find the example.
-
Checked that out. What I need is a dirty simple button to resize the glyph to the button dimensions, without having to edit the actual image to create the 4 glyphs, or to write the code to load the image at runtime. So, I created a new component, based on TBGRASpeedButton code to do just that. It's simple and works for me.
The code is below. If you find it useful I can send you the lrs file for the lazarus component button image.
Fox
unit BGRAResizeSpeedButton;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Buttons, LResources, Forms,
Controls, Graphics, Dialogs, BGRASpeedButton, BGRABitmap;
type
TBGRAResizeSpeedButton = class(TBGRASpeedButton)
private
{ Private declarations }
FBGRA: TBGRABitmap;
protected
{ Protected declarations }
function DrawGlyph(ACanvas: TCanvas; const AClient: TRect;
const AOffset: TPoint; AState: TButtonState; ATransparent: boolean;
BiDiFlags: longint): TRect; override;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
{ Published declarations }
end;
procedure Register;
implementation
function TBGRAResizeSpeedButton.DrawGlyph(ACanvas: TCanvas; const AClient: TRect;
const AOffset: TPoint; AState: TButtonState; ATransparent: boolean;
BiDiFlags: longint): TRect;
begin
if Glyph = nil then Exit;
Result:=AClient;
if Assigned(Glyph) and Not Glyph.Empty then
begin
FBGRA.Assign(Glyph);
BGRAReplace(FBGRA,FBGRA.Resample(Self.Width-6,Self.Height-6));
if (AState = bsDown) or (Down = True) then
FBGRA.Draw(ACanvas, 4, 4, False)
else
FBGRA.Draw(ACanvas, 3, 3, False);
end;
end;
constructor TBGRAResizeSpeedButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FBGRA := TBGRABitmap.Create;
end;
destructor TBGRAResizeSpeedButton.Destroy;
begin
FBGRA.Free;
inherited Destroy;
end;
procedure Register;
begin
// {$I bgraresizespeedbutton_icon.lrs}
RegisterComponents('BGRA Controls',[TBGRAResizeSpeedButton]);
end;
end.
-
Nice.
I've uploaded this to the BGRAControls repository. Please attach the icon in a post here.
-
Here is the source code, the icon lrs file and my package file.
I think the best effect comes from using it with png images (even with transparency) and setting Flat to true (but that's my personnal choice).
Fox
-
Ok thanks.
It has been added to BGRA Controls in SVN and new version.
-
Great. Thanks
Fox
-
When trying the component using GTK2 the image position was not correct. Got the fix below, should you wish to check and replace in the code you uploaded to the repository (I only use win and gtk, btw...feel free to add stuff to QT or any other widget type)
Fox
function TBGRAResizeSpeedButton.DrawGlyph(ACanvas: TCanvas; const AClient: TRect;
const AOffset: TPoint; AState: TButtonState; ATransparent: boolean;
BiDiFlags: longint): TRect;
{$IFDEF LCLgtk2}
Const
Sign = -1;
{$ELSE}
Const
Sign = 1;
{$ENDIF}
begin
if Glyph = nil then Exit;
Result:=AClient;
if Assigned(Glyph) and Not Glyph.Empty then
begin
FBGRA.Assign(Glyph);
BGRAReplace(FBGRA,FBGRA.Resample(Self.Width-6,Self.Height-6));
if Not Enabled then FBGRA.InplaceGrayscale;
if (AState = bsDown) or (Down = True) then
FBGRA.Draw(ACanvas, Sign * 4, Sign * 4, False)
else
FBGRA.Draw(ACanvas, Sign * 3, Sign * 3, False);
end;
end;
-
helix, do you have the latest version of BGRABitmap (7.3) ? There is a fix for gtk coordinates.
-
It is TBGRAResizeSpeedButton, someone can test it?