A little fun with Delphi for today’s Star Wars day!
This is a pretty simple 3D form with a 3D layout at an angle, and then a 2D layout with text and images is animated up the 3D layout. The only code is populating the labels as the animation kicks off automatically.
Download the code and run the full credit scroll, or change the message to share with your friends. It is FireMonkey, and while I only tested it on Windows, it should work on Android, iOS, macOS, and even Linux if you are running FMX Linux.
Today is the Lunar New Year starting the Chinese year of the Fire Monkey. The first day of the New Year falls on the new moon between 21 January and 20 February, which in 2016 is Monday, February 8th. The animal associated with the year is cyclical, as is the elemental sign. The last year of the monkey was 2004, and that year it was the Wood Monkey. The Fire elemental sign is considered the prosperity stage.
How are you using FireMonkey this year? How will the Monkey help you prosper?
FireMonkey has many layout controls to choose from. Come learn the differences and how to use them to create dynamic, multi-platform user interfaces.
FireMonkey Layouts with Delphi
FireMonkey Layouts with C++Builder
Understanding and using FireMonkey Layouts
FireMonkey and the FireUI makes it easy to build one form to rule all the platforms. Combining layout controls and making use of Anchors, Alignment, Padding and Margins it is easy to make one form that looks and works great on all platforms.
The AbsoluteToLocal and LocalToAbsolute for TScaledLayout don’t handle the scaling. I’ve created a class helper that adds new methods for dealing with scaling.
{ TScaledLayoutHelper - interface }
type
TScaledLayoutHelper = class helper for TScaledLayout
function LocalToAbsoluteScaled(const Point: TPointF): TPointF;
function AbsoluteToLocalScaled(const Point: TPointF): TPointF;
end;
{ TScaledLayoutHelper - implementation }
function TScaledLayoutHelper.AbsoluteToLocalScaled( const Point: TPointF): TPointF;
begin
Result.X := Self.Position.X
+ Point.X
* Self.Width
/ Self.OriginalWidth;
Result.Y := Self.Position.Y
+ Point.Y
* Self.Height
/ Self.OriginalHeight;
end;
function TScaledLayoutHelper.LocalToAbsoluteScaled( const Point: TPointF): TPointF;
begin
Result.X := Point.X
/ Self.Width
/ Self.OriginalWidth
- Self.Position.X;
Result.Y := Point.Y
/ Self.Height
/ Self.OriginalHeight
- Self.Position.Y;
end;
If you look at the original implementations of AbsoluteToLocal and LocalToAbsolute you will see they have different execution paths and calculations based on private members, so there may be some circumstances where my new ones don’t work as expected. They did work in my tests, and I am open to feedback.