$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r51918 - in sandbox-branches/andreo/guigl: boost/guigl libs/guigl/example
From: andreytorba_at_[hidden]
Date: 2009-03-22 19:59:06
Author: andreo
Date: 2009-03-22 19:59:05 EDT (Sun, 22 Mar 2009)
New Revision: 51918
URL: http://svn.boost.org/trac/boost/changeset/51918
Log:
color reorganization
Text files modified: 
   sandbox-branches/andreo/guigl/boost/guigl/color.hpp              |    90 +++++++++++++++++++++++-----------      
   sandbox-branches/andreo/guigl/boost/guigl/parameters.hpp         |   105 ++++++++++++++++++++------------------- 
   sandbox-branches/andreo/guigl/libs/guigl/example/sexy_button.cpp |    20 +++---                                  
   3 files changed, 124 insertions(+), 91 deletions(-)
Modified: sandbox-branches/andreo/guigl/boost/guigl/color.hpp
==============================================================================
--- sandbox-branches/andreo/guigl/boost/guigl/color.hpp	(original)
+++ sandbox-branches/andreo/guigl/boost/guigl/color.hpp	2009-03-22 19:59:05 EDT (Sun, 22 Mar 2009)
@@ -1,5 +1,5 @@
 /*=================================---------------------------------------------
-Copyright 2008 Torba Andrey
+Copyright 2009 Andrey Torba
 
 Distributed under the Boost Software License, Version 1.0.
 (See accompanying file LICENSE_1_0.txt or copy at
@@ -10,61 +10,93 @@
 #define BOOST__GUIGL__COLOR_HPP
 
 #include <boost/guigl/types.hpp>
-#include "gl.hpp"
 
 namespace boost { namespace guigl {
 
-  inline color_type make_color(float r, float g, float b, float a = 1.0f)
+    template<class T>
+    color_type make_color(T r, T g, T b, T a);
+
+    template<>
+    inline color_type make_color<float>(float r, float g, float b, float a)
     {
-    return color_type(r, g, b, a);
+        return color_type(r, g, b, a);
     }
 
-  inline color_type red(float alpha = 1)
+    template<>
+    inline color_type make_color<double>(double r, double g, double b, double a)
     {
-    return make_color(1, 0, 0, alpha);
+        return make_color(
+            static_cast<float>(r),
+            static_cast<float>(g),
+            static_cast<float>(b),
+            static_cast<float>(a));
     }
 
-  inline color_type green(float alpha = 1)
+    template<>
+    inline color_type make_color<int>(int r, int g, int b, int a)
     {
-    return make_color(0, 1, 0, alpha);
+        return make_color(
+            static_cast<float>(r)/255,
+            static_cast<float>(g)/255,
+            static_cast<float>(b)/255,
+            static_cast<float>(a)/255);
     }
 
-  inline color_type blue(float alpha = 1)
+    template<class T>
+    color_type make_color(T r, T g, T b);
+
+    template<>
+    inline color_type make_color<float>(float r, float g, float b)
     {
-    return make_color(0, 0, 1, alpha);
+        return make_color(r, g, b, 1.0f);
     }
 
-  inline color_type yellow(float alpha = 1)
+    template<>
+    inline color_type make_color<double>(double r, double g, double b)
     {
-    return make_color(1, 1, 0, alpha);
+        return make_color(r, g, b, 1.0);
     }
 
-  inline color_type white(float alpha = 1)
+    template<>
+    inline color_type make_color<int>(int r, int g, int b)
     {
-    return make_color(1, 1, 1, alpha);
+        return make_color(r, g, b, 255);
     }
 
-  inline color_type black(float alpha = 1)
-    {
-    return make_color(0, 0, 0, alpha);
+#define BOOST_GUIGL_COLOR(name, red, green, blue)   \
+    inline color_type name(float alpha = 1.0f)      \
+    {                                               \
+    return make_color(red, green, blue, alpha); \
     }
 
-  inline color_type make_color256(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255)
+    BOOST_GUIGL_COLOR(red,      1.0f, 0.0f, 0.0f);
+    BOOST_GUIGL_COLOR(green,    0.0f, 1.0f, 0.0f);
+    BOOST_GUIGL_COLOR(blue,     0.0f, 0.0f, 1.0f);
+    BOOST_GUIGL_COLOR(black,    0.0f, 0.0f, 0.0f);
+    BOOST_GUIGL_COLOR(white,    1.0f, 1.0f, 1.0f);
+    BOOST_GUIGL_COLOR(yellow,   1.0f, 1.0f, 0.0f);
+
+    inline color_type grey(float brightness = 0.5f, float alpha = 1.0f)
     {
-    return make_color(
-      static_cast<float>(r)/255,
-      static_cast<float>(g)/255,
-      static_cast<float>(b)/255,
-      static_cast<float>(a)/255);
+        return make_color(brightness, brightness, brightness, alpha);
     }
 
-  namespace gl {
+#undef BOOST_GUIGL_COLOR
+
+}}
+
+#include <boost/guigl/gl.hpp>
+// TODO: move to another place
+namespace boost { namespace guigl { namespace gl {
     inline void color(color_type const& clr)
-      {
-      color(float(clr[0]), float(clr[1]), float(clr[2]), float(clr[3]));
-      }
+    {
+        // TODO: use gil concepts to access channels
+        color(
+            static_cast<float>(clr[0]),
+            static_cast<float>(clr[1]),
+            static_cast<float>(clr[2]),
+            static_cast<float>(clr[3]));
     }
-
-  }}
+}}}
 
 #endif BOOST__GUIGL__COLOR_HPP
Modified: sandbox-branches/andreo/guigl/boost/guigl/parameters.hpp
==============================================================================
--- sandbox-branches/andreo/guigl/boost/guigl/parameters.hpp	(original)
+++ sandbox-branches/andreo/guigl/boost/guigl/parameters.hpp	2009-03-22 19:59:05 EDT (Sun, 22 Mar 2009)
@@ -1,9 +1,9 @@
 /*=================================---------------------------------------------
-    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)
+Copyright 2008,2009 Stjepan Rajko, 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__PARAMETER_MAP_HPP
@@ -12,59 +12,60 @@
 #include <boost/guigl/event.hpp>
 #include <boost/guigl/types.hpp>
 #include <boost/parameter/typed_name.hpp>
+#include <boost/guigl/color.hpp>
 
 namespace boost { namespace guigl {
 
-namespace keywords {
-    BOOST_PARAMETER_TYPED_NAME_WDEFAULT(label,const std::string,"")
-    BOOST_PARAMETER_TYPED_NAME_WDEFAULT(size,const size_type,(size_type(200,200)))
-    BOOST_PARAMETER_TYPED_NAME_WDEFAULT(position,const position_type,(size_type(0,0)))
-    BOOST_PARAMETER_TYPED_NAME_WDEFAULT(background,const color_type,(white()))
-    BOOST_PARAMETER_TYPED_NAME_WDEFAULT(color,const color_type,(blue()))
-    BOOST_PARAMETER_TYPED_NAME_WDEFAULT(active_color,const color_type,(red()))
-    BOOST_PARAMETER_TYPED_NAME_WDEFAULT(depth,const bool,false)
-    BOOST_PARAMETER_TYPED_NAME_WDEFAULT(min,const double,0.0)
-    BOOST_PARAMETER_TYPED_NAME_WDEFAULT(max,const double,1.0)
-    BOOST_PARAMETER_TYPED_NAME_WDEFAULT(step,const double,0.0)
-    BOOST_PARAMETER_TYPED_NAME_WDEFAULT(period,const double,0.0)
-
-    BOOST_PARAMETER_TYPED_NAME_WDEFAULT(clickable_button,button::enum_type,button::left)
-    BOOST_PARAMETER_TYPED_NAME_WDEFAULT(draggable_button,button::enum_type,button::left)
-
-    BOOST_PARAMETER_UNTYPED_NAME(value)
-    BOOST_PARAMETER_UNTYPED_NAME(children)
-    BOOST_PARAMETER_UNTYPED_NAME(draw_prologue)
-    BOOST_PARAMETER_UNTYPED_NAME(draw_epilogue)
-    BOOST_PARAMETER_UNTYPED_NAME(on_event)
-    
-    typedef boost::parameter::aux::empty_typed_arg_list default_parameters;
-}
-
-using namespace keywords;
-
-template<
-    typename T0=boost::parameter::void_, typename T1=boost::parameter::void_,
-    typename T2=boost::parameter::void_, typename T3=boost::parameter::void_,
-    typename T4=boost::parameter::void_, typename T5=boost::parameter::void_,
-    typename T6=boost::parameter::void_, typename T7=boost::parameter::void_>
-struct argument_pack
-{
-    typedef
-        boost::parameter::aux::typed_arg_list<
+    namespace keywords {
+        BOOST_PARAMETER_TYPED_NAME_WDEFAULT(label,const std::string,"")
+            BOOST_PARAMETER_TYPED_NAME_WDEFAULT(size,const size_type,(size_type(200,200)))
+            BOOST_PARAMETER_TYPED_NAME_WDEFAULT(position,const position_type,(size_type(0,0)))
+            BOOST_PARAMETER_TYPED_NAME_WDEFAULT(background,const color_type,(black()))
+            BOOST_PARAMETER_TYPED_NAME_WDEFAULT(color,const color_type,(white()))
+            BOOST_PARAMETER_TYPED_NAME_WDEFAULT(active_color,const color_type,(red()))
+            BOOST_PARAMETER_TYPED_NAME_WDEFAULT(depth,const bool,false)
+            BOOST_PARAMETER_TYPED_NAME_WDEFAULT(min,const double,0.0)
+            BOOST_PARAMETER_TYPED_NAME_WDEFAULT(max,const double,1.0)
+            BOOST_PARAMETER_TYPED_NAME_WDEFAULT(step,const double,0.0)
+            BOOST_PARAMETER_TYPED_NAME_WDEFAULT(period,const double,0.0)
+
+            BOOST_PARAMETER_TYPED_NAME_WDEFAULT(clickable_button,button::enum_type,button::left)
+            BOOST_PARAMETER_TYPED_NAME_WDEFAULT(draggable_button,button::enum_type,button::left)
+
+            BOOST_PARAMETER_UNTYPED_NAME(value)
+            BOOST_PARAMETER_UNTYPED_NAME(children)
+            BOOST_PARAMETER_UNTYPED_NAME(draw_prologue)
+            BOOST_PARAMETER_UNTYPED_NAME(draw_epilogue)
+            BOOST_PARAMETER_UNTYPED_NAME(on_event)
+
+            typedef boost::parameter::aux::empty_typed_arg_list default_parameters;
+    }
+
+    using namespace keywords;
+
+    template<
+        typename T0=boost::parameter::void_, typename T1=boost::parameter::void_,
+        typename T2=boost::parameter::void_, typename T3=boost::parameter::void_,
+        typename T4=boost::parameter::void_, typename T5=boost::parameter::void_,
+        typename T6=boost::parameter::void_, typename T7=boost::parameter::void_>
+    struct argument_pack
+    {
+        typedef
+            boost::parameter::aux::typed_arg_list<
             boost::parameter::aux::typed_tagged_argument<T0, typename T0::value_type>,
             typename argument_pack<T1, T2, T3, T4, T5, T6, T7>::type
-        > type;
-};
+            > type;
+    };
 
-template<>
-struct argument_pack<
-    boost::parameter::void_, boost::parameter::void_,
-    boost::parameter::void_, boost::parameter::void_,
-    boost::parameter::void_, boost::parameter::void_,
-    boost::parameter::void_, boost::parameter::void_>
-{
-    typedef boost::parameter::aux::empty_typed_arg_list type;
-};
+    template<>
+    struct argument_pack<
+        boost::parameter::void_, boost::parameter::void_,
+        boost::parameter::void_, boost::parameter::void_,
+        boost::parameter::void_, boost::parameter::void_,
+        boost::parameter::void_, boost::parameter::void_>
+    {
+        typedef boost::parameter::aux::empty_typed_arg_list type;
+    };
 
 }}
 
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-22 19:59:05 EDT (Sun, 22 Mar 2009)
@@ -265,32 +265,32 @@
     sexy_button* btn1 = new sexy_button((
         _size = position_type(window_size.x - border*2, window_size.y - border*2),
         _position = position_type(border, border) ));
-    btn1->set_color<bg_color>(make_color256(132, 177, 232));
-    btn1->set_color<highlight_color>(make_color256(160, 197, 241));
+    btn1->set_color<bg_color>(make_color(132, 177, 232));
+    btn1->set_color<highlight_color>(make_color(160, 197, 241));
 
     sexy_button* btn2 = new sexy_button((
         _size = btn_size,
         _position = position_type(border*2, border*2) ));
-    btn2->set_color<bg_color>(make_color256(12, 114, 163));
-    btn2->set_color<highlight_color>(make_color256(3, 95, 138));
+    btn2->set_color<bg_color>(make_color(12, 114, 163));
+    btn2->set_color<highlight_color>(make_color(3, 95, 138));
 
     sexy_button* btn3 = new sexy_button((
         _size = btn_size,
         _position = position_type(border*3 + btn_size.x, border*2) ));
-    btn3->set_color<bg_color>(make_color256(8, 208, 60));
-    btn3->set_color<highlight_color>(make_color256(9, 171, 51));
+    btn3->set_color<bg_color>(make_color(8, 208, 60));
+    btn3->set_color<highlight_color>(make_color(9, 171, 51));
 
     sexy_button* btn4 = new sexy_button((
         _size = btn_size,
         _position = position_type(border*2, border*3 + btn_size.y) ));
-    btn4->set_color<bg_color>(make_color256(255, 35, 87));
-    btn4->set_color<highlight_color>(make_color256(219, 4, 55));
+    btn4->set_color<bg_color>(make_color(255, 35, 87));
+    btn4->set_color<highlight_color>(make_color(219, 4, 55));
 
     sexy_button* btn5 = new sexy_button((
         _size = btn_size,
         _position = position_type(border*3 + btn_size.x, border*3 + btn_size.y) ));
-    btn5->set_color<bg_color>(make_color256(249, 230, 73));
-    btn5->set_color<highlight_color>(make_color256(255, 255, 25));
+    btn5->set_color<bg_color>(make_color(249, 230, 73));
+    btn5->set_color<highlight_color>(make_color(255, 255, 25));
 
     test_window1
         << btn1 << btn2 << btn3 << btn4 << btn5