// Author: Juan Carlos De Abreu (jcabreur@gmail.com)
//
// This file define a class inherent from Frame that allow put a button in a
// create a console window.

#ifndef GUI_CONSOLE_H__
#define GUI_CONSOLE_H__

#include "tchar.h"

#include "../util/string.h"
#include "vector"

#include "../global.h"
#include "frame.h"

BEGIN_TEG_NAMESPACE();
BEGIN_NAMESPACE(gui);

class Console : public Frame {
 public:
  // Console constructor and destructor.
  // 590 && 270
  Console();
  Console(int x, int y, int width, int height);
  ~Console();

  // 
  inline int cont() { return cont_; }
  inline void set_cont(int cont) { cont_ = cont; }

  // Method to display the console.
  virtual void Render() const;
	
  void process(int key); // Method to process the keys.
  void addMessage(const std::tstring& msg);

 protected:
  // Define of the type line.
  enum { INPUT_LINE = 0, OUTPUT_LINE = 1};

  // TODO: put this method in the text class ...
  void printText(float x__, float y__, float z__, std::string str) const;
  void printText(float x__, float y__, float z__, std::string str, std::vector<int> colors) const;

 private:
  // Methods.
  void addANewChar(_TCHAR c); // Method to add a new char.
  void addNewLine(); // Method to add a new line.
  void clearAChar(); // Method to clear a char.

  void saveLastLine();
  void execute();

  void keyEnd();
  void keyHome();

  // To manage instructions that can copy like linux style...
  void keyUp();
  void keyDown();
  void keyLeft();
  void keyRight();

  void keyCtrlLeft();
  void keyCtrlRight();

  // To make possible copy and paste in the console.
  int copyStartX, copyEndX;	// Selection ...
  void keyShiftLeft();
  void keyShiftRight();
  void paste();
  void copy();
  void cut();

  // Attributes.
  int cont_;	// to draw a _ each second... aproximatly
  int pos_x_, pos_y_;
  std::vector<bool> type_line_;
  std::vector<std::tstring> lines_;
};

END_NAMESPACE(gui);
END_TEG_NAMESPACE();

#endif  // GUI_CONSOLE_H__
