standardFont = "fonts/arial.mvec";

BlackColor = Color(0,0,0,255);
BlueColor = Color(77,115,178,255);
DarkBlueColor = Color(40,60,120,255);
WhiteColor = Color(255,255,255,255);
MenuButtonFontColor = Color(255,255,255,255);
MenuOverButtonFontColor = Color(248,177,73,255);
MenuDisabledButtonFontColor = Color(10,10,10,255);

ScreenWight = 1024;
ScreenHeight = 768;

mainMenuButtonSound="assets/audio/sfx/menu_click.ogg";
defaultButtonSound="assets/audio/sfx/menu_click.ogg";
mainMenuOpenSound="assets/audio/sfx/menu_openwindow.ogg";
mainMenuOverSound="assets/audio/sfx/menu_focus.ogg";
mainLampSwitch="assets/audio/sfx/menu_lampswitch.ogg";

StandardButtonGraphics = {
	"menu/button_02.png",
	"menu/button_03.png",
	"menu/button_01.png"
};

CheckboxButtonGraphics = {
	"menu/button_ok_disabled",
	"menu/button_ok_up",
	"menu/button_ok_disabled_over",
	"menu/button_ok_rollover",
};

ProfilesButtonGraphics =
{
	"menu/button_02.png",
	"menu/button_03.png",
	"menu/button_01.png"
};

ProfilesNamesGraphics =
{
	"menu/button_05.png",
	"menu/button_04.png",
	"menu/button_06.png",
	"menu/button_04.png"
};

StandardButtonFont = {
  standardFont,
  22,
  BlackColor
};

MenuButtonFont = {
  standardFont,
  22,
  MenuOverButtonFontColor
};

CheckButtonFont = {
  standardFont,
  22,
  Color(0,0,0,255)
};

MenuDisabledButtonFont = {
  standardFont,
  22,
  MenuDisabledButtonFontColor
};

WelcomeFont = {
  standardFont,
  26,
  WhiteColor
};


DialogTitleFont = {
  standardFont,
  48,
  BlackColor
};

DialogBodyFont = {
  standardFont,
  28,
  BlackColor
};

HeaderFont = {
  standardFont,
  48,
  BlackColor
};

AboutMovieFont1 = {
  standardFont,
  20,
  WhiteColor
};

AboutMovieFont2 = {
  standardFont,
  20,
  Color(0,0,0,255)
};


DefaultStyle = {
	font=DialogBodyFont,
    sound = defaultButtonSound,    
    rolloversound = mainMenuOverSound,    
};

DialogTitleText = {
	parent=DefaultStyle,
	font = DialogTitleFont,
	flags = kVAlignCenter + kHAlignCenter,
	x=16,y=12,w=kMax,h=kMax-200
};

DialogBodyText = {
	parent=DefaultStyle,
	font = DialogBodyFont,
	flags = kVAlignCenter + kHAlignCenter,
	x=0,y=46,w=kMax,h=kMax-60
};

SliderStyle =
{
	parent=DefaultStyle,
	railtop = "menu/slider_empty",
	railmid = "menu/slider_empty",
	railbot = "menu/slider_empty",
	sliderimage = "menu/slider_empty",
	sliderrollimage = "menu/slider_empty",
};

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

MenuButtonEmpty = {
	font = DialogBodyFont,
	graphics = {
	"menu/btn_empty",
	"menu/btn_empty",
	"menu/btn_empty"},
	w=2, h=2
};

MenuButtonCross = {
	parent = DefaultStyle,
	font = MenuButtonFont,
	sound = kDefaultButtonSound,
	graphics = {
	"menu/button_cross_up",
	"menu/button_cross_rollover",
	"menu/button_cross_rollover",
	"menu/button_cross_up"},
	w=63, h=50
};

MenuButtonOk = {
	parent = DefaultStyle,
	font = MenuButtonFont,
	sound = kDefaultButtonSound,
	graphics = {
	"menu/button_ok_up",
	"menu/button_ok_rollover",
	"menu/button_ok_rollover",
	"menu/button_ok_disabled"},
	w=63, h=50
};

MenuButtonStyle = {
	parent = DefaultStyle,
	flags = kHAlignCenter + kVAlignTop,
	font = MenuButtonFont,
	sound = kDefaultButtonSound,
	graphics = {},
	w=169, h=40
};

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

CheckboxButtonStyle = {
	parent = DefaultStyle,
	font = CheckButtonFont,
	type = kToggle,
	sound = kDefaultButtonSound,
	graphics = CheckboxButtonGraphics,
	tx=28,
};

ProfilesButtonStyle =
{
	--type = kPush,
	parent = DefaultStyle,
	flags = kHAlignCenter + kVAlignCenter,
	font = StandardButtonFont,
	graphics = ProfilesButtonGraphics
};

ProfilesNamesStyle =
{
	type = kRadio,
	flags = kHAlignCenter + kVAlignCenter,
	font = StandardButtonFont,
	graphics = ProfilesNamesGraphics
};

SetDefaultStyle(DefaultStyle);

-- Create a TButton with a label
--
-- We're overriding the default "Button" here with
-- some custom behavior. Specifically, we're layering
-- a Text{} object on top of every button, and it's placed
-- on all layers (up, down, roll-over).
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

-- 4.0.15 -- Begin new hotkey support
			-- Get the label
			local label = GetTag(button,"label");
			local hotkey = GetTag(button,"hotkey");

			label,labelkey = StripKeyFromLabel( GetString(label) );

			-- If no hotkey was specified explicitly, then
			-- use the translated key.
			if not hotkey then
				-- change our local
				hotkey = labelkey
			end;

			RegisterHotkey( hotkey, GetTag(button,"name") );
-- 4.0.15 -- End new hotkey support (more below!)

			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
				{
-- 4.0.15 -- Begin new hotkey support
					label="#"..TagHotKey( hotkey, label ),
-- 4.0.15 -- End new hotkey support
					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

kMenuButtonFontSize = 22;

function MenuButtonLabel( label, color, colorHighlight )

	if not color then
		color = Color(248,177,73,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='MenuButton';
		DoWindow( button )
	end
end

function QEMenuButton( 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

-- 4.0.15 -- Begin new hotkey support
            -- Get the label
            local label = GetTag(button,"label");
            local hotkey = GetTag(button,"hotkey");

            label,labelkey = StripKeyFromLabel( GetString(label) );

            -- If no hotkey was specified explicitly, then
            -- use the translated key.
            if not hotkey then
                -- change our local
                hotkey = labelkey
            end;

            RegisterHotkey( hotkey, GetTag(button,"name") );
-- 4.0.15 -- End new hotkey support (more below!)

            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
                {
-- 4.0.15 -- Begin new hotkey support
                    label="#"..TagHotKey( hotkey, label ),
-- 4.0.15 -- End new hotkey support
                    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='QEMenuButton';
        DoWindow( button )
    end
end

kIllegalNameChars = "!@#$%^&*()><\\\"\'[]{}|?/+=~`.,;:-_ ";