Sample Graphics

From Lazarus wiki
Revision as of 23:27, 13 March 2011 by Lainz (talk | contribs) (→‎gdgfx)
Jump to navigationJump to search

Template:Graphics Gallery

Graphics Gallery

This gallery is to show the designs can be created from Lazarus and drawing tools, like BGRABitmap.

gdgfx

Name: gdgfx 'Gradient Graphics'

Author: Lainz

Description: Shows how to create buttons and gradients with and without transparency in Lazarus using BGRABitmap and an enhanced version of Double Gradient that supports alpha.

Notes: Tested on Win32. Includes used version of BGRABitmap & DoubleGradient.

Picture: gdgfx.png

Top-Left: 'like flash player setup button' / Top-Right: 'like win7 explorer toolbar' / Bottom: double gradient with alpha / Background: same as bottom.

Download: gdgfx.7z (60.01 KB)

Flash Player Button

Add a new TPaintBox, set 'btn1' as name. Go OnPaint event and add this code:

<delphi>var

 tempbmp1, tempbmp2: TBGRABitmap;

begin

 // Background Gradient
 tempbmp1:=TBGRABitmap.Create(btn1.Width,btn1.Height,BGRA(104,104,104,255));
 tempbmp1.Canvas.GradientFill(Rect(1,Round(btn1.Height*0.25),btn1.Width-1,btn1.Height-1),$686868,$404040,gdVertical);
 // Frame Border
 tempbmp1.Canvas.Brush.Color:=$181818;
 tempbmp1.Canvas.FrameRect(btn1.ClientRect);
 // Light Gradient
 tempbmp2:=TBGRABitmap.Create(btn1.Width,btn1.Height,BGRA(0,0,0,0));
 tempbmp2.GradientFill(1,1,btn1.Width-1,btn1.Height-1,
 BGRA(255,255,255,34),
 BGRA(255,255,255,10), gtLinear,
 PointF(btn1.ClientRect.Right,btn1.ClientRect.Top),
 PointF(btn1.ClientRect.Right,btn1.ClientRect.Bottom),
 dmDrawWithTransparency,True,False);
 tempbmp2.AlphaFillRect(2,2,btn1.Width-2,btn1.Height-2,0);
 // Merge Bitmaps
 tempbmp1.Canvas.Draw(0,0,tempbmp2.Bitmap);
 // Paint in Canvas
 btn1.Canvas.Draw(0,0,tempbmp1.Bitmap);
 // Free Bitmaps
 tempbmp1.Free;
 tempbmp2.Free;

end;</delphi>

Windows 7 Explorer Toolbar

Add a new TPaintBox, set 'btn2' as name. Go OnPaint event and add this code:

<delphi>var

 backBmp, lightBmp: TBGRABitmap;
 gradBmp: TBitmap;

begin

 // Background Gradient
 gradBmp := DoubleGradientFill(
             btn2.ClientRect,
             $FFFAF5,$FAF0E6,
             $F4E6DC,$F7E9DD,
             gdVertical,gdVertical,gdVertical,0.5);
 // Use as background
 backBmp := TBGRABitmap.Create(gradBmp);
 gradBmp.Free;
 // Light Gradient
 lightBmp:= TBGRABitmap.Create(btn2.Width,btn2.Height,BGRA(0,0,0,0));
 lightBmp.Rectangle(0,0,btn2.Width,btn2.Height-2,
    BGRA(255,255,255,100),
    dmSet);
 lightBmp.SetHorizLine(0,btn2.Height-1,btn2.Width-1,BGRA(160,175,195,255));
 lightBmp.SetHorizLine(0,btn2.Height-2,btn2.Width-1,BGRA(205,218,234,255));
 // Merge Bitmaps
 backBmp.PutImage(0,0,lightBmp,dmDrawWithTransparency);
 lightBmp.Free;
 // Paint in Canvas
 backBmp.Draw(btn2.Canvas,0,0,True);
 backBmp.Free;

end;</delphi>