TD2Background does have an OnBeforePaint event like any other TD2VisualObject. However, because of the way this works, the top TD2Backround (the root) does not fire this event. That's a pity, because it's an ideal place to initialize some components at run time, if that's not possible at design time.
The reason OnBeforePaint event is not fired is because that event is fired only for all the children of a given object. Since the root object (TD2Background) is not a child of any object, the OnBeforePaint is never called.
The following patch remedies this omission.
In orca_scene2d.pas inherit the BeforePaint method in TD2Background
TD2Background = class(TD2Control)
private
FFill: TD2Brush;
procedure SetFill(const Value: TD2Brush);
protected
procedure BeforePaint; override; // *** DB ***
procedure PaintChildren; override;
procedure FillChanged(Sender: TObject); virtual;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Paint; override;
published
property Resource;
property Fill: TD2Brush read FFill write SetFill;
end;
In orca_scene2d_obj_controls.inc make this little change:
procedure TD2Background.FillChanged(Sender: TObject);
begin
Repaint;
end;
procedure TD2Background.BeforePaint; // *** DB ***
begin // *** DB ***
inherited BeforePaint; // *** DB ***
if Assigned(FOnBeforePaint) then begin // *** DB ***
// Only if we're the top background // *** DB ***
if Self.Scene.GetRoot = Self then // *** DB ***
FOnBeforePaint(Self, Self.Canvas, // *** DB ***
d2Rect(0, 0, FWidth, FHeight) );// *** DB ***
end{if}; // *** DB ***
end; // *** DB ***