Welcome to the NetCologne GmbH open source mirroring service!

This machine mirrors various open-source projects. 20 Gbit/s uplink.

If there are any issues or you want another project mirrored, please contact mirror-service -=AT=- netcologne DOT de !

gui_child_manager.cxx Source File
Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

gui_child_manager.cxx

Go to the documentation of this file.
00001 //  $Id: gui_child_manager.cxx,v 1.5 2003/01/11 19:07:48 grumbel Exp $
00002 //
00003 //  Construo - A wire-frame construction gamee
00004 //  Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
00005 //
00006 //  This program is free software; you can redistribute it and/or
00007 //  modify it under the terms of the GNU General Public License
00008 //  as published by the Free Software Foundation; either version 2
00009 //  of the License, or (at your option) any later version.
00010 //
00011 //  This program is distributed in the hope that it will be useful,
00012 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //  GNU General Public License for more details.
00015 //
00016 //  You should have received a copy of the GNU General Public License
00017 //  along with this program; if not, write to the Free Software
00018 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020 #include <algorithm>
00021 #include "graphic_context.hxx"
00022 #include "colors.hxx"
00023 #include "gui_child_manager.hxx"
00024 
00025 GUIChildManager::GUIChildManager (int x, int y, int width, int height)
00026   : GUIComponent (x, y, width, height)
00027 {
00028   current_component = 0;
00029 }
00030 
00031 GUIChildManager::~GUIChildManager ()
00032 {
00033   for (ComponentLst::iterator i = components.begin (); i != components.end (); ++i)
00034     {
00035       delete *i;
00036     }
00037 }
00038 
00039 void
00040 GUIChildManager::add (GUIComponent* comp)
00041 {
00042   components.push_back(comp);
00043 }
00044 
00045 void
00046 GUIChildManager::remove (GUIComponent* comp)
00047 {
00048   // FIXME: Memory leak
00049   components.erase(std::remove(components.begin(), components.end(), comp), components.end());
00050 }
00051 
00052 void
00053 GUIChildManager::replace(GUIComponent* old_comp, GUIComponent* new_comp)
00054 {
00055   for (ComponentLst::iterator i = components.begin(); i != components.end(); ++i)
00056     {
00057       if (*i == old_comp)
00058         {
00059           *i = new_comp;
00060           return;
00061         }
00062     }
00063 }
00064 
00065 void
00066 GUIChildManager::draw (GraphicContext* parent_gc)
00067 {
00068   gc.set_parent_gc (parent_gc);
00069   gc.set_offset (x_pos, y_pos);
00070   
00071   parent_gc->draw_fill_rect (x_pos, y_pos,
00072                              x_pos + width, y_pos + height, 
00073                              Colors::button_bg_passive);
00074   parent_gc->draw_rect (x_pos, y_pos,
00075                         x_pos + width, y_pos + height, 
00076                         Colors::button_fg_passive);
00077 
00078   parent_gc->draw_fill_rect (x_pos, y_pos,
00079                              x_pos + width, y_pos, 
00080                              Colors::button_bg_hover);
00081 
00082   parent_gc->draw_rect (x_pos, y_pos,
00083                         x_pos + width, y_pos, 
00084                         Colors::button_fg_passive);
00085 
00086   for (ComponentLst::reverse_iterator i = components.rbegin (); i != components.rend (); ++i)
00087     {
00088       (*i)->draw (&gc);
00089     }
00090 
00091   draw_overlay(parent_gc);
00092 }
00093 
00094 void
00095 GUIChildManager::on_primary_button_press (int x, int y)
00096 {
00097   for (ComponentLst::iterator i = components.begin (); i != components.end (); ++i)
00098     {
00099       if ((*i)->is_at (x - x_pos, y - y_pos))
00100         {
00101           (*i)->on_primary_button_press (x - x_pos, y - y_pos);
00102           return;
00103         }
00104     }
00105 }
00106 
00107 void
00108 GUIChildManager::on_primary_button_release (int x, int y)
00109 {
00110   for (ComponentLst::iterator i = components.begin (); i != components.end (); ++i)
00111     {
00112       if ((*i)->is_at (x - x_pos, y - y_pos))
00113         {
00114           (*i)->on_primary_button_release (x - x_pos, y - y_pos);
00115           return;
00116         }
00117     }
00118 }
00119 
00120 void
00121 GUIChildManager::on_secondary_button_press (int x, int y)
00122 {
00123   for (ComponentLst::iterator i = components.begin (); i != components.end (); ++i)
00124     {
00125       if ((*i)->is_at (x - x_pos, y - y_pos))
00126         {
00127           (*i)->on_secondary_button_press (x - x_pos, y - y_pos);
00128           return;
00129         }
00130     }
00131 }
00132 
00133 void
00134 GUIChildManager::on_secondary_button_release (int x, int y)
00135 {
00136   for (ComponentLst::iterator i = components.begin (); i != components.end (); ++i)
00137     {
00138       if ((*i)->is_at (x - x_pos, y - y_pos))
00139         {
00140           (*i)->on_secondary_button_release (x - x_pos, y - y_pos);
00141           return;
00142         }
00143     }
00144 }
00145   
00146 void
00147 GUIChildManager::on_delete_press (int x, int y)
00148 {
00149   for (ComponentLst::iterator i = components.begin (); i != components.end (); ++i)
00150     {
00151       if ((*i)->is_at (x - x_pos, y - y_pos))
00152         {
00153           (*i)->on_delete_press (x - x_pos, y - y_pos);
00154           return;
00155         }
00156     }
00157 }
00158 
00159 void
00160 GUIChildManager::on_fix_press (int x, int y)
00161 {
00162   for (ComponentLst::iterator i = components.begin (); i != components.end (); ++i)
00163     {
00164       if ((*i)->is_at (x - x_pos, y - y_pos))
00165         {
00166           (*i)->on_fix_press (x - x_pos, y - y_pos);
00167           return;
00168         }
00169     }
00170 }
00171 
00172 void
00173 GUIChildManager::on_mouse_enter ()
00174 {
00175 }
00176 
00177 void
00178 GUIChildManager::on_mouse_leave ()
00179 {
00180 }
00181 
00182 void
00183 GUIChildManager::wheel_up (int x, int y)
00184 {
00185   for (ComponentLst::iterator i = components.begin (); i != components.end (); ++i)
00186     {
00187       if ((*i)->is_at (x - x_pos, y - y_pos))
00188         {
00189           (*i)->wheel_up (x - x_pos, y - y_pos);
00190           return;
00191         }
00192     }
00193 }
00194 
00195 void
00196 GUIChildManager::wheel_down (int x, int y)
00197 {
00198   for (ComponentLst::iterator i = components.begin (); i != components.end (); ++i)
00199     {
00200       if ((*i)->is_at (x - x_pos, y - y_pos))
00201         {
00202           (*i)->wheel_down (x - x_pos, y - y_pos);
00203           return;
00204         }
00205     }
00206 }
00207 
00208 void
00209 GUIChildManager::scroll_left ()
00210 {
00211   /*  for (ComponentLst::iterator i = components.begin (); i != components.end (); ++i)
00212       {
00213       if ((*i)->is_at (x - x_pos, y - y_pos))
00214       {
00215       (*i)->scroll_left (x - x_pos, y - y_pos);
00216       return;
00217       }
00218       }*/
00219 }
00220 
00221 void
00222 GUIChildManager::scroll_right ()
00223 {
00224   /*
00225     for (ComponentLst::iterator i = components.begin (); i != components.end (); ++i)
00226     {
00227     if ((*i)->is_at (x - x_pos, y - y_pos))
00228     {
00229     (*i)->scroll_right (x - x_pos, y - y_pos);
00230     return;
00231     }
00232     }*/
00233 }
00234 
00235 void
00236 GUIChildManager::scroll_up ()
00237 {
00238   /*  for (ComponentLst::iterator i = components.begin (); i != components.end (); ++i)
00239       {
00240       if ((*i)->is_at (x - x_pos, y - y_pos))
00241       {
00242       (*i)->scroll_down (x - x_pos, y - y_pos);
00243       return;
00244       }
00245       }*/
00246 }
00247 
00248 void
00249 GUIChildManager::scroll_down ()
00250 {
00251   /*
00252     for (ComponentLst::iterator i = components.begin (); i != components.end (); ++i)
00253     {
00254     if ((*i)->is_at (x - x_pos, y - y_pos))
00255     {
00256     (*i)->scroll_down (x - x_pos, y - y_pos);
00257     return;
00258     }
00259     }*/
00260 }
00261 
00262 void
00263 GUIChildManager::on_mouse_move (int x, int y, int of_x, int of_y)
00264 {
00265   GUIComponent* comp = find_component_at (x, y);
00266   //std::cout << " MouseMove: " << x << " " << y << " " << comp << std::endl;
00267 
00268   if (comp != current_component)
00269     {
00270       if (comp) comp->on_mouse_enter();
00271       if (current_component) current_component->on_mouse_leave();
00272       current_component = comp;
00273     }
00274   else if (comp)
00275     comp->on_mouse_move(x, y, of_x, of_y);
00276 }
00277 
00278 GUIComponent* 
00279 GUIChildManager::find_component_at (int x, int y)
00280 {
00281   for (ComponentLst::iterator i = components.begin (); i != components.end (); ++i)
00282     {
00283       if ((*i)->is_at (x - x_pos, y - y_pos))
00284         {
00285           return *i;
00286         }
00287     }
00288   return 0;
00289 }
00290 
00291 /* EOF */

Generated on Thu Jul 24 10:24:30 2003 for Construo by doxygen1.3-rc3