/*****************************************************************************/
/* D2K: A Doom Source Port for the 21st Century                              */
/*                                                                           */
/* Copyright (C) 2014: See COPYRIGHT file                                    */
/*                                                                           */
/* This file is part of D2K.                                                 */
/*                                                                           */
/* D2K is free software: you can redistribute it and/or modify it under the  */
/* terms of the GNU General Public License as published by the Free Software */
/* Foundation, either version 2 of the License, or (at your option) any      */
/* later version.                                                            */
/*                                                                           */
/* D2K is distributed in the hope that it will be useful, but WITHOUT ANY    */
/* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS */
/* FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more    */
/* details.                                                                  */
/*                                                                           */
/* You should have received a copy of the GNU General Public License along   */
/* with D2K.  If not, see <http://www.gnu.org/licenses/>.                    */
/*                                                                           */
/*****************************************************************************/


#ifndef HULIB_H__
#define HULIB_H__

struct patchnum_s;
typedef struct patchnum_s patchnum_t;

/* background and foreground screen numbers
 * different from other modules. */
//e6y #define BG      1
#define FG      0

#define HU_MAXLINES   4
#define HU_MAXLINELENGTH  80
#define HU_REFRESHSPACING 8 /*jff 2/26/98 space lines in text refresh widget*/
/*jff 2/26/98 maximum number of messages allowed in refresh list */
#define HU_MAXMESSAGES 16

typedef struct hu_color_s {
  float r;
  float g;
  float b;
  float a;
} hu_color_t;

/*
 * Typedefs of widgets
 */

/* Text Line widget
 *  (parent of Scrolling Text and Input Text widgets) */
typedef struct {
  // left-justified position of scrolling text window
  int   x;
  int   y;
  int   w;
  int   val;

  const patchnum_t* f;                    // font
  int   sc;                             // start character
  //const char *cr;                       //jff 2/16/52 output color range
  // Proff - Made this an int again. Needed for OpenGL
  int   cm;                         //jff 2/16/52 output color range

  // killough 1/23/98: Support multiple lines:
  #define MAXLINES 25

  int   linelen;
  char  l[HU_MAXLINELENGTH*MAXLINES+1]; // line of text
  int   len;                            // current line length

  // whether this line needs to be udpated
  int   needsupdate;

  // e6y: wide-res
  patch_translation_e flags;
} hu_textline_t;

// Scrolling Text window widget
//  (child of Text Line widget)
typedef struct {
  hu_textline_t  l[HU_MAXLINES]; // text lines to draw
  int            h; // height in lines
  int            cl; // current line number
  bool          *on; // pointer to bool stating whether to update window
  bool           laston; // last value of *->on.

} hu_stext_t;

//jff 2/26/98 new widget to display last hud_msg_lines of messages
// Message refresh window widget
typedef struct
{
  hu_textline_t l[HU_MAXMESSAGES]; // text lines to draw
  int     nl;                          // height in lines
  int     nr;                          // total height in rows
  int     cl;                          // current line number

  int x,y,w,h;                         // window position and size
  const patchnum_t *bg;                  // patches for background

  // pointer to bool stating whether to update window
  bool    *on;
  bool   laston;             // last value of *->on.

} hu_mtext_t;



// Input Text Line widget
//  (child of Text Line widget)
typedef struct
{
  hu_textline_t l;    // text line to input on

  // left margin past which I am not to delete characters
  int     lm;

  // pointer to bool stating whether to update window
  bool        *on;
  bool   laston;   // last value of *->on;

} hu_itext_t;


//
// Widget creation, access, and update routines
//

//
// textline code
//

// clear a line of text
void HUlib_clearTextLine(hu_textline_t *t);

void HUlib_initTextLine
(
  hu_textline_t *t,
  int x,
  int y,
  const patchnum_t *f,
  int sc,
  int cm,    //jff 2/16/98 add color range parameter
  patch_translation_e flags
);

// returns success
bool HUlib_addCharToTextLine(hu_textline_t *t, char ch);

// draws tline
void HUlib_drawTextLine(hu_textline_t *l, bool drawcursor);

// erases text line
void HUlib_eraseTextLine(hu_textline_t *l);


//
// Scrolling Text window widget routines
//

// initialize an stext widget
//jff 2/16/98 add color range parameter
void HUlib_initSText(hu_stext_t* s, int x, int y, int h,
                                    const patchnum_t *font, int startchar,
                                    int cm, patch_translation_e flags,
                                    bool *on);

// add a text message to an stext widget
void HUlib_addMessageToSText(hu_stext_t *s, const char *prefix,
                                            const char *msg);

// draws stext
void HUlib_drawSText(hu_stext_t* s);

// erases all stext lines
void HUlib_eraseSText(hu_stext_t* s);

//jff 2/26/98 message refresh widget
// initialize refresh text widget
void HUlib_initMText(hu_mtext_t *m, int x, int y, int w, int h,
                                    const patchnum_t* font,
                                    int startchar, int cm,
                                    const patchnum_t* bgfont,
                                    patch_translation_e flags,
                                    bool *on);

//jff 2/26/98 message refresh widget
// add a text message to refresh text widget
void HUlib_addMessageToMText(hu_mtext_t *m, const char *prefix,
                                            const char *msg);

//jff 2/26/98 new routine to display a background on which
// the list of last hud_msg_lines are displayed
void HUlib_drawMBg(int x, int y, int w, int h, const patchnum_t *bgp);

//jff 2/26/98 message refresh widget
// draws mtext
void HUlib_drawMText(hu_mtext_t *m);

//jff 4/28/98 erases behind message list
void HUlib_eraseMText(hu_mtext_t *m);

// Input Text Line widget routines
//jff 2/16/98 add color range parameter
void HUlib_initIText(hu_itext_t *it, int x, int y, const patchnum_t *font,
                                     int startchar, int cm,
                                     patch_translation_e flags, bool *on);

// resets line and left margin
void HUlib_resetIText(hu_itext_t *it);

// left of left-margin
void HUlib_addPrefixToIText(hu_itext_t *it, char *str);

// whether eaten
bool HUlib_keyInIText(hu_itext_t *it, unsigned char ch);

void HUlib_drawIText(hu_itext_t *it);

// erases all itext lines
void HUlib_eraseIText(hu_itext_t *it);

//e6y
void HUlib_setTextXCenter(hu_textline_t *t);

#endif

/* vi: set et ts=2 sw=2: */

