I have created an FMX graphics application that draws various graphics from a custom binary vector file format. I'd now like to create a Windows Preview Handler to support that file format. I have already created a basic VCL preview handler based on the code found here. Some minor fixes were needed to get it to build in Delphi 10.4. I have also added a TPaintBox that I can draw to using the VCL TCanvas drawing functions.
The problem is that all the drawing for my file format is using FMX and uses several functions that don't exist in VCL, such as colour gradients and opacity. Is it possible to somehow mix in FMX TCanvas code for the preview handler?
If not then I have another option, but I'm not sure how well it would work. I would add functionality to the FMX application such that executing it with the appropriate input parameters (file path and dimensions) would generate an image file. The preview handler would just need to call it and load the image to display it. This would mean that the preview handler could be VCL only and would also reduce code size by not replicating the drawing code, but there may be latency issues.
I could also potentially use GDI+ or Direct2D in a VCL application since it would also support the advanced drawing functions, but it would mean rewriting all the drawing functions and I'm not sure if it would look exactly the same.
Any ideas are welcome. Thanks.
Related
I want to display graphics on top of an existing window, is that possible using pure Lua? because i cannot find the stuff i need, i only found how to display graphics in an specific OpenGL window.
I've looked to some code posted on github
https://github.com/ittner/lua-gd/tree/master
https://github.com/stetre/moongl
https://github.com/vrld/G4L
that's all i've found
There is no way to do it in pure Lua, as it doesn't provide any platform-specific drawing/GUI methods. It's possible to use some library (like those you've listed), but I'm not familiar with them. You can probably use wxlua, which is a wrapper around wxwidgets and provides SetTransparent method on its wxFrame object and ways to draw on a surface with transparent background or transparent brush (you can set the degree of transparency). You still need to find the position of the window you are interested in (to cover it with your window) and this is going to be system-dependent. For example, on Windows you can do this by using winapi window functions.
An old-school graphics effect is palette animation, where for an image of (say) 256 colours, the palette that each color index of 0-255 refers to is shifted. As it shifts, the colours of each pixel change.
You can read more about the technique here and see a fantastic HTML5 reproduction of old-style effects here. Here is a plasma example from Wikipedia:
I would like to achieve the same effect in FireMonkey, using FMX TBitmaps or another inbuilt class. (I currently have TBitmaps - with static colours - built once-off from a table of values.) FMX is quite abstracted from the underlying OS, and also using underlying OS techniques will stop the app being cross-platform-compatible. On the other hand, since it uses DirectX or OpenGL under the hood, fast animation effects should be very possible. What's the best approach?
I am using Delphi XE2 (original FireMonkey) but a technique for anything up to XE4 (FMX 3) is fine too.
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 2010, Win32 VCL. I need to create a main menu for my application with the most standard look. TMainMenu looks nice in all Windows versions, the only bad thing is when it displaying images for items with Enabled=False.
Delphi has some strange method for building that disabled images (b/w extrusion with bevels, for me it looks like spew). I want to make a patch for that procedure in VCL sources and let menu to select disabled images from the same TImageList, but I can't find it.
Is it exists at all or it is some standard windows API call? Do you know where is that procedure located?
Sure OwnerDraw style can fix all this but I want a bit faster solution.
There's a great post on Galfar's Lair blog which describes the problem, and has code for a workaround, overriding the TImageList DoDraw method.
Here's the pic (linked) showing the 'before' and 'after'.
I think this relates to pretty much all Delphi versions.
If you can provide your images as PNG you can use TPngImageList from PngComponents. It has different options to make a blended or grayscaled disabled image. The PNG format allows you to make use of alphablending.
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.