Rebuild autotool system
[construo.git] / gui_child_manager.cxx
blob8f9eac6655935eeff74de7fee1408721dff6e2dc
1 // $Id: gui_child_manager.cxx,v 1.5 2003/01/11 19:07:48 grumbel Exp $
2 //
3 // Construo - A wire-frame construction gamee
4 // Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include <algorithm>
21 #include "graphic_context.hxx"
22 #include "colors.hxx"
23 #include "gui_child_manager.hxx"
25 GUIChildManager::GUIChildManager (int x, int y, int width, int height)
26 : GUIComponent (x, y, width, height)
28 current_component = 0;
31 GUIChildManager::~GUIChildManager ()
33 for (ComponentLst::iterator i = components.begin (); i != components.end (); ++i)
35 delete *i;
39 void
40 GUIChildManager::add (GUIComponent* comp)
42 components.push_back(comp);
45 void
46 GUIChildManager::remove (GUIComponent* comp)
48 // FIXME: Memory leak
49 components.erase(std::remove(components.begin(), components.end(), comp), components.end());
52 void
53 GUIChildManager::replace(GUIComponent* old_comp, GUIComponent* new_comp)
55 for (ComponentLst::iterator i = components.begin(); i != components.end(); ++i)
57 if (*i == old_comp)
59 *i = new_comp;
60 return;
65 void
66 GUIChildManager::draw (GraphicContext* parent_gc)
68 gc.set_parent_gc (parent_gc);
69 gc.set_offset (x_pos, y_pos);
71 parent_gc->draw_fill_rect (x_pos, y_pos,
72 x_pos + width, y_pos + height,
73 Colors::button_bg_passive);
74 parent_gc->draw_rect (x_pos, y_pos,
75 x_pos + width, y_pos + height,
76 Colors::button_fg_passive);
78 parent_gc->draw_fill_rect (x_pos, y_pos,
79 x_pos + width, y_pos,
80 Colors::button_bg_hover);
82 parent_gc->draw_rect (x_pos, y_pos,
83 x_pos + width, y_pos,
84 Colors::button_fg_passive);
86 for (ComponentLst::reverse_iterator i = components.rbegin (); i != components.rend (); ++i)
88 (*i)->draw (&gc);
91 draw_overlay(parent_gc);
94 void
95 GUIChildManager::on_primary_button_press (int x, int y)
97 for (ComponentLst::iterator i = components.begin (); i != components.end (); ++i)
99 if ((*i)->is_at (x - x_pos, y - y_pos))
101 (*i)->on_primary_button_press (x - x_pos, y - y_pos);
102 return;
107 void
108 GUIChildManager::on_primary_button_release (int x, int y)
110 for (ComponentLst::iterator i = components.begin (); i != components.end (); ++i)
112 if ((*i)->is_at (x - x_pos, y - y_pos))
114 (*i)->on_primary_button_release (x - x_pos, y - y_pos);
115 return;
120 void
121 GUIChildManager::on_secondary_button_press (int x, int y)
123 for (ComponentLst::iterator i = components.begin (); i != components.end (); ++i)
125 if ((*i)->is_at (x - x_pos, y - y_pos))
127 (*i)->on_secondary_button_press (x - x_pos, y - y_pos);
128 return;
133 void
134 GUIChildManager::on_secondary_button_release (int x, int y)
136 for (ComponentLst::iterator i = components.begin (); i != components.end (); ++i)
138 if ((*i)->is_at (x - x_pos, y - y_pos))
140 (*i)->on_secondary_button_release (x - x_pos, y - y_pos);
141 return;
146 void
147 GUIChildManager::on_delete_press (int x, int y)
149 for (ComponentLst::iterator i = components.begin (); i != components.end (); ++i)
151 if ((*i)->is_at (x - x_pos, y - y_pos))
153 (*i)->on_delete_press (x - x_pos, y - y_pos);
154 return;
159 void
160 GUIChildManager::on_fix_press (int x, int y)
162 for (ComponentLst::iterator i = components.begin (); i != components.end (); ++i)
164 if ((*i)->is_at (x - x_pos, y - y_pos))
166 (*i)->on_fix_press (x - x_pos, y - y_pos);
167 return;
172 void
173 GUIChildManager::on_mouse_enter ()
177 void
178 GUIChildManager::on_mouse_leave ()
182 void
183 GUIChildManager::wheel_up (int x, int y)
185 for (ComponentLst::iterator i = components.begin (); i != components.end (); ++i)
187 if ((*i)->is_at (x - x_pos, y - y_pos))
189 (*i)->wheel_up (x - x_pos, y - y_pos);
190 return;
195 void
196 GUIChildManager::wheel_down (int x, int y)
198 for (ComponentLst::iterator i = components.begin (); i != components.end (); ++i)
200 if ((*i)->is_at (x - x_pos, y - y_pos))
202 (*i)->wheel_down (x - x_pos, y - y_pos);
203 return;
208 void
209 GUIChildManager::scroll_left ()
211 /* for (ComponentLst::iterator i = components.begin (); i != components.end (); ++i)
213 if ((*i)->is_at (x - x_pos, y - y_pos))
215 (*i)->scroll_left (x - x_pos, y - y_pos);
216 return;
221 void
222 GUIChildManager::scroll_right ()
225 for (ComponentLst::iterator i = components.begin (); i != components.end (); ++i)
227 if ((*i)->is_at (x - x_pos, y - y_pos))
229 (*i)->scroll_right (x - x_pos, y - y_pos);
230 return;
235 void
236 GUIChildManager::scroll_up ()
238 /* for (ComponentLst::iterator i = components.begin (); i != components.end (); ++i)
240 if ((*i)->is_at (x - x_pos, y - y_pos))
242 (*i)->scroll_down (x - x_pos, y - y_pos);
243 return;
248 void
249 GUIChildManager::scroll_down ()
252 for (ComponentLst::iterator i = components.begin (); i != components.end (); ++i)
254 if ((*i)->is_at (x - x_pos, y - y_pos))
256 (*i)->scroll_down (x - x_pos, y - y_pos);
257 return;
262 void
263 GUIChildManager::on_mouse_move (int x, int y, int of_x, int of_y)
265 GUIComponent* comp = find_component_at (x, y);
266 //std::cout << " MouseMove: " << x << " " << y << " " << comp << std::endl;
268 if (comp != current_component)
270 if (comp) comp->on_mouse_enter();
271 if (current_component) current_component->on_mouse_leave();
272 current_component = comp;
274 else if (comp)
275 comp->on_mouse_move(x, y, of_x, of_y);
278 GUIComponent*
279 GUIChildManager::find_component_at (int x, int y)
281 for (ComponentLst::iterator i = components.begin (); i != components.end (); ++i)
283 if ((*i)->is_at (x - x_pos, y - y_pos))
285 return *i;
288 return 0;
291 /* EOF */