nux-0.9.46

Nux/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 STACKMANAGER_H
00024 #define STACKMANAGER_H
00025 
00026 #include "BaseWindow.h"
00027 
00028 #include <sigc++/connection.h>
00029 
00030 namespace nux
00031 {
00032 
00033   class MenuPage;
00034   class PBuffer;
00035   class WindowThread;
00036   class View;
00037   class InputArea;
00038   class Area;
00039   class BaseWindow;
00040   class PaintLayer;
00041   class Event;
00042 
00043   class WindowCompositor
00044   {
00045   public:
00046     WindowCompositor();
00047     ~WindowCompositor();
00048 
00049 
00051     Geometry GetTooltipGeometry() const;
00052 
00054     Geometry GetTooltipMainWindowGeometry() const;
00055 
00056     bool MouseDown (Point pt);
00057 
00058     bool MouseMove (Point pt);
00059     bool MouseUp (Point pt);
00060 
00061     void ProcessEvent (IEvent &ievent);
00062 
00063 
00064     ObjectPtr<IOpenGLFrameBufferObject>& GetWindowFrameBufferObject()
00065     {
00066       return m_FrameBufferObject;
00067     }
00068     ObjectPtr<IOpenGLFrameBufferObject> m_FrameBufferObject;
00069 
00070     ObjectPtr< IOpenGLBaseTexture > GetScreenBlurTexture();
00071 
00072     void StartModalWindow (ObjectWeakPtr<BaseWindow>);
00073     void StopModalWindow (ObjectWeakPtr<BaseWindow>);
00074 
00075     void AddMenu(MenuPage* menu, BaseWindow *window, bool OverrideCurrentMenuChain = true);
00076     void RemoveMenu(MenuPage* menu);
00077     void CleanMenu();
00078 
00079     void PushModalWindow (ObjectWeakPtr<BaseWindow> window);
00080 
00081     void SetWidgetDrawingOverlay (InputArea *ic, BaseWindow *OverlayWindow);
00082     InputArea *GetWidgetDrawingOverlay();
00083 
00084     void SetTooltip (InputArea *TooltipArea, const TCHAR *TooltipText, int x, int y);
00092     bool ValidateMouseInsideTooltipArea (int x, int y);
00098     bool IsTooltipActive();
00099     void CancelTooltip();
00100 
00101     void SetAreaEventRoot (int x, int y)
00102     {
00103       _event_root.Set (x, y);
00104     }
00105 
00106     const IEvent *GetCurrentEvent() const
00107     {
00108       return m_CurrentEvent;
00109     }
00110 
00111     long DispatchEventToArea (Event &event, Area* area, long TraverseInfo, long ProcessEventInfo);
00112 
00113     long DispatchEventToView (Event &event, View* view, long TraverseInfo, long ProcessEventInfo);
00114 
00115     void SetBackgroundPaintLayer (AbstractPaintLayer *bkg);
00116 
00121     void SetAlwaysOnFrontWindow (BaseWindow *window);
00122 
00123 
00125 
00134     bool EnableExclusiveInputArea (InputArea *input_area);
00135     
00137 
00142     bool DisableExclusiveInputArea (InputArea *input_area);
00143 
00145 
00148     bool InExclusiveInputMode ();
00149 
00151 
00154     void RestoreRenderingSurface ();
00155 
00157     void* GetBackupTextureData (BaseWindow *base_window, int &width, int &height, int &format);
00158 
00160 
00164     void ResetDnDArea();
00165 
00166     // SetDnDArea is declared as private.
00167     //void SetDnDArea (InputArea* area);
00168     InputArea* GetDnDArea ();
00169 
00171 
00174     BaseWindow* GetProcessingTopView ()
00175     {
00176       return m_CurrentWindow.GetPointer ();
00177     }
00178 
00179     // Pointer Grab API
00180 
00182 
00190     bool GrabPointerAdd (InputArea* area);
00191 
00193 
00200     bool GrabPointerRemove (InputArea* area);
00201 
00203     bool IsInPointerGrabStack (InputArea* area);
00204 
00206     InputArea* GetPointerGrabArea ();
00207 
00208     // Keyboard Grab API
00209 
00211 
00219     bool GrabKeyboardAdd (InputArea* area);
00220 
00222 
00229     bool GrabKeyboardRemove (InputArea* area);
00230 
00232     bool IsInKeyboardGrabStack (InputArea* area);
00233 
00235     InputArea* GetKeyboardGrabArea ();
00236 
00237   private:
00239     void Draw (bool SizeConfigurationEvent, bool force_draw);
00240 
00241     void DrawPopup (bool force_draw);
00242     void DrawMenu (bool force_draw);
00243     void DrawOverlay (bool force_draw);
00244     void DrawTooltip (bool force_draw);
00245 
00247 
00253     void RenderTopViews (bool force_draw, std::list< ObjectWeakPtr<BaseWindow> >& WindowList, bool draw_modal, bool use_fbo);
00254 
00256     void RenderTopViewContent (BaseWindow *window, bool force_draw);
00257 
00258     void RenderMainWindowComposition (bool force_draw, bool UseFBO);
00259 
00260 
00261 
00271     void PresentBufferToScreen (ObjectPtr<IOpenGLBaseTexture> HWTexture, int x, int y, bool RenderToMainTexture, bool BluredBackground = false, float opacity=1.0f);
00272     void PresentRendering();
00273 
00277     void SetMainColorRT();
00278 
00284     void CopyTextureToMainColorRT (ObjectPtr<IOpenGLBaseTexture> HWTexture, int x, int y);
00285 
00289     void SetCompositionRT();
00290 
00296     void CopyTextureToCompositionRT (ObjectPtr<IOpenGLBaseTexture> HWTexture, int x, int y);
00297 
00299 
00306     void PushHigher (BaseWindow *top_floating_view, BaseWindow *bottom_floating_view, bool strict = false);
00308     void PushToFront (BaseWindow *bottom_floating_view);
00310     void PushToBack (BaseWindow *bottom_floating_view);
00311 
00317     BaseWindow *GetSelectedWindow();
00318 
00319     
00320     BaseWindow *GetFocusAreaWindow()
00321     {
00322       return m_FocusAreaWindow.GetPointer ();
00323     }
00324 
00326 
00330     void SetProcessingTopView (BaseWindow* window)
00331     {
00332       m_CurrentWindow = window;
00333     }
00334 
00335     private:
00336 
00337     void SetFocusAreaWindow (BaseWindow *window)
00338     {
00339       m_FocusAreaWindow = window;
00340     }
00341 
00342     void SetCurrentEvent (IEvent *event)
00343     {
00344       m_CurrentEvent = event;
00345     }
00346 
00347     void EnsureAlwaysOnFrontWindow ();
00348 
00349     void FormatRenderTargets (int width, int height);
00350 
00351     //void UpdatePostProcessRT();
00352 
00359     void FloatingAreaConfigureNotify (int Width, int Height);
00360 
00361     void SetMouseFocusArea (InputArea* area);
00362     
00363     InputArea* GetMouseFocusArea ();
00364     
00365     void OnMouseFocusAreaDestroyed (Object* area)
00366     {
00367       if (_mouse_focus_area == area)
00368         SetMouseFocusArea (NULL);
00369     }
00370 
00371     void SetMouseOverArea (InputArea* area);
00372 
00373     InputArea* GetMouseOverArea ();
00374 
00375     void OnMouseOverAreaDestroyed (Object* area)
00376     {
00377       if (_mouse_over_area == area)
00378         SetMouseOverArea (NULL);
00379     }
00380 
00381     void SetPreviousMouseOverArea (InputArea* area);
00382 
00383     InputArea* GetPreviousMouseOverArea ();
00384 
00385     void OnPreviousMouseOverAreaDestroyed (Object* area)
00386     {
00387       if (_previous_mouse_over_area == area)
00388         SetPreviousMouseOverArea (NULL);
00389     }
00390     
00391     void SetKeyboardFocusArea (InputArea* area);
00392 
00393     InputArea* GetKeyboardFocusArea ();
00394 
00395     void OnKeyboardFocusAreaDestroyed (Object* area);
00396 
00397     void RegisterWindow (BaseWindow*);
00398 
00399     void UnRegisterWindow (BaseWindow*);
00400 
00402     void ViewWindowPreEventCycle ();
00403 
00405     void ViewWindowPostEventCycle ();
00406 
00408     long MenuEventCycle (Event &event, long TraverseInfo, long ProcessEventInfo);
00409 
00410     // We use Rectangle texture to attach to the frame-buffer because some GPU like the Geforce FX 5600 do not
00411     // have support for ARB_texture_non_power_of_two. However it does support ARB_texture_recatangle.
00412     struct RenderTargetTextures
00413     {
00414       ObjectPtr<IOpenGLBaseTexture> color_rt;
00415       ObjectPtr<IOpenGLBaseTexture> depth_rt;
00416     };
00417     ObjectPtr<IOpenGLBaseTexture> m_MainColorRT;
00418     ObjectPtr<IOpenGLBaseTexture> m_MainDepthRT;
00419     ObjectPtr<IOpenGLBaseTexture> m_CompositionRT;
00420 
00422     RenderTargetTextures &GetWindowBuffer (BaseWindow* window);
00423 
00424     ObjectWeakPtr<BaseWindow> m_CurrentWindow;    
00425     ObjectWeakPtr<BaseWindow> m_FocusAreaWindow;  
00426     ObjectWeakPtr<BaseWindow> m_MenuWindow;       
00427     IEvent* m_CurrentEvent; 
00428 
00435     InputArea* _mouse_focus_area;
00436     InputArea* _mouse_over_area;      
00437     InputArea* _previous_mouse_over_area;
00439 
00443     InputArea* _keyboard_focus_area;
00444     
00445     void SetDnDArea (InputArea* area);
00446 
00447     // DnD support
00448     InputArea* _dnd_area;   
00449 
00451 
00455     void ExecPendingExclusiveInputAreaAction ();
00456 
00458 
00461     InputArea *GetExclusiveInputArea ();
00462 
00478     InputArea* _exclusive_input_area;
00479     
00483     bool _in_exclusive_input_mode;
00484 
00489     bool _pending_exclusive_input_mode_action;
00490 
00492     bool _inside_event_processing;
00493 
00495     bool _inside_rendering_cycle;
00496 
00498 
00501     sigc::signal<void, BaseWindow* > sigVisibleViewWindow;    
00502 
00504 
00507     sigc::signal<void, BaseWindow* > sigHiddenViewWindow;    
00508 
00509     InputArea* OverlayDrawingCommand;
00510     ObjectWeakPtr<BaseWindow> m_OverlayWindow;            
00511     ObjectWeakPtr<BaseWindow> _tooltip_window;            
00512     Geometry    _tooltip_geometry;              
00513     Geometry    _tooltip_mainwindow_geometry;   
00514     Geometry    _tooltip_text_geometry;         
00515     Point _event_root;
00516 
00517 
00518     AbstractPaintLayer *m_Background;
00519 
00520     std::list< ObjectWeakPtr<BaseWindow> > _view_window_list;
00521     std::list< ObjectWeakPtr<BaseWindow> > _modal_view_window_list;
00522     ObjectWeakPtr<BaseWindow>            _always_on_front_window;  
00523 
00524     std::list<MenuPage *> *m_MenuList;
00525 
00531     ObjectWeakPtr<BaseWindow> m_SelectedWindow;
00532 
00533     std::map< BaseWindow*, struct RenderTargetTextures > _window_to_texture_map;
00534 
00535     ObjectWeakPtr<BaseWindow> m_ModalWindow;
00536     Point m_MouseLastPos;
00537     Point m_MouseCurrentPos;
00538 
00539     bool m_PopupRemoved;
00540     bool m_MenuRemoved;
00541     bool m_MouseUp;
00542     bool m_MouseDown;
00543 
00544     // Window Geometry
00545     int m_Width;
00546     int m_Height;
00547 
00548     NString m_TooltipText;
00549     InputArea *m_TooltipArea;
00550     int m_TooltipX;
00551     int m_TooltipY;
00552 
00553     sigc::connection _previous_mouse_over_area_conn;
00554     sigc::connection _keyboard_focus_area_conn;
00555     sigc::connection _mouse_focus_area_conn;
00556     sigc::connection _mouse_over_area_conn;
00557 
00558 //     bool m_FullSceneBlurUpdated;
00559 //     ObjectPtr<IOpenGLBaseTexture> m_BlurTexture;
00560 //     ObjectPtr<IOpenGLBaseTexture> m_FullSceneMip0;
00561 //     ObjectPtr<IOpenGLBaseTexture> m_FullSceneMip1;
00562 //     ObjectPtr<IOpenGLBaseTexture> m_FullSceneMip2;
00563 
00564 
00566 
00571     std::list<InputArea*> _pointer_grab_stack;
00572 
00574 
00579     std::list<InputArea*> _keyboard_grab_stack;
00580 
00581   private:
00582     WindowCompositor (const WindowCompositor &);
00583     // Does not make sense for a singleton. This is a self assignment.
00584     WindowCompositor &operator= (const WindowCompositor &);
00585     // Declare operator address-of as private
00586     WindowCompositor *operator &();
00587 
00588     friend class InputArea;
00589     friend class WindowThread;
00590     friend class TimerHandler;
00591     friend class MenuBar;
00592     friend class MenuPage;
00593     friend class BaseWindow;
00594     friend class HSplitter;
00595     friend class VSplitter;
00596     friend class TableCtrl;
00597     friend class View;
00598   };
00599 
00600 }
00601 #endif // STACKMANAGER_H
00602