core/vgui/vgui_debug_tableau.cxx
Go to the documentation of this file.
00001 // This is core/vgui/vgui_debug_tableau.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 // \file
00007 // \author Andrew W. Fitzgibbon, Oxford RRG
00008 // \date   08 Oct 1999
00009 // \brief  See vgui_debug_tableau.cxx for a description of this file.
00010 
00011 #include "vgui_debug_tableau.h"
00012 #include <vcl_iostream.h>
00013 #include <vgui/vgui_event.h>
00014 
00015 //-----------------------------------------------------------------------------
00016 //: Constructor - don't use this, use vgui_debug_tableau_new.
00017 //  Takes the one and only child of this tableau.
00018 vgui_debug_tableau::vgui_debug_tableau(vgui_tableau_sptr const& child_tableau):
00019   vgui_wrapper_tableau(child_tableau)
00020 {
00021   verbosity = 1;
00022 }
00023 
00024 //-----------------------------------------------------------------------------
00025 //: Destructor - called by vgui_debug_tableau_sptr.
00026 vgui_debug_tableau::~vgui_debug_tableau()
00027 {
00028 }
00029 
00030 //-----------------------------------------------------------------------------
00031 static void print_tableau(vcl_ostream& s, vcl_string indent, vgui_tableau_sptr t)
00032 {
00033   s << indent << t->pretty_name() << vcl_endl;
00034 
00035   // Print any children
00036   vcl_vector<vgui_tableau_sptr> children;
00037   t->get_children(&children);
00038 
00039   if (children.size() > 1)
00040     indent += "     ";
00041   else
00042     indent += " ";
00043 
00044   for (unsigned int i = 0; i < children.size(); ++i)
00045     print_tableau(s, indent, children[i]);
00046 }
00047 
00048 //-----------------------------------------------------------------------------
00049 static void print_tableau(vgui_tableau_sptr t)
00050 {
00051   print_tableau(vcl_cerr, __FILE__ ": ", t);
00052 }
00053 
00054 //-----------------------------------------------------------------------------
00055 //: Handle events by printing them and then forwarding to the child tableau.
00056 bool vgui_debug_tableau::handle(const vgui_event& e)
00057 {
00058   vgui_event e_in = e;
00059 
00060   // First run the event through the child :
00061   bool handled = child && child->handle(e);
00062 
00063   // Print the event
00064   bool print = (verbosity > 0);
00065   if (e.type == vgui_MOTION)
00066     print = (verbosity > 1);
00067   if (print)
00068     vcl_cerr << __FILE__ ": " << (handled ? "TOOK" : "left") << ": " << e << vcl_endl;
00069 
00070   if (!(e == e_in))
00071     vcl_cerr << __FILE__ ": The event changed !!!\n";
00072 
00073   // Handle our events
00074   // In general, we'd like a debug tableau to have no effect on its child,
00075   // so we pass the events through
00076   if (e.type == vgui_KEY_PRESS)
00077     switch (e.key) {
00078     case 'v':
00079       if (++verbosity > 2) verbosity = 0;
00080       vcl_cerr << __FILE__ ": verbosity = " << verbosity << vcl_endl;
00081       break;
00082     case 'p':
00083       print_tableau(this);
00084       break;
00085     default:
00086       break; // quell warning
00087     }
00088 
00089   return handled;
00090 }