
#include <stdio.h>
#include <string.h>
#include "app.h"
#include "GenCard.h"

/*
 *  A simple function for drawing white text over
 *  the same text in black, offset a little to
 *  provide the shadowed text effect seen on older
 *  style Magic cards.
 *
 *  Note: using anti-aliased fonts here produces
 *  weird effects. So, don't call this function
 *  except with a non-anti-aliased font selected
 *  into the Graphics object. The reason is that
 *  the black shadow darkens the pixels, and then
 *  the white text (which also has anti-aliasing
 *  because it's the same font) can darken it
 *  again, producing near-black dots in random
 *  places. It's essentially an interference
 *  pattern, producing 'beats' in odd places.
 *
 *  To allow anti-aliasing, I should really make
 *  a proper anti-aliased shadow font which
 *  pre-composes the shadow and the white text,
 *  and only puts the anti-aliasing around the
 *  outer edges of the combined font glyphs.
 *  That way, only the outer edges will blend
 *  with the background picture, producing a
 *  pleasant effect.
 */
void draw_white_shadow_text(Graphics *g, Rect r, int align, char *utf8, int nbytes)
{
	app_set_colour(g, BLACK);
	r.x += 2; r.y += 2;
	app_draw_text(g, r, align, utf8, nbytes);
	r.x -= 1; r.y -= 1;
	app_draw_text(g, r, align, utf8, nbytes);
	app_set_colour(g, WHITE);
	r.x -= 1; r.y -= 1;
	app_draw_text(g, r, align, utf8, nbytes);
	app_set_colour(g, BLACK);
}

/*
 *  This version of the above function only offsets the
 *  black text by one pixel instead of two.
 *  Used for tiny text where a 2-pixel shadow would be excessive.
 */
void draw_white_shadow_text_1(Graphics *g, Rect r, int align, char *utf8, int nbytes)
{
	app_set_colour(g, BLACK);
	r.x += 1; r.y += 1;
	app_draw_text(g, r, align, utf8, nbytes);
	app_set_colour(g, WHITE);
	r.x -= 1; r.y -= 1;
	app_draw_text(g, r, align, utf8, nbytes);
	app_set_colour(g, BLACK);
}

/*
 *  This version of the above function draws text
 *  with associated styles, using the given font list.
 *  The black shadow offset is 2 pixels.
 */
void draw_white_shadow_text_style(Graphics *g, Font *fonts[], Rect r,
				int align,
				char *utf8, int nbytes, char *style)
{
	app_set_colour(g, BLACK);
	r.x += 2; r.y += 2;
	style_text(g, fonts, r, align, utf8, nbytes, style);
	r.x -= 1; r.y -= 1;
	style_text(g, fonts, r, align, utf8, nbytes, style);
	app_set_colour(g, WHITE);
	r.x -= 1; r.y -= 1;
	style_text(g, fonts, r, align, utf8, nbytes, style);
	app_set_colour(g, BLACK);
}

