Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r51854 - in sandbox-branches/andreo/guigl: boost/guigl boost/guigl/view boost/guigl/view/impl libs/guigl/example
From: andreytorba_at_[hidden]
Date: 2009-03-19 10:17:26


Author: andreo
Date: 2009-03-19 10:17:26 EDT (Thu, 19 Mar 2009)
New Revision: 51854
URL: http://svn.boost.org/trac/boost/changeset/51854

Log:
sexy button development
Text files modified:
   sandbox-branches/andreo/guigl/boost/guigl/color.hpp | 8 ++
   sandbox-branches/andreo/guigl/boost/guigl/view/impl/mouse_tracking.hpp | 5 +
   sandbox-branches/andreo/guigl/boost/guigl/view/mouse_tracking.hpp | 4 +
   sandbox-branches/andreo/guigl/libs/guigl/example/sexy_button.cpp | 148 ++++++++++++++++++++++++++++-----------
   4 files changed, 121 insertions(+), 44 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-19 10:17:26 EDT (Thu, 19 Mar 2009)
@@ -10,6 +10,7 @@
 #define BOOST__GUIGL__COLOR_HPP
 
 #include <boost/guigl/types.hpp>
+#include "gl.hpp"
 
 namespace boost { namespace guigl {
 
@@ -57,6 +58,13 @@
       static_cast<float>(a)/255);
     }
 
+ namespace gl {
+ inline void color(color_type const& clr)
+ {
+ color(float(clr[0]), float(clr[1]), float(clr[2]), float(clr[3]));
+ }
+ }
+
   }}
 
 #endif BOOST__GUIGL__COLOR_HPP

Modified: sandbox-branches/andreo/guigl/boost/guigl/view/impl/mouse_tracking.hpp
==============================================================================
--- sandbox-branches/andreo/guigl/boost/guigl/view/impl/mouse_tracking.hpp (original)
+++ sandbox-branches/andreo/guigl/boost/guigl/view/impl/mouse_tracking.hpp 2009-03-19 10:17:26 EDT (Thu, 19 Mar 2009)
@@ -58,6 +58,7 @@
         bool operator()(const movement_event &event_info) const
         {
             m_mouse_tracking.m_mouse_state.position = event_info.position;
+ m_mouse_tracking.on_mouse_move();
             return false;
         }
 
@@ -70,11 +71,15 @@
         bool operator()(const entry_exit_event &event_info) const
         {
             if(event_info.region == region::exit)
+ {
                 m_mouse_tracking.m_mouse_state.inside = false;
+ m_mouse_tracking.on_mouse_leave();
+ }
             else
             {
                 m_mouse_tracking.m_mouse_state.inside = true;
                 m_mouse_tracking.m_mouse_state.button_down = get_button_state<BaseView>::is_down(m_mouse_tracking);
+ m_mouse_tracking.on_mouse_enter();
             }
             return false;
         }

Modified: sandbox-branches/andreo/guigl/boost/guigl/view/mouse_tracking.hpp
==============================================================================
--- sandbox-branches/andreo/guigl/boost/guigl/view/mouse_tracking.hpp (original)
+++ sandbox-branches/andreo/guigl/boost/guigl/view/mouse_tracking.hpp 2009-03-19 10:17:26 EDT (Thu, 19 Mar 2009)
@@ -53,6 +53,10 @@
 protected:
     bool BOOST_EXPORT_SYMBOLS on_event(const event_type &event_info);
 
+ virtual void on_mouse_enter() {};
+ virtual void on_mouse_leave() {};
+ virtual void on_mouse_move() {};
+
 private:
     guigl::mouse_state m_mouse_state;
 

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-19 10:17:26 EDT (Thu, 19 Mar 2009)
@@ -14,11 +14,16 @@
 #include <boost/guigl/view/impl/clickable.hpp>
 #include <boost/guigl/view/impl/positioned.hpp>
 #include <boost/guigl/view/impl/active_colored.hpp>
+#include <boost/guigl/view/impl/mouse_tracking.hpp>
 
 #include <boost/guigl/platform/opengl.hpp>
 
 #include <boost/guigl/gl.hpp>
 
+#include <boost/fusion/container/generation/make_map.hpp>
+#include <boost/fusion/include/make_map.hpp>
+#include <boost/fusion/include/at_key.hpp>
+
 using namespace boost::guigl;
 
 struct circle2d_generator {
@@ -41,57 +46,56 @@
     }
   };
 
-template<class ColorKey, class BaseType>
-class color_set {
+template<class ColorMap, class BaseType>
+class colored : public BaseType {
 private:
- typedef std::map<ColorKey, color_type> color_map_type;
- color_map_type m_color_set;
+ ColorMap m_color_map;
 
 public:
   typedef BaseType base_type;
 
   template<typename ArgumentPack>
- color_set(const ArgumentPack &args)
+ colored(const ArgumentPack &args)
     : base_type(args)
     {}
 
- color_set(const color_set &rhs)
- : base_type(rhs), m_color_set(rhs.m_color_set)
- {}
-
- void set_color(ColorKey const& key, color_type const& color)
- {
- m_color_set[key] = color;
+ template<class ColorKey>
+ color_type color()
+ {
+ return boost::fusion::at_key<ColorKey>(m_color_map);
     }
 
- bool use_color(ColorKey const& key)
- {
- color_map_type::const_iterator it = m_color_set.find(key);
- if(it == m_color_set.end())
- return false;
- gl::color((*it)[0], (*it)[1], (*it)[2], (*it)[3]);
- return true;
+ template<class ColorKey>
+ void set_color(color_type const& clr)
+ {
+ boost::fusion::at_key<ColorKey>(m_color_map) = clr;
     }
 
- boost::optional<color_type> get_color(ColorKey const& key) const
+ template<class ColorKey>
+ void use_color()
     {
- color_map_type::const_iterator it = m_color_set.find(key);
- if(it != m_color_set.end())
- return *it;
- else
- return boost::optional<color_type>();
+ 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]));
     }
 
   };
 
 class sexy_button;
 
+//TODO: define color tags with help of mpl::list
+typedef boost::fusion::map<
+boost::fusion::pair<struct active_color, color_type>
+, boost::fusion::pair<struct bg_color, color_type>
+, boost::fusion::pair<struct highlight_color, color_type>
+> sexy_button_color_map_type;
+
 typedef
-color_set<int,
+colored<sexy_button_color_map_type,
+view::mouse_tracking<
 //view::solid_background<
 //view::clickable<sexy_button,button::left_type,
 view::positioned<>
-/*>*/ /*>*/ > button_base_type;
+/*>*/ > > button_base_type;
 
 class sexy_button : public button_base_type {
 private:
@@ -106,17 +110,29 @@
     : base_type(args)
     {}
 
+ void on_mouse_enter()
+ {
+ window::redraw(*this);
+ }
+
+ void on_mouse_leave()
+ {
+ window::redraw(*this);
+ }
+
+ //void on_mouse_move()
+ // {
+ // window::redraw(*this);
+ // }
+
   void draw_circle_segment(circle2d_generator const& circle, int phase, int angle)
     {
     position_type pos;
- for(int i = phase; i < phase+angle; i += 10)
+ for(int i = phase; i <= phase+angle; i += 10)
       {
       pos = circle(double(i)/180*3.1425926);
       gl::vertex(pos.x, pos.y);
       }
- position_type last_pos = circle(double(phase+angle)/180*3.1425926);
- if(last_pos != pos)
- gl::vertex(pos.x, pos.y);
     }
 
   void draw_rounded_rect()
@@ -148,8 +164,6 @@
     {
     base_type::draw_prologue();
 
- use_color(0);
-
     glEnable (GL_LINE_SMOOTH);
     //glEnable (GL_POLYGON_SMOOTH);
     glEnable (GL_BLEND);
@@ -157,8 +171,19 @@
     glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); //glEnable(GL_POLYGON_SMOOTH);
     //glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST); //glEnable(GL_POLYGON_SMOOTH);
 
- glLineWidth(0.1);
+ { // shadow
+ gl::scoped_matrix m;
+ gl::translate(2., 2.);
+ gl::color(black(0.1));
+ glBegin(GL_POLYGON);
+ draw_rounded_rect();
+ glEnd();
+ }
 
+ if(mouse_state().inside)
+ use_color<highlight_color>();
+ else
+ use_color<bg_color>();
     glBegin(GL_POLYGON);
     draw_rounded_rect();
     glEnd();
@@ -167,6 +192,12 @@
     draw_rounded_rect();
     glEnd();
 
+ glLineWidth(0.5);
+ gl::color(black(mouse_state().inside ? 1.0 : 0.7));
+ glBegin(GL_LINE_LOOP);
+ draw_rounded_rect();
+ glEnd();
+
     base_type::draw_epilogue();
     }
 
@@ -174,18 +205,47 @@
 
 int main()
 {
- window test_window1(( _label = "custom example", _size=size_type(300,300) ));
+ double border = 10;
+ position_type window_size(300, 300);
+ position_type btn_size((window_size.x - border*5)/2, (window_size.y - border*5)/2);
+
+ window test_window1((
+ _label = "custom example",
+ _size = window_size
+ ));
+
+ 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(160, 197, 241));
+ btn1->set_color<highlight_color>(make_color256(132, 177, 232));
+
+ 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));
+
+ 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));
     
+ 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));
+
+ 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));
+
     test_window1
- << new sexy_button((
- _size=size_type(100, 50),
- _position = position_type(10, 10),
- _active_color = make_color256(12, 114, 163) ))
-
- << new sexy_button((
- _size=size_type(100, 50),
- _position = position_type(150, 10),
- _active_color = make_color256(12, 114, 163) ))
+ << btn1 << btn2 << btn3 << btn4 << btn5
       ;
 
     application::run();


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