added history in shell
This commit is contained in:
parent
b2a71429c9
commit
33378ef8de
@ -19,10 +19,11 @@ TextInputNode::TextInputNode(glm::vec2 dimension):
|
||||
m_cursor_mesh(nullptr),
|
||||
m_cursor_pos(0),
|
||||
m_cursor_pos_updated(false),
|
||||
m_move_cursor_left(NO_ACTION),
|
||||
m_move_cursor_right(NO_ACTION),
|
||||
m_callback(nullptr),
|
||||
m_tab_callback(nullptr)
|
||||
m_tab_callback(nullptr),
|
||||
m_history(std::vector<std::string>()),
|
||||
m_history_pos(0),
|
||||
m_inputActions({NO_ACTION, NO_ACTION, NO_ACTION, NO_ACTION})
|
||||
{
|
||||
// Font *shellfont = RESOURCE_GET(Font,"shellfont");
|
||||
Mesh* mesh = new Mesh();
|
||||
@ -44,18 +45,46 @@ void TextInputNode::update()
|
||||
|
||||
auto input = getEngine().getInput();
|
||||
for(auto action : input->getActions()){
|
||||
if (action.action == m_move_cursor_left){
|
||||
if (action.action == m_inputActions[MOVE_CURSOR_LEFT]){
|
||||
if (m_cursor_pos > 0){
|
||||
m_cursor_pos--;
|
||||
m_cursor_pos_updated=true;
|
||||
}
|
||||
}
|
||||
else if(action.action == m_move_cursor_right){
|
||||
else if(action.action == m_inputActions[MOVE_CURSOR_RIGHT]){
|
||||
if(m_cursor_pos < m_text.length()){
|
||||
m_cursor_pos++;
|
||||
m_cursor_pos_updated=true;
|
||||
}
|
||||
}
|
||||
else if(action.action == m_inputActions[HISTORY_PREVIOUS]){
|
||||
if(m_history_pos > 0)
|
||||
{
|
||||
m_history_pos--;
|
||||
m_text = m_history[m_history_pos];
|
||||
m_cursor_pos = m_text.size();
|
||||
m_text_updated = true;
|
||||
m_cursor_pos_updated = true;
|
||||
}
|
||||
}
|
||||
else if(action.action == m_inputActions[HISTORY_NEXT]){
|
||||
if (m_history_pos < m_history.size())
|
||||
{
|
||||
m_history_pos++;
|
||||
if (m_history_pos == m_history.size())
|
||||
{
|
||||
m_text.clear();
|
||||
m_cursor_pos = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_text = m_history[m_history_pos];
|
||||
m_cursor_pos = m_text.size();
|
||||
}
|
||||
m_text_updated = true;
|
||||
m_cursor_pos_updated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(unsigned int i = 0 ; i < text.length() ; i++){
|
||||
@ -150,3 +179,18 @@ std::string TextInputNode::getText()
|
||||
return m_text;
|
||||
}
|
||||
|
||||
void TextInputNode::clearText()
|
||||
{
|
||||
m_history.push_back(m_text);
|
||||
m_history_pos++;
|
||||
m_text.clear();
|
||||
}
|
||||
|
||||
void TextInputNode::setInputs(int cursor_left, int cursor_right, int history_up, int history_down)
|
||||
{
|
||||
m_inputActions[TextInputAction::MOVE_CURSOR_LEFT] = cursor_left;
|
||||
m_inputActions[TextInputAction::MOVE_CURSOR_RIGHT] = cursor_right;
|
||||
m_inputActions[TextInputAction::HISTORY_NEXT] = history_down;
|
||||
m_inputActions[TextInputAction::HISTORY_PREVIOUS] = history_up;
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,15 @@
|
||||
#include "scene/textnode.h"
|
||||
#include "scene/gui/callback.h"
|
||||
|
||||
/*
|
||||
struct TextInputAction{
|
||||
int cursor_left;
|
||||
int cursor_right;
|
||||
int history_next;
|
||||
int history_previous;
|
||||
};
|
||||
*/
|
||||
|
||||
class TextInputNode : public GUINode
|
||||
{
|
||||
glm::vec2 m_dimension;
|
||||
@ -22,12 +31,16 @@ class TextInputNode : public GUINode
|
||||
unsigned int m_cursor_pos;
|
||||
bool m_cursor_pos_updated;
|
||||
|
||||
int m_move_cursor_left;
|
||||
int m_move_cursor_right;
|
||||
|
||||
CallBack* m_callback;
|
||||
CallBack* m_tab_callback;
|
||||
|
||||
std::vector<std::string> m_history;
|
||||
unsigned int m_history_pos;
|
||||
|
||||
std::vector<int> m_inputActions;
|
||||
|
||||
enum TextInputAction {MOVE_CURSOR_LEFT,MOVE_CURSOR_RIGHT,HISTORY_PREVIOUS,HISTORY_NEXT};
|
||||
|
||||
public:
|
||||
TextInputNode(glm::vec2 dimension);
|
||||
void update();
|
||||
@ -41,9 +54,10 @@ public:
|
||||
std::string getText();
|
||||
void setCallBack(CallBack* callback){m_callback = callback;}
|
||||
void setTabCallBack(CallBack* callback){m_tab_callback = callback;}
|
||||
void setMoveCursorLeft(int action){m_move_cursor_left = action;}
|
||||
void setMoveCursorRight(int action){m_move_cursor_right = action;}
|
||||
void clearText(){m_text.clear();}
|
||||
|
||||
void setInputs(int cursor_left, int cursor_right, int history_up, int history_down);
|
||||
|
||||
void clearText();
|
||||
};
|
||||
|
||||
#endif // TEXTINPUTNODE_H
|
||||
|
@ -24,8 +24,7 @@ const float SparrowShell::DEFAULT_FONT_SIZE = 16.f;
|
||||
|
||||
SparrowShell::SparrowShell(sf::Window* window):
|
||||
m_buffer(new ShellBuffer(BUFFER_MAX_LENGTH)),
|
||||
m_text_color(glm::vec3(0.7,1,0.3)),
|
||||
m_inputActions({NO_ACTION, NO_ACTION, NO_ACTION, NO_ACTION})
|
||||
m_text_color(glm::vec3(0.7,1,0.3))
|
||||
{
|
||||
sf::Vector2u size = window->getSize();
|
||||
m_dimension = glm::ivec2(size.x,DEFAULT_FONT_SIZE*(BUFFER_DISPLAYED_LINES+1));
|
||||
@ -124,12 +123,7 @@ void SparrowShell::scrollDown()
|
||||
}
|
||||
|
||||
void SparrowShell::setInputs(int cursor_left, int cursor_right, int history_up, int history_down){
|
||||
m_inputActions[MOVE_CURSOR_LEFT] = cursor_left;
|
||||
m_inputActions[MOVE_CURSOR_RIGHT] = cursor_right;
|
||||
m_inputActions[HISTORY_PREVIOUS] = history_up;
|
||||
m_inputActions[HISTORY_NEXT] = history_down;
|
||||
m_input_node->setMoveCursorLeft(cursor_left);
|
||||
m_input_node->setMoveCursorRight(cursor_right);
|
||||
m_input_node->setInputs(cursor_left,cursor_right,history_up,history_down);
|
||||
}
|
||||
|
||||
void SparrowShell::toggleShell()
|
||||
|
@ -60,9 +60,9 @@ private:
|
||||
int m_move_cursor_right;
|
||||
std::string m_previous_context;
|
||||
|
||||
std::vector<int> m_inputActions;
|
||||
// std::vector<int> m_inputActions;
|
||||
|
||||
enum ShellAction {MOVE_CURSOR_LEFT=0,MOVE_CURSOR_RIGHT,HISTORY_PREVIOUS,HISTORY_NEXT};
|
||||
// enum ShellAction {MOVE_CURSOR_LEFT,MOVE_CURSOR_RIGHT,HISTORY_PREVIOUS,HISTORY_NEXT};
|
||||
|
||||
public:
|
||||
static const unsigned int BUFFER_MAX_LENGTH;
|
||||
|
Loading…
x
Reference in New Issue
Block a user