I noticed some unusual behaviors using clDefault color.
clDefault = TColor($20000000); //536870912
As an example (http://wiki.freepascal.org/Colors):
Using it for Brush will use the normal background brush of the target
DC (device context).
On a Form's canvas a FillRect will paint a
rectangular area filled with the normal background of a standard
window. This is whatever the widgetset and theme defines. This might
be the color gray or a gradient or a picture.
Using clDefault on the
Canvas of a TListBox will paint with the normal background, which is
normally white on Windows. So in a TListBox clDefault is the same as
clWindow.
Using it as Pen color will use the default line color for
the device context.
Using it as Font color will use the normal text
color of the device context.
Could someone tell me how clDefault works?
I mean, is it interpreted by the OS or by the VCL code and how?
You provide a link to FPC documentation, but then talk about the VCL and tag the question Delphi. I'm going to assume that you are asking about Delphi VCL and just ignore your linked documentation which does not apply.
In the VCL, for pens, fonts, and brushes, the default color is black. That's because $20000000 has 0 for R, G and B channels. The alpha channel is $20, but is ignored, certainly for methods like LineTo, FillRect, etc. This is quite different from the FPC documentation you linked to.
If you use clDefault for the Color of a TListBox, then it will again be black. Again, different from the FPC documentation you linked to.
Certainly the value $20000000 has no special meaning to GDI. For pens, fonts, brushes etc. the value is passed down to GDI which interprets it as black.
If you study the VCL source code you will find a variety of places where clDefault is used. In the main clDefault is used as a sentinel value. The VCL code checks whether or not a specified color property is equal to clDefault, and then takes special action if it is.
So far as I can tell, that's all there is to it. Some parts of the VCL treat clDefault as a sentinel, otherwise it is black.
Related
When creating a custom FireMonkey style, you often run into style objects, such as TButtonStyleObject, that include one or more properties (such as TButtonStyleObject.NormalLink) that are collections of TBitmapLinks. Each individual TBitmapLink defines three properties, CapInsets, Scale, and SourceRect. SourceRect contains the coordinates of a segment of a bitmap that will be used to draw some aspect of the control (see Using TBitmapLinks with the FireMonkey Style Designer for more detail).
My question is, what does CapInsets do?
I think it is something related how to paint a resizable component using a single bitmap. The CapInsets should represent the stretchable portion of the bitmap leaving apart, in example, the borders so they do not get too thin or too large when you resize the component.
Think about a button and a 25x50 px bitmap to be the backround. Think it is a single color rectangle with a little border. What if you resize the button to be 25x500 px? The left and right border will become too large (and no more proportional to the top and bottom border).
I found no documentation except this article in russian (translation to italian is very bad, the english one isn't so clear to me as well), look for the "Background" section http://habrahabr.ru/post/137851/
HTH
How can change alphablend of a form without affect on control in form?
Delphi XE7
One solution to this problem is to use Multi-Device Application (if using VCL is not possible).
If you need to leave a transparent TForm just changing a property Transparency = True.
If you need to leave a semi-transparent component, all components have the Opacity property that can be assigned a more transparent value between 0 and 1, where 0 is closer to that component.
For example you could put the controls within a TLayout and change the Opacity of it as you see fit, and have no effect on the other components, or vice versa.
Actually the answer to this might be pretty simple...(for windows only)
The JEDI VCL library has a component (TJvTransparentForm) that allows you to take an Alpha blended PNG image (ie the gray background shown in your picture above) and use it to make a form control. The picture is actually stored in a TImage and you would need to place your "Icons" on the image itself. Then just respond to the mouse clicks on the TImage.
You have what your asking for (maybe?).
If you were tricky enough you could probably even track the mouse movement and change the Image to glow the correct "button" that the mouse was over.
Is there any way to make a control transparent like button, edit, panel or etc...? I mean something like opacity or alpha blend that we have in form property.
Some components have the transparent property. In others you can choose 'none' as the color property. It differs from component to component, but not all components can be made transparent by changing a property.
You should try googling Delphi transparent components, there are downloadable components and tricks you can do to make existing components transparent.
Take a look at the Win32 windows styles, especially WS_TRANSPARENT (or WS_EX_TRANSPARENT).
Applying transparency on a child control can be done very easily using old-fashioned regions and the SetWindowRgn() function.
Applying alpha blending on a child control, on the other hand, is very difficult to do prior to Windows 8. It involves painting the parent window to a bitmap first, then alpha blending an image of the child control on top of the bitmap, then rendering the bitmap onscreen.
In Windows 8, the WS_EX_LAYERED window style (which is what Tform's TransparentColor and AlphaBlendValue properties use internally) has finally been implemented for child controls.
I'm trying to make a "blank" background to place an image on top of. It's not too difficult to create crosshatches by placing a TImage on a form and doing the following:
image1.Canvas.brush.Style := bsDiagCross;
image1.canvas.brush.color := clWhatever;
image1.canvas.FillRect(image1.clientrect);
This works, and I get a crosshatch pattern in clWhatever over a black background. But that's the problem. It's always black, and I can't find any way to specify a background color in case I want something other than black.
Does anyone know how to do this?
The color of a hatched brush is the foreground color - the color of the hatch itself.
The background color is set separately when using hatched brushes and as far as I know isn't exposed as a property of the TCanvas and thus requires the use of the Windows GDI API SetBkColor() function.
e.g. to draw a red hatch on a white background, add a call to set the background color before drawing using the canvas brush:
image1.Canvas.brush.Style := bsDiagCross;
image1.canvas.brush.color := clRed;
SetBkColor(image1.Canvas.Handle, ColorToRGB(clWhite));
image1.canvas.FillRect(image1.clientrect);
[Update:] NOTE: It appears that in Delphi 2010 (and possibly some earlier version/s) you should call SetBKColor() AFTER setting brush properties. Internally when the canvas creates it's brush it calls SetBKColor() which tramples on any explicit calls to SetBKColor() made prior to referencing the Canvas.Brush. The timing of when the internal canvas brush is created, or the internal use of SetBkColor(), appears to have changed between Delphi 2006 (used when testing the original posting) and Delphi 2010. Whatever the reason it is clearly more reliable to call SetBKColor immediately prior to using it.
I have a form with an image as the background.
Now I need to put several transparent dark color areas in several areas off the form.
I need not to hide the background. How can I do this?
Standard Delphi control do AFAIK not support that kind of transparency. You therefore have two possiblities:
use third-party components
create your own component (you can derive from an existing one) and override the paint method. In the paint method just draw the correct part of the background image and darken every pixel to get the effect you want.
You can try Delphi 2009/2010 which supports using PNG images. The PNG image format allows for alpha layer transparency, which it sounds it what your looking for. This assumes that your wanting a fixed shape on your form.
EDIT-- For Delphi 2007, you can attempt to use the PNG Components which if I remember correctly do properly handle alpha transparency.
Is the background image and the darker areas the only thing that you want on your form, or do you have other components that should be blended too?
If it's only the background image and the dark areas, I would recommend that you check out Graphics32. It's an image control supporting layers. It should be fairly easy to archive what you want (or what I assume that you want...) from that.