Delphi cutting glass - delphi

I'm using Delphi XE2, and I like glass effects, and I want to "cut" glass as in Windows 7 tablet tools.
If you also know how cut a button I'll be happy if you tell me how.
Thanks

Drawing in the top area is simply a matter of using a glass frame and painting in the non-client area, or alternatively, using the DwmExtendFrameIntoClientArea API.
The best code sample I have seen for this is the VCL "Ribbon" control, which provides a "QAT" (quick Access toolbar) area, painted in the "non client area".
Note that the author has to think not only about how to render when Vista/Win7 systems which have Glass ON, but also has to decide how to render on WinXp, Win7 and Vista when the Themes engine is off. There is quite a bit of logic in the Vcl.Ribbon.pas (or just Ribbon.pas if you're in XE or earlier) unit dedicated to that.
Look at procedure TCustomRibbonQuickAccessPopupToolbar.NCPaint(DC: HDC); in the Vcl Ribbon sources.
Drawing a non-rectangular "extended area" that protrudes from the bottom is probably a matter of applying a custom window clipping region.

Did you mean you want shaped forms? If so
Irregularly shaped forms
could help. I imagine this will work on Windows 7 (note Remy's comment in the answer).
hth

Related

Delphi Firemonkey Scale for High DPI Windows

I thought scaling an application in FireMonkey should be easy as it is supposed to work an a Retina-Mac too. It seems there is some background magic which chooses another style than, but this doesn't seem to be the case in Windows.
In VCL there was TForm.Scaled which does the job (more or less).
For FireMonkey I found this Article by Embarcadero but it seems Embarcadero is not quite sure if this approach is useful as in XE5 the sampleproject "ControlsDemo" doesn't contain the scale-trackbar anymore. It also requires to have a root-TLayout present in all forms for which the scale factor can be set. I don't have such a element in my forms (and I'm afraid to add one as I cannot be sure if I run in another firemonkey bug than).
So how do I account for different DPI-Settings using FireMonkey?
Edit: I tried hacking TPlatFormWin and set CurrentScreenScale to 2 but it didn't work: I got black toolbars, but no scaling, but at least it used the HighRes alternative from the provided TImage.MultiResBitmap.
If anyone reads this... my experience with Windows desktop Firemonkey is that you have to take care of OS DPI setting manually and it's OK to put your controls in a top container (a TLayout) that's Scale is set according to the OS screen DPI settings (determined with some low level code).
However there are cases when you need to reverse this scaling - for example a Viewport3D must be scaled back 1/X to correctly show inside the scaled up container. Otherwise pixel level artifacts will show, image quality will be awful.
This scale up/scale back technique works nicely.
U can do something like this to change the root TLayout:
with 100 being the default
if windowsscale>0 then begin
LayoutScale.height:=ClientHeight*100/windowsscale;
LayoutScale.Width :=Clientwidth*100/windowsscale;
LayoutScale.Scale.X:=windowsscale/100;
LayoutScale.Scale.Y:=windowsscale/100;
end;

How to Make a form snap to edges of the screen

I just recently started learning Firemonkey, so if the question is stupid, please do not kick. How can I make a Firemonkey form that sticks to the edges of the screen. In VCL is easily done by using the properties ScreenSnap: = true and SnapBuffer: = 15 for example. Another way - processing messages WM_WWINDOWPOSCHANGING or WM_MOVING. How can I make the same with FireMonkey?
Thanks.
Since FMX is platform neutral, doing platform specific things is a lot harder. It should become a little easier with FM2 that ships with Delphi XE3 now.
For Delphi XE2, probably the easiest way is to wrap your FMX stuff in a VCL form.

Options for pure-graphics display in Delphi 2009

My whole experience with direct use of graphics consists of drawing shapes using Turbo Pascal’s gdi unit on a 386 machine ages ago, finding it unbearably slow and never giving it a second thought. In other words, I have next to no idea where to begin.
For a simple Internet radio player application, I would like to design a graphic display somewhat similar to Winamp (but a bit larger and easier on the eyes, since the illegibility of such displays is one reason I’m trying to do my own).
Simple graphic components like those imitating LED displays are nowhere near sufficient, of course. I don’t expect to be drawing clickable UI controls, and certainly not skins – just the readout, with text, digits and a few symbols. I understand Delphi 2010 supports Direct2D, but I only have D2009.
What are my options? Are there any 3rd party components that would help?
On edit two small points. I need the drawing to be flicker-free (i.e,, unlike what I experienced all those years ago in Turbo Pascal :-). Is TCanvas going to be fast enough for that? Also, I would probably want to use alphablending, which I don't think I can get with the basic TextOut, LineTo etc. graphics API. (I just don't know what's possible). What about GDI+?
A library for fast 2D graphics for Delphi is available as open source on Sourceforge:
Graphics32 (home page: http://www.graphics32.org/)
Graphics32 is a graphics library for
Delphi and Kylix/CLX. Optimized for
32-bit pixel formats, it provides fast
operations with pixels and graphic
primitives. In most cases Graphics32
considerably outperforms the standard
TBitmap/TCanvas methods.
Features Some of Graphics32 features include:
Fast per-pixel access up to 100 times faster compared to standard TBitmap;
High-performance Bitmap alpha blending (including per-pixel alpha blending);
Pixel, line and polygon antialiasing with sub-pixel accuracy (combined with alpha blending);
Arbitrary polygon transformations and custom fillings;
Bitmap resampling with high quality reconstruction filters (e.g. Lanczos, Cubic, Mitchell);
A unique state-of-the-art rasterization system;
Affine transformations of bitmaps: rotations, scaling, etc with sub-pixel accuracy;
Arbitrary projective transformations of bitmaps;
Arbitrary remapping transformations of bitmaps (e.g. for Warping, Morphing);
Flexible supersampling implementation for maximum sampling quality;
Flicker-free image displaying components with optimized double buffering via advanced MicroTiles based repaint optimizer;
Multiple customizible easy-to-use overlay layers;
Locking of bitmaps for safe multithreading;
A property editor for RGB and alpha channel loading;
Design-time loading of image formats supported by standard TPicture;
Works on Borland Delphi, C++ Builder and Kylix (The last version that supported Kylix was 1.8.3).
As of version 1.5.1b Graphics32 is licensed under the terms of the Mozilla Public License.
Take a look at TCanvas. It's built into most visual controls and contains easy methods for the sort of simple drawing you're looking at, without the need for mucking around with DirectX or OpenGL. If you want a really simple surface you can draw on, place a blank TImage TPaintBox on the form and use its Canvas as your drawing surface.
Mostly I agree with Mason and the comments. TPaintBox is a very simple component really. You implement the OnPaint event and are in complete control. It is fast enough on a fast-enough machine.
Put it on a TScrollBox and you don't even need to worry about where the user has scrolled to :)
Make sure you check out the DoubleBufferred property of the parent control(panel/ScrollBox).
If it is a complex drawing/graphic also check out InvalidateRect - this controls which area of a canvas is redrawn.
Of course like all graphics/drawing it gets pretty complicated pretty quickly :(
Just saw your edit. If you need alpha blending and flicker-free drawing, TCanvas is probably not going to be good enough for you. You should look at components that wrap OpenGL or Direct3D and provide you a high-power graphics canvas.
One such package is Asphyre, though I'm not sure if they have a version that works on Delphi 2009+ yet. I've also got a custom-built library that wraps SDL 1.3 and gives you a drawing frame component you can place on a Delphi form. It does work on Delphi 2009 and later, but I haven't released it as its own package yet. You could find it if you dig around in the SVN archive of my game engine, but if you can wait a day or two I could try to get it made into an easily-usable BPL component package and available for download.

Delphi: image with alpha blending capabilities

Is there some simple component that could display PNG 32-bit images and alpha-blend it to another image on mouse enter and on mouse leave? Or even just a simple image that can load 32-bit PNG and additionally would have Alpha parameter...
I suppose I could use some skin library (alphacontrols?) or some graphics library, but for some simple purely visual effects that would be quite an overkill and I can't seem to find a simple one that does it for me and would work on Glass surface as well...
It is not quite a component, but here is a link to a good article on how to do it yourself. Its just a few lines of code:
http://melander.dk/articles/alphasplash/
The basic TImage is capable of displaying a PNG image and alpha-blend-it to whatever is behind it. You just need to add the "pngimage" unit to the uses clause of your form. You didn't mention the version of Delphi you're on: Delphi 2010 has this unit, but I have no idea with what version of Delphi they started shipping it. For Delphi 7 I know for sure you'll need to find the open source "pngimage".
If you need to do this when the user moves in and out of your control, consider caching the state images in bitmaps: it will be faster at runtime and you can use a single TImage that shows the current image, you don't need two overlapping TIMage controls.

How to make the form into fully transparent 32bit alpha?

i use to create a full transparent form, but the png and the 32bit image will not blend to the form and images is not properly displayed its trnsparency. i get the concept here but i cannot put button on it. all abject are invisible except the image backgound. by the way my compiler is delphi7 and D2009
Seems that Andreas Hausladen stumbled upon a similar problem and has already implemented a solution: he rewrote TJvTransparentForm in the JVCL library.
Even if you are not going to use that component directly you may gain some insight by studying the source.
Here is the link to Andreas' article.
If you want to use a PNG to control transparency you might want to look into "layered windows":
SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_LAYERED);
UpdateLayeredWindow
This allows you to have variable transparency accross the window, just as PNG allows! The problem is, controls on layered windows don't really work, I guess it's a Windows issue. My solution was to actually brake up the big window into multiple smaller windows, with all the controls on non-layered windows. This creates yet an other problem, because you now have multiple windows and you want them to move like a single window. The solution: implement your own algorithm for moving the window accross the screen and use:
BeginDeferWindowPos
DeferWindowPos
EndDeferWindowPos
... to move all windows at once, so the user has no idea she's looking at multiple windows! Finally, if you want to get fancy, you might want to look into SetWindowRgn: this allows you to create a window with a non-rectangular shape.
P.S: Reading Andrea's link from Uwe Raabe, he's using the same technique, only he packaged it ready for action!

Resources