/* -*-ePiX-*- */
#include "epix.h"
using namespace ePiX;

/*
 * Font tests; draws all 32 combinations of five attributes:
 *
 * label_color: (Neutral: cols 1, 3; Red, cols 2, 4)
 * label_mask:  (Neutral: cols 1, 2; Yellow: cols 3, 4)
 *
 * label_border color: (Neutral: odd rows, Blue otherwise)
 * label_border width: (0pt: rows 1-2, 5-6, 1pt otherwise)
 *
 * pad: (0pt: rows 1-4, 1pt otherwise)
 */

// test objects
void objs()
{
  label(P(-0.5,0), "The");
  masklabel(P(0.5,0), "The");
}

// attribute-setting commands on bool flags
void label_color(bool arg)
{
  if (arg)
    label_color(Red());

  else
    label_color(Neutral());
}

void label_mask(bool arg)
{
  if (arg)
    label_mask(Yellow(0.3));
  else
    label_mask(Neutral());
}

void set_border(bool col, std::string len)
{
  if (col)
    label_border(Blue(1.2), len);

  else
    label_border(Neutral(), len);
}

void label_border(bool col, bool wid)
{
  if (wid)
    set_border(col, "1pt");

  else
    set_border(col, "0pt");
}

void pad(bool arg)
{
  if (arg)
    label_pad("6pt");

  else
    label_pad("0pt");
}

// we'll use 0, 1 as loop indices; convert to bool
bool tf(int i)
{
  return i == 0 ? false : true;
}

// where to position the result of a test
P loc(int i0, int i1, int i2, int i3, int i4)
{
  double horiz(0), vert(7);
  if (tf(i0))
    horiz += 1;

  if (tf(i1))
    horiz += 2;

  if (tf(i2))
    vert -= 1;

  if(tf(i3))
    vert -= 2;

  if (tf(i4))
    vert -= 4;

  return P(horiz, vert);
}

int main()
{
  picture(P(0,0), P(4,8), "6 x 9in");

  begin();

  // the tests proper
  for (int i0=0; i0<2; ++i0)
    for (int i1=0; i1<2; ++i1)
      for (int i2=0; i2<2; ++i2)
	for (int i3=0; i3<2; ++i3)
	  for (int i4=0; i4<2; ++i4)
	    {
	      screen scr(P(-1,-1), P(1,1));
	      activate(scr);

	      solid(); // may need to reset line style
	      border(Green(0.6), "0.1pt");

	      backing(Black(0.1));
	      pen(Black(0.3));
	      grid(8,8);

	      label_color(tf(i0));
	      label_mask(tf(i1));
	      label_border(tf(i2),tf(i3));
	      pad(tf(i4));

	      objs();

	      scr.scale(0.9);
	      inset(loc(i0,i1,i2,i3,i4), loc(i0,i1,i2,i3,i4) + P(1,1));
	      deactivate(scr);
	    }
  end();
}