~unity-team/nux/texture-atlas

« back to all changes in this revision

Viewing changes to Nux/KineticScrollView.h

  • Committer: Nicolas d'Offay
  • Date: 2012-11-16 18:23:48 UTC
  • mfrom: (682.2.25 trunk)
  • Revision ID: nicolas.doffay@canonical.com-20121116182348-ygq13lkwgbugen04
Additional work to get the texture atlas class running as a normal texture.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2012 - Canonical Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU Lesser General Public License, as
 
6
 * published by the  Free Software Foundation; either version 2.1 or 3.0
 
7
 * of the License.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful, but
 
10
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
11
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
 
12
 * PURPOSE.  See the applicable version of the GNU Lesser General Public
 
13
 * License for more details.
 
14
 *
 
15
 * You should have received a copy of both the GNU Lesser General Public
 
16
 * License along with this program. If not, see <http://www.gnu.org/licenses/>
 
17
 *
 
18
 * Authored by: Daniel d'Andrada <daniel.dandrada@canonical.com>
 
19
 */
 
20
 
 
21
#ifndef NUX_KINETIC_SCROLL_VIEW_H
 
22
#define NUX_KINETIC_SCROLL_VIEW_H
 
23
 
 
24
#include <Nux/View.h>
 
25
#include <Nux/KineticScrolling/KineticScroller.h>
 
26
#include <Nux/KineticScrolling/KineticScrollingEnums.h>
 
27
 
 
28
namespace nux
 
29
{
 
30
 
 
31
/*
 
32
  Used to scroll content that is bigger than the available space to display it.
 
33
 
 
34
  Unlike ScrollView, where scroll bars are used to move the content, here you directly
 
35
  drag the content with a mouse pointer or finger (in case of a touchscreen).
 
36
 
 
37
  Items inside a KineticScrollView should properly handle events of type
 
38
  EVENT_MOUSE_CANCEL. If an item inside a kinetic scroll view is pressed, it gets
 
39
  a EVENT_MOUSE_DOWN as usual. But if the user starts dragging it (instead of
 
40
  releasing it to generete a "click"), the KineticScrollView will get ownership of the
 
41
  mouse and that item will receive an EVENT_MOUSE_CANCEL signalling that it no
 
42
  longer has the mouse and won't get any further events from it. The mouse will
 
43
  then be used for scrolling or flicking the KineticScrollView contents until it's
 
44
  released.
 
45
 
 
46
  Usage example:
 
47
 
 
48
  VLayout *layout = new Layout;
 
49
  for (...)
 
50
  {
 
51
    ...
 
52
    layout->AddView(item ...);
 
53
  }
 
54
  KineticScrollView *kinetic_scroll_view = new KineticScrollView;
 
55
  kinetic_scroll_view->SetLayout(layout);
 
56
 
 
57
 */
 
58
class KineticScrollView : public View
 
59
{
 
60
  NUX_DECLARE_OBJECT_TYPE(KineticScrollView, View);
 
61
 public:
 
62
  KineticScrollView(NUX_FILE_LINE_PROTO);
 
63
  virtual ~KineticScrollView();
 
64
 
 
65
  void SetScrollableDirections(ScrollableDirections scrollable_directions);
 
66
 
 
67
  /*!
 
68
    Defines what happens when the viewport is about to go beyond content boundaries
 
69
 
 
70
    The default value is DragAndOvershootBounds.
 
71
   */
 
72
  void SetBoundsBehavior(BoundsBehavior bounds_behavior);
 
73
 
 
74
  /* Reimplemented */
 
75
  virtual bool ChildMouseEvent(const Event& event);
 
76
 
 
77
 protected:
 
78
  virtual void Draw(GraphicsEngine &graphics_engine, bool force_draw);
 
79
  virtual void DrawContent(GraphicsEngine &graphics_engine, bool force_draw);
 
80
  virtual long PostLayoutManagement(long LayoutResult);
 
81
  virtual void PostResizeGeometry();
 
82
 
 
83
 private:
 
84
  void OnMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags);
 
85
  void OnMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags);
 
86
  void OnMouseDrag(int x, int y, int dx, int dy,
 
87
                   unsigned long button_flags, unsigned long key_flags);
 
88
  void SetLayoutTranslation(int x, int y);
 
89
 
 
90
  KineticScroller scroller_;
 
91
 
 
92
  /* Variables used to process events from ChildMouseEven() */
 
93
  bool mouse_pressed_on_child_;
 
94
  int last_child_mouse_position_x_;
 
95
  int last_child_mouse_position_y_;
 
96
};
 
97
 
 
98
} // namespace nux
 
99
 
 
100
#endif // NUX_KINETIC_SCROLL_VIEW_H