Back to index

nux  3.0.0
ScrollView.h
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright 2010-2011 Inalogic® Inc.
00004  *
00005  * This program is free software: you can redistribute it and/or modify it
00006  * under the terms of the GNU Lesser General Public License, as
00007  * published by the  Free Software Foundation; either version 2.1 or 3.0
00008  * of the License.
00009  *
00010  * This program is distributed in the hope that it will be useful, but
00011  * WITHOUT ANY WARRANTY; without even the implied warranties of
00012  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00013  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00014  * License for more details.
00015  *
00016  * You should have received a copy of both the GNU Lesser General Public
00017  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00018  *
00019  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00020  *
00021  */
00022 
00023 
00024 #ifndef SCROLLVIEW_H
00025 #define SCROLLVIEW_H
00026 
00027 #include "Nux.h"
00028 #include "View.h"
00029 
00030 namespace nux
00031 {
00032   class HScrollBar;
00033   class VScrollBar;
00034 
00035 // Rename it to ScrollArea or ScrollWindow
00036   class ScrollView: public View
00037   {
00038     NUX_DECLARE_OBJECT_TYPE(ScrollView, View);
00039   public:
00040     ScrollView(NUX_FILE_LINE_PROTO);
00041     virtual ~ScrollView();
00042 
00043     // API
00044     void EnableVerticalScrollBar(bool b);
00045     void EnableHorizontalScrollBar(bool b);
00046     virtual bool SetLayout(Layout *layout);
00047 
00055     void SetSizeMatchContent(bool b);
00056 
00062     bool IsSizeMatchContent() const;
00063 
00065     virtual void SetGeometry(const Geometry &geo);
00066 
00068     //  EMITERS    //
00070     void OnSizeGrigMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags);
00071     void OnSizeGrigMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
00072     void EmitMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
00073     //void EmitInternalResize(int x, int y, int w, int h);
00074 
00075 
00077     //  RECEIVERS  //
00079     virtual void ScrollLeft(float stepx, int mousedx);
00080     virtual void ScrollRight(float stepx, int mousedx);
00081     virtual void ScrollUp(float stepy, int mousedy);
00082     virtual void ScrollDown(float stepy, int mousedy);
00083 
00084     virtual void ResetScrollToLeft();
00085     virtual void ResetScrollToRight();
00086     virtual void ResetScrollToUp();
00087     virtual void ResetScrollToDown();
00088 
00089     // amount to scroll by for each mouse wheel event
00090     int m_MouseWheelScrollSize;
00091 
00092     // Geometry of the layout that encompass the child layouts.
00094     int m_ViewContentX;
00096     int m_ViewContentY;
00098     int m_ViewContentWidth;
00100     int m_ViewContentHeight;
00101 
00102     //Client View Area
00104     int m_ViewX;
00106     int m_ViewY;
00108     int m_ViewWidth;
00110     int m_ViewHeight;
00111 
00112     Geometry m_ViewGeometry;
00113     Geometry m_ContentGeometry;
00114 
00115     // signals
00122     sigc::signal<void, int, int> scrolling;
00123 
00124   public:
00125     void    SetViewContentLeftMargin(int margin)
00126     {
00127       m_ViewContentLeftMargin = margin;
00128     }
00129     int     GetViewContentLeftMargin() const
00130     {
00131       return m_ViewContentLeftMargin;
00132     }
00133     void    SetViewContentRightMargin(int margin)
00134     {
00135       m_ViewContentRightMargin = margin;
00136     }
00137     int     GetViewContentRightMargin() const
00138     {
00139       return m_ViewContentRightMargin;
00140     }
00141     void    SetViewContentTopMargin(int margin)
00142     {
00143       m_ViewContentTopMargin = margin;
00144     }
00145     int     GetViewContentTopMargin() const
00146     {
00147       return m_ViewContentTopMargin;
00148     }
00149     void    SetViewContentBottomMargin(int margin)
00150     {
00151       m_ViewContentBottomMargin = margin;
00152     }
00153     int     GetViewContentBottomMargin() const
00154     {
00155       return m_ViewContentBottomMargin;
00156     }
00157 
00158   protected:
00159 
00160     virtual void Draw(GraphicsEngine &graphics_engine, bool force_draw);
00161     virtual void DrawContent(GraphicsEngine &graphics_engine, bool force_draw);
00162     virtual void PostDraw(GraphicsEngine &graphics_engine, bool force_draw);
00163     virtual Area* FindAreaUnderMouse(const Point& mouse_position, NuxEventType event_type);
00164 
00165     void RecvMouseWheel(int x, int y, int wheel_delta,  long button_flags, unsigned long key_flags);
00166     void OnChildFocusChanged(Area *child);
00167 
00169 
00173     void SetVScrollBar(VScrollBar* newVScrollBar);
00174 
00175     // Backup texture to speed up scrolling
00176     ObjectPtr<IOpenGLFrameBufferObject> m_FrameBufferObject;
00177 
00178     void SwapTextureIndex()
00179     {
00180       m_TextureIndex = (m_TextureIndex == 0) ? 1 : 0;
00181     }
00182     void SetTextureIndex(int index)
00183     {
00184       m_TextureIndex = index;
00185     }
00186     int GetTextureIndex()
00187     {
00188       return m_TextureIndex;
00189     }
00190     int m_TextureIndex;
00191     bool m_ReformatTexture;
00192 
00193     // ScrollBars
00194     HScrollBar     *_hscrollbar;
00195     VScrollBar     *_vscrollbar;
00196     bool m_horizontal_scrollbar_enable;
00197     bool m_vertical_scrollbar_enable;
00198 
00199     int m_top_border;
00200     int m_border;
00201 
00203     int _delta_x;
00204 
00206     int _delta_y;
00207 
00208     void FormatContent();
00209     virtual void PreLayoutManagement();
00210     virtual long PostLayoutManagement(long LayoutResult);
00211     virtual void ComputeContentPosition(float offsetX, float offsetY);
00212 
00213     virtual long PostLayoutManagement2(long LayoutResult);
00214 
00215   private:
00216 
00217     virtual bool AcceptKeyNavFocus();
00222     bool m_bSizeMatchContent;
00223 
00224     int m_ViewContentLeftMargin;
00225     int m_ViewContentRightMargin;
00226     int m_ViewContentTopMargin;
00227     int m_ViewContentBottomMargin;
00228   };
00229 }
00230 
00231 #endif // SCROLLVIEW_H