Welcome, Guest
Username: Password: Remember me
Components and Libraries for Graphics Development, discussions, problems and suggestions.
  • Page:
  • 1

TOPIC:

ORCA TD2Background doesn't fire OnBeforePaint evnt 11 years 7 months ago #3793

  • RockyLuck
  • RockyLuck's Avatar Topic Author
  • Visitor
  • Visitor

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 ***

Please Log in or Create an account to join the conversation.

ORCA TD2Background doesn't fire OnBeforePaint evnt 11 years 7 months ago #3900

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4540
  • Thank you received: 1117
Yes Sir
PilotLogic Architect and Core Programmer

Please Log in or Create an account to join the conversation.

  • Page:
  • 1