|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r52022 - sandbox-branches/andreo/guigl/libs/guigl/example
From: andreytorba_at_[hidden]
Date: 2009-03-27 15:12:15
Author: andreo
Date: 2009-03-27 15:12:14 EDT (Fri, 27 Mar 2009)
New Revision: 52022
URL: http://svn.boost.org/trac/boost/changeset/52022
Log:
added mouse tracking in polygon.cpp
Text files modified:
sandbox-branches/andreo/guigl/libs/guigl/example/ggl.cpp | 3
sandbox-branches/andreo/guigl/libs/guigl/example/polygon.cpp | 186 +++++++++++++++++++++++----------------
2 files changed, 109 insertions(+), 80 deletions(-)
Modified: sandbox-branches/andreo/guigl/libs/guigl/example/ggl.cpp
==============================================================================
--- sandbox-branches/andreo/guigl/libs/guigl/example/ggl.cpp (original)
+++ sandbox-branches/andreo/guigl/libs/guigl/example/ggl.cpp 2009-03-27 15:12:14 EDT (Fri, 27 Mar 2009)
@@ -18,8 +18,7 @@
#include <boost/assign/std.hpp>
-#include <geometry/geometries/geometries.hpp>
-#include <geometry/algorithms/correct.hpp>
+#include <geometry/geometry.hpp>
namespace geometry { namespace traits{
template<class T>
Modified: sandbox-branches/andreo/guigl/libs/guigl/example/polygon.cpp
==============================================================================
--- sandbox-branches/andreo/guigl/libs/guigl/example/polygon.cpp (original)
+++ sandbox-branches/andreo/guigl/libs/guigl/example/polygon.cpp 2009-03-27 15:12:14 EDT (Fri, 27 Mar 2009)
@@ -8,7 +8,10 @@
#include <boost/guigl/application.hpp>
#include <boost/guigl/window.hpp>
-#include <boost/guigl/widget/custom.hpp>
+#include <boost/guigl/view/mouse_tracking.hpp>
+#include <boost/guigl/view/impl/mouse_tracking.hpp>
+#include <boost/guigl/view/positioned.hpp>
+#include <boost/guigl/view/impl/positioned.hpp>
#include <boost/guigl/ggl.hpp>
#include <boost/assign/std.hpp>
@@ -25,96 +28,123 @@
using namespace boost::guigl;
using namespace geometry;
-struct draw_stuff {
- typedef polygon_2d Polygon;
- typedef box_2d Box;
- typedef std::vector<polygon_2d> PV;
-
- Polygon poly;
- Polygon hull;
- Box cb;
- PV v;
+typedef view::mouse_tracking<view::positioned<> > my_widget_base_type;
+class my_widget : public my_widget_base_type
+{
+private:
+ typedef polygon_2d Polygon;
+ typedef box_2d Box;
+ typedef std::vector<polygon_2d> PV;
+
+ Polygon poly;
+ Polygon hull;
+ Box cb;
+ PV v;
- draw_stuff()
- : cb(make<point_2d>(1.5, 1.5), make<point_2d>(4.5, 2.5))
+ void init()
{
- const double coor[][2] = {
- {2.0, 1.3}, {2.4, 1.7}, {2.8, 1.8}, {3.4, 1.2}, {3.7, 1.6},
- {3.4, 2.0}, {4.1, 3.0}, {5.3, 2.6}, {5.4, 1.2}, {4.9, 0.8}, {2.9, 0.7},
- {2.0, 1.3} // closing point is opening point
- };
- assign(poly, coor);
-
- {
- poly.inners().resize(1);
- const double coor[][2] = { {4.0, 2.0}, {4.2, 1.4}, {4.8, 1.9}, {4.4, 2.2}, {4.0, 2.0} };
- assign(poly.inners().back(), coor);
- }
+ box_2d b(make<point_2d>(150, 150), make<point_2d>(450, 250));
+ cb = b;
- correct(poly);
+ const double coor[][2] = {
+ {200, 130}, {240, 170}, {280, 180}, {340, 120}, {370, 160},
+ {340, 200}, {410, 300}, {530, 260}, {540, 120}, {490, 80}, {290, 70},
+ {200, 130} // closing point is opening point
+ };
+ assign(poly, coor);
+
+ {
+ poly.inners().resize(1);
+ const double coor[][2] = { {400, 200}, {420, 140}, {480, 190}, {440, 220}, {400, 200} };
+ assign(poly.inners().back(), coor);
+ }
- convex_hull(poly, std::back_inserter(hull.outer()));
+ correct(poly);
- intersection(cb, poly, std::back_inserter(v));
+ convex_hull(poly, std::back_inserter(hull.outer()));
+
+ }
+
+ void on_mouse_move()
+ {
+ box_2d box(
+ make<point_2d>(mouse_state().position.x - 100, mouse_state().position.y - 50),
+ make<point_2d>(mouse_state().position.x + 100, mouse_state().position.y + 50));
+ cb = box;
+
+ v.clear();
+ intersection(cb, poly, std::back_inserter(v));
+
+ BOOST_FOREACH(Polygon& pg, v)
+ correct(pg);
+ window::redraw(*this);
+ }
+
+public:
+ typedef my_widget_base_type base_type;
+
+ template<typename ArgumentPack>
+ my_widget(const ArgumentPack &args)
+ : base_type(args)
+ {
+ init();
}
- template<class T>
- static void draw_polygon(
- T const& g,
- color_type const& body,
- color_type const& border)
+ template<class T>
+ static void draw_polygon(
+ T const& g,
+ color_type const& body,
+ color_type const& border)
{
- // body of polygon
- gl::color(body);
- ggl::draw(g);
-
- // contours of polygon
- gl::color(border);
- ggl::draw(exterior_ring(g));
+ // body of polygon
+ gl::color(body);
+ ggl::draw(g);
+
+ // contours of polygon
+ gl::color(border);
+ ggl::draw(exterior_ring(g));
- typedef typename ring_type<T>::type R;
+ typedef typename ring_type<T>::type R;
- BOOST_FOREACH(R const& r, interior_rings(g))
- ggl::draw(r);
+ BOOST_FOREACH(R const& r, interior_rings(g))
+ ggl::draw(r);
}
- void operator()() const {
- gl::scoped_matrix m;
- //gl::translate(100., 100.);
- gl::scale(80., 80., 80.);
-
- glEnable(GL_POINT_SMOOTH);
- glEnable(GL_LINE_SMOOTH);
-
- // hull
- draw_polygon(hull, yellow(0.3), red(0.4));
-
- // polygon
- draw_polygon(poly, yellow(0.8), red(0.8));
-
- // box
- gl::color(blue(0.2));
- ggl::rect(cb);
-
- // intersection
- BOOST_FOREACH(polygon_2d const& pg, v)
- draw_polygon(pg, red(0.4), black(0.8));
+ void draw_prologue()
+ {
+ base_type::draw_prologue();
+
+ glEnable(GL_LINE_SMOOTH);
+
+ // hull
+ draw_polygon(hull, yellow(0.3), red(0.4));
+
+ // polygon
+ draw_polygon(poly, yellow(0.8), red(0.8));
+
+ // box
+ gl::color(blue(0.2));
+ ggl::rect(cb);
+
+ // intersection
+ BOOST_FOREACH(polygon_2d const& pg, v)
+ draw_polygon(pg, red(0.4), black(0.8));
}
- };
+ BOOST_GUIGL_WIDGET_DRAW_IMPL(my_widget);
+};
int main()
- {
- window wnd((
- _label = "tess example",
- _size=size_type(500, 500),
- _background = white() ));
-
- wnd << new widget::custom((
- _size=size_type(500,500),
- _draw_prologue = draw_stuff()
- ));
-
- application::run();
- return 0;
- }
+{
+ window wnd((
+ _label = "tess example",
+ _size=size_type(600, 600),
+ _background = white() ));
+
+ wnd << new my_widget((
+ _size=size_type(600, 600)
+ ));
+
+ application::run();
+ return 0;
+}
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