Back to index

nux  3.0.0
WindowCompositor.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 
00023 #ifndef WINDOWCOMPOSITOR_H
00024 #define WINDOWCOMPOSITOR_H
00025 
00026 #include "BaseWindow.h"
00027 
00028 #include <sigc++/trackable.h>
00029 #include <sigc++/connection.h>
00030 
00031 #include <NuxCore/ObjectPtr.h>
00032 
00033 namespace nux
00034 {
00035   class MenuPage;
00036   class PBuffer;
00037   class WindowThread;
00038   class View;
00039   class InputArea;
00040   class Area;
00041   class PaintLayer;
00042   class Event;
00043 
00045   class WindowCompositor : public sigc::trackable
00046   {
00047   public:
00048     typedef ObjectWeakPtr<BaseWindow> WeakBaseWindowPtr;
00049 
00050     WindowCompositor(WindowThread* window_thread);
00051     ~WindowCompositor();
00052 
00054     Geometry GetTooltipGeometry() const;
00055 
00057     Geometry GetTooltipMainWindowGeometry() const;
00058 
00059 //     bool MouseDown(Point pt);
00060 // 
00061 //     bool MouseMove(Point pt);
00062 //     bool MouseUp(Point pt);
00063 
00064     void ProcessEvent(Event& event);
00065 
00066     //====================================
00067     void MouseEventCycle(Event& event);
00068     void DndEventCycle(Event& event);
00069     bool _enable_nux_new_event_architecture;
00070 
00071 
00072     Point _mouse_position_on_owner;
00073     Point _mouse_position;
00074 
00076     Point GetMousePosition();
00077     
00078     void KeyboardEventCycle(Event& event);
00079 
00080     void MenuEventCycle(Event& event);
00081     MenuPage* _mouse_owner_menu_page;
00082     MenuPage* _mouse_over_menu_page;
00083     bool      _starting_menu_event_cycle;
00084     bool      _menu_is_active;
00085 
00087 
00096     bool SetKeyFocusArea(InputArea* area, KeyNavDirection direction = KEY_NAV_NONE);
00097 
00099 
00104     InputArea* GetKeyFocusArea();
00105 
00107 
00110     sigc::signal<void, BaseWindow*> sigVisibleViewWindow;    
00111 
00113 
00116     sigc::signal<void, BaseWindow*> sigHiddenViewWindow;    
00117 
00118   private:
00119 
00121     void GetAreaUnderMouse(const Point& mouse_position,
00122                            NuxEventType event_type,
00123                            InputArea** area_under_mouse_pointer,
00124                            BaseWindow** window);
00125 
00127     void FindKeyFocusArea(NuxEventType event_type,
00128                           unsigned int key_symbol,
00129                           unsigned int special_keys_state,
00130                           InputArea** key_focus_area,
00131                           BaseWindow** window);
00132     
00134     void FindKeyFocusAreaFrom(NuxEventType event_type,
00135       unsigned int key_symbol,
00136       unsigned int special_keys_state,
00137       InputArea* root_search_area,
00138       InputArea** key_focus_area,
00139       BaseWindow** window);
00140 
00141     void ResetMousePointerAreas();
00142 
00144     Area* GetMouseOwnerArea();
00145 
00147     void SetMouseOwnerArea(Area* area);
00148 
00150     void SetMouseOverArea(Area* area);
00151     
00153     void SetMouseOwnerBaseWindow(BaseWindow* base_window);
00154 
00156     void OnMouseOverViewDestroyed(Object* area);
00157     
00159     void OnMouseOwnerViewDestroyed(Object* area);
00160 
00162     void OnKeyNavFocusDestroyed(Object* area);
00163 
00165     void OnMouseOwnerBaseWindowDestroyed(Object* area);
00166 
00167     void SendKeyEvent(InputArea* input_area, NuxEventType event_type,
00168       unsigned int key_sym,
00169       unsigned long x11_key_code,
00170       unsigned long special_keys_state,
00171       const char* text,
00172       int key_repeat_count);
00173 
00174 
00176 
00180     InputArea* key_focus_area_;
00181     InputArea* mouse_owner_area_;
00182     InputArea* mouse_over_area_;
00183     BaseWindow* mouse_owner_base_window_;
00184 
00185     int dnd_safety_x_;
00186     int dnd_safety_y_;
00187 
00188     sigc::connection mouse_over_view_connection_;
00189     sigc::connection mouse_owner_view_connection_;
00190     sigc::connection mouse_owner_basewindow_connection_;
00191     sigc::connection key_focus_area_connection_;
00192 
00201     sigc::signal<void, Area*, bool, KeyNavDirection> key_nav_focus_change;
00202 
00208     sigc::signal<void, Area*> key_nav_focus_activate;
00209 
00210     //====================================
00211   
00212   public:
00221     void SetReferenceFramebuffer(unsigned int fbo_object, Geometry fbo_geometry);
00222 
00228     bool RestoreReferenceFramebuffer();
00229 
00230     ObjectPtr<IOpenGLFrameBufferObject>& GetWindowFrameBufferObject()
00231     {
00232       return m_FrameBufferObject;
00233     }
00234     
00235     ObjectPtr<IOpenGLFrameBufferObject> m_FrameBufferObject;
00236 
00237     void StartModalWindow(ObjectWeakPtr<BaseWindow>);
00238     void StopModalWindow(ObjectWeakPtr<BaseWindow>);
00239 
00240     void AddMenu(MenuPage* menu, BaseWindow* window, bool OverrideCurrentMenuChain = true);
00241     void RemoveMenu(MenuPage* menu);
00242     void CleanMenu();
00243 
00244     void PushModalWindow(ObjectWeakPtr<BaseWindow> window);
00245 
00246     void SetWidgetDrawingOverlay(InputArea* ic, BaseWindow* OverlayWindow);
00247     InputArea* GetWidgetDrawingOverlay();
00248 
00249     void SetTooltip(InputArea* TooltipArea, const char* TooltipText, int x, int y);
00257     bool ValidateMouseInsideTooltipArea(int x, int y);
00263     bool IsTooltipActive();
00264     void CancelTooltip();
00265 
00266     void SetAreaEventRoot(int x, int y)
00267     {
00268       _event_root = Point(x, y);
00269     }
00270 
00271     void SetBackgroundPaintLayer(AbstractPaintLayer* bkg);
00272 
00277     void SetAlwaysOnFrontWindow(BaseWindow* window);
00278 
00279 
00281 
00290     bool EnableExclusiveInputArea(InputArea* input_area);
00291     
00293 
00298     bool DisableExclusiveInputArea(InputArea* input_area);
00299 
00301 
00304     bool InExclusiveInputMode();
00305 
00307 
00310     void RestoreRenderingSurface();
00311 
00313     void* GetBackupTextureData(BaseWindow* base_window, int& width, int& height, int& format);
00314 
00316 
00320     void ResetDnDArea();
00321 
00322     // SetDnDArea is declared as private.
00323     //void SetDnDArea(InputArea* area);
00324     InputArea* GetDnDArea();
00325 
00327 
00330     BaseWindow* GetProcessingTopView()
00331     {
00332       return m_CurrentWindow.GetPointer();
00333     }
00334 
00335     // Pointer Grab API
00336 
00338 
00346     bool GrabPointerAdd(InputArea* area);
00347 
00349 
00356     bool GrabPointerRemove(InputArea* area);
00357 
00359     bool IsInPointerGrabStack(InputArea* area);
00360 
00362     InputArea* GetPointerGrabArea();
00363 
00364     // Keyboard Grab API
00365 
00367 
00375     bool GrabKeyboardAdd(InputArea* area);
00376 
00378 
00385     bool GrabKeyboardRemove(InputArea* area);
00386 
00388     bool IsInKeyboardGrabStack(InputArea* area);
00389 
00391     InputArea* GetKeyboardGrabArea();
00392 
00393     // We use Rectangle texture to attach to the frame-buffer because some GPU like the Geforce FX 5600 do not
00394     // have support for ARB_texture_non_power_of_two. However it does support ARB_texture_recatangle.
00395     struct RenderTargetTextures
00396     {
00397       ObjectPtr<IOpenGLBaseTexture> color_rt;
00398       ObjectPtr<IOpenGLBaseTexture> depth_rt;
00399     };
00400     
00402 
00408     RenderTargetTextures& GetWindowBuffer(BaseWindow* window);
00409 
00410   private:
00412     void Draw(bool SizeConfigurationEvent, bool force_draw);
00413 
00414     void DrawPopup(bool force_draw);
00415     void DrawMenu(bool force_draw);
00416     void DrawOverlay(bool force_draw);
00417     void DrawTooltip(bool force_draw);
00418 
00420 
00425     void RenderTopViews(bool force_draw, std::list< ObjectWeakPtr<BaseWindow> >& WindowList, bool draw_modal);
00426 
00428     void RenderTopViewContent(BaseWindow* window, bool force_draw);
00429 
00430     void RenderMainWindowComposition(bool force_draw);
00431 
00441     void PresentBufferToScreen(ObjectPtr<IOpenGLBaseTexture> HWTexture, int x, int y, bool RenderToMainTexture, bool BluredBackground = false, float opacity=1.0f, bool premultiply = false);
00442 
00446     void SetMainColorRT();
00447 
00449 
00456     void PushHigher(BaseWindow* top_floating_view, BaseWindow* bottom_floating_view, bool strict = false);
00458     void PushToFront(BaseWindow* bottom_floating_view);
00460     void PushToBack(BaseWindow* bottom_floating_view);
00461 
00467     BaseWindow* GetSelectedWindow();
00468 
00469     
00470     BaseWindow* GetFocusAreaWindow()
00471     {
00472       return m_FocusAreaWindow.GetPointer();
00473     }
00474 
00476 
00480     void SetProcessingTopView(BaseWindow* window)
00481     {
00482       m_CurrentWindow = window;
00483     }
00484 
00485     private:
00486 
00487     void SetFocusAreaWindow(BaseWindow* window)
00488     {
00489       m_FocusAreaWindow = window;
00490     }
00491 
00492     void SetCurrentEvent(Event* event)
00493     {
00494       m_CurrentEvent = event;
00495     }
00496 
00497     void EnsureAlwaysOnFrontWindow();
00498 
00499     void FormatRenderTargets(int width, int height);
00500 
00501     //void UpdatePostProcessRT();
00502 
00509     void FloatingAreaConfigureNotify(int Width, int Height);
00510 
00511     void RegisterWindow(BaseWindow*);
00512     // UnRegister is called via the object destroyed event, hence the Object*.
00513     void UnRegisterWindow(Object*);
00514 
00515     ObjectPtr<IOpenGLBaseTexture> m_MainColorRT;
00516     ObjectPtr<IOpenGLBaseTexture> m_MainDepthRT;
00517 
00518     WeakBaseWindowPtr m_CurrentWindow;    
00519     WeakBaseWindowPtr m_FocusAreaWindow;  
00520     WeakBaseWindowPtr m_MenuWindow;       
00521     Event* m_CurrentEvent; 
00522 
00523     InputArea* _mouse_over_area;      
00524     InputArea* _previous_mouse_over_area;
00525 
00526     void SetDnDArea(InputArea* area);
00527 
00528     // DnD support
00529     InputArea* _dnd_area;   
00530 
00532 
00536     void ExecPendingExclusiveInputAreaAction();
00537 
00539 
00542     InputArea* GetExclusiveInputArea();
00543 
00558     InputArea* _exclusive_input_area;
00559 
00563     bool _in_exclusive_input_mode;
00564 
00569     bool _pending_exclusive_input_mode_action;
00570 
00572     bool inside_event_cycle_;
00573 
00575     bool inside_rendering_cycle_;
00576 
00577     InputArea* OverlayDrawingCommand;
00578     WeakBaseWindowPtr m_OverlayWindow;            
00579     WeakBaseWindowPtr _tooltip_window;            
00580     Geometry    _tooltip_geometry;              
00581     Geometry    _tooltip_mainwindow_geometry;   
00582     Geometry    _tooltip_text_geometry;         
00583     Point _event_root;
00584 
00585     bool on_menu_closure_continue_with_event_;
00586     AbstractPaintLayer* m_Background;
00587 
00588     typedef std::list<WeakBaseWindowPtr> WindowList;
00589     WindowList _view_window_list;
00590     WindowList _modal_view_window_list;
00591     WeakBaseWindowPtr _always_on_front_window;  
00592 
00593     std::list<MenuPage* >* _menu_chain;
00594 
00600     WeakBaseWindowPtr m_SelectedWindow;
00601 
00602     std::map<BaseWindow*, struct RenderTargetTextures> _window_to_texture_map;
00603 
00604     WeakBaseWindowPtr m_ModalWindow;
00605     Point m_MouseLastPos;
00606     Point m_MouseCurrentPos;
00607 
00608     bool m_PopupRemoved;
00609     bool m_MenuRemoved;
00610     bool m_MouseUp;
00611     bool m_MouseDown;
00612 
00613     // Window Geometry
00614     int m_Width;
00615     int m_Height;
00616 
00617     NString m_TooltipText;
00618     InputArea* m_TooltipArea;
00619     int m_TooltipX;
00620     int m_TooltipY;
00621 
00623     unsigned int reference_fbo_;
00624     Geometry reference_fbo_geometry_;
00625 
00627 
00632     std::list<InputArea*> pointer_grab_stack_;
00633 
00635 
00640     std::list<InputArea*> keyboard_grab_stack_;
00641 
00642   private:
00643     WindowThread* window_thread_; 
00644 
00646 
00650     void BeforeDestructor();
00651 
00652     WindowCompositor(const WindowCompositor&);
00653     // Does not make sense for a singleton. This is a self assignment.
00654     WindowCompositor& operator= (const WindowCompositor&);
00655     // Declare operator address-of as private
00656     WindowCompositor* operator & ();
00657 
00658     friend class InputArea;
00659     friend class WindowThread;
00660     friend class TimerHandler;
00661     friend class MenuBar;
00662     friend class MenuPage;
00663     friend class BaseWindow;
00664     friend class HSplitter;
00665     friend class VSplitter;
00666     friend class TableCtrl;
00667     friend class View;
00668   };
00669 
00670 }
00671 #endif // WINDOWCOMPOSITOR_H
00672