https://wiki.freepascal.org/api.php?action=feedcontributions&user=Lainz&feedformat=atomFree Pascal wiki - User contributions [en]2024-03-29T09:51:14ZUser contributionsMediaWiki 1.35.6https://wiki.freepascal.org/index.php?title=BGRAControls&diff=66663BGRAControls2013-03-08T22:23:51Z<p>Lainz: /* BCXButton */</p>
<hr />
<div>{{BGRAControls}}<br />
<br />
== Install ==<br />
<br />
You can use TortoiseSVN to download the svn repository and TortoiseGIT to download the git repository.<br />
<br />
We're using BGRABitmap SVN to develop BGRAControls. Important changes in BGRABitmap can stop working BGRAControls.<br />
<br />
=== Download BGRABitmap ===<br />
<br />
Install BGRABitmap with the file bgrabitmap.lpk.<br />
<br />
'''Release:''' https://sourceforge.net/projects/lazpaint/files/src/<br />
<br />
==== SVN ====<br />
<br />
'''Latest SVN:''' svn co https://lazpaint.svn.sourceforge.net/svnroot/lazpaint lazpaint<br />
<br />
=== Download BGRAControls ===<br />
<br />
Install BGRAControls with the file bgracontrols.lpk.<br />
<br />
'''Release:''' https://sourceforge.net/projects/bgracontrols/files/<br />
<br />
==== SVN ====<br />
<br />
'''SVN Browse:''' http://bgracontrols.svn.sourceforge.net/viewvc/bgracontrols/<br />
<br />
'''SVN Checkout:''' svn co https://bgracontrols.svn.sourceforge.net/svnroot/bgracontrols bgracontrols<br />
<br />
==== GIT ====<br />
<br />
'''GIT Browse:''' http://bgracontrols.git.sourceforge.net/git/gitweb-index.cgi<br />
<br />
'''GIT Checkout:''' git://bgracontrols.git.sourceforge.net/gitroot/bgracontrols/bgracontrols <br />
<br />
== Overview ==<br />
<br />
License: Modified LGPL.<br />
<br />
As many people know, Lazarus GTK doesn't have full alpha support. I created a set of components which use TBGRABitmap for drawing icons, so it partially solves the problem with alpha in GTK. But this components set is not only a GTK patch but has more fancy components which are using the power of the BGRABitmap package.<br />
<br />
=== Author: Dibo. ===<br />
Package founder and package mantainer.<br />
<br />
BC Controls<br />
- TBCButton<br />
- TBCLabel<br />
- TBCPanel<br />
<br />
BGRA Controls<br />
- TBGRAImageList<br />
- TBGRASpeedButton<br />
<br />
=== Author: Circular. ===<br />
BGRABitmap creator, contributor and package mantainer.<br />
<br />
- TBGRAFlashProgressBar<br />
- TBGRAGraphicControl<br />
- TBGRAKnob<br />
- TBGRAShape<br />
- TBGRAVirtualScreen<br />
<br />
=== Author: Lainz. ===<br />
Contributor and package mantainer.<br />
<br />
BC Controls<br />
- TBCImageButton<br />
- TBCGameGrid<br />
<br />
BGRA Controls<br />
- TBGRASpriteAnimation<br />
<br />
=== Author: Emerson Cavalcanti. ===<br />
- TBGRAImageManipulation<br />
<br />
=== Author: mora. ===<br />
- Contributor to BCButton functionality.<br />
<br />
== Related Articles ==<br />
<br />
[[BGRASpriteAnimation]] - Usage of the sprite animation component.<br />
<br />
[[uE_Controls]] - Other controls developed with BGRABitmap.<br />
<br />
[[BGRABitmap]] - The library used to create this controls.<br />
<br />
[[LazPaint]] - A paint program developed with Lazarus and BGRABitmap.<br />
<br />
== BC ==<br />
=== BCButton ===<br />
[[Image:bcbutton.png]]<br />
=== BCGameGrid ===<br />
[[Image:bcgamegrid.png]]<br />
=== BCImageButton ===<br />
The bitmap must contain 4 states (from top to bottom, with the same Height) in the following order: normal, hover, active, disabled.<br />
<br />
''Example Button:''<br />
<br />
[[Image:samplebgraimagebutton.png]]<br />
<br />
''Example Button (with Alpha):''<br />
<br />
[[Image:samplebgraimagebuttonalpha.png]]<br />
<br />
=== BCXButton ===<br />
Fully customizable button with 'OnRenderControl' event. This control doesn't has default properties, it's supposed that you will override this control and add all the things you wish.<br />
<br />
- Like TCDButton (Custom Drawn Button).<br />
<br />
- Call 'OnRenderControl' event (like a Drawer in CD) for each button, or one for all buttons.<br />
<br />
- Create fully customizable buttons, like using BGRAVirtualScreen or BCGraphicControl.<br />
<br />
[[Image:bcxbutton.png]]<br />
<br />
=== BCLabel ===<br />
[[Image:bclabel.png]]<br />
<br />
=== BCPanel ===<br />
[[Image:bcpanel.png]]<br />
<br />
== BGRA ==<br />
=== BGRAProgressBar ===<br />
'''Use as replace of:''' TProgressBar<br />
<br />
[[Image:BC-Bgraflashprogressbar.png]]<br />
<br />
Flash progressbar created by circular.<br />
<br />
=== BGRAGraphicControl ===<br />
'''Use as replace of:''' TPaintBox<br />
<br />
TBGRAGraphicControl, which allows to draw your component by yourself with alpha blending.<br />
<br />
=== BGRAImageList ===<br />
'''Use as replace of:''' TImageList<br />
<br />
'''Before:'''<br />
<br />
[[Image:before-TImageList.png]]<br />
<br />
'''After:'''<br />
<br />
[[Image:after-TBGRAImageList.png]]<br />
<br />
Component which inherits from TImageList. So each control (tested on TToolBar and TTreeView) which is using TImageList.Draw method for drawing icons, automatically can have alpha support. Just use this component instead of TImageList. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing).<br />
<br />
=== BGRAImageManipulation ===<br />
'''Use as replace of:''' TImage<br />
<br />
Component to facilitate the importation of images in an application.<br />
<br />
In the current version you can import an image and cut out keeping the aspect ratio (or not). For example, if you want to import photos using the 3x4 ratio, adjust the 'ratio' property to 3:4. If import an image with different size, the component will ensure that the image meets the proportions of the desired dimensions.<br />
<br />
You can determine the minimum size of the image adjusting the properties 'MinWidth'and 'MinHeight'.<br />
<br />
You can rotate the image using functions builtin.<br />
<br />
See demo of component:<br />
<br />
[[Image:bgraimagemanipulation.jpg]]<br />
<br />
After retrieving the image modified by the component, just put the image into your destination using the stretch. It is obvious that the target must have the same ratio chosen on component for do not distort the final result.<br />
<br />
=== BGRAKnob ===<br />
[[Image:BC-Bgraknob.png]]<br />
<br />
Graphic knob component created by circular.<br />
<br />
=== BGRAShape ===<br />
'''Use as replace of:''' TShape<br />
<br />
[[Image:samplebgrashape.png]]<br />
<br />
The component has full alpha support and you can put the number of polygons you want with rounded borders & gradients (linear, radial, diamond, reflected).<br />
<br />
=== BGRASpeedButton ===<br />
'''Use as replace of:''' TSpeedButton<br />
<br />
[[Image:BGRASpeedButton.png]]<br />
<br />
Component which inherits from TSpeedButton and draws the glyph using TBGRABitmap. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing).<br />
<br />
=== BGRASpriteAnimation ===<br />
'''Use as replace of:''' TImage<br />
<br />
Read more in the article [[BGRASpriteAnimation]].<br />
<br />
[[Image:bgraspriteanimation.png]]<br />
<br />
With this you can do animations from bitmap. You need an image with all the frames layout in in a horizontal position.<br />
<br />
It has the ability to specify how many times the animation should be played (0 for infinite, 1, 2, etc) and static to stop the animation, is capable to specify the speed and direction and support transparency.<br />
<br />
Features:<br />
* Animation: invert, position, lap, speed, static, repeat.<br />
* Sprite: fill opacity (global transparency), flip mode (horizontal, vertical, both), key color (transparent color), resample (normal or fine resample modes). AutoSize.<br />
* AnimatedGifToSprite: convert an animated gif to a BGRABitmap sprite.<br />
<br />
=== BGRAVirtualScreen ===<br />
'''Use as replacement of:''' TPanel, TPaintBox<br />
<br />
The principle is to draw on a memory bitmap.<br />
<br />
The component has a specific event, OnRedraw, which is called when the whole bitmap needs to be redrawn. It happens at the beginning and when the component is resized. You can also query to redraw the bitmap with Redraw and DiscardBitmap methods. The second one only invalidates the content, which can wait until the messageloop is handled.<br />
<br />
Otherwise, it is possible to modify the Bitmap property and call Invalidate or Repaint, to avoid erasing the whole bitmap content.<br />
<br />
== Test ==<br />
=== Game - Maze ===<br />
[[Image:game_maze.png]]<br />
<br />
=== Game - Puzzle ===<br />
[[Image:game_puzzle.png]]<br />
<br />
=== SliceScaling - CustomDrawn Windows 7 ===<br />
<br />
[[Image:customdrawnwindows7.png]]<br />
<br />
This is a drawer for [[Lazarus Custom Drawn Controls]], you need that component installed with the latest Lazarus revision to work.<br />
<br />
Working in this drawer: button, statictext, checkbox, radiobutton and progressbar.<br />
<br />
This has also extra images for 'Luna' (Windows XP Theme) 'Aero Lite' (Windows 8 Theme) and extra buttons (arrows).<br />
<br />
=== SliceScaling - TAChart ===<br />
<br />
9-slice scaling is usefull to create sizable UI elements like in the Custom Drawn Windows 7 Drawer.<br />
<br />
There's a [[TAChart]] example with slice scaled bars.<br />
<br />
[[File:slicescaledtachart.png]]<br />
<br />
== Outdated ==<br />
<br />
[[BGRAButton Gallery]] - Gallery of buttons with source code to use in your projects with BGRAButton.<br />
<br />
=== BGRABitmapThemeUtils ===<br />
<br />
This unit is used by BGRAImageButton to draw the button! Also it's usefull to skin controls from bitmaps.<br />
<br />
A more advanced version of this is SliceScaling.pas unit.<br />
<br />
=== BGRANeoButton ===<br />
<br />
This unit is an example, it's usefull to learn how to create your own button with bgrabitmap. BTW read the BGRAImageButton and BGRAButton code. All in this unit can be overriden. I've not added 'invalidate' messages in types and AutoSize, add your own according to your programming needs.<br />
<br />
=== TBGRAWin7ToolBar ===<br />
<br />
[[Image:bgrawin7toolbar.png]]<br />
<br />
Is a TBGRAVirtualScreen descendant with some default child sizing, and nice Win7 ToolBar background.<br />
<br />
=== BGRASamples unit ===<br />
<br />
This unit has sample drawings, styles for buttons and colors used in different UI.<br />
<br />
[[Image:ioselements.png]]<br />
<br />
* '''Accent Color:''' the colors used in the Windows Phone. The accent color can be used in TBGRAButton and TBGRAImageButton (see the different procedures).<br />
* '''Facebook button color:''' gray, green and blue, with a procedure to create an image in the normal or pressed state, also to use this style in a TBGRAImageButton.<br />
* '''TBGRASampleStyle:''' Styles for TBGRAButton ('Default', 'Flash Player', 'Windows 7 ToolBar', 'Windows 7 ToolBar Smooth', 'Windows 7', 'Office 2010', 'Mac OSX Lion', 'Windows 7 Cristal').<br />
* '''iOS Elements:''' Draw a gray bar, the blue toolbar and a tiled background, the same elements used in the iOS screen.<br />
* '''Glass:''' used in testbgracontrols, it show an image in a virtualscreen and apply blur in the buttons area.<br />
* '''Drawings:''' flash player body and toolbar, windows 7 toolbar.<br />
<br />
* Some other usefull procedures to work with TBGRAButton and TBGRAImageButton.<br />
<br />
=== TBGRAImageToggleBox ===<br />
<br />
REMOVED IN VER 1.1.0.7.<br />
<br />
'''Use as replace of:''' TToggleBox<br />
<br />
Component used to create a toggle box from Bitmap.<br />
<br />
The bitmap must contain 8 images (from top to bottom, with the same Height) in the following order: unchecked normal, unchecked enter, unchecked pressed, unchecked disabled for Unchecked state and checked normal, checked enter, checked pressed, checked disabled for Normal state.<br />
<br />
''Example toggle box:''<br />
<br />
[[Image:sampletogglebox.png]]<br />
<br />
=== TBGRALabel ===<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
Label component based on TBGRAButton.<br />
<br />
Features:<br />
* Caption with shadow or not<br />
* Full alpha and antialias support or not<br />
* WordWarp or not<br />
* Caption with Property Editor Multiline<br />
<br />
=== TBGRALabelFX ===<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
[[Image:bgralabelfx.png]]<br />
<br />
Features:<br />
* Outline<br />
* Shadow<br />
<br />
ToDo:<br />
* Use BGRATextFX multicolor, textures.<br />
* etc.<br />
<br />
=== TBGRAImageButton ===<br />
<br />
If you need some code to load and split an image from file, and then scale the borders like in this control you can use TBGRABitmapThemeUtils (included in BGRAControls).<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgraimagebutton.png]]<br />
<br />
Component used to create a button with 4 states from Bitmap.<br />
<br />
'''Features:'''<br />
* Load the image from the "Bitmap" property in the object inspector or load from file using "BitmapFile".<br />
<br />
// You can load bmp and also png files<br />
BGRAImageButton1.BitmapLoadFromFile(BGRAImageButton1.BitmapFile);<br />
<br />
* BitmapOptions: you can set the border pixels, resample method and fill modes. Usefull to create textured / like Windows themed buttons.<br />
* AutoSize, ModalResult.<br />
* Text with Shadow, you can disable text render with the option "TextVisible".<br />
* Sound: in mouse enter and leave in Windows from .wav files.<br />
* Toggle: you can read / set the current state with the property "Checked".<br />
* Animation: glowing effect.<br />
<br />
'''Usage:'''<br />
<br />
The bitmap must contain 4 states (from top to bottom, with the same Height) in the following order: normal, enter, pressed, disabled.<br />
<br />
If you choose to use BitmapOptions you need to have for each state an image which has a border, and inside some content that can be repeated. Then with FillCenter option (if you want a textured button), it gets repeated while the borders stay as they are. This is like the method used in Windows to theme the buttons.<br />
<br />
=== TBGRAButton ===<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgrabutton.png]]<br />
<br />
Customizable graphic component which is using only BGRABitmap functions for drawing. This component is insensitive for -dGTK_ONLY switch. Demo project included in package.<br />
<br />
'''Functionality:'''<br />
* Gradient, Clear or Color body. [[Double_Gradient]].<br />
* Text with shadow: BGRA antialias or like system default with ClearType.<br />
* Rounded border, inner Light.<br />
* States: normal, hover & clicked fully customizable and grayscale disabled state.<br />
* Special: Down, DropDown, Static.<br />
* Full AutoSize working with Glyph.<br />
<br />
=== TBGRAPanel ===<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
Simple TPanel descendant which can have gradient background. Created especially for TBGRAButton (for creating a nice looking toolbar for bgrabuttons). This component is insensitive for -dGTK_ONLY switch<br />
<br />
[[Category:Components]]<br />
[[Category:Graphics]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=File:bcxbutton.png&diff=66662File:bcxbutton.png2013-03-08T22:17:53Z<p>Lainz: uploaded a new version of &quot;File:bcxbutton.png&quot;</p>
<hr />
<div></div>Lainzhttps://wiki.freepascal.org/index.php?title=BGRAControls&diff=66661BGRAControls2013-03-08T21:02:57Z<p>Lainz: /* BC */ added BCXButton</p>
<hr />
<div>{{BGRAControls}}<br />
<br />
== Install ==<br />
<br />
You can use TortoiseSVN to download the svn repository and TortoiseGIT to download the git repository.<br />
<br />
We're using BGRABitmap SVN to develop BGRAControls. Important changes in BGRABitmap can stop working BGRAControls.<br />
<br />
=== Download BGRABitmap ===<br />
<br />
Install BGRABitmap with the file bgrabitmap.lpk.<br />
<br />
'''Release:''' https://sourceforge.net/projects/lazpaint/files/src/<br />
<br />
==== SVN ====<br />
<br />
'''Latest SVN:''' svn co https://lazpaint.svn.sourceforge.net/svnroot/lazpaint lazpaint<br />
<br />
=== Download BGRAControls ===<br />
<br />
Install BGRAControls with the file bgracontrols.lpk.<br />
<br />
'''Release:''' https://sourceforge.net/projects/bgracontrols/files/<br />
<br />
==== SVN ====<br />
<br />
'''SVN Browse:''' http://bgracontrols.svn.sourceforge.net/viewvc/bgracontrols/<br />
<br />
'''SVN Checkout:''' svn co https://bgracontrols.svn.sourceforge.net/svnroot/bgracontrols bgracontrols<br />
<br />
==== GIT ====<br />
<br />
'''GIT Browse:''' http://bgracontrols.git.sourceforge.net/git/gitweb-index.cgi<br />
<br />
'''GIT Checkout:''' git://bgracontrols.git.sourceforge.net/gitroot/bgracontrols/bgracontrols <br />
<br />
== Overview ==<br />
<br />
License: Modified LGPL.<br />
<br />
As many people know, Lazarus GTK doesn't have full alpha support. I created a set of components which use TBGRABitmap for drawing icons, so it partially solves the problem with alpha in GTK. But this components set is not only a GTK patch but has more fancy components which are using the power of the BGRABitmap package.<br />
<br />
=== Author: Dibo. ===<br />
Package founder and package mantainer.<br />
<br />
BC Controls<br />
- TBCButton<br />
- TBCLabel<br />
- TBCPanel<br />
<br />
BGRA Controls<br />
- TBGRAImageList<br />
- TBGRASpeedButton<br />
<br />
=== Author: Circular. ===<br />
BGRABitmap creator, contributor and package mantainer.<br />
<br />
- TBGRAFlashProgressBar<br />
- TBGRAGraphicControl<br />
- TBGRAKnob<br />
- TBGRAShape<br />
- TBGRAVirtualScreen<br />
<br />
=== Author: Lainz. ===<br />
Contributor and package mantainer.<br />
<br />
BC Controls<br />
- TBCImageButton<br />
- TBCGameGrid<br />
<br />
BGRA Controls<br />
- TBGRASpriteAnimation<br />
<br />
=== Author: Emerson Cavalcanti. ===<br />
- TBGRAImageManipulation<br />
<br />
=== Author: mora. ===<br />
- Contributor to BCButton functionality.<br />
<br />
== Related Articles ==<br />
<br />
[[BGRASpriteAnimation]] - Usage of the sprite animation component.<br />
<br />
[[uE_Controls]] - Other controls developed with BGRABitmap.<br />
<br />
[[BGRABitmap]] - The library used to create this controls.<br />
<br />
[[LazPaint]] - A paint program developed with Lazarus and BGRABitmap.<br />
<br />
== BC ==<br />
=== BCButton ===<br />
[[Image:bcbutton.png]]<br />
=== BCGameGrid ===<br />
[[Image:bcgamegrid.png]]<br />
=== BCImageButton ===<br />
The bitmap must contain 4 states (from top to bottom, with the same Height) in the following order: normal, hover, active, disabled.<br />
<br />
''Example Button:''<br />
<br />
[[Image:samplebgraimagebutton.png]]<br />
<br />
''Example Button (with Alpha):''<br />
<br />
[[Image:samplebgraimagebuttonalpha.png]]<br />
<br />
=== BCXButton ===<br />
Fully customizable button with 'OnRenderControl' event.<br />
<br />
- Like TCDButton (Custom Drawn Button).<br />
<br />
- Call 'OnRenderControl' event (like a Drawer in CD) for each button, or one for all buttons.<br />
<br />
- Create fully customizable buttons, like using BGRAVirtualScreen or BCGraphicControl.<br />
<br />
[[Image:bcxbutton.png]]<br />
<br />
=== BCLabel ===<br />
[[Image:bclabel.png]]<br />
<br />
=== BCPanel ===<br />
[[Image:bcpanel.png]]<br />
<br />
== BGRA ==<br />
=== BGRAProgressBar ===<br />
'''Use as replace of:''' TProgressBar<br />
<br />
[[Image:BC-Bgraflashprogressbar.png]]<br />
<br />
Flash progressbar created by circular.<br />
<br />
=== BGRAGraphicControl ===<br />
'''Use as replace of:''' TPaintBox<br />
<br />
TBGRAGraphicControl, which allows to draw your component by yourself with alpha blending.<br />
<br />
=== BGRAImageList ===<br />
'''Use as replace of:''' TImageList<br />
<br />
'''Before:'''<br />
<br />
[[Image:before-TImageList.png]]<br />
<br />
'''After:'''<br />
<br />
[[Image:after-TBGRAImageList.png]]<br />
<br />
Component which inherits from TImageList. So each control (tested on TToolBar and TTreeView) which is using TImageList.Draw method for drawing icons, automatically can have alpha support. Just use this component instead of TImageList. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing).<br />
<br />
=== BGRAImageManipulation ===<br />
'''Use as replace of:''' TImage<br />
<br />
Component to facilitate the importation of images in an application.<br />
<br />
In the current version you can import an image and cut out keeping the aspect ratio (or not). For example, if you want to import photos using the 3x4 ratio, adjust the 'ratio' property to 3:4. If import an image with different size, the component will ensure that the image meets the proportions of the desired dimensions.<br />
<br />
You can determine the minimum size of the image adjusting the properties 'MinWidth'and 'MinHeight'.<br />
<br />
You can rotate the image using functions builtin.<br />
<br />
See demo of component:<br />
<br />
[[Image:bgraimagemanipulation.jpg]]<br />
<br />
After retrieving the image modified by the component, just put the image into your destination using the stretch. It is obvious that the target must have the same ratio chosen on component for do not distort the final result.<br />
<br />
=== BGRAKnob ===<br />
[[Image:BC-Bgraknob.png]]<br />
<br />
Graphic knob component created by circular.<br />
<br />
=== BGRAShape ===<br />
'''Use as replace of:''' TShape<br />
<br />
[[Image:samplebgrashape.png]]<br />
<br />
The component has full alpha support and you can put the number of polygons you want with rounded borders & gradients (linear, radial, diamond, reflected).<br />
<br />
=== BGRASpeedButton ===<br />
'''Use as replace of:''' TSpeedButton<br />
<br />
[[Image:BGRASpeedButton.png]]<br />
<br />
Component which inherits from TSpeedButton and draws the glyph using TBGRABitmap. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing).<br />
<br />
=== BGRASpriteAnimation ===<br />
'''Use as replace of:''' TImage<br />
<br />
Read more in the article [[BGRASpriteAnimation]].<br />
<br />
[[Image:bgraspriteanimation.png]]<br />
<br />
With this you can do animations from bitmap. You need an image with all the frames layout in in a horizontal position.<br />
<br />
It has the ability to specify how many times the animation should be played (0 for infinite, 1, 2, etc) and static to stop the animation, is capable to specify the speed and direction and support transparency.<br />
<br />
Features:<br />
* Animation: invert, position, lap, speed, static, repeat.<br />
* Sprite: fill opacity (global transparency), flip mode (horizontal, vertical, both), key color (transparent color), resample (normal or fine resample modes). AutoSize.<br />
* AnimatedGifToSprite: convert an animated gif to a BGRABitmap sprite.<br />
<br />
=== BGRAVirtualScreen ===<br />
'''Use as replacement of:''' TPanel, TPaintBox<br />
<br />
The principle is to draw on a memory bitmap.<br />
<br />
The component has a specific event, OnRedraw, which is called when the whole bitmap needs to be redrawn. It happens at the beginning and when the component is resized. You can also query to redraw the bitmap with Redraw and DiscardBitmap methods. The second one only invalidates the content, which can wait until the messageloop is handled.<br />
<br />
Otherwise, it is possible to modify the Bitmap property and call Invalidate or Repaint, to avoid erasing the whole bitmap content.<br />
<br />
== Test ==<br />
=== Game - Maze ===<br />
[[Image:game_maze.png]]<br />
<br />
=== Game - Puzzle ===<br />
[[Image:game_puzzle.png]]<br />
<br />
=== SliceScaling - CustomDrawn Windows 7 ===<br />
<br />
[[Image:customdrawnwindows7.png]]<br />
<br />
This is a drawer for [[Lazarus Custom Drawn Controls]], you need that component installed with the latest Lazarus revision to work.<br />
<br />
Working in this drawer: button, statictext, checkbox, radiobutton and progressbar.<br />
<br />
This has also extra images for 'Luna' (Windows XP Theme) 'Aero Lite' (Windows 8 Theme) and extra buttons (arrows).<br />
<br />
=== SliceScaling - TAChart ===<br />
<br />
9-slice scaling is usefull to create sizable UI elements like in the Custom Drawn Windows 7 Drawer.<br />
<br />
There's a [[TAChart]] example with slice scaled bars.<br />
<br />
[[File:slicescaledtachart.png]]<br />
<br />
== Outdated ==<br />
<br />
[[BGRAButton Gallery]] - Gallery of buttons with source code to use in your projects with BGRAButton.<br />
<br />
=== BGRABitmapThemeUtils ===<br />
<br />
This unit is used by BGRAImageButton to draw the button! Also it's usefull to skin controls from bitmaps.<br />
<br />
A more advanced version of this is SliceScaling.pas unit.<br />
<br />
=== BGRANeoButton ===<br />
<br />
This unit is an example, it's usefull to learn how to create your own button with bgrabitmap. BTW read the BGRAImageButton and BGRAButton code. All in this unit can be overriden. I've not added 'invalidate' messages in types and AutoSize, add your own according to your programming needs.<br />
<br />
=== TBGRAWin7ToolBar ===<br />
<br />
[[Image:bgrawin7toolbar.png]]<br />
<br />
Is a TBGRAVirtualScreen descendant with some default child sizing, and nice Win7 ToolBar background.<br />
<br />
=== BGRASamples unit ===<br />
<br />
This unit has sample drawings, styles for buttons and colors used in different UI.<br />
<br />
[[Image:ioselements.png]]<br />
<br />
* '''Accent Color:''' the colors used in the Windows Phone. The accent color can be used in TBGRAButton and TBGRAImageButton (see the different procedures).<br />
* '''Facebook button color:''' gray, green and blue, with a procedure to create an image in the normal or pressed state, also to use this style in a TBGRAImageButton.<br />
* '''TBGRASampleStyle:''' Styles for TBGRAButton ('Default', 'Flash Player', 'Windows 7 ToolBar', 'Windows 7 ToolBar Smooth', 'Windows 7', 'Office 2010', 'Mac OSX Lion', 'Windows 7 Cristal').<br />
* '''iOS Elements:''' Draw a gray bar, the blue toolbar and a tiled background, the same elements used in the iOS screen.<br />
* '''Glass:''' used in testbgracontrols, it show an image in a virtualscreen and apply blur in the buttons area.<br />
* '''Drawings:''' flash player body and toolbar, windows 7 toolbar.<br />
<br />
* Some other usefull procedures to work with TBGRAButton and TBGRAImageButton.<br />
<br />
=== TBGRAImageToggleBox ===<br />
<br />
REMOVED IN VER 1.1.0.7.<br />
<br />
'''Use as replace of:''' TToggleBox<br />
<br />
Component used to create a toggle box from Bitmap.<br />
<br />
The bitmap must contain 8 images (from top to bottom, with the same Height) in the following order: unchecked normal, unchecked enter, unchecked pressed, unchecked disabled for Unchecked state and checked normal, checked enter, checked pressed, checked disabled for Normal state.<br />
<br />
''Example toggle box:''<br />
<br />
[[Image:sampletogglebox.png]]<br />
<br />
=== TBGRALabel ===<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
Label component based on TBGRAButton.<br />
<br />
Features:<br />
* Caption with shadow or not<br />
* Full alpha and antialias support or not<br />
* WordWarp or not<br />
* Caption with Property Editor Multiline<br />
<br />
=== TBGRALabelFX ===<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
[[Image:bgralabelfx.png]]<br />
<br />
Features:<br />
* Outline<br />
* Shadow<br />
<br />
ToDo:<br />
* Use BGRATextFX multicolor, textures.<br />
* etc.<br />
<br />
=== TBGRAImageButton ===<br />
<br />
If you need some code to load and split an image from file, and then scale the borders like in this control you can use TBGRABitmapThemeUtils (included in BGRAControls).<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgraimagebutton.png]]<br />
<br />
Component used to create a button with 4 states from Bitmap.<br />
<br />
'''Features:'''<br />
* Load the image from the "Bitmap" property in the object inspector or load from file using "BitmapFile".<br />
<br />
// You can load bmp and also png files<br />
BGRAImageButton1.BitmapLoadFromFile(BGRAImageButton1.BitmapFile);<br />
<br />
* BitmapOptions: you can set the border pixels, resample method and fill modes. Usefull to create textured / like Windows themed buttons.<br />
* AutoSize, ModalResult.<br />
* Text with Shadow, you can disable text render with the option "TextVisible".<br />
* Sound: in mouse enter and leave in Windows from .wav files.<br />
* Toggle: you can read / set the current state with the property "Checked".<br />
* Animation: glowing effect.<br />
<br />
'''Usage:'''<br />
<br />
The bitmap must contain 4 states (from top to bottom, with the same Height) in the following order: normal, enter, pressed, disabled.<br />
<br />
If you choose to use BitmapOptions you need to have for each state an image which has a border, and inside some content that can be repeated. Then with FillCenter option (if you want a textured button), it gets repeated while the borders stay as they are. This is like the method used in Windows to theme the buttons.<br />
<br />
=== TBGRAButton ===<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgrabutton.png]]<br />
<br />
Customizable graphic component which is using only BGRABitmap functions for drawing. This component is insensitive for -dGTK_ONLY switch. Demo project included in package.<br />
<br />
'''Functionality:'''<br />
* Gradient, Clear or Color body. [[Double_Gradient]].<br />
* Text with shadow: BGRA antialias or like system default with ClearType.<br />
* Rounded border, inner Light.<br />
* States: normal, hover & clicked fully customizable and grayscale disabled state.<br />
* Special: Down, DropDown, Static.<br />
* Full AutoSize working with Glyph.<br />
<br />
=== TBGRAPanel ===<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
Simple TPanel descendant which can have gradient background. Created especially for TBGRAButton (for creating a nice looking toolbar for bgrabuttons). This component is insensitive for -dGTK_ONLY switch<br />
<br />
[[Category:Components]]<br />
[[Category:Graphics]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=File:bcxbutton.png&diff=66660File:bcxbutton.png2013-03-08T21:01:45Z<p>Lainz: </p>
<hr />
<div></div>Lainzhttps://wiki.freepascal.org/index.php?title=BGRAControls&diff=66653BGRAControls2013-03-08T16:48:44Z<p>Lainz: Updated according to latest BGRAControls SVN.</p>
<hr />
<div>{{BGRAControls}}<br />
<br />
== Install ==<br />
<br />
You can use TortoiseSVN to download the svn repository and TortoiseGIT to download the git repository.<br />
<br />
We're using BGRABitmap SVN to develop BGRAControls. Important changes in BGRABitmap can stop working BGRAControls.<br />
<br />
=== Download BGRABitmap ===<br />
<br />
Install BGRABitmap with the file bgrabitmap.lpk.<br />
<br />
'''Release:''' https://sourceforge.net/projects/lazpaint/files/src/<br />
<br />
==== SVN ====<br />
<br />
'''Latest SVN:''' svn co https://lazpaint.svn.sourceforge.net/svnroot/lazpaint lazpaint<br />
<br />
=== Download BGRAControls ===<br />
<br />
Install BGRAControls with the file bgracontrols.lpk.<br />
<br />
'''Release:''' https://sourceforge.net/projects/bgracontrols/files/<br />
<br />
==== SVN ====<br />
<br />
'''SVN Browse:''' http://bgracontrols.svn.sourceforge.net/viewvc/bgracontrols/<br />
<br />
'''SVN Checkout:''' svn co https://bgracontrols.svn.sourceforge.net/svnroot/bgracontrols bgracontrols<br />
<br />
==== GIT ====<br />
<br />
'''GIT Browse:''' http://bgracontrols.git.sourceforge.net/git/gitweb-index.cgi<br />
<br />
'''GIT Checkout:''' git://bgracontrols.git.sourceforge.net/gitroot/bgracontrols/bgracontrols <br />
<br />
== Overview ==<br />
<br />
License: Modified LGPL.<br />
<br />
As many people know, Lazarus GTK doesn't have full alpha support. I created a set of components which use TBGRABitmap for drawing icons, so it partially solves the problem with alpha in GTK. But this components set is not only a GTK patch but has more fancy components which are using the power of the BGRABitmap package.<br />
<br />
=== Author: Dibo. ===<br />
Package founder and package mantainer.<br />
<br />
BC Controls<br />
- TBCButton<br />
- TBCLabel<br />
- TBCPanel<br />
<br />
BGRA Controls<br />
- TBGRAImageList<br />
- TBGRASpeedButton<br />
<br />
=== Author: Circular. ===<br />
BGRABitmap creator, contributor and package mantainer.<br />
<br />
- TBGRAFlashProgressBar<br />
- TBGRAGraphicControl<br />
- TBGRAKnob<br />
- TBGRAShape<br />
- TBGRAVirtualScreen<br />
<br />
=== Author: Lainz. ===<br />
Contributor and package mantainer.<br />
<br />
BC Controls<br />
- TBCImageButton<br />
- TBCGameGrid<br />
<br />
BGRA Controls<br />
- TBGRASpriteAnimation<br />
<br />
=== Author: Emerson Cavalcanti. ===<br />
- TBGRAImageManipulation<br />
<br />
=== Author: mora. ===<br />
- Contributor to BCButton functionality.<br />
<br />
== Related Articles ==<br />
<br />
[[BGRASpriteAnimation]] - Usage of the sprite animation component.<br />
<br />
[[uE_Controls]] - Other controls developed with BGRABitmap.<br />
<br />
[[BGRABitmap]] - The library used to create this controls.<br />
<br />
[[LazPaint]] - A paint program developed with Lazarus and BGRABitmap.<br />
<br />
== BC ==<br />
=== BCButton ===<br />
[[Image:bcbutton.png]]<br />
=== BCGameGrid ===<br />
[[Image:bcgamegrid.png]]<br />
=== BCImageButton ===<br />
The bitmap must contain 4 states (from top to bottom, with the same Height) in the following order: normal, hover, active, disabled.<br />
<br />
''Example Button:''<br />
<br />
[[Image:samplebgraimagebutton.png]]<br />
<br />
''Example Button (with Alpha):''<br />
<br />
[[Image:samplebgraimagebuttonalpha.png]]<br />
<br />
=== BCLabel ===<br />
[[Image:bclabel.png]]<br />
<br />
=== BCPanel ===<br />
[[Image:bcpanel.png]]<br />
<br />
== BGRA ==<br />
=== BGRAProgressBar ===<br />
'''Use as replace of:''' TProgressBar<br />
<br />
[[Image:BC-Bgraflashprogressbar.png]]<br />
<br />
Flash progressbar created by circular.<br />
<br />
=== BGRAGraphicControl ===<br />
'''Use as replace of:''' TPaintBox<br />
<br />
TBGRAGraphicControl, which allows to draw your component by yourself with alpha blending.<br />
<br />
=== BGRAImageList ===<br />
'''Use as replace of:''' TImageList<br />
<br />
'''Before:'''<br />
<br />
[[Image:before-TImageList.png]]<br />
<br />
'''After:'''<br />
<br />
[[Image:after-TBGRAImageList.png]]<br />
<br />
Component which inherits from TImageList. So each control (tested on TToolBar and TTreeView) which is using TImageList.Draw method for drawing icons, automatically can have alpha support. Just use this component instead of TImageList. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing).<br />
<br />
=== BGRAImageManipulation ===<br />
'''Use as replace of:''' TImage<br />
<br />
Component to facilitate the importation of images in an application.<br />
<br />
In the current version you can import an image and cut out keeping the aspect ratio (or not). For example, if you want to import photos using the 3x4 ratio, adjust the 'ratio' property to 3:4. If import an image with different size, the component will ensure that the image meets the proportions of the desired dimensions.<br />
<br />
You can determine the minimum size of the image adjusting the properties 'MinWidth'and 'MinHeight'.<br />
<br />
You can rotate the image using functions builtin.<br />
<br />
See demo of component:<br />
<br />
[[Image:bgraimagemanipulation.jpg]]<br />
<br />
After retrieving the image modified by the component, just put the image into your destination using the stretch. It is obvious that the target must have the same ratio chosen on component for do not distort the final result.<br />
<br />
=== BGRAKnob ===<br />
[[Image:BC-Bgraknob.png]]<br />
<br />
Graphic knob component created by circular.<br />
<br />
=== BGRAShape ===<br />
'''Use as replace of:''' TShape<br />
<br />
[[Image:samplebgrashape.png]]<br />
<br />
The component has full alpha support and you can put the number of polygons you want with rounded borders & gradients (linear, radial, diamond, reflected).<br />
<br />
=== BGRASpeedButton ===<br />
'''Use as replace of:''' TSpeedButton<br />
<br />
[[Image:BGRASpeedButton.png]]<br />
<br />
Component which inherits from TSpeedButton and draws the glyph using TBGRABitmap. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing).<br />
<br />
=== BGRASpriteAnimation ===<br />
'''Use as replace of:''' TImage<br />
<br />
Read more in the article [[BGRASpriteAnimation]].<br />
<br />
[[Image:bgraspriteanimation.png]]<br />
<br />
With this you can do animations from bitmap. You need an image with all the frames layout in in a horizontal position.<br />
<br />
It has the ability to specify how many times the animation should be played (0 for infinite, 1, 2, etc) and static to stop the animation, is capable to specify the speed and direction and support transparency.<br />
<br />
Features:<br />
* Animation: invert, position, lap, speed, static, repeat.<br />
* Sprite: fill opacity (global transparency), flip mode (horizontal, vertical, both), key color (transparent color), resample (normal or fine resample modes). AutoSize.<br />
* AnimatedGifToSprite: convert an animated gif to a BGRABitmap sprite.<br />
<br />
=== BGRAVirtualScreen ===<br />
'''Use as replacement of:''' TPanel, TPaintBox<br />
<br />
The principle is to draw on a memory bitmap.<br />
<br />
The component has a specific event, OnRedraw, which is called when the whole bitmap needs to be redrawn. It happens at the beginning and when the component is resized. You can also query to redraw the bitmap with Redraw and DiscardBitmap methods. The second one only invalidates the content, which can wait until the messageloop is handled.<br />
<br />
Otherwise, it is possible to modify the Bitmap property and call Invalidate or Repaint, to avoid erasing the whole bitmap content.<br />
<br />
== Test ==<br />
=== Game - Maze ===<br />
[[Image:game_maze.png]]<br />
<br />
=== Game - Puzzle ===<br />
[[Image:game_puzzle.png]]<br />
<br />
=== SliceScaling - CustomDrawn Windows 7 ===<br />
<br />
[[Image:customdrawnwindows7.png]]<br />
<br />
This is a drawer for [[Lazarus Custom Drawn Controls]], you need that component installed with the latest Lazarus revision to work.<br />
<br />
Working in this drawer: button, statictext, checkbox, radiobutton and progressbar.<br />
<br />
This has also extra images for 'Luna' (Windows XP Theme) 'Aero Lite' (Windows 8 Theme) and extra buttons (arrows).<br />
<br />
=== SliceScaling - TAChart ===<br />
<br />
9-slice scaling is usefull to create sizable UI elements like in the Custom Drawn Windows 7 Drawer.<br />
<br />
There's a [[TAChart]] example with slice scaled bars.<br />
<br />
[[File:slicescaledtachart.png]]<br />
<br />
== Outdated ==<br />
<br />
[[BGRAButton Gallery]] - Gallery of buttons with source code to use in your projects with BGRAButton.<br />
<br />
=== BGRABitmapThemeUtils ===<br />
<br />
This unit is used by BGRAImageButton to draw the button! Also it's usefull to skin controls from bitmaps.<br />
<br />
A more advanced version of this is SliceScaling.pas unit.<br />
<br />
=== BGRANeoButton ===<br />
<br />
This unit is an example, it's usefull to learn how to create your own button with bgrabitmap. BTW read the BGRAImageButton and BGRAButton code. All in this unit can be overriden. I've not added 'invalidate' messages in types and AutoSize, add your own according to your programming needs.<br />
<br />
=== TBGRAWin7ToolBar ===<br />
<br />
[[Image:bgrawin7toolbar.png]]<br />
<br />
Is a TBGRAVirtualScreen descendant with some default child sizing, and nice Win7 ToolBar background.<br />
<br />
=== BGRASamples unit ===<br />
<br />
This unit has sample drawings, styles for buttons and colors used in different UI.<br />
<br />
[[Image:ioselements.png]]<br />
<br />
* '''Accent Color:''' the colors used in the Windows Phone. The accent color can be used in TBGRAButton and TBGRAImageButton (see the different procedures).<br />
* '''Facebook button color:''' gray, green and blue, with a procedure to create an image in the normal or pressed state, also to use this style in a TBGRAImageButton.<br />
* '''TBGRASampleStyle:''' Styles for TBGRAButton ('Default', 'Flash Player', 'Windows 7 ToolBar', 'Windows 7 ToolBar Smooth', 'Windows 7', 'Office 2010', 'Mac OSX Lion', 'Windows 7 Cristal').<br />
* '''iOS Elements:''' Draw a gray bar, the blue toolbar and a tiled background, the same elements used in the iOS screen.<br />
* '''Glass:''' used in testbgracontrols, it show an image in a virtualscreen and apply blur in the buttons area.<br />
* '''Drawings:''' flash player body and toolbar, windows 7 toolbar.<br />
<br />
* Some other usefull procedures to work with TBGRAButton and TBGRAImageButton.<br />
<br />
=== TBGRAImageToggleBox ===<br />
<br />
REMOVED IN VER 1.1.0.7.<br />
<br />
'''Use as replace of:''' TToggleBox<br />
<br />
Component used to create a toggle box from Bitmap.<br />
<br />
The bitmap must contain 8 images (from top to bottom, with the same Height) in the following order: unchecked normal, unchecked enter, unchecked pressed, unchecked disabled for Unchecked state and checked normal, checked enter, checked pressed, checked disabled for Normal state.<br />
<br />
''Example toggle box:''<br />
<br />
[[Image:sampletogglebox.png]]<br />
<br />
=== TBGRALabel ===<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
Label component based on TBGRAButton.<br />
<br />
Features:<br />
* Caption with shadow or not<br />
* Full alpha and antialias support or not<br />
* WordWarp or not<br />
* Caption with Property Editor Multiline<br />
<br />
=== TBGRALabelFX ===<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
[[Image:bgralabelfx.png]]<br />
<br />
Features:<br />
* Outline<br />
* Shadow<br />
<br />
ToDo:<br />
* Use BGRATextFX multicolor, textures.<br />
* etc.<br />
<br />
=== TBGRAImageButton ===<br />
<br />
If you need some code to load and split an image from file, and then scale the borders like in this control you can use TBGRABitmapThemeUtils (included in BGRAControls).<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgraimagebutton.png]]<br />
<br />
Component used to create a button with 4 states from Bitmap.<br />
<br />
'''Features:'''<br />
* Load the image from the "Bitmap" property in the object inspector or load from file using "BitmapFile".<br />
<br />
// You can load bmp and also png files<br />
BGRAImageButton1.BitmapLoadFromFile(BGRAImageButton1.BitmapFile);<br />
<br />
* BitmapOptions: you can set the border pixels, resample method and fill modes. Usefull to create textured / like Windows themed buttons.<br />
* AutoSize, ModalResult.<br />
* Text with Shadow, you can disable text render with the option "TextVisible".<br />
* Sound: in mouse enter and leave in Windows from .wav files.<br />
* Toggle: you can read / set the current state with the property "Checked".<br />
* Animation: glowing effect.<br />
<br />
'''Usage:'''<br />
<br />
The bitmap must contain 4 states (from top to bottom, with the same Height) in the following order: normal, enter, pressed, disabled.<br />
<br />
If you choose to use BitmapOptions you need to have for each state an image which has a border, and inside some content that can be repeated. Then with FillCenter option (if you want a textured button), it gets repeated while the borders stay as they are. This is like the method used in Windows to theme the buttons.<br />
<br />
=== TBGRAButton ===<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgrabutton.png]]<br />
<br />
Customizable graphic component which is using only BGRABitmap functions for drawing. This component is insensitive for -dGTK_ONLY switch. Demo project included in package.<br />
<br />
'''Functionality:'''<br />
* Gradient, Clear or Color body. [[Double_Gradient]].<br />
* Text with shadow: BGRA antialias or like system default with ClearType.<br />
* Rounded border, inner Light.<br />
* States: normal, hover & clicked fully customizable and grayscale disabled state.<br />
* Special: Down, DropDown, Static.<br />
* Full AutoSize working with Glyph.<br />
<br />
=== TBGRAPanel ===<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
Simple TPanel descendant which can have gradient background. Created especially for TBGRAButton (for creating a nice looking toolbar for bgrabuttons). This component is insensitive for -dGTK_ONLY switch<br />
<br />
[[Category:Components]]<br />
[[Category:Graphics]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=File:game_puzzle.png&diff=66652File:game puzzle.png2013-03-08T16:48:12Z<p>Lainz: </p>
<hr />
<div></div>Lainzhttps://wiki.freepascal.org/index.php?title=File:game_maze.png&diff=66651File:game maze.png2013-03-08T16:48:07Z<p>Lainz: </p>
<hr />
<div></div>Lainzhttps://wiki.freepascal.org/index.php?title=File:bcpanel.png&diff=66645File:bcpanel.png2013-03-08T16:42:23Z<p>Lainz: </p>
<hr />
<div></div>Lainzhttps://wiki.freepascal.org/index.php?title=File:bclabel.png&diff=66644File:bclabel.png2013-03-08T16:42:19Z<p>Lainz: </p>
<hr />
<div></div>Lainzhttps://wiki.freepascal.org/index.php?title=File:bcgamegrid.png&diff=66643File:bcgamegrid.png2013-03-08T16:42:10Z<p>Lainz: </p>
<hr />
<div></div>Lainzhttps://wiki.freepascal.org/index.php?title=File:bcbutton.png&diff=66642File:bcbutton.png2013-03-08T16:42:01Z<p>Lainz: </p>
<hr />
<div></div>Lainzhttps://wiki.freepascal.org/index.php?title=FileAssociation&diff=65954FileAssociation2013-02-17T11:59:09Z<p>Lainz: /* License */</p>
<hr />
<div>==FileAssociation==<br />
<br />
'''Package Name:''' fileassoc.lpk<br />
<br />
'''Component Name:''' TFileAssociation (fileassociation.pas)<br />
<br />
With this component you can easily register file associations for all Windows versions. This includes Windows Vista/7/8 Default Programs feature.<br />
<br />
Install like any package. The component is under the "System" tab.<br />
<br />
==License==<br />
Modified LGPL (The same as Lazarus).<br />
<br />
==Intended platform==<br />
Win32, Win64.<br />
<br />
==Status==<br />
Stable.<br />
<br />
==Where to download it:==<br />
[http://lazarus.freepascal.org/index.php/topic,19941.0.html Download (in Lazarus Forum)]<br />
<br />
==Who wrote it==<br />
[[User:Lainz|Lainz]].<br />
<br />
==Is support available==<br />
<br />
Yes, ask in the Lazarus forum, the same page that contains the download.<br />
<br />
==Test (included in download)==<br />
<br />
This registers file association for Lazarus.<br />
<br />
[[File:fileassoc.png]]<br />
<br />
Add a TFileAssociation in the form (assoc), a TButton (btnExec), a TDirectoryEdit (lazDir).<br />
<br />
Set these properties in the TFileAssociation:<br />
<br />
AppDescription = Open Source IDE for Free Pascal.<br />
<br />
AppName = Lazarus IDE<br />
<br />
AppNameNoSpaces = LazarusIDE<br />
<br />
CmdNameNoSpaces = Open<br />
<br />
<syntaxhighlight><br />
const<br />
lazExe = 'lazarus.exe';<br />
<br />
...<br />
<br />
procedure TForm1.btnExecClick(Sender: TObject);<br />
var<br />
lazExePath: string;<br />
AddedToAll: boolean;<br />
begin<br />
lazExePath := lazDir.Directory + PathDelim + lazExe;<br />
if FileExistsUTF8(lazExePath) then<br />
begin<br />
assoc.CmdData := '"' + lazExePath + '" "%1"';<br />
assoc.CmdIcon := lazExePath;<br />
<br />
// if you leave it empty the system will use localized 'Open' ('Abrir', 'Ouvrir', etc..)<br />
// it works for CmdNameNoSpaces 'Open', 'Edit', 'Print'<br />
// assoc.CmdName := 'Open with Lazarus';<br />
<br />
assoc.ExtData := '.lfm';<br />
assoc.ExtIcon := lazDir.Directory + '\images\LazarusForm.ico';<br />
assoc.ExtName := 'Lazarus Form';<br />
assoc.ExtNameNoSpaces := 'LazarusForm';<br />
<br />
// if can't add to all users try to add to single user<br />
if not assoc.Execute then<br />
begin<br />
AddedToAll := False;<br />
assoc.RegisterForAllUsers := False;<br />
// if doesn't works..<br />
if not assoc.Execute then<br />
begin<br />
ShowMessage('Can not write to registry');<br />
Exit;<br />
end;<br />
end<br />
else<br />
AddedToAll := True;<br />
<br />
// it needs to be called only one time<br />
assoc.AddAppToDefaultPrograms := False;<br />
<br />
assoc.ExtData := '.lpi';<br />
assoc.ExtIcon := lazDir.Directory + '\images\LazarusProject.ico';<br />
assoc.ExtName := 'Lazarus Project Information';<br />
assoc.ExtNameNoSpaces := 'LazarusProjectInformation';<br />
assoc.Execute;<br />
<br />
assoc.ExtData := '.lpk';<br />
assoc.ExtIcon := lazDir.Directory + '\images\lazaruspackage.ico';<br />
assoc.ExtName := 'Lazarus Package';<br />
assoc.ExtNameNoSpaces := 'LazarusPackage';<br />
assoc.Execute;<br />
<br />
assoc.ExtData := '.lpr';<br />
assoc.ExtIcon := lazDir.Directory + '\images\lprfile.ico';<br />
assoc.ExtName := 'Lazarus Program';<br />
assoc.ExtNameNoSpaces := 'LazarusProgram';<br />
assoc.Execute;<br />
<br />
assoc.ExtData := '.inc';<br />
assoc.ExtIcon := lazDir.Directory + '\images\includefile.ico';<br />
assoc.ExtName := 'Include File';<br />
assoc.ExtNameNoSpaces := 'IncludeFile';<br />
assoc.Execute;<br />
<br />
assoc.ExtData := '.pas';<br />
assoc.ExtIcon := lazDir.Directory + '\images\lprfile.ico';<br />
assoc.ExtName := 'Pascal Source Code';<br />
assoc.ExtNameNoSpaces := 'PascalSourceCodePAS';<br />
assoc.Execute;<br />
<br />
assoc.ExtData := '.pp';<br />
assoc.ExtIcon := lazDir.Directory + '\images\lprfile.ico';<br />
assoc.ExtName := 'Pascal Source Code';<br />
assoc.ExtNameNoSpaces := 'PascalSourceCodePP';<br />
assoc.Execute;<br />
<br />
// refresh icon cache<br />
assoc.ClearIconCache;<br />
<br />
if AddedToAll then<br />
ShowMessage('File Association Registered for All Users.')<br />
else<br />
ShowMessage('File Association Registered for Current User.' +<br />
LineEnding +<br />
'If you want to register for All Users run this program with Administrative Privileges.');<br />
end<br />
else<br />
ShowMessage(format('The directory %0:s does not contain %1:s.',<br />
['"' + lazDir.Directory + '"', '"' + lazExe + '"']));<br />
end;<br />
</syntaxhighlight><br />
<br />
[[Category:Lazarus]]<br />
[[Category:Components]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=Windows_Programming_Tips&diff=65935Windows Programming Tips2013-02-16T18:31:09Z<p>Lainz: /* File Association */</p>
<hr />
<div>This page is dedicated to desktop Windows programming tips.<br />
<br />
__TOC__<br />
<br />
{{Other Interfaces}}<br />
<br />
==Articles about Windows Programming==<br />
*[[High DPI]] - How to make your application DPI-aware on Windows 7.<br />
*[[Aero Glass]] - How to apply Aero Glass effect in a Lazarus Form on Windows 7.<br />
*[[Windows Icon]] - How to design your icon with the right sizes.<br />
*[[Inno Setup Usage]] - How to create setup files with File Association support.<br />
<br />
==Windows specific compiler options==<br />
<br />
The most prominent options are the '''-W''' flags. A GUI application requires the '''-WG''' flag. See ''Project Options / Compiler Options / Linking / Target OS Specific options / Win32 GUI application''. No console is shown, '''writeln''' and '''readln''' are not possible, you will get '''File not open''' errors. Omitting this option creates a console application (same as passing -WC).<br />
<br />
==COM Programming==<br />
<br />
===Importing and using a COM library===<br />
<br />
The first step to import and use a COM library is generating the interface definitions from it. Use the program importtl which is located in Free Pascal in fpc/utils/importtl. A pre-compiled binary of this program can be found here: http://sourceforge.net/projects/p-tools/files/ImportTL/<br />
<br />
You can call it, for example for MSAA like this:<br />
<br />
importtl.exe C:\Windows\system32\oleacc.dll<br />
<br />
And it will generate the type library pascal unit Accessibility_1_1_TLB.pas in the folder where it is.<br />
<br />
===Creating a library which exports a COM object===<br />
<br />
ToDo: write me<br />
<br />
===Windows Sensor/Location API===<br />
Available since Windows 7. See [[LazDeviceAPIs#Possible_Windows_implementation]]<br />
<br />
==ActiveX controls==<br />
You can use ActiveX controls in recent Lazarus versions. See [[LazActiveX]]<br />
<br />
==Code snippets==<br />
<br />
===File Association===<br />
To add icons to file associations and register for use with a program use:<br />
[[FileAssociation]] component.<br />
<br />
===Listing all available drives===<br />
<br />
<syntaxhighlight><br />
program listdevices;<br />
<br />
{$ifdef fpc}{$mode delphi}{$endif}<br />
{$apptype console}<br />
<br />
uses<br />
Windows;<br />
<br />
var<br />
Drive: Char;<br />
DriveLetter: string;<br />
begin<br />
WriteLn('The following drives were found in this computer:');<br />
WriteLn('');<br />
<br />
// Search all drive letters<br />
for Drive := 'A' to 'Z' do<br />
begin<br />
DriveLetter := Drive + ':\';<br />
<br />
case GetDriveType(PChar(DriveLetter)) of<br />
DRIVE_REMOVABLE: WriteLn(DriveLetter + ' Floppy Drive');<br />
DRIVE_FIXED: WriteLn(DriveLetter + ' Fixed Drive');<br />
DRIVE_REMOTE: WriteLn(DriveLetter + ' Network Drive');<br />
DRIVE_CDROM: WriteLn(DriveLetter + ' CD-ROM Drive');<br />
DRIVE_RAMDISK: WriteLn(DriveLetter + ' RAM Disk');<br />
end;<br />
end;<br />
<br />
// Also add a stop to see the result under Windows<br />
WriteLn('');<br />
WriteLn('Please press <ENTER> to exit the program.');<br />
ReadLn(DriveLetter);<br />
end.<br />
</syntaxhighlight><br />
<br />
===Creating a shortcut (.lnk) file===<br />
Creating a shortcut on the desktop (can be easily adapted to any location). Adapted from [http://www.mail-archive.com/fpc-pascal@lists.freepascal.org/msg13325.html post by Felipe Monteiro de Carvalho]<br />
The ISLink object has more methods that you can use to modify your shortcut...<br />
<br />
<syntaxhighlight><br />
uses<br />
...<br />
windows, shlobj {for special folders}, ActiveX, ComObj;<br />
...<br />
procedure CreateDesktopShortCut(Target, TargetArguments, ShortcutName: string);<br />
var<br />
IObject: IUnknown;<br />
ISLink: IShellLink;<br />
IPFile: IPersistFile;<br />
PIDL: PItemIDList;<br />
InFolder: array[0..MAX_PATH] of Char;<br />
TargetName: String;<br />
LinkName: WideString;<br />
begin<br />
{ Creates an instance of IShellLink }<br />
IObject := CreateComObject(CLSID_ShellLink);<br />
ISLink := IObject as IShellLink;<br />
IPFile := IObject as IPersistFile;<br />
<br />
ISLink.SetPath(pChar(Target));<br />
ISLink.SetArguments(pChar(TargetArguments));<br />
ISLink.SetWorkingDirectory(pChar(ExtractFilePath(Target)));<br />
<br />
{ Get the desktop location }<br />
SHGetSpecialFolderLocation(0, CSIDL_DESKTOPDIRECTORY, PIDL);<br />
SHGetPathFromIDList(PIDL, InFolder);<br />
LinkName := InFolder + PathDelim + ShortcutName+'.lnk';<br />
<br />
{ Create the link }<br />
IPFile.Save(PWChar(LinkName), false);<br />
end;<br />
<br />
</syntaxhighlight><br />
<br />
===Getting special folders (My documents, Desktop, local application data, etc)===<br />
Often it is useful to get the location of a special folder such as the desktop. The example below shows how you can get the LocalAppData directory - where the Lazarus installer stores its configuration by default.<br />
Look in the [http://delphi-miranda-plugins.googlecode.com/svn-history/r105/trunk/FPC/units/src/shlobj.pp shlobj] unit for more defines that let you look up the Desktop, Recycle Bin, etc.<br />
<syntaxhighlight><br />
uses <br />
...<br />
shlobj;<br />
<br />
var<br />
AppDataPath: Array[0..MaxPathLen] of Char; //Allocate memory<br />
...<br />
begin<br />
...<br />
AppDataPath:='';<br />
SHGetSpecialFolderPath(0,AppDataPath,CSIDL_LOCAL_APPDATA,false);<br />
writeln('Your local appdata path is: ' + AppDataPath);<br />
</syntaxhighlight><br />
<br />
===Enabling and disabling devices===<br />
The following code can be used to enable and disable Windows devices; it is useful to e.g. reset a serial port or USB device.<br />
An example program follows below.<br />
<syntaxhighlight><br />
unit controlwindevice;<br />
<br />
{ Enable Disable windows devices<br />
<br />
Copyright (c) 2010-2012 Ludo Brands<br />
<br />
Permission is hereby granted, free of charge, to any person obtaining a copy<br />
of this software and associated documentation files (the "Software"), to<br />
deal in the Software without restriction, including without limitation the<br />
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or<br />
sell copies of the Software, and to permit persons to whom the Software is<br />
furnished to do so, subject to the following conditions:<br />
<br />
The above copyright notice and this permission notice shall be included in<br />
all copies or substantial portions of the Software.<br />
<br />
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br />
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br />
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE<br />
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br />
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br />
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br />
IN THE SOFTWARE.<br />
}<br />
<br />
<br />
{$mode delphi}{$H+}<br />
<br />
interface<br />
<br />
uses<br />
Classes, SysUtils,dynlibs,windows;<br />
<br />
const<br />
GUID_DEVCLASS_NET : TGUID = '{4D36E972-E325-11CE-BFC1-08002BE10318}';<br />
GUID_DEVCLASS_PORT : TGUID = '{4D36E978-E325-11CE-BFC1-08002BE10318}';<br />
<br />
type<br />
TDeviceControlResult=(DCROK,DCRErrEnumDeviceInfo,DCRErrSetClassInstallParams,<br />
DCRErrDIF_PROPERTYCHANGE);<br />
<br />
function LoadDevices(GUID_DevClass:TGUID):TStringList;<br />
function EnableDevice(SelectedItem: DWord):TDeviceControlResult;<br />
function DisableDevice(SelectedItem: DWord):TDeviceControlResult;<br />
<br />
implementation<br />
<br />
// Setup api, based on SetupApi.pas JEDI library<br />
const<br />
DIF_PROPERTYCHANGE = $00000012;<br />
DICS_ENABLE = $00000001;<br />
DICS_DISABLE = $00000002;<br />
DICS_FLAG_GLOBAL = $00000001; // make change in all hardware profiles<br />
DIGCF_PRESENT = $00000002;<br />
SPDRP_DEVICEDESC = $00000000; // DeviceDesc (R/W)<br />
SPDRP_CLASS = $00000007; // Class (R--tied to ClassGUID)<br />
SPDRP_CLASSGUID = $00000008; // ClassGUID (R/W)<br />
SPDRP_FRIENDLYNAME = $0000000C; // FriendlyName (R/W)<br />
<br />
type<br />
HDEVINFO = Pointer;<br />
DI_FUNCTION = LongWord; // Function type for device installer<br />
<br />
PSPClassInstallHeader = ^TSPClassInstallHeader;<br />
SP_CLASSINSTALL_HEADER = packed record<br />
cbSize: DWORD;<br />
InstallFunction: DI_FUNCTION;<br />
end;<br />
TSPClassInstallHeader = SP_CLASSINSTALL_HEADER;<br />
<br />
PSPPropChangeParams = ^TSPPropChangeParams;<br />
SP_PROPCHANGE_PARAMS = packed record<br />
ClassInstallHeader: TSPClassInstallHeader;<br />
StateChange: DWORD;<br />
Scope: DWORD;<br />
HwProfile: DWORD;<br />
end;<br />
TSPPropChangeParams = SP_PROPCHANGE_PARAMS;<br />
<br />
PSPDevInfoData = ^TSPDevInfoData;<br />
SP_DEVINFO_DATA = packed record<br />
cbSize: DWORD;<br />
ClassGuid: TGUID;<br />
DevInst: DWORD; // DEVINST handle<br />
Reserved: ULONG_PTR;<br />
end;<br />
TSPDevInfoData = SP_DEVINFO_DATA;<br />
<br />
TSetupDiEnumDeviceInfo = function(DeviceInfoSet: HDEVINFO;<br />
MemberIndex: DWORD; var DeviceInfoData: TSPDevInfoData): LongBool; stdcall;<br />
TSetupDiSetClassInstallParamsA = function(DeviceInfoSet: HDEVINFO;<br />
DeviceInfoData: PSPDevInfoData; ClassInstallParams: PSPClassInstallHeader;<br />
ClassInstallParamsSize: DWORD): LongBool; stdcall;<br />
TSetupDiSetClassInstallParamsW = function(DeviceInfoSet: HDEVINFO;<br />
DeviceInfoData: PSPDevInfoData; ClassInstallParams: PSPClassInstallHeader;<br />
ClassInstallParamsSize: DWORD): LongBool; stdcall;<br />
TSetupDiSetClassInstallParams = TSetupDiSetClassInstallParamsA;<br />
TSetupDiCallClassInstaller = function(InstallFunction: DI_FUNCTION;<br />
DeviceInfoSet: HDEVINFO; DeviceInfoData: PSPDevInfoData): LongBool; stdcall;<br />
TSetupDiGetClassDevs = function(ClassGuid: PGUID; const Enumerator: PAnsiChar;<br />
hwndParent: HWND; Flags: DWORD): HDEVINFO; stdcall;<br />
TSetupDiGetDeviceRegistryPropertyA = function(DeviceInfoSet: HDEVINFO;<br />
const DeviceInfoData: TSPDevInfoData; Property_: DWORD;<br />
var PropertyRegDataType: DWORD; PropertyBuffer: PBYTE; PropertyBufferSize: DWORD;<br />
var RequiredSize: DWORD): BOOL; stdcall;<br />
TSetupDiGetDeviceRegistryPropertyW = function(DeviceInfoSet: HDEVINFO;<br />
const DeviceInfoData: TSPDevInfoData; Property_: DWORD;<br />
var PropertyRegDataType: DWORD; PropertyBuffer: PBYTE; PropertyBufferSize: DWORD;<br />
var RequiredSize: DWORD): BOOL; stdcall;<br />
TSetupDiGetDeviceRegistryProperty = TSetupDiGetDeviceRegistryPropertyA;<br />
<br />
var<br />
DevInfo: hDevInfo;<br />
SetupDiEnumDeviceInfo: TSetupDiEnumDeviceInfo;<br />
SetupDiSetClassInstallParams: TSetupDiSetClassInstallParams;<br />
SetupDiCallClassInstaller: TSetupDiCallClassInstaller;<br />
SetupDiGetClassDevs: TSetupDiGetClassDevs;<br />
SetupDiGetDeviceRegistryProperty: TSetupDiGetDeviceRegistryProperty;<br />
<br />
var<br />
SetupApiLoadCount:integer=0;<br />
<br />
function LoadSetupApi: Boolean;<br />
var SetupApiLib:TLibHandle;<br />
begin<br />
Result := True;<br />
Inc(SetupApiLoadCount);<br />
if SetupApiLoadCount > 1 then<br />
Exit;<br />
SetupApiLib:=LoadLibrary('SetupApi.dll');<br />
Result := SetupApiLib<>0;<br />
if Result then<br />
begin<br />
SetupDiEnumDeviceInfo := GetProcedureAddress(SetupApiLib, 'SetupDiEnumDeviceInfo');<br />
SetupDiSetClassInstallParams := GetProcedureAddress(SetupApiLib, 'SetupDiSetClassInstallParamsA');<br />
SetupDiCallClassInstaller := GetProcedureAddress(SetupApiLib, 'SetupDiCallClassInstaller');<br />
SetupDiGetClassDevs := GetProcedureAddress(SetupApiLib, 'SetupDiGetClassDevsA');<br />
SetupDiGetDeviceRegistryProperty := GetProcedureAddress(SetupApiLib, 'SetupDiGetDeviceRegistryPropertyA');<br />
end;<br />
end;<br />
<br />
// implementation<br />
<br />
function StateChange(NewState, SelectedItem: DWord;<br />
hDevInfo: hDevInfo): TDeviceControlResult;<br />
var<br />
PropChangeParams: TSPPropChangeParams;<br />
DeviceInfoData: TSPDevInfoData;<br />
begin<br />
PropChangeParams.ClassInstallHeader.cbSize := SizeOf(TSPClassInstallHeader);<br />
DeviceInfoData.cbSize := SizeOf(TSPDevInfoData);<br />
// Get a handle to the Selected Item.<br />
if (not SetupDiEnumDeviceInfo(hDevInfo, SelectedItem, DeviceInfoData)) then<br />
begin<br />
Result := DCRErrEnumDeviceInfo;<br />
exit;<br />
end;<br />
// Set the PropChangeParams structure.<br />
PropChangeParams.ClassInstallHeader.InstallFunction := DIF_PROPERTYCHANGE;<br />
PropChangeParams.Scope := DICS_FLAG_GLOBAL;<br />
PropChangeParams.StateChange := NewState;<br />
if (not SetupDiSetClassInstallParams(hDevInfo, @DeviceInfoData,<br />
PSPClassInstallHeader(@PropChangeParams), SizeOf(PropChangeParams))) then<br />
begin<br />
Result := DCRErrSetClassInstallParams;<br />
exit;<br />
end;<br />
// Call the ClassInstaller and perform the change.<br />
if (not SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, hDevInfo, @DeviceInfoData)) then<br />
begin<br />
Result := DCRErrDIF_PROPERTYCHANGE;<br />
exit;<br />
end;<br />
Result := DCROK;<br />
end;<br />
<br />
function GetRegistryProperty(PnPHandle: HDEVINFO;<br />
DevData: TSPDevInfoData; Prop: DWORD; Buffer: PChar;<br />
dwLength: DWord): Boolean;<br />
var<br />
aBuffer: array[0..256] of Char;<br />
begin<br />
dwLength := 0;<br />
aBuffer[0] := #0;<br />
SetupDiGetDeviceRegistryProperty(PnPHandle, DevData, Prop, Prop, PBYTE(@aBuffer[0]), SizeOf(aBuffer), dwLength);<br />
StrCopy(Buffer, aBuffer);<br />
Result := Buffer^ <> #0;<br />
end;<br />
<br />
function ConstructDeviceName(DeviceInfoSet: hDevInfo;<br />
DeviceInfoData: TSPDevInfoData; Buffer: PChar; dwLength: DWord): Boolean;<br />
const<br />
UnknownDevice = '<Unknown Device>';<br />
begin<br />
if (not GetRegistryProperty(DeviceInfoSet, DeviceInfoData, SPDRP_FRIENDLYNAME, Buffer, dwLength)) then<br />
begin<br />
if (not GetRegistryProperty(DeviceInfoSet, DeviceInfoData, SPDRP_DEVICEDESC, Buffer, dwLength)) then<br />
begin<br />
if (not GetRegistryProperty(DeviceInfoSet, DeviceInfoData, SPDRP_CLASS, Buffer, dwLength)) then<br />
begin<br />
if (not GetRegistryProperty(DeviceInfoSet, DeviceInfoData, SPDRP_CLASSGUID, Buffer, dwLength)) then<br />
begin<br />
dwLength := DWord(SizeOf(UnknownDevice));<br />
Buffer := Pointer(LocalAlloc(LPTR, Cardinal(dwLength)));<br />
StrCopy(Buffer, UnknownDevice);<br />
end;<br />
end;<br />
end;<br />
end;<br />
Result := true;<br />
end;<br />
<br />
<br />
function LoadDevices(GUID_DevClass:TGUID):TStringList;<br />
var<br />
DeviceInfoData: TSPDevInfoData;<br />
i: DWord;<br />
pszText: PChar;<br />
<br />
begin<br />
if (not LoadSetupAPI) then<br />
begin<br />
result:=nil;<br />
exit;<br />
end;<br />
DevInfo := nil;<br />
// Get a handle to all devices in all classes present on system<br />
DevInfo := SetupDiGetClassDevs(@GUID_DevClass, nil, 0, DIGCF_PRESENT);<br />
if (DevInfo = Pointer(INVALID_HANDLE_VALUE)) then<br />
begin<br />
result:=nil;<br />
exit;<br />
end;<br />
Result:=TStringList.Create;<br />
DeviceInfoData.cbSize := SizeOf(TSPDevInfoData);<br />
i := 0;<br />
// Enumerate though all the devices.<br />
while SetupDiEnumDeviceInfo(DevInfo, i, DeviceInfoData) do<br />
begin<br />
GetMem(pszText, 256);<br />
try<br />
// Get a friendly name for the device.<br />
ConstructDeviceName(DevInfo, DeviceInfoData, pszText, DWord(nil));<br />
Result.AddObject(pszText,Tobject(i));<br />
finally<br />
FreeMem(pszText);<br />
inc(i);<br />
end;<br />
end;<br />
end;<br />
<br />
function EnableDevice(SelectedItem: DWord):TDeviceControlResult;<br />
<br />
begin<br />
result:=StateChange(DICS_ENABLE, SelectedItem , DevInfo);<br />
end;<br />
<br />
function DisableDevice(SelectedItem: DWord):TDeviceControlResult;<br />
<br />
begin<br />
result:=StateChange(DICS_DISABLE, SelectedItem , DevInfo);<br />
end;<br />
<br />
end.<br />
</syntaxhighlight><br />
<br />
Example program that lists all ports preceeded by a number. <br />
<br />
Enter a number and the port will be disabled. Enter return again and the port will be enabled again.<br />
<syntaxhighlight><br />
program devicetest;<br />
<br />
{$mode delphi}{$H+}<br />
<br />
uses<br />
Classes, controlwindevice;<br />
var<br />
sl:tstringlist;<br />
i:integer;<br />
begin<br />
sl:=Loaddevices(GUID_DEVCLASS_PORT);<br />
for i:=0 to sl.count-1 do<br />
writeln(i,' : ',sl[i]);<br />
readln(i);<br />
if DisableDevice(i)=DCROK then<br />
writeln(sl[i],' disabled');<br />
readln;<br />
if EnableDevice(i)=DCROK then<br />
writeln(sl[i],' enabled');<br />
sl.Free;<br />
readln;<br />
end.<br />
</syntaxhighlight><br />
<br />
===Downloading a file using urlmon===<br />
Urlmon.dll is built into Windows and can be used to e.g. download a file from a web site. It supports SSL/TLS connections.<br />
<br />
Windows-only; please look into libraries like [[Synapse]] and [[Indy]] for cross-platform solutions.<br />
<syntaxhighlight><br />
function URLDownloadToFile(pCaller: pointer; URL: PChar; FileName: PChar; Reserved: DWORD; lpfnCB : pointer): HResult; stdcall; external 'urlmon.dll' name 'URLDownloadToFileA';<br />
<br />
procedure TForm1.Button1Click(Sender: TObject);<br />
var Source, Dest: string;<br />
begin<br />
Source:='http://lazarus.freepascal.org';<br />
Dest:='C:\Windows\temp\data.txt';<br />
if URLDownloadToFile(nil, PChar(Source), PChar(Dest), 0, nil)=0 then<br />
showmessage('Download ok!')<br />
else<br />
showMessage('Error downloading '+Source);<br />
end;<br />
</syntaxhighlight><br />
<br />
[[category:Example programs]]<br />
[[category:Lazarus]]<br />
[[category:FPC]]<br />
[[Category:Operating Systems and Platforms]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=FileAssociation&diff=65934FileAssociation2013-02-16T18:26:43Z<p>Lainz: /* Test (included in download) */</p>
<hr />
<div>==FileAssociation==<br />
<br />
'''Package Name:''' fileassoc.lpk<br />
'''Component Name:''' TFileAssociation (fileassociation.pas)<br />
<br />
With this component you can easily register file associations for all Windows versions. This includes Windows Vista/7/8 Default Programs feature.<br />
<br />
Install like any package. The component is under the "System" tab.<br />
<br />
==License==<br />
LGPL (The same as Lazarus).<br />
<br />
==Intended platform==<br />
Win32, Win64.<br />
<br />
==Status==<br />
Stable.<br />
<br />
==Where to download it:==<br />
[http://lazarus.freepascal.org/index.php/topic,19941.0.html Download (in Lazarus Forum)]<br />
<br />
==Who wrote it==<br />
Lainz.<br />
<br />
==Is support available==<br />
<br />
Yes, Ask in the lazarus forum, the same page that contains the download.<br />
<br />
==Test (included in download)==<br />
<br />
This register file association for lazarus.<br />
<br />
[[File:fileassoc.png]]<br />
<br />
Add a TFileAssociation in the form (assoc), a TButton (btnExec), a TDirectoryEdit (lazDir).<br />
<br />
Set these properties in the TFileAssociation:<br />
<br />
AppDescription = Open Source IDE for Free Pascal.<br />
<br />
AppName = Lazarus IDE<br />
<br />
AppNameNoSpaces = LazarusIDE<br />
<br />
CmdNameNoSpaces = Open<br />
<br />
<syntaxhighlight><br />
const<br />
lazExe = 'lazarus.exe';<br />
<br />
...<br />
<br />
procedure TForm1.btnExecClick(Sender: TObject);<br />
var<br />
lazExePath: string;<br />
AddedToAll: boolean;<br />
begin<br />
lazExePath := lazDir.Directory + PathDelim + lazExe;<br />
if FileExistsUTF8(lazExePath) then<br />
begin<br />
assoc.CmdData := '"' + lazExePath + '" "%1"';<br />
assoc.CmdIcon := lazExePath;<br />
<br />
// if you leave it empty the system will use localized 'Open' ('Abrir', 'Ouvrir', etc..)<br />
// it works for CmdNameNoSpaces 'Open', 'Edit', 'Print'<br />
// assoc.CmdName := 'Open with Lazarus';<br />
<br />
assoc.ExtData := '.lfm';<br />
assoc.ExtIcon := lazDir.Directory + '\images\LazarusForm.ico';<br />
assoc.ExtName := 'Lazarus Form';<br />
assoc.ExtNameNoSpaces := 'LazarusForm';<br />
<br />
// if can't add to all users try to add to single user<br />
if not assoc.Execute then<br />
begin<br />
AddedToAll := False;<br />
assoc.RegisterForAllUsers := False;<br />
// if doesn't works..<br />
if not assoc.Execute then<br />
begin<br />
ShowMessage('Can not write to registry');<br />
Exit;<br />
end;<br />
end<br />
else<br />
AddedToAll := True;<br />
<br />
// it needs to be called only one time<br />
assoc.AddAppToDefaultPrograms := False;<br />
<br />
assoc.ExtData := '.lpi';<br />
assoc.ExtIcon := lazDir.Directory + '\images\LazarusProject.ico';<br />
assoc.ExtName := 'Lazarus Project Information';<br />
assoc.ExtNameNoSpaces := 'LazarusProjectInformation';<br />
assoc.Execute;<br />
<br />
assoc.ExtData := '.lpk';<br />
assoc.ExtIcon := lazDir.Directory + '\images\lazaruspackage.ico';<br />
assoc.ExtName := 'Lazarus Package';<br />
assoc.ExtNameNoSpaces := 'LazarusPackage';<br />
assoc.Execute;<br />
<br />
assoc.ExtData := '.lpr';<br />
assoc.ExtIcon := lazDir.Directory + '\images\lprfile.ico';<br />
assoc.ExtName := 'Lazarus Program';<br />
assoc.ExtNameNoSpaces := 'LazarusProgram';<br />
assoc.Execute;<br />
<br />
assoc.ExtData := '.inc';<br />
assoc.ExtIcon := lazDir.Directory + '\images\includefile.ico';<br />
assoc.ExtName := 'Include File';<br />
assoc.ExtNameNoSpaces := 'IncludeFile';<br />
assoc.Execute;<br />
<br />
assoc.ExtData := '.pas';<br />
assoc.ExtIcon := lazDir.Directory + '\images\lprfile.ico';<br />
assoc.ExtName := 'Pascal Source Code';<br />
assoc.ExtNameNoSpaces := 'PascalSourceCodePAS';<br />
assoc.Execute;<br />
<br />
assoc.ExtData := '.pp';<br />
assoc.ExtIcon := lazDir.Directory + '\images\lprfile.ico';<br />
assoc.ExtName := 'Pascal Source Code';<br />
assoc.ExtNameNoSpaces := 'PascalSourceCodePP';<br />
assoc.Execute;<br />
<br />
// refresh icon cache<br />
assoc.ClearIconCache;<br />
<br />
if AddedToAll then<br />
ShowMessage('File Association Registered for All Users.')<br />
else<br />
ShowMessage('File Association Registered for Current User.' +<br />
LineEnding +<br />
'If you want to register for All Users run this program with Administrative Privileges.');<br />
end<br />
else<br />
ShowMessage(format('The directory %0:s does not contain %1:s.',<br />
['"' + lazDir.Directory + '"', '"' + lazExe + '"']));<br />
end;<br />
</syntaxhighlight></div>Lainzhttps://wiki.freepascal.org/index.php?title=FileAssociation&diff=65933FileAssociation2013-02-16T18:17:59Z<p>Lainz: Created page with "==FileAssociation== '''Package Name:''' fileassoc.lpk '''Component Name:''' TFileAssociation (fileassociation.pas) With this component you can easily register file associati..."</p>
<hr />
<div>==FileAssociation==<br />
<br />
'''Package Name:''' fileassoc.lpk<br />
'''Component Name:''' TFileAssociation (fileassociation.pas)<br />
<br />
With this component you can easily register file associations for all Windows versions. This includes Windows Vista/7/8 Default Programs feature.<br />
<br />
Install like any package. The component is under the "System" tab.<br />
<br />
==License==<br />
LGPL (The same as Lazarus).<br />
<br />
==Intended platform==<br />
Win32, Win64.<br />
<br />
==Status==<br />
Stable.<br />
<br />
==Where to download it:==<br />
[http://lazarus.freepascal.org/index.php/topic,19941.0.html Download (in Lazarus Forum)]<br />
<br />
==Who wrote it==<br />
Lainz.<br />
<br />
==Is support available==<br />
<br />
Yes, Ask in the lazarus forum, the same page that contains the download.<br />
<br />
==Test (included in download)==<br />
<br />
This register file association for lazarus.<br />
<br />
[[File:fileassoc.png]]<br />
<br />
Add a TFileAssociation in the form, a TButton, a TDirectoryEdit and then write this code:<br />
<syntaxhighlight><br />
const<br />
lazExe = 'lazarus.exe';<br />
<br />
...<br />
<br />
procedure TForm1.btnExecClick(Sender: TObject);<br />
var<br />
lazExePath: string;<br />
AddedToAll: boolean;<br />
begin<br />
lazExePath := lazDir.Directory + PathDelim + lazExe;<br />
if FileExistsUTF8(lazExePath) then<br />
begin<br />
assoc.CmdData := '"' + lazExePath + '" "%1"';<br />
assoc.CmdIcon := lazExePath;<br />
<br />
// if you leave it empty the system will use localized 'Open' ('Abrir', 'Ouvrir', etc..)<br />
// it works for CmdNameNoSpaces 'Open', 'Edit', 'Print'<br />
// assoc.CmdName := 'Open with Lazarus';<br />
<br />
assoc.ExtData := '.lfm';<br />
assoc.ExtIcon := lazDir.Directory + '\images\LazarusForm.ico';<br />
assoc.ExtName := 'Lazarus Form';<br />
assoc.ExtNameNoSpaces := 'LazarusForm';<br />
<br />
// if can't add to all users try to add to single user<br />
if not assoc.Execute then<br />
begin<br />
AddedToAll := False;<br />
assoc.RegisterForAllUsers := False;<br />
// if doesn't works..<br />
if not assoc.Execute then<br />
begin<br />
ShowMessage('Can not write to registry');<br />
Exit;<br />
end;<br />
end<br />
else<br />
AddedToAll := True;<br />
<br />
// it needs to be called only one time<br />
assoc.AddAppToDefaultPrograms := False;<br />
<br />
assoc.ExtData := '.lpi';<br />
assoc.ExtIcon := lazDir.Directory + '\images\LazarusProject.ico';<br />
assoc.ExtName := 'Lazarus Project Information';<br />
assoc.ExtNameNoSpaces := 'LazarusProjectInformation';<br />
assoc.Execute;<br />
<br />
assoc.ExtData := '.lpk';<br />
assoc.ExtIcon := lazDir.Directory + '\images\lazaruspackage.ico';<br />
assoc.ExtName := 'Lazarus Package';<br />
assoc.ExtNameNoSpaces := 'LazarusPackage';<br />
assoc.Execute;<br />
<br />
assoc.ExtData := '.lpr';<br />
assoc.ExtIcon := lazDir.Directory + '\images\lprfile.ico';<br />
assoc.ExtName := 'Lazarus Program';<br />
assoc.ExtNameNoSpaces := 'LazarusProgram';<br />
assoc.Execute;<br />
<br />
assoc.ExtData := '.inc';<br />
assoc.ExtIcon := lazDir.Directory + '\images\includefile.ico';<br />
assoc.ExtName := 'Include File';<br />
assoc.ExtNameNoSpaces := 'IncludeFile';<br />
assoc.Execute;<br />
<br />
assoc.ExtData := '.pas';<br />
assoc.ExtIcon := lazDir.Directory + '\images\lprfile.ico';<br />
assoc.ExtName := 'Pascal Source Code';<br />
assoc.ExtNameNoSpaces := 'PascalSourceCodePAS';<br />
assoc.Execute;<br />
<br />
assoc.ExtData := '.pp';<br />
assoc.ExtIcon := lazDir.Directory + '\images\lprfile.ico';<br />
assoc.ExtName := 'Pascal Source Code';<br />
assoc.ExtNameNoSpaces := 'PascalSourceCodePP';<br />
assoc.Execute;<br />
<br />
// refresh icon cache<br />
assoc.ClearIconCache;<br />
<br />
if AddedToAll then<br />
ShowMessage('File Association Registered for All Users.')<br />
else<br />
ShowMessage('File Association Registered for Current User.' +<br />
LineEnding +<br />
'If you want to register for All Users run this program with Administrative Privileges.');<br />
end<br />
else<br />
ShowMessage(format('The directory %0:s does not contain %1:s.',<br />
['"' + lazDir.Directory + '"', '"' + lazExe + '"']));<br />
end;<br />
</syntaxhighlight></div>Lainzhttps://wiki.freepascal.org/index.php?title=File:fileassoc.png&diff=65932File:fileassoc.png2013-02-16T18:16:23Z<p>Lainz: </p>
<hr />
<div></div>Lainzhttps://wiki.freepascal.org/index.php?title=Components_and_Code_examples&diff=65931Components and Code examples2013-02-16T18:06:14Z<p>Lainz: /* System */</p>
<hr />
<div>{{Components and Code examples}}<br />
<br />
==Lazarus-CCR Released Components==<br />
<br />
===Multimedia===<br />
* [[ACS]] - Audio Component Suite, a collection of components to develop applications for audio playing/recording/processing. Can play wav,ogg,mp3,mp2,wma ... record from any recordable source, do everything simultan, ripping and more. See [http://acs.ullihome.de/ ACS]<br />
* [[Bluetooth]] - Accessing Bluetooth devices. For example the Wiimote.<br />
<br />
===Graphics===<br />
* [[Graphics libraries]] - here you can see the main graphic libraries you can use to develop.<br />
* [[pyramidtiff]] - a command line tool to create from an image file a tiff file with multiple resolutions usable with iipimage and other high resolution image viewers.<br />
<br />
'''2D Drawing'''<br />
<br />
* [[ZenGL]] - cross-platform game development library using OpenGL.<br />
* [[BGRABitmap]] - Drawing shapes and bitmaps with transparency, direct access to pixels, etc. <br />
* [[LazRGBGraphics]] - A package for fast in memory image processing and pixel manipulations (like scan line).<br />
* [[fpvectorial]] - Offers support to read, modify and write vectorial images. <br />
* [[Double Gradient]] - Draw 'double gradient' & 'n gradient' bitmaps easy.<br />
* [[Gradient Filler]] - TGradientFiller is the best way to create custom n gradients in Lazarus.<br />
* [[PascalMagick]] - an easy to use API for interfacing with [http://www.imagemagick.org ImageMagick], a multiplatform free software suite to create, edit, and compose bitmap images.<br />
* [[Sample Graphics]] - graphics gallery created with Lazarus and drawing tools<br />
* [[Fast direct pixel access]] - speed comparison of some methods for direct bitmap pixel access<br />
* [[SMNetGradient]] - A Gradient Fill component for Lazarus.<br />
* [[TMetafile_/_TMetafileCanvas|TMetafile/TMetafileCanvas]] - EnhMetafile API implementation for Windows.<br />
<br />
'''3D Drawing'''<br />
<br />
* [[GLScene]] - A port of the 3D visual OpenGL graphics Library [http://www.glscene.org GLScene]<br />
* [[TOpenGLBox]] - A barebones OpenGL component for Lazarus that provides an OpenGL rendering area.<br />
<br />
'''Charts'''<br />
<br />
* [[TAChart]] - Charting component for Lazarus<br />
* [[PlotPanel]] - A plotting and charting component for animated graphs<br />
* [[Perlin Noise]] - An article about using Perlin Noise on LCL applications.<br />
<br />
===Tools===<br />
* [[FpSystools]] - Conversion of TurboPower's Systools for Kylix package to Lazarus/FPC<br />
* [[DCPcrypt]] - DCPcrypt Cryptographic Component Library<br />
* [[RXfpc]] - Some of the well known RXlib components components converted to Lazarus<br />
* [[MultiLog]] - A Log system designed for FPC-Lazarus<br />
* [[OnGuard]] - A port of Turbo Power OnGuard<br />
* [[UniqueInstance]] - A component to force only one instance running at same time<br />
* [[XDev Toolkit]] - Cross-platform development tools.<br />
* [[MouseAndKeyInput]] - Tool for cross-platform manipulation with mouse and key input.<br />
* [[PascalSane]] - bindings for the libsane scanner API, with demo application.<br />
* [[log4delphi]] - A Log system based on log4j<br />
* [[fppkggui]] - A simple frontend gui for [[fppkg]]<br />
* [[SymScan]] - Barcode Scanner interface for Symbol/Motorolla MC series handhelds.<br />
* [[Theodp]] - UTF-8 Tools<br />
* [[DELPHI FORM TO HTML CONVERTER]] - Delphi Form to HTML Converter - new by PEW<br />
* [[InstantFPC]] - run pascal programs as normal unix scripts<br />
* [[LazBarcodes]] - Generate barcodes (QRCode, Aztec, DataMatrix, ...)<br />
<br />
===Archiving===<br />
* [[Zlibar]] - Objects to create and extract a zlib compressed archive containing multiple files<br />
* [[FreePascalArchivePackage]] - Conversion of TurboPower Software's Abbrevia library for the Free Pascal Compiler<br />
* [[ZipFile]] - Component that encapsulates a zipfile, you can read and write from it as if it's a filesystem<br />
* [[libtar]] - Classes for .TAR archives by Stefan Heymann, who kindly relicensed so that they are now in the FPC 2.1.1 and later distributions. Can be combined by zstream to create .tar.gz files.<br />
* [[bzip2lib]] - Stream classes for bzip2 compression and decompression.<br />
<br />
===Editors and viewers===<br />
* [[PowerPDF]] - Port of the PowerPDF (visual) components for Lazarus<br />
* [[RichView]] - Port of the TRichView Freeware Edition Components to Lazarus<br />
* [[Fshcomp]] - Edit components.<br />
* [[SynEdit]] - Source Editor component (used by the IDE)<br />
* [http://wiki.lazarus.freepascal.org/SynEdit/port Synedit 2.0.5 port]<br />
* [[RichMemo]] - A cross-platform component designed as rich text editor and viewer.<br />
<br />
===Networking===<br />
* [[BeepFp]] - BEEP Protocol framework<br />
* [[Sockets]] - TCP/IP Sockets components<br />
* [[lNet]] - Networking components which provides simple, single-threaded event-driven networking suite with protocols from TCP and UDP to SMTP and HTTP. lNet was designed to not depend on any external libraries and is extremely portable.<br />
* [[FPC_and_Apache_Modules|FPC and Apache Modules]] - Headers for creating Apache modules with fpc<br />
* [[Web_Service_Toolkit|Web Services Toolkit]] - Web Services authoring and consumption<br />
<br />
===Databases===<br />
* [[fb embedded2 Laz]] - Using an embedded FireBird 2.0.3 server with Lazarus by including the Firebird DLLs as a resource.<br />
* [[TPSQL]] - Components for connecting to PostgreSQL database servers<br />
* [[tiOPF]] - TechInsite Object Persistent Framework (Ver. 2)<br />
* [[TParadoxDataSet]] - An TDataSet implementation that can read Paradox files up to Version 7 (and up ??)<br />
* [[ZeosDBO]] - Component for connecting to multiple database (Firebird, PostgreSQL, MySQL, Oracle)<br />
* [[SQLitePass]] - Components for connecting to SQLite database<br />
* [[MS Access]] - Procedure using TODBCConnection with FILEDSN<br />
* [[IBX]] - Component for direct connecting to FirebirdSQL<br />
* [[ZMSQL]] - TBufDataset SQL enhanced in-memory database, storing data as delimited text files<br />
<br />
===File formats===<br />
* [[CsvDocument]] - CSV files handling using parser or cell-based API similar to one of StringGrid component.<br />
* [[FPSpreadsheet]] - A library for handling spreadsheet files. Supports the formats from MS Excel and OpenOffice.<br />
<br />
===Containers===<br />
* [[StringHashMap]] - String -> Pointer associative map container. Fast and memory efficient.<br />
<br />
===System===<br />
* [[EpikTimer]] - Precision timer component written specifically for Lazarus.<br />
* [[Manager Worker Threads System]] - Manager Worker Thread system to process simultaneous data objects in real-time.<br />
* [[TrayIcon]] - A multiplatform System Tray component<br />
* [[TPopupNotifier]] - How to use TPopupNotifier to show "balloon help".<br />
* [[MultiDoc]] - A component to write pseudo-MDI application with Lazarus.<br />
* [[MDButtonsBar]] - ButtonsBar to MultiDoc Component.<br />
* [[MPICH]] - Bindings for the MPI - Message Passing Interface. Distributed computing.<br />
* [[Bluetooth]] - Accessing Bluetooth devices.<br />
* [[FileAssociation]] - Register file associations for all Windows versions. This includes Default Programs feature for Vista+.<br />
<br />
===Visual components===<br />
* [[VirtualTreeview]] - A port of the fast virtual treeview from [http://www.soft-gems.net/index.php?option=com_content&task=view&id=12&Itemid=33 SoftGems]<br />
* [[VirtualDBTreeEx]] - Checking interface built with data with checking rules, inherits [[VirtualTreeview]]<br />
* [[Turbopower Visual PlanIt]] - A port of the Planner Components<br />
* [[RingChart and AnalogWatch]] - Another Elliptical Chart and an Analogic Watch for Lazarus and FPC<br />
* [[ColorBox]] - Color picker with preview<br />
* [[Spook's Panel Components]] - A collection of panel components<br />
* [[HistoryFiles]] - A component for store the recent files list into an .ini file and show the result into a menu.<br />
* [[ColorPalette]] - A color palette grid with ability to use custom palette.<br />
* [[OrphPort]] - Subset of TurboPower's Orpheus controls.<br />
* [[TSubForm]] - A Data-Aware SubForm that replicates controls based on records in a dataset.<br />
* [[Lui Controls]] - A set of visual controls (TToggleLabel, TMenuButton)<br />
* [[uE Controls]] - A open source set of instrumentation controls for Lazarus and Free Pascal, compilable under Windows and Linux. <br />
* [[JvXPBar]] - A port of [http://jvcl.sourceforge.net JVCL's] TJvXPBar control that can display an icon, a header and zero or more clickable items in its client area.<br />
* [[Extended]] - A last level visual components package, which can manage a management software linked to data.<br />
* [[CmdLine]] - A Prompt as VCL Control.<br />
* [[Wile64]] - Components for Lazarus (TGifAnim, TColorProgress, TLabelCut...)<br />
* [[TGradButton]] - A new good looking Button Component<br />
* [[BGRAControls]] - Components which are using the power of the [[BGRABitmap]] package. BGRAImageList, BGRASpeedButton, BGRAButton, BGRAPanel.<br />
* [[TMyRollOut and ExpandPanel]] - A collapsable panel with a button (like TJvRollOut); these panels can be arranged with "Expandpanel"<br />
* [[FileMenuHandler]] - Handles Recent files list and Open, Save, Save As, Exit Commands.<br />
* [[THtmlPort]] - Lazarus port of Dave Baldwin's HTML Components (THtmlViewer, TFrameViewer, TFrameBrowser).<br />
* [[GeckoPort]] - Lazarus port of Takanori Ito's Gecko SDK for Delphi, including TGeckoBrowser.<br />
* [[ZVDateTimeControls Package]] - This package contains TZVDateTimePicker (the clone of Delphi's TDateTimePicker) and TDBZVDatePicker (a data aware version of TZVDateTimePicker).<br />
* [[jujiboutils]] - Set of components to input and validate different kinds of data, floats, dates, etc.<br />
<br />
=== Lazarus IDE Extensions === <br />
* [[Manual Docker]] - The extension allows Messages window to dock to the source editor.<br />
<br />
=== Hardware Access === <br />
* [http://forum.lazarus.freepascal.org/index.php/topic,7894.0.html NIDAQmxBase] - Unit for using National Instruments data acquisition devices through the NI DAQmx Base library (not the bigger NI DAQmx library).<br />
<br />
==Packages/Programs for FPC/Lazarus (not hosted here)==<br />
* [[5dpo]] (5dpo Component Library - Sdpo) is a set of components released by the 5dpo Robotic Soccer Team.<br />
* [http://audorra.sourceforge.net/ Audorra] is a digital audio library for Delphi and Freepascal.<br />
* [http://www.bpdx.com/ Brain Patchwork DX, LLC.] has ported their TCP/UDP Client and Server Components to Lazarus 0.9.22/FPC 2.0.4 - visual and non-visual implementation are supported (www.bpdx.com)<br />
* [[Castle Game Engine]], a 3D game engine especially focused on VRML/X3D formats.<br />
* [http://cups4lazarus.sourceforge.net/ CUPS for Lazarus project] Common UNIX Printing System for FPC/Lazarus.<br />
* [http://www.benibela.de/sources_en.html#diagram Diagram] a unit to draw a diagram using a model/view system<br />
* [[DelphiWebScript]] Object-oriented scripting engine based on Object pascal language.<br />
* [http://www.tcoq.org/composants DrawObjectsExtended] a graphical component ported from Delphi to draw structured diagrams.<br />
* [http://www.tcoq.org/composants ExcelInterfaces], a component to interface FPC and Lazarus programs with the Excel spreadsheet tool. It also demonstrates the use of COM interfaces on the Windows platform <br />
* [https://bitbucket.org/reiniero/fpctwit fpctwit] FreePascal OAuth v1 library using Synapse. Sample FPC plurk, twitter clients. Sample Lazarus twitter client.<br />
* [http://sourceforge.net/projects/fibl/ FIBL] FreeIBComponents package porting for Lazarus.<br />
* [http://breakoutbox.de/pascal/applications.html FreeImage] is an Open Source library project which supports popular graphics image formats like PNG, BMP, JPEG, TIFF and others (works with Windows, Linux and Mac OS X). PicViewer is a Example Application (Windows only) and shows basic usage of this DLL.<br />
* [http://fundementals.sourceforge.net/ Fundamentals Code Library] includes libraries for Unicode, Strings, Data Structures, Sockets and Mathematics.<br />
* [https://github.com/mdbs99/Greyhound Greyhound Project] is a tiny ORM-ish for FreePascal. You can use SQLdb, Zeos or whatever you want to connect to a DBMS.<br />
* [http://www.icu4pas.org/ ICU4PAS] is an Object Pascal, cross platform, Direct Class Wrapper over the ICU libraries. ICU is a mature, widely used set of C/C++ and Java libraries providing Unicode and Globalization support for software applications.<br />
* Indy <br />
** Original (now dormant) effort: [http://indy4lazarus.sourceforge.net/ Indy for Lazarus project] 119 components Indy for FPC/Lazarus. <br />
** Newer attempt [[Indy with Lazarus]] (Both Indy9 and Indy10)<br />
* [http://sourceforge.net/projects/rtcsdk/ RealThinClient SDK] - components for building stable HTTP(S) Clients, Servers, Routers, Proxies, Load Balancers and ISAPIs with Delphi/Lazarus.<br />
* [http://www.benibela.de/sources_en.html#internettools Internet Tools] are a set of units for webpage processing: There is a html/xml parser with sax/dom-like interface, XPath 2 / XQuery expressions engine, CSS 3 selectors, templates with xml pattern-matching and a http/s connection wrapper (around synapse and wininet) <br />
* http://ioda.sourceforge.net/index.html ioda is a fulltext search database: a word indexing and retrieving engine. It stores unique words from a file or database source in a btree and their repeaters in an flexible and highly space optimized list structure. Each stored word "knews" its source, position in the source and some (optional) info bytes. (writen in FPC)<br />
* [https://sourceforge.net/projects/jedi-sdl/ JEDI-SDL] : Pascal headers for SDL<br />
* [http://code.google.com/p/lazarus-zlib/ lazarus-zlib] - library, contains simple functions for work with zlib-archives (it uses the original zlib source, compiled in obj-files).<br />
* [http://www.breakoutbox.de/pascal/pascal.html#LibSndFile LibSndFile.dll] is a C library for reading and writing files containing sampled sound (such as MS Windows WAV and the Apple/SGI AIFF format) through one standard library interface. The download also contains a GUI demo application written under Windows.<br />
* [http://www.breakoutbox.de/pascal/pascal.html#mpg123 mpg123.dll] is a MPEG 1.0/2.0/2.5 decoder DLL for layers 1,2 and 3. The MPEG 1.0 layer 3 aka MP3 is most commonly tested. The Library itself is available for Linux, MacOSX, FreeBSD, SunOS4.1.3, Solaris 2.5, HPUX 9.x, SGI Irix and Cygwin or plain MS Windows. Cross-platform compatible source code should be possible in LAZARUS as soon as the wrapper file for portaudio.DLL is tested by Linux and Mac owners. The example code contains two wrapper files, tested under Windows 32bit only.<br />
* [https://www.birtles.org.uk/programming/ Pascal LZMA SDK]<br />
* [https://bitbucket.org/reiniero/notepad-pluginlazarus Notepad++ plugin template for Lazarus]: a demo template that should get you started quickly with writing your own plugin for the free (Windows only) Notepad++ text editor. Ported from the existing Delphi template.<br />
* [http://wiki.lazarus.freepascal.org/PascalSCADA PascalSCADA] is a set of components to make easy the development of HMI/SCADA applications (applications that needs interact with PLC's and others industrial devices).<br />
* [http://www.breakoutbox.de/pascal/pascal.html#PortAudio PortAudio] project is a portable cross-platform Audio API currently available for Windows, Macintosh OS X, Unix (OSS/ALSA), SGI, and BeOS. It allows cross-platform compatible source code also in LAZARUS. The download contains the wrapper file that makes the C Library available and also example applications showing how to use the PortAudio DLL under Lazarus LCL / Windows. The wrapper file for portaudio.DLL is from the UltraStar Sourceforge project.<br />
* [http://sourceforge.net/projects/qxotica/ qxotica] - tools for creating qooxdoo Web apps. Develop both the JavaScript qooxdoo-based client and the Pascal server app in Lazarus.<br />
* [[RackCtls]] a collection of components with an "Hi-fi system" appearance.<br />
* [http://tcoq.free.fr/composants.html Runge-Kutta] a scientific component to integrate partial differential equations, using events.<br />
* Starting with version 32, Lucas Gebauer's outstanding [http://www.ararat.cz/synapse/ Synapse] TCP/IP library is now compatible with Free Pascal and Lazarus. Lucas has also just released version 12 of his Synaser serial port communications suite that also runs under Free Pascal.<br />
* [https://github.com/rnapoles/Synedit-Port Synedit-Port] Synedit 2.0.5 port - SynEdit is an advanced multi-line edit control.<br />
* [http://www.benibela.de/components_en.html#treelistview TTreeListView] is the combination of a TTreeView with a TListView, showing items in a tree with columns<br />
* [http://sourceforge.net/projects/ultrastardx/ UltraStar Deluxe] has headers for the following libraries for Windows, Linux and Mac OS X (with a few exceptions):<br />
** portaudio<br />
** bass<br />
** ffmpeg<br />
** SDL<br />
** libpng<br />
** FreeImage<br />
** freetype<br />
** JEDI-SDL<br />
** Lua<br />
** midi<br />
** pcre<br />
** portmixer<br />
** projectM<br />
** samplerate<br />
** SQLite<br />
** zlib<br />
** fft<br />
<br />
==Commercial Packages for FPC/Lazarus==<br />
*TMS FlexCel Studio for VCL/LCL - http://www.tmssoftware.com/site/flexcel.asp - A Spreadsheet component<br />
*Devart PostgreSQL Data Access Components (PgDAC) - http://www.devart.com/pgdac/ - PostgreSQL Components that use native wire protocol no libpq needed.<br />
*Devart SecureBridge Components - http://www.devart.com/sbridge/ - SSH/SFTP/SSL components Easily create SSH tunnels and SFTP clients and much more.<br />
<br />
==Example programs==<br />
See also: <br />
* [[Page Of Code Sites]]: includes sites such as Rosetta Code, Torry and much more<br />
* [[:Category:Tutorials|Tutorials]]: tutorials for FPC/Lazarus<br />
<br />
Example programs:<br />
* [[SysRec]] - Video Capturing and Recording application, you can download it [http://sourceforge.net/project/showfiles.php?group_id=92177 here].<br />
* [[Micro-mainframe Transmission Command Generator for IBM Mainframes]]<br />
* [[Synapse]] - The Synapse page has an SSH/Telnet client unit and example program that demonstrates running commands on servers.<br />
* [[Sudoku]] - A Sudoku solver.<br />
* [[Libview]] - Views all exported function names of a given library.<br />
* [[Contacts Database]] - An expanded version of the address book example with reports.<br />
* [[OpenGL Tutorial]] - Example code for the OpenGL tutorial<br />
* [[Robot - The Game]] - Very easy written sample for beginners<br />
* [[Kaldemonia]] - Google Searcher shows simple threading, using Synapse networking library.<br />
* [[TSqlite3 Master Detail Example]] - Working Master Detail Example using 3 small tables and sqlite components.<br />
* [[JCSV (Jans CSV Components)]] - Working Example of TJansCSV Component Set<br />
* [[How To Use Interfaces to write less code]] - Working Example of Interfaces and generics.<br />
* [http://sourceforge.net/project/showfiles.php?group_id=240460 LRS_Explorer] - A little software to add some pictures, music, etc.. into a Lazarus resource (lrs) file.<br />
* [[Creating LCL Control From Libraries]] - Shows you how to create and manage LCL UI controls in an application from plug-ins (dll/so/dynlib).<br />
<br />
==RTL, FLC and LCL Usage examples==<br />
* [[Manager Worker Threads System]] - An example of how to design a Manager Worker Thread Application.<br />
* [[Dialog Examples]] - useful dialogs not found in the Component Palette<br />
* [[Howto Use TOpenDialog]] - How to use the FileOpen Dialog<br />
* [[Howto Use TSaveDialog]] - How to use the FileSave Dialog<br />
* [[ServiceManager]] - How to use the ServiceManager to handle running services<br />
<br />
==See Also==<br />
<br />
* [[Projects using Lazarus]]<br />
* [[FPC Applications/Projects Gallery]]<br />
* [[Operating Systems written in FPC]]<br />
* [[Using the Lazarus-ccr SVN repository]]<br />
<br />
[[Category:Promotion]]<br />
[[Category:Components]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=Windows_Programming_Tips&diff=65919Windows Programming Tips2013-02-15T23:44:51Z<p>Lainz: TFileAssociation component</p>
<hr />
<div>This page is dedicated to desktop Windows programming tips.<br />
<br />
__TOC__<br />
<br />
{{Other Interfaces}}<br />
<br />
==Articles about Windows Programming==<br />
*[[High DPI]] - How to make your application DPI-aware on Windows 7.<br />
*[[Aero Glass]] - How to apply Aero Glass effect in a Lazarus Form on Windows 7.<br />
*[[Windows Icon]] - How to design your icon with the right sizes.<br />
*[[Inno Setup Usage]] - How to create setup files with File Association support.<br />
<br />
==Windows specific compiler options==<br />
<br />
The most prominent options are the '''-W''' flags. A GUI application requires the '''-WG''' flag. See ''Project Options / Compiler Options / Linking / Target OS Specific options / Win32 GUI application''. No console is shown, '''writeln''' and '''readln''' are not possible, you will get '''File not open''' errors. Omitting this option creates a console application (same as passing -WC).<br />
<br />
==COM Programming==<br />
<br />
===Importing and using a COM library===<br />
<br />
The first step to import and use a COM library is generating the interface definitions from it. Use the program importtl which is located in Free Pascal in fpc/utils/importtl. A pre-compiled binary of this program can be found here: http://sourceforge.net/projects/p-tools/files/ImportTL/<br />
<br />
You can call it, for example for MSAA like this:<br />
<br />
importtl.exe C:\Windows\system32\oleacc.dll<br />
<br />
And it will generate the type library pascal unit Accessibility_1_1_TLB.pas in the folder where it is.<br />
<br />
===Creating a library which exports a COM object===<br />
<br />
ToDo: write me<br />
<br />
===Windows Sensor/Location API===<br />
Available since Windows 7. See [[LazDeviceAPIs#Possible_Windows_implementation]]<br />
<br />
==ActiveX controls==<br />
You can use ActiveX controls in recent Lazarus versions. See [[LazActiveX]]<br />
<br />
==Code snippets==<br />
<br />
===File Association===<br />
To add icons to file associations and register for use with a program use:<br />
[http://lazarus.freepascal.org/index.php/topic,19941.0.html TFileAssociation Component]<br />
<br />
===Listing all available drives===<br />
<br />
<syntaxhighlight><br />
program listdevices;<br />
<br />
{$ifdef fpc}{$mode delphi}{$endif}<br />
{$apptype console}<br />
<br />
uses<br />
Windows;<br />
<br />
var<br />
Drive: Char;<br />
DriveLetter: string;<br />
begin<br />
WriteLn('The following drives were found in this computer:');<br />
WriteLn('');<br />
<br />
// Search all drive letters<br />
for Drive := 'A' to 'Z' do<br />
begin<br />
DriveLetter := Drive + ':\';<br />
<br />
case GetDriveType(PChar(DriveLetter)) of<br />
DRIVE_REMOVABLE: WriteLn(DriveLetter + ' Floppy Drive');<br />
DRIVE_FIXED: WriteLn(DriveLetter + ' Fixed Drive');<br />
DRIVE_REMOTE: WriteLn(DriveLetter + ' Network Drive');<br />
DRIVE_CDROM: WriteLn(DriveLetter + ' CD-ROM Drive');<br />
DRIVE_RAMDISK: WriteLn(DriveLetter + ' RAM Disk');<br />
end;<br />
end;<br />
<br />
// Also add a stop to see the result under Windows<br />
WriteLn('');<br />
WriteLn('Please press <ENTER> to exit the program.');<br />
ReadLn(DriveLetter);<br />
end.<br />
</syntaxhighlight><br />
<br />
===Creating a shortcut (.lnk) file===<br />
Creating a shortcut on the desktop (can be easily adapted to any location). Adapted from [http://www.mail-archive.com/fpc-pascal@lists.freepascal.org/msg13325.html post by Felipe Monteiro de Carvalho]<br />
The ISLink object has more methods that you can use to modify your shortcut...<br />
<br />
<syntaxhighlight><br />
uses<br />
...<br />
windows, shlobj {for special folders}, ActiveX, ComObj;<br />
...<br />
procedure CreateDesktopShortCut(Target, TargetArguments, ShortcutName: string);<br />
var<br />
IObject: IUnknown;<br />
ISLink: IShellLink;<br />
IPFile: IPersistFile;<br />
PIDL: PItemIDList;<br />
InFolder: array[0..MAX_PATH] of Char;<br />
TargetName: String;<br />
LinkName: WideString;<br />
begin<br />
{ Creates an instance of IShellLink }<br />
IObject := CreateComObject(CLSID_ShellLink);<br />
ISLink := IObject as IShellLink;<br />
IPFile := IObject as IPersistFile;<br />
<br />
ISLink.SetPath(pChar(Target));<br />
ISLink.SetArguments(pChar(TargetArguments));<br />
ISLink.SetWorkingDirectory(pChar(ExtractFilePath(Target)));<br />
<br />
{ Get the desktop location }<br />
SHGetSpecialFolderLocation(0, CSIDL_DESKTOPDIRECTORY, PIDL);<br />
SHGetPathFromIDList(PIDL, InFolder);<br />
LinkName := InFolder + PathDelim + ShortcutName+'.lnk';<br />
<br />
{ Create the link }<br />
IPFile.Save(PWChar(LinkName), false);<br />
end;<br />
<br />
</syntaxhighlight><br />
<br />
===Getting special folders (My documents, Desktop, local application data, etc)===<br />
Often it is useful to get the location of a special folder such as the desktop. The example below shows how you can get the LocalAppData directory - where the Lazarus installer stores its configuration by default.<br />
Look in the [http://delphi-miranda-plugins.googlecode.com/svn-history/r105/trunk/FPC/units/src/shlobj.pp shlobj] unit for more defines that let you look up the Desktop, Recycle Bin, etc.<br />
<syntaxhighlight><br />
uses <br />
...<br />
shlobj;<br />
<br />
var<br />
AppDataPath: Array[0..MaxPathLen] of Char; //Allocate memory<br />
...<br />
begin<br />
...<br />
AppDataPath:='';<br />
SHGetSpecialFolderPath(0,AppDataPath,CSIDL_LOCAL_APPDATA,false);<br />
writeln('Your local appdata path is: ' + AppDataPath);<br />
</syntaxhighlight><br />
<br />
===Enabling and disabling devices===<br />
The following code can be used to enable and disable Windows devices; it is useful to e.g. reset a serial port or USB device.<br />
An example program follows below.<br />
<syntaxhighlight><br />
unit controlwindevice;<br />
<br />
{ Enable Disable windows devices<br />
<br />
Copyright (c) 2010-2012 Ludo Brands<br />
<br />
Permission is hereby granted, free of charge, to any person obtaining a copy<br />
of this software and associated documentation files (the "Software"), to<br />
deal in the Software without restriction, including without limitation the<br />
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or<br />
sell copies of the Software, and to permit persons to whom the Software is<br />
furnished to do so, subject to the following conditions:<br />
<br />
The above copyright notice and this permission notice shall be included in<br />
all copies or substantial portions of the Software.<br />
<br />
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br />
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br />
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE<br />
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br />
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br />
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br />
IN THE SOFTWARE.<br />
}<br />
<br />
<br />
{$mode delphi}{$H+}<br />
<br />
interface<br />
<br />
uses<br />
Classes, SysUtils,dynlibs,windows;<br />
<br />
const<br />
GUID_DEVCLASS_NET : TGUID = '{4D36E972-E325-11CE-BFC1-08002BE10318}';<br />
GUID_DEVCLASS_PORT : TGUID = '{4D36E978-E325-11CE-BFC1-08002BE10318}';<br />
<br />
type<br />
TDeviceControlResult=(DCROK,DCRErrEnumDeviceInfo,DCRErrSetClassInstallParams,<br />
DCRErrDIF_PROPERTYCHANGE);<br />
<br />
function LoadDevices(GUID_DevClass:TGUID):TStringList;<br />
function EnableDevice(SelectedItem: DWord):TDeviceControlResult;<br />
function DisableDevice(SelectedItem: DWord):TDeviceControlResult;<br />
<br />
implementation<br />
<br />
// Setup api, based on SetupApi.pas JEDI library<br />
const<br />
DIF_PROPERTYCHANGE = $00000012;<br />
DICS_ENABLE = $00000001;<br />
DICS_DISABLE = $00000002;<br />
DICS_FLAG_GLOBAL = $00000001; // make change in all hardware profiles<br />
DIGCF_PRESENT = $00000002;<br />
SPDRP_DEVICEDESC = $00000000; // DeviceDesc (R/W)<br />
SPDRP_CLASS = $00000007; // Class (R--tied to ClassGUID)<br />
SPDRP_CLASSGUID = $00000008; // ClassGUID (R/W)<br />
SPDRP_FRIENDLYNAME = $0000000C; // FriendlyName (R/W)<br />
<br />
type<br />
HDEVINFO = Pointer;<br />
DI_FUNCTION = LongWord; // Function type for device installer<br />
<br />
PSPClassInstallHeader = ^TSPClassInstallHeader;<br />
SP_CLASSINSTALL_HEADER = packed record<br />
cbSize: DWORD;<br />
InstallFunction: DI_FUNCTION;<br />
end;<br />
TSPClassInstallHeader = SP_CLASSINSTALL_HEADER;<br />
<br />
PSPPropChangeParams = ^TSPPropChangeParams;<br />
SP_PROPCHANGE_PARAMS = packed record<br />
ClassInstallHeader: TSPClassInstallHeader;<br />
StateChange: DWORD;<br />
Scope: DWORD;<br />
HwProfile: DWORD;<br />
end;<br />
TSPPropChangeParams = SP_PROPCHANGE_PARAMS;<br />
<br />
PSPDevInfoData = ^TSPDevInfoData;<br />
SP_DEVINFO_DATA = packed record<br />
cbSize: DWORD;<br />
ClassGuid: TGUID;<br />
DevInst: DWORD; // DEVINST handle<br />
Reserved: ULONG_PTR;<br />
end;<br />
TSPDevInfoData = SP_DEVINFO_DATA;<br />
<br />
TSetupDiEnumDeviceInfo = function(DeviceInfoSet: HDEVINFO;<br />
MemberIndex: DWORD; var DeviceInfoData: TSPDevInfoData): LongBool; stdcall;<br />
TSetupDiSetClassInstallParamsA = function(DeviceInfoSet: HDEVINFO;<br />
DeviceInfoData: PSPDevInfoData; ClassInstallParams: PSPClassInstallHeader;<br />
ClassInstallParamsSize: DWORD): LongBool; stdcall;<br />
TSetupDiSetClassInstallParamsW = function(DeviceInfoSet: HDEVINFO;<br />
DeviceInfoData: PSPDevInfoData; ClassInstallParams: PSPClassInstallHeader;<br />
ClassInstallParamsSize: DWORD): LongBool; stdcall;<br />
TSetupDiSetClassInstallParams = TSetupDiSetClassInstallParamsA;<br />
TSetupDiCallClassInstaller = function(InstallFunction: DI_FUNCTION;<br />
DeviceInfoSet: HDEVINFO; DeviceInfoData: PSPDevInfoData): LongBool; stdcall;<br />
TSetupDiGetClassDevs = function(ClassGuid: PGUID; const Enumerator: PAnsiChar;<br />
hwndParent: HWND; Flags: DWORD): HDEVINFO; stdcall;<br />
TSetupDiGetDeviceRegistryPropertyA = function(DeviceInfoSet: HDEVINFO;<br />
const DeviceInfoData: TSPDevInfoData; Property_: DWORD;<br />
var PropertyRegDataType: DWORD; PropertyBuffer: PBYTE; PropertyBufferSize: DWORD;<br />
var RequiredSize: DWORD): BOOL; stdcall;<br />
TSetupDiGetDeviceRegistryPropertyW = function(DeviceInfoSet: HDEVINFO;<br />
const DeviceInfoData: TSPDevInfoData; Property_: DWORD;<br />
var PropertyRegDataType: DWORD; PropertyBuffer: PBYTE; PropertyBufferSize: DWORD;<br />
var RequiredSize: DWORD): BOOL; stdcall;<br />
TSetupDiGetDeviceRegistryProperty = TSetupDiGetDeviceRegistryPropertyA;<br />
<br />
var<br />
DevInfo: hDevInfo;<br />
SetupDiEnumDeviceInfo: TSetupDiEnumDeviceInfo;<br />
SetupDiSetClassInstallParams: TSetupDiSetClassInstallParams;<br />
SetupDiCallClassInstaller: TSetupDiCallClassInstaller;<br />
SetupDiGetClassDevs: TSetupDiGetClassDevs;<br />
SetupDiGetDeviceRegistryProperty: TSetupDiGetDeviceRegistryProperty;<br />
<br />
var<br />
SetupApiLoadCount:integer=0;<br />
<br />
function LoadSetupApi: Boolean;<br />
var SetupApiLib:TLibHandle;<br />
begin<br />
Result := True;<br />
Inc(SetupApiLoadCount);<br />
if SetupApiLoadCount > 1 then<br />
Exit;<br />
SetupApiLib:=LoadLibrary('SetupApi.dll');<br />
Result := SetupApiLib<>0;<br />
if Result then<br />
begin<br />
SetupDiEnumDeviceInfo := GetProcedureAddress(SetupApiLib, 'SetupDiEnumDeviceInfo');<br />
SetupDiSetClassInstallParams := GetProcedureAddress(SetupApiLib, 'SetupDiSetClassInstallParamsA');<br />
SetupDiCallClassInstaller := GetProcedureAddress(SetupApiLib, 'SetupDiCallClassInstaller');<br />
SetupDiGetClassDevs := GetProcedureAddress(SetupApiLib, 'SetupDiGetClassDevsA');<br />
SetupDiGetDeviceRegistryProperty := GetProcedureAddress(SetupApiLib, 'SetupDiGetDeviceRegistryPropertyA');<br />
end;<br />
end;<br />
<br />
// implementation<br />
<br />
function StateChange(NewState, SelectedItem: DWord;<br />
hDevInfo: hDevInfo): TDeviceControlResult;<br />
var<br />
PropChangeParams: TSPPropChangeParams;<br />
DeviceInfoData: TSPDevInfoData;<br />
begin<br />
PropChangeParams.ClassInstallHeader.cbSize := SizeOf(TSPClassInstallHeader);<br />
DeviceInfoData.cbSize := SizeOf(TSPDevInfoData);<br />
// Get a handle to the Selected Item.<br />
if (not SetupDiEnumDeviceInfo(hDevInfo, SelectedItem, DeviceInfoData)) then<br />
begin<br />
Result := DCRErrEnumDeviceInfo;<br />
exit;<br />
end;<br />
// Set the PropChangeParams structure.<br />
PropChangeParams.ClassInstallHeader.InstallFunction := DIF_PROPERTYCHANGE;<br />
PropChangeParams.Scope := DICS_FLAG_GLOBAL;<br />
PropChangeParams.StateChange := NewState;<br />
if (not SetupDiSetClassInstallParams(hDevInfo, @DeviceInfoData,<br />
PSPClassInstallHeader(@PropChangeParams), SizeOf(PropChangeParams))) then<br />
begin<br />
Result := DCRErrSetClassInstallParams;<br />
exit;<br />
end;<br />
// Call the ClassInstaller and perform the change.<br />
if (not SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, hDevInfo, @DeviceInfoData)) then<br />
begin<br />
Result := DCRErrDIF_PROPERTYCHANGE;<br />
exit;<br />
end;<br />
Result := DCROK;<br />
end;<br />
<br />
function GetRegistryProperty(PnPHandle: HDEVINFO;<br />
DevData: TSPDevInfoData; Prop: DWORD; Buffer: PChar;<br />
dwLength: DWord): Boolean;<br />
var<br />
aBuffer: array[0..256] of Char;<br />
begin<br />
dwLength := 0;<br />
aBuffer[0] := #0;<br />
SetupDiGetDeviceRegistryProperty(PnPHandle, DevData, Prop, Prop, PBYTE(@aBuffer[0]), SizeOf(aBuffer), dwLength);<br />
StrCopy(Buffer, aBuffer);<br />
Result := Buffer^ <> #0;<br />
end;<br />
<br />
function ConstructDeviceName(DeviceInfoSet: hDevInfo;<br />
DeviceInfoData: TSPDevInfoData; Buffer: PChar; dwLength: DWord): Boolean;<br />
const<br />
UnknownDevice = '<Unknown Device>';<br />
begin<br />
if (not GetRegistryProperty(DeviceInfoSet, DeviceInfoData, SPDRP_FRIENDLYNAME, Buffer, dwLength)) then<br />
begin<br />
if (not GetRegistryProperty(DeviceInfoSet, DeviceInfoData, SPDRP_DEVICEDESC, Buffer, dwLength)) then<br />
begin<br />
if (not GetRegistryProperty(DeviceInfoSet, DeviceInfoData, SPDRP_CLASS, Buffer, dwLength)) then<br />
begin<br />
if (not GetRegistryProperty(DeviceInfoSet, DeviceInfoData, SPDRP_CLASSGUID, Buffer, dwLength)) then<br />
begin<br />
dwLength := DWord(SizeOf(UnknownDevice));<br />
Buffer := Pointer(LocalAlloc(LPTR, Cardinal(dwLength)));<br />
StrCopy(Buffer, UnknownDevice);<br />
end;<br />
end;<br />
end;<br />
end;<br />
Result := true;<br />
end;<br />
<br />
<br />
function LoadDevices(GUID_DevClass:TGUID):TStringList;<br />
var<br />
DeviceInfoData: TSPDevInfoData;<br />
i: DWord;<br />
pszText: PChar;<br />
<br />
begin<br />
if (not LoadSetupAPI) then<br />
begin<br />
result:=nil;<br />
exit;<br />
end;<br />
DevInfo := nil;<br />
// Get a handle to all devices in all classes present on system<br />
DevInfo := SetupDiGetClassDevs(@GUID_DevClass, nil, 0, DIGCF_PRESENT);<br />
if (DevInfo = Pointer(INVALID_HANDLE_VALUE)) then<br />
begin<br />
result:=nil;<br />
exit;<br />
end;<br />
Result:=TStringList.Create;<br />
DeviceInfoData.cbSize := SizeOf(TSPDevInfoData);<br />
i := 0;<br />
// Enumerate though all the devices.<br />
while SetupDiEnumDeviceInfo(DevInfo, i, DeviceInfoData) do<br />
begin<br />
GetMem(pszText, 256);<br />
try<br />
// Get a friendly name for the device.<br />
ConstructDeviceName(DevInfo, DeviceInfoData, pszText, DWord(nil));<br />
Result.AddObject(pszText,Tobject(i));<br />
finally<br />
FreeMem(pszText);<br />
inc(i);<br />
end;<br />
end;<br />
end;<br />
<br />
function EnableDevice(SelectedItem: DWord):TDeviceControlResult;<br />
<br />
begin<br />
result:=StateChange(DICS_ENABLE, SelectedItem , DevInfo);<br />
end;<br />
<br />
function DisableDevice(SelectedItem: DWord):TDeviceControlResult;<br />
<br />
begin<br />
result:=StateChange(DICS_DISABLE, SelectedItem , DevInfo);<br />
end;<br />
<br />
end.<br />
</syntaxhighlight><br />
<br />
Example program that lists all ports preceeded by a number. <br />
<br />
Enter a number and the port will be disabled. Enter return again and the port will be enabled again.<br />
<syntaxhighlight><br />
program devicetest;<br />
<br />
{$mode delphi}{$H+}<br />
<br />
uses<br />
Classes, controlwindevice;<br />
var<br />
sl:tstringlist;<br />
i:integer;<br />
begin<br />
sl:=Loaddevices(GUID_DEVCLASS_PORT);<br />
for i:=0 to sl.count-1 do<br />
writeln(i,' : ',sl[i]);<br />
readln(i);<br />
if DisableDevice(i)=DCROK then<br />
writeln(sl[i],' disabled');<br />
readln;<br />
if EnableDevice(i)=DCROK then<br />
writeln(sl[i],' enabled');<br />
sl.Free;<br />
readln;<br />
end.<br />
</syntaxhighlight><br />
<br />
===Downloading a file using urlmon===<br />
Urlmon.dll is built into Windows and can be used to e.g. download a file from a web site. It supports SSL/TLS connections.<br />
<br />
Windows-only; please look into libraries like [[Synapse]] and [[Indy]] for cross-platform solutions.<br />
<syntaxhighlight><br />
function URLDownloadToFile(pCaller: pointer; URL: PChar; FileName: PChar; Reserved: DWORD; lpfnCB : pointer): HResult; stdcall; external 'urlmon.dll' name 'URLDownloadToFileA';<br />
<br />
procedure TForm1.Button1Click(Sender: TObject);<br />
var Source, Dest: string;<br />
begin<br />
Source:='http://lazarus.freepascal.org';<br />
Dest:='C:\Windows\temp\data.txt';<br />
if URLDownloadToFile(nil, PChar(Source), PChar(Dest), 0, nil)=0 then<br />
showmessage('Download ok!')<br />
else<br />
showMessage('Error downloading '+Source);<br />
end;<br />
</syntaxhighlight><br />
<br />
[[category:Example programs]]<br />
[[category:Lazarus]]<br />
[[category:FPC]]<br />
[[Category:Operating Systems and Platforms]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=High_DPI&diff=64278High DPI2012-11-28T19:23:49Z<p>Lainz: /* Example - Using AutoSize */</p>
<hr />
<div>{{High DPI}}<br />
<br />
== Introduction ==<br />
DPI (dots per inch) is the relation between size in pixels and the actual display size. Here dot is an equivalent for pixel in printing terminology. Applications can either use pixel sizes, or take into account the actual display size. In this second case, sizes are given in points.<br />
<br />
On Windows 95 and later, it is possible to change the DPI ratio to make elements bigger. High DPI means any custom DPI setting with more than 96 DPI (the default setting) [http://msdn.microsoft.com/en-us/library/ee318406(VS.85).aspx *].<br />
<br />
High DPI awareness means that an application takes this DPI setting into account. This article was designed for Windows 7. For Windows 8 Metro Applications read this http://blogs.msdn.com/b/b8/archive/2012/03/21/scaling-to-different-screens.aspx<br />
<br />
'''Pixels and points'''<br />
<br />
For example '''300 DPI''' means that there are 300 pixels (or dots) per inch. There are 72 points per inch, so :<br />
<br />
300 pixels ↔ 1 inch<br />
<br />
300/72 pixels ↔ 1 point<br />
<br />
4.16 pixels ↔ 1 point<br />
<br />
'''Now with 96 DPI :'''<br />
<br />
72 pixels ↔ 1 inch<br />
<br />
1.33 pixel ↔ 1 point<br />
<br />
'''Now with 144 DPI :'''<br />
<br />
144 pixels ↔ 1 inch<br />
<br />
2 pixels ↔ 1 point<br />
<br />
== Example - Fixed Font Sizes (not HighDPI) ==<br />
<br />
Here is a form with an undefined font size (set to zero, which is the default value). It has been designed at 96 DPI (100%), and it looks like this :<br />
<br />
[[Image:Testdpi100.png]]<br />
<br />
Now, at 120 DPI (125%), it becomes :<br />
<br />
[[Image:Testdpi125.png]]<br />
<br />
As you can see, the font gets bigger and so the text is clipped. The window title gets bigger, but the client area of the window remains the same size. Note that these changes in size can occur by using an application with a different Windows theme, or with another operating system.<br />
<br />
To avoid this, you must set the font size to a non-zero value. Note that Font.Size is expressed in points and Font.Height is expressed in pixels. In fact, only the value of Font.Height is stored, and Font.Size changes according to current DPI value. So if we set the font size, it will be fixed to a certain size in pixels.<br />
<br />
If we try again with a fixed font size of 9 points, then at 96 DPI (100%), we get this :<br />
<br />
[[Image:Testdpi100fixedM12P9.png]]<br />
<br />
Now if the same program is run at 120 DPI (125%), it becomes :<br />
<br />
[[Image:Testdpi125fixedM12P9.png]]<br />
<br />
The result is the almost the same. The title bar is bigger, but the client area and the font size is the same. Note that in fact, the size in points of the font has changed.<br />
<br />
The conclusion from this is that it is possible to avoid inconsistency in the display by fixing font sizes. But we do not take into account that the graphical elements may be smaller according to actual DPI of the screen. With DPI awareness, it is possible to make an application behave as if it knew the real size of the pixels.<br />
<br />
== Setting High DPI under Windows ==<br />
<br />
'''Windows Vista / Windows 7'''<br />
<br />
In Windows 7 go to Control Panel > Appearance and Personalization > Display (or just Control Panel > Display in recent updates).<br />
<br />
Select Smaller 100% (default), Medium 125% or Larger 150%. If you select 100% (96 DPI) this is the default Windows DPI setting, (High DPI is not the default).<br />
<br />
If you select 125% (120 DPI) the option "Use Windows XP style DPI scaling" is enabled. Applications you run under this setting are scaled as if running under Windows XP.<br />
<br />
If you select 150% (144 DPI) the option "Use Windows XP style DPI scaling" is disabled (DPI Virtualization is enabled), and applications you run under this setting must be High DPI Awareness to prevent system scaling which will produce a blurred image.<br />
<br />
You can also set your custom DPI setting via the option "Set custom text size (DPI)" and enable/disable the DPI Virtualization.<br />
<br />
== Example - DPI Aware Application (For Vista +) ==<br />
<br />
[http://sourceforge.net/projects/cpicksniff2/ CPickSniff] is an application to capture screen colors. We will use it as an example to see how High DPI works in Windows.<br />
<br />
'''Default DPI'''<br />
<br />
This is the app running at 96 DPI (100%). It's the default mode, when scaling isn't necessary.<br />
<br />
[[Image:cpicksniff_defaultdpi.png]]<br />
<br />
'''Windows DPI Scaling'''<br />
<br />
This is same app running at 144 DPI (150%) without a manifest, so Windows scales it like a bitmap. The result is a blurred image.<br />
<br />
[[Image:cpicksniff_blured.png]]<br />
<br />
'''With Manifest'''<br />
<br />
Running at 144 DPI (150%). This time the app includes a manifest but the application contains no code to handle scaling. Items aren't scaled whereas fonts are scaled (Windows does this automatically), so text is clipped.<br />
<br />
[[Image:cpicksniff_nohighdpi.png]]<br />
<br />
'''High DPI'''<br />
<br />
Finally with both a manifest and a coded scaling handler, the app is in High DPI.<br />
<br />
[[Image:cpicksniff_highdpi.png]]<br />
<br />
=== STEP 1 - Declare High DPI Awareness ===<br />
To do this we need a manifest file that includes the declaration, with Lazarus 0.9.30 we can do this by going to Options > Project Options > then selecting the options "Use Manifest to Enable Themes (Windows)" and "Dpi Aware application (for Vista +)".<br />
<br />
=== STEP 2 - Scale Forms and Controls ===<br />
To do this we can call ScaleDPI procedure in the OnCreate event of each form in your project.<br />
<br />
First copy the code below and save it to a text file "uscaledpi.pas":<br />
<br />
<syntaxhighlight>unit uscaledpi;<br />
<br />
{$mode objfpc}{$H+}<br />
<br />
interface<br />
<br />
uses<br />
Forms, Graphics, Controls;<br />
<br />
procedure HighDPI(FromDPI: integer);<br />
procedure ScaleDPI(Control: TControl; FromDPI: integer);<br />
<br />
implementation<br />
<br />
procedure HighDPI(FromDPI: integer);<br />
var<br />
i: integer;<br />
begin<br />
if Screen.PixelsPerInch = FromDPI then<br />
exit;<br />
<br />
for i := 0 to Screen.FormCount - 1 do<br />
ScaleDPI(Screen.Forms[i], FromDPI);<br />
end;<br />
<br />
procedure ScaleDPI(Control: TControl; FromDPI: integer);<br />
var<br />
i: integer;<br />
WinControl: TWinControl;<br />
begin<br />
if Screen.PixelsPerInch = FromDPI then<br />
exit;<br />
<br />
with Control do<br />
begin<br />
Left := ScaleX(Left, FromDPI);<br />
Top := ScaleY(Top, FromDPI);<br />
Width := ScaleX(Width, FromDPI);<br />
Height := ScaleY(Height, FromDPI);<br />
end;<br />
<br />
if Control is TWinControl then<br />
begin<br />
WinControl := TWinControl(Control);<br />
if WinControl.ControlCount = 0 then<br />
exit;<br />
for i := 0 to WinControl.ControlCount - 1 do<br />
ScaleDPI(WinControl.Controls[i], FromDPI);<br />
end;<br />
end;<br />
<br />
end.</syntaxhighlight><br />
<br />
Copy the "uscaledpi.pas" file to the main folder of your project:<br />
<br />
MyProject\uscaledpi.pas<br />
<br />
In the "uses" section of your project you need to add "uScaleDPI":<br />
<br />
<syntaxhighlight>unit form1;<br />
<br />
{$mode objfpc}{$H+}<br />
<br />
interface<br />
<br />
uses<br />
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,<br />
uScaleDPI; // This includes ScaleDPI procedure </syntaxhighlight><br />
<br />
The OnCreate event of each form calls the procedure in this way:<br />
<br />
<syntaxhighlight>procedure TForm1.FormCreate(Sender: TObject);<br />
begin<br />
ScaleDPI(Self,96); // 96 is the DPI you designed the Form1 <br />
end;</syntaxhighlight><br />
<br />
'''Scale All Forms'''<br />
<br />
You can resize all forms at once without having to touch each form's OnCreate event.<br />
In order to do this open your project source (typically the ''Project1''.lpr file) and add uScaleDPI in the uses clause.<br />
<br />
Then call the procedure ''HighDPI'' below the code that initializes the forms:<br />
<br />
<syntaxhighlight>begin<br />
RequireDerivedFormResource := True;<br />
Application.Initialize;<br />
Application.CreateForm(TForm1, Form1);<br />
Application.CreateForm(TForm2, Form2);<br />
Application.CreateForm(TForm3, Form3);<br />
HighDPI(96); // 96 is the DPI you designed the Form1, Form2 & Form3<br />
Application.Run;<br />
end.</syntaxhighlight><br />
<br />
The result looks like this:<br />
<br />
<syntaxhighlight>program Project1;<br />
<br />
{$mode objfpc}{$H+}<br />
<br />
uses<br />
{$IFDEF UNIX}{$IFDEF UseCThreads}<br />
cthreads,<br />
{$ENDIF}{$ENDIF}<br />
Interfaces, Forms,<br />
Unit1, Unit2, Unit3,<br />
uScaleDPI;<br />
<br />
{$R *.res}<br />
<br />
begin<br />
RequireDerivedFormResource := True;<br />
Application.Initialize;<br />
Application.CreateForm(TForm1, Form1);<br />
Application.CreateForm(TForm2, Form2);<br />
Application.CreateForm(TForm3, Form3);<br />
HighDPI(96);<br />
Application.Run;<br />
end.</syntaxhighlight><br />
<br />
'''Advanced'''<br />
<br />
Some controls have more properties or different property names like TToolBar buttons (ButtonHeight / ButtonWidth instead Width / Height). Also if you use fixed font sizes the behaviour can change in different OSs.<br />
<br />
You can edit the ScaleDPI procedure to include code to scale all controls in the way you want.<br />
<br />
This is the ''uscaledpi'' used in [[LazPaint]]. This is very useful for scaling ToolBars and ToolBox.<br />
<br />
This is not the final High DPI unit, for example you can use under Windows different LCL widgets, like Qt and this can change the final result.<br />
<br />
'''Link:''' [http://lazpaint.svn.sourceforge.net/viewvc/lazpaint/lazpaint/uscaledpi.pas?view=log uscaledpi.pas in LazPaint]<br />
<br />
== Example - Using AutoSize ==<br />
<br />
You can enable the 'AutoSize' option for each control you have (including Forms). Then test the effect under the different DPI modes, with different 'skinning' themes (if available in your target OS) and different font sizes. This can be very useful technique, and has been employed to solve several Lazarus IDE HighDPI issues.<br />
<br />
For example using the default AutoSize and ChildSizing most controls can be automatically sized and positioned. But the spacing must be scaled:<br />
<br />
<syntaxhighlight> with WinControl.ChildSizing do<br />
begin<br />
HorizontalSpacing := ScaleX(HorizontalSpacing, FromDPI);<br />
LeftRightSpacing := ScaleX(LeftRightSpacing, FromDPI);<br />
TopBottomSpacing := ScaleY(TopBottomSpacing, FromDPI);<br />
VerticalSpacing := ScaleY(VerticalSpacing, FromDPI);<br />
end; <br />
</syntaxhighlight><br />
<br />
For more information see:<br />
<br />
* [[Autosize / Layout]]<br />
* [[LCL AutoSizing]]<br />
<br />
The uscaledpi.pas with this additional code:<br />
<br />
<syntaxhighlight> unit uscaledpi;<br />
<br />
{$mode objfpc}{$H+}<br />
<br />
interface<br />
<br />
uses<br />
Forms, Graphics, Controls;<br />
<br />
procedure HighDPI(FromDPI: integer);<br />
procedure ScaleDPI(Control: TControl; FromDPI: integer);<br />
<br />
implementation<br />
<br />
procedure HighDPI(FromDPI: integer);<br />
var<br />
i: integer;<br />
begin<br />
if Screen.PixelsPerInch = FromDPI then<br />
exit;<br />
<br />
for i := 0 to Screen.FormCount - 1 do<br />
ScaleDPI(Screen.Forms[i], FromDPI);<br />
end;<br />
<br />
procedure ScaleDPI(Control: TControl; FromDPI: integer);<br />
var<br />
i: integer;<br />
WinControl: TWinControl;<br />
begin<br />
if Screen.PixelsPerInch = FromDPI then<br />
exit;<br />
<br />
with Control do<br />
begin<br />
Left := ScaleX(Left, FromDPI);<br />
Top := ScaleY(Top, FromDPI);<br />
Width := ScaleX(Width, FromDPI);<br />
Height := ScaleY(Height, FromDPI);<br />
end;<br />
<br />
if Control is TWinControl then<br />
begin<br />
WinControl := TWinControl(Control);<br />
if WinControl.ControlCount = 0 then<br />
exit;<br />
<br />
with WinControl.ChildSizing do<br />
begin<br />
HorizontalSpacing := ScaleX(HorizontalSpacing, FromDPI);<br />
LeftRightSpacing := ScaleX(LeftRightSpacing, FromDPI);<br />
TopBottomSpacing := ScaleY(TopBottomSpacing, FromDPI);<br />
VerticalSpacing := ScaleY(VerticalSpacing, FromDPI);<br />
end;<br />
<br />
for i := 0 to WinControl.ControlCount - 1 do<br />
ScaleDPI(WinControl.Controls[i], FromDPI);<br />
end;<br />
end;<br />
<br />
end.<br />
</syntaxhighlight><br />
<br />
== External Links ==<br />
<br />
*[http://msdn.microsoft.com/en-us/library/dd464646(v=VS.85).aspx High DPI (Windows)] MSDN article about High DPI<br />
*[http://msdn.microsoft.com/en-us/library/windows/apps/hh465362 Guidelines for scaling] Windows Dev Center - User experience guidelines for scaling Metro style apps<br />
*[[Windows Icon]] How to create icons that work with High DPI.<br />
<br />
[[Category:Tutorials]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=BGRAControls&diff=62905BGRAControls2012-10-19T00:34:46Z<p>Lainz: /* TBGRASliceScaling */</p>
<hr />
<div>{{BGRAControls}}<br />
<br />
== Install ==<br />
<br />
You can use TortoiseSVN to download the svn repository and TortoiseGIT to download the git repository.<br />
<br />
We're using BGRABitmap SVN to develop BGRAControls. Important changes in BGRABitmap can stop working BGRAControls.<br />
<br />
'''1) Download BGRABitmap'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/lazpaint/files/src/<br />
<br />
'''Latest SVN:''' svn co https://lazpaint.svn.sourceforge.net/svnroot/lazpaint lazpaint<br />
<br />
Install BGRABitmap with the file bgrabitmap.lpk<br />
<br />
'''2) Download BGRAControls'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/bgracontrols/files/<br />
<br />
''SVN''<br />
<br />
'''SVN Browse:''' http://bgracontrols.svn.sourceforge.net/viewvc/bgracontrols/<br />
<br />
'''SVN Checkout:''' svn co https://bgracontrols.svn.sourceforge.net/svnroot/bgracontrols bgracontrols<br />
<br />
''GIT''<br />
<br />
'''GIT Browse:''' http://bgracontrols.git.sourceforge.net/git/gitweb-index.cgi<br />
<br />
'''GIT Checkout:''' git://bgracontrols.git.sourceforge.net/gitroot/bgracontrols/bgracontrols <br />
<br />
Install BGRAControls with the file bgracontrols.lpk<br />
<br />
== Overview ==<br />
<br />
'''Authors:''' <br />
<br />
Dibo (package founder and maintainer, author: ''TBGRAImageList'', ''TBGRASpeedButton'', ''TBGRAButton'', ''TBGRAPanel'')<br />
<br />
Lainz (package maintainer, author: ''TBGRAImageButton'', ''TBGRAImageToggleBox'', ''TBGRASpriteAnimation'', ''TBGRALabelFX'', ''TBGRAWin7ToolBar'', ''TBGRANeoButton'', ''Windows 7 Drawer'' and some other stuff)<br />
<br />
Circular (package maintainer, author: ''TBGRAKnob'', ''TBGRAFlashProgressBar'', ''TBGRAVirtualScreen'', ''TBGRAShape'', ''TBGRAGraphicControl'')<br />
<br />
Emerson Cavalcanti (author: ''TBGRAImageManipulation'')<br />
<br />
codedeep (author: ''TBGRALabel'')<br />
<br />
'''License:''' Modified LGPL.<br />
<br />
As many people know, Lazarus GTK doesn't have full alpha support. I created a set of components which use TBGRABitmap for drawing icons, so it partially solves the problem with alpha in GTK. But this components set is not only a GTK patch but has more fancy components which are using the power of the BGRABitmap package.<br />
<br />
'''Screenshots:''' Some shots of the project 'testbgracontrols'.<br />
<br />
[[Image:testbgrac1.png]]<br />
<br />
''testbgracontrols > Main.''<br />
<br />
[[Image:testbgrac2.png]]<br />
<br />
''testbgracontrols > Windows 7 ToolBar.''<br />
<br />
[[Image:testbgrac4.png]]<br />
<br />
''testbgracontrols > Ribbon.''<br />
<br />
== Related Articles ==<br />
<br />
[[BGRAButton Gallery]] - Gallery of buttons with source code to use in your projects with BGRAButton.<br />
<br />
[[BGRASpriteAnimation]] - Usage of the sprite animation component.<br />
<br />
[[uE_Controls]] - Other controls developed with BGRABitmap.<br />
<br />
[[BGRABitmap]] - The library used to create this controls.<br />
<br />
[[LazPaint]] - A paint program developed with Lazarus and BGRABitmap.<br />
<br />
== Using ==<br />
<br />
Drop and use like normal component.<br />
<br />
'''Button''':<br />
* TBGRAButton<br />
* TBGRAImageButton<br />
* TBGRAImageToggleBox<br />
* TBGRASpeedButton<br />
<br />
'''Label'''<br />
* TBGRALabel<br />
* TBGRALabelFX<br />
<br />
'''Panel'''<br />
* TBGRAPanel<br />
* TBGRAVirtualScreen<br />
<br />
'''Image'''<br />
* TBGRAGraphicControl<br />
* TBGRAImageList<br />
* TBGRAImageManipulation<br />
* TBGRASpriteAnimation<br />
<br />
'''Other'''<br />
* TBGRAFlashProgressBar<br />
* TBGRAKnob<br />
* TBGRAShape<br />
* TBGRAWin7ToolBar<br />
<br />
== TBGRAImageList ==<br />
<br />
'''Use as replace of:''' TImageList<br />
<br />
'''Before:'''<br />
<br />
[[Image:before-TImageList.png]]<br />
<br />
'''After:'''<br />
<br />
[[Image:after-TBGRAImageList.png]]<br />
<br />
Component which inherits from TImageList. So each control (tested on TToolBar and TTreeView) which is using TImageList.Draw method for drawing icons, automatically can have alpha support. Just use this component instead of TImageList. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRASpeedButton ==<br />
<br />
'''Use as replace of:''' TSpeedButton<br />
<br />
[[Image:BGRASpeedButton.png]]<br />
<br />
Component which inherits from TSpeedButton and draws the glyph using TBGRABitmap. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRAButton ==<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgrabutton.png]]<br />
<br />
Customizable graphic component which is using only BGRABitmap functions for drawing. This component is insensitive for -dGTK_ONLY switch. Demo project included in package.<br />
<br />
'''Functionality:'''<br />
* Gradient, Clear or Color body. [[Double_Gradient]].<br />
* Text with shadow: BGRA antialias or like system default with ClearType.<br />
* Rounded border, inner Light.<br />
* States: normal, hover & clicked fully customizable and grayscale disabled state.<br />
* Special: Down, DropDown, Static.<br />
* Full AutoSize working with Glyph.<br />
<br />
== TBGRAPanel ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
Simple TPanel descendant which can have gradient background. Created especially for TBGRAButton (for creating a nice looking toolbar for bgrabuttons). This component is insensitive for -dGTK_ONLY switch<br />
<br />
== TBGRAKnob ==<br />
[[Image:BC-Bgraknob.png]]<br />
<br />
Graphic knob component created by circular.<br />
<br />
== TBGRAFlashProgressBar ==<br />
<br />
'''Use as replace of:''' TProgressBar<br />
<br />
[[Image:BC-Bgraflashprogressbar.png]]<br />
<br />
Flash progressbar created by circular.<br />
<br />
== TBGRAImageManipulation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Component to facilitate the importation of images in an application.<br />
<br />
In the current version you can import an image and cut out keeping the aspect ratio (or not). For example, if you want to import photos using the 3x4 ratio, adjust the 'ratio' property to 3:4. If import an image with different size, the component will ensure that the image meets the proportions of the desired dimensions.<br />
<br />
You can determine the minimum size of the image adjusting the properties 'MinWidth'and 'MinHeight'.<br />
<br />
You can rotate the image using functions builtin.<br />
<br />
See demo of component:<br />
<br />
[[Image:bgraimagemanipulation.jpg]]<br />
<br />
After retrieving the image modified by the component, just put the image into your destination using the stretch. It is obvious that the target must have the same ratio chosen on component for do not distort the final result.<br />
<br />
== TBGRAImageButton ==<br />
<br />
If you need some code to load and split an image from file, and then scale the borders like in this control you can use TBGRABitmapThemeUtils (included in BGRAControls).<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgraimagebutton.png]]<br />
<br />
Component used to create a button with 4 states from Bitmap.<br />
<br />
'''Features:'''<br />
* Load the image from the "Bitmap" property in the object inspector or load from file using "BitmapFile".<br />
<br />
// You can load bmp and also png files<br />
BGRAImageButton1.BitmapLoadFromFile(BGRAImageButton1.BitmapFile);<br />
<br />
* BitmapOptions: you can set the border pixels, resample method and fill modes. Usefull to create textured / like Windows themed buttons.<br />
* AutoSize, ModalResult.<br />
* Text with Shadow, you can disable text render with the option "TextVisible".<br />
* Sound: in mouse enter and leave in Windows from .wav files.<br />
* Toggle: you can read / set the current state with the property "Checked".<br />
* Animation: glowing effect.<br />
<br />
'''Usage:'''<br />
<br />
The bitmap must contain 4 states (from top to bottom, with the same Height) in the following order: normal, enter, pressed, disabled.<br />
<br />
If you choose to use BitmapOptions you need to have for each state an image which has a border, and inside some content that can be repeated. Then with FillCenter option (if you want a textured button), it gets repeated while the borders stay as they are. This is like the method used in Windows to theme the buttons.<br />
<br />
''Example Button:''<br />
<br />
[[Image:samplebgraimagebutton.png]]<br />
<br />
''Example Button (with Alpha):''<br />
<br />
[[Image:samplebgraimagebuttonalpha.png]]<br />
<br />
== TBGRAVirtualScreen ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
The principle is to draw on a memory bitmap.<br />
<br />
The component has a specific event, OnRedraw, which is called when the whole bitmap needs to be redrawn. It happens at the beginning, when resizing and when the Redraw method is called.<br />
<br />
Otherwise, it is possible to modify the Bitmap property and call Invalidate or Repaint, to avoid erasing the whole bitmap content.<br />
<br />
== TBGRAShape ==<br />
<br />
'''Use as replace of:''' TShape<br />
<br />
[[Image:samplebgrashape.png]]<br />
<br />
The component has full alpha support and you can put the number of polygons you want with rounded borders & gradients (linear, radial, diamond, reflected).<br />
<br />
== TBGRAImageToggleBox ==<br />
<br />
REMOVED IN VER 1.1.0.7.<br />
<br />
'''Use as replace of:''' TToggleBox<br />
<br />
Component used to create a toggle box from Bitmap.<br />
<br />
The bitmap must contain 8 images (from top to bottom, with the same Height) in the following order: unchecked normal, unchecked enter, unchecked pressed, unchecked disabled for Unchecked state and checked normal, checked enter, checked pressed, checked disabled for Normal state.<br />
<br />
''Example toggle box:''<br />
<br />
[[Image:sampletogglebox.png]]<br />
<br />
== TBGRAGraphicControl ==<br />
<br />
'''Use as replace of:''' TPaintBox<br />
<br />
TBGRAGraphicControl, which allows to draw your component by yourself with alpha blending.<br />
<br />
== TBGRASpriteAnimation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Read more in the article [[BGRASpriteAnimation]].<br />
<br />
[[Image:bgraspriteanimation.png]]<br />
<br />
With this you can do animations from bitmap. You need an image with all the frames layout in in a horizontal position.<br />
<br />
It has the ability to specify how many times the animation should be played (0 for infinite, 1, 2, etc) and static to stop the animation, is capable to specify the speed and direction and support transparency.<br />
<br />
Features:<br />
* Animation: invert, position, lap, speed, static, repeat.<br />
* Sprite: fill opacity (global transparency), flip mode (horizontal, vertical, both), key color (transparent color), resample (normal or fine resample modes). AutoSize.<br />
* AnimatedGifToSprite: convert an animated gif to a BGRABitmap sprite.<br />
<br />
== TBGRALabel ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
Label component based on TBGRAButton.<br />
<br />
Features:<br />
* Caption with shadow or not<br />
* Full alpha and antialias support or not<br />
* WordWarp or not<br />
* Caption with Property Editor Multiline<br />
<br />
== TBGRALabelFX ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
[[Image:bgralabelfx.png]]<br />
<br />
Features:<br />
* Outline<br />
* Shadow<br />
<br />
ToDo:<br />
* Use BGRATextFX multicolor, textures.<br />
* etc.<br />
<br />
== TBGRAWin7ToolBar ==<br />
<br />
[[Image:bgrawin7toolbar.png]]<br />
<br />
Is a TBGRAVirtualScreen descendant with some default child sizing, and nice Win7 ToolBar background.<br />
<br />
== BGRASamples unit ==<br />
<br />
This unit has sample drawings, styles for buttons and colors used in different UI.<br />
<br />
[[Image:ioselements.png]]<br />
<br />
* '''Accent Color:''' the colors used in the Windows Phone. The accent color can be used in TBGRAButton and TBGRAImageButton (see the different procedures).<br />
* '''Facebook button color:''' gray, green and blue, with a procedure to create an image in the normal or pressed state, also to use this style in a TBGRAImageButton.<br />
* '''TBGRASampleStyle:''' Styles for TBGRAButton ('Default', 'Flash Player', 'Windows 7 ToolBar', 'Windows 7 ToolBar Smooth', 'Windows 7', 'Office 2010', 'Mac OSX Lion', 'Windows 7 Cristal').<br />
* '''iOS Elements:''' Draw a gray bar, the blue toolbar and a tiled background, the same elements used in the iOS screen.<br />
* '''Glass:''' used in testbgracontrols, it show an image in a virtualscreen and apply blur in the buttons area.<br />
* '''Drawings:''' flash player body and toolbar, windows 7 toolbar.<br />
<br />
* Some other usefull procedures to work with TBGRAButton and TBGRAImageButton.<br />
<br />
== BGRABitmapThemeUtils ==<br />
<br />
This unit is used by BGRAImageButton to draw the button! Also it's usefull to skin controls from bitmaps.<br />
<br />
A more advanced version of this is SliceScaling.pas unit.<br />
<br />
== TBGRASliceScaling ==<br />
<br />
9-slice scaling, it's usefull to create sizable UI elements like in the Custom Drawn Windows 7 Drawer.<br />
<br />
Also there's a [[TAChart]] example with slice scaled bars.<br />
<br />
[[File:slicescaledtachart.png]]<br />
<br />
== BGRANeoButton ==<br />
<br />
This unit is an example, it's usefull to learn how to create your own button with bgrabitmap. BTW read the BGRAImageButton and BGRAButton code. All in this unit can be overriden. I've not added 'invalidate' messages in types and AutoSize, add your own according to your programming needs.<br />
<br />
== Custom Drawn Windows 7 ==<br />
<br />
[[Image:customdrawnwindows7.png]]<br />
<br />
This is a drawer for [[Lazarus Custom Drawn Controls]], you need that component installed with the latest Lazarus revision to work.<br />
<br />
Working in this drawer: button, statictext, checkbox, radiobutton and progressbar.<br />
<br />
This has also extra images for 'Luna' (Windows XP Theme) 'Aero Lite' (Windows 8 Theme) and extra buttons (arrows).<br />
<br />
[[Category:Components]]<br />
[[Category:Graphics]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=BGRAControls&diff=62904BGRAControls2012-10-19T00:34:22Z<p>Lainz: /* TBGRASliceScaling */</p>
<hr />
<div>{{BGRAControls}}<br />
<br />
== Install ==<br />
<br />
You can use TortoiseSVN to download the svn repository and TortoiseGIT to download the git repository.<br />
<br />
We're using BGRABitmap SVN to develop BGRAControls. Important changes in BGRABitmap can stop working BGRAControls.<br />
<br />
'''1) Download BGRABitmap'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/lazpaint/files/src/<br />
<br />
'''Latest SVN:''' svn co https://lazpaint.svn.sourceforge.net/svnroot/lazpaint lazpaint<br />
<br />
Install BGRABitmap with the file bgrabitmap.lpk<br />
<br />
'''2) Download BGRAControls'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/bgracontrols/files/<br />
<br />
''SVN''<br />
<br />
'''SVN Browse:''' http://bgracontrols.svn.sourceforge.net/viewvc/bgracontrols/<br />
<br />
'''SVN Checkout:''' svn co https://bgracontrols.svn.sourceforge.net/svnroot/bgracontrols bgracontrols<br />
<br />
''GIT''<br />
<br />
'''GIT Browse:''' http://bgracontrols.git.sourceforge.net/git/gitweb-index.cgi<br />
<br />
'''GIT Checkout:''' git://bgracontrols.git.sourceforge.net/gitroot/bgracontrols/bgracontrols <br />
<br />
Install BGRAControls with the file bgracontrols.lpk<br />
<br />
== Overview ==<br />
<br />
'''Authors:''' <br />
<br />
Dibo (package founder and maintainer, author: ''TBGRAImageList'', ''TBGRASpeedButton'', ''TBGRAButton'', ''TBGRAPanel'')<br />
<br />
Lainz (package maintainer, author: ''TBGRAImageButton'', ''TBGRAImageToggleBox'', ''TBGRASpriteAnimation'', ''TBGRALabelFX'', ''TBGRAWin7ToolBar'', ''TBGRANeoButton'', ''Windows 7 Drawer'' and some other stuff)<br />
<br />
Circular (package maintainer, author: ''TBGRAKnob'', ''TBGRAFlashProgressBar'', ''TBGRAVirtualScreen'', ''TBGRAShape'', ''TBGRAGraphicControl'')<br />
<br />
Emerson Cavalcanti (author: ''TBGRAImageManipulation'')<br />
<br />
codedeep (author: ''TBGRALabel'')<br />
<br />
'''License:''' Modified LGPL.<br />
<br />
As many people know, Lazarus GTK doesn't have full alpha support. I created a set of components which use TBGRABitmap for drawing icons, so it partially solves the problem with alpha in GTK. But this components set is not only a GTK patch but has more fancy components which are using the power of the BGRABitmap package.<br />
<br />
'''Screenshots:''' Some shots of the project 'testbgracontrols'.<br />
<br />
[[Image:testbgrac1.png]]<br />
<br />
''testbgracontrols > Main.''<br />
<br />
[[Image:testbgrac2.png]]<br />
<br />
''testbgracontrols > Windows 7 ToolBar.''<br />
<br />
[[Image:testbgrac4.png]]<br />
<br />
''testbgracontrols > Ribbon.''<br />
<br />
== Related Articles ==<br />
<br />
[[BGRAButton Gallery]] - Gallery of buttons with source code to use in your projects with BGRAButton.<br />
<br />
[[BGRASpriteAnimation]] - Usage of the sprite animation component.<br />
<br />
[[uE_Controls]] - Other controls developed with BGRABitmap.<br />
<br />
[[BGRABitmap]] - The library used to create this controls.<br />
<br />
[[LazPaint]] - A paint program developed with Lazarus and BGRABitmap.<br />
<br />
== Using ==<br />
<br />
Drop and use like normal component.<br />
<br />
'''Button''':<br />
* TBGRAButton<br />
* TBGRAImageButton<br />
* TBGRAImageToggleBox<br />
* TBGRASpeedButton<br />
<br />
'''Label'''<br />
* TBGRALabel<br />
* TBGRALabelFX<br />
<br />
'''Panel'''<br />
* TBGRAPanel<br />
* TBGRAVirtualScreen<br />
<br />
'''Image'''<br />
* TBGRAGraphicControl<br />
* TBGRAImageList<br />
* TBGRAImageManipulation<br />
* TBGRASpriteAnimation<br />
<br />
'''Other'''<br />
* TBGRAFlashProgressBar<br />
* TBGRAKnob<br />
* TBGRAShape<br />
* TBGRAWin7ToolBar<br />
<br />
== TBGRAImageList ==<br />
<br />
'''Use as replace of:''' TImageList<br />
<br />
'''Before:'''<br />
<br />
[[Image:before-TImageList.png]]<br />
<br />
'''After:'''<br />
<br />
[[Image:after-TBGRAImageList.png]]<br />
<br />
Component which inherits from TImageList. So each control (tested on TToolBar and TTreeView) which is using TImageList.Draw method for drawing icons, automatically can have alpha support. Just use this component instead of TImageList. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRASpeedButton ==<br />
<br />
'''Use as replace of:''' TSpeedButton<br />
<br />
[[Image:BGRASpeedButton.png]]<br />
<br />
Component which inherits from TSpeedButton and draws the glyph using TBGRABitmap. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRAButton ==<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgrabutton.png]]<br />
<br />
Customizable graphic component which is using only BGRABitmap functions for drawing. This component is insensitive for -dGTK_ONLY switch. Demo project included in package.<br />
<br />
'''Functionality:'''<br />
* Gradient, Clear or Color body. [[Double_Gradient]].<br />
* Text with shadow: BGRA antialias or like system default with ClearType.<br />
* Rounded border, inner Light.<br />
* States: normal, hover & clicked fully customizable and grayscale disabled state.<br />
* Special: Down, DropDown, Static.<br />
* Full AutoSize working with Glyph.<br />
<br />
== TBGRAPanel ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
Simple TPanel descendant which can have gradient background. Created especially for TBGRAButton (for creating a nice looking toolbar for bgrabuttons). This component is insensitive for -dGTK_ONLY switch<br />
<br />
== TBGRAKnob ==<br />
[[Image:BC-Bgraknob.png]]<br />
<br />
Graphic knob component created by circular.<br />
<br />
== TBGRAFlashProgressBar ==<br />
<br />
'''Use as replace of:''' TProgressBar<br />
<br />
[[Image:BC-Bgraflashprogressbar.png]]<br />
<br />
Flash progressbar created by circular.<br />
<br />
== TBGRAImageManipulation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Component to facilitate the importation of images in an application.<br />
<br />
In the current version you can import an image and cut out keeping the aspect ratio (or not). For example, if you want to import photos using the 3x4 ratio, adjust the 'ratio' property to 3:4. If import an image with different size, the component will ensure that the image meets the proportions of the desired dimensions.<br />
<br />
You can determine the minimum size of the image adjusting the properties 'MinWidth'and 'MinHeight'.<br />
<br />
You can rotate the image using functions builtin.<br />
<br />
See demo of component:<br />
<br />
[[Image:bgraimagemanipulation.jpg]]<br />
<br />
After retrieving the image modified by the component, just put the image into your destination using the stretch. It is obvious that the target must have the same ratio chosen on component for do not distort the final result.<br />
<br />
== TBGRAImageButton ==<br />
<br />
If you need some code to load and split an image from file, and then scale the borders like in this control you can use TBGRABitmapThemeUtils (included in BGRAControls).<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgraimagebutton.png]]<br />
<br />
Component used to create a button with 4 states from Bitmap.<br />
<br />
'''Features:'''<br />
* Load the image from the "Bitmap" property in the object inspector or load from file using "BitmapFile".<br />
<br />
// You can load bmp and also png files<br />
BGRAImageButton1.BitmapLoadFromFile(BGRAImageButton1.BitmapFile);<br />
<br />
* BitmapOptions: you can set the border pixels, resample method and fill modes. Usefull to create textured / like Windows themed buttons.<br />
* AutoSize, ModalResult.<br />
* Text with Shadow, you can disable text render with the option "TextVisible".<br />
* Sound: in mouse enter and leave in Windows from .wav files.<br />
* Toggle: you can read / set the current state with the property "Checked".<br />
* Animation: glowing effect.<br />
<br />
'''Usage:'''<br />
<br />
The bitmap must contain 4 states (from top to bottom, with the same Height) in the following order: normal, enter, pressed, disabled.<br />
<br />
If you choose to use BitmapOptions you need to have for each state an image which has a border, and inside some content that can be repeated. Then with FillCenter option (if you want a textured button), it gets repeated while the borders stay as they are. This is like the method used in Windows to theme the buttons.<br />
<br />
''Example Button:''<br />
<br />
[[Image:samplebgraimagebutton.png]]<br />
<br />
''Example Button (with Alpha):''<br />
<br />
[[Image:samplebgraimagebuttonalpha.png]]<br />
<br />
== TBGRAVirtualScreen ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
The principle is to draw on a memory bitmap.<br />
<br />
The component has a specific event, OnRedraw, which is called when the whole bitmap needs to be redrawn. It happens at the beginning, when resizing and when the Redraw method is called.<br />
<br />
Otherwise, it is possible to modify the Bitmap property and call Invalidate or Repaint, to avoid erasing the whole bitmap content.<br />
<br />
== TBGRAShape ==<br />
<br />
'''Use as replace of:''' TShape<br />
<br />
[[Image:samplebgrashape.png]]<br />
<br />
The component has full alpha support and you can put the number of polygons you want with rounded borders & gradients (linear, radial, diamond, reflected).<br />
<br />
== TBGRAImageToggleBox ==<br />
<br />
REMOVED IN VER 1.1.0.7.<br />
<br />
'''Use as replace of:''' TToggleBox<br />
<br />
Component used to create a toggle box from Bitmap.<br />
<br />
The bitmap must contain 8 images (from top to bottom, with the same Height) in the following order: unchecked normal, unchecked enter, unchecked pressed, unchecked disabled for Unchecked state and checked normal, checked enter, checked pressed, checked disabled for Normal state.<br />
<br />
''Example toggle box:''<br />
<br />
[[Image:sampletogglebox.png]]<br />
<br />
== TBGRAGraphicControl ==<br />
<br />
'''Use as replace of:''' TPaintBox<br />
<br />
TBGRAGraphicControl, which allows to draw your component by yourself with alpha blending.<br />
<br />
== TBGRASpriteAnimation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Read more in the article [[BGRASpriteAnimation]].<br />
<br />
[[Image:bgraspriteanimation.png]]<br />
<br />
With this you can do animations from bitmap. You need an image with all the frames layout in in a horizontal position.<br />
<br />
It has the ability to specify how many times the animation should be played (0 for infinite, 1, 2, etc) and static to stop the animation, is capable to specify the speed and direction and support transparency.<br />
<br />
Features:<br />
* Animation: invert, position, lap, speed, static, repeat.<br />
* Sprite: fill opacity (global transparency), flip mode (horizontal, vertical, both), key color (transparent color), resample (normal or fine resample modes). AutoSize.<br />
* AnimatedGifToSprite: convert an animated gif to a BGRABitmap sprite.<br />
<br />
== TBGRALabel ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
Label component based on TBGRAButton.<br />
<br />
Features:<br />
* Caption with shadow or not<br />
* Full alpha and antialias support or not<br />
* WordWarp or not<br />
* Caption with Property Editor Multiline<br />
<br />
== TBGRALabelFX ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
[[Image:bgralabelfx.png]]<br />
<br />
Features:<br />
* Outline<br />
* Shadow<br />
<br />
ToDo:<br />
* Use BGRATextFX multicolor, textures.<br />
* etc.<br />
<br />
== TBGRAWin7ToolBar ==<br />
<br />
[[Image:bgrawin7toolbar.png]]<br />
<br />
Is a TBGRAVirtualScreen descendant with some default child sizing, and nice Win7 ToolBar background.<br />
<br />
== BGRASamples unit ==<br />
<br />
This unit has sample drawings, styles for buttons and colors used in different UI.<br />
<br />
[[Image:ioselements.png]]<br />
<br />
* '''Accent Color:''' the colors used in the Windows Phone. The accent color can be used in TBGRAButton and TBGRAImageButton (see the different procedures).<br />
* '''Facebook button color:''' gray, green and blue, with a procedure to create an image in the normal or pressed state, also to use this style in a TBGRAImageButton.<br />
* '''TBGRASampleStyle:''' Styles for TBGRAButton ('Default', 'Flash Player', 'Windows 7 ToolBar', 'Windows 7 ToolBar Smooth', 'Windows 7', 'Office 2010', 'Mac OSX Lion', 'Windows 7 Cristal').<br />
* '''iOS Elements:''' Draw a gray bar, the blue toolbar and a tiled background, the same elements used in the iOS screen.<br />
* '''Glass:''' used in testbgracontrols, it show an image in a virtualscreen and apply blur in the buttons area.<br />
* '''Drawings:''' flash player body and toolbar, windows 7 toolbar.<br />
<br />
* Some other usefull procedures to work with TBGRAButton and TBGRAImageButton.<br />
<br />
== BGRABitmapThemeUtils ==<br />
<br />
This unit is used by BGRAImageButton to draw the button! Also it's usefull to skin controls from bitmaps.<br />
<br />
A more advanced version of this is SliceScaling.pas unit.<br />
<br />
== TBGRASliceScaling ==<br />
<br />
9-slice scaling, it's usefull to create sizable UI elements like in the Custom Drawn Windows 7 Drawer.<br />
<br />
Also there's a [[tachart]] example with slice scaled bars.<br />
<br />
[[File:slicescaledtachart.png]]<br />
<br />
== BGRANeoButton ==<br />
<br />
This unit is an example, it's usefull to learn how to create your own button with bgrabitmap. BTW read the BGRAImageButton and BGRAButton code. All in this unit can be overriden. I've not added 'invalidate' messages in types and AutoSize, add your own according to your programming needs.<br />
<br />
== Custom Drawn Windows 7 ==<br />
<br />
[[Image:customdrawnwindows7.png]]<br />
<br />
This is a drawer for [[Lazarus Custom Drawn Controls]], you need that component installed with the latest Lazarus revision to work.<br />
<br />
Working in this drawer: button, statictext, checkbox, radiobutton and progressbar.<br />
<br />
This has also extra images for 'Luna' (Windows XP Theme) 'Aero Lite' (Windows 8 Theme) and extra buttons (arrows).<br />
<br />
[[Category:Components]]<br />
[[Category:Graphics]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=File:slicescaledtachart.png&diff=62903File:slicescaledtachart.png2012-10-19T00:34:06Z<p>Lainz: </p>
<hr />
<div></div>Lainzhttps://wiki.freepascal.org/index.php?title=BGRAControls&diff=62824BGRAControls2012-10-16T10:00:18Z<p>Lainz: /* BGRABitmapThemeUtils */</p>
<hr />
<div>{{BGRAControls}}<br />
<br />
== Install ==<br />
<br />
You can use TortoiseSVN to download the svn repository and TortoiseGIT to download the git repository.<br />
<br />
We're using BGRABitmap SVN to develop BGRAControls. Important changes in BGRABitmap can stop working BGRAControls.<br />
<br />
'''1) Download BGRABitmap'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/lazpaint/files/src/<br />
<br />
'''Latest SVN:''' svn co https://lazpaint.svn.sourceforge.net/svnroot/lazpaint lazpaint<br />
<br />
Install BGRABitmap with the file bgrabitmap.lpk<br />
<br />
'''2) Download BGRAControls'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/bgracontrols/files/<br />
<br />
''SVN''<br />
<br />
'''SVN Browse:''' http://bgracontrols.svn.sourceforge.net/viewvc/bgracontrols/<br />
<br />
'''SVN Checkout:''' svn co https://bgracontrols.svn.sourceforge.net/svnroot/bgracontrols bgracontrols<br />
<br />
''GIT''<br />
<br />
'''GIT Browse:''' http://bgracontrols.git.sourceforge.net/git/gitweb-index.cgi<br />
<br />
'''GIT Checkout:''' git://bgracontrols.git.sourceforge.net/gitroot/bgracontrols/bgracontrols <br />
<br />
Install BGRAControls with the file bgracontrols.lpk<br />
<br />
== Overview ==<br />
<br />
'''Authors:''' <br />
<br />
Dibo (package founder and maintainer, author: ''TBGRAImageList'', ''TBGRASpeedButton'', ''TBGRAButton'', ''TBGRAPanel'')<br />
<br />
Lainz (package maintainer, author: ''TBGRAImageButton'', ''TBGRAImageToggleBox'', ''TBGRASpriteAnimation'', ''TBGRALabelFX'', ''TBGRAWin7ToolBar'', ''TBGRANeoButton'', ''Windows 7 Drawer'' and some other stuff)<br />
<br />
Circular (package maintainer, author: ''TBGRAKnob'', ''TBGRAFlashProgressBar'', ''TBGRAVirtualScreen'', ''TBGRAShape'', ''TBGRAGraphicControl'')<br />
<br />
Emerson Cavalcanti (author: ''TBGRAImageManipulation'')<br />
<br />
codedeep (author: ''TBGRALabel'')<br />
<br />
'''License:''' Modified LGPL.<br />
<br />
As many people know, Lazarus GTK doesn't have full alpha support. I created a set of components which use TBGRABitmap for drawing icons, so it partially solves the problem with alpha in GTK. But this components set is not only a GTK patch but has more fancy components which are using the power of the BGRABitmap package.<br />
<br />
'''Screenshots:''' Some shots of the project 'testbgracontrols'.<br />
<br />
[[Image:testbgrac1.png]]<br />
<br />
''testbgracontrols > Main.''<br />
<br />
[[Image:testbgrac2.png]]<br />
<br />
''testbgracontrols > Windows 7 ToolBar.''<br />
<br />
[[Image:testbgrac4.png]]<br />
<br />
''testbgracontrols > Ribbon.''<br />
<br />
== Related Articles ==<br />
<br />
[[BGRAButton Gallery]] - Gallery of buttons with source code to use in your projects with BGRAButton.<br />
<br />
[[BGRASpriteAnimation]] - Usage of the sprite animation component.<br />
<br />
[[uE_Controls]] - Other controls developed with BGRABitmap.<br />
<br />
[[BGRABitmap]] - The library used to create this controls.<br />
<br />
[[LazPaint]] - A paint program developed with Lazarus and BGRABitmap.<br />
<br />
== Using ==<br />
<br />
Drop and use like normal component.<br />
<br />
'''Button''':<br />
* TBGRAButton<br />
* TBGRAImageButton<br />
* TBGRAImageToggleBox<br />
* TBGRASpeedButton<br />
<br />
'''Label'''<br />
* TBGRALabel<br />
* TBGRALabelFX<br />
<br />
'''Panel'''<br />
* TBGRAPanel<br />
* TBGRAVirtualScreen<br />
<br />
'''Image'''<br />
* TBGRAGraphicControl<br />
* TBGRAImageList<br />
* TBGRAImageManipulation<br />
* TBGRASpriteAnimation<br />
<br />
'''Other'''<br />
* TBGRAFlashProgressBar<br />
* TBGRAKnob<br />
* TBGRAShape<br />
* TBGRAWin7ToolBar<br />
<br />
== TBGRAImageList ==<br />
<br />
'''Use as replace of:''' TImageList<br />
<br />
'''Before:'''<br />
<br />
[[Image:before-TImageList.png]]<br />
<br />
'''After:'''<br />
<br />
[[Image:after-TBGRAImageList.png]]<br />
<br />
Component which inherits from TImageList. So each control (tested on TToolBar and TTreeView) which is using TImageList.Draw method for drawing icons, automatically can have alpha support. Just use this component instead of TImageList. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRASpeedButton ==<br />
<br />
'''Use as replace of:''' TSpeedButton<br />
<br />
[[Image:BGRASpeedButton.png]]<br />
<br />
Component which inherits from TSpeedButton and draws the glyph using TBGRABitmap. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRAButton ==<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgrabutton.png]]<br />
<br />
Customizable graphic component which is using only BGRABitmap functions for drawing. This component is insensitive for -dGTK_ONLY switch. Demo project included in package.<br />
<br />
'''Functionality:'''<br />
* Gradient, Clear or Color body. [[Double_Gradient]].<br />
* Text with shadow: BGRA antialias or like system default with ClearType.<br />
* Rounded border, inner Light.<br />
* States: normal, hover & clicked fully customizable and grayscale disabled state.<br />
* Special: Down, DropDown, Static.<br />
* Full AutoSize working with Glyph.<br />
<br />
== TBGRAPanel ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
Simple TPanel descendant which can have gradient background. Created especially for TBGRAButton (for creating a nice looking toolbar for bgrabuttons). This component is insensitive for -dGTK_ONLY switch<br />
<br />
== TBGRAKnob ==<br />
[[Image:BC-Bgraknob.png]]<br />
<br />
Graphic knob component created by circular.<br />
<br />
== TBGRAFlashProgressBar ==<br />
<br />
'''Use as replace of:''' TProgressBar<br />
<br />
[[Image:BC-Bgraflashprogressbar.png]]<br />
<br />
Flash progressbar created by circular.<br />
<br />
== TBGRAImageManipulation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Component to facilitate the importation of images in an application.<br />
<br />
In the current version you can import an image and cut out keeping the aspect ratio (or not). For example, if you want to import photos using the 3x4 ratio, adjust the 'ratio' property to 3:4. If import an image with different size, the component will ensure that the image meets the proportions of the desired dimensions.<br />
<br />
You can determine the minimum size of the image adjusting the properties 'MinWidth'and 'MinHeight'.<br />
<br />
You can rotate the image using functions builtin.<br />
<br />
See demo of component:<br />
<br />
[[Image:bgraimagemanipulation.jpg]]<br />
<br />
After retrieving the image modified by the component, just put the image into your destination using the stretch. It is obvious that the target must have the same ratio chosen on component for do not distort the final result.<br />
<br />
== TBGRAImageButton ==<br />
<br />
If you need some code to load and split an image from file, and then scale the borders like in this control you can use TBGRABitmapThemeUtils (included in BGRAControls).<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgraimagebutton.png]]<br />
<br />
Component used to create a button with 4 states from Bitmap.<br />
<br />
'''Features:'''<br />
* Load the image from the "Bitmap" property in the object inspector or load from file using "BitmapFile".<br />
<br />
// You can load bmp and also png files<br />
BGRAImageButton1.BitmapLoadFromFile(BGRAImageButton1.BitmapFile);<br />
<br />
* BitmapOptions: you can set the border pixels, resample method and fill modes. Usefull to create textured / like Windows themed buttons.<br />
* AutoSize, ModalResult.<br />
* Text with Shadow, you can disable text render with the option "TextVisible".<br />
* Sound: in mouse enter and leave in Windows from .wav files.<br />
* Toggle: you can read / set the current state with the property "Checked".<br />
* Animation: glowing effect.<br />
<br />
'''Usage:'''<br />
<br />
The bitmap must contain 4 states (from top to bottom, with the same Height) in the following order: normal, enter, pressed, disabled.<br />
<br />
If you choose to use BitmapOptions you need to have for each state an image which has a border, and inside some content that can be repeated. Then with FillCenter option (if you want a textured button), it gets repeated while the borders stay as they are. This is like the method used in Windows to theme the buttons.<br />
<br />
''Example Button:''<br />
<br />
[[Image:samplebgraimagebutton.png]]<br />
<br />
''Example Button (with Alpha):''<br />
<br />
[[Image:samplebgraimagebuttonalpha.png]]<br />
<br />
== TBGRAVirtualScreen ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
The principle is to draw on a memory bitmap.<br />
<br />
The component has a specific event, OnRedraw, which is called when the whole bitmap needs to be redrawn. It happens at the beginning, when resizing and when the Redraw method is called.<br />
<br />
Otherwise, it is possible to modify the Bitmap property and call Invalidate or Repaint, to avoid erasing the whole bitmap content.<br />
<br />
== TBGRAShape ==<br />
<br />
'''Use as replace of:''' TShape<br />
<br />
[[Image:samplebgrashape.png]]<br />
<br />
The component has full alpha support and you can put the number of polygons you want with rounded borders & gradients (linear, radial, diamond, reflected).<br />
<br />
== TBGRAImageToggleBox ==<br />
<br />
REMOVED IN VER 1.1.0.7.<br />
<br />
'''Use as replace of:''' TToggleBox<br />
<br />
Component used to create a toggle box from Bitmap.<br />
<br />
The bitmap must contain 8 images (from top to bottom, with the same Height) in the following order: unchecked normal, unchecked enter, unchecked pressed, unchecked disabled for Unchecked state and checked normal, checked enter, checked pressed, checked disabled for Normal state.<br />
<br />
''Example toggle box:''<br />
<br />
[[Image:sampletogglebox.png]]<br />
<br />
== TBGRAGraphicControl ==<br />
<br />
'''Use as replace of:''' TPaintBox<br />
<br />
TBGRAGraphicControl, which allows to draw your component by yourself with alpha blending.<br />
<br />
== TBGRASpriteAnimation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Read more in the article [[BGRASpriteAnimation]].<br />
<br />
[[Image:bgraspriteanimation.png]]<br />
<br />
With this you can do animations from bitmap. You need an image with all the frames layout in in a horizontal position.<br />
<br />
It has the ability to specify how many times the animation should be played (0 for infinite, 1, 2, etc) and static to stop the animation, is capable to specify the speed and direction and support transparency.<br />
<br />
Features:<br />
* Animation: invert, position, lap, speed, static, repeat.<br />
* Sprite: fill opacity (global transparency), flip mode (horizontal, vertical, both), key color (transparent color), resample (normal or fine resample modes). AutoSize.<br />
* AnimatedGifToSprite: convert an animated gif to a BGRABitmap sprite.<br />
<br />
== TBGRALabel ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
Label component based on TBGRAButton.<br />
<br />
Features:<br />
* Caption with shadow or not<br />
* Full alpha and antialias support or not<br />
* WordWarp or not<br />
* Caption with Property Editor Multiline<br />
<br />
== TBGRALabelFX ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
[[Image:bgralabelfx.png]]<br />
<br />
Features:<br />
* Outline<br />
* Shadow<br />
<br />
ToDo:<br />
* Use BGRATextFX multicolor, textures.<br />
* etc.<br />
<br />
== TBGRAWin7ToolBar ==<br />
<br />
[[Image:bgrawin7toolbar.png]]<br />
<br />
Is a TBGRAVirtualScreen descendant with some default child sizing, and nice Win7 ToolBar background.<br />
<br />
== BGRASamples unit ==<br />
<br />
This unit has sample drawings, styles for buttons and colors used in different UI.<br />
<br />
[[Image:ioselements.png]]<br />
<br />
* '''Accent Color:''' the colors used in the Windows Phone. The accent color can be used in TBGRAButton and TBGRAImageButton (see the different procedures).<br />
* '''Facebook button color:''' gray, green and blue, with a procedure to create an image in the normal or pressed state, also to use this style in a TBGRAImageButton.<br />
* '''TBGRASampleStyle:''' Styles for TBGRAButton ('Default', 'Flash Player', 'Windows 7 ToolBar', 'Windows 7 ToolBar Smooth', 'Windows 7', 'Office 2010', 'Mac OSX Lion', 'Windows 7 Cristal').<br />
* '''iOS Elements:''' Draw a gray bar, the blue toolbar and a tiled background, the same elements used in the iOS screen.<br />
* '''Glass:''' used in testbgracontrols, it show an image in a virtualscreen and apply blur in the buttons area.<br />
* '''Drawings:''' flash player body and toolbar, windows 7 toolbar.<br />
<br />
* Some other usefull procedures to work with TBGRAButton and TBGRAImageButton.<br />
<br />
== BGRABitmapThemeUtils ==<br />
<br />
This unit is used by BGRAImageButton to draw the button! Also it's usefull to skin controls from bitmaps.<br />
<br />
A more advanced version of this is SliceScaling.pas unit.<br />
<br />
== TBGRASliceScaling ==<br />
<br />
9-slice scaling, it's usefull to create sizable UI elements like in the Custom Drawn Windows 7 Drawer.<br />
<br />
== BGRANeoButton ==<br />
<br />
This unit is an example, it's usefull to learn how to create your own button with bgrabitmap. BTW read the BGRAImageButton and BGRAButton code. All in this unit can be overriden. I've not added 'invalidate' messages in types and AutoSize, add your own according to your programming needs.<br />
<br />
== Custom Drawn Windows 7 ==<br />
<br />
[[Image:customdrawnwindows7.png]]<br />
<br />
This is a drawer for [[Lazarus Custom Drawn Controls]], you need that component installed with the latest Lazarus revision to work.<br />
<br />
Working in this drawer: button, statictext, checkbox, radiobutton and progressbar.<br />
<br />
This has also extra images for 'Luna' (Windows XP Theme) 'Aero Lite' (Windows 8 Theme) and extra buttons (arrows).<br />
<br />
[[Category:Components]]<br />
[[Category:Graphics]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=Lazarus_Custom_Drawn_Controls&diff=62820Lazarus Custom Drawn Controls2012-10-15T17:12:14Z<p>Lainz: /* The Drawers */</p>
<hr />
<div>The '''Lazarus Custom Drawn Controls''' are a set of controls equivalent to the standard Lazarus controls, but which draw themselves. They can have many uses, including the ability to fully customize the drawing, the ability to have exactly the same look in different platforms and also a higher consistency of behavior.<br />
<br />
This set of controls is divided into two parts:<br />
* the custom drawn controls which are necessary for implementing Lazarus widgetsets and are located in the unit lazarus/lcl/customdrawncontrols.pas. These are described here.<br />
* all other custom drawn controls, which are used often, but aren't indispensable to implement a LCL custom drawn widgetset. Those are located in the package lazarus/components/customdrawn. These are described in the page [[Lazarus Custom Drawn Package]]<br />
<br />
__TOC__<br />
<br />
==How start using these components?==<br />
<br />
To be able to use them in the Lazarus GUI designer install the package lazarus/components/customdrawn.lpk<br />
<br />
To only create customdrawn components by code one can simply add customdrawncontrols, customdrawndrawers and customdrawn_common to the uses clause, declare them and use them. Note that currently only the Win2000 drawer is in the LCL, so any other drawers need to be obtained from the package customdrawn.lpk<br />
<br />
It is important to note that styles are only available if you add the corresponding unit of the style to the uses clause.<br />
<br />
==How do these components work?==<br />
<br />
The basic programming technique utilized by this set of controls is explained at the [[Developing with Graphics#Create a custom control which draws itself]] page.<br />
<br />
The code of the controls itself is implemented in the unit customdrawncontrols.pas, but this unit has no drawing code at all. Customdrawncontrols.pas provides the code which processes all the control's keyboard and mouse events, implementing all the mouse and key response behaviour. Each control instance has a Drawer connected to it. A Drawer in our nomenclature (an instance of the TCDDrawer class) is similar to a theme rendering engine or suchlike. The unit customdrawndrawers.pas manages the list of all known drawers and it also declares all the basic data types needed for State and StateEx. These properties contain all the information about the control's current state, which is passed to the drawer so that it can have the information it requires to draw the control correctly.<br />
Only one instance of each drawer can exist in a program, and all controls refer to that single instance through the drawer's manager in customdrawndrawers.pas. Each control has a property called DrawStyle which allows you to choose (from an enumerated type) which draw style to use, and then customdrawndrawers.pas converts this information into a Drawer instance. You can specify the dsDefault DrawStyle which will then use the style specified in the global variable DefaultStyle. This was done to allow the style of all controls to be changed at once. Simply change this global variable and then call Invalidate on the controls. You can see below a code snippet from customdrawndrawers.pas which shows the methods which have been exposed to manage the list of drawers and also the Default style:<br />
<br />
<syntaxhighlight><br />
unit customdrawndrawers;<br />
//...<br />
TCDDrawStyle = (<br />
// The default is given by the DefaultStyle global variable<br />
// Don't implement anything for this drawer<br />
dsDefault = 0,<br />
// This is a common drawer, the base for all others. It implements the look from dsWin2000<br />
dsCommon,<br />
// Operating system styles<br />
dsWinCE, dsWin2000, dsWinXP,<br />
dsKDEPlastique, dsGNOME, dsMacOSX,<br />
dsAndroid,<br />
// Other special styles for the user<br />
dsExtra1, dsExtra2, dsExtra3, dsExtra4, dsExtra5,<br />
dsExtra6, dsExtra7, dsExtra8, dsExtra9, dsExtra10<br />
);<br />
//...<br />
procedure RegisterDrawer(ADrawer: TCDDrawer; AStyle: TCDDrawStyle);<br />
function GetDefaultDrawer: TCDDrawer;<br />
function GetDrawer(AStyle: TCDDrawStyle): TCDDrawer;<br />
<br />
var<br />
DefaultStyle: TCDDrawStyle = dsCommon; // For now default to the most complete one, later per platform<br />
</syntaxhighlight><br />
<br />
Each Drawer class has methods to draw all controls and also all available primitives. All new drawers created by users should inherit from the class TCDCommonDrawer (which is the basic common drawer declared in the unit customdrawn_common.pas). If you don't inherit from TCDCommonDrawer your application might crash if it hits an abstract method. This is the most complete drawer, which implements all abstract methods from its base class, so inheriting from it guarantees that there will never be crashes owing to methods you have not yet implemented. Other drawers can override the desired methods to change the drawing style.<br />
<br />
The dsCommon drawer uses only TCanvas for all its rendering, but other themes might also use TLazIntfImage and TFPImageCanvas instead, in order to have a faster pixel access. This programming technique is described in [[Developing with Graphics#Working with TLazIntfImage]].<br />
<br />
===Color Palette===<br />
<br />
Drawers have also access to a color Palette, which has the usual LCL system colors. Default drawers will load their colors from the operating system via the LCL acording to the native platform. However, outside their native platform, drawers will use a standard color palette.<br />
<br />
<syntaxhighlight><br />
TCDColorPalette = class<br />
public<br />
ScrollBar, Background, ActiveCaption, InactiveCaption,<br />
Menu, Window, WindowFrame, MenuText, WindowText, CaptionText,<br />
ActiveBorder, InactiveBorder, AppWorkspace, Highlight, HighlightText,<br />
BtnFace, BtnShadow, GrayText, BtnText, InactiveCaptionText,<br />
BtnHighlight, color3DDkShadow, color3DLight, InfoText, InfoBk,<br />
//<br />
HotLight, GradientActiveCaption, GradientInactiveCaption,<br />
MenuHighlight, MenuBar, Form: TColor;<br />
end;<br />
<br />
{ There are 5 possible sources of input for color palettes:<br />
palDefault - Uses palNative when the operating system matches the drawer style,<br />
palFallback otherwise<br />
palNative - Obtain from the operating system<br />
palFallback - Use the fallback colors of the drawer<br />
palUserConfig-Load it from the user configuration files, ToDo<br />
palCustom - The user application has set its own palette<br />
}<br />
TCDPaletteKind = (palDefault, palNative, palFallback, palUserConfig, palCustom);<br />
<br />
{ TCDDrawer }<br />
<br />
TCDDrawer = class<br />
protected<br />
public<br />
Palette: TCDColorPalette;<br />
constructor Create; virtual;<br />
destructor Destroy; override;<br />
procedure SetPaletteKind(APaletteKind: TCDPaletteKind);<br />
procedure LoadNativePaletteColors;<br />
procedure LoadFallbackPaletteColors; virtual;<br />
</syntaxhighlight><br />
<br />
As the code above shows, you can choose where the colors should come from - either from the operating system current theme, from the drawer's default, or from a user-defined scheme provided by your application. This allows you to change all yor application's colors at runtime simply by changing the palette.<br />
<br />
==The Drawers==<br />
<br />
===dsCommon===<br />
<br />
This is the base drawer for all others and it implements a Win2000-look with some small improvements, like better focus drawings on controls<br />
<br />
===dsWinCE===<br />
<br />
Imitates the Windows CE look, with some small improvements like better focus drawings on controls<br />
<br />
===dsWin2000===<br />
<br />
Imitates the Windows 2000 look. Since dsCommon provides the Windows 2000 look already, this class implements no methods at all<br />
<br />
===dsWinXP===<br />
<br />
Imitates the Windows XP look<br />
<br />
===dsKDEPlastique===<br />
<br />
Imitates the look of the Plastique Qt/KDE Theme<br />
<br />
===dsAndroid===<br />
<br />
Imitates the Android look<br />
<br />
===dsWindows7===<br />
<br />
Imitates the Windows 7 look, and also can be used to imitate Windows XP and Windows 8 look, and most msstyles or Windows skins. Currently is available only with BGRABitmap graphic library, and you can get this drawer in the BGRAControls package:<br />
http://wiki.lazarus.freepascal.org/BGRAControls#Custom_Drawn_Windows_7<br />
<br />
You can try to get this working if you convert the slicescaling.pas unit. The technique used to draw the images is 9-slice scaling.<br />
<br />
Some working code to create 9-slice scaling is available here:<br />
http://sourceforge.net/p/bmpthemeutils/home/Home/<br />
<br />
==Controls which imitate the Standard Palette==<br />
<br />
===TCDButton===<br />
<br />
This is a fully custom drawn button.<br />
<br />
Usage example:<br />
<br />
<syntaxhighlight><br />
uses customdrawnextras;<br />
<br />
procedure TForm1.FormCreate(Sender: TObject);<br />
var<br />
MyButton: TCDButton;<br />
begin<br />
MyButton := TCDButton.Create(Self);<br />
MyButton.Parent := Self;<br />
MyButton.DrawStyle := dsWin2000;<br />
MyButton.Left := 100;<br />
MyButton.Top := 100;<br />
MyButton.Width := 200;<br />
MyButton.Height := 50;<br />
MyButton.Caption := 'My Button';<br />
MyButton.Color := clRed;<br />
MyButton.OnClick := @HandleButtonClick;<br />
end;<br />
</syntaxhighlight><br />
<br />
[[Image:Custom_drawn_buttons.png]]<br />
<br />
===TCDEdit===<br />
<br />
This is a fully custom drawn edit control.<br />
<br />
[[Image:TCDEdit.png]]<br />
<br />
===TCDCheckBox===<br />
<br />
This is a fully custom drawn check box.<br />
<br />
[[Image:TCDCheckBox.png]]<br />
<br />
===TCDRadioButton===<br />
<br />
[[Image:TCDRadioButton.png]]<br />
<br />
===TCDScrollBar===<br />
<br />
[[Image:TCDScrollBar.png]]<br />
<br />
===TCDGroupBox===<br />
<br />
This is a fully custom drawn group box.<br />
<br />
[[Image:TCDGroupBox.png]]<br />
<br />
==Controls which imitate the Additional Palette==<br />
<br />
===TCDStaticText===<br />
<br />
==Controls which imitate the Common Controls Palette==<br />
<br />
===TCDTrackBar===<br />
<br />
A substitute for TTrackBar<br />
<br />
[[Image:TCDTrackBar.png]]<br />
<br />
===TCDProgressBar===<br />
<br />
[[Image:TCDProgressBar.png]]<br />
<br />
===TCDListView===<br />
<br />
Under construction.<br />
<br />
===TCDTabControl===<br />
<br />
A substitute for TTabControl<br />
<br />
===TCDPageControl===<br />
<br />
A substitute for TPageControl<br />
<br />
[[Image:TCDPageControl.png]]<br />
<br />
==Custom Drawn Packages==<br />
<br />
Moved here: [[Lazarus Custom Drawn Package]]<br />
<br />
==Other good custom drawn components for Lazarus==<br />
<br />
* [[VirtualTreeview]]<br />
<br />
==Maintainers==<br />
<br />
* [[User:Sekelsenmat|Felipe Monteiro de Carvalho]]<br />
* JiXian Yang<br />
<br />
== See Also ==<br />
<br />
*[[Lazarus Components Directory]]<br />
*[[Lazarus Custom Drawn Package]]<br />
*[[Custom Drawn Interface]]<br />
<br />
[[Category:Components]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=File:customdrawnwindows7.png&diff=62818File:customdrawnwindows7.png2012-10-15T17:06:56Z<p>Lainz: uploaded a new version of &quot;File:customdrawnwindows7.png&quot;</p>
<hr />
<div></div>Lainzhttps://wiki.freepascal.org/index.php?title=LazControls&diff=59129LazControls2012-05-22T16:15:31Z<p>Lainz: /* TListFilterEdit */</p>
<hr />
<div>LazControls is a set of controls that are often used in Lazarus.<br />
<br />
==TListFilterEdit==<br />
<br />
This is a control that can easily filter a ListBox.<br />
<br />
Once property TListFilterEdit.FilteredListBox is assigned then TListFilterEdit makes copy of ListBox.Items and works with it. If you add ListBox.Items.Add later, then these data does not appear in TListFilterEdit.<br />
<br />
You should do always:<br />
<br />
<syntaxhighlight><br />
TListFilterEdit.FilteredListBox:=nil;<br />
//Add data to ListBox<br />
TListFilterEdit.FilteredListBox:=ListBox;<br />
</syntaxhighlight></div>Lainzhttps://wiki.freepascal.org/index.php?title=LazControls&diff=59128LazControls2012-05-22T15:40:45Z<p>Lainz: Created page with "LazControls is a set of controls that are often used in Lazarus. ==TListFilterEdit== This is a control that can easily filter a ListBox. Once property TListFilterEdit.Filte..."</p>
<hr />
<div>LazControls is a set of controls that are often used in Lazarus.<br />
<br />
==TListFilterEdit==<br />
<br />
This is a control that can easily filter a ListBox.<br />
<br />
Once property TListFilterEdit.FilteredListBox is assigned then TListFilterEdit makes copy of ListBox.Items and works with it. If you add ListBox.Items.Add later, then these data does not appear in TListFilterEdit.<br />
<br />
You should do always:<br />
<br />
TListFilterEdit.FilteredListBox:=nil;<br />
//Add data to ListBox<br />
TListFilterEdit.FilteredListBox:=ListBox;</div>Lainzhttps://wiki.freepascal.org/index.php?title=Lazarus_Components_Directory&diff=59127Lazarus Components Directory2012-05-22T15:35:07Z<p>Lainz: /* List of Components */</p>
<hr />
<div>The "components" directory of the Lazarus source tree comes with a number of very useful components, and they are described bellow. Note that there are also other components which can be downloaded separetely from the [[Components_and_Code_examples#Lazarus-CCR_Released_Components|Lazarus Code and Component Repository]].<br />
<br />
==List of Components==<br />
<br />
*aggpas<br />
*cgi<br />
*chmhelp<br />
*codetools<br />
*compilers<br />
*custom<br />
*[[Lazarus Custom Drawn Package|customdrawn]] - An under construction package containing all kinds of custom drawn components for Lazarus.<br />
*customform<br />
*[[Daemons and Services|daemon]] - Creating background applications<br />
*datadict<br />
*dbexport<br />
*editortoolbar<br />
*[[Lazarus for education|education]] - How to setup the IDE for courses and beginners<br />
*externhelp<br />
*filebrowser<br />
*fpcunit<br />
*[[fcl-web|fpweb]] - Creating web applications with the fpWeb framework, which allows to use a same source to deploy a web application as CGI, FastCGI or as an Apache Module<br />
*h2pas<br />
*images<br />
*jcf2<br />
*[[lazcontrols]]<br />
*lazreport<br />
*lazsvnpkg<br />
*lazthread<br />
*leakview<br />
*macfiles<br />
*memds<br />
*messagecomposer<br />
*mouseandkeyinput<br />
*mpaslex<br />
*[[OpenGL|opengl]] - A windowed-control which provides an OpenGL surface<br />
*paradox<br />
*plotfunction<br />
*prettyformat<br />
*prettymessages<br />
*printers<br />
*projecttemplates<br />
*rtticontrols<br />
*rx<br />
*sdf<br />
*simpleideintf<br />
*sqldb<br />
*sqlite<br />
*[[SynEdit|synedit]] - SynEdit is an advanced multi-line edit control, which is integrated into the Lazarus.<br />
*synunihighlighter<br />
*tachart<br />
*tdbf<br />
*todolist<br />
*turbopower_ipro<br />
<br />
==See Also==<br />
<br />
*[[Lazarus_Tutorial#The_Component_Palette|LCL Components]] - A description of the main LCL controls which come installed with Lazarus, such as TMainMenu, TButton, TComboBox, TTimer, etc.<br />
<br />
<br />
[[Category:Lazarus]]<br />
[[Category:Components]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=BGRASpriteAnimation&diff=58342BGRASpriteAnimation2012-04-20T15:04:52Z<p>Lainz: /* Overview */</p>
<hr />
<div>{{BGRASpriteAnimation}}<br />
<br />
== Overview ==<br />
<br />
[[BGRASpriteAnimation]] is a graphic control developed with the [[BGRABitmap]] library. It is part of the [[BGRAControls]] package. This control is usefull to create animations from bitmaps.<br />
<br />
To use as replace of TImage just turn on the option 'AnimStatic' and you'll be able to load single images.<br />
<br />
== Beginning ==<br />
<br />
Add a new BGRASpriteAnimation from the "BGRA Controls" component tab.<br />
<br />
The next step is to load a "sprite". A sprite is a bitmap that contains all the frames of an animation. To load a sprite select "BGRASpriteAnimation1". In the Object Inspector click on the property "Sprite (TBitmap)[...]". Load the sprite the same way as you load any other bitmap.<br />
<br />
This is the sprite we will use to explain how the component works:<br />
<br />
[[Image:bgraspriteanimation_main_sprite.png]]<br />
<br />
We can say the sprite dimensions are 100x500 px. It has 5 frames, so each frame is 100x100 px.<br />
<br />
The next step is to tell the component that the sprite has 5 frames. To set the number of frames in the Object Inspector click on the property "SpriteCount" and set the value to 5.<br />
<br />
Now you can run the application and see the resulting animation.<br />
<br />
== Animation ==<br />
<br />
The animation properties are AnimInvert, AnimPosition, AnimRepeat, AnimRepeatLap, AnimSpeed & AnimStatic.<br />
<br />
'''AnimInvert:''' By default the animation is played from AnimPosition to SpriteCount. If you set AnimInvert to True the animation will be played inversely, that is from the last frame to the first.<br />
<br />
'''AnimPosition:''' The position of the frame in the animation.<br />
<br />
'''AnimRepeat:''' The number of times the animation will be played. Set 0 for infinite.<br />
<br />
'''AnimRepeatLap:''' The number of times the animation was played. If it reaches the value of AnimRepeat the animation will stop.<br />
<br />
'''AnimSpeed:''' The speed in milliseconds between frames.<br />
<br />
'''AnimStatic:''' Use to start & stop the animation.<br />
<br />
== Sprite ==<br />
<br />
The sprite properties are Sprite, SpriteCount, SpriteFillOpacity, SpriteFlipMode, SpriteKeyColor, SpriteResampleFilter, SpriteResampleMode, SpriteRotation.<br />
<br />
'''Sprite:''' A bitmap that contains all the frames of the animation.<br />
<br />
'''SpriteCount:''' A number that indicates the amount of frames of the sprite.<br />
<br />
The following properties are sprite modifications.<br />
<br />
'''SpriteFillOpacity:''' The amount of opacity from 0 to 255.<br />
<br />
'''SpriteFlipMode:''' Flip none, horizontal, vertical or both. <br />
<br />
'''SpriteKeyColor:''' The color that will be replaced with transparency.<br />
<br />
'''SpriteResampleFilter:''' The filter that will be used on resizing.<br />
<br />
'''SpriteResampleMode:''' If you choose FineResample the selected resample filter will be used.<br />
<br />
'''SpriteRotation:''' Rotation none, clockwise, counterclockwise.<br />
<br />
== Events ==<br />
<br />
OnRedrawBefore, OnRedrawAfter, OnPositionChanging, OnPositionChanged, OnLapChanging, OnLapChanged in that order.<br />
<br />
The following events are specific to sprites.<br />
<br />
'''OnRedrawBefore:''' This fires before applying the sprite modifications.<br />
<br />
'''OnRedrawAfter:''' This fires after applying the sprite modifications, but before applying resample.<br />
<br />
The following events are specific to animation.<br />
<br />
'''OnPositionChanging:''' This fires before the animation changes the AnimPosition value.<br />
<br />
'''OnPositionChanged:''' This fires when the AnimPosition value has changed (by the animation or by the user).<br />
<br />
'''OnLapChanging:''' This fires before the animation changes the AnimRepeatLap value.<br />
<br />
'''OnLapChanged:''' This fires when the AnimRepeatLap value has changed (by the animation or by the user).<br />
<br />
[[Category: Graphics]] [[Category: Components]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=BGRASpriteAnimation&diff=58341BGRASpriteAnimation2012-04-20T15:04:31Z<p>Lainz: /* Overview */</p>
<hr />
<div>{{BGRASpriteAnimation}}<br />
<br />
== Overview ==<br />
<br />
[[BGRASpriteAnimation]] is a graphic control developed with the [[BGRABitmap]] library. It is part of the [[BGRAControls]] package. This control is usefull to create animations from bitmaps.<br />
<br />
To use as replace of TPicture just turn on the option 'AnimStatic' and you'll be able to load single images.<br />
<br />
== Beginning ==<br />
<br />
Add a new BGRASpriteAnimation from the "BGRA Controls" component tab.<br />
<br />
The next step is to load a "sprite". A sprite is a bitmap that contains all the frames of an animation. To load a sprite select "BGRASpriteAnimation1". In the Object Inspector click on the property "Sprite (TBitmap)[...]". Load the sprite the same way as you load any other bitmap.<br />
<br />
This is the sprite we will use to explain how the component works:<br />
<br />
[[Image:bgraspriteanimation_main_sprite.png]]<br />
<br />
We can say the sprite dimensions are 100x500 px. It has 5 frames, so each frame is 100x100 px.<br />
<br />
The next step is to tell the component that the sprite has 5 frames. To set the number of frames in the Object Inspector click on the property "SpriteCount" and set the value to 5.<br />
<br />
Now you can run the application and see the resulting animation.<br />
<br />
== Animation ==<br />
<br />
The animation properties are AnimInvert, AnimPosition, AnimRepeat, AnimRepeatLap, AnimSpeed & AnimStatic.<br />
<br />
'''AnimInvert:''' By default the animation is played from AnimPosition to SpriteCount. If you set AnimInvert to True the animation will be played inversely, that is from the last frame to the first.<br />
<br />
'''AnimPosition:''' The position of the frame in the animation.<br />
<br />
'''AnimRepeat:''' The number of times the animation will be played. Set 0 for infinite.<br />
<br />
'''AnimRepeatLap:''' The number of times the animation was played. If it reaches the value of AnimRepeat the animation will stop.<br />
<br />
'''AnimSpeed:''' The speed in milliseconds between frames.<br />
<br />
'''AnimStatic:''' Use to start & stop the animation.<br />
<br />
== Sprite ==<br />
<br />
The sprite properties are Sprite, SpriteCount, SpriteFillOpacity, SpriteFlipMode, SpriteKeyColor, SpriteResampleFilter, SpriteResampleMode, SpriteRotation.<br />
<br />
'''Sprite:''' A bitmap that contains all the frames of the animation.<br />
<br />
'''SpriteCount:''' A number that indicates the amount of frames of the sprite.<br />
<br />
The following properties are sprite modifications.<br />
<br />
'''SpriteFillOpacity:''' The amount of opacity from 0 to 255.<br />
<br />
'''SpriteFlipMode:''' Flip none, horizontal, vertical or both. <br />
<br />
'''SpriteKeyColor:''' The color that will be replaced with transparency.<br />
<br />
'''SpriteResampleFilter:''' The filter that will be used on resizing.<br />
<br />
'''SpriteResampleMode:''' If you choose FineResample the selected resample filter will be used.<br />
<br />
'''SpriteRotation:''' Rotation none, clockwise, counterclockwise.<br />
<br />
== Events ==<br />
<br />
OnRedrawBefore, OnRedrawAfter, OnPositionChanging, OnPositionChanged, OnLapChanging, OnLapChanged in that order.<br />
<br />
The following events are specific to sprites.<br />
<br />
'''OnRedrawBefore:''' This fires before applying the sprite modifications.<br />
<br />
'''OnRedrawAfter:''' This fires after applying the sprite modifications, but before applying resample.<br />
<br />
The following events are specific to animation.<br />
<br />
'''OnPositionChanging:''' This fires before the animation changes the AnimPosition value.<br />
<br />
'''OnPositionChanged:''' This fires when the AnimPosition value has changed (by the animation or by the user).<br />
<br />
'''OnLapChanging:''' This fires before the animation changes the AnimRepeatLap value.<br />
<br />
'''OnLapChanged:''' This fires when the AnimRepeatLap value has changed (by the animation or by the user).<br />
<br />
[[Category: Graphics]] [[Category: Components]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=File:customdrawnwindows7.png&diff=58340File:customdrawnwindows7.png2012-04-20T15:00:33Z<p>Lainz: uploaded a new version of &quot;File:customdrawnwindows7.png&quot;</p>
<hr />
<div></div>Lainzhttps://wiki.freepascal.org/index.php?title=High_DPI&diff=56860High DPI2012-03-24T19:57:07Z<p>Lainz: /* Introduction */</p>
<hr />
<div>{{High DPI}}<br />
<br />
== Introduction ==<br />
DPI (dot per inch) is the relation between size in pixels and the actual display size. Here dot is an equivalent for pixel in printing terminology. Applications can either use pixel sizes, or take into account that actual display size. In this second cases, sizes are given in points.<br />
<br />
On Windows Vista and further, it is possible to change the DPI ratio to make elements bigger. High DPI means any custom DPI setting with more than 96 DPI (the default setting) [http://msdn.microsoft.com/en-us/library/ee318406(VS.85).aspx *].<br />
<br />
High DPI awareness means that an application takes this DPI setting into account. This article was designed for Windows 7, for Windows 8 Metro Applications read this http://blogs.msdn.com/b/b8/archive/2012/03/21/scaling-to-different-screens.aspx<br />
<br />
'''Pixels and points'''<br />
<br />
For example '''300 DPI''' means that there are 300 pixels (or dot) per inch. There are 72 points per inch, so :<br />
<br />
300 pixels ↔ 1 inch<br />
<br />
300/72 pixels ↔ 1 point<br />
<br />
4.16 pixels ↔ 1 point<br />
<br />
'''Now with 96 DPI :'''<br />
<br />
72 pixels ↔ 1 inch<br />
<br />
1.33 pixel ↔ 1 point<br />
<br />
'''Now with 144 DPI :'''<br />
<br />
144 pixels ↔ 1 inch<br />
<br />
2 pixels ↔ 1 point<br />
<br />
== Example - Fixed Font Sizes (not HighDPI) ==<br />
<br />
Here is a form with an undefined font size (set to zero, which is the default value). Designed in 96 DPI (100%), it looks like this :<br />
<br />
[[Image:Testdpi100.png]]<br />
<br />
Now, with 120 DPI (125%), it becomes :<br />
<br />
[[Image:Testdpi125.png]]<br />
<br />
As you can see, the font gets bigger and clipped, the window title gets bigger, but the client area of the window keeps the same size. Note that these change of size can occur by using an application with different windows theme, or with another operating system.<br />
<br />
To avoid this, set the font size to a non-zero value. Note that Font.Size is expressed in points and Font.Height is expressed in pixels. In fact, the value of Font.Height only is stored, and Font.Size changes according to current DPI value. So if we set the font size, it will be fixed to a certain size in pixels.<br />
<br />
If we try again with a fixed font size of 9 points in 96 DPI (100%), we get this :<br />
<br />
[[Image:Testdpi100fixedM12P9.png]]<br />
<br />
Now if the same program is run in 120 DPI (125%), it becomes :<br />
<br />
[[Image:Testdpi125fixedM12P9.png]]<br />
<br />
The result is the almost the same. The title bar is bigger, but the client area and the font size is the same. Note that in fact, the size in points of the font has changed.<br />
<br />
As a conclusion, it is possible to avoid inconsistence in the display by fixing font sizes. But we do not take into account that the graphical elements may be smaller according to actual DPI of the screen. With DPI awareness, it is possible to make application behave as if they new the real size of the pixels.<br />
<br />
== Setting High DPI under Windows ==<br />
<br />
'''Windows Vista / Windows 7'''<br />
<br />
In Windows 7 go to Control Panel > Appareance and Personalization > Display.<br />
<br />
Select Smaller 100% (default), Medium 125% or Larger 150%. If you select 100% (96 DPI) is the default Windows DPI setting, not High DPI.<br />
<br />
If you select 125% (120 DPI) the option "Use Windows XP style DPI scaling" is enabled, applications you run under this setting are scaled like at Windows XP.<br />
<br />
If you select 150% (144 DPI) the option "Use Windows XP style DPI scaling" is disabled (DPI Virtualization enabled), applications you run under this setting must be High DPI Awareness else they will be scaled by the system like a blurred image.<br />
<br />
Also you can set your custom DPI setting in the option "Set custom text size (DPI)" and enable/disable the DPI Virtualization.<br />
<br />
== Example - DPI Aware Application (For Vista +) ==<br />
<br />
[http://sourceforge.net/projects/cpicksniff2/ CPickSniff] is an application to capture screen colors. We will use it as an example to see how High DPI works in Windows.<br />
<br />
'''Default DPI'''<br />
<br />
This is the app running at 96 DPI (100%). It's the default mode, when scaling isn't necessary.<br />
<br />
[[Image:cpicksniff_defaultdpi.png]]<br />
<br />
'''Windows DPI Scaling'''<br />
<br />
This is same app running at 144 DPI (150%) without manifest, so Windows scales it like a bitmap. The result is a blurred image.<br />
<br />
[[Image:cpicksniff_blured.png]]<br />
<br />
'''With Manifest'''<br />
<br />
Running at 144 DPI (150%). This time the app includes manifest but the application contains no code to handle scaling. Items aren't scaled whereas font are scaled (Windows does it automatically), so text is clipped.<br />
<br />
[[Image:cpicksniff_nohighdpi.png]]<br />
<br />
'''High DPI'''<br />
<br />
Finally with manifest and scaling handler, the app is in High DPI.<br />
<br />
[[Image:cpicksniff_highdpi.png]]<br />
<br />
=== STEP 1 - Declare High DPI Awareness ===<br />
To do this we need a manifest file that includes the declaration, with Lazarus 0.9.30 we can do this going to Options > Project Options > then select the options "Use Manifest to Enable Themes (Windows)" and "Dpi Aware application (for Vista +)".<br />
<br />
=== STEP 2 - Scale Forms and Controls ===<br />
To do this we can call ScaleDPI procedure OnCreate event of each form in your project.<br />
<br />
First copy the below code and save to a text file "uscaledpi.pas":<br />
<br />
<syntaxhighlight>unit uscaledpi;<br />
<br />
{$mode objfpc}{$H+}<br />
<br />
interface<br />
<br />
uses<br />
Forms, Graphics, Controls;<br />
<br />
procedure HighDPI(FromDPI: integer);<br />
procedure ScaleDPI(Control: TControl; FromDPI: integer);<br />
<br />
implementation<br />
<br />
procedure HighDPI(FromDPI: integer);<br />
var<br />
i: integer;<br />
begin<br />
if Screen.PixelsPerInch = FromDPI then<br />
exit;<br />
<br />
for i := 0 to Screen.FormCount - 1 do<br />
ScaleDPI(Screen.Forms[i], FromDPI);<br />
end;<br />
<br />
procedure ScaleDPI(Control: TControl; FromDPI: integer);<br />
var<br />
i: integer;<br />
WinControl: TWinControl;<br />
begin<br />
if Screen.PixelsPerInch = FromDPI then<br />
exit;<br />
<br />
with Control do<br />
begin<br />
Left := ScaleX(Left, FromDPI);<br />
Top := ScaleY(Top, FromDPI);<br />
Width := ScaleX(Width, FromDPI);<br />
Height := ScaleY(Height, FromDPI);<br />
end;<br />
<br />
if Control is TWinControl then<br />
begin<br />
WinControl := TWinControl(Control);<br />
if WinControl.ControlCount = 0 then<br />
exit;<br />
for i := 0 to WinControl.ControlCount - 1 do<br />
ScaleDPI(WinControl.Controls[i], FromDPI);<br />
end;<br />
end;<br />
<br />
end.</syntaxhighlight><br />
<br />
Copy the "uscaledpi.pas" file to the main folder of your project:<br />
<br />
MyProject\uscaledpi.pas<br />
<br />
In the "uses" section of your project you need to add "uScaleDPI":<br />
<br />
<syntaxhighlight>unit form1;<br />
<br />
{$mode objfpc}{$H+}<br />
<br />
interface<br />
<br />
uses<br />
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,<br />
uScaleDPI; // This includes ScaleDPI procedure </syntaxhighlight><br />
<br />
The OnCreate event of each form calls the procedure in this way:<br />
<br />
<syntaxhighlight>procedure TForm1.FormCreate(Sender: TObject);<br />
begin<br />
ScaleDPI(Self,96); // 96 is the DPI you designed the Form1 <br />
end;</syntaxhighlight><br />
<br />
'''Scale All Forms'''<br />
<br />
You can resize all forms at once without having to go to the event on create.<br />
<br />
In order to do this open your project source (typically the ''Project1''.lpr file) and add uScaleDPI in the uses clause.<br />
<br />
Then call the procedure ''HighDPI'' below the code that initializes the forms:<br />
<br />
<syntaxhighlight>begin<br />
RequireDerivedFormResource := True;<br />
Application.Initialize;<br />
Application.CreateForm(TForm1, Form1);<br />
Application.CreateForm(TForm2, Form2);<br />
Application.CreateForm(TForm3, Form3);<br />
HighDPI(96); // 96 is the DPI you designed the Form1, Form2 & Form3<br />
Application.Run;<br />
end.</syntaxhighlight><br />
<br />
The result looks like this:<br />
<br />
<syntaxhighlight>program Project1;<br />
<br />
{$mode objfpc}{$H+}<br />
<br />
uses<br />
{$IFDEF UNIX}{$IFDEF UseCThreads}<br />
cthreads,<br />
{$ENDIF}{$ENDIF}<br />
Interfaces, Forms,<br />
Unit1, Unit2, Unit3,<br />
uScaleDPI;<br />
<br />
{$R *.res}<br />
<br />
begin<br />
RequireDerivedFormResource := True;<br />
Application.Initialize;<br />
Application.CreateForm(TForm1, Form1);<br />
Application.CreateForm(TForm2, Form2);<br />
Application.CreateForm(TForm3, Form3);<br />
HighDPI(96);<br />
Application.Run;<br />
end.</syntaxhighlight><br />
<br />
'''Advanced'''<br />
<br />
Some controls have more properties or different property names like TToolBar buttons (ButtonHeight / ButtonWidth instead Width / Height). Also if you use fixed font sizes the behavior can change in different os's.<br />
<br />
You can edit the ScaleDPI procedure to include a code to scale all controls in the way you want.<br />
<br />
This is the ''uscaledpi'' used in [[LazPaint]]. This is very usefull to scale ToolBars and ToolBox.<br />
<br />
This is not the final High DPI unit, for example you can use under Windows different LCL widgets, like Qt and this can change the final result.<br />
<br />
'''Link:''' [http://lazpaint.svn.sourceforge.net/viewvc/lazpaint/lazpaint/uscaledpi.pas?view=log uscaledpi.pas in LazPaint]<br />
<br />
== Example - Using AutoSize ==<br />
<br />
You can enable the 'AutoSize' option for each control you have (including Forms). Then test it under the different DPI modes, with different 'skinning' themes (if available in your target OS) and different font sizes. It can be very usefull, some Lazarus IDE HighDPI issues was solved using this technique.<br />
<br />
For example using the default AutoSize and ChildSizing most of the controls can be automatically sized and positioned. But the spacing must be scaled:<br />
<br />
<syntaxhighlight> with WinControl.ChildSizing do<br />
begin<br />
HorizontalSpacing := ScaleX(HorizontalSpacing, FromDPI);<br />
LeftRightSpacing := ScaleX(LeftRightSpacing, FromDPI);<br />
TopBottomSpacing := ScaleY(TopBottomSpacing, FromDPI);<br />
VerticalSpacing := ScaleY(VerticalSpacing, FromDPI);<br />
end; <br />
</syntaxhighlight><br />
<br />
More information:<br />
<br />
* [[Autosize_/_Layout]]<br />
<br />
* [[LCL_AutoSizing]]<br />
<br />
== External Links ==<br />
<br />
*[http://msdn.microsoft.com/en-us/library/dd464646(v=VS.85).aspx High DPI (Windows)] MSDN article about High DPI<br />
*[http://msdn.microsoft.com/en-us/library/windows/apps/hh465362 Guidelines for scaling] Windows Dev Center - User experience guidelines for scaling Metro style apps<br />
*[[Windows Icon]] How to create icons that work with High DPI.<br />
<br />
[[Category:Tutorials]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=High_DPI&diff=56070High DPI2012-03-13T17:55:27Z<p>Lainz: /* Example - Using AutoSize */</p>
<hr />
<div>{{High DPI}}<br />
<br />
== Introduction ==<br />
DPI (dot per inch) is the relation between size in pixels and the actual display size. Here dot is an equivalent for pixel in printing terminology. Applications can either use pixel sizes, or take into account that actual display size. In this second cases, sizes are given in points.<br />
<br />
On Windows Vista and further, it is possible to change the DPI ratio to make elements bigger. High DPI means any custom DPI setting with more than 96 DPI (the default setting) [http://msdn.microsoft.com/en-us/library/ee318406(VS.85).aspx *].<br />
<br />
High DPI awareness means that an application takes this DPI setting into account.<br />
<br />
'''Pixels and points'''<br />
<br />
For example '''300 DPI''' means that there are 300 pixels (or dot) per inch. There are 72 points per inch, so :<br />
<br />
300 pixels ↔ 1 inch<br />
<br />
300/72 pixels ↔ 1 point<br />
<br />
4.16 pixels ↔ 1 point<br />
<br />
'''Now with 96 DPI :'''<br />
<br />
72 pixels ↔ 1 inch<br />
<br />
1.33 pixel ↔ 1 point<br />
<br />
'''Now with 144 DPI :'''<br />
<br />
144 pixels ↔ 1 inch<br />
<br />
2 pixels ↔ 1 point<br />
<br />
== Example - Fixed Font Sizes (not HighDPI) ==<br />
<br />
Here is a form with an undefined font size (set to zero, which is the default value). Designed in 96 DPI (100%), it looks like this :<br />
<br />
[[Image:Testdpi100.png]]<br />
<br />
Now, with 120 DPI (125%), it becomes :<br />
<br />
[[Image:Testdpi125.png]]<br />
<br />
As you can see, the font gets bigger and clipped, the window title gets bigger, but the client area of the window keeps the same size. Note that these change of size can occur by using an application with different windows theme, or with another operating system.<br />
<br />
To avoid this, set the font size to a non-zero value. Note that Font.Size is expressed in points and Font.Height is expressed in pixels. In fact, the value of Font.Height only is stored, and Font.Size changes according to current DPI value. So if we set the font size, it will be fixed to a certain size in pixels.<br />
<br />
If we try again with a fixed font size of 9 points in 96 DPI (100%), we get this :<br />
<br />
[[Image:Testdpi100fixedM12P9.png]]<br />
<br />
Now if the same program is run in 120 DPI (125%), it becomes :<br />
<br />
[[Image:Testdpi125fixedM12P9.png]]<br />
<br />
The result is the almost the same. The title bar is bigger, but the client area and the font size is the same. Note that in fact, the size in points of the font has changed.<br />
<br />
As a conclusion, it is possible to avoid inconsistence in the display by fixing font sizes. But we do not take into account that the graphical elements may be smaller according to actual DPI of the screen. With DPI awareness, it is possible to make application behave as if they new the real size of the pixels.<br />
<br />
== Setting High DPI under Windows ==<br />
<br />
'''Windows Vista / Windows 7'''<br />
<br />
In Windows 7 go to Control Panel > Appareance and Personalization > Display.<br />
<br />
Select Smaller 100% (default), Medium 125% or Larger 150%. If you select 100% (96 DPI) is the default Windows DPI setting, not High DPI.<br />
<br />
If you select 125% (120 DPI) the option "Use Windows XP style DPI scaling" is enabled, applications you run under this setting are scaled like at Windows XP.<br />
<br />
If you select 150% (144 DPI) the option "Use Windows XP style DPI scaling" is disabled (DPI Virtualization enabled), applications you run under this setting must be High DPI Awareness else they will be scaled by the system like a blurred image.<br />
<br />
Also you can set your custom DPI setting in the option "Set custom text size (DPI)" and enable/disable the DPI Virtualization.<br />
<br />
== Example - DPI Aware Application (For Vista +) ==<br />
<br />
[http://sourceforge.net/projects/cpicksniff2/ CPickSniff] is an application to capture screen colors. We will use it as an example to see how High DPI works in Windows.<br />
<br />
'''Default DPI'''<br />
<br />
This is the app running at 96 DPI (100%). It's the default mode, when scaling isn't necessary.<br />
<br />
[[Image:cpicksniff_defaultdpi.png]]<br />
<br />
'''Windows DPI Scaling'''<br />
<br />
This is same app running at 144 DPI (150%) without manifest, so Windows scales it like a bitmap. The result is a blurred image.<br />
<br />
[[Image:cpicksniff_blured.png]]<br />
<br />
'''With Manifest'''<br />
<br />
Running at 144 DPI (150%). This time the app includes manifest but the application contains no code to handle scaling. Items aren't scaled whereas font are scaled (Windows does it automatically), so text is clipped.<br />
<br />
[[Image:cpicksniff_nohighdpi.png]]<br />
<br />
'''High DPI'''<br />
<br />
Finally with manifest and scaling handler, the app is in High DPI.<br />
<br />
[[Image:cpicksniff_highdpi.png]]<br />
<br />
=== STEP 1 - Declare High DPI Awareness ===<br />
To do this we need a manifest file that includes the declaration, with Lazarus 0.9.30 we can do this going to Options > Project Options > then select the options "Use Manifest to Enable Themes (Windows)" and "Dpi Aware application (for Vista +)".<br />
<br />
=== STEP 2 - Scale Forms and Controls ===<br />
To do this we can call ScaleDPI procedure OnCreate event of each form in your project.<br />
<br />
First copy the below code and save to a text file "uscaledpi.pas":<br />
<br />
<delphi>unit uscaledpi;<br />
<br />
{$mode objfpc}{$H+}<br />
<br />
interface<br />
<br />
uses<br />
Forms, Graphics, Controls;<br />
<br />
procedure HighDPI(FromDPI: integer);<br />
procedure ScaleDPI(Control: TControl; FromDPI: integer);<br />
<br />
implementation<br />
<br />
procedure HighDPI(FromDPI: integer);<br />
var<br />
i: integer;<br />
begin<br />
if Screen.PixelsPerInch = FromDPI then<br />
exit;<br />
<br />
for i := 0 to Screen.FormCount - 1 do<br />
ScaleDPI(Screen.Forms[i], FromDPI);<br />
end;<br />
<br />
procedure ScaleDPI(Control: TControl; FromDPI: integer);<br />
var<br />
i: integer;<br />
WinControl: TWinControl;<br />
begin<br />
if Screen.PixelsPerInch = FromDPI then<br />
exit;<br />
<br />
with Control do<br />
begin<br />
Left := ScaleX(Left, FromDPI);<br />
Top := ScaleY(Top, FromDPI);<br />
Width := ScaleX(Width, FromDPI);<br />
Height := ScaleY(Height, FromDPI);<br />
end;<br />
<br />
if Control is TWinControl then<br />
begin<br />
WinControl := TWinControl(Control);<br />
if WinControl.ControlCount = 0 then<br />
exit;<br />
for i := 0 to WinControl.ControlCount - 1 do<br />
ScaleDPI(WinControl.Controls[i], FromDPI);<br />
end;<br />
end;<br />
<br />
end.</delphi><br />
<br />
Copy the "uscaledpi.pas" file to the main folder of your project:<br />
<br />
MyProject\uscaledpi.pas<br />
<br />
In the "uses" section of your project you need to add "uScaleDPI":<br />
<br />
<delphi>unit form1;<br />
<br />
{$mode objfpc}{$H+}<br />
<br />
interface<br />
<br />
uses<br />
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,<br />
uScaleDPI; // This includes ScaleDPI procedure </delphi><br />
<br />
The OnCreate event of each form calls the procedure in this way:<br />
<br />
<delphi>procedure TForm1.FormCreate(Sender: TObject);<br />
begin<br />
ScaleDPI(Self,96); // 96 is the DPI you designed the Form1 <br />
end;</delphi><br />
<br />
'''Scale All Forms'''<br />
<br />
You can resize all forms at once without having to go to the event on create.<br />
<br />
In order to do this open your project source (typically the ''Project1''.lpr file) and add uScaleDPI in the uses clause.<br />
<br />
Then call the procedure ''HighDPI'' below the code that initializes the forms:<br />
<br />
<delphi>begin<br />
RequireDerivedFormResource := True;<br />
Application.Initialize;<br />
Application.CreateForm(TForm1, Form1);<br />
Application.CreateForm(TForm2, Form2);<br />
Application.CreateForm(TForm3, Form3);<br />
HighDPI(96); // 96 is the DPI you designed the Form1, Form2 & Form3<br />
Application.Run;<br />
end.</delphi><br />
<br />
The result looks like this:<br />
<br />
<delphi>program Project1;<br />
<br />
{$mode objfpc}{$H+}<br />
<br />
uses<br />
{$IFDEF UNIX}{$IFDEF UseCThreads}<br />
cthreads,<br />
{$ENDIF}{$ENDIF}<br />
Interfaces, Forms,<br />
Unit1, Unit2, Unit3,<br />
uScaleDPI;<br />
<br />
{$R *.res}<br />
<br />
begin<br />
RequireDerivedFormResource := True;<br />
Application.Initialize;<br />
Application.CreateForm(TForm1, Form1);<br />
Application.CreateForm(TForm2, Form2);<br />
Application.CreateForm(TForm3, Form3);<br />
HighDPI(96);<br />
Application.Run;<br />
end.</delphi><br />
<br />
'''Advanced'''<br />
<br />
Some controls have more properties or different property names like TToolBar buttons (ButtonHeight / ButtonWidth instead Width / Height). Also if you use fixed font sizes the behavior can change in different os's.<br />
<br />
You can edit the ScaleDPI procedure to include a code to scale all controls in the way you want.<br />
<br />
This is the ''uscaledpi'' used in [[LazPaint]]. This is very usefull to scale ToolBars and ToolBox.<br />
<br />
This is not the final High DPI unit, for example you can use under Windows different LCL widgets, like Qt and this can change the final result.<br />
<br />
'''Link:''' [http://lazpaint.svn.sourceforge.net/viewvc/lazpaint/lazpaint/uscaledpi.pas?view=log uscaledpi.pas in LazPaint]<br />
<br />
== Example - Using AutoSize ==<br />
<br />
You can enable the 'AutoSize' option for each control you have (including Forms). Then test it under the different DPI modes, with different 'skinning' themes (if available in your target OS) and different font sizes. It can be very usefull, some Lazarus IDE HighDPI issues was solved using this technique.<br />
<br />
For example using the default AutoSize and ChildSizing most of the controls can be automatically sized and positioned. But the spacing must be scaled:<br />
<br />
<delphi> with WinControl.ChildSizing do<br />
begin<br />
HorizontalSpacing := ScaleX(HorizontalSpacing, FromDPI);<br />
LeftRightSpacing := ScaleX(LeftRightSpacing, FromDPI);<br />
TopBottomSpacing := ScaleY(TopBottomSpacing, FromDPI);<br />
VerticalSpacing := ScaleY(VerticalSpacing, FromDPI);<br />
end; <br />
</delphi><br />
<br />
More information:<br />
<br />
* [[Autosize_/_Layout]]<br />
<br />
* [[LCL_AutoSizing]]<br />
<br />
== External Links ==<br />
<br />
*[http://msdn.microsoft.com/en-us/library/dd464646(v=VS.85).aspx High DPI (Windows)] MSDN article about High DPI<br />
*[http://msdn.microsoft.com/en-us/library/windows/apps/hh465362 Guidelines for scaling] Windows Dev Center - User experience guidelines for scaling Metro style apps<br />
*[[Windows Icon]] How to create icons that work with High DPI.<br />
<br />
[[Category:Tutorials]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=BGRAControls&diff=56025BGRAControls2012-03-09T15:56:33Z<p>Lainz: /* Overview */</p>
<hr />
<div>{{BGRAControls}}<br />
<br />
== Install ==<br />
<br />
You can use TortoiseSVN to download the svn repository and TortoiseGIT to download the git repository.<br />
<br />
We're using BGRABitmap SVN to develop BGRAControls. Important changes in BGRABitmap can stop working BGRAControls.<br />
<br />
'''1) Download BGRABitmap'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/lazpaint/files/src/<br />
<br />
'''Latest SVN:''' svn co https://lazpaint.svn.sourceforge.net/svnroot/lazpaint lazpaint<br />
<br />
Install BGRABitmap with the file bgrabitmap.lpk<br />
<br />
'''2) Download BGRAControls'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/bgracontrols/files/<br />
<br />
''SVN''<br />
<br />
'''SVN Browse:''' http://bgracontrols.svn.sourceforge.net/viewvc/bgracontrols/<br />
<br />
'''SVN Checkout:''' svn co https://bgracontrols.svn.sourceforge.net/svnroot/bgracontrols bgracontrols<br />
<br />
''GIT''<br />
<br />
'''GIT Browse:''' http://bgracontrols.git.sourceforge.net/git/gitweb-index.cgi<br />
<br />
'''GIT Checkout:''' git://bgracontrols.git.sourceforge.net/gitroot/bgracontrols/bgracontrols <br />
<br />
Install BGRAControls with the file bgracontrols.lpk<br />
<br />
== Overview ==<br />
<br />
'''Authors:''' <br />
<br />
Dibo (package founder and maintainer, author: ''TBGRAImageList'', ''TBGRASpeedButton'', ''TBGRAButton'', ''TBGRAPanel'')<br />
<br />
Lainz (package maintainer, author: ''TBGRAImageButton'', ''TBGRAImageToggleBox'', ''TBGRASpriteAnimation'', ''TBGRALabelFX'', ''TBGRAWin7ToolBar'', ''TBGRANeoButton'', ''Windows 7 Drawer'' and some other stuff)<br />
<br />
Circular (package maintainer, author: ''TBGRAKnob'', ''TBGRAFlashProgressBar'', ''TBGRAVirtualScreen'', ''TBGRAShape'', ''TBGRAGraphicControl'')<br />
<br />
Emerson Cavalcanti (author: ''TBGRAImageManipulation'')<br />
<br />
codedeep (author: ''TBGRALabel'')<br />
<br />
'''License:''' Modified LGPL.<br />
<br />
As many people know, Lazarus GTK doesn't have full alpha support. I created a set of components which use TBGRABitmap for drawing icons, so it partially solves the problem with alpha in GTK. But this components set is not only a GTK patch but has more fancy components which are using the power of the BGRABitmap package.<br />
<br />
'''Screenshots:''' Some shots of the project 'testbgracontrols'.<br />
<br />
[[Image:testbgrac1.png]]<br />
<br />
''testbgracontrols > Main.''<br />
<br />
[[Image:testbgrac2.png]]<br />
<br />
''testbgracontrols > Windows 7 ToolBar.''<br />
<br />
[[Image:testbgrac4.png]]<br />
<br />
''testbgracontrols > Ribbon.''<br />
<br />
== Related Articles ==<br />
<br />
[[BGRAButton Gallery]] - Gallery of buttons with source code to use in your projects with BGRAButton.<br />
<br />
[[BGRASpriteAnimation]] - Usage of the sprite animation component.<br />
<br />
[[uE_Controls]] - Other controls developed with BGRABitmap.<br />
<br />
[[BGRABitmap]] - The library used to create this controls.<br />
<br />
[[LazPaint]] - A paint program developed with Lazarus and BGRABitmap.<br />
<br />
== Using ==<br />
<br />
Drop and use like normal component.<br />
<br />
'''Button''':<br />
* TBGRAButton<br />
* TBGRAImageButton<br />
* TBGRAImageToggleBox<br />
* TBGRASpeedButton<br />
<br />
'''Label'''<br />
* TBGRALabel<br />
* TBGRALabelFX<br />
<br />
'''Panel'''<br />
* TBGRAPanel<br />
* TBGRAVirtualScreen<br />
<br />
'''Image'''<br />
* TBGRAGraphicControl<br />
* TBGRAImageList<br />
* TBGRAImageManipulation<br />
* TBGRASpriteAnimation<br />
<br />
'''Other'''<br />
* TBGRAFlashProgressBar<br />
* TBGRAKnob<br />
* TBGRAShape<br />
* TBGRAWin7ToolBar<br />
<br />
== TBGRAImageList ==<br />
<br />
'''Use as replace of:''' TImageList<br />
<br />
'''Before:'''<br />
<br />
[[Image:before-TImageList.png]]<br />
<br />
'''After:'''<br />
<br />
[[Image:after-TBGRAImageList.png]]<br />
<br />
Component which inherits from TImageList. So each control (tested on TToolBar and TTreeView) which is using TImageList.Draw method for drawing icons, automatically can have alpha support. Just use this component instead of TImageList. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRASpeedButton ==<br />
<br />
'''Use as replace of:''' TSpeedButton<br />
<br />
[[Image:BGRASpeedButton.png]]<br />
<br />
Component which inherits from TSpeedButton and draws the glyph using TBGRABitmap. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRAButton ==<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgrabutton.png]]<br />
<br />
Customizable graphic component which is using only BGRABitmap functions for drawing. This component is insensitive for -dGTK_ONLY switch. Demo project included in package.<br />
<br />
'''Functionality:'''<br />
* Gradient, Clear or Color body. [[Double_Gradient]].<br />
* Text with shadow: BGRA antialias or like system default with ClearType.<br />
* Rounded border, inner Light.<br />
* States: normal, hover & clicked fully customizable and grayscale disabled state.<br />
* Special: Down, DropDown, Static.<br />
* Full AutoSize working with Glyph.<br />
<br />
== TBGRAPanel ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
Simple TPanel descendant which can have gradient background. Created especially for TBGRAButton (for creating a nice looking toolbar for bgrabuttons). This component is insensitive for -dGTK_ONLY switch<br />
<br />
== TBGRAKnob ==<br />
[[Image:BC-Bgraknob.png]]<br />
<br />
Graphic knob component created by circular.<br />
<br />
== TBGRAFlashProgressBar ==<br />
<br />
'''Use as replace of:''' TProgressBar<br />
<br />
[[Image:BC-Bgraflashprogressbar.png]]<br />
<br />
Flash progressbar created by circular.<br />
<br />
== TBGRAImageManipulation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Component to facilitate the importation of images in an application.<br />
<br />
In the current version you can import an image and cut out keeping the aspect ratio (or not). For example, if you want to import photos using the 3x4 ratio, adjust the 'ratio' property to 3:4. If import an image with different size, the component will ensure that the image meets the proportions of the desired dimensions.<br />
<br />
You can determine the minimum size of the image adjusting the properties 'MinWidth'and 'MinHeight'.<br />
<br />
You can rotate the image using functions builtin.<br />
<br />
See demo of component:<br />
<br />
[[Image:bgraimagemanipulation.jpg]]<br />
<br />
After retrieving the image modified by the component, just put the image into your destination using the stretch. It is obvious that the target must have the same ratio chosen on component for do not distort the final result.<br />
<br />
== TBGRAImageButton ==<br />
<br />
If you need some code to load and split an image from file, and then scale the borders like in this control you can use TBGRABitmapThemeUtils (included in BGRAControls).<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgraimagebutton.png]]<br />
<br />
Component used to create a button with 4 states from Bitmap.<br />
<br />
'''Features:'''<br />
* Load the image from the "Bitmap" property in the object inspector or load from file using "BitmapFile".<br />
<br />
// You can load bmp and also png files<br />
BGRAImageButton1.BitmapLoadFromFile(BGRAImageButton1.BitmapFile);<br />
<br />
* BitmapOptions: you can set the border pixels, resample method and fill modes. Usefull to create textured / like Windows themed buttons.<br />
* AutoSize, ModalResult.<br />
* Text with Shadow, you can disable text render with the option "TextVisible".<br />
* Sound: in mouse enter and leave in Windows from .wav files.<br />
* Toggle: you can read / set the current state with the property "Checked".<br />
* Animation: glowing effect.<br />
<br />
'''Usage:'''<br />
<br />
The bitmap must contain 4 states (from top to bottom, with the same Height) in the following order: normal, enter, pressed, disabled.<br />
<br />
If you choose to use BitmapOptions you need to have for each state an image which has a border, and inside some content that can be repeated. Then with FillCenter option (if you want a textured button), it gets repeated while the borders stay as they are. This is like the method used in Windows to theme the buttons.<br />
<br />
''Example Button:''<br />
<br />
[[Image:samplebgraimagebutton.png]]<br />
<br />
''Example Button (with Alpha):''<br />
<br />
[[Image:samplebgraimagebuttonalpha.png]]<br />
<br />
== TBGRAVirtualScreen ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
The principle is to draw on a memory bitmap.<br />
<br />
The component has a specific event, OnRedraw, which is called when the whole bitmap needs to be redrawn. It happens at the beginning, when resizing and when the Redraw method is called.<br />
<br />
Otherwise, it is possible to modify the Bitmap property and call Invalidate or Repaint, to avoid erasing the whole bitmap content.<br />
<br />
== TBGRAShape ==<br />
<br />
'''Use as replace of:''' TShape<br />
<br />
[[Image:samplebgrashape.png]]<br />
<br />
The component has full alpha support and you can put the number of polygons you want with rounded borders & gradients (linear, radial, diamond, reflected).<br />
<br />
== TBGRAImageToggleBox ==<br />
<br />
REMOVED IN VER 1.1.0.7.<br />
<br />
'''Use as replace of:''' TToggleBox<br />
<br />
Component used to create a toggle box from Bitmap.<br />
<br />
The bitmap must contain 8 images (from top to bottom, with the same Height) in the following order: unchecked normal, unchecked enter, unchecked pressed, unchecked disabled for Unchecked state and checked normal, checked enter, checked pressed, checked disabled for Normal state.<br />
<br />
''Example toggle box:''<br />
<br />
[[Image:sampletogglebox.png]]<br />
<br />
== TBGRAGraphicControl ==<br />
<br />
'''Use as replace of:''' TPaintBox<br />
<br />
TBGRAGraphicControl, which allows to draw your component by yourself with alpha blending.<br />
<br />
== TBGRASpriteAnimation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Read more in the article [[BGRASpriteAnimation]].<br />
<br />
[[Image:bgraspriteanimation.png]]<br />
<br />
With this you can do animations from bitmap. You need an image with all the frames layout in in a horizontal position.<br />
<br />
It has the ability to specify how many times the animation should be played (0 for infinite, 1, 2, etc) and static to stop the animation, is capable to specify the speed and direction and support transparency.<br />
<br />
Features:<br />
* Animation: invert, position, lap, speed, static, repeat.<br />
* Sprite: fill opacity (global transparency), flip mode (horizontal, vertical, both), key color (transparent color), resample (normal or fine resample modes). AutoSize.<br />
* AnimatedGifToSprite: convert an animated gif to a BGRABitmap sprite.<br />
<br />
== TBGRALabel ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
Label component based on TBGRAButton.<br />
<br />
Features:<br />
* Caption with shadow or not<br />
* Full alpha and antialias support or not<br />
* WordWarp or not<br />
* Caption with Property Editor Multiline<br />
<br />
== TBGRALabelFX ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
[[Image:bgralabelfx.png]]<br />
<br />
Features:<br />
* Outline<br />
* Shadow<br />
<br />
ToDo:<br />
* Use BGRATextFX multicolor, textures.<br />
* etc.<br />
<br />
== TBGRAWin7ToolBar ==<br />
<br />
[[Image:bgrawin7toolbar.png]]<br />
<br />
Is a TBGRAVirtualScreen descendant with some default child sizing, and nice Win7 ToolBar background.<br />
<br />
== BGRASamples unit ==<br />
<br />
This unit has sample drawings, styles for buttons and colors used in different UI.<br />
<br />
[[Image:ioselements.png]]<br />
<br />
* '''Accent Color:''' the colors used in the Windows Phone. The accent color can be used in TBGRAButton and TBGRAImageButton (see the different procedures).<br />
* '''Facebook button color:''' gray, green and blue, with a procedure to create an image in the normal or pressed state, also to use this style in a TBGRAImageButton.<br />
* '''TBGRASampleStyle:''' Styles for TBGRAButton ('Default', 'Flash Player', 'Windows 7 ToolBar', 'Windows 7 ToolBar Smooth', 'Windows 7', 'Office 2010', 'Mac OSX Lion', 'Windows 7 Cristal').<br />
* '''iOS Elements:''' Draw a gray bar, the blue toolbar and a tiled background, the same elements used in the iOS screen.<br />
* '''Glass:''' used in testbgracontrols, it show an image in a virtualscreen and apply blur in the buttons area.<br />
* '''Drawings:''' flash player body and toolbar, windows 7 toolbar.<br />
<br />
* Some other usefull procedures to work with TBGRAButton and TBGRAImageButton.<br />
<br />
== BGRABitmapThemeUtils ==<br />
<br />
This unit is used by BGRAImageButton to draw the button! Also it's usefull to skin controls from bitmaps. You can see how to use it in the BGRAImageButton code or in the Custom Drawn Windows 7 (included in BGRAControls).<br />
<br />
== BGRANeoButton ==<br />
<br />
This unit is an example, it's usefull to learn how to create your own button with bgrabitmap. BTW read the BGRAImageButton and BGRAButton code. All in this unit can be overriden. I've not added 'invalidate' messages in types and AutoSize, add your own according to your programming needs.<br />
<br />
== Custom Drawn Windows 7 ==<br />
<br />
[[Image:customdrawnwindows7.png]]<br />
<br />
This is a drawer for [[Lazarus Custom Drawn Controls]], you need that component installed with the latest Lazarus revision to work.<br />
<br />
Working in this drawer: button, statictext, checkbox, radiobutton and progressbar.<br />
<br />
This has also extra images for 'Luna' (Windows XP Theme) 'Aero Lite' (Windows 8 Theme) and extra buttons (arrows).<br />
<br />
[[Category:Components]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=BGRAControls&diff=56024BGRAControls2012-03-09T15:55:12Z<p>Lainz: /* Custom Drawn Windows 7 */</p>
<hr />
<div>{{BGRAControls}}<br />
<br />
== Install ==<br />
<br />
You can use TortoiseSVN to download the svn repository and TortoiseGIT to download the git repository.<br />
<br />
We're using BGRABitmap SVN to develop BGRAControls. Important changes in BGRABitmap can stop working BGRAControls.<br />
<br />
'''1) Download BGRABitmap'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/lazpaint/files/src/<br />
<br />
'''Latest SVN:''' svn co https://lazpaint.svn.sourceforge.net/svnroot/lazpaint lazpaint<br />
<br />
Install BGRABitmap with the file bgrabitmap.lpk<br />
<br />
'''2) Download BGRAControls'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/bgracontrols/files/<br />
<br />
''SVN''<br />
<br />
'''SVN Browse:''' http://bgracontrols.svn.sourceforge.net/viewvc/bgracontrols/<br />
<br />
'''SVN Checkout:''' svn co https://bgracontrols.svn.sourceforge.net/svnroot/bgracontrols bgracontrols<br />
<br />
''GIT''<br />
<br />
'''GIT Browse:''' http://bgracontrols.git.sourceforge.net/git/gitweb-index.cgi<br />
<br />
'''GIT Checkout:''' git://bgracontrols.git.sourceforge.net/gitroot/bgracontrols/bgracontrols <br />
<br />
Install BGRAControls with the file bgracontrols.lpk<br />
<br />
== Overview ==<br />
<br />
'''Authors:''' <br />
<br />
Dibo (package founder and maintainer, author: ''TBGRAImageList'', ''TBGRASpeedButton'', ''TBGRAButton'', ''TBGRAPanel'')<br />
<br />
Lainz (package maintainer, author: ''TBGRAImageButton'', ''TBGRAImageToggleBox'', ''TBGRASpriteAnimation'', ''TBGRALabelFX'', ''TBGRAWin7ToolBar'')<br />
<br />
Circular (package maintainer, author: ''TBGRAKnob'', ''TBGRAFlashProgressBar'', ''TBGRAVirtualScreen'', ''TBGRAShape'', ''TBGRAGraphicControl'')<br />
<br />
Emerson Cavalcanti (author: ''TBGRAImageManipulation'')<br />
<br />
codedeep (author: ''TBGRALabel'')<br />
<br />
'''License:''' Modified LGPL.<br />
<br />
As many people know, Lazarus GTK doesn't have full alpha support. I created a set of components which use TBGRABitmap for drawing icons, so it partially solves the problem with alpha in GTK. But this components set is not only a GTK patch but has more fancy components which are using the power of the BGRABitmap package.<br />
<br />
'''Screenshots:''' Some shots of the project 'testbgracontrols'.<br />
<br />
[[Image:testbgrac1.png]]<br />
<br />
''testbgracontrols > Main.''<br />
<br />
[[Image:testbgrac2.png]]<br />
<br />
''testbgracontrols > Windows 7 ToolBar.''<br />
<br />
[[Image:testbgrac4.png]]<br />
<br />
''testbgracontrols > Ribbon.''<br />
<br />
== Related Articles ==<br />
<br />
[[BGRAButton Gallery]] - Gallery of buttons with source code to use in your projects with BGRAButton.<br />
<br />
[[BGRASpriteAnimation]] - Usage of the sprite animation component.<br />
<br />
[[uE_Controls]] - Other controls developed with BGRABitmap.<br />
<br />
[[BGRABitmap]] - The library used to create this controls.<br />
<br />
[[LazPaint]] - A paint program developed with Lazarus and BGRABitmap.<br />
<br />
== Using ==<br />
<br />
Drop and use like normal component.<br />
<br />
'''Button''':<br />
* TBGRAButton<br />
* TBGRAImageButton<br />
* TBGRAImageToggleBox<br />
* TBGRASpeedButton<br />
<br />
'''Label'''<br />
* TBGRALabel<br />
* TBGRALabelFX<br />
<br />
'''Panel'''<br />
* TBGRAPanel<br />
* TBGRAVirtualScreen<br />
<br />
'''Image'''<br />
* TBGRAGraphicControl<br />
* TBGRAImageList<br />
* TBGRAImageManipulation<br />
* TBGRASpriteAnimation<br />
<br />
'''Other'''<br />
* TBGRAFlashProgressBar<br />
* TBGRAKnob<br />
* TBGRAShape<br />
* TBGRAWin7ToolBar<br />
<br />
== TBGRAImageList ==<br />
<br />
'''Use as replace of:''' TImageList<br />
<br />
'''Before:'''<br />
<br />
[[Image:before-TImageList.png]]<br />
<br />
'''After:'''<br />
<br />
[[Image:after-TBGRAImageList.png]]<br />
<br />
Component which inherits from TImageList. So each control (tested on TToolBar and TTreeView) which is using TImageList.Draw method for drawing icons, automatically can have alpha support. Just use this component instead of TImageList. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRASpeedButton ==<br />
<br />
'''Use as replace of:''' TSpeedButton<br />
<br />
[[Image:BGRASpeedButton.png]]<br />
<br />
Component which inherits from TSpeedButton and draws the glyph using TBGRABitmap. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRAButton ==<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgrabutton.png]]<br />
<br />
Customizable graphic component which is using only BGRABitmap functions for drawing. This component is insensitive for -dGTK_ONLY switch. Demo project included in package.<br />
<br />
'''Functionality:'''<br />
* Gradient, Clear or Color body. [[Double_Gradient]].<br />
* Text with shadow: BGRA antialias or like system default with ClearType.<br />
* Rounded border, inner Light.<br />
* States: normal, hover & clicked fully customizable and grayscale disabled state.<br />
* Special: Down, DropDown, Static.<br />
* Full AutoSize working with Glyph.<br />
<br />
== TBGRAPanel ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
Simple TPanel descendant which can have gradient background. Created especially for TBGRAButton (for creating a nice looking toolbar for bgrabuttons). This component is insensitive for -dGTK_ONLY switch<br />
<br />
== TBGRAKnob ==<br />
[[Image:BC-Bgraknob.png]]<br />
<br />
Graphic knob component created by circular.<br />
<br />
== TBGRAFlashProgressBar ==<br />
<br />
'''Use as replace of:''' TProgressBar<br />
<br />
[[Image:BC-Bgraflashprogressbar.png]]<br />
<br />
Flash progressbar created by circular.<br />
<br />
== TBGRAImageManipulation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Component to facilitate the importation of images in an application.<br />
<br />
In the current version you can import an image and cut out keeping the aspect ratio (or not). For example, if you want to import photos using the 3x4 ratio, adjust the 'ratio' property to 3:4. If import an image with different size, the component will ensure that the image meets the proportions of the desired dimensions.<br />
<br />
You can determine the minimum size of the image adjusting the properties 'MinWidth'and 'MinHeight'.<br />
<br />
You can rotate the image using functions builtin.<br />
<br />
See demo of component:<br />
<br />
[[Image:bgraimagemanipulation.jpg]]<br />
<br />
After retrieving the image modified by the component, just put the image into your destination using the stretch. It is obvious that the target must have the same ratio chosen on component for do not distort the final result.<br />
<br />
== TBGRAImageButton ==<br />
<br />
If you need some code to load and split an image from file, and then scale the borders like in this control you can use TBGRABitmapThemeUtils (included in BGRAControls).<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgraimagebutton.png]]<br />
<br />
Component used to create a button with 4 states from Bitmap.<br />
<br />
'''Features:'''<br />
* Load the image from the "Bitmap" property in the object inspector or load from file using "BitmapFile".<br />
<br />
// You can load bmp and also png files<br />
BGRAImageButton1.BitmapLoadFromFile(BGRAImageButton1.BitmapFile);<br />
<br />
* BitmapOptions: you can set the border pixels, resample method and fill modes. Usefull to create textured / like Windows themed buttons.<br />
* AutoSize, ModalResult.<br />
* Text with Shadow, you can disable text render with the option "TextVisible".<br />
* Sound: in mouse enter and leave in Windows from .wav files.<br />
* Toggle: you can read / set the current state with the property "Checked".<br />
* Animation: glowing effect.<br />
<br />
'''Usage:'''<br />
<br />
The bitmap must contain 4 states (from top to bottom, with the same Height) in the following order: normal, enter, pressed, disabled.<br />
<br />
If you choose to use BitmapOptions you need to have for each state an image which has a border, and inside some content that can be repeated. Then with FillCenter option (if you want a textured button), it gets repeated while the borders stay as they are. This is like the method used in Windows to theme the buttons.<br />
<br />
''Example Button:''<br />
<br />
[[Image:samplebgraimagebutton.png]]<br />
<br />
''Example Button (with Alpha):''<br />
<br />
[[Image:samplebgraimagebuttonalpha.png]]<br />
<br />
== TBGRAVirtualScreen ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
The principle is to draw on a memory bitmap.<br />
<br />
The component has a specific event, OnRedraw, which is called when the whole bitmap needs to be redrawn. It happens at the beginning, when resizing and when the Redraw method is called.<br />
<br />
Otherwise, it is possible to modify the Bitmap property and call Invalidate or Repaint, to avoid erasing the whole bitmap content.<br />
<br />
== TBGRAShape ==<br />
<br />
'''Use as replace of:''' TShape<br />
<br />
[[Image:samplebgrashape.png]]<br />
<br />
The component has full alpha support and you can put the number of polygons you want with rounded borders & gradients (linear, radial, diamond, reflected).<br />
<br />
== TBGRAImageToggleBox ==<br />
<br />
REMOVED IN VER 1.1.0.7.<br />
<br />
'''Use as replace of:''' TToggleBox<br />
<br />
Component used to create a toggle box from Bitmap.<br />
<br />
The bitmap must contain 8 images (from top to bottom, with the same Height) in the following order: unchecked normal, unchecked enter, unchecked pressed, unchecked disabled for Unchecked state and checked normal, checked enter, checked pressed, checked disabled for Normal state.<br />
<br />
''Example toggle box:''<br />
<br />
[[Image:sampletogglebox.png]]<br />
<br />
== TBGRAGraphicControl ==<br />
<br />
'''Use as replace of:''' TPaintBox<br />
<br />
TBGRAGraphicControl, which allows to draw your component by yourself with alpha blending.<br />
<br />
== TBGRASpriteAnimation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Read more in the article [[BGRASpriteAnimation]].<br />
<br />
[[Image:bgraspriteanimation.png]]<br />
<br />
With this you can do animations from bitmap. You need an image with all the frames layout in in a horizontal position.<br />
<br />
It has the ability to specify how many times the animation should be played (0 for infinite, 1, 2, etc) and static to stop the animation, is capable to specify the speed and direction and support transparency.<br />
<br />
Features:<br />
* Animation: invert, position, lap, speed, static, repeat.<br />
* Sprite: fill opacity (global transparency), flip mode (horizontal, vertical, both), key color (transparent color), resample (normal or fine resample modes). AutoSize.<br />
* AnimatedGifToSprite: convert an animated gif to a BGRABitmap sprite.<br />
<br />
== TBGRALabel ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
Label component based on TBGRAButton.<br />
<br />
Features:<br />
* Caption with shadow or not<br />
* Full alpha and antialias support or not<br />
* WordWarp or not<br />
* Caption with Property Editor Multiline<br />
<br />
== TBGRALabelFX ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
[[Image:bgralabelfx.png]]<br />
<br />
Features:<br />
* Outline<br />
* Shadow<br />
<br />
ToDo:<br />
* Use BGRATextFX multicolor, textures.<br />
* etc.<br />
<br />
== TBGRAWin7ToolBar ==<br />
<br />
[[Image:bgrawin7toolbar.png]]<br />
<br />
Is a TBGRAVirtualScreen descendant with some default child sizing, and nice Win7 ToolBar background.<br />
<br />
== BGRASamples unit ==<br />
<br />
This unit has sample drawings, styles for buttons and colors used in different UI.<br />
<br />
[[Image:ioselements.png]]<br />
<br />
* '''Accent Color:''' the colors used in the Windows Phone. The accent color can be used in TBGRAButton and TBGRAImageButton (see the different procedures).<br />
* '''Facebook button color:''' gray, green and blue, with a procedure to create an image in the normal or pressed state, also to use this style in a TBGRAImageButton.<br />
* '''TBGRASampleStyle:''' Styles for TBGRAButton ('Default', 'Flash Player', 'Windows 7 ToolBar', 'Windows 7 ToolBar Smooth', 'Windows 7', 'Office 2010', 'Mac OSX Lion', 'Windows 7 Cristal').<br />
* '''iOS Elements:''' Draw a gray bar, the blue toolbar and a tiled background, the same elements used in the iOS screen.<br />
* '''Glass:''' used in testbgracontrols, it show an image in a virtualscreen and apply blur in the buttons area.<br />
* '''Drawings:''' flash player body and toolbar, windows 7 toolbar.<br />
<br />
* Some other usefull procedures to work with TBGRAButton and TBGRAImageButton.<br />
<br />
== BGRABitmapThemeUtils ==<br />
<br />
This unit is used by BGRAImageButton to draw the button! Also it's usefull to skin controls from bitmaps. You can see how to use it in the BGRAImageButton code or in the Custom Drawn Windows 7 (included in BGRAControls).<br />
<br />
== BGRANeoButton ==<br />
<br />
This unit is an example, it's usefull to learn how to create your own button with bgrabitmap. BTW read the BGRAImageButton and BGRAButton code. All in this unit can be overriden. I've not added 'invalidate' messages in types and AutoSize, add your own according to your programming needs.<br />
<br />
== Custom Drawn Windows 7 ==<br />
<br />
[[Image:customdrawnwindows7.png]]<br />
<br />
This is a drawer for [[Lazarus Custom Drawn Controls]], you need that component installed with the latest Lazarus revision to work.<br />
<br />
Working in this drawer: button, statictext, checkbox, radiobutton and progressbar.<br />
<br />
This has also extra images for 'Luna' (Windows XP Theme) 'Aero Lite' (Windows 8 Theme) and extra buttons (arrows).<br />
<br />
[[Category:Components]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=BGRAControls&diff=55042BGRAControls2012-01-24T20:10:18Z<p>Lainz: /* BGRABitmapThemeUtils */</p>
<hr />
<div>{{BGRAControls}}<br />
<br />
== Install ==<br />
<br />
You can use TortoiseSVN to download the svn repository and TortoiseGIT to download the git repository.<br />
<br />
We're using BGRABitmap SVN to develop BGRAControls. Important changes in BGRABitmap can stop working BGRAControls.<br />
<br />
'''1) Download BGRABitmap'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/lazpaint/files/src/<br />
<br />
'''Latest SVN:''' svn co https://lazpaint.svn.sourceforge.net/svnroot/lazpaint lazpaint<br />
<br />
Install BGRABitmap with the file bgrabitmap.lpk<br />
<br />
'''2) Download BGRAControls'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/bgracontrols/files/<br />
<br />
''SVN''<br />
<br />
'''SVN Browse:''' http://bgracontrols.svn.sourceforge.net/viewvc/bgracontrols/<br />
<br />
'''SVN Checkout:''' svn co https://bgracontrols.svn.sourceforge.net/svnroot/bgracontrols bgracontrols<br />
<br />
''GIT''<br />
<br />
'''GIT Browse:''' http://bgracontrols.git.sourceforge.net/git/gitweb-index.cgi<br />
<br />
'''GIT Checkout:''' git://bgracontrols.git.sourceforge.net/gitroot/bgracontrols/bgracontrols <br />
<br />
Install BGRAControls with the file bgracontrols.lpk<br />
<br />
== Overview ==<br />
<br />
'''Authors:''' <br />
<br />
Dibo (package founder and maintainer, author: ''TBGRAImageList'', ''TBGRASpeedButton'', ''TBGRAButton'', ''TBGRAPanel'')<br />
<br />
Lainz (package maintainer, author: ''TBGRAImageButton'', ''TBGRAImageToggleBox'', ''TBGRASpriteAnimation'', ''TBGRALabelFX'', ''TBGRAWin7ToolBar'')<br />
<br />
Circular (package maintainer, author: ''TBGRAKnob'', ''TBGRAFlashProgressBar'', ''TBGRAVirtualScreen'', ''TBGRAShape'', ''TBGRAGraphicControl'')<br />
<br />
Emerson Cavalcanti (author: ''TBGRAImageManipulation'')<br />
<br />
codedeep (author: ''TBGRALabel'')<br />
<br />
'''License:''' Modified LGPL.<br />
<br />
As many people know, Lazarus GTK doesn't have full alpha support. I created a set of components which use TBGRABitmap for drawing icons, so it partially solves the problem with alpha in GTK. But this components set is not only a GTK patch but has more fancy components which are using the power of the BGRABitmap package.<br />
<br />
'''Screenshots:''' Some shots of the project 'testbgracontrols'.<br />
<br />
[[Image:testbgrac1.png]]<br />
<br />
''testbgracontrols > Main.''<br />
<br />
[[Image:testbgrac2.png]]<br />
<br />
''testbgracontrols > Windows 7 ToolBar.''<br />
<br />
[[Image:testbgrac4.png]]<br />
<br />
''testbgracontrols > Ribbon.''<br />
<br />
== Related Articles ==<br />
<br />
[[BGRAButton Gallery]] - Gallery of buttons with source code to use in your projects with BGRAButton.<br />
<br />
[[BGRASpriteAnimation]] - Usage of the sprite animation component.<br />
<br />
[[uE_Controls]] - Other controls developed with BGRABitmap.<br />
<br />
[[BGRABitmap]] - The library used to create this controls.<br />
<br />
[[LazPaint]] - A paint program developed with Lazarus and BGRABitmap.<br />
<br />
== Using ==<br />
<br />
Drop and use like normal component.<br />
<br />
'''Button''':<br />
* TBGRAButton<br />
* TBGRAImageButton<br />
* TBGRAImageToggleBox<br />
* TBGRASpeedButton<br />
<br />
'''Label'''<br />
* TBGRALabel<br />
* TBGRALabelFX<br />
<br />
'''Panel'''<br />
* TBGRAPanel<br />
* TBGRAVirtualScreen<br />
<br />
'''Image'''<br />
* TBGRAGraphicControl<br />
* TBGRAImageList<br />
* TBGRAImageManipulation<br />
* TBGRASpriteAnimation<br />
<br />
'''Other'''<br />
* TBGRAFlashProgressBar<br />
* TBGRAKnob<br />
* TBGRAShape<br />
* TBGRAWin7ToolBar<br />
<br />
== TBGRAImageList ==<br />
<br />
'''Use as replace of:''' TImageList<br />
<br />
'''Before:'''<br />
<br />
[[Image:before-TImageList.png]]<br />
<br />
'''After:'''<br />
<br />
[[Image:after-TBGRAImageList.png]]<br />
<br />
Component which inherits from TImageList. So each control (tested on TToolBar and TTreeView) which is using TImageList.Draw method for drawing icons, automatically can have alpha support. Just use this component instead of TImageList. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRASpeedButton ==<br />
<br />
'''Use as replace of:''' TSpeedButton<br />
<br />
[[Image:BGRASpeedButton.png]]<br />
<br />
Component which inherits from TSpeedButton and draws the glyph using TBGRABitmap. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRAButton ==<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgrabutton.png]]<br />
<br />
Customizable graphic component which is using only BGRABitmap functions for drawing. This component is insensitive for -dGTK_ONLY switch. Demo project included in package.<br />
<br />
'''Functionality:'''<br />
* Gradient, Clear or Color body. [[Double_Gradient]].<br />
* Text with shadow: BGRA antialias or like system default with ClearType.<br />
* Rounded border, inner Light.<br />
* States: normal, hover & clicked fully customizable and grayscale disabled state.<br />
* Special: Down, DropDown, Static.<br />
* Full AutoSize working with Glyph.<br />
<br />
== TBGRAPanel ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
Simple TPanel descendant which can have gradient background. Created especially for TBGRAButton (for creating a nice looking toolbar for bgrabuttons). This component is insensitive for -dGTK_ONLY switch<br />
<br />
== TBGRAKnob ==<br />
[[Image:BC-Bgraknob.png]]<br />
<br />
Graphic knob component created by circular.<br />
<br />
== TBGRAFlashProgressBar ==<br />
<br />
'''Use as replace of:''' TProgressBar<br />
<br />
[[Image:BC-Bgraflashprogressbar.png]]<br />
<br />
Flash progressbar created by circular.<br />
<br />
== TBGRAImageManipulation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Component to facilitate the importation of images in an application.<br />
<br />
In the current version you can import an image and cut out keeping the aspect ratio (or not). For example, if you want to import photos using the 3x4 ratio, adjust the 'ratio' property to 3:4. If import an image with different size, the component will ensure that the image meets the proportions of the desired dimensions.<br />
<br />
You can determine the minimum size of the image adjusting the properties 'MinWidth'and 'MinHeight'.<br />
<br />
You can rotate the image using functions builtin.<br />
<br />
See demo of component:<br />
<br />
[[Image:bgraimagemanipulation.jpg]]<br />
<br />
After retrieving the image modified by the component, just put the image into your destination using the stretch. It is obvious that the target must have the same ratio chosen on component for do not distort the final result.<br />
<br />
== TBGRAImageButton ==<br />
<br />
If you need some code to load and split an image from file, and then scale the borders like in this control you can use TBGRABitmapThemeUtils (included in BGRAControls).<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgraimagebutton.png]]<br />
<br />
Component used to create a button with 4 states from Bitmap.<br />
<br />
'''Features:'''<br />
* Load the image from the "Bitmap" property in the object inspector or load from file using "BitmapFile".<br />
<br />
// You can load bmp and also png files<br />
BGRAImageButton1.BitmapLoadFromFile(BGRAImageButton1.BitmapFile);<br />
<br />
* BitmapOptions: you can set the border pixels, resample method and fill modes. Usefull to create textured / like Windows themed buttons.<br />
* AutoSize, ModalResult.<br />
* Text with Shadow, you can disable text render with the option "TextVisible".<br />
* Sound: in mouse enter and leave in Windows from .wav files.<br />
* Toggle: you can read / set the current state with the property "Checked".<br />
* Animation: glowing effect.<br />
<br />
'''Usage:'''<br />
<br />
The bitmap must contain 4 states (from top to bottom, with the same Height) in the following order: normal, enter, pressed, disabled.<br />
<br />
If you choose to use BitmapOptions you need to have for each state an image which has a border, and inside some content that can be repeated. Then with FillCenter option (if you want a textured button), it gets repeated while the borders stay as they are. This is like the method used in Windows to theme the buttons.<br />
<br />
''Example Button:''<br />
<br />
[[Image:samplebgraimagebutton.png]]<br />
<br />
''Example Button (with Alpha):''<br />
<br />
[[Image:samplebgraimagebuttonalpha.png]]<br />
<br />
== TBGRAVirtualScreen ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
The principle is to draw on a memory bitmap.<br />
<br />
The component has a specific event, OnRedraw, which is called when the whole bitmap needs to be redrawn. It happens at the beginning, when resizing and when the Redraw method is called.<br />
<br />
Otherwise, it is possible to modify the Bitmap property and call Invalidate or Repaint, to avoid erasing the whole bitmap content.<br />
<br />
== TBGRAShape ==<br />
<br />
'''Use as replace of:''' TShape<br />
<br />
[[Image:samplebgrashape.png]]<br />
<br />
The component has full alpha support and you can put the number of polygons you want with rounded borders & gradients (linear, radial, diamond, reflected).<br />
<br />
== TBGRAImageToggleBox ==<br />
<br />
REMOVED IN VER 1.1.0.7.<br />
<br />
'''Use as replace of:''' TToggleBox<br />
<br />
Component used to create a toggle box from Bitmap.<br />
<br />
The bitmap must contain 8 images (from top to bottom, with the same Height) in the following order: unchecked normal, unchecked enter, unchecked pressed, unchecked disabled for Unchecked state and checked normal, checked enter, checked pressed, checked disabled for Normal state.<br />
<br />
''Example toggle box:''<br />
<br />
[[Image:sampletogglebox.png]]<br />
<br />
== TBGRAGraphicControl ==<br />
<br />
'''Use as replace of:''' TPaintBox<br />
<br />
TBGRAGraphicControl, which allows to draw your component by yourself with alpha blending.<br />
<br />
== TBGRASpriteAnimation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Read more in the article [[BGRASpriteAnimation]].<br />
<br />
[[Image:bgraspriteanimation.png]]<br />
<br />
With this you can do animations from bitmap. You need an image with all the frames layout in in a horizontal position.<br />
<br />
It has the ability to specify how many times the animation should be played (0 for infinite, 1, 2, etc) and static to stop the animation, is capable to specify the speed and direction and support transparency.<br />
<br />
Features:<br />
* Animation: invert, position, lap, speed, static, repeat.<br />
* Sprite: fill opacity (global transparency), flip mode (horizontal, vertical, both), key color (transparent color), resample (normal or fine resample modes). AutoSize.<br />
* AnimatedGifToSprite: convert an animated gif to a BGRABitmap sprite.<br />
<br />
== TBGRALabel ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
Label component based on TBGRAButton.<br />
<br />
Features:<br />
* Caption with shadow or not<br />
* Full alpha and antialias support or not<br />
* WordWarp or not<br />
* Caption with Property Editor Multiline<br />
<br />
== TBGRALabelFX ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
[[Image:bgralabelfx.png]]<br />
<br />
Features:<br />
* Outline<br />
* Shadow<br />
<br />
ToDo:<br />
* Use BGRATextFX multicolor, textures.<br />
* etc.<br />
<br />
== TBGRAWin7ToolBar ==<br />
<br />
[[Image:bgrawin7toolbar.png]]<br />
<br />
Is a TBGRAVirtualScreen descendant with some default child sizing, and nice Win7 ToolBar background.<br />
<br />
== BGRASamples unit ==<br />
<br />
This unit has sample drawings, styles for buttons and colors used in different UI.<br />
<br />
[[Image:ioselements.png]]<br />
<br />
* '''Accent Color:''' the colors used in the Windows Phone. The accent color can be used in TBGRAButton and TBGRAImageButton (see the different procedures).<br />
* '''Facebook button color:''' gray, green and blue, with a procedure to create an image in the normal or pressed state, also to use this style in a TBGRAImageButton.<br />
* '''TBGRASampleStyle:''' Styles for TBGRAButton ('Default', 'Flash Player', 'Windows 7 ToolBar', 'Windows 7 ToolBar Smooth', 'Windows 7', 'Office 2010', 'Mac OSX Lion', 'Windows 7 Cristal').<br />
* '''iOS Elements:''' Draw a gray bar, the blue toolbar and a tiled background, the same elements used in the iOS screen.<br />
* '''Glass:''' used in testbgracontrols, it show an image in a virtualscreen and apply blur in the buttons area.<br />
* '''Drawings:''' flash player body and toolbar, windows 7 toolbar.<br />
<br />
* Some other usefull procedures to work with TBGRAButton and TBGRAImageButton.<br />
<br />
== BGRABitmapThemeUtils ==<br />
<br />
This unit is used by BGRAImageButton to draw the button! Also it's usefull to skin controls from bitmaps. You can see how to use it in the BGRAImageButton code or in the Custom Drawn Windows 7 (included in BGRAControls).<br />
<br />
== BGRANeoButton ==<br />
<br />
This unit is an example, it's usefull to learn how to create your own button with bgrabitmap. BTW read the BGRAImageButton and BGRAButton code. All in this unit can be overriden. I've not added 'invalidate' messages in types and AutoSize, add your own according to your programming needs.<br />
<br />
== Custom Drawn Windows 7 ==<br />
<br />
[[Image:customdrawnwindows7.png]]<br />
<br />
This is a drawer for [[Lazarus Custom Drawn Controls]], you need that component installed with the latest Lazarus revision to work.<br />
<br />
Working in this drawer: button, statictext, checkbox, radiobutton and progressbar.<br />
<br />
[[Category:Components]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=BGRAControls&diff=55041BGRAControls2012-01-24T20:09:51Z<p>Lainz: /* TBGRAImageButton */</p>
<hr />
<div>{{BGRAControls}}<br />
<br />
== Install ==<br />
<br />
You can use TortoiseSVN to download the svn repository and TortoiseGIT to download the git repository.<br />
<br />
We're using BGRABitmap SVN to develop BGRAControls. Important changes in BGRABitmap can stop working BGRAControls.<br />
<br />
'''1) Download BGRABitmap'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/lazpaint/files/src/<br />
<br />
'''Latest SVN:''' svn co https://lazpaint.svn.sourceforge.net/svnroot/lazpaint lazpaint<br />
<br />
Install BGRABitmap with the file bgrabitmap.lpk<br />
<br />
'''2) Download BGRAControls'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/bgracontrols/files/<br />
<br />
''SVN''<br />
<br />
'''SVN Browse:''' http://bgracontrols.svn.sourceforge.net/viewvc/bgracontrols/<br />
<br />
'''SVN Checkout:''' svn co https://bgracontrols.svn.sourceforge.net/svnroot/bgracontrols bgracontrols<br />
<br />
''GIT''<br />
<br />
'''GIT Browse:''' http://bgracontrols.git.sourceforge.net/git/gitweb-index.cgi<br />
<br />
'''GIT Checkout:''' git://bgracontrols.git.sourceforge.net/gitroot/bgracontrols/bgracontrols <br />
<br />
Install BGRAControls with the file bgracontrols.lpk<br />
<br />
== Overview ==<br />
<br />
'''Authors:''' <br />
<br />
Dibo (package founder and maintainer, author: ''TBGRAImageList'', ''TBGRASpeedButton'', ''TBGRAButton'', ''TBGRAPanel'')<br />
<br />
Lainz (package maintainer, author: ''TBGRAImageButton'', ''TBGRAImageToggleBox'', ''TBGRASpriteAnimation'', ''TBGRALabelFX'', ''TBGRAWin7ToolBar'')<br />
<br />
Circular (package maintainer, author: ''TBGRAKnob'', ''TBGRAFlashProgressBar'', ''TBGRAVirtualScreen'', ''TBGRAShape'', ''TBGRAGraphicControl'')<br />
<br />
Emerson Cavalcanti (author: ''TBGRAImageManipulation'')<br />
<br />
codedeep (author: ''TBGRALabel'')<br />
<br />
'''License:''' Modified LGPL.<br />
<br />
As many people know, Lazarus GTK doesn't have full alpha support. I created a set of components which use TBGRABitmap for drawing icons, so it partially solves the problem with alpha in GTK. But this components set is not only a GTK patch but has more fancy components which are using the power of the BGRABitmap package.<br />
<br />
'''Screenshots:''' Some shots of the project 'testbgracontrols'.<br />
<br />
[[Image:testbgrac1.png]]<br />
<br />
''testbgracontrols > Main.''<br />
<br />
[[Image:testbgrac2.png]]<br />
<br />
''testbgracontrols > Windows 7 ToolBar.''<br />
<br />
[[Image:testbgrac4.png]]<br />
<br />
''testbgracontrols > Ribbon.''<br />
<br />
== Related Articles ==<br />
<br />
[[BGRAButton Gallery]] - Gallery of buttons with source code to use in your projects with BGRAButton.<br />
<br />
[[BGRASpriteAnimation]] - Usage of the sprite animation component.<br />
<br />
[[uE_Controls]] - Other controls developed with BGRABitmap.<br />
<br />
[[BGRABitmap]] - The library used to create this controls.<br />
<br />
[[LazPaint]] - A paint program developed with Lazarus and BGRABitmap.<br />
<br />
== Using ==<br />
<br />
Drop and use like normal component.<br />
<br />
'''Button''':<br />
* TBGRAButton<br />
* TBGRAImageButton<br />
* TBGRAImageToggleBox<br />
* TBGRASpeedButton<br />
<br />
'''Label'''<br />
* TBGRALabel<br />
* TBGRALabelFX<br />
<br />
'''Panel'''<br />
* TBGRAPanel<br />
* TBGRAVirtualScreen<br />
<br />
'''Image'''<br />
* TBGRAGraphicControl<br />
* TBGRAImageList<br />
* TBGRAImageManipulation<br />
* TBGRASpriteAnimation<br />
<br />
'''Other'''<br />
* TBGRAFlashProgressBar<br />
* TBGRAKnob<br />
* TBGRAShape<br />
* TBGRAWin7ToolBar<br />
<br />
== TBGRAImageList ==<br />
<br />
'''Use as replace of:''' TImageList<br />
<br />
'''Before:'''<br />
<br />
[[Image:before-TImageList.png]]<br />
<br />
'''After:'''<br />
<br />
[[Image:after-TBGRAImageList.png]]<br />
<br />
Component which inherits from TImageList. So each control (tested on TToolBar and TTreeView) which is using TImageList.Draw method for drawing icons, automatically can have alpha support. Just use this component instead of TImageList. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRASpeedButton ==<br />
<br />
'''Use as replace of:''' TSpeedButton<br />
<br />
[[Image:BGRASpeedButton.png]]<br />
<br />
Component which inherits from TSpeedButton and draws the glyph using TBGRABitmap. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRAButton ==<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgrabutton.png]]<br />
<br />
Customizable graphic component which is using only BGRABitmap functions for drawing. This component is insensitive for -dGTK_ONLY switch. Demo project included in package.<br />
<br />
'''Functionality:'''<br />
* Gradient, Clear or Color body. [[Double_Gradient]].<br />
* Text with shadow: BGRA antialias or like system default with ClearType.<br />
* Rounded border, inner Light.<br />
* States: normal, hover & clicked fully customizable and grayscale disabled state.<br />
* Special: Down, DropDown, Static.<br />
* Full AutoSize working with Glyph.<br />
<br />
== TBGRAPanel ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
Simple TPanel descendant which can have gradient background. Created especially for TBGRAButton (for creating a nice looking toolbar for bgrabuttons). This component is insensitive for -dGTK_ONLY switch<br />
<br />
== TBGRAKnob ==<br />
[[Image:BC-Bgraknob.png]]<br />
<br />
Graphic knob component created by circular.<br />
<br />
== TBGRAFlashProgressBar ==<br />
<br />
'''Use as replace of:''' TProgressBar<br />
<br />
[[Image:BC-Bgraflashprogressbar.png]]<br />
<br />
Flash progressbar created by circular.<br />
<br />
== TBGRAImageManipulation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Component to facilitate the importation of images in an application.<br />
<br />
In the current version you can import an image and cut out keeping the aspect ratio (or not). For example, if you want to import photos using the 3x4 ratio, adjust the 'ratio' property to 3:4. If import an image with different size, the component will ensure that the image meets the proportions of the desired dimensions.<br />
<br />
You can determine the minimum size of the image adjusting the properties 'MinWidth'and 'MinHeight'.<br />
<br />
You can rotate the image using functions builtin.<br />
<br />
See demo of component:<br />
<br />
[[Image:bgraimagemanipulation.jpg]]<br />
<br />
After retrieving the image modified by the component, just put the image into your destination using the stretch. It is obvious that the target must have the same ratio chosen on component for do not distort the final result.<br />
<br />
== TBGRAImageButton ==<br />
<br />
If you need some code to load and split an image from file, and then scale the borders like in this control you can use TBGRABitmapThemeUtils (included in BGRAControls).<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgraimagebutton.png]]<br />
<br />
Component used to create a button with 4 states from Bitmap.<br />
<br />
'''Features:'''<br />
* Load the image from the "Bitmap" property in the object inspector or load from file using "BitmapFile".<br />
<br />
// You can load bmp and also png files<br />
BGRAImageButton1.BitmapLoadFromFile(BGRAImageButton1.BitmapFile);<br />
<br />
* BitmapOptions: you can set the border pixels, resample method and fill modes. Usefull to create textured / like Windows themed buttons.<br />
* AutoSize, ModalResult.<br />
* Text with Shadow, you can disable text render with the option "TextVisible".<br />
* Sound: in mouse enter and leave in Windows from .wav files.<br />
* Toggle: you can read / set the current state with the property "Checked".<br />
* Animation: glowing effect.<br />
<br />
'''Usage:'''<br />
<br />
The bitmap must contain 4 states (from top to bottom, with the same Height) in the following order: normal, enter, pressed, disabled.<br />
<br />
If you choose to use BitmapOptions you need to have for each state an image which has a border, and inside some content that can be repeated. Then with FillCenter option (if you want a textured button), it gets repeated while the borders stay as they are. This is like the method used in Windows to theme the buttons.<br />
<br />
''Example Button:''<br />
<br />
[[Image:samplebgraimagebutton.png]]<br />
<br />
''Example Button (with Alpha):''<br />
<br />
[[Image:samplebgraimagebuttonalpha.png]]<br />
<br />
== TBGRAVirtualScreen ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
The principle is to draw on a memory bitmap.<br />
<br />
The component has a specific event, OnRedraw, which is called when the whole bitmap needs to be redrawn. It happens at the beginning, when resizing and when the Redraw method is called.<br />
<br />
Otherwise, it is possible to modify the Bitmap property and call Invalidate or Repaint, to avoid erasing the whole bitmap content.<br />
<br />
== TBGRAShape ==<br />
<br />
'''Use as replace of:''' TShape<br />
<br />
[[Image:samplebgrashape.png]]<br />
<br />
The component has full alpha support and you can put the number of polygons you want with rounded borders & gradients (linear, radial, diamond, reflected).<br />
<br />
== TBGRAImageToggleBox ==<br />
<br />
REMOVED IN VER 1.1.0.7.<br />
<br />
'''Use as replace of:''' TToggleBox<br />
<br />
Component used to create a toggle box from Bitmap.<br />
<br />
The bitmap must contain 8 images (from top to bottom, with the same Height) in the following order: unchecked normal, unchecked enter, unchecked pressed, unchecked disabled for Unchecked state and checked normal, checked enter, checked pressed, checked disabled for Normal state.<br />
<br />
''Example toggle box:''<br />
<br />
[[Image:sampletogglebox.png]]<br />
<br />
== TBGRAGraphicControl ==<br />
<br />
'''Use as replace of:''' TPaintBox<br />
<br />
TBGRAGraphicControl, which allows to draw your component by yourself with alpha blending.<br />
<br />
== TBGRASpriteAnimation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Read more in the article [[BGRASpriteAnimation]].<br />
<br />
[[Image:bgraspriteanimation.png]]<br />
<br />
With this you can do animations from bitmap. You need an image with all the frames layout in in a horizontal position.<br />
<br />
It has the ability to specify how many times the animation should be played (0 for infinite, 1, 2, etc) and static to stop the animation, is capable to specify the speed and direction and support transparency.<br />
<br />
Features:<br />
* Animation: invert, position, lap, speed, static, repeat.<br />
* Sprite: fill opacity (global transparency), flip mode (horizontal, vertical, both), key color (transparent color), resample (normal or fine resample modes). AutoSize.<br />
* AnimatedGifToSprite: convert an animated gif to a BGRABitmap sprite.<br />
<br />
== TBGRALabel ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
Label component based on TBGRAButton.<br />
<br />
Features:<br />
* Caption with shadow or not<br />
* Full alpha and antialias support or not<br />
* WordWarp or not<br />
* Caption with Property Editor Multiline<br />
<br />
== TBGRALabelFX ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
[[Image:bgralabelfx.png]]<br />
<br />
Features:<br />
* Outline<br />
* Shadow<br />
<br />
ToDo:<br />
* Use BGRATextFX multicolor, textures.<br />
* etc.<br />
<br />
== TBGRAWin7ToolBar ==<br />
<br />
[[Image:bgrawin7toolbar.png]]<br />
<br />
Is a TBGRAVirtualScreen descendant with some default child sizing, and nice Win7 ToolBar background.<br />
<br />
== BGRASamples unit ==<br />
<br />
This unit has sample drawings, styles for buttons and colors used in different UI.<br />
<br />
[[Image:ioselements.png]]<br />
<br />
* '''Accent Color:''' the colors used in the Windows Phone. The accent color can be used in TBGRAButton and TBGRAImageButton (see the different procedures).<br />
* '''Facebook button color:''' gray, green and blue, with a procedure to create an image in the normal or pressed state, also to use this style in a TBGRAImageButton.<br />
* '''TBGRASampleStyle:''' Styles for TBGRAButton ('Default', 'Flash Player', 'Windows 7 ToolBar', 'Windows 7 ToolBar Smooth', 'Windows 7', 'Office 2010', 'Mac OSX Lion', 'Windows 7 Cristal').<br />
* '''iOS Elements:''' Draw a gray bar, the blue toolbar and a tiled background, the same elements used in the iOS screen.<br />
* '''Glass:''' used in testbgracontrols, it show an image in a virtualscreen and apply blur in the buttons area.<br />
* '''Drawings:''' flash player body and toolbar, windows 7 toolbar.<br />
<br />
* Some other usefull procedures to work with TBGRAButton and TBGRAImageButton.<br />
<br />
== BGRABitmapThemeUtils ==<br />
<br />
This unit is used by BGRAImageButton to draw the button! Also it's usefull to skin controls from bitmaps. You can see how to use it in the BGRAImageButton code or in a CustomDrawn drawer here:<br />
* https://sourceforge.net/projects/bmpthemeutils/<br />
<br />
== BGRANeoButton ==<br />
<br />
This unit is an example, it's usefull to learn how to create your own button with bgrabitmap. BTW read the BGRAImageButton and BGRAButton code. All in this unit can be overriden. I've not added 'invalidate' messages in types and AutoSize, add your own according to your programming needs.<br />
<br />
== Custom Drawn Windows 7 ==<br />
<br />
[[Image:customdrawnwindows7.png]]<br />
<br />
This is a drawer for [[Lazarus Custom Drawn Controls]], you need that component installed with the latest Lazarus revision to work.<br />
<br />
Working in this drawer: button, statictext, checkbox, radiobutton and progressbar.<br />
<br />
[[Category:Components]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=BGRAControls&diff=55040BGRAControls2012-01-24T20:07:30Z<p>Lainz: added custom drawn windows 7</p>
<hr />
<div>{{BGRAControls}}<br />
<br />
== Install ==<br />
<br />
You can use TortoiseSVN to download the svn repository and TortoiseGIT to download the git repository.<br />
<br />
We're using BGRABitmap SVN to develop BGRAControls. Important changes in BGRABitmap can stop working BGRAControls.<br />
<br />
'''1) Download BGRABitmap'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/lazpaint/files/src/<br />
<br />
'''Latest SVN:''' svn co https://lazpaint.svn.sourceforge.net/svnroot/lazpaint lazpaint<br />
<br />
Install BGRABitmap with the file bgrabitmap.lpk<br />
<br />
'''2) Download BGRAControls'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/bgracontrols/files/<br />
<br />
''SVN''<br />
<br />
'''SVN Browse:''' http://bgracontrols.svn.sourceforge.net/viewvc/bgracontrols/<br />
<br />
'''SVN Checkout:''' svn co https://bgracontrols.svn.sourceforge.net/svnroot/bgracontrols bgracontrols<br />
<br />
''GIT''<br />
<br />
'''GIT Browse:''' http://bgracontrols.git.sourceforge.net/git/gitweb-index.cgi<br />
<br />
'''GIT Checkout:''' git://bgracontrols.git.sourceforge.net/gitroot/bgracontrols/bgracontrols <br />
<br />
Install BGRAControls with the file bgracontrols.lpk<br />
<br />
== Overview ==<br />
<br />
'''Authors:''' <br />
<br />
Dibo (package founder and maintainer, author: ''TBGRAImageList'', ''TBGRASpeedButton'', ''TBGRAButton'', ''TBGRAPanel'')<br />
<br />
Lainz (package maintainer, author: ''TBGRAImageButton'', ''TBGRAImageToggleBox'', ''TBGRASpriteAnimation'', ''TBGRALabelFX'', ''TBGRAWin7ToolBar'')<br />
<br />
Circular (package maintainer, author: ''TBGRAKnob'', ''TBGRAFlashProgressBar'', ''TBGRAVirtualScreen'', ''TBGRAShape'', ''TBGRAGraphicControl'')<br />
<br />
Emerson Cavalcanti (author: ''TBGRAImageManipulation'')<br />
<br />
codedeep (author: ''TBGRALabel'')<br />
<br />
'''License:''' Modified LGPL.<br />
<br />
As many people know, Lazarus GTK doesn't have full alpha support. I created a set of components which use TBGRABitmap for drawing icons, so it partially solves the problem with alpha in GTK. But this components set is not only a GTK patch but has more fancy components which are using the power of the BGRABitmap package.<br />
<br />
'''Screenshots:''' Some shots of the project 'testbgracontrols'.<br />
<br />
[[Image:testbgrac1.png]]<br />
<br />
''testbgracontrols > Main.''<br />
<br />
[[Image:testbgrac2.png]]<br />
<br />
''testbgracontrols > Windows 7 ToolBar.''<br />
<br />
[[Image:testbgrac4.png]]<br />
<br />
''testbgracontrols > Ribbon.''<br />
<br />
== Related Articles ==<br />
<br />
[[BGRAButton Gallery]] - Gallery of buttons with source code to use in your projects with BGRAButton.<br />
<br />
[[BGRASpriteAnimation]] - Usage of the sprite animation component.<br />
<br />
[[uE_Controls]] - Other controls developed with BGRABitmap.<br />
<br />
[[BGRABitmap]] - The library used to create this controls.<br />
<br />
[[LazPaint]] - A paint program developed with Lazarus and BGRABitmap.<br />
<br />
== Using ==<br />
<br />
Drop and use like normal component.<br />
<br />
'''Button''':<br />
* TBGRAButton<br />
* TBGRAImageButton<br />
* TBGRAImageToggleBox<br />
* TBGRASpeedButton<br />
<br />
'''Label'''<br />
* TBGRALabel<br />
* TBGRALabelFX<br />
<br />
'''Panel'''<br />
* TBGRAPanel<br />
* TBGRAVirtualScreen<br />
<br />
'''Image'''<br />
* TBGRAGraphicControl<br />
* TBGRAImageList<br />
* TBGRAImageManipulation<br />
* TBGRASpriteAnimation<br />
<br />
'''Other'''<br />
* TBGRAFlashProgressBar<br />
* TBGRAKnob<br />
* TBGRAShape<br />
* TBGRAWin7ToolBar<br />
<br />
== TBGRAImageList ==<br />
<br />
'''Use as replace of:''' TImageList<br />
<br />
'''Before:'''<br />
<br />
[[Image:before-TImageList.png]]<br />
<br />
'''After:'''<br />
<br />
[[Image:after-TBGRAImageList.png]]<br />
<br />
Component which inherits from TImageList. So each control (tested on TToolBar and TTreeView) which is using TImageList.Draw method for drawing icons, automatically can have alpha support. Just use this component instead of TImageList. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRASpeedButton ==<br />
<br />
'''Use as replace of:''' TSpeedButton<br />
<br />
[[Image:BGRASpeedButton.png]]<br />
<br />
Component which inherits from TSpeedButton and draws the glyph using TBGRABitmap. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRAButton ==<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgrabutton.png]]<br />
<br />
Customizable graphic component which is using only BGRABitmap functions for drawing. This component is insensitive for -dGTK_ONLY switch. Demo project included in package.<br />
<br />
'''Functionality:'''<br />
* Gradient, Clear or Color body. [[Double_Gradient]].<br />
* Text with shadow: BGRA antialias or like system default with ClearType.<br />
* Rounded border, inner Light.<br />
* States: normal, hover & clicked fully customizable and grayscale disabled state.<br />
* Special: Down, DropDown, Static.<br />
* Full AutoSize working with Glyph.<br />
<br />
== TBGRAPanel ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
Simple TPanel descendant which can have gradient background. Created especially for TBGRAButton (for creating a nice looking toolbar for bgrabuttons). This component is insensitive for -dGTK_ONLY switch<br />
<br />
== TBGRAKnob ==<br />
[[Image:BC-Bgraknob.png]]<br />
<br />
Graphic knob component created by circular.<br />
<br />
== TBGRAFlashProgressBar ==<br />
<br />
'''Use as replace of:''' TProgressBar<br />
<br />
[[Image:BC-Bgraflashprogressbar.png]]<br />
<br />
Flash progressbar created by circular.<br />
<br />
== TBGRAImageManipulation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Component to facilitate the importation of images in an application.<br />
<br />
In the current version you can import an image and cut out keeping the aspect ratio (or not). For example, if you want to import photos using the 3x4 ratio, adjust the 'ratio' property to 3:4. If import an image with different size, the component will ensure that the image meets the proportions of the desired dimensions.<br />
<br />
You can determine the minimum size of the image adjusting the properties 'MinWidth'and 'MinHeight'.<br />
<br />
You can rotate the image using functions builtin.<br />
<br />
See demo of component:<br />
<br />
[[Image:bgraimagemanipulation.jpg]]<br />
<br />
After retrieving the image modified by the component, just put the image into your destination using the stretch. It is obvious that the target must have the same ratio chosen on component for do not distort the final result.<br />
<br />
== TBGRAImageButton ==<br />
<br />
If you need some code to load and split an image from file, and then scale the borders like in this control you can download bitmapthemeutils:<br />
* https://sourceforge.net/projects/bmpthemeutils/<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgraimagebutton.png]]<br />
<br />
Component used to create a button with 4 states from Bitmap.<br />
<br />
'''Features:'''<br />
* Load the image from the "Bitmap" property in the object inspector or load from file using "BitmapFile".<br />
<br />
// You can load bmp and also png files<br />
BGRAImageButton1.BitmapLoadFromFile(BGRAImageButton1.BitmapFile);<br />
<br />
* BitmapOptions: you can set the border pixels, resample method and fill modes. Usefull to create textured / like Windows themed buttons.<br />
* AutoSize, ModalResult.<br />
* Text with Shadow, you can disable text render with the option "TextVisible".<br />
* Sound: in mouse enter and leave in Windows from .wav files.<br />
* Toggle: you can read / set the current state with the property "Checked".<br />
* Animation: glowing effect.<br />
<br />
'''Usage:'''<br />
<br />
The bitmap must contain 4 states (from top to bottom, with the same Height) in the following order: normal, enter, pressed, disabled.<br />
<br />
If you choose to use BitmapOptions you need to have for each state an image which has a border, and inside some content that can be repeated. Then with FillCenter option (if you want a textured button), it gets repeated while the borders stay as they are. This is like the method used in Windows to theme the buttons.<br />
<br />
''Example Button:''<br />
<br />
[[Image:samplebgraimagebutton.png]]<br />
<br />
''Example Button (with Alpha):''<br />
<br />
[[Image:samplebgraimagebuttonalpha.png]]<br />
<br />
== TBGRAVirtualScreen ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
The principle is to draw on a memory bitmap.<br />
<br />
The component has a specific event, OnRedraw, which is called when the whole bitmap needs to be redrawn. It happens at the beginning, when resizing and when the Redraw method is called.<br />
<br />
Otherwise, it is possible to modify the Bitmap property and call Invalidate or Repaint, to avoid erasing the whole bitmap content.<br />
<br />
== TBGRAShape ==<br />
<br />
'''Use as replace of:''' TShape<br />
<br />
[[Image:samplebgrashape.png]]<br />
<br />
The component has full alpha support and you can put the number of polygons you want with rounded borders & gradients (linear, radial, diamond, reflected).<br />
<br />
== TBGRAImageToggleBox ==<br />
<br />
REMOVED IN VER 1.1.0.7.<br />
<br />
'''Use as replace of:''' TToggleBox<br />
<br />
Component used to create a toggle box from Bitmap.<br />
<br />
The bitmap must contain 8 images (from top to bottom, with the same Height) in the following order: unchecked normal, unchecked enter, unchecked pressed, unchecked disabled for Unchecked state and checked normal, checked enter, checked pressed, checked disabled for Normal state.<br />
<br />
''Example toggle box:''<br />
<br />
[[Image:sampletogglebox.png]]<br />
<br />
== TBGRAGraphicControl ==<br />
<br />
'''Use as replace of:''' TPaintBox<br />
<br />
TBGRAGraphicControl, which allows to draw your component by yourself with alpha blending.<br />
<br />
== TBGRASpriteAnimation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Read more in the article [[BGRASpriteAnimation]].<br />
<br />
[[Image:bgraspriteanimation.png]]<br />
<br />
With this you can do animations from bitmap. You need an image with all the frames layout in in a horizontal position.<br />
<br />
It has the ability to specify how many times the animation should be played (0 for infinite, 1, 2, etc) and static to stop the animation, is capable to specify the speed and direction and support transparency.<br />
<br />
Features:<br />
* Animation: invert, position, lap, speed, static, repeat.<br />
* Sprite: fill opacity (global transparency), flip mode (horizontal, vertical, both), key color (transparent color), resample (normal or fine resample modes). AutoSize.<br />
* AnimatedGifToSprite: convert an animated gif to a BGRABitmap sprite.<br />
<br />
== TBGRALabel ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
Label component based on TBGRAButton.<br />
<br />
Features:<br />
* Caption with shadow or not<br />
* Full alpha and antialias support or not<br />
* WordWarp or not<br />
* Caption with Property Editor Multiline<br />
<br />
== TBGRALabelFX ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
[[Image:bgralabelfx.png]]<br />
<br />
Features:<br />
* Outline<br />
* Shadow<br />
<br />
ToDo:<br />
* Use BGRATextFX multicolor, textures.<br />
* etc.<br />
<br />
== TBGRAWin7ToolBar ==<br />
<br />
[[Image:bgrawin7toolbar.png]]<br />
<br />
Is a TBGRAVirtualScreen descendant with some default child sizing, and nice Win7 ToolBar background.<br />
<br />
== BGRASamples unit ==<br />
<br />
This unit has sample drawings, styles for buttons and colors used in different UI.<br />
<br />
[[Image:ioselements.png]]<br />
<br />
* '''Accent Color:''' the colors used in the Windows Phone. The accent color can be used in TBGRAButton and TBGRAImageButton (see the different procedures).<br />
* '''Facebook button color:''' gray, green and blue, with a procedure to create an image in the normal or pressed state, also to use this style in a TBGRAImageButton.<br />
* '''TBGRASampleStyle:''' Styles for TBGRAButton ('Default', 'Flash Player', 'Windows 7 ToolBar', 'Windows 7 ToolBar Smooth', 'Windows 7', 'Office 2010', 'Mac OSX Lion', 'Windows 7 Cristal').<br />
* '''iOS Elements:''' Draw a gray bar, the blue toolbar and a tiled background, the same elements used in the iOS screen.<br />
* '''Glass:''' used in testbgracontrols, it show an image in a virtualscreen and apply blur in the buttons area.<br />
* '''Drawings:''' flash player body and toolbar, windows 7 toolbar.<br />
<br />
* Some other usefull procedures to work with TBGRAButton and TBGRAImageButton.<br />
<br />
== BGRABitmapThemeUtils ==<br />
<br />
This unit is used by BGRAImageButton to draw the button! Also it's usefull to skin controls from bitmaps. You can see how to use it in the BGRAImageButton code or in a CustomDrawn drawer here:<br />
* https://sourceforge.net/projects/bmpthemeutils/<br />
<br />
== BGRANeoButton ==<br />
<br />
This unit is an example, it's usefull to learn how to create your own button with bgrabitmap. BTW read the BGRAImageButton and BGRAButton code. All in this unit can be overriden. I've not added 'invalidate' messages in types and AutoSize, add your own according to your programming needs.<br />
<br />
== Custom Drawn Windows 7 ==<br />
<br />
[[Image:customdrawnwindows7.png]]<br />
<br />
This is a drawer for [[Lazarus Custom Drawn Controls]], you need that component installed with the latest Lazarus revision to work.<br />
<br />
Working in this drawer: button, statictext, checkbox, radiobutton and progressbar.<br />
<br />
[[Category:Components]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=File:customdrawnwindows7.png&diff=55039File:customdrawnwindows7.png2012-01-24T20:07:08Z<p>Lainz: </p>
<hr />
<div></div>Lainzhttps://wiki.freepascal.org/index.php?title=BGRAControls&diff=54939BGRAControls2012-01-18T19:17:42Z<p>Lainz: BGRANeoButton and BGRABitmapThemeUtils</p>
<hr />
<div>{{BGRAControls}}<br />
<br />
== Install ==<br />
<br />
You can use TortoiseSVN to download the svn repository and TortoiseGIT to download the git repository.<br />
<br />
We're using BGRABitmap SVN to develop BGRAControls. Important changes in BGRABitmap can stop working BGRAControls.<br />
<br />
'''1) Download BGRABitmap'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/lazpaint/files/src/<br />
<br />
'''Latest SVN:''' svn co https://lazpaint.svn.sourceforge.net/svnroot/lazpaint lazpaint<br />
<br />
Install BGRABitmap with the file bgrabitmap.lpk<br />
<br />
'''2) Download BGRAControls'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/bgracontrols/files/<br />
<br />
''SVN''<br />
<br />
'''SVN Browse:''' http://bgracontrols.svn.sourceforge.net/viewvc/bgracontrols/<br />
<br />
'''SVN Checkout:''' svn co https://bgracontrols.svn.sourceforge.net/svnroot/bgracontrols bgracontrols<br />
<br />
''GIT''<br />
<br />
'''GIT Browse:''' http://bgracontrols.git.sourceforge.net/git/gitweb-index.cgi<br />
<br />
'''GIT Checkout:''' git://bgracontrols.git.sourceforge.net/gitroot/bgracontrols/bgracontrols <br />
<br />
Install BGRAControls with the file bgracontrols.lpk<br />
<br />
== Overview ==<br />
<br />
'''Authors:''' <br />
<br />
Dibo (package founder and maintainer, author: ''TBGRAImageList'', ''TBGRASpeedButton'', ''TBGRAButton'', ''TBGRAPanel'')<br />
<br />
Lainz (package maintainer, author: ''TBGRAImageButton'', ''TBGRAImageToggleBox'', ''TBGRASpriteAnimation'', ''TBGRALabelFX'', ''TBGRAWin7ToolBar'')<br />
<br />
Circular (package maintainer, author: ''TBGRAKnob'', ''TBGRAFlashProgressBar'', ''TBGRAVirtualScreen'', ''TBGRAShape'', ''TBGRAGraphicControl'')<br />
<br />
Emerson Cavalcanti (author: ''TBGRAImageManipulation'')<br />
<br />
codedeep (author: ''TBGRALabel'')<br />
<br />
'''License:''' Modified LGPL.<br />
<br />
As many people know, Lazarus GTK doesn't have full alpha support. I created a set of components which use TBGRABitmap for drawing icons, so it partially solves the problem with alpha in GTK. But this components set is not only a GTK patch but has more fancy components which are using the power of the BGRABitmap package.<br />
<br />
'''Screenshots:''' Some shots of the project 'testbgracontrols'.<br />
<br />
[[Image:testbgrac1.png]]<br />
<br />
''testbgracontrols > Main.''<br />
<br />
[[Image:testbgrac2.png]]<br />
<br />
''testbgracontrols > Windows 7 ToolBar.''<br />
<br />
[[Image:testbgrac4.png]]<br />
<br />
''testbgracontrols > Ribbon.''<br />
<br />
== Related Articles ==<br />
<br />
[[BGRAButton Gallery]] - Gallery of buttons with source code to use in your projects with BGRAButton.<br />
<br />
[[BGRASpriteAnimation]] - Usage of the sprite animation component.<br />
<br />
[[uE_Controls]] - Other controls developed with BGRABitmap.<br />
<br />
[[BGRABitmap]] - The library used to create this controls.<br />
<br />
[[LazPaint]] - A paint program developed with Lazarus and BGRABitmap.<br />
<br />
== Using ==<br />
<br />
Drop and use like normal component.<br />
<br />
'''Button''':<br />
* TBGRAButton<br />
* TBGRAImageButton<br />
* TBGRAImageToggleBox<br />
* TBGRASpeedButton<br />
<br />
'''Label'''<br />
* TBGRALabel<br />
* TBGRALabelFX<br />
<br />
'''Panel'''<br />
* TBGRAPanel<br />
* TBGRAVirtualScreen<br />
<br />
'''Image'''<br />
* TBGRAGraphicControl<br />
* TBGRAImageList<br />
* TBGRAImageManipulation<br />
* TBGRASpriteAnimation<br />
<br />
'''Other'''<br />
* TBGRAFlashProgressBar<br />
* TBGRAKnob<br />
* TBGRAShape<br />
* TBGRAWin7ToolBar<br />
<br />
== TBGRAImageList ==<br />
<br />
'''Use as replace of:''' TImageList<br />
<br />
'''Before:'''<br />
<br />
[[Image:before-TImageList.png]]<br />
<br />
'''After:'''<br />
<br />
[[Image:after-TBGRAImageList.png]]<br />
<br />
Component which inherits from TImageList. So each control (tested on TToolBar and TTreeView) which is using TImageList.Draw method for drawing icons, automatically can have alpha support. Just use this component instead of TImageList. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRASpeedButton ==<br />
<br />
'''Use as replace of:''' TSpeedButton<br />
<br />
[[Image:BGRASpeedButton.png]]<br />
<br />
Component which inherits from TSpeedButton and draws the glyph using TBGRABitmap. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRAButton ==<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgrabutton.png]]<br />
<br />
Customizable graphic component which is using only BGRABitmap functions for drawing. This component is insensitive for -dGTK_ONLY switch. Demo project included in package.<br />
<br />
'''Functionality:'''<br />
* Gradient, Clear or Color body. [[Double_Gradient]].<br />
* Text with shadow: BGRA antialias or like system default with ClearType.<br />
* Rounded border, inner Light.<br />
* States: normal, hover & clicked fully customizable and grayscale disabled state.<br />
* Special: Down, DropDown, Static.<br />
* Full AutoSize working with Glyph.<br />
<br />
== TBGRAPanel ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
Simple TPanel descendant which can have gradient background. Created especially for TBGRAButton (for creating a nice looking toolbar for bgrabuttons). This component is insensitive for -dGTK_ONLY switch<br />
<br />
== TBGRAKnob ==<br />
[[Image:BC-Bgraknob.png]]<br />
<br />
Graphic knob component created by circular.<br />
<br />
== TBGRAFlashProgressBar ==<br />
<br />
'''Use as replace of:''' TProgressBar<br />
<br />
[[Image:BC-Bgraflashprogressbar.png]]<br />
<br />
Flash progressbar created by circular.<br />
<br />
== TBGRAImageManipulation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Component to facilitate the importation of images in an application.<br />
<br />
In the current version you can import an image and cut out keeping the aspect ratio (or not). For example, if you want to import photos using the 3x4 ratio, adjust the 'ratio' property to 3:4. If import an image with different size, the component will ensure that the image meets the proportions of the desired dimensions.<br />
<br />
You can determine the minimum size of the image adjusting the properties 'MinWidth'and 'MinHeight'.<br />
<br />
You can rotate the image using functions builtin.<br />
<br />
See demo of component:<br />
<br />
[[Image:bgraimagemanipulation.jpg]]<br />
<br />
After retrieving the image modified by the component, just put the image into your destination using the stretch. It is obvious that the target must have the same ratio chosen on component for do not distort the final result.<br />
<br />
== TBGRAImageButton ==<br />
<br />
If you need some code to load and split an image from file, and then scale the borders like in this control you can download bitmapthemeutils:<br />
* https://sourceforge.net/projects/bmpthemeutils/<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgraimagebutton.png]]<br />
<br />
Component used to create a button with 4 states from Bitmap.<br />
<br />
'''Features:'''<br />
* Load the image from the "Bitmap" property in the object inspector or load from file using "BitmapFile".<br />
<br />
// You can load bmp and also png files<br />
BGRAImageButton1.BitmapLoadFromFile(BGRAImageButton1.BitmapFile);<br />
<br />
* BitmapOptions: you can set the border pixels, resample method and fill modes. Usefull to create textured / like Windows themed buttons.<br />
* AutoSize, ModalResult.<br />
* Text with Shadow, you can disable text render with the option "TextVisible".<br />
* Sound: in mouse enter and leave in Windows from .wav files.<br />
* Toggle: you can read / set the current state with the property "Checked".<br />
* Animation: glowing effect.<br />
<br />
'''Usage:'''<br />
<br />
The bitmap must contain 4 states (from top to bottom, with the same Height) in the following order: normal, enter, pressed, disabled.<br />
<br />
If you choose to use BitmapOptions you need to have for each state an image which has a border, and inside some content that can be repeated. Then with FillCenter option (if you want a textured button), it gets repeated while the borders stay as they are. This is like the method used in Windows to theme the buttons.<br />
<br />
''Example Button:''<br />
<br />
[[Image:samplebgraimagebutton.png]]<br />
<br />
''Example Button (with Alpha):''<br />
<br />
[[Image:samplebgraimagebuttonalpha.png]]<br />
<br />
== TBGRAVirtualScreen ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
The principle is to draw on a memory bitmap.<br />
<br />
The component has a specific event, OnRedraw, which is called when the whole bitmap needs to be redrawn. It happens at the beginning, when resizing and when the Redraw method is called.<br />
<br />
Otherwise, it is possible to modify the Bitmap property and call Invalidate or Repaint, to avoid erasing the whole bitmap content.<br />
<br />
== TBGRAShape ==<br />
<br />
'''Use as replace of:''' TShape<br />
<br />
[[Image:samplebgrashape.png]]<br />
<br />
The component has full alpha support and you can put the number of polygons you want with rounded borders & gradients (linear, radial, diamond, reflected).<br />
<br />
== TBGRAImageToggleBox ==<br />
<br />
REMOVED IN VER 1.1.0.7.<br />
<br />
'''Use as replace of:''' TToggleBox<br />
<br />
Component used to create a toggle box from Bitmap.<br />
<br />
The bitmap must contain 8 images (from top to bottom, with the same Height) in the following order: unchecked normal, unchecked enter, unchecked pressed, unchecked disabled for Unchecked state and checked normal, checked enter, checked pressed, checked disabled for Normal state.<br />
<br />
''Example toggle box:''<br />
<br />
[[Image:sampletogglebox.png]]<br />
<br />
== TBGRAGraphicControl ==<br />
<br />
'''Use as replace of:''' TPaintBox<br />
<br />
TBGRAGraphicControl, which allows to draw your component by yourself with alpha blending.<br />
<br />
== TBGRASpriteAnimation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Read more in the article [[BGRASpriteAnimation]].<br />
<br />
[[Image:bgraspriteanimation.png]]<br />
<br />
With this you can do animations from bitmap. You need an image with all the frames layout in in a horizontal position.<br />
<br />
It has the ability to specify how many times the animation should be played (0 for infinite, 1, 2, etc) and static to stop the animation, is capable to specify the speed and direction and support transparency.<br />
<br />
Features:<br />
* Animation: invert, position, lap, speed, static, repeat.<br />
* Sprite: fill opacity (global transparency), flip mode (horizontal, vertical, both), key color (transparent color), resample (normal or fine resample modes). AutoSize.<br />
* AnimatedGifToSprite: convert an animated gif to a BGRABitmap sprite.<br />
<br />
== TBGRALabel ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
Label component based on TBGRAButton.<br />
<br />
Features:<br />
* Caption with shadow or not<br />
* Full alpha and antialias support or not<br />
* WordWarp or not<br />
* Caption with Property Editor Multiline<br />
<br />
== TBGRALabelFX ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
[[Image:bgralabelfx.png]]<br />
<br />
Features:<br />
* Outline<br />
* Shadow<br />
<br />
ToDo:<br />
* Use BGRATextFX multicolor, textures.<br />
* etc.<br />
<br />
== TBGRAWin7ToolBar ==<br />
<br />
[[Image:bgrawin7toolbar.png]]<br />
<br />
Is a TBGRAVirtualScreen descendant with some default child sizing, and nice Win7 ToolBar background.<br />
<br />
== BGRASamples unit ==<br />
<br />
This unit has sample drawings, styles for buttons and colors used in different UI.<br />
<br />
[[Image:ioselements.png]]<br />
<br />
* '''Accent Color:''' the colors used in the Windows Phone. The accent color can be used in TBGRAButton and TBGRAImageButton (see the different procedures).<br />
* '''Facebook button color:''' gray, green and blue, with a procedure to create an image in the normal or pressed state, also to use this style in a TBGRAImageButton.<br />
* '''TBGRASampleStyle:''' Styles for TBGRAButton ('Default', 'Flash Player', 'Windows 7 ToolBar', 'Windows 7 ToolBar Smooth', 'Windows 7', 'Office 2010', 'Mac OSX Lion', 'Windows 7 Cristal').<br />
* '''iOS Elements:''' Draw a gray bar, the blue toolbar and a tiled background, the same elements used in the iOS screen.<br />
* '''Glass:''' used in testbgracontrols, it show an image in a virtualscreen and apply blur in the buttons area.<br />
* '''Drawings:''' flash player body and toolbar, windows 7 toolbar.<br />
<br />
* Some other usefull procedures to work with TBGRAButton and TBGRAImageButton.<br />
<br />
== BGRABitmapThemeUtils ==<br />
<br />
This unit is used by BGRAImageButton to draw the button! Also it's usefull to skin controls from bitmaps. You can see how to use it in the BGRAImageButton code or in a CustomDrawn drawer here:<br />
* https://sourceforge.net/projects/bmpthemeutils/<br />
<br />
== BGRANeoButton ==<br />
<br />
This unit is an example, it's usefull to learn how to create your own button with bgrabitmap. BTW read the BGRAImageButton and BGRAButton code. All in this unit can be overriden. I've not added 'invalidate' messages in types and AutoSize, add your own according to your programming needs.<br />
<br />
[[Category:Components]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=BGRAControls&diff=54891BGRAControls2012-01-16T00:20:53Z<p>Lainz: /* Install */ Added browse and git</p>
<hr />
<div>{{BGRAControls}}<br />
<br />
== Install ==<br />
<br />
You can use TortoiseSVN to download the svn repository and TortoiseGIT to download the git repository.<br />
<br />
We're using BGRABitmap SVN to develop BGRAControls. Important changes in BGRABitmap can stop working BGRAControls.<br />
<br />
'''1) Download BGRABitmap'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/lazpaint/files/src/<br />
<br />
'''Latest SVN:''' svn co https://lazpaint.svn.sourceforge.net/svnroot/lazpaint lazpaint<br />
<br />
Install BGRABitmap with the file bgrabitmap.lpk<br />
<br />
'''2) Download BGRAControls'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/bgracontrols/files/<br />
<br />
''SVN''<br />
<br />
'''SVN Browse:''' http://bgracontrols.svn.sourceforge.net/viewvc/bgracontrols/<br />
<br />
'''SVN Checkout:''' svn co https://bgracontrols.svn.sourceforge.net/svnroot/bgracontrols bgracontrols<br />
<br />
''GIT''<br />
<br />
'''GIT Browse:''' http://bgracontrols.git.sourceforge.net/git/gitweb-index.cgi<br />
<br />
'''GIT Checkout:''' git://bgracontrols.git.sourceforge.net/gitroot/bgracontrols/bgracontrols <br />
<br />
Install BGRAControls with the file bgracontrols.lpk<br />
<br />
== Overview ==<br />
<br />
'''Authors:''' <br />
<br />
Dibo (package founder and maintainer, author: ''TBGRAImageList'', ''TBGRASpeedButton'', ''TBGRAButton'', ''TBGRAPanel'')<br />
<br />
Lainz (package maintainer, author: ''TBGRAImageButton'', ''TBGRAImageToggleBox'', ''TBGRASpriteAnimation'', ''TBGRALabelFX'', ''TBGRAWin7ToolBar'')<br />
<br />
Circular (package maintainer, author: ''TBGRAKnob'', ''TBGRAFlashProgressBar'', ''TBGRAVirtualScreen'', ''TBGRAShape'', ''TBGRAGraphicControl'')<br />
<br />
Emerson Cavalcanti (author: ''TBGRAImageManipulation'')<br />
<br />
codedeep (author: ''TBGRALabel'')<br />
<br />
'''License:''' Modified LGPL.<br />
<br />
As many people know, Lazarus GTK doesn't have full alpha support. I created a set of components which use TBGRABitmap for drawing icons, so it partially solves the problem with alpha in GTK. But this components set is not only a GTK patch but has more fancy components which are using the power of the BGRABitmap package.<br />
<br />
'''Screenshots:''' Some shots of the project 'testbgracontrols'.<br />
<br />
[[Image:testbgrac1.png]]<br />
<br />
''testbgracontrols > Main.''<br />
<br />
[[Image:testbgrac2.png]]<br />
<br />
''testbgracontrols > Windows 7 ToolBar.''<br />
<br />
[[Image:testbgrac4.png]]<br />
<br />
''testbgracontrols > Ribbon.''<br />
<br />
== Related Articles ==<br />
<br />
[[BGRAButton Gallery]] - Gallery of buttons with source code to use in your projects with BGRAButton.<br />
<br />
[[BGRASpriteAnimation]] - Usage of the sprite animation component.<br />
<br />
[[uE_Controls]] - Other controls developed with BGRABitmap.<br />
<br />
[[BGRABitmap]] - The library used to create this controls.<br />
<br />
[[LazPaint]] - A paint program developed with Lazarus and BGRABitmap.<br />
<br />
== Using ==<br />
<br />
Drop and use like normal component.<br />
<br />
'''Button''':<br />
* TBGRAButton<br />
* TBGRAImageButton<br />
* TBGRAImageToggleBox<br />
* TBGRASpeedButton<br />
<br />
'''Label'''<br />
* TBGRALabel<br />
* TBGRALabelFX<br />
<br />
'''Panel'''<br />
* TBGRAPanel<br />
* TBGRAVirtualScreen<br />
<br />
'''Image'''<br />
* TBGRAGraphicControl<br />
* TBGRAImageList<br />
* TBGRAImageManipulation<br />
* TBGRASpriteAnimation<br />
<br />
'''Other'''<br />
* TBGRAFlashProgressBar<br />
* TBGRAKnob<br />
* TBGRAShape<br />
* TBGRAWin7ToolBar<br />
<br />
== TBGRAImageList ==<br />
<br />
'''Use as replace of:''' TImageList<br />
<br />
'''Before:'''<br />
<br />
[[Image:before-TImageList.png]]<br />
<br />
'''After:'''<br />
<br />
[[Image:after-TBGRAImageList.png]]<br />
<br />
Component which inherits from TImageList. So each control (tested on TToolBar and TTreeView) which is using TImageList.Draw method for drawing icons, automatically can have alpha support. Just use this component instead of TImageList. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRASpeedButton ==<br />
<br />
'''Use as replace of:''' TSpeedButton<br />
<br />
[[Image:BGRASpeedButton.png]]<br />
<br />
Component which inherits from TSpeedButton and draws the glyph using TBGRABitmap. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRAButton ==<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgrabutton.png]]<br />
<br />
Customizable graphic component which is using only BGRABitmap functions for drawing. This component is insensitive for -dGTK_ONLY switch. Demo project included in package.<br />
<br />
'''Functionality:'''<br />
* Gradient, Clear or Color body. [[Double_Gradient]].<br />
* Text with shadow: BGRA antialias or like system default with ClearType.<br />
* Rounded border, inner Light.<br />
* States: normal, hover & clicked fully customizable and grayscale disabled state.<br />
* Special: Down, DropDown, Static.<br />
* Full AutoSize working with Glyph.<br />
<br />
== TBGRAPanel ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
Simple TPanel descendant which can have gradient background. Created especially for TBGRAButton (for creating a nice looking toolbar for bgrabuttons). This component is insensitive for -dGTK_ONLY switch<br />
<br />
== TBGRAKnob ==<br />
[[Image:BC-Bgraknob.png]]<br />
<br />
Graphic knob component created by circular.<br />
<br />
== TBGRAFlashProgressBar ==<br />
<br />
'''Use as replace of:''' TProgressBar<br />
<br />
[[Image:BC-Bgraflashprogressbar.png]]<br />
<br />
Flash progressbar created by circular.<br />
<br />
== TBGRAImageManipulation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Component to facilitate the importation of images in an application.<br />
<br />
In the current version you can import an image and cut out keeping the aspect ratio (or not). For example, if you want to import photos using the 3x4 ratio, adjust the 'ratio' property to 3:4. If import an image with different size, the component will ensure that the image meets the proportions of the desired dimensions.<br />
<br />
You can determine the minimum size of the image adjusting the properties 'MinWidth'and 'MinHeight'.<br />
<br />
You can rotate the image using functions builtin.<br />
<br />
See demo of component:<br />
<br />
[[Image:bgraimagemanipulation.jpg]]<br />
<br />
After retrieving the image modified by the component, just put the image into your destination using the stretch. It is obvious that the target must have the same ratio chosen on component for do not distort the final result.<br />
<br />
== TBGRAImageButton ==<br />
<br />
If you need some code to load and split an image from file, and then scale the borders like in this control you can download bitmapthemeutils:<br />
* https://sourceforge.net/projects/bmpthemeutils/<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgraimagebutton.png]]<br />
<br />
Component used to create a button with 4 states from Bitmap.<br />
<br />
'''Features:'''<br />
* Load the image from the "Bitmap" property in the object inspector or load from file using "BitmapFile".<br />
<br />
// You can load bmp and also png files<br />
BGRAImageButton1.BitmapLoadFromFile(BGRAImageButton1.BitmapFile);<br />
<br />
* BitmapOptions: you can set the border pixels, resample method and fill modes. Usefull to create textured / like Windows themed buttons.<br />
* AutoSize, ModalResult.<br />
* Text with Shadow, you can disable text render with the option "TextVisible".<br />
* Sound: in mouse enter and leave in Windows from .wav files.<br />
* Toggle: you can read / set the current state with the property "Checked".<br />
* Animation: glowing effect.<br />
<br />
'''Usage:'''<br />
<br />
The bitmap must contain 4 states (from top to bottom, with the same Height) in the following order: normal, enter, pressed, disabled.<br />
<br />
If you choose to use BitmapOptions you need to have for each state an image which has a border, and inside some content that can be repeated. Then with FillCenter option (if you want a textured button), it gets repeated while the borders stay as they are. This is like the method used in Windows to theme the buttons.<br />
<br />
''Example Button:''<br />
<br />
[[Image:samplebgraimagebutton.png]]<br />
<br />
''Example Button (with Alpha):''<br />
<br />
[[Image:samplebgraimagebuttonalpha.png]]<br />
<br />
== TBGRAVirtualScreen ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
The principle is to draw on a memory bitmap.<br />
<br />
The component has a specific event, OnRedraw, which is called when the whole bitmap needs to be redrawn. It happens at the beginning, when resizing and when the Redraw method is called.<br />
<br />
Otherwise, it is possible to modify the Bitmap property and call Invalidate or Repaint, to avoid erasing the whole bitmap content.<br />
<br />
== TBGRAShape ==<br />
<br />
'''Use as replace of:''' TShape<br />
<br />
[[Image:samplebgrashape.png]]<br />
<br />
The component has full alpha support and you can put the number of polygons you want with rounded borders & gradients (linear, radial, diamond, reflected).<br />
<br />
== TBGRAImageToggleBox ==<br />
<br />
REMOVED IN VER 1.1.0.7.<br />
<br />
'''Use as replace of:''' TToggleBox<br />
<br />
Component used to create a toggle box from Bitmap.<br />
<br />
The bitmap must contain 8 images (from top to bottom, with the same Height) in the following order: unchecked normal, unchecked enter, unchecked pressed, unchecked disabled for Unchecked state and checked normal, checked enter, checked pressed, checked disabled for Normal state.<br />
<br />
''Example toggle box:''<br />
<br />
[[Image:sampletogglebox.png]]<br />
<br />
== TBGRAGraphicControl ==<br />
<br />
'''Use as replace of:''' TPaintBox<br />
<br />
TBGRAGraphicControl, which allows to draw your component by yourself with alpha blending.<br />
<br />
== TBGRASpriteAnimation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Read more in the article [[BGRASpriteAnimation]].<br />
<br />
[[Image:bgraspriteanimation.png]]<br />
<br />
With this you can do animations from bitmap. You need an image with all the frames layout in in a horizontal position.<br />
<br />
It has the ability to specify how many times the animation should be played (0 for infinite, 1, 2, etc) and static to stop the animation, is capable to specify the speed and direction and support transparency.<br />
<br />
Features:<br />
* Animation: invert, position, lap, speed, static, repeat.<br />
* Sprite: fill opacity (global transparency), flip mode (horizontal, vertical, both), key color (transparent color), resample (normal or fine resample modes). AutoSize.<br />
* AnimatedGifToSprite: convert an animated gif to a BGRABitmap sprite.<br />
<br />
== TBGRALabel ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
Label component based on TBGRAButton.<br />
<br />
Features:<br />
* Caption with shadow or not<br />
* Full alpha and antialias support or not<br />
* WordWarp or not<br />
* Caption with Property Editor Multiline<br />
<br />
== TBGRALabelFX ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
[[Image:bgralabelfx.png]]<br />
<br />
Features:<br />
* Outline<br />
* Shadow<br />
<br />
ToDo:<br />
* Use BGRATextFX multicolor, textures.<br />
* etc.<br />
<br />
== TBGRAWin7ToolBar ==<br />
<br />
[[Image:bgrawin7toolbar.png]]<br />
<br />
Is a TBGRAVirtualScreen descendant with some default child sizing, and nice Win7 ToolBar background.<br />
<br />
== BGRASamples unit ==<br />
<br />
This unit has sample drawings, styles for buttons and colors used in different UI.<br />
<br />
[[Image:ioselements.png]]<br />
<br />
* '''Accent Color:''' the colors used in the Windows Phone. The accent color can be used in TBGRAButton and TBGRAImageButton (see the different procedures).<br />
* '''Facebook button color:''' gray, green and blue, with a procedure to create an image in the normal or pressed state, also to use this style in a TBGRAImageButton.<br />
* '''TBGRASampleStyle:''' Styles for TBGRAButton ('Default', 'Flash Player', 'Windows 7 ToolBar', 'Windows 7 ToolBar Smooth', 'Windows 7', 'Office 2010', 'Mac OSX Lion', 'Windows 7 Cristal').<br />
* '''iOS Elements:''' Draw a gray bar, the blue toolbar and a tiled background, the same elements used in the iOS screen.<br />
* '''Glass:''' used in testbgracontrols, it show an image in a virtualscreen and apply blur in the buttons area.<br />
* '''Drawings:''' flash player body and toolbar, windows 7 toolbar.<br />
<br />
* Some other usefull procedures to work with TBGRAButton and TBGRAImageButton.<br />
<br />
[[Category:Components]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=Application_Icon&diff=54450Application Icon2011-12-26T23:05:20Z<p>Lainz: /* Windows */</p>
<hr />
<div>{{Application Icon}}<br />
<br />
The application icon is usually displayed on the main window of the application, and it can be controlled by setting Application.Icon<br />
<br />
To change the icon of the executable itself, it is necessary to employ a platform-dependent technique. In Lazarus 0.9.27 support for this was added to the Project Options dialog, but it currently doesn't work for Linux because it requires calling an application to set the icon.<br />
<br />
__TOC__<br />
<br />
==IDE support for the Application Icon==<br />
<br />
Just set the icon in the Project Options dialog, accessible in the Project menu.<br />
<br />
Works for Windows and Mac OS X.<br />
<br />
==Platform-specific techniques==<br />
<br />
===Windows===<br />
<br />
1. Create a new file named "project.rc" (for example) containing:<br />
<br />
MAINICON ICON "editor.ico" <br />
<br />
2. Include in you project *.lpr file the following instruction:<br />
<br />
{$R project.rc} <br />
<br />
Work with version 0.9.24 and above.<br />
<br />
3. In the article [[Windows Icon]] you can see the best practices for creating the icon.<br />
<br />
===Setting the Application Icon on Mac OS X===<br />
<br />
<br />
Under Mac OS X it is necessary to set an icon for the Application Bundle. This is done by adding a field to the Info.plist file, like this:<br />
<br />
<key>CFBundleIconFile</key><br />
<string>iconfile.icns</string><br />
<br />
Where iconfile.icns is located inside MyBundle.app/Contents/Resources<br />
<br />
You can find instructions to create an icns file [http://www.macinstruct.com/node/59 here]<br />
<br />
===Linux===<br />
<br />
Under Linux application icons are located in special directories which are different on each Window Manager. The structure inside that directory, however, is standarized and described on the [http://www.freedesktop.org/Standards/icon-theme-spec Icon Theme Specification]<br />
<br />
====K Desktop Environment (KDE)====<br />
<br />
You can find the directory for application icons for use by all users and for each user using the command:<br />
<br />
kde-config --path icon<br />
<br />
This should print a list of colon-separated paths to stdout.<br />
<br />
====GNOME====<br />
<br />
You can find the directory for application icons for use by all users and for each user using the command:<br />
<br />
gnome-config --datadir<br />
<br />
This should print a path to stdout, inside which is found a directory called pixmaps that attends to the Icon Theme Specification.<br />
<br />
[[Category:Lazarus]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=Multimedia_Programming&diff=54438Multimedia Programming2011-12-24T17:56:31Z<p>Lainz: /* OMEGA Engine */ typo</p>
<hr />
<div>=Playing Videos=<br />
<br />
==Starting a player application==<br />
<br />
Once you know the command line and parameters you can use TProcessUTF8 to start the player:<br />
<br />
<Delphi><br />
uses <br />
Classes, ..., LCLProc, UTF8Process;<br />
<br />
...<br />
<br />
implementation<br />
<br />
procedure TMainForm.Button1Click(Sender: TObject);<br />
var<br />
Player: TProcessUTF8;<br />
begin<br />
Player:=TProcessUTF8.Create(nil);<br />
try<br />
Player.CommandLine:=PathToPlayer+' '+ParametersAndMediaFile;<br />
Player.Execute;<br />
finally<br />
Player.Free;<br />
end;<br />
end;<br />
</Delphi><br />
<br />
For example to start under Linux the mplayer to play a video use:<br />
<br />
<Delphi><br />
uses <br />
Classes, ..., FileUtil, LCLProc, UTF8Process;<br />
<br />
...<br />
<br />
implementation<br />
<br />
procedure TMainForm.Button1Click(Sender: TObject);<br />
var<br />
Player: TProcessUTF8;<br />
Filename: String;<br />
PlayerPath: String;<br />
PlayerParams: String;<br />
begin<br />
Filename:='/home/username/video.mpg';<br />
PlayerPath:=FindDefaultExecutablePath('mplayer');<br />
PlayerParams:='"'+Filename+'"';<br />
Player:=TProcessUTF8.Create(nil);<br />
try<br />
Player.CommandLine:=PlayerPath+' '+PlayerParams;<br />
Player.Execute;<br />
finally<br />
Player.Free;<br />
end;<br />
end;<br />
</Delphi><br />
<br />
==VFW - Video for Windows==<br />
<br />
Capturing and playing video streams from TV cards and webcams under Windows the [[Glossary#VFW|VFW]] [[Glossary#API|API]] can be used with [[SysRec]].<br />
<br />
==MPlayer for Linux gtk2/X==<br />
<br />
'''mplayer''' is an open source and free movie player. There is a LCL control embedding the mplayer, so you can built your own movie players or just play a video in your application. You can download it here:<br />
<pre><br />
svn co https://lazarus-ccr.svn.sourceforge.net/svnroot/lazarus-ccr/components/mplayer mplayer<br />
</pre><br />
<br />
=Playing Sounds=<br />
<br />
==Using the Audio Component Suite==<br />
<br />
Read the page about the [[ACS|Audio Component Suite]]<br />
<br />
==Using the OpenAL Library==<br />
<br />
A tutorial for Delphi can be found here: [http://www.noeska.com/doal/tutorials.aspx]<br />
<br />
Free Pascal comes with a unit for accessing OpenAL located in fpc/packages/openal as well as [http://svn.freepascal.org/svn/fpc/trunk/packages/openal/examples usage examples]<br />
<br />
==BASS==<br />
<br />
The BASS library can be downloaded from: http://www.un4seen.com/ and http://www.un4seen.com/forum/?topic=8682.0<br />
<br />
There is a DJ application, for Windows and Linux, written with Lazarus and using Bass lib:<br />
http://members.lycos.co.uk/mixk/<br />
<br />
==Audiere Library==<br />
<br />
Has bindings for Delphi, but they don't work with FPC:<br />
<br />
* http://www.casteng.com/whypascal.shtml<br />
* http://www.afterwarp.net/resources/soundlib<br />
* http://code.google.com/p/audiere-bind-delphi/<br />
<br />
==Audorra Library==<br />
<br />
Works fine with Lazarus: <br />
<br />
http://sourceforge.net/projects/audorra/<br />
<br />
==OMEGA Engine==<br />
<br />
The OMEGA Engine is a full game engine in single Omega.dll file which is just 50kb. It can successfully play FLAC,OGG,MP3,MP2,AMR and WMA files. It searches and uses installed audio codecs from the system.<br />
<br />
http://sourceforge.net/projects/omega-engine/files/<br />
<br />
The project is dead, but is very easy to use:<br />
<br />
<delphi><br />
Media_Play('Music.mp3', TRUE);<br />
</delphi><br />
<br />
==SDL + SDL_mixer==<br />
<br />
The basic SDL library comes with a very simple sound system. On top of that, SDL mixer adds more sound APIs which build a more flexible solution.<br />
<br />
==FMOD==<br />
<br />
Is a closed source solution. It is free for use for non-comercial software, but requires the payment of licenses for commercial software.<br />
<br />
==Squall sound==<br />
<br />
Squall sound works fine with FPC. It has 3D audio and EAX effects, but just supports MP3, OGG and WAV formats.<br />
<br />
http://www.afterwarp.net/resources/soundlib<br />
<br />
[[Category:Tutorials]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=BGRAControls&diff=54286BGRAControls2011-12-19T00:01:56Z<p>Lainz: /* TBGRAImageButton */</p>
<hr />
<div>{{BGRAControls}}<br />
<br />
== Install ==<br />
<br />
You can use TortoiseSVN to download the svn repository and TortoiseGIT to download the git repository.<br />
<br />
We're using BGRABitmap SVN to develop BGRAControls. Important changes in BGRABitmap can stop working BGRAControls.<br />
<br />
'''1) Download BGRABitmap'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/lazpaint/files/src/<br />
<br />
'''Latest SVN:''' svn co https://lazpaint.svn.sourceforge.net/svnroot/lazpaint lazpaint<br />
<br />
Install BGRABitmap with the file bgrabitmap.lpk<br />
<br />
'''2) Download BGRAControls'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/bgracontrols/files/<br />
<br />
'''Latest GIT:''' git://bgracontrols.git.sourceforge.net/gitroot/bgracontrols/bgracontrols <br />
<br />
Install BGRAControls with the file bgracontrols.lpk<br />
<br />
== Overview ==<br />
<br />
'''Authors:''' <br />
<br />
Dibo (package founder and maintainer, author: ''TBGRAImageList'', ''TBGRASpeedButton'', ''TBGRAButton'', ''TBGRAPanel'')<br />
<br />
Lainz (package maintainer, author: ''TBGRAImageButton'', ''TBGRAImageToggleBox'', ''TBGRASpriteAnimation'', ''TBGRALabelFX'', ''TBGRAWin7ToolBar'')<br />
<br />
Circular (package maintainer, author: ''TBGRAKnob'', ''TBGRAFlashProgressBar'', ''TBGRAVirtualScreen'', ''TBGRAShape'', ''TBGRAGraphicControl'')<br />
<br />
Emerson Cavalcanti (author: ''TBGRAImageManipulation'')<br />
<br />
codedeep (author: ''TBGRALabel'')<br />
<br />
'''License:''' Modified LGPL.<br />
<br />
As many people know, Lazarus GTK doesn't have full alpha support. I created a set of components which use TBGRABitmap for drawing icons, so it partially solves the problem with alpha in GTK. But this components set is not only a GTK patch but has more fancy components which are using the power of the BGRABitmap package.<br />
<br />
'''Screenshots:''' Some shots of the project 'testbgracontrols'.<br />
<br />
[[Image:testbgrac1.png]]<br />
<br />
''testbgracontrols > Main.''<br />
<br />
[[Image:testbgrac2.png]]<br />
<br />
''testbgracontrols > Windows 7 ToolBar.''<br />
<br />
[[Image:testbgrac4.png]]<br />
<br />
''testbgracontrols > Ribbon.''<br />
<br />
== Related Articles ==<br />
<br />
[[BGRAButton Gallery]] - Gallery of buttons with source code to use in your projects with BGRAButton.<br />
<br />
[[BGRASpriteAnimation]] - Usage of the sprite animation component.<br />
<br />
[[uE_Controls]] - Other controls developed with BGRABitmap.<br />
<br />
[[BGRABitmap]] - The library used to create this controls.<br />
<br />
[[LazPaint]] - A paint program developed with Lazarus and BGRABitmap.<br />
<br />
== Using ==<br />
<br />
Drop and use like normal component.<br />
<br />
'''Button''':<br />
* TBGRAButton<br />
* TBGRAImageButton<br />
* TBGRAImageToggleBox<br />
* TBGRASpeedButton<br />
<br />
'''Label'''<br />
* TBGRALabel<br />
* TBGRALabelFX<br />
<br />
'''Panel'''<br />
* TBGRAPanel<br />
* TBGRAVirtualScreen<br />
<br />
'''Image'''<br />
* TBGRAGraphicControl<br />
* TBGRAImageList<br />
* TBGRAImageManipulation<br />
* TBGRASpriteAnimation<br />
<br />
'''Other'''<br />
* TBGRAFlashProgressBar<br />
* TBGRAKnob<br />
* TBGRAShape<br />
* TBGRAWin7ToolBar<br />
<br />
== TBGRAImageList ==<br />
<br />
'''Use as replace of:''' TImageList<br />
<br />
'''Before:'''<br />
<br />
[[Image:before-TImageList.png]]<br />
<br />
'''After:'''<br />
<br />
[[Image:after-TBGRAImageList.png]]<br />
<br />
Component which inherits from TImageList. So each control (tested on TToolBar and TTreeView) which is using TImageList.Draw method for drawing icons, automatically can have alpha support. Just use this component instead of TImageList. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRASpeedButton ==<br />
<br />
'''Use as replace of:''' TSpeedButton<br />
<br />
[[Image:BGRASpeedButton.png]]<br />
<br />
Component which inherits from TSpeedButton and draws the glyph using TBGRABitmap. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRAButton ==<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgrabutton.png]]<br />
<br />
Customizable graphic component which is using only BGRABitmap functions for drawing. This component is insensitive for -dGTK_ONLY switch. Demo project included in package.<br />
<br />
'''Functionality:'''<br />
* Gradient, Clear or Color body. [[Double_Gradient]].<br />
* Text with shadow: BGRA antialias or like system default with ClearType.<br />
* Rounded border, inner Light.<br />
* States: normal, hover & clicked fully customizable and grayscale disabled state.<br />
* Special: Down, DropDown, Static.<br />
* Full AutoSize working with Glyph.<br />
<br />
== TBGRAPanel ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
Simple TPanel descendant which can have gradient background. Created especially for TBGRAButton (for creating a nice looking toolbar for bgrabuttons). This component is insensitive for -dGTK_ONLY switch<br />
<br />
== TBGRAKnob ==<br />
[[Image:BC-Bgraknob.png]]<br />
<br />
Graphic knob component created by circular.<br />
<br />
== TBGRAFlashProgressBar ==<br />
<br />
'''Use as replace of:''' TProgressBar<br />
<br />
[[Image:BC-Bgraflashprogressbar.png]]<br />
<br />
Flash progressbar created by circular.<br />
<br />
== TBGRAImageManipulation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Component to facilitate the importation of images in an application.<br />
<br />
In the current version you can import an image and cut out keeping the aspect ratio (or not). For example, if you want to import photos using the 3x4 ratio, adjust the 'ratio' property to 3:4. If import an image with different size, the component will ensure that the image meets the proportions of the desired dimensions.<br />
<br />
You can determine the minimum size of the image adjusting the properties 'MinWidth'and 'MinHeight'.<br />
<br />
You can rotate the image using functions builtin.<br />
<br />
See demo of component:<br />
<br />
[[Image:bgraimagemanipulation.jpg]]<br />
<br />
After retrieving the image modified by the component, just put the image into your destination using the stretch. It is obvious that the target must have the same ratio chosen on component for do not distort the final result.<br />
<br />
== TBGRAImageButton ==<br />
<br />
If you need some code to load and split an image from file, and then scale the borders like in this control you can download bitmapthemeutils:<br />
* https://sourceforge.net/projects/bmpthemeutils/<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgraimagebutton.png]]<br />
<br />
Component used to create a button with 4 states from Bitmap.<br />
<br />
'''Features:'''<br />
* Load the image from the "Bitmap" property in the object inspector or load from file using "BitmapFile".<br />
<br />
// You can load bmp and also png files<br />
BGRAImageButton1.BitmapLoadFromFile(BGRAImageButton1.BitmapFile);<br />
<br />
* BitmapOptions: you can set the border pixels, resample method and fill modes. Usefull to create textured / like Windows themed buttons.<br />
* AutoSize, ModalResult.<br />
* Text with Shadow, you can disable text render with the option "TextVisible".<br />
* Sound: in mouse enter and leave in Windows from .wav files.<br />
* Toggle: you can read / set the current state with the property "Checked".<br />
* Animation: glowing effect.<br />
<br />
'''Usage:'''<br />
<br />
The bitmap must contain 4 states (from top to bottom, with the same Height) in the following order: normal, enter, pressed, disabled.<br />
<br />
If you choose to use BitmapOptions you need to have for each state an image which has a border, and inside some content that can be repeated. Then with FillCenter option (if you want a textured button), it gets repeated while the borders stay as they are. This is like the method used in Windows to theme the buttons.<br />
<br />
''Example Button:''<br />
<br />
[[Image:samplebgraimagebutton.png]]<br />
<br />
''Example Button (with Alpha):''<br />
<br />
[[Image:samplebgraimagebuttonalpha.png]]<br />
<br />
== TBGRAVirtualScreen ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
The principle is to draw on a memory bitmap.<br />
<br />
The component has a specific event, OnRedraw, which is called when the whole bitmap needs to be redrawn. It happens at the beginning, when resizing and when the Redraw method is called.<br />
<br />
Otherwise, it is possible to modify the Bitmap property and call Invalidate or Repaint, to avoid erasing the whole bitmap content.<br />
<br />
== TBGRAShape ==<br />
<br />
'''Use as replace of:''' TShape<br />
<br />
[[Image:samplebgrashape.png]]<br />
<br />
The component has full alpha support and you can put the number of polygons you want with rounded borders & gradients (linear, radial, diamond, reflected).<br />
<br />
== TBGRAImageToggleBox ==<br />
<br />
REMOVED IN VER 1.1.0.7.<br />
<br />
'''Use as replace of:''' TToggleBox<br />
<br />
Component used to create a toggle box from Bitmap.<br />
<br />
The bitmap must contain 8 images (from top to bottom, with the same Height) in the following order: unchecked normal, unchecked enter, unchecked pressed, unchecked disabled for Unchecked state and checked normal, checked enter, checked pressed, checked disabled for Normal state.<br />
<br />
''Example toggle box:''<br />
<br />
[[Image:sampletogglebox.png]]<br />
<br />
== TBGRAGraphicControl ==<br />
<br />
'''Use as replace of:''' TPaintBox<br />
<br />
TBGRAGraphicControl, which allows to draw your component by yourself with alpha blending.<br />
<br />
== TBGRASpriteAnimation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Read more in the article [[BGRASpriteAnimation]].<br />
<br />
[[Image:bgraspriteanimation.png]]<br />
<br />
With this you can do animations from bitmap. You need an image with all the frames layout in in a horizontal position.<br />
<br />
It has the ability to specify how many times the animation should be played (0 for infinite, 1, 2, etc) and static to stop the animation, is capable to specify the speed and direction and support transparency.<br />
<br />
Features:<br />
* Animation: invert, position, lap, speed, static, repeat.<br />
* Sprite: fill opacity (global transparency), flip mode (horizontal, vertical, both), key color (transparent color), resample (normal or fine resample modes). AutoSize.<br />
* AnimatedGifToSprite: convert an animated gif to a BGRABitmap sprite.<br />
<br />
== TBGRALabel ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
Label component based on TBGRAButton.<br />
<br />
Features:<br />
* Caption with shadow or not<br />
* Full alpha and antialias support or not<br />
* WordWarp or not<br />
* Caption with Property Editor Multiline<br />
<br />
== TBGRALabelFX ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
[[Image:bgralabelfx.png]]<br />
<br />
Features:<br />
* Outline<br />
* Shadow<br />
<br />
ToDo:<br />
* Use BGRATextFX multicolor, textures.<br />
* etc.<br />
<br />
== TBGRAWin7ToolBar ==<br />
<br />
[[Image:bgrawin7toolbar.png]]<br />
<br />
Is a TBGRAVirtualScreen descendant with some default child sizing, and nice Win7 ToolBar background.<br />
<br />
== BGRASamples unit ==<br />
<br />
This unit has sample drawings, styles for buttons and colors used in different UI.<br />
<br />
[[Image:ioselements.png]]<br />
<br />
* '''Accent Color:''' the colors used in the Windows Phone. The accent color can be used in TBGRAButton and TBGRAImageButton (see the different procedures).<br />
* '''Facebook button color:''' gray, green and blue, with a procedure to create an image in the normal or pressed state, also to use this style in a TBGRAImageButton.<br />
* '''TBGRASampleStyle:''' Styles for TBGRAButton ('Default', 'Flash Player', 'Windows 7 ToolBar', 'Windows 7 ToolBar Smooth', 'Windows 7', 'Office 2010', 'Mac OSX Lion', 'Windows 7 Cristal').<br />
* '''iOS Elements:''' Draw a gray bar, the blue toolbar and a tiled background, the same elements used in the iOS screen.<br />
* '''Glass:''' used in testbgracontrols, it show an image in a virtualscreen and apply blur in the buttons area.<br />
* '''Drawings:''' flash player body and toolbar, windows 7 toolbar.<br />
<br />
* Some other usefull procedures to work with TBGRAButton and TBGRAImageButton.<br />
<br />
[[Category:Components]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=BGRAControls&diff=54183BGRAControls2011-12-11T16:13:13Z<p>Lainz: /* TBGRAImageButton */ missing 'Animation'</p>
<hr />
<div>{{BGRAControls}}<br />
<br />
== Install ==<br />
<br />
You can use TortoiseSVN to download the svn repository and TortoiseGIT to download the git repository.<br />
<br />
We're using BGRABitmap SVN to develop BGRAControls. Important changes in BGRABitmap can stop working BGRAControls.<br />
<br />
'''1) Download BGRABitmap'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/lazpaint/files/src/<br />
<br />
'''Latest SVN:''' svn co https://lazpaint.svn.sourceforge.net/svnroot/lazpaint lazpaint<br />
<br />
Install BGRABitmap with the file bgrabitmap.lpk<br />
<br />
'''2) Download BGRAControls'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/bgracontrols/files/<br />
<br />
'''Latest GIT:''' git://bgracontrols.git.sourceforge.net/gitroot/bgracontrols/bgracontrols <br />
<br />
Install BGRAControls with the file bgracontrols.lpk<br />
<br />
== Overview ==<br />
<br />
'''Authors:''' <br />
<br />
Dibo (package founder and maintainer, author: ''TBGRAImageList'', ''TBGRASpeedButton'', ''TBGRAButton'', ''TBGRAPanel'')<br />
<br />
Lainz (package maintainer, author: ''TBGRAImageButton'', ''TBGRAImageToggleBox'', ''TBGRASpriteAnimation'', ''TBGRALabelFX'', ''TBGRAWin7ToolBar'')<br />
<br />
Circular (package maintainer, author: ''TBGRAKnob'', ''TBGRAFlashProgressBar'', ''TBGRAVirtualScreen'', ''TBGRAShape'', ''TBGRAGraphicControl'')<br />
<br />
Emerson Cavalcanti (author: ''TBGRAImageManipulation'')<br />
<br />
codedeep (author: ''TBGRALabel'')<br />
<br />
'''License:''' Modified LGPL.<br />
<br />
As many people know, Lazarus GTK doesn't have full alpha support. I created a set of components which use TBGRABitmap for drawing icons, so it partially solves the problem with alpha in GTK. But this components set is not only a GTK patch but has more fancy components which are using the power of the BGRABitmap package.<br />
<br />
'''Screenshots:''' Some shots of the project 'testbgracontrols'.<br />
<br />
[[Image:testbgrac1.png]]<br />
<br />
''testbgracontrols > Main.''<br />
<br />
[[Image:testbgrac2.png]]<br />
<br />
''testbgracontrols > Windows 7 ToolBar.''<br />
<br />
[[Image:testbgrac4.png]]<br />
<br />
''testbgracontrols > Ribbon.''<br />
<br />
== Related Articles ==<br />
<br />
[[BGRAButton Gallery]] - Gallery of buttons with source code to use in your projects with BGRAButton.<br />
<br />
[[BGRASpriteAnimation]] - Usage of the sprite animation component.<br />
<br />
[[uE_Controls]] - Other controls developed with BGRABitmap.<br />
<br />
[[BGRABitmap]] - The library used to create this controls.<br />
<br />
[[LazPaint]] - A paint program developed with Lazarus and BGRABitmap.<br />
<br />
== Using ==<br />
<br />
Drop and use like normal component.<br />
<br />
'''Button''':<br />
* TBGRAButton<br />
* TBGRAImageButton<br />
* TBGRAImageToggleBox<br />
* TBGRASpeedButton<br />
<br />
'''Label'''<br />
* TBGRALabel<br />
* TBGRALabelFX<br />
<br />
'''Panel'''<br />
* TBGRAPanel<br />
* TBGRAVirtualScreen<br />
<br />
'''Image'''<br />
* TBGRAGraphicControl<br />
* TBGRAImageList<br />
* TBGRAImageManipulation<br />
* TBGRASpriteAnimation<br />
<br />
'''Other'''<br />
* TBGRAFlashProgressBar<br />
* TBGRAKnob<br />
* TBGRAShape<br />
* TBGRAWin7ToolBar<br />
<br />
== TBGRAImageList ==<br />
<br />
'''Use as replace of:''' TImageList<br />
<br />
'''Before:'''<br />
<br />
[[Image:before-TImageList.png]]<br />
<br />
'''After:'''<br />
<br />
[[Image:after-TBGRAImageList.png]]<br />
<br />
Component which inherits from TImageList. So each control (tested on TToolBar and TTreeView) which is using TImageList.Draw method for drawing icons, automatically can have alpha support. Just use this component instead of TImageList. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRASpeedButton ==<br />
<br />
'''Use as replace of:''' TSpeedButton<br />
<br />
[[Image:BGRASpeedButton.png]]<br />
<br />
Component which inherits from TSpeedButton and draws the glyph using TBGRABitmap. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRAButton ==<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgrabutton.png]]<br />
<br />
Customizable graphic component which is using only BGRABitmap functions for drawing. This component is insensitive for -dGTK_ONLY switch. Demo project included in package.<br />
<br />
'''Functionality:'''<br />
* Gradient, Clear or Color body. [[Double_Gradient]].<br />
* Text with shadow: BGRA antialias or like system default with ClearType.<br />
* Rounded border, inner Light.<br />
* States: normal, hover & clicked fully customizable and grayscale disabled state.<br />
* Special: Down, DropDown, Static.<br />
* Full AutoSize working with Glyph.<br />
<br />
== TBGRAPanel ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
Simple TPanel descendant which can have gradient background. Created especially for TBGRAButton (for creating a nice looking toolbar for bgrabuttons). This component is insensitive for -dGTK_ONLY switch<br />
<br />
== TBGRAKnob ==<br />
[[Image:BC-Bgraknob.png]]<br />
<br />
Graphic knob component created by circular.<br />
<br />
== TBGRAFlashProgressBar ==<br />
<br />
'''Use as replace of:''' TProgressBar<br />
<br />
[[Image:BC-Bgraflashprogressbar.png]]<br />
<br />
Flash progressbar created by circular.<br />
<br />
== TBGRAImageManipulation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Component to facilitate the importation of images in an application.<br />
<br />
In the current version you can import an image and cut out keeping the aspect ratio (or not). For example, if you want to import photos using the 3x4 ratio, adjust the 'ratio' property to 3:4. If import an image with different size, the component will ensure that the image meets the proportions of the desired dimensions.<br />
<br />
You can determine the minimum size of the image adjusting the properties 'MinWidth'and 'MinHeight'.<br />
<br />
You can rotate the image using functions builtin.<br />
<br />
See demo of component:<br />
<br />
[[Image:bgraimagemanipulation.jpg]]<br />
<br />
After retrieving the image modified by the component, just put the image into your destination using the stretch. It is obvious that the target must have the same ratio chosen on component for do not distort the final result.<br />
<br />
== TBGRAImageButton ==<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgraimagebutton.png]]<br />
<br />
Component used to create a button with 4 states from Bitmap.<br />
<br />
'''Features:'''<br />
* Load the image from the "Bitmap" property in the object inspector or load from file using "BitmapFile".<br />
<br />
// You can load bmp and also png files<br />
BGRAImageButton1.BitmapLoadFromFile(BGRAImageButton1.BitmapFile);<br />
<br />
* BitmapOptions: you can set the border pixels, resample method and fill modes. Usefull to create textured / like Windows themed buttons.<br />
* AutoSize, ModalResult.<br />
* Text with Shadow, you can disable text render with the option "TextVisible".<br />
* Sound: in mouse enter and leave in Windows from .wav files.<br />
* Toggle: you can read / set the current state with the property "Checked".<br />
* Animation: glowing effect.<br />
<br />
'''Usage:'''<br />
<br />
The bitmap must contain 4 states (from top to bottom, with the same Height) in the following order: normal, enter, pressed, disabled.<br />
<br />
If you choose to use BitmapOptions you need to have for each state an image which has a border, and inside some content that can be repeated. Then with FillCenter option (if you want a textured button), it gets repeated while the borders stay as they are. This is like the method used in Windows to theme the buttons.<br />
<br />
''Example Button:''<br />
<br />
[[Image:samplebgraimagebutton.png]]<br />
<br />
''Example Button (with Alpha):''<br />
<br />
[[Image:samplebgraimagebuttonalpha.png]]<br />
<br />
== TBGRAVirtualScreen ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
The principle is to draw on a memory bitmap.<br />
<br />
The component has a specific event, OnRedraw, which is called when the whole bitmap needs to be redrawn. It happens at the beginning, when resizing and when the Redraw method is called.<br />
<br />
Otherwise, it is possible to modify the Bitmap property and call Invalidate or Repaint, to avoid erasing the whole bitmap content.<br />
<br />
== TBGRAShape ==<br />
<br />
'''Use as replace of:''' TShape<br />
<br />
[[Image:samplebgrashape.png]]<br />
<br />
The component has full alpha support and you can put the number of polygons you want with rounded borders & gradients (linear, radial, diamond, reflected).<br />
<br />
== TBGRAImageToggleBox ==<br />
<br />
REMOVED IN VER 1.1.0.7.<br />
<br />
'''Use as replace of:''' TToggleBox<br />
<br />
Component used to create a toggle box from Bitmap.<br />
<br />
The bitmap must contain 8 images (from top to bottom, with the same Height) in the following order: unchecked normal, unchecked enter, unchecked pressed, unchecked disabled for Unchecked state and checked normal, checked enter, checked pressed, checked disabled for Normal state.<br />
<br />
''Example toggle box:''<br />
<br />
[[Image:sampletogglebox.png]]<br />
<br />
== TBGRAGraphicControl ==<br />
<br />
'''Use as replace of:''' TPaintBox<br />
<br />
TBGRAGraphicControl, which allows to draw your component by yourself with alpha blending.<br />
<br />
== TBGRASpriteAnimation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Read more in the article [[BGRASpriteAnimation]].<br />
<br />
[[Image:bgraspriteanimation.png]]<br />
<br />
With this you can do animations from bitmap. You need an image with all the frames layout in in a horizontal position.<br />
<br />
It has the ability to specify how many times the animation should be played (0 for infinite, 1, 2, etc) and static to stop the animation, is capable to specify the speed and direction and support transparency.<br />
<br />
Features:<br />
* Animation: invert, position, lap, speed, static, repeat.<br />
* Sprite: fill opacity (global transparency), flip mode (horizontal, vertical, both), key color (transparent color), resample (normal or fine resample modes). AutoSize.<br />
* AnimatedGifToSprite: convert an animated gif to a BGRABitmap sprite.<br />
<br />
== TBGRALabel ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
Label component based on TBGRAButton.<br />
<br />
Features:<br />
* Caption with shadow or not<br />
* Full alpha and antialias support or not<br />
* WordWarp or not<br />
* Caption with Property Editor Multiline<br />
<br />
== TBGRALabelFX ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
[[Image:bgralabelfx.png]]<br />
<br />
Features:<br />
* Outline<br />
* Shadow<br />
<br />
ToDo:<br />
* Use BGRATextFX multicolor, textures.<br />
* etc.<br />
<br />
== TBGRAWin7ToolBar ==<br />
<br />
[[Image:bgrawin7toolbar.png]]<br />
<br />
Is a TBGRAVirtualScreen descendant with some default child sizing, and nice Win7 ToolBar background.<br />
<br />
== BGRASamples unit ==<br />
<br />
This unit has sample drawings, styles for buttons and colors used in different UI.<br />
<br />
[[Image:ioselements.png]]<br />
<br />
* '''Accent Color:''' the colors used in the Windows Phone. The accent color can be used in TBGRAButton and TBGRAImageButton (see the different procedures).<br />
* '''Facebook button color:''' gray, green and blue, with a procedure to create an image in the normal or pressed state, also to use this style in a TBGRAImageButton.<br />
* '''TBGRASampleStyle:''' Styles for TBGRAButton ('Default', 'Flash Player', 'Windows 7 ToolBar', 'Windows 7 ToolBar Smooth', 'Windows 7', 'Office 2010', 'Mac OSX Lion', 'Windows 7 Cristal').<br />
* '''iOS Elements:''' Draw a gray bar, the blue toolbar and a tiled background, the same elements used in the iOS screen.<br />
* '''Glass:''' used in testbgracontrols, it show an image in a virtualscreen and apply blur in the buttons area.<br />
* '''Drawings:''' flash player body and toolbar, windows 7 toolbar.<br />
<br />
* Some other usefull procedures to work with TBGRAButton and TBGRAImageButton.<br />
<br />
[[Category:Components]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=BGRAControls&diff=54182BGRAControls2011-12-11T16:11:33Z<p>Lainz: /* TBGRAImageButton */ description</p>
<hr />
<div>{{BGRAControls}}<br />
<br />
== Install ==<br />
<br />
You can use TortoiseSVN to download the svn repository and TortoiseGIT to download the git repository.<br />
<br />
We're using BGRABitmap SVN to develop BGRAControls. Important changes in BGRABitmap can stop working BGRAControls.<br />
<br />
'''1) Download BGRABitmap'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/lazpaint/files/src/<br />
<br />
'''Latest SVN:''' svn co https://lazpaint.svn.sourceforge.net/svnroot/lazpaint lazpaint<br />
<br />
Install BGRABitmap with the file bgrabitmap.lpk<br />
<br />
'''2) Download BGRAControls'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/bgracontrols/files/<br />
<br />
'''Latest GIT:''' git://bgracontrols.git.sourceforge.net/gitroot/bgracontrols/bgracontrols <br />
<br />
Install BGRAControls with the file bgracontrols.lpk<br />
<br />
== Overview ==<br />
<br />
'''Authors:''' <br />
<br />
Dibo (package founder and maintainer, author: ''TBGRAImageList'', ''TBGRASpeedButton'', ''TBGRAButton'', ''TBGRAPanel'')<br />
<br />
Lainz (package maintainer, author: ''TBGRAImageButton'', ''TBGRAImageToggleBox'', ''TBGRASpriteAnimation'', ''TBGRALabelFX'', ''TBGRAWin7ToolBar'')<br />
<br />
Circular (package maintainer, author: ''TBGRAKnob'', ''TBGRAFlashProgressBar'', ''TBGRAVirtualScreen'', ''TBGRAShape'', ''TBGRAGraphicControl'')<br />
<br />
Emerson Cavalcanti (author: ''TBGRAImageManipulation'')<br />
<br />
codedeep (author: ''TBGRALabel'')<br />
<br />
'''License:''' Modified LGPL.<br />
<br />
As many people know, Lazarus GTK doesn't have full alpha support. I created a set of components which use TBGRABitmap for drawing icons, so it partially solves the problem with alpha in GTK. But this components set is not only a GTK patch but has more fancy components which are using the power of the BGRABitmap package.<br />
<br />
'''Screenshots:''' Some shots of the project 'testbgracontrols'.<br />
<br />
[[Image:testbgrac1.png]]<br />
<br />
''testbgracontrols > Main.''<br />
<br />
[[Image:testbgrac2.png]]<br />
<br />
''testbgracontrols > Windows 7 ToolBar.''<br />
<br />
[[Image:testbgrac4.png]]<br />
<br />
''testbgracontrols > Ribbon.''<br />
<br />
== Related Articles ==<br />
<br />
[[BGRAButton Gallery]] - Gallery of buttons with source code to use in your projects with BGRAButton.<br />
<br />
[[BGRASpriteAnimation]] - Usage of the sprite animation component.<br />
<br />
[[uE_Controls]] - Other controls developed with BGRABitmap.<br />
<br />
[[BGRABitmap]] - The library used to create this controls.<br />
<br />
[[LazPaint]] - A paint program developed with Lazarus and BGRABitmap.<br />
<br />
== Using ==<br />
<br />
Drop and use like normal component.<br />
<br />
'''Button''':<br />
* TBGRAButton<br />
* TBGRAImageButton<br />
* TBGRAImageToggleBox<br />
* TBGRASpeedButton<br />
<br />
'''Label'''<br />
* TBGRALabel<br />
* TBGRALabelFX<br />
<br />
'''Panel'''<br />
* TBGRAPanel<br />
* TBGRAVirtualScreen<br />
<br />
'''Image'''<br />
* TBGRAGraphicControl<br />
* TBGRAImageList<br />
* TBGRAImageManipulation<br />
* TBGRASpriteAnimation<br />
<br />
'''Other'''<br />
* TBGRAFlashProgressBar<br />
* TBGRAKnob<br />
* TBGRAShape<br />
* TBGRAWin7ToolBar<br />
<br />
== TBGRAImageList ==<br />
<br />
'''Use as replace of:''' TImageList<br />
<br />
'''Before:'''<br />
<br />
[[Image:before-TImageList.png]]<br />
<br />
'''After:'''<br />
<br />
[[Image:after-TBGRAImageList.png]]<br />
<br />
Component which inherits from TImageList. So each control (tested on TToolBar and TTreeView) which is using TImageList.Draw method for drawing icons, automatically can have alpha support. Just use this component instead of TImageList. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRASpeedButton ==<br />
<br />
'''Use as replace of:''' TSpeedButton<br />
<br />
[[Image:BGRASpeedButton.png]]<br />
<br />
Component which inherits from TSpeedButton and draws the glyph using TBGRABitmap. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRAButton ==<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgrabutton.png]]<br />
<br />
Customizable graphic component which is using only BGRABitmap functions for drawing. This component is insensitive for -dGTK_ONLY switch. Demo project included in package.<br />
<br />
'''Functionality:'''<br />
* Gradient, Clear or Color body. [[Double_Gradient]].<br />
* Text with shadow: BGRA antialias or like system default with ClearType.<br />
* Rounded border, inner Light.<br />
* States: normal, hover & clicked fully customizable and grayscale disabled state.<br />
* Special: Down, DropDown, Static.<br />
* Full AutoSize working with Glyph.<br />
<br />
== TBGRAPanel ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
Simple TPanel descendant which can have gradient background. Created especially for TBGRAButton (for creating a nice looking toolbar for bgrabuttons). This component is insensitive for -dGTK_ONLY switch<br />
<br />
== TBGRAKnob ==<br />
[[Image:BC-Bgraknob.png]]<br />
<br />
Graphic knob component created by circular.<br />
<br />
== TBGRAFlashProgressBar ==<br />
<br />
'''Use as replace of:''' TProgressBar<br />
<br />
[[Image:BC-Bgraflashprogressbar.png]]<br />
<br />
Flash progressbar created by circular.<br />
<br />
== TBGRAImageManipulation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Component to facilitate the importation of images in an application.<br />
<br />
In the current version you can import an image and cut out keeping the aspect ratio (or not). For example, if you want to import photos using the 3x4 ratio, adjust the 'ratio' property to 3:4. If import an image with different size, the component will ensure that the image meets the proportions of the desired dimensions.<br />
<br />
You can determine the minimum size of the image adjusting the properties 'MinWidth'and 'MinHeight'.<br />
<br />
You can rotate the image using functions builtin.<br />
<br />
See demo of component:<br />
<br />
[[Image:bgraimagemanipulation.jpg]]<br />
<br />
After retrieving the image modified by the component, just put the image into your destination using the stretch. It is obvious that the target must have the same ratio chosen on component for do not distort the final result.<br />
<br />
== TBGRAImageButton ==<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgraimagebutton.png]]<br />
<br />
Component used to create a button with 4 states from Bitmap.<br />
<br />
'''Features:'''<br />
* Load the image from the "Bitmap" property in the object inspector or load from file using "BitmapFile".<br />
<br />
// You can load bmp and also png files<br />
BGRAImageButton1.BitmapLoadFromFile(BGRAImageButton1.BitmapFile);<br />
<br />
* BitmapOptions: you can set the border pixels, resample method and fill modes. Usefull to create textured / like Windows themed buttons.<br />
* AutoSize, ModalResult.<br />
* Text with Shadow, you can disable text render with the option "TextVisible".<br />
* Sound: in mouse enter and leave in Windows from .wav files.<br />
* Toggle: you can read / set the current state with the property "Checked".<br />
<br />
'''Usage:'''<br />
<br />
The bitmap must contain 4 states (from top to bottom, with the same Height) in the following order: normal, enter, pressed, disabled.<br />
<br />
If you choose to use BitmapOptions you need to have for each state an image which has a border, and inside some content that can be repeated. Then with FillCenter option (if you want a textured button), it gets repeated while the borders stay as they are. This is like the method used in Windows to theme the buttons.<br />
<br />
''Example Button:''<br />
<br />
[[Image:samplebgraimagebutton.png]]<br />
<br />
''Example Button (with Alpha):''<br />
<br />
[[Image:samplebgraimagebuttonalpha.png]]<br />
<br />
== TBGRAVirtualScreen ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
The principle is to draw on a memory bitmap.<br />
<br />
The component has a specific event, OnRedraw, which is called when the whole bitmap needs to be redrawn. It happens at the beginning, when resizing and when the Redraw method is called.<br />
<br />
Otherwise, it is possible to modify the Bitmap property and call Invalidate or Repaint, to avoid erasing the whole bitmap content.<br />
<br />
== TBGRAShape ==<br />
<br />
'''Use as replace of:''' TShape<br />
<br />
[[Image:samplebgrashape.png]]<br />
<br />
The component has full alpha support and you can put the number of polygons you want with rounded borders & gradients (linear, radial, diamond, reflected).<br />
<br />
== TBGRAImageToggleBox ==<br />
<br />
REMOVED IN VER 1.1.0.7.<br />
<br />
'''Use as replace of:''' TToggleBox<br />
<br />
Component used to create a toggle box from Bitmap.<br />
<br />
The bitmap must contain 8 images (from top to bottom, with the same Height) in the following order: unchecked normal, unchecked enter, unchecked pressed, unchecked disabled for Unchecked state and checked normal, checked enter, checked pressed, checked disabled for Normal state.<br />
<br />
''Example toggle box:''<br />
<br />
[[Image:sampletogglebox.png]]<br />
<br />
== TBGRAGraphicControl ==<br />
<br />
'''Use as replace of:''' TPaintBox<br />
<br />
TBGRAGraphicControl, which allows to draw your component by yourself with alpha blending.<br />
<br />
== TBGRASpriteAnimation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Read more in the article [[BGRASpriteAnimation]].<br />
<br />
[[Image:bgraspriteanimation.png]]<br />
<br />
With this you can do animations from bitmap. You need an image with all the frames layout in in a horizontal position.<br />
<br />
It has the ability to specify how many times the animation should be played (0 for infinite, 1, 2, etc) and static to stop the animation, is capable to specify the speed and direction and support transparency.<br />
<br />
Features:<br />
* Animation: invert, position, lap, speed, static, repeat.<br />
* Sprite: fill opacity (global transparency), flip mode (horizontal, vertical, both), key color (transparent color), resample (normal or fine resample modes). AutoSize.<br />
* AnimatedGifToSprite: convert an animated gif to a BGRABitmap sprite.<br />
<br />
== TBGRALabel ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
Label component based on TBGRAButton.<br />
<br />
Features:<br />
* Caption with shadow or not<br />
* Full alpha and antialias support or not<br />
* WordWarp or not<br />
* Caption with Property Editor Multiline<br />
<br />
== TBGRALabelFX ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
[[Image:bgralabelfx.png]]<br />
<br />
Features:<br />
* Outline<br />
* Shadow<br />
<br />
ToDo:<br />
* Use BGRATextFX multicolor, textures.<br />
* etc.<br />
<br />
== TBGRAWin7ToolBar ==<br />
<br />
[[Image:bgrawin7toolbar.png]]<br />
<br />
Is a TBGRAVirtualScreen descendant with some default child sizing, and nice Win7 ToolBar background.<br />
<br />
== BGRASamples unit ==<br />
<br />
This unit has sample drawings, styles for buttons and colors used in different UI.<br />
<br />
[[Image:ioselements.png]]<br />
<br />
* '''Accent Color:''' the colors used in the Windows Phone. The accent color can be used in TBGRAButton and TBGRAImageButton (see the different procedures).<br />
* '''Facebook button color:''' gray, green and blue, with a procedure to create an image in the normal or pressed state, also to use this style in a TBGRAImageButton.<br />
* '''TBGRASampleStyle:''' Styles for TBGRAButton ('Default', 'Flash Player', 'Windows 7 ToolBar', 'Windows 7 ToolBar Smooth', 'Windows 7', 'Office 2010', 'Mac OSX Lion', 'Windows 7 Cristal').<br />
* '''iOS Elements:''' Draw a gray bar, the blue toolbar and a tiled background, the same elements used in the iOS screen.<br />
* '''Glass:''' used in testbgracontrols, it show an image in a virtualscreen and apply blur in the buttons area.<br />
* '''Drawings:''' flash player body and toolbar, windows 7 toolbar.<br />
<br />
* Some other usefull procedures to work with TBGRAButton and TBGRAImageButton.<br />
<br />
[[Category:Components]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=Developing_with_Graphics&diff=54164Developing with Graphics2011-12-08T18:08:32Z<p>Lainz: /* Using the non-native StretchDraw from LazCanvas */ free interpolation</p>
<hr />
<div>{{Developing with Graphics}}<br />
<br />
This page describes the basic classes and techniques regarding drawing graphics with Lazarus. Other more specific topics are in separate articles.<br />
<br />
__TOC__<br />
<br />
== Libraries ==<br />
<br />
[[Graphics libraries]] - here you can see the main graphic libraries you can use to develop.<br />
<br />
==Other graphics articles== <br />
===2D drawing===<br />
* [[ZenGL]] - cross-platform game development library using OpenGL.<br />
* [[BGRABitmap]] - Drawing shapes and bitmaps with transparency, direct access to pixels, etc. <br />
* [[LazRGBGraphics]] - A package for fast in memory image processing and pixel manipulations (like scan line).<br />
* [[fpvectorial]] - Offers support to read, modify and write vectorial images. <br />
* [[Double Gradient]] - Draw 'double gradient' & 'n gradient' bitmaps easy.<br />
* [[Gradient Filler]] - TGradientFiller is the best way to create custom n gradients in Lazarus.<br />
* [[PascalMagick]] - an easy to use API for interfacing with [http://www.imagemagick.org ImageMagick], a multiplatform free software suite to create, edit, and compose bitmap images.<br />
* [[Sample Graphics]] - graphics gallery created with Lazarus and drawing tools<br />
* [[Fast direct pixel access]] - speed comparison of some methods for direct bitmap pixel access<br />
<br />
===3D drawing===<br />
* [[GLScene]] - A port of the 3D visual OpenGL graphics Library [http://www.glscene.org GLScene]<br />
===Charts===<br />
* [[TAChart]] - Charting component for Lazarus<br />
* [[PlotPanel]] - A plotting and charting component for animated graphs<br />
* [[Perlin Noise]] - An article about using Perlin Noise on LCL applications.<br />
<br />
==Introduction to the Graphics model of the LCL==<br />
<br />
The LCL provides two kinds of drawing class: Native classes and non-native classes. Native graphics classes are the most traditional way of drawing graphics in the LCL and are also the most important one, while the non-native classes are complementary, but also very important. The native classes are mostly located in the unit '''Graphics''' of the LCL and are the very know classes: TBitmap, TCanvas, TFont, TBrush, TPen, TPortableNetworkGraphic, etc.<br />
<br />
TCanvas is a class capable of executing drawings. It cannot exist alone and must either be attached to something visible (or at least which may possibly be visible), such as a visual control descending from TControl, or be attached to a off-screen buffer from a TRasterImage descendent (TBitmap is the most commonly used). TFont, TBrush and TPen describe how the drawing of various operations will be executed in the Canvas.<br />
<br />
TRasterImage (usually used via it's descendent TBitmap) is a memory area reserved for drawing graphics, but it is created for maximum compatibility with the native Canvas and therefore in LCL-Gtk2 in X11 it is located in the X11 server, which makes pixel access via the Pixels property extremely slow. In Windows it is very fast because Windows allows creating a locally allocated image which can receive drawings from a Windows Canvas. <br />
<br />
Besides these there are also non-native drawing classes located in the units graphtype (TRawImage), intfgraphics (TLazIntfImage) and lazcanvas (TLazCanvas, this one exists in Lazarus 0.9.31+). TRawImage is the storage and description of a memory area which contains an image. TLazIntfImage is an image which attaches itself to a TRawImage and takes care of converting between TFPColor and the real pixel format of the TRawImage. TLazCanvas is a non-native Canvas which can draw to an image in a TLazIntfImage.<br />
<br />
The main difference between the native classes and the non-native ones is that the native ones do not perform exactly the same in all platforms, because the drawing is done by the underlying platform itself. The speed and also the exact final result of the image drawing can have differences. The non-native classes are guaranteed to perform exactly the same drawing in all platforms with a pixel level precision and they all perform reasonably fast in all platforms.<br />
<br />
In the widgetset LCL-CustomDrawn the native classes are implemented using the non-native ones.<br />
<br />
All of these classes will be better described in the sections bellow.<br />
<br />
==Working with TCanvas==<br />
<br />
===Using the default GUI font===<br />
<br />
This can be done with this simple code:<br />
<br />
<delphi>SelectObject(Canvas.Handle, GetStockObject(DEFAULT_GUI_FONT));</delphi><br />
<br />
===Drawing a text limited on the width===<br />
<br />
Use the DrawText routine, first with DT_CALCRECT and then without it.<br />
<br />
<delphi>// First calculate the text size then draw it<br />
TextBox := Rect(0, currentPos.Y, Width, High(Integer));<br />
DrawText(ACanvas.Handle, PChar(Text), Length(Text),<br />
TextBox, DT_WORDBREAK or DT_INTERNAL or DT_CALCRECT);<br />
<br />
DrawText(ACanvas.Handle, PChar(Text), Length(Text),<br />
TextBox, DT_WORDBREAK or DT_INTERNAL);</delphi><br />
<br />
===Drawing text with sharp edges (non antialiased)===<br />
<br />
Some widgetsets support this via<br />
<br />
<Delphi>Canvas.Font.Quality := fqNonAntialiased;</Delphi><br />
<br />
Some widgetsets like the gtk2 do not support this and always paint antialiased. Here is a simple procedure to draw text with sharp edges under gtk2. It does not consider all cases, but it should give an idea:<br />
<br />
<Delphi>procedure PaintAliased(Canvas: TCanvas; x,y: integer; const TheText: string);<br />
var<br />
w,h: integer;<br />
IntfImg: TLazIntfImage;<br />
Img: TBitmap;<br />
dy: Integer;<br />
dx: Integer;<br />
col: TFPColor;<br />
FontColor: TColor;<br />
c: TColor;<br />
begin<br />
w:=0;<br />
h:=0;<br />
Canvas.GetTextSize(TheText,w,h);<br />
if (w<=0) or (h<=0) then exit;<br />
Img:=TBitmap.Create;<br />
IntfImg:=nil;<br />
try<br />
// paint text to a bitmap<br />
Img.Masked:=true;<br />
Img.SetSize(w,h);<br />
Img.Canvas.Brush.Style:=bsSolid;<br />
Img.Canvas.Brush.Color:=clWhite;<br />
Img.Canvas.FillRect(0,0,w,h);<br />
Img.Canvas.Font:=Canvas.Font;<br />
Img.Canvas.TextOut(0,0,TheText);<br />
// get memory image<br />
IntfImg:=Img.CreateIntfImage;<br />
// replace gray pixels<br />
FontColor:=ColorToRGB(Canvas.Font.Color);<br />
for dy:=0 to h-1 do begin<br />
for dx:=0 to w-1 do begin<br />
col:=IntfImg.Colors[dx,dy];<br />
c:=FPColorToTColor(col);<br />
if c<>FontColor then<br />
IntfImg.Colors[dx,dy]:=colTransparent;<br />
end;<br />
end;<br />
// create bitmap<br />
Img.LoadFromIntfImage(IntfImg);<br />
// paint<br />
Canvas.Draw(x,y,Img);<br />
finally<br />
IntfImg.Free;<br />
Img.Free;<br />
end;<br />
end;</Delphi><br />
<br />
==Working with TBitmap==<br />
TBitmap object stores a bitmap where you can draw before showing it to the screen. When you create a bitmap, you must specify the height and width, otherwise it will be zero and nothing will be drawn.<br />
<br />
===Direct pixel access===<br />
To do direct access to bitmaps one can use libraries, such as [[BGRABitmap]], [[LazRGBGraphics]] and [[Current conversion projects#Graphics32|Graphics32]]. For a comparison of pixel access methods, see [[Fast direct pixel access|fast direct pixel access]].<br />
<br />
On some operating systems, the bitmap data is not stored in memory so it cannot be accessed directly. As Lazarus is meant to be platform independent, the TBitmap class does not provide a property like Scanline. There is a GetDataLineStart function, equivalent to Scanline, but only available for memory images like [[Developing with Graphics#Working with TLazIntfImage|TLazIntfImage]] which internally uses TRawImage.<br />
<br />
To sum it up, with the standard TBitmap, you can only change pixels indirectly, by modifying a memory bitmap, then convert it to a drawable bitmap. This process is of course slower than direct pixel access.<br />
<br />
===Drawing color transparent bitmaps===<br />
<br />
A new feature, implemented on Lazarus 0.9.11, is color transparent bitmaps. Bitmap files (*.BMP) cannot store any information about transparency, but they can work as they had if you select a color on them to represent the transparent area. This is a common trick used on Win32 applications.<br />
<br />
The following example loads a bitmap from a Windows resource, selects a color to be transparent (clFuchsia) and then draws it to a canvas.<br />
<br />
<delphi>procedure MyForm.MyButtonOnClick(Sender: TObject);<br />
var<br />
buffer: THandle;<br />
bmp: TBitmap;<br />
memstream: TMemoryStream;<br />
begin<br />
bmp := TBitmap.Create;<br />
<br />
buffer := Windows.LoadBitmap(hInstance, MAKEINTRESOURCE(ResourceID));<br />
<br />
if (buffer = 0) then exit; // Error loading the bitmap<br />
<br />
bmp.Handle := buffer;<br />
memstream := TMemoryStream.create;<br />
try<br />
bmp.SaveToStream(memstream);<br />
memstream.position := 0;<br />
bmp.LoadFromStream(memstream);<br />
finally<br />
memstream.free;<br />
end;<br />
<br />
bmp.Transparent := True;<br />
bmp.TransparentColor := clFuchsia;<br />
<br />
MyCanvas.Draw(0, 0, bmp);<br />
<br />
bmp.Free; // Release allocated resource<br />
end;</delphi><br />
<br />
Notice the memory operations performed with the [[doc:rtl/classes/tmemorystream.html|TMemoryStream]]. They are necessary to ensure the correct loading of the image.<br />
<br />
===Taking a screenshot of the screen===<br />
<br />
Since Lazarus 0.9.16 you can use LCL to take screenshots of the screen on a cross-platform way. The following example code does it (works on gtk2 and win32, but not gtk1 currently):<br />
<br />
<delphi>uses Graphics, LCLIntf, LCLType;<br />
<br />
...<br />
<br />
var<br />
MyBitmap: TBitmap;<br />
ScreenDC: HDC;<br />
begin<br />
MyBitmap := TBitmap.Create;<br />
ScreenDC := GetDC(0);<br />
MyBitmap.LoadFromDevice(ScreenDC);<br />
ReleaseDC(ScreenDC);<br />
<br />
...</delphi><br />
<br />
==Working with TLazIntfImage, TRawImage and TLazCanvas==<br />
<br />
TLazIntfImage is a non-native equivalent of TRasterImage (more commonly utilized in the form of it's descendent TBitmap). The first thing to be aware about this class is that unlike TBitmap it will not automatically allocate a memory area for the bitmap, one should first initialize a memory area and then give it to the TLazIntfImage. Right after creating a TLazIntfImage one should either connect it to a TRawImage or load it from a TBitmap.<br />
<br />
TRawImage is of the type object and therefore does not need to be created nor freed. It can either allocate the image memory itself when one calls TRawImage.CreateData or one can pass a memory block allocated for examply by a 3rd party library such as the Windows API of the Cocoa Framework from Mac OS X and pass the information of the image in TRawImage.Description, TRawImage.Data and TRawImage.DataSize. Instead of attaching it to a RawImage one could also load it from a TBitmap which will copy the data from the TBitmap and won't be syncronized with it afterwards. The TLazCanvas cannot exist alone and must always be attached to a TLazIntfImage.<br />
<br />
The example bellow shows how to choose a format for the data and ask the TRawImage to create it for us and then we attach it to a TLazIntfImage and then attach a TLazCanvas to it:<br />
<br />
<delphi><br />
uses graphtype, intfgraphics, lazcanvas;<br />
<br />
var<br />
AImage: TLazIntfImage;<br />
ACanvas: TLazCanvas;<br />
lRawImage: TRawImage;<br />
begin<br />
lRawImage.Init;<br />
lRawImage.Description.Init_BPP32_A8R8G8B8_BIO_TTB(AWidth, AHeight);<br />
lRawImage.CreateData(True)<br />
AImage := TLazIntfImage.Create(AWidth, AHeight);<br />
AImage.SetRawImage(lRawImage);<br />
ACanvas := TLazCanvas.Create(AImage);<br />
</delphi><br />
<br />
===Fading example===<br />
<br />
A fading example with TLazIntfImage<br />
<br />
<delphi>{ This code has been taken from the $LazarusPath/examples/lazintfimage/fadein1.lpi project. }<br />
uses LCLType, // HBitmap type<br />
IntfGraphics, // TLazIntfImage type<br />
fpImage; // TFPColor type<br />
...<br />
procedure TForm1.FadeIn(ABitMap: TBitMap);<br />
var<br />
SrcIntfImg, TempIntfImg: TLazIntfImage;<br />
ImgHandle,ImgMaskHandle: HBitmap;<br />
FadeStep: Integer;<br />
px, py: Integer;<br />
CurColor: TFPColor;<br />
TempBitmap: TBitmap;<br />
begin<br />
SrcIntfImg:=TLazIntfImage.Create(0,0);<br />
SrcIntfImg.LoadFromBitmap(ABitmap.Handle,ABitmap.MaskHandle);<br />
TempIntfImg:=TLazIntfImage.Create(0,0);<br />
TempIntfImg.LoadFromBitmap(ABitmap.Handle,ABitmap.MaskHandle);<br />
TempBitmap:=TBitmap.Create;<br />
for FadeStep:=1 to 32 do begin<br />
for py:=0 to SrcIntfImg.Height-1 do begin<br />
for px:=0 to SrcIntfImg.Width-1 do begin<br />
CurColor:=SrcIntfImg.Colors[px,py];<br />
CurColor.Red:=(CurColor.Red*FadeStep) shr 5;<br />
CurColor.Green:=(CurColor.Green*FadeStep) shr 5;<br />
CurColor.Blue:=(CurColor.Blue*FadeStep) shr 5;<br />
TempIntfImg.Colors[px,py]:=CurColor;<br />
end;<br />
end;<br />
TempIntfImg.CreateBitmaps(ImgHandle,ImgMaskHandle,false);<br />
TempBitmap.Handle:=ImgHandle;<br />
TempBitmap.MaskHandle:=ImgMaskHandle;<br />
Canvas.Draw(0,0,TempBitmap);<br />
end;<br />
SrcIntfImg.Free;<br />
TempIntfImg.Free;<br />
TempBitmap.Free;<br />
end;</delphi><br />
<br />
<br />
===Image format specific example===<br />
<br />
If you know that the TBitmap is using blue 8bit, green 8bit, red 8bit you can directly access the bytes, which is somewhat faster:<br />
<br />
<delphi>uses LCLType, // HBitmap type<br />
IntfGraphics, // TLazIntfImage type<br />
fpImage; // TFPColor type<br />
...<br />
type<br />
TRGBTripleArray = array[0..32767] of TRGBTriple;<br />
PRGBTripleArray = ^TRGBTripleArray;<br />
<br />
procedure TForm1.FadeIn2(aBitMap: TBitMap);<br />
var<br />
IntfImg1, IntfImg2: TLazIntfImage;<br />
ImgHandle,ImgMaskHandle: HBitmap;<br />
FadeStep: Integer;<br />
px, py: Integer;<br />
CurColor: TFPColor;<br />
TempBitmap: TBitmap;<br />
Row1, Row2: PRGBTripleArray;<br />
begin<br />
IntfImg1:=TLazIntfImage.Create(0,0);<br />
IntfImg1.LoadFromBitmap(aBitmap.Handle,aBitmap.MaskHandle);<br />
<br />
IntfImg2:=TLazIntfImage.Create(0,0);<br />
IntfImg2.LoadFromBitmap(aBitmap.Handle,aBitmap.MaskHandle);<br />
<br />
TempBitmap:=TBitmap.Create;<br />
<br />
//with Scanline-like<br />
for FadeStep:=1 to 32 do begin<br />
for py:=0 to IntfImg1.Height-1 do begin<br />
Row1 := IntfImg1.GetDataLineStart(py); //like Delphi TBitMap.ScanLine<br />
Row2 := IntfImg2.GetDataLineStart(py); //like Delphi TBitMap.ScanLine<br />
for px:=0 to IntfImg1.Width-1 do begin<br />
Row2^[px].rgbtRed:= (FadeStep * Row1^[px].rgbtRed) shr 5;<br />
Row2^[px].rgbtGreen := (FadeStep * Row1^[px].rgbtGreen) shr 5; // Fading<br />
Row2^[px].rgbtBlue := (FadeStep * Row1^[px].rgbtBlue) shr 5;<br />
end;<br />
end;<br />
IntfImg2.CreateBitmaps(ImgHandle,ImgMaskHandle,false);<br />
<br />
TempBitmap.Handle:=ImgHandle;<br />
TempBitmap.MaskHandle:=ImgMaskHandle;<br />
Canvas.Draw(0,0,TempBitmap);<br />
end; <br />
<br />
IntfImg1.Free;<br />
IntfImg2.Free;<br />
TempBitmap.Free;<br />
end;</delphi><br />
<br />
===Conversion between TLazIntfImage and TBitmap===<br />
<br />
Since Lazarus has no TBitmap.ScanLines property, the best way to access the pixels of an image in a fast way for both reading and writing is by using TLazIntfImage. The TBitmap can be converted to a TLazIntfImage by using TBitmap.CreateIntfImage() and after modifying the pixels it can be converted back to a TBitmap by using TBitmap.LoadFromIntfImage();<br />
Here's the sample on how to create TLazIntfImage from TBitmap, modify it and then go back to the TBitmap.<br />
<br />
<delphi>uses<br />
...GraphType, IntfGraphics, LCLType, LCLProc, LCLIntf ...<br />
<br />
procedure TForm1.Button4Click(Sender: TObject);<br />
var<br />
b: TBitmap;<br />
t: TLazIntfImage;<br />
begin<br />
b := TBitmap.Create;<br />
try<br />
b.LoadFromFile('test.bmp');<br />
t := b.CreateIntfImage;<br />
<br />
// Read and/or write to the pixels<br />
t.Colors[10,20] := colGreen;<br />
<br />
b.LoadFromIntfImage(t);<br />
finally<br />
t.Free;<br />
b.Free;<br />
end;<br />
end;</delphi><br />
<br />
===Using the non-native StretchDraw from LazCanvas===<br />
<br />
Just like TCanvas.StretchDraw there is TLazCanvas.StretchDraw but you need to specify the interpolation which you desire to use. The interpolation which provides a Windows-like StretchDraw with a very sharp result (the opposite of anti-aliased) can be added with: TLazCanvas.Interpolation := TFPSharpInterpolation.Create;<br />
<br />
There are other interpolations available in the unit fpcanvas.<br />
<br />
<delphi><br />
uses intfgraphics, lazcanvas;<br />
<br />
procedure TForm1.StretchDrawBitmapToBitmap(SourceBitmap, DestBitmap: TBitmap; DestWidth, DestHeight: integer);<br />
var<br />
DestIntfImage, SourceIntfImage: TLazIntfImage;<br />
DestCanvas: TLazCanvas;<br />
begin<br />
// Prepare the destination<br />
<br />
DestIntfImage := TLazIntfImage.Create(0, 0);<br />
DestIntfImage.LoadFromBitmap(DestBitmap.Handle, 0);<br />
<br />
DestCanvas := TLazCanvas.Create(DestIntfImage);<br />
<br />
//Prepare the source<br />
SourceIntfImage := TLazIntfImage.Create(0, 0);<br />
SourceIntfImage.LoadFromBitmap(SourceBitmap.Handle, 0);<br />
<br />
// Execute the stretch draw via TFPSharpInterpolation<br />
DestCanvas.Interpolation := TFPSharpInterpolation.Create;<br />
DestCanvas.StretchDraw(0, 0, DestWidth, DestHeight, SourceIntfImage);<br />
<br />
// Reload the image into the TBitmap<br />
DestBitmap.LoadFromIntfImage(DestIntfImage);<br />
<br />
SourceIntfImage.Free;<br />
DestCanvas.Interpolation.Free; <br />
DestCanvas.Free;<br />
DestIntfImage.Free;<br />
end;<br />
<br />
procedure TForm1.FormPaint(Sender: TObject);<br />
var<br />
Bmp, DestBitmap: TBitmap;<br />
begin<br />
// Prepare the destination<br />
DestBitmap := TBitmap.Create;<br />
DestBitmap.Width := 100;<br />
DestBitmap.Height := 100;<br />
<br />
Bmp := TBitmap.Create;<br />
Bmp.Width := 10;<br />
Bmp.Height := 10;<br />
Bmp.Canvas.Pen.Color := clYellow;<br />
Bmp.Canvas.Brush.Color := clYellow;<br />
Bmp.Canvas.Rectangle(0, 0, 10, 10);<br />
StretchDrawBitmapToBitmap(Bmp, DestBitmap, 100, 100);<br />
Canvas.Draw(0, 0, Bmp);<br />
Canvas.Draw(100, 100, DestBitmap);<br />
end; <br />
</delphi><br />
<br />
==Motion Graphics - How to Avoid flickering==<br />
<br />
Many programs draw their output to the GUI as 2D graphics. If those graphics need to change quickly you will soon face a problem: quickly changing graphics often flicker on the screen. This happens when users sometimes sees the whole images and sometimes only when it is partially drawn. It occurs because the painting process requires time.<br />
<br />
But how can I avoid the flickering and get the best drawing speed? Of course you could work with hardware acceleration using OpenGL, but this approach is quite heavy for small programs or old computers. This tutorial will focus on drawing to a TCanvas. If you need help with OpenGL, take a look at the example that comes with Lazarus. You can also use A.J. Venter's gamepack, which provides a double-buffered canvas and a sprite component.<br />
<br />
A brief and very helpful article on avoiding flicker can be found at http://delphi.about.com/library/bluc/text/uc052102g.htm. Although written for Delphi, the techniques work well with Lazarus.<br />
<br />
Now we will examine the options we have for drawing to a Canvas:<br />
* [[#Draw to a TImage|Draw to a TImage]]<br />
* [[#Draw on the OnPaint event|Draw on the OnPaint event of the form, a TPaintBox or another control]]<br />
* [[#Create a custom control which draws itself|Create a custom control which draws itself]]<br />
* [[#Using A.J. Venter's gamepack|Using A.J. Venter's gamepack]]<br />
<br />
===Draw to a TImage===<br />
<br />
A TImage consists of 2 parts: A TGraphic, usually a TBitmap, holding the persistent picture and the visual area, which is repainted on every OnPaint. Resizing the TImage does '''not''' resize the bitmap.<br />
The graphic (or bitmap) is accessible via Image1.Picture.Graphic (or Image1.Picture.Bitmap). The canvas is Image1.Picture.Bitmap.Canvas. <br />
The canvas of the visual area of a TImage is only accessible during Image1.OnPaint via Image1.Canvas.<br />
<br />
'''Important''': Never use the OnPaint of the Image1 event to draw to the graphic/bitmap of a TImage. The graphic of a TImage is buffered so all you need to do is draw to it from anywhere and the change is there forever. However, if you are constantly redrawing, the image will flicker. In this case you can try the other options. Drawing to a TImage is considered slower then the other approaches.<br />
<br />
====Resizing the bitmap of a TImage====<br />
<br />
Note: Do not use this during OnPaint.<br />
<br />
<delphi>with Image1.Picture.Bitmap do begin<br />
Width:=100;<br />
Height:=120;<br />
end;</delphi><br />
<br />
Same in one step:<br />
<br />
<delphi>with Image1.Picture.Bitmap do begin<br />
SetSize(100, 120);<br />
end;</delphi><br />
<br />
====Painting on the bitmap of a TImage====<br />
<br />
Note: Do not use this during OnPaint.<br />
<br />
<delphi>with Image1.Picture.Bitmap.Canvas do begin<br />
// fill the entire bitmap with red<br />
Brush.Color := clRed;<br />
FillRect(0, 0, Width, Height);<br />
end;</delphi><br />
<br />
Note: Inside of Image1.OnPaint the Image1.Canvas points to the volatile visible area. Outside of Image1.OnPaint the Image1.Canvas points to Image1.Picture.Bitmap.Canvas.<br />
<br />
Another example:<br />
<br />
<delphi>procedure TForm1.BitBtn1Click(Sender: TObject);<br />
var<br />
x, y: Integer;<br />
begin<br />
// Draws the backgroung<br />
MyImage.Canvas.Pen.Color := clWhite;<br />
MyImage.Canvas.Rectangle(0, 0, Image.Width, Image.Height);<br />
<br />
// Draws squares<br />
MyImage.Canvas.Pen.Color := clBlack;<br />
for x := 1 to 8 do<br />
for y := 1 to 8 do<br />
MyImage.Canvas.Rectangle(Round((x - 1) * Image.Width / 8), Round((y - 1) * Image.Height / 8),<br />
Round(x * Image.Width / 8), Round(y * Image.Height / 8));<br />
end;</delphi><br />
<br />
==== Painting on the volatile visual area of the TImage====<br />
<br />
You can only paint on this area during OnPaint. OnPaint is eventually called automatically by the LCL when the area was invalidated. You can invalidate the area manually with Image1.Invalidate. This will not immediately call OnPaint and you can call Invalidate as many times as you want.<br />
<br />
<delphi>procedure TForm.Image1Paint(Sender: TObject);<br />
begin<br />
// paint a line<br />
Canvas.Pen.Color := clRed;<br />
Canvas.Line(0, 0, Width, Height);<br />
end;</delphi><br />
<br />
===Draw on the OnPaint event===<br />
<br />
In this case all the drawing has to be done on the OnPaint event of the form, or of another control. The isn't buffered like in the TImage, and it needs to be fully redrawn in each call of the OnPaint event handler.<br />
<br />
<delphi>procedure TForm.Form1Paint(Sender: TObject);<br />
begin<br />
// paint a line<br />
Canvas.Pen.Color := clRed;<br />
Canvas.Line(0, 0, Width, Height);<br />
end;</delphi><br />
<br />
===Create a custom control which draws itself===<br />
Creating a custom control has the advantage of structuring your code and you can reuse the control. This approach is very fast, but it can still generate flickering if you don't draw to a TBitmap first and then draw to the canvas. On this case there is no need to use the OnPaint event of the control.<br />
<br />
Here is an example custom control:<br />
<br />
<delphi>uses<br />
Classes, SysUtils, Controls, Graphics, LCLType;<br />
<br />
type<br />
TMyDrawingControl = class(TCustomControl)<br />
public<br />
procedure EraseBackground(DC: HDC); override;<br />
procedure Paint; override;<br />
end;<br />
<br />
implementation<br />
<br />
procedure TMyDrawingControl.EraseBackground(DC: HDC);<br />
begin<br />
// Uncomment this to enable default background erasing<br />
//inherited EraseBackground(DC);<br />
end; <br />
<br />
procedure TMyDrawingControl.Paint;<br />
var<br />
x, y: Integer;<br />
Bitmap: TBitmap;<br />
begin<br />
Bitmap := TBitmap.Create;<br />
try<br />
// Initializes the Bitmap Size<br />
Bitmap.Height := Height;<br />
Bitmap.Width := Width;<br />
<br />
// Draws the background<br />
Bitmap.Canvas.Pen.Color := clWhite;<br />
Bitmap.Canvas.Rectangle(0, 0, Width, Height);<br />
<br />
// Draws squares<br />
Bitmap.Canvas.Pen.Color := clBlack;<br />
for x := 1 to 8 do<br />
for y := 1 to 8 do<br />
Bitmap.Canvas.Rectangle(Round((x - 1) * Width / 8), Round((y - 1) * Height / 8),<br />
Round(x * Width / 8), Round(y * Height / 8));<br />
<br />
Canvas.Draw(0, 0, Bitmap);<br />
finally<br />
Bitmap.Free;<br />
end;<br />
<br />
inherited Paint;<br />
end;</delphi><br />
<br />
and how we create it on the form:<br />
<delphi>procedure TMyForm.FormCreate(Sender: TObject);<br />
begin<br />
MyDrawingControl := TMyDrawingControl.Create(Self);<br />
MyDrawingControl.Height := 400;<br />
MyDrawingControl.Width := 500;<br />
MyDrawingControl.Top := 0;<br />
MyDrawingControl.Left := 0;<br />
MyDrawingControl.Parent := Self;<br />
MyDrawingControl.DoubleBuffered := True;<br />
end;</delphi><br />
<br />
It is destroyed automatically, because we use Self as owner.<br />
<br />
Setting Top and Left to zero is not necessary, since this is the standard position, but is done so to reinforce where the control will be put.<br />
<br />
"MyDrawingControl.Parent := Self;" is very important and you won't see your control if you don't do so.<br />
<br />
"MyDrawingControl.DoubleBuffered := True;" is required to avoid flickering on Windows. It has no effect on gtk.<br />
<br />
===Using A.J. Venter's gamepack===<br />
<br />
The gamepack approach is to draw everything to one double-buffered canvas, which only gets updated to the visible canvas when you are ready. This takes quite a bit of code, but it has the advantage of being able to do large rapidly changing scenes with multiple sprites on them. If you wish to use this approach, you may be interested in A.J. Venter's gamepack, a set of components for game development in Lazarus, which provides a double-buffered display area component as well as a sprite component, designed to integrate well with one another.<br />
<br />
[http://www.4shared.com/file/tZj_Uh8Z/gamepack-10tar.html Download: A.J. Venter's GamePack 1.0]<br />
<br />
Outdated links:<br />
*<code>svn co svn://silentcoder.co.za/lazarus/gamepack</code><br />
*[http://outkastsolutions.co.za/outkast/index.php?option=com_openwiki&Itemid=&id=gamepack A.J. Venter's gamepack homepage]<br />
<br />
== Image formats ==<br />
<br />
Here is a table with the adequate class to use for each image format.<br />
<br />
{| border=2 width="100%" align="center"<br />
|-<br />
! Format<br />
! Image class<br />
! Unit<br />
|-<br />
|Cursor (cur)||TCursor||Graphics<br />
|-<br />
|Bitmap (bmp)||TBitmap||Graphics<br />
|-<br />
|Windows icon (ico)||TIcon||Graphics<br />
|-<br />
|Mac OS X icon (icns)||TicnsIcon||Graphics<br />
|-<br />
|Pixmap (xpm)||TPixmap||Graphics<br />
|-<br />
|Portable Network Graphic (png)||TPortableNetworkGraphic||Graphics<br />
|-<br />
|JPEG (jpg, jpeg)||TJpegImage||Graphics<br />
|-<br />
|PNM (pnm)||TPortableAnyMapGraphic||Graphics<br />
|}<br />
<br />
See also the list of [[fcl-image#Image_formats|fcl-image supported formats]].<br />
<br />
=== Converting formats ===<br />
Sometimes it must be necessary to convert one graphic type to another.<br />
One of the way is convert a graphic to intermediate format, and the convert it to TBitmap.<br />
Most of format can create an image from TBitmap.<br />
<br />
Converting Bitmap to PNG and saving it to a file:<br />
<br />
<delphi>procedure SaveToPng(const bmp: TBitmap; PngFileName: String);<br />
var<br />
png : TPortableNetworkGraphic; <br />
begin <br />
png := TPortableNetworkGraphic.Create;<br />
try<br />
png.Assign(bmp);<br />
png.SaveToFile(PngFileName);<br />
finally <br />
png.Free;<br />
end;<br />
end;</delphi><br />
<br />
==Pixel Formats==<br />
<br />
===TColor===<br />
<br />
The internal pixel format for TColor in the LCL is the XXBBGGRR format, which matches the native Windows format and is opposite to most other libraries, which use AARRGGBB. The XX part is used to identify if the color is a fixed color, which case XX should be 00 or if it is an index to a system color. There is no space reserved for an alpha channel.<br />
<br />
To convert from separate RGB channels to TColor use:<br />
<br />
<delphi>RGBToColor(RedVal, GreenVal, BlueVal);</delphi><br />
<br />
To get each channel of a TColor variable use the Red, Green and Blue functions:<br />
<br />
<delphi>RedVal := Red(MyColor);<br />
GreenVal := Green(MyColor);<br />
BlueVal := Blue(MyColor);</delphi><br />
<br />
===TFPColor===<br />
<br />
TFPColor uses the AARRGGBB format common to most libraries, but it uses 16-bits for the depth of each color channel, totaling 64-bits per pixel, which is unusual. This does not necessarely mean that images will consume that much memory, however. Images created using TRawImage+TLazIntfImage can have any internal storage format and then on drawing operations TFPColor is converted to this internal format.<br />
<br />
The unit Graphics provides routines to convert between TColor and TFPColor:<br />
<br />
<delphi><br />
function FPColorToTColorRef(const FPColor: TFPColor): TColorRef;<br />
function FPColorToTColor(const FPColor: TFPColor): TColor;<br />
function TColorToFPColor(const c: TColorRef): TFPColor; overload;<br />
function TColorToFPColor(const c: TColor): TFPColor; overload; // does not work on system color<br />
</delphi><br />
<br />
==Drawing with fcl-image==<br />
<br />
You can draw images which won't be displayed in the screen without the LCL, by just using fcl-image directly. For example a program running on a webserver without X11 could benefit from not having a visual library as a dependency. FPImage (alias fcl-image) is a very generic image and drawing library written completely in pascal. In fact the LCL uses FPImage too for all the loading and saving from/to files and implements the drawing function through calls to the widgetset (winapi, gtk, carbon, ...). Fcl-image on the other hand also has drawing routines.<br />
<br />
For more information, please read the article about [[fcl-image]].<br />
<br />
[[Category:Tutorials]]<br />
[[Category:Graphics]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=BGRAControls&diff=54087BGRAControls2011-12-02T14:31:26Z<p>Lainz: /* TBGRAImageButton */</p>
<hr />
<div>{{BGRAControls}}<br />
<br />
== Install ==<br />
<br />
You can use TortoiseSVN to download the svn repository and TortoiseGIT to download the git repository.<br />
<br />
We're using BGRABitmap SVN to develop BGRAControls. Important changes in BGRABitmap can stop working BGRAControls.<br />
<br />
'''1) Download BGRABitmap'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/lazpaint/files/src/<br />
<br />
'''Latest SVN:''' svn co https://lazpaint.svn.sourceforge.net/svnroot/lazpaint lazpaint<br />
<br />
Install BGRABitmap with the file bgrabitmap.lpk<br />
<br />
'''2) Download BGRAControls'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/bgracontrols/files/<br />
<br />
'''Latest GIT:''' git://bgracontrols.git.sourceforge.net/gitroot/bgracontrols/bgracontrols <br />
<br />
Install BGRAControls with the file bgracontrols.lpk<br />
<br />
== Overview ==<br />
<br />
'''Authors:''' <br />
<br />
Dibo (package founder and maintainer, author: ''TBGRAImageList'', ''TBGRASpeedButton'', ''TBGRAButton'', ''TBGRAPanel'')<br />
<br />
Lainz (package maintainer, author: ''TBGRAImageButton'', ''TBGRAImageToggleBox'', ''TBGRASpriteAnimation'', ''TBGRALabelFX'', ''TBGRAWin7ToolBar'')<br />
<br />
Circular (package maintainer, author: ''TBGRAKnob'', ''TBGRAFlashProgressBar'', ''TBGRAVirtualScreen'', ''TBGRAShape'', ''TBGRAGraphicControl'')<br />
<br />
Emerson Cavalcanti (author: ''TBGRAImageManipulation'')<br />
<br />
codedeep (author: ''TBGRALabel'')<br />
<br />
'''License:''' Modified LGPL.<br />
<br />
As many people know, Lazarus GTK doesn't have full alpha support. I created a set of components which use TBGRABitmap for drawing icons, so it partially solves the problem with alpha in GTK. But this components set is not only a GTK patch but has more fancy components which are using the power of the BGRABitmap package.<br />
<br />
'''Screenshots:''' Some shots of the project 'testbgracontrols'.<br />
<br />
[[Image:testbgrac1.png]]<br />
<br />
''testbgracontrols > Main.''<br />
<br />
[[Image:testbgrac2.png]]<br />
<br />
''testbgracontrols > Windows 7 ToolBar.''<br />
<br />
[[Image:testbgrac4.png]]<br />
<br />
''testbgracontrols > Ribbon.''<br />
<br />
== Related Articles ==<br />
<br />
[[BGRAButton Gallery]] - Gallery of buttons with source code to use in your projects with BGRAButton.<br />
<br />
[[BGRASpriteAnimation]] - Usage of the sprite animation component.<br />
<br />
[[uE_Controls]] - Other controls developed with BGRABitmap.<br />
<br />
[[BGRABitmap]] - The library used to create this controls.<br />
<br />
[[LazPaint]] - A paint program developed with Lazarus and BGRABitmap.<br />
<br />
== Using ==<br />
<br />
Drop and use like normal component.<br />
<br />
'''Button''':<br />
* TBGRAButton<br />
* TBGRAImageButton<br />
* TBGRAImageToggleBox<br />
* TBGRASpeedButton<br />
<br />
'''Label'''<br />
* TBGRALabel<br />
* TBGRALabelFX<br />
<br />
'''Panel'''<br />
* TBGRAPanel<br />
* TBGRAVirtualScreen<br />
<br />
'''Image'''<br />
* TBGRAGraphicControl<br />
* TBGRAImageList<br />
* TBGRAImageManipulation<br />
* TBGRASpriteAnimation<br />
<br />
'''Other'''<br />
* TBGRAFlashProgressBar<br />
* TBGRAKnob<br />
* TBGRAShape<br />
* TBGRAWin7ToolBar<br />
<br />
== TBGRAImageList ==<br />
<br />
'''Use as replace of:''' TImageList<br />
<br />
'''Before:'''<br />
<br />
[[Image:before-TImageList.png]]<br />
<br />
'''After:'''<br />
<br />
[[Image:after-TBGRAImageList.png]]<br />
<br />
Component which inherits from TImageList. So each control (tested on TToolBar and TTreeView) which is using TImageList.Draw method for drawing icons, automatically can have alpha support. Just use this component instead of TImageList. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRASpeedButton ==<br />
<br />
'''Use as replace of:''' TSpeedButton<br />
<br />
[[Image:BGRASpeedButton.png]]<br />
<br />
Component which inherits from TSpeedButton and draws the glyph using TBGRABitmap. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRAButton ==<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgrabutton.png]]<br />
<br />
Customizable graphic component which is using only BGRABitmap functions for drawing. This component is insensitive for -dGTK_ONLY switch. Demo project included in package.<br />
<br />
'''Functionality:'''<br />
* Gradient, Clear or Color body. [[Double_Gradient]].<br />
* Text with shadow: BGRA antialias or like system default with ClearType.<br />
* Rounded border, inner Light.<br />
* States: normal, hover & clicked fully customizable and grayscale disabled state.<br />
* Special: Down, DropDown, Static.<br />
* Full AutoSize working with Glyph.<br />
<br />
== TBGRAPanel ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
Simple TPanel descendant which can have gradient background. Created especially for TBGRAButton (for creating a nice looking toolbar for bgrabuttons). This component is insensitive for -dGTK_ONLY switch<br />
<br />
== TBGRAKnob ==<br />
[[Image:BC-Bgraknob.png]]<br />
<br />
Graphic knob component created by circular.<br />
<br />
== TBGRAFlashProgressBar ==<br />
<br />
'''Use as replace of:''' TProgressBar<br />
<br />
[[Image:BC-Bgraflashprogressbar.png]]<br />
<br />
Flash progressbar created by circular.<br />
<br />
== TBGRAImageManipulation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Component to facilitate the importation of images in an application.<br />
<br />
In the current version you can import an image and cut out keeping the aspect ratio (or not). For example, if you want to import photos using the 3x4 ratio, adjust the 'ratio' property to 3:4. If import an image with different size, the component will ensure that the image meets the proportions of the desired dimensions.<br />
<br />
You can determine the minimum size of the image adjusting the properties 'MinWidth'and 'MinHeight'.<br />
<br />
You can rotate the image using functions builtin.<br />
<br />
See demo of component:<br />
<br />
[[Image:bgraimagemanipulation.jpg]]<br />
<br />
After retrieving the image modified by the component, just put the image into your destination using the stretch. It is obvious that the target must have the same ratio chosen on component for do not distort the final result.<br />
<br />
== TBGRAImageButton ==<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgraimagebutton.png]]<br />
<br />
Component used to create a button with 4 states from Bitmap. Has Caption support with Shadow.<br />
<br />
The bitmap must contain the 4 states (from top to bottom, with the same Height) in the following order: normal, enter, pressed, disabled.<br />
<br />
If you choose to use the BitmapOptions you need to have for each state an image which has a border, and inside some content that can be repeated. Then with FillCenter option (if you want a textured button), it gets repeated while the borders stay as they are. This is like the method used in Windows to theme the buttons.<br />
<br />
''Example Button:''<br />
<br />
[[Image:samplebgraimagebutton.png]]<br />
<br />
''Example Button (with Alpha):''<br />
<br />
[[Image:samplebgraimagebuttonalpha.png]]<br />
<br />
== TBGRAVirtualScreen ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
The principle is to draw on a memory bitmap.<br />
<br />
The component has a specific event, OnRedraw, which is called when the whole bitmap needs to be redrawn. It happens at the beginning, when resizing and when the Redraw method is called.<br />
<br />
Otherwise, it is possible to modify the Bitmap property and call Invalidate or Repaint, to avoid erasing the whole bitmap content.<br />
<br />
== TBGRAShape ==<br />
<br />
'''Use as replace of:''' TShape<br />
<br />
[[Image:samplebgrashape.png]]<br />
<br />
The component has full alpha support and you can put the number of polygons you want with rounded borders & gradients (linear, radial, diamond, reflected).<br />
<br />
== TBGRAImageToggleBox ==<br />
<br />
REMOVED IN VER 1.1.0.7.<br />
<br />
'''Use as replace of:''' TToggleBox<br />
<br />
Component used to create a toggle box from Bitmap.<br />
<br />
The bitmap must contain 8 images (from top to bottom, with the same Height) in the following order: unchecked normal, unchecked enter, unchecked pressed, unchecked disabled for Unchecked state and checked normal, checked enter, checked pressed, checked disabled for Normal state.<br />
<br />
''Example toggle box:''<br />
<br />
[[Image:sampletogglebox.png]]<br />
<br />
== TBGRAGraphicControl ==<br />
<br />
'''Use as replace of:''' TPaintBox<br />
<br />
TBGRAGraphicControl, which allows to draw your component by yourself with alpha blending.<br />
<br />
== TBGRASpriteAnimation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Read more in the article [[BGRASpriteAnimation]].<br />
<br />
[[Image:bgraspriteanimation.png]]<br />
<br />
With this you can do animations from bitmap. You need an image with all the frames layout in in a horizontal position.<br />
<br />
It has the ability to specify how many times the animation should be played (0 for infinite, 1, 2, etc) and static to stop the animation, is capable to specify the speed and direction and support transparency.<br />
<br />
Features:<br />
* Animation: invert, position, lap, speed, static, repeat.<br />
* Sprite: fill opacity (global transparency), flip mode (horizontal, vertical, both), key color (transparent color), resample (normal or fine resample modes). AutoSize.<br />
* AnimatedGifToSprite: convert an animated gif to a BGRABitmap sprite.<br />
<br />
== TBGRALabel ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
Label component based on TBGRAButton.<br />
<br />
Features:<br />
* Caption with shadow or not<br />
* Full alpha and antialias support or not<br />
* WordWarp or not<br />
* Caption with Property Editor Multiline<br />
<br />
== TBGRALabelFX ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
[[Image:bgralabelfx.png]]<br />
<br />
Features:<br />
* Outline<br />
* Shadow<br />
<br />
ToDo:<br />
* Use BGRATextFX multicolor, textures.<br />
* etc.<br />
<br />
== TBGRAWin7ToolBar ==<br />
<br />
[[Image:bgrawin7toolbar.png]]<br />
<br />
Is a TBGRAVirtualScreen descendant with some default child sizing, and nice Win7 ToolBar background.<br />
<br />
== BGRASamples unit ==<br />
<br />
This unit has sample drawings, styles for buttons and colors used in different UI.<br />
<br />
[[Image:ioselements.png]]<br />
<br />
* '''Accent Color:''' the colors used in the Windows Phone. The accent color can be used in TBGRAButton and TBGRAImageButton (see the different procedures).<br />
* '''Facebook button color:''' gray, green and blue, with a procedure to create an image in the normal or pressed state, also to use this style in a TBGRAImageButton.<br />
* '''TBGRASampleStyle:''' Styles for TBGRAButton ('Default', 'Flash Player', 'Windows 7 ToolBar', 'Windows 7 ToolBar Smooth', 'Windows 7', 'Office 2010', 'Mac OSX Lion', 'Windows 7 Cristal').<br />
* '''iOS Elements:''' Draw a gray bar, the blue toolbar and a tiled background, the same elements used in the iOS screen.<br />
* '''Glass:''' used in testbgracontrols, it show an image in a virtualscreen and apply blur in the buttons area.<br />
* '''Drawings:''' flash player body and toolbar, windows 7 toolbar.<br />
<br />
* Some other usefull procedures to work with TBGRAButton and TBGRAImageButton.<br />
<br />
[[Category:Components]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=BGRAControls&diff=53856BGRAControls2011-11-16T22:22:22Z<p>Lainz: /* TBGRAButton */</p>
<hr />
<div>{{BGRAControls}}<br />
<br />
== Install ==<br />
<br />
You can use TortoiseSVN to download the svn repository and TortoiseGIT to download the git repository.<br />
<br />
We're using BGRABitmap SVN to develop BGRAControls. Important changes in BGRABitmap can stop working BGRAControls.<br />
<br />
'''1) Download BGRABitmap'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/lazpaint/files/src/<br />
<br />
'''Latest SVN:''' svn co https://lazpaint.svn.sourceforge.net/svnroot/lazpaint lazpaint<br />
<br />
Install BGRABitmap with the file bgrabitmap.lpk<br />
<br />
'''2) Download BGRAControls'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/bgracontrols/files/<br />
<br />
'''Latest GIT:''' git://bgracontrols.git.sourceforge.net/gitroot/bgracontrols/bgracontrols <br />
<br />
Install BGRAControls with the file bgracontrols.lpk<br />
<br />
== Overview ==<br />
<br />
'''Authors:''' <br />
<br />
Dibo (package founder and maintainer, author: ''TBGRAImageList'', ''TBGRASpeedButton'', ''TBGRAButton'', ''TBGRAPanel'')<br />
<br />
Lainz (package maintainer, author: ''TBGRAImageButton'', ''TBGRAImageToggleBox'', ''TBGRASpriteAnimation'', ''TBGRALabelFX'', ''TBGRAWin7ToolBar'')<br />
<br />
Circular (package maintainer, author: ''TBGRAKnob'', ''TBGRAFlashProgressBar'', ''TBGRAVirtualScreen'', ''TBGRAShape'', ''TBGRAGraphicControl'')<br />
<br />
Emerson Cavalcanti (author: ''TBGRAImageManipulation'')<br />
<br />
codedeep (author: ''TBGRALabel'')<br />
<br />
'''License:''' Modified LGPL.<br />
<br />
As many people know, Lazarus GTK doesn't have full alpha support. I created a set of components which use TBGRABitmap for drawing icons, so it partially solves the problem with alpha in GTK. But this components set is not only a GTK patch but has more fancy components which are using the power of the BGRABitmap package.<br />
<br />
'''Screenshots:''' Some shots of the project 'testbgracontrols'.<br />
<br />
[[Image:testbgrac1.png]]<br />
<br />
''testbgracontrols > Main.''<br />
<br />
[[Image:testbgrac2.png]]<br />
<br />
''testbgracontrols > Windows 7 ToolBar.''<br />
<br />
[[Image:testbgrac4.png]]<br />
<br />
''testbgracontrols > Ribbon.''<br />
<br />
== Related Articles ==<br />
<br />
[[BGRAButton Gallery]] - Gallery of buttons with source code to use in your projects with BGRAButton.<br />
<br />
[[BGRASpriteAnimation]] - Usage of the sprite animation component.<br />
<br />
[[uE_Controls]] - Other controls developed with BGRABitmap.<br />
<br />
[[BGRABitmap]] - The library used to create this controls.<br />
<br />
[[LazPaint]] - A paint program developed with Lazarus and BGRABitmap.<br />
<br />
== Using ==<br />
<br />
Drop and use like normal component.<br />
<br />
'''Button''':<br />
* TBGRAButton<br />
* TBGRAImageButton<br />
* TBGRAImageToggleBox<br />
* TBGRASpeedButton<br />
<br />
'''Label'''<br />
* TBGRALabel<br />
* TBGRALabelFX<br />
<br />
'''Panel'''<br />
* TBGRAPanel<br />
* TBGRAVirtualScreen<br />
<br />
'''Image'''<br />
* TBGRAGraphicControl<br />
* TBGRAImageList<br />
* TBGRAImageManipulation<br />
* TBGRASpriteAnimation<br />
<br />
'''Other'''<br />
* TBGRAFlashProgressBar<br />
* TBGRAKnob<br />
* TBGRAShape<br />
* TBGRAWin7ToolBar<br />
<br />
== TBGRAImageList ==<br />
<br />
'''Use as replace of:''' TImageList<br />
<br />
'''Before:'''<br />
<br />
[[Image:before-TImageList.png]]<br />
<br />
'''After:'''<br />
<br />
[[Image:after-TBGRAImageList.png]]<br />
<br />
Component which inherits from TImageList. So each control (tested on TToolBar and TTreeView) which is using TImageList.Draw method for drawing icons, automatically can have alpha support. Just use this component instead of TImageList. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRASpeedButton ==<br />
<br />
'''Use as replace of:''' TSpeedButton<br />
<br />
[[Image:BGRASpeedButton.png]]<br />
<br />
Component which inherits from TSpeedButton and draws the glyph using TBGRABitmap. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRAButton ==<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgrabutton.png]]<br />
<br />
Customizable graphic component which is using only BGRABitmap functions for drawing. This component is insensitive for -dGTK_ONLY switch. Demo project included in package.<br />
<br />
'''Functionality:'''<br />
* Gradient, Clear or Color body. [[Double_Gradient]].<br />
* Text with shadow: BGRA antialias or like system default with ClearType.<br />
* Rounded border, inner Light.<br />
* States: normal, hover & clicked fully customizable and grayscale disabled state.<br />
* Special: Down, DropDown, Static.<br />
* Full AutoSize working with Glyph.<br />
<br />
== TBGRAPanel ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
Simple TPanel descendant which can have gradient background. Created especially for TBGRAButton (for creating a nice looking toolbar for bgrabuttons). This component is insensitive for -dGTK_ONLY switch<br />
<br />
== TBGRAKnob ==<br />
[[Image:BC-Bgraknob.png]]<br />
<br />
Graphic knob component created by circular.<br />
<br />
== TBGRAFlashProgressBar ==<br />
<br />
'''Use as replace of:''' TProgressBar<br />
<br />
[[Image:BC-Bgraflashprogressbar.png]]<br />
<br />
Flash progressbar created by circular.<br />
<br />
== TBGRAImageManipulation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Component to facilitate the importation of images in an application.<br />
<br />
In the current version you can import an image and cut out keeping the aspect ratio (or not). For example, if you want to import photos using the 3x4 ratio, adjust the 'ratio' property to 3:4. If import an image with different size, the component will ensure that the image meets the proportions of the desired dimensions.<br />
<br />
You can determine the minimum size of the image adjusting the properties 'MinWidth'and 'MinHeight'.<br />
<br />
You can rotate the image using functions builtin.<br />
<br />
See demo of component:<br />
<br />
[[Image:bgraimagemanipulation.jpg]]<br />
<br />
After retrieving the image modified by the component, just put the image into your destination using the stretch. It is obvious that the target must have the same ratio chosen on component for do not distort the final result.<br />
<br />
== TBGRAImageButton ==<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgraimagebutton.png]]<br />
<br />
Component used to create a button with 4 states from Bitmap. Has Caption support with Shadow.<br />
<br />
The bitmap must contain the 4 states (from top to bottom, with the same Height) in the following order: normal, enter, pressed, disabled.<br />
<br />
''Example Button:''<br />
<br />
[[Image:samplebgraimagebutton.png]]<br />
<br />
''Example Button (with Alpha):''<br />
<br />
[[Image:samplebgraimagebuttonalpha.png]]<br />
<br />
== TBGRAVirtualScreen ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
The principle is to draw on a memory bitmap.<br />
<br />
The component has a specific event, OnRedraw, which is called when the whole bitmap needs to be redrawn. It happens at the beginning, when resizing and when the Redraw method is called.<br />
<br />
Otherwise, it is possible to modify the Bitmap property and call Invalidate or Repaint, to avoid erasing the whole bitmap content.<br />
<br />
== TBGRAShape ==<br />
<br />
'''Use as replace of:''' TShape<br />
<br />
[[Image:samplebgrashape.png]]<br />
<br />
The component has full alpha support and you can put the number of polygons you want with rounded borders & gradients (linear, radial, diamond, reflected).<br />
<br />
== TBGRAImageToggleBox ==<br />
<br />
REMOVED IN VER 1.1.0.7.<br />
<br />
'''Use as replace of:''' TToggleBox<br />
<br />
Component used to create a toggle box from Bitmap.<br />
<br />
The bitmap must contain 8 images (from top to bottom, with the same Height) in the following order: unchecked normal, unchecked enter, unchecked pressed, unchecked disabled for Unchecked state and checked normal, checked enter, checked pressed, checked disabled for Normal state.<br />
<br />
''Example toggle box:''<br />
<br />
[[Image:sampletogglebox.png]]<br />
<br />
== TBGRAGraphicControl ==<br />
<br />
'''Use as replace of:''' TPaintBox<br />
<br />
TBGRAGraphicControl, which allows to draw your component by yourself with alpha blending.<br />
<br />
== TBGRASpriteAnimation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Read more in the article [[BGRASpriteAnimation]].<br />
<br />
[[Image:bgraspriteanimation.png]]<br />
<br />
With this you can do animations from bitmap. You need an image with all the frames layout in in a horizontal position.<br />
<br />
It has the ability to specify how many times the animation should be played (0 for infinite, 1, 2, etc) and static to stop the animation, is capable to specify the speed and direction and support transparency.<br />
<br />
Features:<br />
* Animation: invert, position, lap, speed, static, repeat.<br />
* Sprite: fill opacity (global transparency), flip mode (horizontal, vertical, both), key color (transparent color), resample (normal or fine resample modes). AutoSize.<br />
* AnimatedGifToSprite: convert an animated gif to a BGRABitmap sprite.<br />
<br />
== TBGRALabel ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
Label component based on TBGRAButton.<br />
<br />
Features:<br />
* Caption with shadow or not<br />
* Full alpha and antialias support or not<br />
* WordWarp or not<br />
* Caption with Property Editor Multiline<br />
<br />
== TBGRALabelFX ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
[[Image:bgralabelfx.png]]<br />
<br />
Features:<br />
* Outline<br />
* Shadow<br />
<br />
ToDo:<br />
* Use BGRATextFX multicolor, textures.<br />
* etc.<br />
<br />
== TBGRAWin7ToolBar ==<br />
<br />
[[Image:bgrawin7toolbar.png]]<br />
<br />
Is a TBGRAVirtualScreen descendant with some default child sizing, and nice Win7 ToolBar background.<br />
<br />
== BGRASamples unit ==<br />
<br />
This unit has sample drawings, styles for buttons and colors used in different UI.<br />
<br />
[[Image:ioselements.png]]<br />
<br />
* '''Accent Color:''' the colors used in the Windows Phone. The accent color can be used in TBGRAButton and TBGRAImageButton (see the different procedures).<br />
* '''Facebook button color:''' gray, green and blue, with a procedure to create an image in the normal or pressed state, also to use this style in a TBGRAImageButton.<br />
* '''TBGRASampleStyle:''' Styles for TBGRAButton ('Default', 'Flash Player', 'Windows 7 ToolBar', 'Windows 7 ToolBar Smooth', 'Windows 7', 'Office 2010', 'Mac OSX Lion', 'Windows 7 Cristal').<br />
* '''iOS Elements:''' Draw a gray bar, the blue toolbar and a tiled background, the same elements used in the iOS screen.<br />
* '''Glass:''' used in testbgracontrols, it show an image in a virtualscreen and apply blur in the buttons area.<br />
* '''Drawings:''' flash player body and toolbar, windows 7 toolbar.<br />
<br />
* Some other usefull procedures to work with TBGRAButton and TBGRAImageButton.<br />
<br />
[[Category:Components]]</div>Lainzhttps://wiki.freepascal.org/index.php?title=BGRAControls&diff=53855BGRAControls2011-11-16T21:52:54Z<p>Lainz: /* BGRASamples unit */ added screenshot</p>
<hr />
<div>{{BGRAControls}}<br />
<br />
== Install ==<br />
<br />
You can use TortoiseSVN to download the svn repository and TortoiseGIT to download the git repository.<br />
<br />
We're using BGRABitmap SVN to develop BGRAControls. Important changes in BGRABitmap can stop working BGRAControls.<br />
<br />
'''1) Download BGRABitmap'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/lazpaint/files/src/<br />
<br />
'''Latest SVN:''' svn co https://lazpaint.svn.sourceforge.net/svnroot/lazpaint lazpaint<br />
<br />
Install BGRABitmap with the file bgrabitmap.lpk<br />
<br />
'''2) Download BGRAControls'''<br />
<br />
'''Release:''' https://sourceforge.net/projects/bgracontrols/files/<br />
<br />
'''Latest GIT:''' git://bgracontrols.git.sourceforge.net/gitroot/bgracontrols/bgracontrols <br />
<br />
Install BGRAControls with the file bgracontrols.lpk<br />
<br />
== Overview ==<br />
<br />
'''Authors:''' <br />
<br />
Dibo (package founder and maintainer, author: ''TBGRAImageList'', ''TBGRASpeedButton'', ''TBGRAButton'', ''TBGRAPanel'')<br />
<br />
Lainz (package maintainer, author: ''TBGRAImageButton'', ''TBGRAImageToggleBox'', ''TBGRASpriteAnimation'', ''TBGRALabelFX'', ''TBGRAWin7ToolBar'')<br />
<br />
Circular (package maintainer, author: ''TBGRAKnob'', ''TBGRAFlashProgressBar'', ''TBGRAVirtualScreen'', ''TBGRAShape'', ''TBGRAGraphicControl'')<br />
<br />
Emerson Cavalcanti (author: ''TBGRAImageManipulation'')<br />
<br />
codedeep (author: ''TBGRALabel'')<br />
<br />
'''License:''' Modified LGPL.<br />
<br />
As many people know, Lazarus GTK doesn't have full alpha support. I created a set of components which use TBGRABitmap for drawing icons, so it partially solves the problem with alpha in GTK. But this components set is not only a GTK patch but has more fancy components which are using the power of the BGRABitmap package.<br />
<br />
'''Screenshots:''' Some shots of the project 'testbgracontrols'.<br />
<br />
[[Image:testbgrac1.png]]<br />
<br />
''testbgracontrols > Main.''<br />
<br />
[[Image:testbgrac2.png]]<br />
<br />
''testbgracontrols > Windows 7 ToolBar.''<br />
<br />
[[Image:testbgrac4.png]]<br />
<br />
''testbgracontrols > Ribbon.''<br />
<br />
== Related Articles ==<br />
<br />
[[BGRAButton Gallery]] - Gallery of buttons with source code to use in your projects with BGRAButton.<br />
<br />
[[BGRASpriteAnimation]] - Usage of the sprite animation component.<br />
<br />
[[uE_Controls]] - Other controls developed with BGRABitmap.<br />
<br />
[[BGRABitmap]] - The library used to create this controls.<br />
<br />
[[LazPaint]] - A paint program developed with Lazarus and BGRABitmap.<br />
<br />
== Using ==<br />
<br />
Drop and use like normal component.<br />
<br />
'''Button''':<br />
* TBGRAButton<br />
* TBGRAImageButton<br />
* TBGRAImageToggleBox<br />
* TBGRASpeedButton<br />
<br />
'''Label'''<br />
* TBGRALabel<br />
* TBGRALabelFX<br />
<br />
'''Panel'''<br />
* TBGRAPanel<br />
* TBGRAVirtualScreen<br />
<br />
'''Image'''<br />
* TBGRAGraphicControl<br />
* TBGRAImageList<br />
* TBGRAImageManipulation<br />
* TBGRASpriteAnimation<br />
<br />
'''Other'''<br />
* TBGRAFlashProgressBar<br />
* TBGRAKnob<br />
* TBGRAShape<br />
* TBGRAWin7ToolBar<br />
<br />
== TBGRAImageList ==<br />
<br />
'''Use as replace of:''' TImageList<br />
<br />
'''Before:'''<br />
<br />
[[Image:before-TImageList.png]]<br />
<br />
'''After:'''<br />
<br />
[[Image:after-TBGRAImageList.png]]<br />
<br />
Component which inherits from TImageList. So each control (tested on TToolBar and TTreeView) which is using TImageList.Draw method for drawing icons, automatically can have alpha support. Just use this component instead of TImageList. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRASpeedButton ==<br />
<br />
'''Use as replace of:''' TSpeedButton<br />
<br />
[[Image:BGRASpeedButton.png]]<br />
<br />
Component which inherits from TSpeedButton and draws the glyph using TBGRABitmap. This component has been written for enabling GTK alpha, so on Windows (and other interfaces) it works just like normal TImageList (it doesn't use BGRABitmap for drawing)<br />
<br />
== TBGRAButton ==<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgrabutton.png]]<br />
<br />
Customizable graphic component which is using only BGRABitmap functions for drawing. This component is insensitive for -dGTK_ONLY switch. Demo project included in package.<br />
<br />
Functionality:<br />
*Gradients<br />
*Double gradients<br />
*Rounding<br />
*Border style, width and color<br />
*Drop down list<br />
*Glyph<br />
*States (normal, hover, clicked)<br />
*Caption with shadow<br />
*Full alpha and antialias support<br />
*Can work as image if no caption is set (has no stretch function yet)<br />
<br />
== TBGRAPanel ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
Simple TPanel descendant which can have gradient background. Created especially for TBGRAButton (for creating a nice looking toolbar for bgrabuttons). This component is insensitive for -dGTK_ONLY switch<br />
<br />
== TBGRAKnob ==<br />
[[Image:BC-Bgraknob.png]]<br />
<br />
Graphic knob component created by circular.<br />
<br />
== TBGRAFlashProgressBar ==<br />
<br />
'''Use as replace of:''' TProgressBar<br />
<br />
[[Image:BC-Bgraflashprogressbar.png]]<br />
<br />
Flash progressbar created by circular.<br />
<br />
== TBGRAImageManipulation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Component to facilitate the importation of images in an application.<br />
<br />
In the current version you can import an image and cut out keeping the aspect ratio (or not). For example, if you want to import photos using the 3x4 ratio, adjust the 'ratio' property to 3:4. If import an image with different size, the component will ensure that the image meets the proportions of the desired dimensions.<br />
<br />
You can determine the minimum size of the image adjusting the properties 'MinWidth'and 'MinHeight'.<br />
<br />
You can rotate the image using functions builtin.<br />
<br />
See demo of component:<br />
<br />
[[Image:bgraimagemanipulation.jpg]]<br />
<br />
After retrieving the image modified by the component, just put the image into your destination using the stretch. It is obvious that the target must have the same ratio chosen on component for do not distort the final result.<br />
<br />
== TBGRAImageButton ==<br />
<br />
'''Use as replace of:''' TButton<br />
<br />
[[Image:bgraimagebutton.png]]<br />
<br />
Component used to create a button with 4 states from Bitmap. Has Caption support with Shadow.<br />
<br />
The bitmap must contain the 4 states (from top to bottom, with the same Height) in the following order: normal, enter, pressed, disabled.<br />
<br />
''Example Button:''<br />
<br />
[[Image:samplebgraimagebutton.png]]<br />
<br />
''Example Button (with Alpha):''<br />
<br />
[[Image:samplebgraimagebuttonalpha.png]]<br />
<br />
== TBGRAVirtualScreen ==<br />
<br />
'''Use as replace of:''' TPanel<br />
<br />
The principle is to draw on a memory bitmap.<br />
<br />
The component has a specific event, OnRedraw, which is called when the whole bitmap needs to be redrawn. It happens at the beginning, when resizing and when the Redraw method is called.<br />
<br />
Otherwise, it is possible to modify the Bitmap property and call Invalidate or Repaint, to avoid erasing the whole bitmap content.<br />
<br />
== TBGRAShape ==<br />
<br />
'''Use as replace of:''' TShape<br />
<br />
[[Image:samplebgrashape.png]]<br />
<br />
The component has full alpha support and you can put the number of polygons you want with rounded borders & gradients (linear, radial, diamond, reflected).<br />
<br />
== TBGRAImageToggleBox ==<br />
<br />
REMOVED IN VER 1.1.0.7.<br />
<br />
'''Use as replace of:''' TToggleBox<br />
<br />
Component used to create a toggle box from Bitmap.<br />
<br />
The bitmap must contain 8 images (from top to bottom, with the same Height) in the following order: unchecked normal, unchecked enter, unchecked pressed, unchecked disabled for Unchecked state and checked normal, checked enter, checked pressed, checked disabled for Normal state.<br />
<br />
''Example toggle box:''<br />
<br />
[[Image:sampletogglebox.png]]<br />
<br />
== TBGRAGraphicControl ==<br />
<br />
'''Use as replace of:''' TPaintBox<br />
<br />
TBGRAGraphicControl, which allows to draw your component by yourself with alpha blending.<br />
<br />
== TBGRASpriteAnimation ==<br />
<br />
'''Use as replace of:''' TImage<br />
<br />
Read more in the article [[BGRASpriteAnimation]].<br />
<br />
[[Image:bgraspriteanimation.png]]<br />
<br />
With this you can do animations from bitmap. You need an image with all the frames layout in in a horizontal position.<br />
<br />
It has the ability to specify how many times the animation should be played (0 for infinite, 1, 2, etc) and static to stop the animation, is capable to specify the speed and direction and support transparency.<br />
<br />
Features:<br />
* Animation: invert, position, lap, speed, static, repeat.<br />
* Sprite: fill opacity (global transparency), flip mode (horizontal, vertical, both), key color (transparent color), resample (normal or fine resample modes). AutoSize.<br />
* AnimatedGifToSprite: convert an animated gif to a BGRABitmap sprite.<br />
<br />
== TBGRALabel ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
Label component based on TBGRAButton.<br />
<br />
Features:<br />
* Caption with shadow or not<br />
* Full alpha and antialias support or not<br />
* WordWarp or not<br />
* Caption with Property Editor Multiline<br />
<br />
== TBGRALabelFX ==<br />
<br />
'''Use as replace of:''' TLabel<br />
<br />
[[Image:bgralabelfx.png]]<br />
<br />
Features:<br />
* Outline<br />
* Shadow<br />
<br />
ToDo:<br />
* Use BGRATextFX multicolor, textures.<br />
* etc.<br />
<br />
== TBGRAWin7ToolBar ==<br />
<br />
[[Image:bgrawin7toolbar.png]]<br />
<br />
Is a TBGRAVirtualScreen descendant with some default child sizing, and nice Win7 ToolBar background.<br />
<br />
== BGRASamples unit ==<br />
<br />
This unit has sample drawings, styles for buttons and colors used in different UI.<br />
<br />
[[Image:ioselements.png]]<br />
<br />
* '''Accent Color:''' the colors used in the Windows Phone. The accent color can be used in TBGRAButton and TBGRAImageButton (see the different procedures).<br />
* '''Facebook button color:''' gray, green and blue, with a procedure to create an image in the normal or pressed state, also to use this style in a TBGRAImageButton.<br />
* '''TBGRASampleStyle:''' Styles for TBGRAButton ('Default', 'Flash Player', 'Windows 7 ToolBar', 'Windows 7 ToolBar Smooth', 'Windows 7', 'Office 2010', 'Mac OSX Lion', 'Windows 7 Cristal').<br />
* '''iOS Elements:''' Draw a gray bar, the blue toolbar and a tiled background, the same elements used in the iOS screen.<br />
* '''Glass:''' used in testbgracontrols, it show an image in a virtualscreen and apply blur in the buttons area.<br />
* '''Drawings:''' flash player body and toolbar, windows 7 toolbar.<br />
<br />
* Some other usefull procedures to work with TBGRAButton and TBGRAImageButton.<br />
<br />
[[Category:Components]]</div>Lainz