X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fcanvas%2FCanvas.hxx;h=2c817f61bcbf98fe17805b505847204df1d41f7f;hb=23413b47818b042620eeeaf306ffe6d1ae81852d;hp=4a3187fff4d68c4d73820463d6e9ae5c9f2a2b45;hpb=fd27e7bd43d51956ef810e7493a205c48d7bf64a;p=simgear.git diff --git a/simgear/canvas/Canvas.hxx b/simgear/canvas/Canvas.hxx index 4a3187ff..2c817f61 100644 --- a/simgear/canvas/Canvas.hxx +++ b/simgear/canvas/Canvas.hxx @@ -1,4 +1,4 @@ -// The canvas for rendering with the 2d API +///@file The canvas for rendering with the 2d API // // Copyright (C) 2012 Thomas Geymayer // @@ -23,32 +23,41 @@ #include "ODGauge.hxx" #include +#include +#include +#include #include #include + #include #include -#include +#include #include namespace simgear { +/// Canvas 2D drawing API namespace canvas { class CanvasMgr; class MouseEvent; class Canvas: - public PropertyBasedElement + public PropertyBasedElement, + public nasal::Object { public: enum StatusFlags { STATUS_OK, - MISSING_SIZE_X = 0x0001, - MISSING_SIZE_Y = 0x0002, - CREATE_FAILED = 0x0004 + STATUS_DIRTY = 1, + LAYOUT_DIRTY = STATUS_DIRTY << 1, + MISSING_SIZE_X = LAYOUT_DIRTY << 1, + MISSING_SIZE_Y = MISSING_SIZE_X << 1, + MISSING_SIZE = MISSING_SIZE_X | MISSING_SIZE_Y, + CREATE_FAILED = MISSING_SIZE_Y << 1 }; /** @@ -70,29 +79,60 @@ namespace canvas Canvas(SGPropertyNode* node); virtual ~Canvas(); - - void setSystemAdapter(const SystemAdapterPtr& system_adapter); - SystemAdapterPtr getSystemAdapter() const; + virtual void onDestroy(); void setCanvasMgr(CanvasMgr* canvas_mgr); CanvasMgr* getCanvasMgr() const; + bool isInit() const; + /** - * Add a canvas which should be mared as dirty upon any change to this + * Add a canvas which should be marked as dirty upon any change to this * canvas. * * This mechanism is used to eg. redraw a canvas if it's displaying * another canvas (recursive canvases) */ - void addDependentCanvas(const CanvasWeakPtr& canvas); + void addParentCanvas(const CanvasWeakPtr& canvas); + + /** + * Add a canvas which should be marked visible if this canvas is visible. + */ + void addChildCanvas(const CanvasWeakPtr& canvas); /** * Stop notifying the given canvas upon changes */ - void removeDependentCanvas(const CanvasWeakPtr& canvas); + void removeParentCanvas(const CanvasWeakPtr& canvas); + void removeChildCanvas(const CanvasWeakPtr& canvas); + /** + * Create a new group + */ GroupPtr createGroup(const std::string& name = ""); + /** + * Get an existing group with the given name + */ + GroupPtr getGroup(const std::string& name); + + /** + * Get an existing group with the given name or otherwise create a new + * group + */ + GroupPtr getOrCreateGroup(const std::string& name); + + /** + * Get the root group of the canvas + */ + GroupPtr getRootGroup(); + + /** + * Set the layout of the canvas (the layout will automatically update with + * the viewport size of the canvas) + */ + void setLayout(const LayoutRef& layout); + /** * Enable rendering for the next frame * @@ -103,7 +143,8 @@ namespace canvas void update(double delta_time_sec); - naRef addEventListener(const nasal::CallContext& ctx); + bool addEventListener(const std::string& type, const EventListener& cb); + bool dispatchEvent(const EventPtr& event); void setSizeX(int sx); void setSizeY(int sy); @@ -116,8 +157,11 @@ namespace canvas int getViewWidth() const; int getViewHeight() const; + SGRect getViewport() const; bool handleMouseEvent(const MouseEventPtr& event); + bool propagateEvent( EventPtr const& event, + EventPropagationPath const& path ); virtual void childAdded( SGPropertyNode * parent, SGPropertyNode * child ); @@ -129,15 +173,26 @@ namespace canvas CullCallbackPtr getCullCallback() const; + void reloadPlacements( const std::string& type = std::string() ); static void addPlacementFactory( const std::string& type, PlacementFactory factory ); + static void removePlacementFactory(const std::string& type); + + /** + * Set global SystemAdapter for all Canvas/ODGauge instances. + * + * The SystemAdapter is responsible for application specific operations + * like loading images/fonts and adding/removing cameras to the scene + * graph. + */ + static void setSystemAdapter(const SystemAdapterPtr& system_adapter); + static SystemAdapterPtr getSystemAdapter(); protected: - SystemAdapterPtr _system_adapter; CanvasMgr *_canvas_mgr; - std::auto_ptr _event_manager; + boost::scoped_ptr _event_manager; int _size_x, _size_y, @@ -147,38 +202,33 @@ namespace canvas PropertyObject _status; PropertyObject _status_msg; - PropertyObject _mouse_x, _mouse_y, - _mouse_dx, _mouse_dy, - _mouse_button, - _mouse_state, - _mouse_mod, - _mouse_scroll, - _mouse_event; - bool _sampling_dirty, _render_dirty, _visible; ODGauge _texture; - GroupPtr _root_group; + + GroupPtr _root_group; + LayoutRef _layout; CullCallbackPtr _cull_callback; bool _render_always; // _dirty_placements; std::vector _placements; - std::set _dependent_canvases; // _parent_canvases, // PlacementFactoryMap; static PlacementFactoryMap _placement_factories; - virtual void setSelf(const PropertyBasedElementPtr& self); void setStatusFlags(unsigned int flags, bool set = true); private: + static SystemAdapterPtr _system_adapter; + Canvas(const Canvas&); // = delete; Canvas& operator=(const Canvas&); // = delete; };