$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r51968 - in sandbox-branches/andreo/guigl: . boost/guigl boost/guigl/view libs/guigl/build/vc8ide libs/guigl/example
From: andreytorba_at_[hidden]
Date: 2009-03-25 10:01:19
Author: andreo
Date: 2009-03-25 10:01:17 EDT (Wed, 25 Mar 2009)
New Revision: 51968
URL: http://svn.boost.org/trac/boost/changeset/51968
Log:
added GL_BLEND mode into base view by default
added experimental special points and special segment to base view
added experimental ggl support (https://svn.boost.org/svn/boost/sandbox/ggl)
added ggl.cpp example
Added:
   sandbox-branches/andreo/guigl/boost/guigl/ggl.hpp   (contents, props changed)
   sandbox-branches/andreo/guigl/libs/guigl/example/ggl.cpp   (contents, props changed)
Text files modified: 
   sandbox-branches/andreo/guigl/Jamroot                                |     5 ++                                      
   sandbox-branches/andreo/guigl/boost/guigl/types.hpp                  |     2 +                                       
   sandbox-branches/andreo/guigl/boost/guigl/view/base.hpp              |    74 +++++++++++++++++++++++++++++++++++++-- 
   sandbox-branches/andreo/guigl/libs/guigl/build/vc8ide/build.vcproj   |     4 ++                                      
   sandbox-branches/andreo/guigl/libs/guigl/build/vc8ide/example.vcproj |     4 ++                                      
   sandbox-branches/andreo/guigl/libs/guigl/example/Jamfile             |     3 +                                       
   sandbox-branches/andreo/guigl/libs/guigl/example/sexy_button.cpp     |     6 +-                                      
   7 files changed, 88 insertions(+), 10 deletions(-)
Modified: sandbox-branches/andreo/guigl/Jamroot
==============================================================================
--- sandbox-branches/andreo/guigl/Jamroot	(original)
+++ sandbox-branches/andreo/guigl/Jamroot	2009-03-25 10:01:17 EDT (Wed, 25 Mar 2009)
@@ -16,6 +16,7 @@
 
 # record the root of the datalow directory structure
 path-constant TOP : . ;
+path-constant GGL : ../ggl ;	# ggl path (https://svn.boost.org/svn/boost/sandbox/ggl)
 
 # we are using Boost
 use-project boost : $(BOOST_ROOT) ;
@@ -29,7 +30,9 @@
    : usage-requirements
         <include>.
         <include>$(BOOST_ROOT)
-    : requirements
+   : requirements
         <include>.
         <include>$(BOOST_ROOT)
+        <include>$(GGL)
+        <include>$(GGL)/boost/ggl
    ;
\ No newline at end of file
Added: sandbox-branches/andreo/guigl/boost/guigl/ggl.hpp
==============================================================================
--- (empty file)
+++ sandbox-branches/andreo/guigl/boost/guigl/ggl.hpp	2009-03-25 10:01:17 EDT (Wed, 25 Mar 2009)
@@ -0,0 +1,372 @@
+/*=================================---------------------------------------------
+Copyright 2009 Andrey Torba
+
+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__GGL_HPP
+#define BOOST__GUIGL__GGL_HPP
+
+#include <boost/guigl/gl.hpp>
+#include <boost/guigl/types.hpp>
+#include <boost/ggl/geometry/geometry.hpp>
+#include <boost/ggl/geometry/geometries/register/register_point.hpp>
+#include <boost/static_assert.hpp>
+
+// i don't know why but GEOMETRY_REGISTER_POINT_2D needs type to be without '::'
+typedef boost::guigl::position_type boost__guigl__position_type;
+GEOMETRY_REGISTER_POINT_2D( boost__guigl__position_type, double, geometry::cs::cartesian, operator[](0), operator[](1) );
+
+// GGL doesn't have a GEOMETRY_REGISTER_SEGMENT_2D macro
+namespace geometry { namespace traits {
+
+  // tag trait
+  template<>
+  struct tag<boost::guigl::segment_type>
+    {
+    typedef
+      geometry::segment_tag
+      type;
+    };
+
+  // point_type trait
+  template<>
+  struct point_type<boost::guigl::segment_type>
+    {
+    typedef
+      boost::guigl::segment_type::first_type
+      type;
+    };
+
+  // indexed_access trait
+  template<int I, int D>
+  struct indexed_access<boost::guigl::segment_type,I,D>
+    {
+    BOOST_STATIC_ASSERT( (0 == I) || (1 == I) );
+
+    typedef
+      geometry::traits::point_type<boost::guigl::segment_type>::type
+      point_type;
+
+    typedef
+      geometry::traits::coordinate_type<point_type>::type
+      coordinate_type;
+
+    static inline coordinate_type get(boost::guigl::segment_type const& segment)
+      {
+      return (I == 0)
+        ? geometry::get<D>(segment.first)
+        : geometry::get<D>(segment.second);
+      }
+
+    static inline void set(boost::guigl::segment_type const& segment, coordinate_type const& x)
+      {
+      return (I == 0)
+        ? geometry::set<D>(segment.first, x)
+        : geometry::set<D>(segment.second, x);
+      }
+
+    };
+  }}
+
+namespace boost{ namespace guigl { namespace ggl {
+
+  namespace dispatch
+    {
+    template <typename Tag, typename G>
+    struct object_tag
+      {
+      //static inline void vertex(G const& ) {}
+      //static inline void draw(G const& g) {}
+      };
+
+    ////////////////////////////////////////////////////////////////////////////////
+    // Point
+    template<typename G>
+    struct object_tag<geometry::point_tag, G>
+      {
+      private:
+        template<int D>
+        static inline void vertex_(G const& g);
+
+        template<>
+        static inline void vertex_<2>(G const& g)
+          {
+          boost::guigl::gl::vertex(
+            geometry::get<0>(g),
+            geometry::get<1>(g));
+          }
+
+        template<>
+        static inline void vertex_<3>(G const& g)
+          {
+          boost::guigl::gl::vertex(
+            geometry::get<0>(g),
+            geometry::get<1>(g),
+            geometry::get<2>(g));
+          }
+        template<>
+        static inline void vertex_<4>(G const& g)
+          {
+          boost::guigl::gl::vertex(
+            geometry::get<0>(g),
+            geometry::get<1>(g),
+            geometry::get<2>(g),
+            geometry::get<3>(g));
+          }
+
+      public:
+        static inline
+          BOOST_CONCEPT_REQUIRES(((geometry::ConstPoint<G>)),
+          (void))
+          vertex(G const& g)
+          {
+          vertex_<geometry::traits::dimension<G>::value>(g);
+          }
+
+        static inline
+          BOOST_CONCEPT_REQUIRES(((geometry::ConstPoint<G>)),
+          (void))
+          draw(G const& g)
+          {
+          glBegin(GL_POINTS);
+          vertex(g);
+          glEnd();
+          }
+      };
+    }
+
+  template<class Tag, class G>
+  void vertex(G const& g)
+    {
+    dispatch::object_tag<Tag, G>::vertex(g);
+    }
+
+  template<class G>
+  void vertex(G const& g)
+    {
+    vertex<typename geometry::traits::tag<G>::type>(g);
+    }
+
+  struct vertex_drawer {
+    template<class G>
+    void operator()(G const& g) const {vertex(g);}
+    };
+
+  namespace dispatch
+    {
+
+    ////////////////////////////////////////////////////////////////////////////////
+    // Segment
+    template<typename G>
+    struct object_tag<geometry::segment_tag, G>
+      {
+      private:
+        template<int D>
+        static inline void vertex_(const G& g);
+
+        template<>
+        static inline void vertex_<2>(const G& g)
+          {
+          boost::guigl::gl::vertex(
+            geometry::get<0, 0>(g),
+            geometry::get<0, 1>(g));
+          boost::guigl::gl::vertex(
+            geometry::get<1, 0>(g),
+            geometry::get<1, 1>(g));
+          }
+
+        template<>
+        static inline void vertex_<3>(const G& g)
+          {
+          boost::guigl::gl::vertex(
+            geometry::get<0, 0>(g),
+            geometry::get<0, 1>(g),
+            geometry::get<0, 2>(g));
+          boost::guigl::gl::vertex(
+            geometry::get<1, 0>(g),
+            geometry::get<1, 1>(g),
+            geometry::get<1, 2>(g));
+          }
+
+        template<>
+        static inline void vertex_<4>(const G& g)
+          {
+          boost::guigl::gl::vertex(
+            geometry::get<0, 0>(g),
+            geometry::get<0, 1>(g),
+            geometry::get<0, 2>(g),
+            geometry::get<0, 3>(g));
+          boost::guigl::gl::vertex(
+            geometry::get<1, 0>(g),
+            geometry::get<1, 1>(g),
+            geometry::get<1, 2>(g),
+            geometry::get<1, 3>(g));
+          }
+
+      public:
+        static inline
+          BOOST_CONCEPT_REQUIRES(((geometry::ConstSegment<G>)),
+          (void))
+          vertex(G const& g)
+          {
+          typedef typename geometry::traits::point_type<G>::type point_type;
+          vertex_<geometry::traits::dimension<point_type>::value>(g);
+          }
+
+        static inline
+          BOOST_CONCEPT_REQUIRES(((geometry::ConstSegment<G>)),
+          (void))
+          draw(G const& g)
+          {
+          glBegin(GL_LINES);
+          vertex(g);
+          glEnd();
+          }
+      };
+
+    ////////////////////////////////////////////////////////////////////////////////
+    // Box
+    template<typename G>
+    struct object_tag<geometry::box_tag, G>
+      {
+      private:
+        template<int D>
+        static inline void vertex_(const G& g);
+
+        template<>
+        static inline void vertex_<2>(const G& g)
+          {
+          boost::guigl::gl::vertex(
+            geometry::get<geometry::min_corner, 0>(g),
+            geometry::get<geometry::min_corner, 1>(g));
+          boost::guigl::gl::vertex(
+            geometry::get<geometry::min_corner, 0>(g),
+            geometry::get<geometry::max_corner, 1>(g));
+          boost::guigl::gl::vertex(
+            geometry::get<geometry::max_corner, 0>(g),
+            geometry::get<geometry::max_corner, 1>(g));
+          boost::guigl::gl::vertex(
+            geometry::get<geometry::max_corner, 0>(g),
+            geometry::get<geometry::min_corner, 1>(g));
+          }
+
+        // support for 3d
+
+      public:
+        static inline
+          BOOST_CONCEPT_REQUIRES(((geometry::ConstBox<G>)),
+          (void))
+          vertex(G const& g)
+          {
+          typedef typename geometry::traits::point_type<G>::type point_type;
+          vertex_<geometry::traits::dimension<point_type>::value>(g);
+          }
+
+        static inline
+          BOOST_CONCEPT_REQUIRES(((geometry::ConstBox<G>)),
+          (void))
+          draw(G const& g)
+          {
+          glBegin(GL_LINE_LOOP);
+          vertex(g);
+          glEnd();
+          }
+      };
+
+    ////////////////////////////////////////////////////////////////////////////////
+    // Point Set
+    template<typename G, int GLMode, template<typename T> class Concept>
+    struct point_set
+      {
+      public:
+        static inline
+          BOOST_CONCEPT_REQUIRES(((Concept<G>)),
+          (void))
+          vertex(G const& g)
+          {
+          std::for_each(
+            boost::begin(g), boost::end(g),
+            vertex_drawer());
+          }
+
+        static inline
+          BOOST_CONCEPT_REQUIRES(((Concept<G>)),
+          (void))
+          draw(G const& g)
+          {
+          glBegin(GLMode);
+          vertex(g);
+          glEnd();
+          }
+      };
+
+    ////////////////////////////////////////////////////////////////////////////////
+    // Linestring
+    template<typename G>
+    struct object_tag<geometry::linestring_tag, G>
+      : public point_set<G, GL_LINE_STRIP, geometry::ConstLinestring>
+      {
+      };
+
+    ////////////////////////////////////////////////////////////////////////////////
+    // Ring
+    template<typename G>
+    struct object_tag<geometry::ring_tag, G>
+      : public point_set<G, GL_LINE_LOOP, geometry::ConstRing>
+      {
+      };
+
+    ////////////////////////////////////////////////////////////////////////////////
+    // polygon_tag
+    // polygon is not implemented yet
+    template<typename G>
+    struct object_tag<geometry::polygon_tag, G>
+      {
+      public:
+        static inline
+          BOOST_CONCEPT_REQUIRES(((geometry::ConstPolygon<G>)),
+          (void))
+          vertex(G const& g)
+          {
+
+          std::for_each(
+            boost::begin(exterior_ring(g)), boost::end(exterior_ring(g)),
+            vertex_drawer());
+          }
+
+        static inline
+          BOOST_CONCEPT_REQUIRES(((geometry::ConstPolygon<G>)),
+          (void))
+          draw(G const& g)
+          {
+          //glBegin(GL_POLYGON);
+          //vertex(g);
+          //glEnd();
+          }
+      };
+
+    }
+
+  template<class Tag, class G>
+  void draw(G const& g)
+    {
+    dispatch::object_tag<Tag, G>::draw(g);
+    }
+
+  template<class G>
+  void draw(G const& g)
+    {
+    draw<typename geometry::traits::tag<G>::type>(g);
+    }
+
+  struct drawer {
+    template<class G>
+    void operator()(G const& g) const {draw(g);}
+    };
+
+  }}}
+
+#endif BOOST__GUIGL__GGL_HPP
Modified: sandbox-branches/andreo/guigl/boost/guigl/types.hpp
==============================================================================
--- sandbox-branches/andreo/guigl/boost/guigl/types.hpp	(original)
+++ sandbox-branches/andreo/guigl/boost/guigl/types.hpp	2009-03-25 10:01:17 EDT (Wed, 25 Mar 2009)
@@ -12,12 +12,14 @@
 
 #include <boost/gil/utilities.hpp>
 #include <boost/gil/typedefs.hpp>
+#include <utility>
 
 namespace boost { namespace guigl {
 
 typedef gil::point2<double> size_type;
 typedef gil::point2<double> position_type;
 typedef gil::rgba32f_pixel_t color_type;
+typedef std::pair<position_type, position_type> segment_type;
 
 }}
 
Modified: sandbox-branches/andreo/guigl/boost/guigl/view/base.hpp
==============================================================================
--- sandbox-branches/andreo/guigl/boost/guigl/view/base.hpp	(original)
+++ sandbox-branches/andreo/guigl/boost/guigl/view/base.hpp	2009-03-25 10:01:17 EDT (Wed, 25 Mar 2009)
@@ -18,6 +18,25 @@
 
 class window;
 
+struct LT {}; // left-top point
+struct LC {}; // left-center point
+struct LB {}; // left-bottom point
+struct CT {}; // center-top point
+struct CC {}; // center-center point
+struct CB {}; // center-bottom point
+struct RT {}; // right-top point
+struct RC {}; // right-center point
+struct RB {}; // right-bottom point
+
+struct VL {}; // vertical left segment
+struct VC {}; // vertical center segment
+struct VR {}; // vertical right segment
+struct HT {}; // horizontal left segment
+struct HC {}; // horizontal center segment
+struct HB {}; // horizontal right segment
+struct D1 {}; // LT-RB diagonal
+struct D2 {}; // LB-RT diagonal
+
 namespace view {
 
 class base
@@ -36,11 +55,56 @@
 
     void set_size(const size_type &size)
     {   m_size = size; }
-    
+
+    template<class PositionTag>
+    position_type point() const;
+
+#define BOOST_GUIGL_SPECIAL_POINT_IMPL(point_tag_, val1_, val2_) \
+  template<>                                            \
+    inline position_type point<point_tag_>() const             \
+      { return position_type(val1_, val2_); }
+  
+    BOOST_GUIGL_SPECIAL_POINT_IMPL(LT, 0., 0.);
+    BOOST_GUIGL_SPECIAL_POINT_IMPL(LC, 0., size().y/2);
+    BOOST_GUIGL_SPECIAL_POINT_IMPL(LB, 0., size().y);
+    BOOST_GUIGL_SPECIAL_POINT_IMPL(CT, size().x/2, 0.);
+    BOOST_GUIGL_SPECIAL_POINT_IMPL(CC, size().x/2, size().y/2);
+    BOOST_GUIGL_SPECIAL_POINT_IMPL(CB, size().x/2, size().y);
+    BOOST_GUIGL_SPECIAL_POINT_IMPL(RT, size().x, 0.);
+    BOOST_GUIGL_SPECIAL_POINT_IMPL(RC, size().x, size().y/2);
+    BOOST_GUIGL_SPECIAL_POINT_IMPL(RB, size().x, size().y);
+
+    template<class SegmentTag>
+    inline segment_type segment() const;
+
+#define BOOST_GUIGL_SPECIAL_SEGMENT_IMPL(segment_tag_, point_tag1_, point_tag2_)    \
+  template<>                                                                        \
+  inline segment_type segment<segment_tag_>() const                                 \
+      {                                                                             \
+      return segment_type(point<point_tag1_>(), point<point_tag2_>());              \
+      }
+
+    BOOST_GUIGL_SPECIAL_SEGMENT_IMPL(VL, LT, LB);
+    BOOST_GUIGL_SPECIAL_SEGMENT_IMPL(VC, CT, CB);
+    BOOST_GUIGL_SPECIAL_SEGMENT_IMPL(VR, RT, RB);
+    BOOST_GUIGL_SPECIAL_SEGMENT_IMPL(HT, LT, RT);
+    BOOST_GUIGL_SPECIAL_SEGMENT_IMPL(HC, LC, RC);
+    BOOST_GUIGL_SPECIAL_SEGMENT_IMPL(HB, LB, RB);
+    BOOST_GUIGL_SPECIAL_SEGMENT_IMPL(D1, LT, RB);
+    BOOST_GUIGL_SPECIAL_SEGMENT_IMPL(D2, RT, LB);
+
 protected:
-    virtual void draw()=0;
-    void draw_prologue() {}
-    void draw_epilogue() {}
+    virtual void draw() = 0;
+    void draw_prologue()
+      {
+      glEnable(GL_BLEND);
+      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+      }
+
+    void draw_epilogue()
+      {
+      glDisable(GL_BLEND);
+      }
     
     virtual bool on_event(const event_type &e)
     {
@@ -57,7 +121,7 @@
 
 #define BOOST_GUIGL_WIDGET_DRAW             \
     friend class ::boost::guigl::access;    \
-    void BOOST_EXPORT_SYMBOLS draw();                            \
+    void BOOST_EXPORT_SYMBOLS draw();       \
     void draw_prologue();                   \
     void draw_epilogue();                   \
 
Modified: sandbox-branches/andreo/guigl/libs/guigl/build/vc8ide/build.vcproj
==============================================================================
--- sandbox-branches/andreo/guigl/libs/guigl/build/vc8ide/build.vcproj	(original)
+++ sandbox-branches/andreo/guigl/libs/guigl/build/vc8ide/build.vcproj	2009-03-25 10:01:17 EDT (Wed, 25 Mar 2009)
@@ -93,6 +93,10 @@
 				>
                         </File>
                         <File
+				RelativePath="..\..\..\..\boost\guigl\ggl.hpp"
+				>
+			</File>
+			<File
                                 RelativePath="..\..\..\..\boost\guigl\gl.hpp"
 				>
                         </File>
Modified: sandbox-branches/andreo/guigl/libs/guigl/build/vc8ide/example.vcproj
==============================================================================
--- sandbox-branches/andreo/guigl/libs/guigl/build/vc8ide/example.vcproj	(original)
+++ sandbox-branches/andreo/guigl/libs/guigl/build/vc8ide/example.vcproj	2009-03-25 10:01:17 EDT (Wed, 25 Mar 2009)
@@ -63,6 +63,10 @@
 			>
                 </File>
                 <File
+			RelativePath="..\..\example\ggl.cpp"
+			>
+		</File>
+		<File
                         RelativePath="..\..\example\Jamfile"
 			>
                 </File>
Modified: sandbox-branches/andreo/guigl/libs/guigl/example/Jamfile
==============================================================================
--- sandbox-branches/andreo/guigl/libs/guigl/example/Jamfile	(original)
+++ sandbox-branches/andreo/guigl/libs/guigl/example/Jamfile	2009-03-25 10:01:17 EDT (Wed, 25 Mar 2009)
@@ -27,9 +27,10 @@
 exe window_only_example : window_only_example.cpp ;
 exe overlapping_example : overlapping_example.cpp ;
 exe sexy_button : sexy_button.cpp ;
+exe ggl : ggl.cpp ;
 
 install window_example_stage
-    : window_example custom_example window_only_example overlapping_example sexy_button
+    : window_example custom_example window_only_example overlapping_example sexy_button ggl
     : <install-dependencies>on <install-type>EXE
       <install-type>LIB <location>$(TOP)/bin/stage/window_example
     ;
Added: sandbox-branches/andreo/guigl/libs/guigl/example/ggl.cpp
==============================================================================
--- (empty file)
+++ sandbox-branches/andreo/guigl/libs/guigl/example/ggl.cpp	2009-03-25 10:01:17 EDT (Wed, 25 Mar 2009)
@@ -0,0 +1,71 @@
+/*=================================---------------------------------------------
+Copyright 2009 Andrey Torba
+
+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)
+-----------------------------------------------===============================*/
+
+#include <boost/guigl/application.hpp>
+#include <boost/guigl/window.hpp>
+#include <boost/guigl/view/positioned.hpp>
+#include <boost/guigl/view/impl/positioned.hpp>
+
+#include <boost/guigl/ggl.hpp>
+#include <boost/guigl/gl.hpp>
+
+using namespace boost::guigl;
+
+typedef view::positioned<> my_widget_base_type;
+class my_widget : public my_widget_base_type
+  {
+  public:
+    typedef my_widget_base_type base_type;
+
+    template<typename ArgumentPack>
+    my_widget(const ArgumentPack &args)
+      : base_type(args)
+      {}
+
+    void draw_prologue()
+      {
+      base_type::draw_prologue();
+
+      gl::color(blue());
+      glLineWidth(1);
+      ggl::draw(segment<VL>());
+      ggl::draw(segment<HT>());
+      ggl::draw(segment<VR>());
+      ggl::draw(segment<HB>());
+
+      gl::color(green(0.5));
+      glLineWidth(2);
+      ggl::draw(segment<HC>());
+      ggl::draw(segment<VC>());
+
+      gl::color(red(0.2));
+      glLineWidth(5);
+      ggl::draw(segment<D1>());
+      ggl::draw(segment<D2>());
+
+      }
+
+    BOOST_GUIGL_WIDGET_DRAW_IMPL(my_widget);
+  };
+
+int main()
+  {
+  window wnd((
+    _label = "custom example",
+    _size = size_type(500, 500),
+    _background = white()
+    ));
+
+  wnd << new my_widget((
+    _size = size_type(300, 300),
+    _position = position_type(100, 100)
+    ));
+
+  application::run();
+  return 0;
+  }
Modified: sandbox-branches/andreo/guigl/libs/guigl/example/sexy_button.cpp
==============================================================================
--- sandbox-branches/andreo/guigl/libs/guigl/example/sexy_button.cpp	(original)
+++ sandbox-branches/andreo/guigl/libs/guigl/example/sexy_button.cpp	2009-03-25 10:01:17 EDT (Wed, 25 Mar 2009)
@@ -79,7 +79,7 @@
     {}
 
     template<class ColorKey>
-    color_type color()
+    color_type const& color()
     { 
         return boost::fusion::at_key<ColorKey>(m_color_map);
     }
@@ -93,8 +93,8 @@
     template<class ColorKey>
     void use_color()
     {
-        color_type const& clr = boost::fusion::at_key<ColorKey>(m_color_map);
-        gl::color(float(clr[0]), float(clr[1]), float(clr[2]), float(clr[3]));
+        color_type const& clr = color<ColorKey>();
+        gl::color<float>(clr[0], clr[1], clr[2], clr[3]);
     }
 
 };