nux-0.9.48

Nux/View.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 ABSTRACTOBJECTBASE_H
00024 #define ABSTRACTOBJECTBASE_H
00025 
00026 #include "Nux.h"
00027 #include "Focusable.h"
00028 
00029 namespace nux
00030 {
00031 
00032   class Layout;
00033 
00034   enum eControlType
00035   {
00036     eNumericValuator,
00037     eSpinBox,
00038     eVector3Box,
00039     eBooleanBox,
00040     eStaticText,
00041     ePopupBox
00042   };
00043 
00044   class View: public InputArea //Area
00045   {
00046     NUX_DECLARE_OBJECT_TYPE (View, InputArea);
00047   public:
00048     View (NUX_FILE_LINE_DECL);
00049     virtual ~View();
00050     //virtual RemoveView(View *ic);
00051 
00052   public:
00053 
00054     long BaseProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo);
00055 
00056     virtual long ComputeChildLayout();
00057     virtual void PositionChildLayout (float offsetX, float offsetY);
00058 
00059     // NUXTODO: Find better name
00060     virtual long ComputeLayout2();
00061 
00062     // NUXTODO: Find better name
00063     virtual void ComputePosition2 (float offsetX, float offsetY);
00064 
00065     virtual void PreLayoutManagement();
00066     virtual long PostLayoutManagement (long LayoutResult);
00067     virtual void PreResizeGeometry();
00068     virtual void PostResizeGeometry();
00069 
00070     // NUXTODO: Find better name
00071     virtual long PostProcessEvent2 (IEvent &ievent, long TraverseInfo, long ProcessEventInfo);
00072 
00073     virtual bool IsLayout() const
00074     {
00075       return false;
00076     }
00077     virtual bool IsSpaceLayout() const
00078     {
00079       return false;
00080     }
00081     virtual bool IsArea() const
00082     {
00083       return false;
00084     }
00085     virtual bool IsView() const
00086     {
00087       return true;
00088     }
00089 
00090     void SetUsingStyleDrawing (bool b)
00091     {
00092       m_UseStyleDrawing = b;
00093     };
00094     bool IsUsingStyleDrawing() const
00095     {
00096       return m_UseStyleDrawing;
00097     };
00098 
00102     void DeactivateView ();
00103 
00107     void ActivateView ();
00108 
00112     bool IsViewActive () const;
00113 
00114   public:
00115     virtual void ProcessDraw (GraphicsEngine &GfxContext, bool force_draw);
00117 
00120     virtual void QueueDraw ();
00121     virtual void NeedRedraw (); 
00122 
00124     virtual void NeedSoftRedraw();
00125     virtual bool IsRedrawNeeded();
00126     virtual void DoneRedraw();
00127 
00128     virtual void OverlayDrawing (GraphicsEngine &GfxContext) {}
00129 
00130     //Layout Bridge
00131 
00132     bool SearchInAllSubNodes (Area *bo);
00133     bool SearchInFirstSubNodes (Area *bo);
00134 
00136     /*
00137         Set the Geometry of the View and the geometry of the Default Background Area.
00138         For simple interface control UI classes (RGBValuator...), this is enough.
00139         For others, they have to overwrite the function and do the appropriate computations
00140         for their component.
00141     */
00142     virtual void SetGeometry (const Geometry &geo);
00143 
00145     /*
00146         Return true if this object can break the layout, meaning, the layout can be done on the composition layout only without
00147         recomputing the whole window layout.
00148     */
00149     virtual bool CanBreakLayout()
00150     {
00151       return false;
00152     }
00153 
00154     virtual void SetTextColor(const Color &color);
00155     virtual Color GetTextColor();
00156 
00158 
00162     virtual Layout* GetLayout();
00163 
00165 
00169     virtual bool SetLayout (Layout *layout);
00170 
00171     sigc::signal<void, View*, Layout*> LayoutAdded;
00172     sigc::signal<void, View*, Layout*> LayoutRemoved;
00173 
00174     void SetFont(ObjectPtr<FontTexture> font);
00175     ObjectPtr<FontTexture> GetFont();
00176 
00177     sigc::signal<void, View*> OnQueueDraw;  
00178 
00179     virtual long ProcessFocusEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo);
00180     virtual void DoSetFocused (bool focused);
00181     virtual bool DoCanFocus ();
00182     virtual bool DoGetFocused ();
00183     void SetCanFocus (bool can_focus);
00184     void SetFocusControl (bool focus_control);
00185     bool HasFocusControl ();
00186 
00187     /*
00188         Returns true if the view has a layout and passes focus to that layout
00189     */
00190     bool HasPassiveFocus ();
00191 
00192   protected:
00193     bool _can_focus;
00194 
00195     void OnChildFocusChanged (Area *parent, Area *child);
00196     sigc::connection _on_focus_changed_handler;
00197 
00198     virtual long ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo) = 0;
00199     virtual void Draw (GraphicsEngine &GfxContext, bool force_draw) = 0;
00200     virtual void DrawContent (GraphicsEngine &GfxContext, bool force_draw);
00201     virtual void PostDraw (GraphicsEngine &GfxContext, bool force_draw);
00202 
00203     void DoMouseDownOutsideArea (int x, int y,unsigned long mousestate, unsigned long keystate);
00204 
00205     void InitializeWidgets();
00206     void InitializeLayout();
00207     void DestroyLayout();
00208 
00209     Color m_TextColor;
00210     ObjectPtr<FontTexture> _font;
00211 
00213     virtual Layout* GetCompositionLayout();
00214 
00216     virtual bool SetCompositionLayout (Layout *layout);
00217 
00218     void RemoveLayout();
00219     void RemoveCompositionLayout();
00220 
00227     bool IsFullRedraw() const;
00228 
00229     virtual void GeometryChangePending ();
00230     virtual void GeometryChanged ();
00231 
00232     Layout *m_CompositionLayout;
00233 
00234     bool _need_redraw; //<! The rendering of the view needs to be refreshed.
00235 
00236     bool _full_redraw; //<! True if Draw is called before ContentDraw. It is read-only and can be accessed by calling IsFullRedraw();
00237 
00238     bool _is_active; 
00239 
00240     bool _can_pass_focus_to_composite_layout; //<! Enable this and keynav will pass focus to your composite layout
00241 
00242   private:
00243     bool m_UseStyleDrawing;
00244     bool _is_view_active;
00245 
00246     friend class WindowCompositor;
00247     friend class Layout;
00248     friend class Area;
00249     friend class LayeredLayout;
00250   };
00251 
00252 }
00253 
00254 #endif // ABSTRACTOBJECTBASE_H