mail[Wesnoth-commits] r24534 - in /trunk/src/gui/widgets: widget.cpp widget.hpp


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

Header


Content

Posted by koraq on March 11, 2008 - 18:22:
Author: mordante
Date: Tue Mar 11 18:22:38 2008
New Revision: 24534

URL: http://svn.gna.org/viewcvs/wesnoth?rev=24534&view=rev
Log:
Add the function to find a widget at a certain location.

Modified:
    trunk/src/gui/widgets/widget.cpp
    trunk/src/gui/widgets/widget.hpp

Modified: trunk/src/gui/widgets/widget.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/widget.cpp?rev=24534&r1=24533&r2=24534&view=diff
==============================================================================
--- trunk/src/gui/widgets/widget.cpp (original)
+++ trunk/src/gui/widgets/widget.cpp Tue Mar 11 18:22:38 2008
@@ -188,7 +188,6 @@
 
 void tsizer::removed_child(const std::string& id, const bool find_all)
 {
-
        for(std::vector<tchild>::iterator itor = children_.begin();
                        itor != children_.end(); ++itor) {
 
@@ -281,6 +280,39 @@
                orig.y += best_row_height[row];
                orig.x = origin.x;
        }
+}
+
+twidget* tsizer::get_widget(const tpoint& coordinate)
+{
+       
+       DBG_GUI << "Find widget at " << coordinate << '\n';
+
+       //! FIXME we need to store the sizes, since this is quite
+       //! pathatic.
+       for(unsigned row = 0; row < rows_; ++row) {
+               for(unsigned col = 0; col < cols_; ++col) {
+
+                       DBG_GUI <<  "Row : " << row << " col : " << col;
+
+                       twidget* widget = child(row, col).widget();
+                       if(!widget) {
+                               DBG_GUI << " no widget found.\n";
+                               continue;
+                       }
+                       
+                       widget = widget->get_widget(coordinate);
+                       if(widget) { 
+                               DBG_GUI << " hit!\n";
+                               return widget;
+                       }
+
+                       DBG_GUI << " no hit.\n";
+
+               }
+       }
+       
+       DBG_GUI << "No widget found.\n";
+       return 0;
 }
 
 tpoint tsizer::tchild::get_best_size()

Modified: trunk/src/gui/widgets/widget.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/widget.hpp?rev=24534&r1=24533&r2=24534&view=diff
==============================================================================
--- trunk/src/gui/widgets/widget.hpp (original)
+++ trunk/src/gui/widgets/widget.hpp Tue Mar 11 18:22:38 2008
@@ -177,6 +177,13 @@
                dirty_ = true;
        }
 
+       //! Gets the widget at the wanted coordinates.
+       twidget* get_widget(const tpoint& coordinate) 
+       { 
+               return coordinate.x >= x_ && coordinate.x < (x_ + w_) &&
+                       coordinate.y >= y_ && coordinate.y < (y_ + h_) ? this 
: 0;
+       }
+
 protected:     
        virtual void set_dirty(const bool dirty = true) { dirty_ = dirty; }
 
@@ -279,6 +286,10 @@
 
        //! Inherited
        void set_best_size(const tpoint& origin);
+
+       //! Gets the widget at the wanted coordinates.
+       //! Override base class.
+       twidget* get_widget(const tpoint& coordinate);
 
 private:
        class tchild 
@@ -335,9 +346,12 @@
                //! Tracks the dirty state of the cell regarding best_size_.
                bool dirty_;
 
-               //! The clipping area for the widget. 
+               //! The clipping area for the widget. This is also the size 
of 
+               //! the container.
                SDL_Rect clip_;
-       };
+
+       }; // class tchild
+
 public:
        class iterator 
        {




Related Messages


Powered by MHonArc, Updated Tue Mar 11 18:41:22 2008