standardFont = "fonts/arial.mvec";

BlackColor = Color(0,0,0,255);
MenuButtonFontColor = Color(255,255,255,255);

kDefaultButtonSound="audio/sfx/buttonclick.ogg";


StandardButtonFont = {
  standardFont,
  18,
  BlackColor
};
StandardTextFont = {
  standardFont,
  30,
  BlackColor
};
MenuButtonFont = {
  standardFont,
  22,
  MenuButtonFontColor
};

DialogBodyFont = {
  standardFont,
  18,
  BlackColor
};

DefaultStyle = {
	font=DialogBodyFont
};
StandardButtonGraphics = {
	"buttons/buttonup",
	"buttons/buttondown",
	"buttons/buttonrollover"
};


ButtonStyle = {
	parent = DefaultStyle,
	font = StandardButtonFont,
	sound = kDefaultButtonSound,
	type= kPush,
	graphics = StandardButtonGraphics,
};

MenuButtonGraphics = {
	"buttons/b_menu",
	"buttons/b_menu_pressed",
	"buttons/b_menu_mouseover"
};

MenuButtonStyle = {
	parent = DefaultStyle,
	font = StandardButtonFont,
	sound = kDefaultButtonSound,
	type= kPush,
	graphics = MenuButtonGraphics,
};
OptionsButtonGraphics = {
        "buttons/b_options",
	"buttons/b_options_pressed",
	"buttons/b_options_mouseover"
        
};
OptionsButtonStyle = {
	parent = DefaultStyle,
	font = StandardButtonFont,
	sound = kDefaultButtonSound,
	type= kPush,
	graphics = OptionsButtonGraphics,
};
ListButtonGraphics = {
        "buttons/b_list",
	"buttons/b_list_pressed",
	"buttons/b_list_mouseover"
        
};
ListButtonStyle = {
	parent = DefaultStyle,
	font = StandardButtonFont,
	sound = kDefaultButtonSound,
	type= kPush,
	graphics = ListButtonGraphics,
};
CasesButtonGraphics = {
        "buttons/b_cases",
	"buttons/b_cases_pressed",
	"buttons/b_cases_mouseover"
        
};
CasesButtonStyle = {
	parent = DefaultStyle,
	font = StandardButtonFont,
	sound = kDefaultButtonSound,
	type= kPush,
	graphics = CasesButtonGraphics,
};

SkipButtonGraphics = {
        "buttons/b_skip",
	"buttons/b_skip_pressed",
	"buttons/b_skip_mouseover"
        
};
SkipButtonStyle = {
	parent = DefaultStyle,
	font = StandardButtonFont,
	sound = kDefaultButtonSound,
	type= kPush,
	graphics = SkipButtonGraphics,
};

MatchButtonGraphics = {
        "buttons/b_match",
	"buttons/b_match_pressed",
	"buttons/b_match_mouseover"
        
};
MatchButtonStyle = {
	parent = DefaultStyle,
	font = StandardButtonFont,
	sound = kDefaultButtonSound,
	type= kPush,
	graphics = MatchButtonGraphics,
};

LongButtonGraphics = {
	"buttons/long_button_up.png",
	"buttons/long_button_down.png",
	"buttons/long_button_over.png"
};

TapButtonGraphics = {
	"buttons/tap_on.png",
	"buttons/tap_on.png",
	"buttons/tap_on_over.png"
};


TapOnButtonGraphics = {
	"buttons/tap_on.png",
	"buttons/tap_on.png",
	"buttons/tap_on_over.png"
};

TapOffButtonGraphics = {
	"buttons/tap_off.png",
	"buttons/tap_off.png",
	"buttons/tap_off_over.png"
};

CheckboxButtonGraphics = {
	"pic/tap_off",
	"pic/tap_on",
	"pic/tap_off_over",
	"pic/tap_on_over"
};

LongButtonStyle = {
	parent = ButtonStyle,
	graphics = LongButtonGraphics
};

TapButtonStyle = {
	parent = ButtonStyle,
	graphics = TapButtonGraphics
};

CheckboxButtonStyle = {
	parent = DefaultStyle,
	font = StandardButtonFont,
	type = kToggle,
	sound = kDefaultButtonSound,
	graphics = CheckboxButtonGraphics,
};


kMenuButtonFontSize = 22;


function Button( button )
	return function()
		-- Grab the label from the button or current style
		if (GetTag(button,"label")) then

			-- Look for text dimensions
			local tx = GetTag(button,"tx");
			local ty = GetTag(button,"ty");
			local tw = GetTag(button,"tw");
			local th = GetTag(button,"th");

			-- Set defaults
			if (not tx) then
				tx = 0;
			end
			if (not ty) then
				ty = 0;
			end
			if (not tw) then
				tw=kMax ;
			end
			if (not th) then
				th=kMax ;
			end

			-- Get the label
			local label = GetTag(button,"label");

			local defflags = kPushButtonAlignment ;
			if (GetTag(button,"type")==kToggle) then
				defflags = kToggleButtonAlignment ;
			elseif (GetTag(button,"type")==kRadio) then
				defflags = kRadioButtonAlignment ;
			end

			local textfactory = GetTag(button,"textfactory");
			if (not textfactory) then
				textfactory = "_text"
			end
			table.insert(button,
				SelectLayer( kAllLayers )
			);
			-- Grow our window to encompass any children we've added
			-- already.
			table.insert(button,
				FitToChildren()
			);

			table.insert(button,
				AppendStyle{ font=button.font; flags=button.flags; }
			);

			table.insert(button,
				Text
				{
					label=label,
					x=tx, y=ty, w=tw, h=th,
					name='label',
					defflags =defflags
				}
			)
		end

		-- Type name of window to create; in our case, "Button".
		-- If you want to create a derived button type, you can do that here.
		button.typename='Button';
		DoWindow( button )
	end
end



-- Create several bits of text that combine to make a blended shadow
function ColorShadowText( x,y,size, label, color )

	return Group(
		{
		-- Add these traits to the current style
			AppendStyle{ x=x, y=y, w=kMax, h=kMax, label=label },
			AppendStyle{ font = { standardFont, size, Color(0,0,0,40)} },
			Text{ y=y+4 },
			AppendStyle{ font = { standardFont, size, Color(0,0,0,255)} },
			Text{ y=y+2 },
			AppendStyle{ font = { standardFont, size, color } } ,
			Text{},
		}
	)
end

function MenuButtonLabel( label, color, colorHighlight )

	if not color then
		color =Color(192,207,255,255);	-- the default colors
		colorHighlight=Color(255,255,255,255)
	end

	return Group{
		Bitmap
		{
			image="backgrounds/bar",
			x=0,y=0,scale=1
		},
		SelectLayer(0),
		ColorShadowText(5,8,kMenuButtonFontSize, label, color ),
		SelectLayer(1),
		ColorShadowText(5,8,kMenuButtonFontSize, label, colorHighlight ),
		SelectLayer(2),
		ColorShadowText(5,8,kMenuButtonFontSize, label, colorHighlight )
	}

end

-- Create a more limited-use button type here; the label is defined inline
-- with MenuButtonLabel above
function MenuButton( button )
	return function()
		-- Type name of window to create; in our case, "Button".
		-- If you want to create a derived button type, you can do that here.
		button.typename='Button';
		DoWindow( button )
	end
end
