Minor Console fixes

This commit is contained in:
Phillip Stephens 2018-12-09 21:12:10 -08:00
parent 7a68a5350b
commit f776f89bee
2 changed files with 19 additions and 7 deletions

View File

@ -47,7 +47,8 @@ public:
enum State { Closed, Closing, Opened, Opening }; enum State { Closed, Closing, Opened, Opening };
private: private:
CVarManager* m_cvarMgr; CVarManager* m_cvarMgr = nullptr;
boo::IWindow* m_window = nullptr;
std::unordered_map<std::string, SConsoleCommand> m_commands; std::unordered_map<std::string, SConsoleCommand> m_commands;
std::vector<std::pair<std::string, Level>> m_log; std::vector<std::pair<std::string, Level>> m_log;
int m_logOffset; int m_logOffset;
@ -82,6 +83,7 @@ public:
void report(Level level, const char* fmt, va_list list); void report(Level level, const char* fmt, va_list list);
void report(Level level, const char* fmt, ...); void report(Level level, const char* fmt, ...);
void init(boo::IWindow* ctx);
void proc(); void proc();
void draw(boo::IGraphicsCommandQueue* gfxQ); void draw(boo::IGraphicsCommandQueue* gfxQ);
void handleCharCode(unsigned long chr, boo::EModifierKey mod, bool repeat); void handleCharCode(unsigned long chr, boo::EModifierKey mod, bool repeat);

View File

@ -1,7 +1,11 @@
#include <hecl/Console.hpp>
#include "hecl/Console.hpp" #include "hecl/Console.hpp"
#include "hecl/CVarManager.hpp" #include "hecl/CVarManager.hpp"
#include "hecl/CVar.hpp" #include "hecl/CVar.hpp"
#include "hecl/hecl.hpp" #include "hecl/hecl.hpp"
#include "boo/graphicsdev/IGraphicsCommandQueue.hpp"
#include "athena/Utility.hpp" #include "athena/Utility.hpp"
namespace hecl { namespace hecl {
@ -167,6 +171,9 @@ void Console::report(Level level, const char* fmt, ...) {
report(level, fmt, ap); report(level, fmt, ap);
va_end(ap); va_end(ap);
} }
void Console::init(boo::IWindow* window) {
m_window = window;
}
void Console::proc() { void Console::proc() {
if (m_conHeight->isModified()) { if (m_conHeight->isModified()) {
@ -184,8 +191,10 @@ void Console::proc() {
fflush(stdout); fflush(stdout);
} else if (m_state == State::Opening) } else if (m_state == State::Opening)
m_state = State::Opened; m_state = State::Opened;
else if (m_state == State::Closing) else if (m_state == State::Closing) {
m_state = State::Closed; m_state = State::Closed;
m_commandString.clear();
}
if (m_cursorPosition > int(m_commandString.size() - 1)) if (m_cursorPosition > int(m_commandString.size() - 1))
m_cursorPosition = int(m_commandString.size() - 1); m_cursorPosition = int(m_commandString.size() - 1);
@ -198,7 +207,8 @@ void Console::proc() {
m_logOffset = 0; m_logOffset = 0;
} }
void Console::draw(boo::IGraphicsCommandQueue* /*gfxQ*/) {} void Console::draw(boo::IGraphicsCommandQueue* /* gfxQ */) {
}
void Console::handleCharCode(unsigned long chr, boo::EModifierKey /*mod*/, bool /*repeat*/) { void Console::handleCharCode(unsigned long chr, boo::EModifierKey /*mod*/, bool /*repeat*/) {
if (chr == U'`' || chr == U'~') { if (chr == U'`' || chr == U'~') {
@ -231,7 +241,7 @@ void Console::handleSpecialKeyDown(boo::ESpecialKey sp, boo::EModifierKey mod, b
break; break;
case boo::ESpecialKey::Backspace: { case boo::ESpecialKey::Backspace: {
if (!m_commandString.empty()) { if (!m_commandString.empty()) {
if (int(mod & boo::EModifierKey::Ctrl) != 0) { if ((mod & boo::EModifierKey::Ctrl) != boo::EModifierKey::None) {
size_t index = m_commandString.rfind(' ', size_t(m_cursorPosition - 1)); size_t index = m_commandString.rfind(' ', size_t(m_cursorPosition - 1));
if (index == std::string::npos) { if (index == std::string::npos) {
@ -257,7 +267,7 @@ void Console::handleSpecialKeyDown(boo::ESpecialKey sp, boo::EModifierKey mod, b
if ((m_cursorPosition + 1) >= int(m_commandString.size())) if ((m_cursorPosition + 1) >= int(m_commandString.size()))
break; break;
if (int(mod & boo::EModifierKey::Ctrl) != 0) { if ((mod & boo::EModifierKey::Ctrl) != boo::EModifierKey::None) {
size_t index = m_commandString.find_first_of(' ', size_t(m_cursorPosition + 1)); size_t index = m_commandString.find_first_of(' ', size_t(m_cursorPosition + 1));
if (index != std::string::npos) if (index != std::string::npos)
m_commandString.erase(size_t(m_cursorPosition + 1), index + 1); m_commandString.erase(size_t(m_cursorPosition + 1), index + 1);
@ -293,7 +303,7 @@ void Console::handleSpecialKeyDown(boo::ESpecialKey sp, boo::EModifierKey mod, b
if (m_cursorPosition < 0) if (m_cursorPosition < 0)
break; break;
if (int(mod & boo::EModifierKey::Ctrl) != 0) if ((mod & boo::EModifierKey::Ctrl) != boo::EModifierKey::None)
m_cursorPosition = int(m_commandString.rfind(' ', size_t(m_cursorPosition) - 1)); m_cursorPosition = int(m_commandString.rfind(' ', size_t(m_cursorPosition) - 1));
else else
m_cursorPosition--; m_cursorPosition--;
@ -306,7 +316,7 @@ void Console::handleSpecialKeyDown(boo::ESpecialKey sp, boo::EModifierKey mod, b
if (m_cursorPosition >= int(m_commandString.size() - 1)) if (m_cursorPosition >= int(m_commandString.size() - 1))
break; break;
if (int(mod & boo::EModifierKey::Ctrl) != 0) { if ((mod & boo::EModifierKey::Ctrl) != boo::EModifierKey::None) {
if (m_commandString[size_t(m_cursorPosition)] == ' ') if (m_commandString[size_t(m_cursorPosition)] == ' ')
m_cursorPosition++; m_cursorPosition++;