Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
groupcontrol.cpp
Go to the documentation of this file.
1 /*
2  * Vega Strike
3  * Copyright (C) 2003 Mike Byron
4  *
5  * http://vegastrike.sourceforge.net/
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */
21 
22 #include "vegastrike.h"
23 
24 #include "groupcontrol.h"
25 
26 #include "eventmanager.h"
27 
28 #include "window.h"
29 
30 //Add a new control to this collection.
32 {
33  m_controls.push_back( child );
34 }
35 
36 //Delete a control that is in this collection.
37 //Returns true if successful.
39 {
40  std::vector< Control* >::iterator iter;
41  for (iter = m_controls.begin(); iter != m_controls.end(); iter++) {
42  Control *currentControl = *iter;
43  if (c == currentControl) {
44  //Found it in this group.
45  m_controls.erase( iter );
46  EventManager::addToDeleteQueue( currentControl );
47  return true;
48  }
49  if ( currentControl->hasGroupChildren() ) {
50  //Check the children.
51  GroupControl *group = static_cast< GroupControl* > (currentControl);
52  if ( group->deleteControl( c ) )
53  return true;
54  }
55  }
56  return false;
57 }
58 
59 //Take a control away from this collection and save it elsewhere.
61 {
62  std::vector< Control* >::iterator iter;
63  for (iter = m_controls.begin(); iter != m_controls.end(); iter++) {
64  Control *currentControl = *iter;
65  if (c == currentControl) {
66  //Found it in this group.
67  m_controls.erase( iter );
68  return currentControl;
69  }
70  if ( currentControl->hasGroupChildren() ) {
71  //Check the children.
72  GroupControl *group = static_cast< GroupControl* > (currentControl);
73  Control *ret = group->removeControlFromGroup( c );
74  if (ret)
75  return ret;
76  }
77  }
78  return NULL;
79 }
80 
81 //Find a control using its id. NULL returned if none found.
82 //Note that the control may be hidden.
83 Control* GroupControl::findControlById( const std::string &id )
84 {
85  std::vector< Control* >::iterator iter;
86  for (iter = m_controls.begin(); iter != m_controls.end(); iter++) {
87  Control *currentControl = *iter;
88  if (currentControl->id() == id)
89  //Found it in this group.
90  return currentControl;
91  if ( currentControl->hasGroupChildren() ) {
92  //Check the children.
93  GroupControl *group = static_cast< GroupControl* > (currentControl);
94  Control *ret = group->findControlById( id );
95  if (ret)
96  return ret;
97  }
98  }
99  return NULL;
100 }
101 
102 //Draw the control.
103 //This should not draw outside its rectangle!
104 void GroupControl::draw( void )
105 {
106  std::vector< Control* >::iterator iter;
107  for (iter = m_controls.begin(); iter != m_controls.end(); iter++) {
108  Control *currentControl = *iter;
109  if ( !currentControl->hidden() )
110  //If it's not hidden, draw it.
111  currentControl->draw();
112  }
113 }
114 
115 //OVERRIDES
117 {
118  std::vector< Control* >::reverse_iterator iter;
119  bool retval = false;
120  //Give this to the appropriate control.
121  for (iter = m_controls.rbegin(); iter != m_controls.rend(); iter++) {
122  Control &control = **iter;
123  if ( !control.hidden() ) {
124  if (control.hasGroupChildren() && !retval) {
125  //Do children first.
126  GroupControl &group = static_cast< GroupControl& > (control);
127  retval = group.processMouseDown( event );
128  }
129  if (control.hitTest( event.loc ) && !retval)
130  retval = control.processMouseDown( event );
131  else
132  control.processUnfocus( event );
133  }
134  }
135  return retval;
136 }
137 
139 {
140  std::vector< Control* >::reverse_iterator iter;
141  //Give this to the appropriate control.
142  for (iter = m_controls.rbegin(); iter != m_controls.rend(); iter++) {
143  Control &control = **iter;
144  if ( !control.hidden() ) {
145  if ( control.hasGroupChildren() ) {
146  //Do children first.
147  GroupControl &group = static_cast< GroupControl& > (control);
148  if ( group.processMouseUp( event ) )
149  return true;
150  }
151  if ( control.hitTest( event.loc ) )
152  return control.processMouseUp( event );
153  }
154  }
155  return false;
156 }
157 
159 {
160  std::vector< Control* >::reverse_iterator iter;
161  //Give this to the appropriate control.
162  for (iter = m_controls.rbegin(); iter != m_controls.rend(); iter++) {
163  Control &control = **iter;
164  if ( !control.hidden() ) {
165  if ( control.hasGroupChildren() ) {
166  //Do children first.
167  GroupControl &group = static_cast< GroupControl& > (control);
168  if ( group.processMouseMove( event ) )
169  return true;
170  }
171  if ( control.hitTest( event.loc ) )
172  return control.processMouseMove( event );
173  }
174  }
175  return false;
176 }
177 
179 {
180  std::vector< Control* >::reverse_iterator iter;
181  //Give this to the appropriate control.
182  for (iter = m_controls.rbegin(); iter != m_controls.rend(); iter++) {
183  Control &control = **iter;
184  if ( !control.hidden() ) {
185  if ( control.hasGroupChildren() ) {
186  //Do children first.
187  GroupControl &group = static_cast< GroupControl& > (control);
188  if ( group.processMouseDrag( event ) )
189  return true;
190  }
191  if ( control.hitTest( event.loc ) )
192  return control.processMouseDrag( event );
193  }
194  }
195  return false;
196 }
197 
199 {
200  for (vector< Control* >::size_type i = 0; i < m_controls.size(); ++i)
202 }
203