1 // $Id: gui_child_manager.cxx,v 1.5 2003/01/11 19:07:48 grumbel Exp $
3 // Construo - A wire-frame construction gamee
4 // Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
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.
21 #include "graphic_context.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
)
40 GUIChildManager::add (GUIComponent
* comp
)
42 components
.push_back(comp
);
46 GUIChildManager::remove (GUIComponent
* comp
)
49 components
.erase(std::remove(components
.begin(), components
.end(), comp
), components
.end());
53 GUIChildManager::replace(GUIComponent
* old_comp
, GUIComponent
* new_comp
)
55 for (ComponentLst::iterator i
= components
.begin(); i
!= components
.end(); ++i
)
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
,
80 Colors::button_bg_hover
);
82 parent_gc
->draw_rect (x_pos
, y_pos
,
84 Colors::button_fg_passive
);
86 for (ComponentLst::reverse_iterator i
= components
.rbegin (); i
!= components
.rend (); ++i
)
91 draw_overlay(parent_gc
);
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
);
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
);
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
);
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
);
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
);
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
);
173 GUIChildManager::on_mouse_enter ()
178 GUIChildManager::on_mouse_leave ()
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
);
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
);
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);
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);
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);
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);
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
;
275 comp
->on_mouse_move(x
, y
, of_x
, of_y
);
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
))