nux-1.14.0
ScrollView.h
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
00116     sigc::signal<void> SigTest;
00117     sigc::signal<void> sigMoveWindow;
00118     sigc::signal<void, int, int, int, int> sigResize;
00119 
00120   public:
00121     void    SetViewContentLeftMargin (int margin)
00122     {
00123       m_ViewContentLeftMargin = margin;
00124     }
00125     int     GetViewContentLeftMargin() const
00126     {
00127       return m_ViewContentLeftMargin;
00128     }
00129     void    SetViewContentRightMargin (int margin)
00130     {
00131       m_ViewContentRightMargin = margin;
00132     }
00133     int     GetViewContentRightMargin() const
00134     {
00135       return m_ViewContentRightMargin;
00136     }
00137     void    SetViewContentTopMargin (int margin)
00138     {
00139       m_ViewContentTopMargin = margin;
00140     }
00141     int     GetViewContentTopMargin() const
00142     {
00143       return m_ViewContentTopMargin;
00144     }
00145     void    SetViewContentBottomMargin (int margin)
00146     {
00147       m_ViewContentBottomMargin = margin;
00148     }
00149     int     GetViewContentBottomMargin() const
00150     {
00151       return m_ViewContentBottomMargin;
00152     }
00153 
00154   protected:
00155 
00156     virtual void Draw (GraphicsEngine &GfxContext, bool force_draw);
00157     virtual void DrawContent (GraphicsEngine &GfxContext, bool force_draw);
00158     virtual void PostDraw (GraphicsEngine &GfxContext, bool force_draw);
00159     virtual long ProcessEvent (Event &event, long TraverseInfo, long ProcessEventInfo);
00160     virtual Area* FindAreaUnderMouse(const Point& mouse_position, NuxEventType event_type);
00161 
00162     void RecvMouseWheel(int x, int y, int wheel_delta,  long button_flags, unsigned long key_flags);
00163 
00165 
00169     void SetVScrollBar (VScrollBar* newVScrollBar);
00170 
00171     void OnChildFocusChanged (/*Area *parent,*/ Area *child);
00172 
00173     // Backup texture to speed up scrolling
00174     ObjectPtr<IOpenGLFrameBufferObject> m_FrameBufferObject;
00175 
00176     void SwapTextureIndex()
00177     {
00178       m_TextureIndex = (m_TextureIndex == 0) ? 1 : 0;
00179     }
00180     void SetTextureIndex (int index)
00181     {
00182       m_TextureIndex = index;
00183     }
00184     int GetTextureIndex()
00185     {
00186       return m_TextureIndex;
00187     }
00188     int m_TextureIndex;
00189     bool m_ReformatTexture;
00190 
00191     // ScrollBars
00192     HScrollBar     *_hscrollbar;
00193     VScrollBar     *_vscrollbar;
00194     bool m_horizontal_scrollbar_enable;
00195     bool m_vertical_scrollbar_enable;
00196 
00197     int m_top_border;
00198     int m_border;
00199 
00201     int _delta_x;
00202 
00204     int _delta_y;
00205 
00206     void FormatContent ();
00207     virtual void PreLayoutManagement ();
00208     virtual long PostLayoutManagement (long LayoutResult);
00209     virtual void PositionChildLayout (float offsetX, float offsetY);
00210 
00211     virtual long PostLayoutManagement2 (long LayoutResult);
00212 
00213   private:
00214 
00215     virtual bool AcceptKeyNavFocus();
00220     bool m_bSizeMatchContent;
00221 
00222     int m_ViewContentLeftMargin;
00223     int m_ViewContentRightMargin;
00224     int m_ViewContentTopMargin;
00225     int m_ViewContentBottomMargin;
00226   };
00227 }
00228 
00229 #endif // SCROLLVIEW_H
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends