
/************************************************
*
* Project Information: Classe CConsole
*
* Filename: Console.h
* Version : 0.0.11-dev
* Last Update: 06-04-2004
*
* Author:  Romain Gaucher -- nEUrOO
* E-mail:  neuroo@kouette.com
* Date  :  16-02-2004
*
* Comment: Gestion de la console
*
***********************************************/

#ifndef __M_CCONSOLE_H
#define __M_CCONSOLE_H

//#include <cwchar>   // me pete les couilles avec wchar_t

#include <cstdio>
#include <cstdlib>
#include <string>
#include <list>
#include <map>


#include "CFonte.hpp"
#include "CLog.hpp"


extern CFonte fonte;
extern CLog   c_log;


typedef struct __SMILEY__ {
   char str[256];  // lieu de la texture
   char rec[256];  // quel caractères a mettre pour reconnaitre ':)'
   short width;
   short height;
} SMILEY;

// Stockage dans le map
// le map resortira une structure ...
typedef struct __STOCK__ {
   unsigned int          id;
   unsigned short         w;
   unsigned short         h;
} STOCKAGE;


class CConsole
{
  std::string                        s_cons;
  std::list<std::string>             l_cons;
  std::list<std::string>::iterator  it_cons;

  unsigned int                   c_nb_lines;
  unsigned int                          c_i;

  std::string                    ver_string;

  // but: map[":)"] =)> id_texture
  // A to Smiley
  // en fait, pour charger le smiley, on fera
  // str étant le mot courant
  // place = atos.find(str);
  // if (place != atos.end())
  //   DrawSmiley(atos[str])
  unsigned int                           nb;
  SMILEY                             *smile;
  std::map<std::string,STOCKAGE>       atos;
  unsigned short                       *dim;
  unsigned short                      pos_x;
  unsigned short                      pos_y;
  
  unsigned int                      text_id;

  public:

       CConsole() {
        ver_string = "~~~ Console v0.11 #tricol# ~~~";
        c_i = 0;
        c_nb_lines = 0;
        s_cons = "$";

        pos_x = 0;
        pos_y = 32;

      };

      ~CConsole() {};

      bool g_LoadSmiley();

      bool Init        ();
      void ALaLigne    ();

      template <typename T> 
      void PushString  (T c);
      void PushChar    (unsigned char  c);
      void PopChar     ();
      // sortie sur la console =)> produit de Action
      int  Sortie      (int erreur, int pos);


      // Récupérer la liste de smileys
      bool RecupererSmiley();

      
      // Fonctions graphiques
      void show      (int w,std::string str); // debug
      void Transition(int v); // transition, console qui descend !

      void c_DrawStr (const char *str, float color_rgb[], int set);
      void o_DrawStr (int &loc_x, const char *str, float color_rgb[], int set);


      void DrawSmiley(int loc_x, int loc_y, unsigned int id, float color_3f[3], int tailles[2]);
      void DrawChar  (unsigned char c, int set);
      void Render    ();
      // Fonction d'intéraction avec le clavier
      void PushKey   (unsigned char c);
      // Interaction avec la fonction appelée
      int  Action    ();

      // log de la console en état
      void print     ()
      {
      	for (it_cons=l_cons.begin();it_cons!=l_cons.end();++it_cons)
      	    c_log << (*it_cons).c_str();
      	c_log << s_cons.c_str();
      }

};

#endif
