nux-1.16.0
WindowCompositor.h
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 
00036   class MenuPage;
00037   class PBuffer;
00038   class WindowThread;
00039   class View;
00040   class InputArea;
00041   class Area;
00042   class PaintLayer;
00043   class Event;
00044 
00045   class WindowCompositor : public sigc::trackable
00046   {
00047   public:
00048     typedef ObjectWeakPtr<BaseWindow> WeakBaseWindowPtr;
00049 
00050     WindowCompositor();
00051     ~WindowCompositor();
00052 
00053 
00055     Geometry GetTooltipGeometry() const;
00056 
00058     Geometry GetTooltipMainWindowGeometry() const;
00059 
00060 //     bool MouseDown(Point pt);
00061 // 
00062 //     bool MouseMove(Point pt);
00063 //     bool MouseUp(Point pt);
00064 
00065     void ProcessEvent(Event &event);
00066 
00067     //====================================
00068     void MouseEventCycle(Event &event);
00069     void DndEventCycle(Event &event);
00070     bool _enable_nux_new_event_architecture;
00071 
00072 
00073     Point _mouse_position_on_owner;
00074     Point _mouse_position;
00075 
00077     Point GetMousePosition();
00078     
00079     void KeyboardEventCycle(Event &event);
00080 
00081     void MenuEventCycle(Event &event);
00082     MenuPage* _mouse_owner_menu_page;
00083     MenuPage* _mouse_over_menu_page;
00084     bool      _starting_menu_event_cycle;
00085     bool      _menu_is_active;
00086 
00087     void SetKeyFocusArea(InputArea* area);
00088     InputArea* GetKeyFocusArea();
00089 
00091 
00094     sigc::signal<void, BaseWindow*> sigVisibleViewWindow;    
00095 
00097 
00100     sigc::signal<void, BaseWindow*> sigHiddenViewWindow;    
00101 
00102   private:
00103 
00105     void GetAreaUnderMouse(const Point& mouse_position,
00106                            NuxEventType event_type,
00107                            InputArea** area_under_mouse_pointer,
00108                            BaseWindow** window);
00109 
00111     void FindKeyFocusArea(NuxEventType event_type,
00112                           unsigned int key_symbol,
00113                           unsigned int special_keys_state,
00114                           InputArea** key_focus_area,
00115                           BaseWindow** window);
00116     
00118     void FindKeyFocusAreaFrom(NuxEventType event_type,
00119       unsigned int key_symbol,
00120       unsigned int special_keys_state,
00121       InputArea* root_search_area,
00122       InputArea** key_focus_area,
00123       BaseWindow** window);
00124 
00125     void ResetMousePointerAreas();
00126 
00128     Area* GetMouseOwnerArea();
00130     void SetMouseOwnerArea(Area* area);
00131 
00133     void SetMouseOverArea(Area* area);
00134     
00136     void SetMouseOwnerBaseWindow(BaseWindow* base_window);
00137 
00139     void OnMouseOverViewDestroyed(Object* area);
00140     
00142     void OnMouseOwnerViewDestroyed(Object* area);
00143 
00145     void OnKeyNavFocusDestroyed(Object* area);
00146 
00148     void OnMouseOwnerBaseWindowDestroyed(Object* area);
00149 
00150     void SendKeyEvent(InputArea* input_area, NuxEventType event_type,
00151       unsigned int key_sym,
00152       unsigned long x11_key_code,
00153       unsigned long special_keys_state,
00154       const char* text,
00155       int key_repeat_count);
00156 
00158 
00162     InputArea* key_focus_area_;
00163     InputArea* mouse_owner_area_;
00164     InputArea* mouse_over_area_;
00165     BaseWindow* mouse_owner_base_window_;
00166 
00167     int dnd_safety_x_;
00168     int dnd_safety_y_;
00169 
00170     sigc::connection mouse_over_view_connection_;
00171     sigc::connection mouse_owner_view_connection_;
00172     sigc::connection mouse_owner_basewindow_connection_;
00173     sigc::connection key_focus_area_connection_;
00174 
00175     //====================================
00176   
00177   public:
00178     ObjectPtr<IOpenGLFrameBufferObject>& GetWindowFrameBufferObject()
00179     {
00180       return m_FrameBufferObject;
00181     }
00182     ObjectPtr<IOpenGLFrameBufferObject> m_FrameBufferObject;
00183 
00184     ObjectPtr<IOpenGLBaseTexture> GetScreenBlurTexture();
00185 
00186     void StartModalWindow(ObjectWeakPtr<BaseWindow>);
00187     void StopModalWindow(ObjectWeakPtr<BaseWindow>);
00188 
00189     void AddMenu(MenuPage* menu, BaseWindow *window, bool OverrideCurrentMenuChain = true);
00190     void RemoveMenu(MenuPage* menu);
00191     void CleanMenu();
00192 
00193     void PushModalWindow(ObjectWeakPtr<BaseWindow> window);
00194 
00195     void SetWidgetDrawingOverlay(InputArea *ic, BaseWindow *OverlayWindow);
00196     InputArea *GetWidgetDrawingOverlay();
00197 
00198     void SetTooltip(InputArea *TooltipArea, const TCHAR *TooltipText, int x, int y);
00206     bool ValidateMouseInsideTooltipArea(int x, int y);
00212     bool IsTooltipActive();
00213     void CancelTooltip();
00214 
00215     void SetAreaEventRoot(int x, int y)
00216     {
00217       _event_root = Point(x, y);
00218     }
00219 
00220     //TODO: DEPRECATED
00221     const IEvent *GetCurrentEvent() const
00222     {
00223       return NULL;
00224     }
00225 
00226     void SetBackgroundPaintLayer(AbstractPaintLayer *bkg);
00227 
00232     void SetAlwaysOnFrontWindow(BaseWindow *window);
00233 
00234 
00236 
00245     bool EnableExclusiveInputArea(InputArea *input_area);
00246     
00248 
00253     bool DisableExclusiveInputArea(InputArea *input_area);
00254 
00256 
00259     bool InExclusiveInputMode();
00260 
00262 
00265     void RestoreRenderingSurface();
00266 
00268     void* GetBackupTextureData(BaseWindow *base_window, int &width, int &height, int &format);
00269 
00271 
00275     void ResetDnDArea();
00276 
00277     // SetDnDArea is declared as private.
00278     //void SetDnDArea (InputArea* area);
00279     InputArea* GetDnDArea();
00280 
00282 
00285     BaseWindow* GetProcessingTopView()
00286     {
00287       return m_CurrentWindow.GetPointer();
00288     }
00289 
00290     // Pointer Grab API
00291 
00293 
00301     bool GrabPointerAdd(InputArea* area);
00302 
00304 
00311     bool GrabPointerRemove(InputArea* area);
00312 
00314     bool IsInPointerGrabStack(InputArea* area);
00315 
00317     InputArea* GetPointerGrabArea();
00318 
00319     // Keyboard Grab API
00320 
00322 
00330     bool GrabKeyboardAdd(InputArea* area);
00331 
00333 
00340     bool GrabKeyboardRemove(InputArea* area);
00341 
00343     bool IsInKeyboardGrabStack (InputArea* area);
00344 
00346     InputArea* GetKeyboardGrabArea ();
00347 
00348   private:
00350     void Draw(bool SizeConfigurationEvent, bool force_draw);
00351 
00352     void DrawPopup(bool force_draw);
00353     void DrawMenu(bool force_draw);
00354     void DrawOverlay(bool force_draw);
00355     void DrawTooltip(bool force_draw);
00356 
00358 
00363     void RenderTopViews(bool force_draw, std::list< ObjectWeakPtr<BaseWindow> >& WindowList, bool draw_modal);
00364 
00366     void RenderTopViewContent(BaseWindow *window, bool force_draw);
00367 
00368     void RenderMainWindowComposition(bool force_draw);
00369 
00379     void PresentBufferToScreen(ObjectPtr<IOpenGLBaseTexture> HWTexture, int x, int y, bool RenderToMainTexture, bool BluredBackground = false, float opacity=1.0f, bool premultiply = false);
00380     void PresentRendering();
00381 
00385     void SetMainColorRT();
00386 
00388 
00395     void PushHigher(BaseWindow *top_floating_view, BaseWindow *bottom_floating_view, bool strict = false);
00397     void PushToFront(BaseWindow *bottom_floating_view);
00399     void PushToBack (BaseWindow *bottom_floating_view);
00400 
00406     BaseWindow *GetSelectedWindow();
00407 
00408     
00409     BaseWindow *GetFocusAreaWindow()
00410     {
00411       return m_FocusAreaWindow.GetPointer();
00412     }
00413 
00415 
00419     void SetProcessingTopView(BaseWindow* window)
00420     {
00421       m_CurrentWindow = window;
00422     }
00423 
00424     private:
00425 
00426     void SetFocusAreaWindow(BaseWindow *window)
00427     {
00428       m_FocusAreaWindow = window;
00429     }
00430 
00431     void SetCurrentEvent(IEvent *event)
00432     {
00433       m_CurrentEvent = event;
00434     }
00435 
00436     void EnsureAlwaysOnFrontWindow();
00437 
00438     void FormatRenderTargets(int width, int height);
00439 
00440     //void UpdatePostProcessRT();
00441 
00448     void FloatingAreaConfigureNotify(int Width, int Height);
00449 
00450     void RegisterWindow(BaseWindow*);
00451     // UnRegister is called via the object destroyed event, hence the Object*.
00452     void UnRegisterWindow(Object*);
00453 
00455     long MenuEventCycle(Event &event, long TraverseInfo, long ProcessEventInfo);
00456 
00457     // We use Rectangle texture to attach to the frame-buffer because some GPU like the Geforce FX 5600 do not
00458     // have support for ARB_texture_non_power_of_two. However it does support ARB_texture_recatangle.
00459     struct RenderTargetTextures
00460     {
00461       ObjectPtr<IOpenGLBaseTexture> color_rt;
00462       ObjectPtr<IOpenGLBaseTexture> depth_rt;
00463     };
00464     ObjectPtr<IOpenGLBaseTexture> m_MainColorRT;
00465     ObjectPtr<IOpenGLBaseTexture> m_MainDepthRT;
00466 
00468     RenderTargetTextures &GetWindowBuffer(BaseWindow* window);
00469 
00470     WeakBaseWindowPtr m_CurrentWindow;    
00471     WeakBaseWindowPtr m_FocusAreaWindow;  
00472     WeakBaseWindowPtr m_MenuWindow;       
00473     IEvent* m_CurrentEvent; 
00474 
00475     InputArea* _mouse_over_area;      
00476     InputArea* _previous_mouse_over_area;
00477 
00478     void SetDnDArea (InputArea* area);
00479 
00480     // DnD support
00481     InputArea* _dnd_area;   
00482 
00484 
00488     void ExecPendingExclusiveInputAreaAction ();
00489 
00491 
00494     InputArea *GetExclusiveInputArea ();
00495 
00511     InputArea* _exclusive_input_area;
00512 
00516     bool _in_exclusive_input_mode;
00517 
00522     bool _pending_exclusive_input_mode_action;
00523 
00525     bool inside_event_cycle_;
00526 
00528     bool inside_rendering_cycle_;
00529 
00530     InputArea* OverlayDrawingCommand;
00531     WeakBaseWindowPtr m_OverlayWindow;            
00532     WeakBaseWindowPtr _tooltip_window;            
00533     Geometry    _tooltip_geometry;              
00534     Geometry    _tooltip_mainwindow_geometry;   
00535     Geometry    _tooltip_text_geometry;         
00536     Point _event_root;
00537 
00538     bool on_menu_closure_continue_with_event_;
00539     AbstractPaintLayer *m_Background;
00540 
00541     typedef std::list<WeakBaseWindowPtr> WindowList;
00542     WindowList _view_window_list;
00543     WindowList _modal_view_window_list;
00544     WeakBaseWindowPtr _always_on_front_window;  
00545 
00546     std::list<MenuPage* > *_menu_chain;
00547 
00553     WeakBaseWindowPtr m_SelectedWindow;
00554 
00555     std::map<BaseWindow*, struct RenderTargetTextures > _window_to_texture_map;
00556 
00557     WeakBaseWindowPtr m_ModalWindow;
00558     Point m_MouseLastPos;
00559     Point m_MouseCurrentPos;
00560 
00561     bool m_PopupRemoved;
00562     bool m_MenuRemoved;
00563     bool m_MouseUp;
00564     bool m_MouseDown;
00565 
00566     // Window Geometry
00567     int m_Width;
00568     int m_Height;
00569 
00570     NString m_TooltipText;
00571     InputArea *m_TooltipArea;
00572     int m_TooltipX;
00573     int m_TooltipY;
00574 
00576 
00581     std::list<InputArea*> pointer_grab_stack_;
00582 
00584 
00589     std::list<InputArea*> keyboard_grab_stack_;
00590 
00591   private:
00592     WindowCompositor (const WindowCompositor &);
00593     // Does not make sense for a singleton. This is a self assignment.
00594     WindowCompositor &operator= (const WindowCompositor &);
00595     // Declare operator address-of as private
00596     WindowCompositor *operator &();
00597 
00598     friend class InputArea;
00599     friend class WindowThread;
00600     friend class TimerHandler;
00601     friend class MenuBar;
00602     friend class MenuPage;
00603     friend class BaseWindow;
00604     friend class HSplitter;
00605     friend class VSplitter;
00606     friend class TableCtrl;
00607     friend class View;
00608   };
00609 
00610 }
00611 #endif // WINDOWCOMPOSITOR_H
00612 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends