// ==PREPROCESSOR==
// @name "StackBlur (text)"
// @author "T.P Wang / marc2003"
// @import "%fb2k_component_path%docs\flags.txt"
// @import "%fb2k_component_path%docs\helpers.txt"
// ==/PREPROCESSOR==

var ww = 0, wh = 0;
var img_to_blur;
var g_font = gdi.Font('Segoe UI', 32, FontStyle.Bold);
var text_to_draw = '"Stack Blur" Sample';

function on_paint(gr) {
	img_to_blur && gr.DrawImage(img_to_blur, 0, 0, ww, wh, 0, 0, ww, wh);
	gr.SetTextRenderingHint(TextRenderingHint.ClearTypeGridFit);
	gr.DrawString(text_to_draw, g_font, RGB(0, 0, 255), 0, 0, ww, wh, StringFormat(StringAlignment.Center, StringAlignment.Center));
}

function on_size() {
	ww = window.Width;
	wh = window.Height;
	if (ww <= 0 || wh <= 0) return;
	img_to_blur = gdi.CreateImage(ww, wh);
	var g = img_to_blur.GetGraphics();
	g.SetTextRenderingHint(TextRenderingHint.AntiAlias);
	g.DrawString(text_to_draw, g_font, RGB(0, 0, 255), 0, 0, ww, wh, StringFormat(StringAlignment.Center, StringAlignment.Center));
	img_to_blur.ReleaseGraphics(g);
	// Make Stack Blur, radius value can be between 2 and 254
	img_to_blur.StackBlur(30);
}
