nux-0.9.46

Nux/ScrollView.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 SCROLLVIEW_H
00024 #define SCROLLVIEW_H
00025 
00026 #include "Nux.h"
00027 
00028 
00029 namespace nux
00030 {
00031   class HScrollBar;
00032   class VScrollBar;
00033 
00034 // Rename it to ScrollArea or ScrollWindow
00035   class ScrollView: public View
00036   {
00037     NUX_DECLARE_OBJECT_TYPE(ScrollView, View);
00038   public:
00039     ScrollView (NUX_FILE_LINE_PROTO);
00040     virtual ~ScrollView();
00041 
00042     // API
00043     void EnableVerticalScrollBar (bool b);
00044     void EnableHorizontalScrollBar (bool b);
00045     virtual bool SetLayout (Layout *layout);
00046 
00054     void SetSizeMatchContent (bool b);
00055 
00061     bool IsSizeMatchContent() const;
00062 
00064     virtual void SetGeometry (const Geometry &geo);
00065 
00067     //  EMITERS    //
00069     void OnSizeGrigMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags);
00070     void OnSizeGrigMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
00071     void EmitMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
00072     //void EmitInternalResize(int x, int y, int w, int h);
00073 
00074 
00076     //  RECEIVERS  //
00078     virtual void ScrollLeft (float stepx, int mousedx);
00079     virtual void ScrollRight (float stepx, int mousedx);
00080     virtual void ScrollUp (float stepy, int mousedy);
00081     virtual void ScrollDown (float stepy, int mousedy);
00082 
00083     virtual void ResetScrollToLeft();
00084     virtual void ResetScrollToRight();
00085     virtual void ResetScrollToUp();
00086     virtual void ResetScrollToDown();
00087 
00088     // amount to scroll by for each mouse wheel event
00089     int m_MouseWheelScrollSize;
00090 
00091     // Geometry of the layout that encompass the child layouts.
00093     int m_ViewContentX;
00095     int m_ViewContentY;
00097     int m_ViewContentWidth;
00099     int m_ViewContentHeight;
00100 
00101     //Client View Area
00103     int m_ViewX;
00105     int m_ViewY;
00107     int m_ViewWidth;
00109     int m_ViewHeight;
00110 
00111     Geometry m_ViewGeometry;
00112     Geometry m_ContentGeometry;
00113 
00114     // signals
00115     sigc::signal<void> SigTest;
00116     sigc::signal<void> sigMoveWindow;
00117     sigc::signal<void, int, int, int, int> sigResize;
00118 
00119   public:
00120     void    SetViewContentLeftMargin (int margin)
00121     {
00122       m_ViewContentLeftMargin = margin;
00123     }
00124     int     GetViewContentLeftMargin() const
00125     {
00126       return m_ViewContentLeftMargin;
00127     }
00128     void    SetViewContentRightMargin (int margin)
00129     {
00130       m_ViewContentRightMargin = margin;
00131     }
00132     int     GetViewContentRightMargin() const
00133     {
00134       return m_ViewContentRightMargin;
00135     }
00136     void    SetViewContentTopMargin (int margin)
00137     {
00138       m_ViewContentTopMargin = margin;
00139     }
00140     int     GetViewContentTopMargin() const
00141     {
00142       return m_ViewContentTopMargin;
00143     }
00144     void    SetViewContentBottomMargin (int margin)
00145     {
00146       m_ViewContentBottomMargin = margin;
00147     }
00148     int     GetViewContentBottomMargin() const
00149     {
00150       return m_ViewContentBottomMargin;
00151     }
00152 
00153   protected:
00154 
00155     virtual void Draw (GraphicsEngine &GfxContext, bool force_draw);
00156     virtual void DrawContent (GraphicsEngine &GfxContext, bool force_draw);
00157     virtual void PostDraw (GraphicsEngine &GfxContext, bool force_draw);
00158     virtual long ProcessEvent (Event &event, long TraverseInfo, long ProcessEventInfo);
00159 
00161 
00165     void SetVScrollBar (VScrollBar* newVScrollBar);
00166 
00167     void OnChildFocusChanged (Area *parent, Area *child);
00168 
00169     // Backup texture to speed up scrolling
00170     ObjectPtr<IOpenGLFrameBufferObject> m_FrameBufferObject;
00171 
00172     void SwapTextureIndex()
00173     {
00174       m_TextureIndex = (m_TextureIndex == 0) ? 1 : 0;
00175     }
00176     void SetTextureIndex (int index)
00177     {
00178       m_TextureIndex = index;
00179     }
00180     int GetTextureIndex()
00181     {
00182       return m_TextureIndex;
00183     }
00184     int m_TextureIndex;
00185     bool m_ReformatTexture;
00186 
00187     // ScrollBars
00188     HScrollBar     *hscrollbar;
00189     VScrollBar     *vscrollbar;
00190     bool m_horizontal_scrollbar_enable;
00191     bool m_vertical_scrollbar_enable;
00192 
00193     int m_SizeGripDragPositionX; //<<<--- remove this
00194     int m_SizeGripDragPositionY;
00195 
00196     //int viewx;
00197     // Internal function
00198     int getBorder() const;
00199     int getTopBorder() const;
00200     void setBorder (int border);
00201     void setTopBorder (int top_border);
00202 
00203     int m_top_border;
00204     int m_border;
00205 
00207     int _delta_x;
00208 
00210     int _delta_y;
00211 
00212     void FormatContent ();
00213     virtual void PreLayoutManagement ();
00214     virtual long PostLayoutManagement (long LayoutResult);
00215     virtual void PositionChildLayout (float offsetX, float offsetY);
00216 
00217     virtual long PostLayoutManagement2 (long LayoutResult);
00218 
00219   private:
00224     bool m_bSizeMatchContent;
00225 
00226     int m_ViewContentLeftMargin;
00227     int m_ViewContentRightMargin;
00228     int m_ViewContentTopMargin;
00229     int m_ViewContentBottomMargin;
00230   };
00231 }
00232 
00233 #endif // SCROLLVIEW_H