OpenMW
apps/openmw/mwgui/console.hpp
Go to the documentation of this file.
00001 #ifndef MWGUI_CONSOLE_H
00002 #define MWGUI_CONSOLE_H
00003 
00004 #include <list>
00005 #include <string>
00006 #include <vector>
00007 
00008 #include <components/compiler/errorhandler.hpp>
00009 #include <components/compiler/lineparser.hpp>
00010 #include <components/compiler/scanner.hpp>
00011 #include <components/compiler/locals.hpp>
00012 #include <components/compiler/output.hpp>
00013 #include <components/compiler/extensions.hpp>
00014 #include <components/interpreter/interpreter.hpp>
00015 
00016 #include "../mwscript/compilercontext.hpp"
00017 #include "../mwscript/interpretercontext.hpp"
00018 
00019 #include "referenceinterface.hpp"
00020 #include "windowbase.hpp"
00021 
00022 namespace MWGui
00023 {
00024   class Console : public WindowBase, private Compiler::ErrorHandler, public ReferenceInterface
00025   {
00026     private:
00027 
00028         Compiler::Extensions mExtensions;
00029         MWScript::CompilerContext mCompilerContext;
00030         std::vector<std::string> mNames;
00031         bool mConsoleOnlyScripts;
00032 
00033         bool compile (const std::string& cmd, Compiler::Output& output);
00034 
00036         virtual void report (const std::string& message, const Compiler::TokenLoc& loc, Type type);
00037 
00039         virtual void report (const std::string& message, Type type);
00040 
00041         void listNames();
00046 
00047     public:
00048 
00049         void setSelectedObject(const MWWorld::Ptr& object);
00051 
00052     protected:
00053 
00054         virtual void onReferenceUnavailable();
00055 
00056 
00057     public:
00058     MyGUI::EditBox* mCommandLine;
00059     MyGUI::EditBox* mHistory;
00060 
00061     typedef std::list<std::string> StringList;
00062 
00063     // History of previous entered commands
00064     StringList mCommandHistory;
00065     StringList::iterator mCurrent;
00066     std::string mEditString;
00067 
00068     Console(int w, int h, bool consoleOnlyScripts);
00069 
00070     virtual void open();
00071     virtual void close();
00072 
00073     void setFont(const std::string &fntName);
00074 
00075     void onResChange(int width, int height);
00076 
00077     void clearHistory();
00078 
00079     // Print a message to the console. Messages may contain color
00080     // code, eg. "#FFFFFF this is white".
00081     void print(const std::string &msg);
00082 
00083     // These are pre-colored versions that you should use.
00084 
00086     void printOK(const std::string &msg);
00087 
00089     void printError(const std::string &msg);
00090 
00091     void execute (const std::string& command);
00092 
00093     void executeFile (const std::string& path);
00094 
00095   private:
00096 
00097     void keyPress(MyGUI::Widget* _sender,
00098                   MyGUI::KeyCode key,
00099                   MyGUI::Char _char);
00100 
00101     void acceptCommand(MyGUI::EditBox* _sender);
00102 
00103     std::string complete( std::string input, std::vector<std::string> &matches );
00104   };
00105 }
00106 #endif