mail[Wesnoth-commits] r28315 - in /trunk/src: tests/gui/ tests/utils/ widgets/


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by paniemin on August 04, 2008 - 03:10:
Author: suokko
Date: Mon Aug  4 00:04:44 2008
New Revision: 28315

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28315&view=rev
Log:
* Fixed drop target to work correctly with multiple groups
* Added initial implementation for fake mouse events for tests

Modified:
    trunk/src/tests/gui/test_drop_target.cpp
    trunk/src/tests/utils/fake_event_source.cpp
    trunk/src/tests/utils/fake_event_source.hpp
    trunk/src/widgets/combo_drag.hpp
    trunk/src/widgets/drop_target.cpp

Modified: trunk/src/tests/gui/test_drop_target.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tests/gui/test_drop_target.cpp?rev=28315&r1=28314&r2=28315&view=diff
==============================================================================
--- trunk/src/tests/gui/test_drop_target.cpp (original)
+++ trunk/src/tests/gui/test_drop_target.cpp Mon Aug  4 00:04:44 2008
@@ -92,5 +92,62 @@
        BOOST_CHECK(gui::drop_target::empty());
 }
 
+BOOST_AUTO_TEST_CASE( test_multiple_drop_groups )
+{
+       gui::drop_group_manager_ptr group(new gui::drop_group_manager());
+       gui::drop_group_manager_ptr group2(new gui::drop_group_manager());
+       BOOST_CHECK(group->get_group_id() > 0);
+       BOOST_CHECK(group2->get_group_id() > 0);
+
+       typedef std::vector<SDL_Rect> location_store;
+       location_store locations;
+       location_store locations2;
+
+       // Create rectangles for drop targets
+       locations.push_back(create_rect(50,50,20,20));
+       locations.push_back(create_rect(50,100,20,20));
+       locations.push_back(create_rect(50,150,20,20));
+       locations.push_back(create_rect(50,200,20,20));
+       locations.push_back(create_rect(50,250,20,20));
+       locations.push_back(create_rect(50,300,20,20));
+
+       locations2.push_back(create_rect(50,50,20,20));
+       locations2.push_back(create_rect(100,50,20,20));
+       locations2.push_back(create_rect(150,50,20,20));
+       locations2.push_back(create_rect(200,50,20,20));
+       locations2.push_back(create_rect(250,50,20,20));
+       locations2.push_back(create_rect(300,50,20,20));
+
+
+       target_store targets;
+       target_store targets2;
+
+       int id_counter = 0;
+
+       std::for_each(locations.begin(), locations.end(),
+                       boost::bind(create_drop_targets,_1, group, 
boost::ref(targets), boost::ref(id_counter)));
+       id_counter = 0;
+       std::for_each(locations2.begin(), locations2.end(),
+                       boost::bind(create_drop_targets,_1, group2, 
boost::ref(targets2), boost::ref(id_counter)));
+
+       BOOST_CHECK_EQUAL(targets.size(), locations.size());
+       BOOST_CHECK_EQUAL(targets2.size(), locations2.size());
+
+       // Modify 3rd rectangle to overlap with 4th
+       locations[2].y = 190;
+
+       // Check for correct drop results
+       BOOST_CHECK_EQUAL(targets[2]->handle_drop(), 3);
+       BOOST_CHECK_EQUAL(targets[3]->handle_drop(), 2);
+       BOOST_CHECK_EQUAL(targets[1]->handle_drop(), -1);
+       BOOST_CHECK_EQUAL(targets[4]->handle_drop(), -1);
+
+       locations2[2].y = 180;
+       locations2[2].x = 50;
+
+       BOOST_CHECK_EQUAL(targets2[2]->handle_drop(), -1);
+
+}
+
 /* vim: set ts=4 sw=4: */
 BOOST_AUTO_TEST_SUITE_END()

Modified: trunk/src/tests/utils/fake_event_source.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tests/utils/fake_event_source.cpp?rev=28315&r1=28314&r2=28315&view=diff
==============================================================================
--- trunk/src/tests/utils/fake_event_source.cpp (original)
+++ trunk/src/tests/utils/fake_event_source.cpp Mon Aug  4 00:04:44 2008
@@ -65,6 +65,13 @@
                        key_list[event_.key.keysym.sym] = 0;
        }
 
+       event_node_mouse_motion::event_node_mouse_motion(size_t time, 
SDL_Event& event) : event_node(time,event)
+       {}
+       void event_node_mouse_motion::fire_event()
+       {
+               SDL_WarpMouse(event_.motion.x,event_.motion.y);
+       }
+
        fake_event_source::fake_event_source() : frame_count_(0)
        {
        }
@@ -113,6 +120,17 @@
                return event;
        }
 
+       event_node_ptr fake_event_source::move_mouse(const size_t time, const 
int x, const int y)
+       {
+               SDL_Event event;
+               event.type = SDL_MOUSEMOTION;
+               event.motion.x = x;
+               event.motion.y = y;
+               event_node_ptr new_move(new event_node_mouse_motion(time, 
event));
+               add_event(new_move);
+               return new_move;
+       }
+
        event_node_ptr fake_event_source::press_key(const size_t time, const 
SDLKey key, const SDLMod mod)
        {
                SDL_Event event = make_key_event(SDL_KEYDOWN, key, mod);

Modified: trunk/src/tests/utils/fake_event_source.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tests/utils/fake_event_source.hpp?rev=28315&r1=28314&r2=28315&view=diff
==============================================================================
--- trunk/src/tests/utils/fake_event_source.hpp (original)
+++ trunk/src/tests/utils/fake_event_source.hpp Mon Aug  4 00:04:44 2008
@@ -65,7 +65,13 @@
        class event_node_keyboard : public event_node {
                public:
                        event_node_keyboard(size_t time, SDL_Event& event);
-                       void fire_event();
+                       virtual void fire_event();
+       };
+
+       class event_node_mouse_motion : public event_node {
+               public:
+                       event_node_mouse_motion(size_t time, SDL_Event& 
event);
+                       virtual void fire_event();
        };
 
        typedef boost::shared_ptr<event_node> event_node_ptr;
@@ -97,6 +103,10 @@
                        event_node_ptr press_key(const size_t time, const 
SDLKey key, const SDLMod mod = KMOD_NONE);
                        event_node_ptr release_key(const size_t time, const 
SDLKey key, const SDLMod mod =KMOD_NONE);
 
+                       event_node_ptr move_mouse(const size_t time, const 
int x, const int y);
+                       event_node_ptr mouse_press(const size_t time, const 
Uint8 button);
+                       event_node_ptr mouse_release(const size_t time, const 
Uint8 button);
+
                        void process(events::pump_info& /*info*/);
        };
 }

Modified: trunk/src/widgets/combo_drag.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/widgets/combo_drag.hpp?rev=28315&r1=28314&r2=28315&view=diff
==============================================================================
--- trunk/src/widgets/combo_drag.hpp (original)
+++ trunk/src/widgets/combo_drag.hpp Mon Aug  4 00:04:44 2008
@@ -64,7 +64,7 @@
                                DROP_DOWN
                        };
                        drag_state drag_;
-                       static const int MIN_DRAG_DISTANCE;
+                       static const float MIN_DRAG_DISTANCE;
                        static const float RETURN_SPEED;
        }; //end class combo
 

Modified: trunk/src/widgets/drop_target.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/widgets/drop_target.cpp?rev=28315&r1=28314&r2=28315&view=diff
==============================================================================
--- trunk/src/widgets/drop_target.cpp (original)
+++ trunk/src/widgets/drop_target.cpp Mon Aug  4 00:04:44 2008
@@ -16,6 +16,8 @@
 
 #include <boost/bind.hpp>
 #include <algorithm>
+
+#include <iostream>
 namespace gui {
 
        drop_target::drop_groups drop_target::groups_;
@@ -57,15 +59,17 @@
 
        int drop_target::handle_drop()
        {
+               drop_groups::iterator end = 
groups_.upper_bound(group_->get_group_id());
                drop_target::drop_groups::iterator itor
                        = 
std::find_if(groups_.lower_bound(group_->get_group_id()), 
-                                       
groups_.upper_bound(group_->get_group_id()),
+                                       end,
                                        boost::bind(&drop_target::hit_rect,
                                                
boost::bind(&drop_target::drop_groups::value_type::second,_1)
                                                ,loc_, id_));
        
-               if (itor == groups_.end())
+               if (itor == end)
                        return -1;
+
                return itor->second->get_id();
        }
 




Related Messages


Powered by MHonArc, Updated Mon Aug 04 04:01:40 2008