gui/dialogs/formula_debugger.cpp

Go to the documentation of this file.
00001 /* $Id: formula_debugger.cpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2009 - 2012 by Yurii Chernyi <terraninfo@terraninfo.net>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 #define GETTEXT_DOMAIN "wesnoth-lib"
00017 
00018 #include "gui/dialogs/formula_debugger.hpp"
00019 
00020 #include "gui/dialogs/helper.hpp"
00021 #include "gui/widgets/button.hpp"
00022 #include "gui/widgets/settings.hpp"
00023 #include "gui/widgets/window.hpp"
00024 #include "../../foreach.hpp"
00025 #include "../../formula_debugger.hpp"
00026 
00027 #include <boost/bind.hpp>
00028 
00029 namespace gui2 {
00030 
00031 /*WIKI
00032  * @page = GUIWindowDefinitionWML
00033  * @order = 2_formula_debugger
00034  *
00035  * == Formula debugger ==
00036  *
00037  * This shows the debugger for the formulas.
00038  *
00039  * @begin{table}{dialog_widgets}
00040  *
00041  * stack & & control & m &
00042  *         A stack. $
00043  *
00044  * execution & & control & m &
00045  *         Execution trace label. $
00046  *
00047  * state & & control & m &
00048  *         The state. $
00049  *
00050  * step & & button & m &
00051  *         Button to step into the execution. $
00052  *
00053  * stepout & & button & m &
00054  *         Button to step out of the execution. $
00055  *
00056  * next & & button & m &
00057  *         Button to execute the next statement. $
00058  *
00059  * continue & & button & m &
00060  *         Button to continue the execution. $
00061  *
00062  * @end{table}
00063  */
00064 
00065 REGISTER_DIALOG(formula_debugger)
00066 
00067 void tformula_debugger::pre_show(CVideo& /*video*/, twindow& window)
00068 {
00069     // stack label
00070     tcontrol* stack_label = find_widget<tcontrol>(
00071             &window, "stack", false, true);
00072 
00073     std::stringstream stack_text;
00074     std::string indent = "  ";
00075     int c = 0;
00076     foreach (const game_logic::debug_info &i, fdb_.get_call_stack()) {
00077         for(int d = 0; d < c; ++d) {
00078             stack_text << indent;
00079         }
00080         stack_text << "#<span color=\"green\">" << i.counter()
00081                 <<"</span>: \"<span color=\"green\">"<< i.name()
00082                 << "</span>\": '" << i.str() << "' " << std::endl;
00083         ++c;
00084     }
00085 
00086     stack_label->set_use_markup(true);
00087     stack_label->set_label(stack_text.str());
00088     window.keyboard_capture(stack_label);
00089 
00090     // execution trace label
00091     tcontrol* execution_label = find_widget<tcontrol>(
00092             &window, "execution", false, true);
00093 
00094     std::stringstream execution_text;
00095     foreach (const game_logic::debug_info &i, fdb_.get_execution_trace()) {
00096         for(int d = 0; d < i.level(); ++d) {
00097             execution_text << indent;
00098         }
00099         if(!i.evaluated()) {
00100             execution_text << "#<span color=\"green\">" << i.counter()
00101                     << "</span>: \"<span color=\"green\">" << i.name()
00102                     << "</span>\": '" << i.str() << "' " << std::endl;
00103         } else {
00104             execution_text << "#<span color=\"yellow\">" << i.counter()
00105                     << "</span>: \"<span color=\"yellow\">" << i.name()
00106                     << "</span>\": '" << i.str() << "' = "
00107                     << "<span color=\"red\">"
00108                     << i.value().to_debug_string(NULL,false)
00109                     <<"</span>" << std::endl;
00110         }
00111     }
00112 
00113     execution_label->set_use_markup(true);
00114     execution_label->set_label(execution_text.str());
00115 
00116     // state
00117     std::string state_str;
00118     bool is_end = false;
00119     if(!fdb_.get_current_breakpoint()) {
00120         state_str = "";
00121     } else {
00122         state_str = fdb_.get_current_breakpoint()->name();
00123             if(state_str=="End") {
00124             is_end = true;
00125         }
00126     }
00127 
00128     find_widget<tcontrol>(&window, "state", false).set_label(state_str);
00129 
00130     // callbacks
00131     tbutton& step_button = find_widget<tbutton>(&window, "step", false);
00132     connect_signal_mouse_left_click(step_button, boost::bind(
00133               &tformula_debugger::callback_step_button
00134             , this
00135             , boost::ref(window)));
00136 
00137     tbutton& stepout_button = find_widget<tbutton>(&window, "stepout", false);
00138     connect_signal_mouse_left_click(stepout_button, boost::bind(
00139               &tformula_debugger::callback_stepout_button
00140             , this
00141             , boost::ref(window)));
00142 
00143     tbutton& next_button = find_widget<tbutton>(&window, "next", false);
00144     connect_signal_mouse_left_click(next_button, boost::bind(
00145               &tformula_debugger::callback_next_button
00146             , this
00147             , boost::ref(window)));
00148 
00149     tbutton& continue_button = find_widget<tbutton>(&window, "continue", false);
00150     connect_signal_mouse_left_click(continue_button, boost::bind(
00151               &tformula_debugger::callback_continue_button
00152             , this
00153             , boost::ref(window)));
00154 
00155     if(is_end) {
00156         step_button.set_active(false);
00157         stepout_button.set_active(false);
00158         next_button.set_active(false);
00159         continue_button.set_active(false);
00160     }
00161 }
00162 
00163 void tformula_debugger::callback_continue_button(twindow& window)
00164 {
00165     fdb_.add_breakpoint_continue_to_end();
00166     window.set_retval(twindow::OK);
00167 }
00168 
00169 void tformula_debugger::callback_next_button(twindow& window)
00170 {
00171     fdb_.add_breakpoint_next();
00172     window.set_retval(twindow::OK);
00173 }
00174 
00175 void tformula_debugger::callback_step_button(twindow& window)
00176 {
00177     fdb_.add_breakpoint_step_into();
00178     window.set_retval(twindow::OK);
00179 }
00180 
00181 void tformula_debugger::callback_stepout_button(twindow& window)
00182 {
00183     fdb_.add_breakpoint_step_out();
00184     window.set_retval(twindow::OK);
00185 }
00186 
00187 } //end of namespace gui2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:51 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs