Recent

Author Topic: BGRASpeedbutton resizing the glyph to the button dimensions ?  (Read 5567 times)

helix2001

  • New member
  • *
  • Posts: 6
Is there any option to have the speedbutton resize the glyph automatically to the control's dimensions ?

Thanks

Paulo

lainz

  • Hero Member
  • *****
  • Posts: 3139
    • Lainz
Re: BGRASpeedbutton resizing the glyph to the button dimensions ?
« Reply #1 on: April 18, 2014, 09:20:06 pm »
Try to use bcimagebutton maybe is the thing you are looking. In test folder find the example.
« Last Edit: April 18, 2014, 09:23:45 pm by 007 »

helix2001

  • New member
  • *
  • Posts: 6
Re: BGRASpeedbutton resizing the glyph to the button dimensions ?
« Reply #2 on: April 18, 2014, 10:05:31 pm »
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.

lainz

  • Hero Member
  • *****
  • Posts: 3139
    • Lainz
Re: BGRASpeedbutton resizing the glyph to the button dimensions ?
« Reply #3 on: April 19, 2014, 02:04:20 am »
Nice.

I've uploaded this to the BGRAControls repository. Please attach the icon in a post here.

helix2001

  • New member
  • *
  • Posts: 6
Re: BGRASpeedbutton resizing the glyph to the button dimensions ?
« Reply #4 on: April 19, 2014, 03:11:05 am »
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

lainz

  • Hero Member
  • *****
  • Posts: 3139
    • Lainz
Re: BGRASpeedbutton resizing the glyph to the button dimensions ?
« Reply #5 on: April 19, 2014, 12:19:21 pm »
Ok thanks.

It has been added to BGRA Controls in SVN and new version.

helix2001

  • New member
  • *
  • Posts: 6
Re: BGRASpeedbutton resizing the glyph to the button dimensions ?
« Reply #6 on: April 19, 2014, 12:36:34 pm »
Great. Thanks

Fox

helix2001

  • New member
  • *
  • Posts: 6
Re: BGRASpeedbutton resizing the glyph to the button dimensions ?
« Reply #7 on: April 24, 2014, 04:49:29 am »
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;

circular

  • Hero Member
  • *****
  • Posts: 2906
    • Personal webpage
Re: BGRASpeedbutton resizing the glyph to the button dimensions ?
« Reply #8 on: April 24, 2014, 03:00:46 pm »
helix, do you have the latest version of BGRABitmap (7.3) ? There is a fix for gtk coordinates.
Conscience is the debugger of the mind

lainz

  • Hero Member
  • *****
  • Posts: 3139
    • Lainz
Re: BGRASpeedbutton resizing the glyph to the button dimensions ?
« Reply #9 on: May 08, 2014, 03:33:54 pm »
It is TBGRAResizeSpeedButton, someone can test it?