Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r48968 - in sandbox/guigl: boost/guigl/view boost/guigl/view/impl boost/guigl/view/impl/detail libs/guigl/build/xcodeide/guigl.xcodeproj libs/guigl/example libs/guigl/src libs/guigl/src/widget
From: stipe_at_[hidden]
Date: 2008-09-25 15:53:25


Author: srajko
Date: 2008-09-25 15:53:24 EDT (Thu, 25 Sep 2008)
New Revision: 48968
URL: http://svn.boost.org/trac/boost/changeset/48968

Log:
compound uses static_compound, added mouse_button_focus_child
Added:
   sandbox/guigl/boost/guigl/view/impl/detail/
   sandbox/guigl/boost/guigl/view/impl/detail/algorithm.hpp (contents, props changed)
   sandbox/guigl/boost/guigl/view/impl/detail/compound_event_processing.hpp (contents, props changed)
Text files modified:
   sandbox/guigl/boost/guigl/view/compound.hpp | 27 ++++-----------------
   sandbox/guigl/boost/guigl/view/draggable.hpp | 2 +
   sandbox/guigl/boost/guigl/view/impl/compound.hpp | 9 ++++---
   sandbox/guigl/boost/guigl/view/impl/draggable.hpp | 12 ++++++---
   sandbox/guigl/boost/guigl/view/impl/mouse_tracking.hpp | 11 ++++----
   sandbox/guigl/boost/guigl/view/impl/static_compound.hpp | 50 +++++++++++++++++++++++----------------
   sandbox/guigl/boost/guigl/view/mouse_tracking.hpp | 10 ++++++-
   sandbox/guigl/boost/guigl/view/static_compound.hpp | 11 ++++----
   sandbox/guigl/libs/guigl/build/xcodeide/guigl.xcodeproj/project.pbxproj | 12 +++++++++
   sandbox/guigl/libs/guigl/example/two_buttons.cpp | 1
   sandbox/guigl/libs/guigl/src/widget/slider.cpp | 2 +
   sandbox/guigl/libs/guigl/src/window.cpp | 6 ----
   12 files changed, 84 insertions(+), 69 deletions(-)

Modified: sandbox/guigl/boost/guigl/view/compound.hpp
==============================================================================
--- sandbox/guigl/boost/guigl/view/compound.hpp (original)
+++ sandbox/guigl/boost/guigl/view/compound.hpp 2008-09-25 15:53:24 EDT (Thu, 25 Sep 2008)
@@ -10,7 +10,7 @@
 #define BOOST__GUIGL__VIEW__COMPOUND_HPP
 
 
-#include <boost/guigl/view/positioned.hpp>
+#include <boost/guigl/view/static_compound.hpp>
 #include <boost/ptr_container/ptr_vector.hpp>
 
 namespace boost { namespace guigl { namespace view {
@@ -22,40 +22,23 @@
 }
 
 template<typename BaseView=base>
-class compound : public BaseView
+class compound : public static_compound<ptr_vector<positioned<> >, BaseView>
 {
 public:
- typedef BaseView base_type;
+ typedef static_compound<ptr_vector<positioned<> >, BaseView> base_type;
 
     template<typename ArgumentPack>
     compound(const ArgumentPack &args)
- : base_type(args)
- , m_mouse_focus_child(0)
+ : base_type(( args, _children=0 ))
     {}
     
     compound & operator << (positioned<> *v)
     {
- m_children.push_back(v);
+ base_type::m_children.push_back(v);
         access::set_parent(*v, *this);
         return *this;
     }
-
- bool on_event(const event_type &event_info);
-
- const ptr_vector<positioned<> > &children() const
- { return m_children; }
-
-protected:
- void draw_prologue();
-
- ptr_vector<positioned<> > &children()
- { return m_children; }
-
-private:
- ptr_vector<positioned<> > m_children;
- positioned<> * m_mouse_focus_child;
 
- friend class detail::compound_event_visitor<BaseView>;
 };
 
 }}}

Modified: sandbox/guigl/boost/guigl/view/draggable.hpp
==============================================================================
--- sandbox/guigl/boost/guigl/view/draggable.hpp (original)
+++ sandbox/guigl/boost/guigl/view/draggable.hpp 2008-09-25 15:53:24 EDT (Thu, 25 Sep 2008)
@@ -34,6 +34,7 @@
     template<typename ArgumentPack>
     draggable(const ArgumentPack &args)
         : base_type(args)
+ , m_dragging(false)
     {}
 
 protected:
@@ -56,6 +57,7 @@
     friend struct detail::draggable_static_visitor<Derived,BaseView>;
     
     position_type m_drag_origin;
+ bool m_dragging;
 };
 
 }}}

Modified: sandbox/guigl/boost/guigl/view/impl/compound.hpp
==============================================================================
--- sandbox/guigl/boost/guigl/view/impl/compound.hpp (original)
+++ sandbox/guigl/boost/guigl/view/impl/compound.hpp 2008-09-25 15:53:24 EDT (Thu, 25 Sep 2008)
@@ -10,10 +10,11 @@
 #define BOOST__GUIGL__VIEW__IMPL__COMPOUND_HPP
 
 
-#include <boost/guigl/access.hpp>
+/*#include <boost/guigl/access.hpp>
 #include <boost/guigl/event.hpp>
-#include <boost/guigl/view/compound.hpp>
-
+#include <boost/guigl/view/compound.hpp>*/
+#include <boost/guigl/view/impl/static_compound.hpp>
+/*
 #include <iostream>
 
 namespace boost { namespace guigl { namespace view {
@@ -135,6 +136,6 @@
         return boost::apply_visitor( detail::compound_event_visitor<BaseView>(*this, event_info), event_info);
 }
 
-}}}
+}}}*/
 
 #endif // BOOST__GUIGL__VIEW__IMPL__COMPOUND_HPP
\ No newline at end of file

Added: sandbox/guigl/boost/guigl/view/impl/detail/algorithm.hpp
==============================================================================
--- (empty file)
+++ sandbox/guigl/boost/guigl/view/impl/detail/algorithm.hpp 2008-09-25 15:53:24 EDT (Thu, 25 Sep 2008)
@@ -0,0 +1,60 @@
+/*=================================---------------------------------------------
+ Copyright 2008 Stjepan Rajko
+
+ Distributed under the Boost Software License, Version 1.0.
+ (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt)
+-----------------------------------------------===============================*/
+
+#ifndef BOOST__GUIGL__VIEW__IMPL__DETAIL__ALGORITHM_HPP
+#define BOOST__GUIGL__VIEW__IMPL__DETAIL__ALGORITHM_HPP
+
+
+#include <boost/bind.hpp>
+#include <boost/bind/placeholders.hpp>
+#include <boost/fusion/include/is_sequence.hpp>
+#include <boost/fusion/include/for_each.hpp>
+#include <boost/fusion/include/accumulate.hpp>
+#include <boost/utility/enable_if.hpp>
+
+//#include <boost/range/algorithm.hpp>
+#include <algorithm>
+#include <numeric>
+
+namespace boost { namespace guigl { namespace view {
+
+namespace detail {
+
+ template<typename Sequence, typename F>
+ typename boost::enable_if<fusion::traits::is_sequence<Sequence> >::type
+ for_each(Sequence &sequence, const F&f)
+ {
+ fusion::for_each(sequence, f);
+ }
+
+ template<typename Sequence, typename F>
+ typename boost::disable_if<fusion::traits::is_sequence<Sequence> >::type
+ for_each(Sequence &sequence, const F&f)
+ {
+ std::for_each(sequence.begin(), sequence.end(), f);
+ }
+
+ template<typename Sequence, typename Init, typename F>
+ typename boost::enable_if<fusion::traits::is_sequence<Sequence>, Init >::type
+ accumulate(Sequence &sequence, const Init &init, const F&f)
+ {
+ return fusion::accumulate(sequence, init, f);
+ }
+
+ template<typename Sequence, typename Init, typename F>
+ typename boost::disable_if<fusion::traits::is_sequence<Sequence>, Init >::type
+ accumulate(Sequence &sequence, const Init &init, const F&f)
+ {
+ return std::accumulate(sequence.begin(), sequence.end(), init, boost::bind(f,_2,_1));
+ }
+
+}
+
+}}}
+
+#endif // BOOST__GUIGL__VIEW__IMPL__DETAIL__COMPOUND_EVENT_PROCESSING_HPP
\ No newline at end of file

Added: sandbox/guigl/boost/guigl/view/impl/detail/compound_event_processing.hpp
==============================================================================
--- (empty file)
+++ sandbox/guigl/boost/guigl/view/impl/detail/compound_event_processing.hpp 2008-09-25 15:53:24 EDT (Thu, 25 Sep 2008)
@@ -0,0 +1,32 @@
+/*=================================---------------------------------------------
+ Copyright 2008 Stjepan Rajko
+
+ Distributed under the Boost Software License, Version 1.0.
+ (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt)
+-----------------------------------------------===============================*/
+
+#ifndef BOOST__GUIGL__VIEW__IMPL__DETAIL__COMPOUND_EVENT_PROCESSING_HPP
+#define BOOST__GUIGL__VIEW__IMPL__DETAIL__COMPOUND_EVENT_PROCESSING_HPP
+
+
+
+namespace boost { namespace guigl { namespace view {
+
+namespace detail {
+
+ template<typename StaticCompound>
+ struct draw
+ {
+ template<typename View>
+ void operator()(View &view) const
+ {
+ StaticCompound::draw(view);
+ }
+ };
+
+}
+
+}}}
+
+#endif // BOOST__GUIGL__VIEW__IMPL__DETAIL__COMPOUND_EVENT_PROCESSING_HPP
\ No newline at end of file

Modified: sandbox/guigl/boost/guigl/view/impl/draggable.hpp
==============================================================================
--- sandbox/guigl/boost/guigl/view/impl/draggable.hpp (original)
+++ sandbox/guigl/boost/guigl/view/impl/draggable.hpp 2008-09-25 15:53:24 EDT (Thu, 25 Sep 2008)
@@ -39,17 +39,21 @@
         {
             if(event_info.direction == direction::down)
             {
- m_draggable.m_drag_origin = m_draggable.mouse_state().get().position;
- m_draggable.call_draggable_on_drag(m_draggable.mouse_state().get().position);
+ m_draggable.m_drag_origin = m_draggable.mouse_state().position;
+ m_draggable.m_dragging = true;
+ m_draggable.call_draggable_on_drag(m_draggable.mouse_state().position);
             }
             else
- m_draggable.call_draggable_on_end_drag(m_draggable.mouse_state().get().position);
+ {
+ m_draggable.call_draggable_on_end_drag(m_draggable.mouse_state().position);
+ m_draggable.m_dragging = false;
+ }
             return true;
         }
         
         bool operator()(const movement_event &event_info) const
         {
- if(m_draggable.mouse_state().get().button_down)
+ if(m_draggable.m_dragging)
                 m_draggable.call_draggable_on_drag(event_info.position);
             return true;
         }

Modified: sandbox/guigl/boost/guigl/view/impl/mouse_tracking.hpp
==============================================================================
--- sandbox/guigl/boost/guigl/view/impl/mouse_tracking.hpp (original)
+++ sandbox/guigl/boost/guigl/view/impl/mouse_tracking.hpp 2008-09-25 15:53:24 EDT (Thu, 25 Sep 2008)
@@ -34,7 +34,7 @@
         static bool is_down(mouse_tracking<BaseView> &view)
         {
             const widget::window *window = dynamic_cast<const widget::window *> (view.root());
- return window->mouse_state() ? window->mouse_state().get().button_down : false;
+ return window->mouse_state().button_down;
         }
     };
 
@@ -57,24 +57,23 @@
 
         bool operator()(const movement_event &event_info) const
         {
- m_mouse_tracking.m_mouse_state.get().position = event_info.position;
+ m_mouse_tracking.m_mouse_state.position = event_info.position;
             return false;
         }
 
         bool operator()(const button_event &event_info) const
         {
- m_mouse_tracking.m_mouse_state.get().button_down = (event_info.direction == direction::down);
+ m_mouse_tracking.m_mouse_state.button_down = (event_info.direction == direction::down);
             return false;
         }
         
         bool operator()(const entry_exit_event &event_info) const
         {
             if(event_info.region == region::exit)
- m_mouse_tracking.m_mouse_state = none_t();
+ m_mouse_tracking.m_mouse_state.inside = false;
             else
             {
- m_mouse_tracking.m_mouse_state = mouse_state();
- m_mouse_tracking.m_mouse_state.get().button_down = get_button_state<BaseView>::is_down(m_mouse_tracking);
+ m_mouse_tracking.m_mouse_state.button_down = get_button_state<BaseView>::is_down(m_mouse_tracking);
             }
             return false;
         }

Modified: sandbox/guigl/boost/guigl/view/impl/static_compound.hpp
==============================================================================
--- sandbox/guigl/boost/guigl/view/impl/static_compound.hpp (original)
+++ sandbox/guigl/boost/guigl/view/impl/static_compound.hpp 2008-09-25 15:53:24 EDT (Thu, 25 Sep 2008)
@@ -13,32 +13,18 @@
 #include <boost/guigl/access.hpp>
 #include <boost/guigl/event.hpp>
 #include <boost/guigl/view/static_compound.hpp>
+#include <boost/guigl/view/impl/detail/compound_event_processing.hpp>
 
 #include <boost/fusion/include/accumulate.hpp>
-#include <boost/fusion/include/for_each.hpp>
 
 
 namespace boost { namespace guigl { namespace view {
 
-namespace detail {
-
- template<typename StaticCompound>
- struct draw
- {
- template<typename View>
- void operator()(View &view) const
- {
- StaticCompound::draw(view);
- }
- };
-
-}
-
 template<typename ChildrenSequence, typename BaseView>
 inline void static_compound<ChildrenSequence, BaseView>::draw_prologue()
 {
     BaseView::draw_prologue();
- fusion::for_each(m_children, detail::draw<static_compound>());
+ detail::for_each(m_children, detail::draw<static_compound>());
 }
 
 
@@ -77,7 +63,11 @@
         button_event translated_event_info(event_info);
         translated_event_info.position -= child_view.position();
         if(visitor.on_event(child_view, translated_event_info))
+ {
+ if(event_info.direction == direction::down)
+ visitor.set_button_focus(child_view);
             return true;
+ }
         return false;
     }
     
@@ -99,6 +89,10 @@
     {
         if(handled)
             return true;
+
+ movement_event translated_event_info(event_info);
+ translated_event_info.position -= child_view.position();
+
         if(!inside(event_info.position, child_view))
         {
             if(&child_view == visitor.mouse_focus_child())
@@ -107,6 +101,8 @@
                 visitor.no_mouse_focus();
                 visitor.on_event(child_view, entry_exit_event(region::exit));
             }
+ if(&child_view == visitor.button_focus_child())
+ visitor.on_event(child_view, translated_event_info);
             return false;
         }
         else
@@ -114,8 +110,6 @@
             visitor.set_mouse_focus(child_view);
             // only the mouse focus child gets movement events
             // forward the movement event
- movement_event translated_event_info(event_info);
- translated_event_info.position -= child_view.position();
             visitor.on_event(child_view, translated_event_info);
             return true;
         }
@@ -162,15 +156,29 @@
             access::on_event(*view.m_mouse_focus_child, entry_exit_event(region::entry));
         }
     }
-
+ positioned<> *button_focus_child() const
+ {
+ return view.m_button_focus_child;
+ }
+ void set_button_focus(positioned<> &child) const
+ {
+ view.m_button_focus_child = &child;
+ }
     bool operator()(const button_event &event_info) const
     {
- return boost::fusion::accumulate(view.children(), false, propagate_button_event<static_compound_event_visitor>(*this, event_info));
+ if(view.m_button_focus_child && event_info.direction == direction::up)
+ {
+ button_event translated_event_info(event_info);
+ translated_event_info.position -= view.m_button_focus_child->position();
+
+ access::on_event(*view.m_button_focus_child, translated_event_info);
+ }
+ return detail::accumulate(view.children(), false, propagate_button_event<static_compound_event_visitor>(*this, event_info));
     }
     
     bool operator()(const movement_event &event_info) const
     {
- boost::fusion::accumulate(view.children(), false, propagate_movement_event<static_compound_event_visitor>(*this, event_info));
+ detail::accumulate(view.children(), false, propagate_movement_event<static_compound_event_visitor>(*this, event_info));
         return true;
     }
 

Modified: sandbox/guigl/boost/guigl/view/mouse_tracking.hpp
==============================================================================
--- sandbox/guigl/boost/guigl/view/mouse_tracking.hpp (original)
+++ sandbox/guigl/boost/guigl/view/mouse_tracking.hpp 2008-09-25 15:53:24 EDT (Thu, 25 Sep 2008)
@@ -15,6 +15,12 @@
 
 struct mouse_state
 {
+ mouse_state()
+ : inside(false)
+ , position(0,0)
+ , button_down(false)
+ {}
+ bool inside;
     position_type position;
     bool button_down;
 };
@@ -38,14 +44,14 @@
         : base_type(args)
     {}
 
- const boost::optional<guigl::mouse_state> &mouse_state() const
+ const guigl::mouse_state &mouse_state() const
     { return m_mouse_state; }
 
 protected:
     bool on_event(const event_type &event_info);
 
 private:
- boost::optional<guigl::mouse_state> m_mouse_state;
+ guigl::mouse_state m_mouse_state;
 
     friend struct detail::mouse_tracking_static_visitor<BaseView>;
 };

Modified: sandbox/guigl/boost/guigl/view/static_compound.hpp
==============================================================================
--- sandbox/guigl/boost/guigl/view/static_compound.hpp (original)
+++ sandbox/guigl/boost/guigl/view/static_compound.hpp 2008-09-25 15:53:24 EDT (Thu, 25 Sep 2008)
@@ -11,7 +11,7 @@
 
 
 #include <boost/guigl/view/positioned.hpp>
-#include <boost/fusion/include/for_each.hpp>
+#include <boost/guigl/view/impl/detail/algorithm.hpp>
 
 namespace boost { namespace guigl { namespace view {
 
@@ -49,9 +49,10 @@
     static_compound(const ArgumentPack &args)
         : base_type(args)
         , m_children(args[_children])
- , m_mouse_focus_child(0)
+ , m_mouse_focus_child(0)
+ , m_button_focus_child(0)
     {
- fusion::for_each(m_children, detail::set_parent<static_compound>(*this));
+ detail::for_each(m_children, detail::set_parent<static_compound>(*this));
     }
     
     bool on_event(const event_type &event_info);
@@ -65,9 +66,9 @@
     ChildrenSequence &children()
     { return m_children; }
 
-private:
     ChildrenSequence m_children;
- positioned<> * m_mouse_focus_child;
+private:
+ positioned<> *m_mouse_focus_child, *m_button_focus_child;
 
     template<typename View>
     static void draw(View &view)

Modified: sandbox/guigl/libs/guigl/build/xcodeide/guigl.xcodeproj/project.pbxproj
==============================================================================
--- sandbox/guigl/libs/guigl/build/xcodeide/guigl.xcodeproj/project.pbxproj (original)
+++ sandbox/guigl/libs/guigl/build/xcodeide/guigl.xcodeproj/project.pbxproj 2008-09-25 15:53:24 EDT (Thu, 25 Sep 2008)
@@ -130,6 +130,8 @@
                 0897912F0E5DBB0F00C79062 /* labeled_button.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = labeled_button.hpp; sourceTree = "<group>"; };
                 0897913B0E5DBC1000C79062 /* glut.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = glut.hpp; sourceTree = "<group>"; };
                 089791BA0E5DC06400C79062 /* event.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = event.hpp; sourceTree = "<group>"; };
+ 0898B3AE0E83CC85004F3E91 /* compound_event_processing.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = compound_event_processing.hpp; sourceTree = "<group>"; };
+ 0898B3D90E83D2DD004F3E91 /* algorithm.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = algorithm.hpp; sourceTree = "<group>"; };
                 089926680E7865B500285958 /* compound.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = compound.hpp; sourceTree = "<group>"; };
                 0899266B0E78664900285958 /* compound.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = compound.cpp; sourceTree = "<group>"; };
                 08998DDF0E528C1F00F583A2 /* window.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = window.hpp; sourceTree = "<group>"; };
@@ -258,6 +260,7 @@
                 08978EC60E5DA49D00C79062 /* impl */ = {
                         isa = PBXGroup;
                         children = (
+ 0898B3AD0E83CC75004F3E91 /* detail */,
                                 08978EC80E5DA4CD00C79062 /* positioned.hpp */,
                                 08978ECC0E5DA55800C79062 /* compound.hpp */,
                                 08978ECF0E5DA5B100C79062 /* solid_background.hpp */,
@@ -287,6 +290,15 @@
                         path = view;
                         sourceTree = "<group>";
                 };
+ 0898B3AD0E83CC75004F3E91 /* detail */ = {
+ isa = PBXGroup;
+ children = (
+ 0898B3AE0E83CC85004F3E91 /* compound_event_processing.hpp */,
+ 0898B3D90E83D2DD004F3E91 /* algorithm.hpp */,
+ );
+ path = detail;
+ sourceTree = "<group>";
+ };
                 089E06FA0E5D0F2A00C425FE /* widget */ = {
                         isa = PBXGroup;
                         children = (

Modified: sandbox/guigl/libs/guigl/example/two_buttons.cpp
==============================================================================
--- sandbox/guigl/libs/guigl/example/two_buttons.cpp (original)
+++ sandbox/guigl/libs/guigl/example/two_buttons.cpp 2008-09-25 15:53:24 EDT (Thu, 25 Sep 2008)
@@ -9,6 +9,7 @@
 
 #include "two_buttons.hpp"
 #include <boost/guigl/view/impl/static_compound.hpp>
+#include <boost/guigl/view/impl/positioned.hpp>
 
 
 void two_buttons::draw()

Modified: sandbox/guigl/libs/guigl/src/widget/slider.cpp
==============================================================================
--- sandbox/guigl/libs/guigl/src/widget/slider.cpp (original)
+++ sandbox/guigl/libs/guigl/src/widget/slider.cpp 2008-09-25 15:53:24 EDT (Thu, 25 Sep 2008)
@@ -38,6 +38,8 @@
     if(m_step!=0.0)
         new_value = round(new_value / m_step) * m_step;
     new_value += m_min;
+ new_value = (std::max)(m_min, new_value);
+ new_value = (std::min)(m_max, new_value);
     set_value(new_value);
 }
 

Modified: sandbox/guigl/libs/guigl/src/window.cpp
==============================================================================
--- sandbox/guigl/libs/guigl/src/window.cpp (original)
+++ sandbox/guigl/libs/guigl/src/window.cpp 2008-09-25 15:53:24 EDT (Thu, 25 Sep 2008)
@@ -78,9 +78,7 @@
     }
     void mouse(int button, int state, int x, int y)
     {
- if (!m_window->mouse_state())
- return;
-
+ movement(x,y);
         button_event event_info;
         switch(button)
         {
@@ -103,8 +101,6 @@
     }
     void movement(int x, int y)
     {
- if (!m_window->mouse_state())
- return;
         movement_event event_info;
         event_info.position = position_type(x, y);
         m_window->on_event(event_info);


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk