UWindow
Class UWindowPulldownMenu

source: e:\games\UnrealTournament\UWindow\Classes\UWindowPulldownMenu.uc
Core.Object
   |
   +--UWindow.UWindowBase
      |
      +--UWindow.UWindowWindow
         |
         +--UWindow.UWindowDialogControl
            |
            +--UWindow.UWindowListControl
               |
               +--UWindow.UWindowPulldownMenu
Direct Known Subclasses:UMenuGameMenu, UMenuHelpMenu, UMenuModMenu, UMenuMultiplayerMenu, UMenuOptionsMenu, UMenuStatsMenu, UMenuToolsMenu, UTGameMenu, UWindowRightClickMenu

class UWindowPulldownMenu
extends UWindow.UWindowListControl

//============================================================================= // UWindowPulldownMenu //=============================================================================
Variables
 int HBorder
 int ItemHeight
 UWindowList Owner
 UWindowPulldownMenuItem Selected
 int TextBorder
 int VBorder


Function Summary
 UWindowPulldownMenuItem AddMenuItem(string C, Texture G)
     
// External functions
 void BeforeExecuteItem(UWindowPulldownMenuItem I)
 void BeforePaint(Canvas C, float X, float Y)
 void Clear()
 void CloseUp(optional bool)
 void Created()
     
// Mostly-private funcitons
 void DeSelect()
 void DrawItem(Canvas C, UWindowList Item, float X, float Y, float W, float H)
 void DrawMenuBackground(Canvas C)
 void ExecuteItem(UWindowPulldownMenuItem I)
 void FocusOtherWindow(UWindowWindow W)
 UWindowMenuBar GetMenuBar()
 void KeyDown(int Key, float X, float Y)
 void KeyUp(int Key, float X, float Y)
 void LMouseDown(float X, float Y)
 void LMouseUp(float X, float Y)
 void MenuCmd(int Item)
 void MouseMove(float X, float Y)
 void Paint(Canvas C, float X, float Y)
 void PerformSelect(UWindowPulldownMenuItem NewSelected)
 void Select(UWindowPulldownMenuItem I)
 void SetSelected(float X, float Y)
 void ShowWindow()



Source Code


00001	//=============================================================================
00002	// UWindowPulldownMenu
00003	//=============================================================================
00004	
00005	
00006	class UWindowPulldownMenu extends UWindowListControl;
00007	
00008	#exec TEXTURE IMPORT NAME=MenuTick FILE=Textures\MenuTick.bmp GROUP="Icons" FLAGS=2 MIPS=OFF
00009	#exec TEXTURE IMPORT NAME=MenuDivider FILE=Textures\MenuDivider.bmp GROUP="Icons" MIPS=OFF
00010	#exec TEXTURE IMPORT NAME=MenuSubArrow FILE=Textures\MenuSubArrow.bmp GROUP="Icons" FLAGS=2 MIPS=OFF
00011	
00012	var UWindowPulldownMenuItem		Selected;
00013	
00014	// Owner is either a UWindowMenuBarItem or UWindowPulldownMenuItem
00015	var UWindowList					Owner;
00016	
00017	var int ItemHeight;
00018	var int VBorder;
00019	var int HBorder;
00020	var int TextBorder;
00021	
00022	// External functions
00023	function UWindowPulldownMenuItem AddMenuItem(string C, Texture G)
00024	{
00025		local UWindowPulldownMenuItem I;
00026	
00027		I = UWindowPulldownMenuItem(Items.Append(class'UWindowPulldownMenuItem'));
00028		
00029		I.Owner = Self;
00030		I.SetCaption(C);
00031		I.Graphic = G;
00032	
00033		return I;
00034	}
00035	
00036	// Mostly-private funcitons
00037	
00038	function Created()
00039	{
00040		ListClass = class'UWindowPulldownMenuItem';
00041		SetAcceptsFocus();
00042		Super.Created();
00043		ItemHeight = LookAndFeel.Pulldown_ItemHeight;
00044		VBorder = LookAndFeel.Pulldown_VBorder;
00045		HBorder = LookAndFeel.Pulldown_HBorder;
00046		TextBorder = LookAndFeel.Pulldown_TextBorder;
00047	}
00048	
00049	function Clear()
00050	{
00051		Items.Clear();
00052		Selected = None;
00053	}
00054	
00055	function DeSelect()
00056	{
00057		if(Selected != None)
00058		{
00059			Selected.DeSelect();
00060			Selected = None;
00061		}
00062	}
00063	
00064	function Select(UWindowPulldownMenuItem I)
00065	{
00066	}
00067	
00068	function PerformSelect(UWindowPulldownMenuItem NewSelected)
00069	{
00070		if(Selected != None && NewSelected != Selected) Selected.DeSelect();
00071	
00072		if(NewSelected == None) 
00073		{
00074			Selected = None;
00075		}
00076		else
00077		{	
00078			if(Selected != NewSelected && NewSelected.Caption != "-" && !NewSelected.bDisabled)
00079				LookAndFeel.PlayMenuSound(Self, MS_MenuItem);
00080							
00081			Selected = NewSelected;
00082			if(Selected != None) 
00083			{
00084				Selected.Select();
00085				Select(Selected);
00086			}
00087		}
00088	}
00089	
00090	function SetSelected(float X, float Y)
00091	{
00092		local UWindowPulldownMenuItem NewSelected;
00093	
00094		NewSelected = UWindowPulldownMenuItem(Items.FindEntry((Y - VBorder) / ItemHeight));
00095	
00096		PerformSelect(NewSelected);
00097	}
00098	
00099	function ShowWindow()
00100	{
00101		local UWindowPulldownMenuItem I;
00102		Super.ShowWindow();
00103		PerformSelect(None);
00104		FocusWindow();
00105	}
00106	
00107	function MouseMove(float X, float Y)
00108	{
00109		Super.MouseMove(X, Y);
00110		SetSelected(X, Y);
00111		FocusWindow();
00112	}
00113	
00114	function LMouseUp(float X, float Y)
00115	{
00116		If(Selected != None && Selected.Caption != "-" && !Selected.bDisabled)
00117		{
00118			BeforeExecuteItem(Selected);
00119			ExecuteItem(Selected);
00120		}
00121		Super.LMouseUp(X, Y);
00122	}
00123	
00124	function LMouseDown(float X, float Y)
00125	{
00126	}
00127	
00128	function BeforePaint(Canvas C, float X, float Y)
00129	{
00130		local float W, H, MaxWidth;
00131		local int Count;
00132		local UWindowPulldownMenuItem I;
00133		
00134		
00135		MaxWidth = 100;
00136		Count = 0;
00137	
00138		C.Font = Root.Fonts[F_Normal];
00139		C.SetPos(0, 0);
00140	
00141		for( I = UWindowPulldownMenuItem(Items.Next);I != None; I = UWindowPulldownMenuItem(I.Next) )
00142		{
00143			Count++;
00144			TextSize(C, RemoveAmpersand(I.Caption), W, H);
00145			if(W > MaxWidth) MaxWidth = W;
00146		}
00147	
00148		WinWidth = MaxWidth + ((HBorder + TextBorder) * 2);
00149		WinHeight = (ItemHeight * Count) + (VBorder * 2);
00150	
00151		// Take care of bHelp items
00152		if(	((UWindowMenuBarItem(Owner) != None) && (UWindowMenuBarItem(Owner).bHelp)) ||
00153			WinLeft+WinWidth > ParentWindow.WinWidth )
00154		{
00155			WinLeft = ParentWindow.WinWidth - WinWidth;
00156		}
00157	
00158		if(UWindowPulldownMenuItem(Owner) != None)
00159		{
00160			I = UWindowPulldownMenuItem(Owner);
00161			
00162			if(WinWidth + WinLeft > ParentWindow.WinWidth)
00163				WinLeft = I.Owner.WinLeft + I.Owner.HBORDER - WinWidth;
00164		}
00165	}
00166	
00167	function Paint(Canvas C, float X, float Y)
00168	{
00169		local int Count;
00170		local UWindowPulldownMenuItem I;
00171	
00172		DrawMenuBackground(C);
00173		
00174		Count = 0;
00175	
00176		for( I = UWindowPulldownMenuItem(Items.Next);I != None; I = UWindowPulldownMenuItem(I.Next) )
00177		{
00178			DrawItem(C, I, HBorder, VBorder + (ItemHeight * Count), WinWidth - (2 * HBorder), ItemHeight);
00179			Count++;
00180		}
00181	}
00182	
00183	function DrawMenuBackground(Canvas C)
00184	{
00185		LookAndFeel.Menu_DrawPulldownMenuBackground(Self, C);
00186	}
00187	
00188	function DrawItem(Canvas C, UWindowList Item, float X, float Y, float W, float H)
00189	{
00190		LookAndFeel.Menu_DrawPulldownMenuItem(Self, UWindowPulldownMenuItem(Item), C, X, Y, W, H, Selected == Item);
00191	}
00192	
00193	function BeforeExecuteItem(UWindowPulldownMenuItem I)
00194	{
00195		LookAndFeel.PlayMenuSound(Self, MS_WindowOpen);
00196	}
00197	
00198	function ExecuteItem(UWindowPulldownMenuItem I)
00199	{
00200		CloseUp();
00201	}
00202	
00203	function CloseUp(optional bool bByOwner)
00204	{
00205		local UWindowPulldownMenuItem I;
00206	
00207		// tell our owners to close up
00208		if(!bByOwner)
00209		{
00210			if(UWindowPulldownMenuItem(Owner) != None)  UWindowPulldownMenuItem(Owner).CloseUp();
00211			if(UWindowMenuBarItem(Owner) != None)  UWindowMenuBarItem(Owner).CloseUp();
00212		}
00213	
00214		// tell our children to close up
00215		for( I = UWindowPulldownMenuItem(Items.Next);I != None; I = UWindowPulldownMenuItem(I.Next) )
00216			if(I.SubMenu != None)
00217				I.SubMenu.CloseUp(True);
00218	}
00219	
00220	function UWindowMenuBar GetMenuBar()
00221	{
00222		if(UWindowPulldownMenuItem(Owner) != None) return UWindowPulldownMenuItem(Owner).GetMenuBar();
00223		if(UWindowMenuBarItem(Owner) != None) return UWindowMenuBarItem(Owner).GetMenuBar();
00224	}
00225	
00226	function FocusOtherWindow(UWindowWindow W)
00227	{
00228		Super.FocusOtherWindow(W);
00229	
00230		if(Selected != None) 
00231			if(W == Selected.SubMenu) return;
00232	
00233		if(UWindowPulldownMenuItem(Owner) != None)
00234			if(UWindowPulldownMenuItem(Owner).Owner == W) return;
00235	
00236		if(bWindowVisible)
00237			CloseUp();
00238	}
00239	
00240	function KeyDown(int Key, float X, float Y)
00241	{
00242		local UWindowPulldownMenuItem I;
00243	
00244		I = Selected;
00245	
00246		switch(Key)
00247		{
00248		case 0x26: // Up
00249			if(I == None || I == Items.Next)
00250				I = UWindowPulldownMenuItem(Items.Last);
00251			else
00252				I = UWindowPulldownMenuItem(I.Prev);
00253	
00254			if(I == None)
00255				I = UWindowPulldownMenuItem(Items.Last);
00256			else 
00257				if(I.Caption == "-")
00258					I = UWindowPulldownMenuItem(I.Prev);
00259	
00260			if(I == None)
00261				I = UWindowPulldownMenuItem(Items.Last);
00262	
00263			if(I.SubMenu == None)
00264				PerformSelect(I);
00265			else
00266				Selected = I;
00267	
00268			break;
00269		case 0x28: // Down
00270			if(I == None)
00271				I = UWindowPulldownMenuItem(Items.Next);
00272			else
00273				I = UWindowPulldownMenuItem(I.Next);
00274	
00275			if(I == None)
00276				I = UWindowPulldownMenuItem(Items.Next);
00277			else
00278				if(I.Caption == "-")
00279					I = UWindowPulldownMenuItem(I.Next);
00280	
00281			if(I == None)
00282				I = UWindowPulldownMenuItem(Items.Next);
00283	
00284			if(I.SubMenu == None)
00285				PerformSelect(I);
00286			else
00287				Selected = I;
00288	
00289			break;
00290		case 0x25: // Left
00291			if(UWindowPulldownMenuItem(Owner) != None)
00292			{
00293				 UWindowPulldownMenuItem(Owner).Owner.PerformSelect(None);
00294				 UWindowPulldownMenuItem(Owner).Owner.Selected = UWindowPulldownMenuItem(Owner);
00295			}
00296			if(UWindowMenuBarItem(Owner) != None)
00297				UWindowMenuBarItem(Owner).Owner.KeyDown(Key, X, Y);
00298			break;
00299		case 0x27: // Right
00300			if(I != None && I.SubMenu != None)
00301			{
00302				Selected = None;
00303				PerformSelect(I);
00304				I.SubMenu.Selected = UWindowPulldownMenuItem(I.SubMenu.Items.Next);
00305			} 
00306			else
00307			{
00308				if(UWindowPulldownMenuItem(Owner) != None)
00309				{
00310					UWindowPulldownMenuItem(Owner).Owner.PerformSelect(None);
00311					UWindowPulldownMenuItem(Owner).Owner.KeyDown(Key, X, Y);
00312				}
00313				if(UWindowMenuBarItem(Owner) != None)
00314					UWindowMenuBarItem(Owner).Owner.KeyDown(Key, X, Y);
00315			}	
00316			break;
00317		case 0x0D: // Enter
00318			if(I.SubMenu != None)
00319			{
00320				Selected = None;
00321				PerformSelect(I);
00322			}
00323			else
00324				if(Selected != None && Selected.Caption != "-" && !Selected.bDisabled)
00325				{
00326					BeforeExecuteItem(Selected);
00327					ExecuteItem(Selected);
00328				}
00329			break;
00330		default:
00331		}		
00332	}
00333	
00334	function KeyUp(int Key, float X, float Y)
00335	{
00336		local UWindowPulldownMenuItem I;
00337			
00338		if(Key >= 0x41 && Key <= 0x60)
00339		{	
00340			// Check for hotkeys in each menu item
00341			for( I = UWindowPulldownMenuItem(Items.Next);I != None; I = UWindowPulldownMenuItem(I.Next) )
00342			{
00343				if(Key == I.HotKey) 
00344				{
00345					PerformSelect(I);
00346					if(I != None && I.Caption != "-" && !I.bDisabled)
00347					{
00348						BeforeExecuteItem(I);
00349						ExecuteItem(I);
00350					}
00351				}
00352			}
00353		}
00354	}
00355	
00356	function MenuCmd(int Item)
00357	{
00358		local int j;
00359		local UWindowPulldownMenuItem I;
00360			
00361		for( I = UWindowPulldownMenuItem(Items.Next);I != None; I = UWindowPulldownMenuItem(I.Next) )
00362		{
00363			if(j == Item)
00364			{
00365				PerformSelect(I);
00366				if( I.Caption != "-" && !I.bDisabled )
00367				{
00368					BeforeExecuteItem(I);
00369					ExecuteItem(I);
00370				}
00371				return;
00372			}
00373			j++;
00374		}
00375	}
00376	
00377	defaultproperties
00378	{
00379	     bAlwaysOnTop=True
00380	}

End Source Code