UWindow
Class UWindowRootWindow

source: e:\games\UnrealTournament\UWindow\Classes\UWindowRootWindow.uc
Core.Object
   |
   +--UWindow.UWindowBase
      |
      +--UWindow.UWindowWindow
         |
         +--UWindow.UWindowRootWindow
Direct Known Subclasses:UBrowserRootWindow, UMenuRootWindow

class UWindowRootWindow
extends UWindow.UWindowWindow

//============================================================================= // UWindowRootWindow - the root window. //=============================================================================
Variables
 WindowConsole Console
           The window the mouse is over
 UWindowWindow FocusedWindow
           The window the mouse is over
 Font Fonts[10]
           window with keyboard focus
 float GUIScale
           window with keyboard focus
 UWindowHotkeyWindowList HotkeyWindows
           window with keyboard focus
 UWindowWindow KeyFocusWindow
           window with keyboard focus
 string LookAndFeelClass
           window with keyboard focus
 UWindowLookAndFeel LooksAndFeels[20]
           window with keyboard focus
 UWindowWindow MouseWindow
           The window the mouse is over
 MouseX, MouseY
           The window the mouse is over
 OldMouseX, OldMouseY
           The window the mouse is over
 float QuitTime
           window with keyboard focus
 RealWidth, RealHeight
           window with keyboard focus
 WECursor, WaitCursor
           window with keyboard focus
 bool bAllowConsole
           window with keyboard focus
 bool bMouseCapture
           The window the mouse is over
 bool bQuickKeyEnable
           window with keyboard focus
 bool bRequestQuit
           window with keyboard focus


Function Summary
 void AddHotkeyWindow(UWindowWindow W)
 void BeginPlay()
 void CancelCapture()
 void CaptureMouse(optional UWindowWindow)
 void ChangeLookAndFeel(string NewLookAndFeel)
 bool CheckCaptureMouseDown()
 bool CheckCaptureMouseUp()
 void CloseActiveWindow()
 void Created()
 void DoQuitGame()
 void DrawMouse(Canvas C)
 UWindowLookAndFeel GetLookAndFeel(String LFClassName)
 Texture GetLookAndFeelTexture()
 void HideWindow()
 bool HotKeyDown(int Key, float X, float Y)
 bool HotKeyUp(int Key, float X, float Y)
 bool IsActive()
 void MoveMouse(float X, float Y)
 void QuitGame()
 void RemoveHotkeyWindow(UWindowWindow W)
 void Resized()
 void SetMousePos(float X, float Y)
 void SetScale(float NewScale)
 void SetupFonts()
 void Tick(float Delta)
 void WindowEvent(WinMessage Msg, Canvas C, float X, float Y, int Key)



Source Code


00001	//=============================================================================
00002	// UWindowRootWindow - the root window.
00003	//=============================================================================
00004	class UWindowRootWindow extends UWindowWindow;
00005	
00006	#exec TEXTURE IMPORT NAME=MouseCursor FILE=Textures\MouseCursor.bmp GROUP="Icons" FLAGS=2 MIPS=OFF
00007	#exec TEXTURE IMPORT NAME=MouseMove FILE=Textures\MouseMove.bmp GROUP="Icons" FLAGS=2 MIPS=OFF
00008	#exec TEXTURE IMPORT NAME=MouseDiag1 FILE=Textures\MouseDiag1.bmp GROUP="Icons" FLAGS=2 MIPS=OFF
00009	#exec TEXTURE IMPORT NAME=MouseDiag2 FILE=Textures\MouseDiag2.bmp GROUP="Icons" FLAGS=2 MIPS=OFF
00010	#exec TEXTURE IMPORT NAME=MouseNS FILE=Textures\MouseNS.bmp GROUP="Icons" FLAGS=2 MIPS=OFF
00011	#exec TEXTURE IMPORT NAME=MouseWE FILE=Textures\MouseWE.bmp GROUP="Icons" FLAGS=2 MIPS=OFF
00012	#exec TEXTURE IMPORT NAME=MouseHand FILE=Textures\MouseHand.bmp GROUP="Icons" FLAGS=2 MIPS=OFF
00013	#exec TEXTURE IMPORT NAME=MouseHSplit FILE=Textures\MouseHSplit.bmp GROUP="Icons" FLAGS=2 MIPS=OFF
00014	#exec TEXTURE IMPORT NAME=MouseVSplit FILE=Textures\MouseVSplit.bmp GROUP="Icons" FLAGS=2 MIPS=OFF
00015	#exec TEXTURE IMPORT NAME=MouseWait FILE=Textures\MouseWait.bmp GROUP="Icons" FLAGS=2 MIPS=OFF
00016	
00017	
00018	//!! Japanese text (experimental).
00019	//#exec OBJ LOAD FILE=..\Textures\Japanese.utx
00020	
00021	var UWindowWindow		MouseWindow;		// The window the mouse is over
00022	var bool				bMouseCapture;
00023	var float				MouseX, MouseY;
00024	var float				OldMouseX, OldMouseY;
00025	var WindowConsole		Console;
00026	var UWindowWindow		FocusedWindow;
00027	var UWindowWindow		KeyFocusWindow;		// window with keyboard focus
00028	var MouseCursor			NormalCursor, MoveCursor, DiagCursor1, HandCursor, HSplitCursor, VSplitCursor, DiagCursor2, NSCursor, WECursor, WaitCursor;
00029	var bool				bQuickKeyEnable;
00030	var UWindowHotkeyWindowList	HotkeyWindows;
00031	var config float		GUIScale;
00032	var float				RealWidth, RealHeight;
00033	var Font				Fonts[10];
00034	var UWindowLookAndFeel	LooksAndFeels[20];
00035	var config string		LookAndFeelClass;
00036	var bool				bRequestQuit;
00037	var float				QuitTime;
00038	var bool				bAllowConsole;
00039	
00040	function BeginPlay() 
00041	{
00042		Root = Self;
00043		MouseWindow = Self;
00044		KeyFocusWindow = Self;
00045	}
00046	
00047	function UWindowLookAndFeel GetLookAndFeel(String LFClassName)
00048	{
00049		local int i;
00050		local class<UWindowLookAndFeel> LFClass;
00051	
00052		LFClass = class<UWindowLookAndFeel>(DynamicLoadObject(LFClassName, class'Class'));
00053	
00054		for(i=0;i<20;i++)
00055		{
00056			if(LooksAndFeels[i] == None)
00057			{
00058				LooksAndFeels[i] = new LFClass;
00059				LooksAndFeels[i].Setup();
00060				return LooksAndFeels[i];
00061			}
00062	
00063			if(LooksAndFeels[i].Class == LFClass)
00064				return LooksAndFeels[i];
00065		}
00066		Log("Out of LookAndFeel array space!!");
00067		return None;
00068	}
00069	
00070	
00071	function Created() 
00072	{
00073		LookAndFeel = GetLookAndFeel(LookAndFeelClass);
00074		SetupFonts();
00075	
00076		NormalCursor.tex = Texture'MouseCursor';
00077		NormalCursor.HotX = 0;
00078		NormalCursor.HotY = 0;
00079		NormalCursor.WindowsCursor = Console.Viewport.IDC_ARROW;
00080	
00081		MoveCursor.tex = Texture'MouseMove';
00082		MoveCursor.HotX = 8;
00083		MoveCursor.HotY = 8;
00084		MoveCursor.WindowsCursor = Console.Viewport.IDC_SIZEALL;
00085		
00086		DiagCursor1.tex = Texture'MouseDiag1';
00087		DiagCursor1.HotX = 8;
00088		DiagCursor1.HotY = 8;
00089		DiagCursor1.WindowsCursor = Console.Viewport.IDC_SIZENWSE;
00090		
00091		HandCursor.tex = Texture'MouseHand';
00092		HandCursor.HotX = 11;
00093		HandCursor.HotY = 1;
00094		HandCursor.WindowsCursor = Console.Viewport.IDC_ARROW;
00095	
00096		HSplitCursor.tex = Texture'MouseHSplit';
00097		HSplitCursor.HotX = 9;
00098		HSplitCursor.HotY = 9;
00099		HSplitCursor.WindowsCursor = Console.Viewport.IDC_SIZEWE;
00100	
00101		VSplitCursor.tex = Texture'MouseVSplit';
00102		VSplitCursor.HotX = 9;
00103		VSplitCursor.HotY = 9;
00104		VSplitCursor.WindowsCursor = Console.Viewport.IDC_SIZENS;
00105	
00106		DiagCursor2.tex = Texture'MouseDiag2';
00107		DiagCursor2.HotX = 7;
00108		DiagCursor2.HotY = 7;
00109		DiagCursor2.WindowsCursor = Console.Viewport.IDC_SIZENESW;
00110	
00111		NSCursor.tex = Texture'MouseNS';
00112		NSCursor.HotX = 3;
00113		NSCursor.HotY = 7;
00114		NSCursor.WindowsCursor = Console.Viewport.IDC_SIZENS;
00115	
00116		WECursor.tex = Texture'MouseWE';
00117		WECursor.HotX = 7;
00118		WECursor.HotY = 3;
00119		WECursor.WindowsCursor = Console.Viewport.IDC_SIZEWE;
00120	
00121		WaitCursor.tex = Texture'MouseWait';
00122		WECursor.HotX = 6;
00123		WECursor.HotY = 9;
00124		WECursor.WindowsCursor = Console.Viewport.IDC_WAIT;
00125	
00126	
00127		HotkeyWindows = New class'UWindowHotkeyWindowList';
00128		HotkeyWindows.Last = HotkeyWindows;
00129		HotkeyWindows.Next = None;
00130		HotkeyWindows.Sentinel = HotkeyWindows;
00131	
00132		Cursor = NormalCursor;
00133	}
00134	
00135	function MoveMouse(float X, float Y)
00136	{
00137		local UWindowWindow NewMouseWindow;
00138		local float tx, ty;
00139	
00140		MouseX = X;
00141		MouseY = Y;
00142	
00143		if(!bMouseCapture)
00144			NewMouseWindow = FindWindowUnder(X, Y);
00145		else
00146			NewMouseWindow = MouseWindow;
00147	
00148		if(NewMouseWindow != MouseWindow)
00149		{
00150			MouseWindow.MouseLeave();
00151			NewMouseWindow.MouseEnter();
00152			MouseWindow = NewMouseWindow;
00153		}
00154	
00155		if(MouseX != OldMouseX || MouseY != OldMouseY)
00156		{
00157			OldMouseX = MouseX;
00158			OldMouseY = MouseY;
00159	
00160			MouseWindow.GetMouseXY(tx, ty);
00161			MouseWindow.MouseMove(tx, ty);
00162		}
00163	}
00164	
00165	function DrawMouse(Canvas C) 
00166	{
00167		local float X, Y;
00168	
00169		if(Console.Viewport.bWindowsMouseAvailable)
00170		{
00171			// Set the windows cursor...
00172			Console.Viewport.SelectedCursor = MouseWindow.Cursor.WindowsCursor;
00173		}
00174		else
00175		{
00176			C.DrawColor.R = 255;
00177			C.DrawColor.G = 255;
00178			C.DrawColor.B = 255;
00179			C.bNoSmooth = True;
00180	
00181			C.SetPos(MouseX * GUIScale - MouseWindow.Cursor.HotX, MouseY * GUIScale - MouseWindow.Cursor.HotY);
00182			C.DrawIcon(MouseWindow.Cursor.tex, 1.0);
00183		}
00184	
00185	
00186	
00187		/* DEBUG - show which window mouse is over
00188	
00189		MouseWindow.GetMouseXY(X, Y);
00190		C.Font = Fonts[F_Normal];
00191	
00192		C.DrawColor.R = 0;
00193		C.DrawColor.G = 0;
00194		C.DrawColor.B = 0;
00195		C.SetPos(MouseX * GUIScale - MouseWindow.Cursor.HotX, MouseY * GUIScale - MouseWindow.Cursor.HotY);
00196		C.DrawText( GetPlayerOwner().GetItemName(string(MouseWindow))$" "$int(MouseX * GUIScale)$", "$int(MouseY * GUIScale)$" ("$int(X)$", "$int(Y)$")");
00197	
00198		C.DrawColor.R = 255;
00199		C.DrawColor.G = 255;
00200		C.DrawColor.B = 0;
00201		C.SetPos(-1 + MouseX * GUIScale - MouseWindow.Cursor.HotX, -1 + MouseY * GUIScale - MouseWindow.Cursor.HotY);
00202		C.DrawText( GetPlayerOwner().GetItemName(string(MouseWindow))$" "$int(MouseX * GUIScale)$", "$int(MouseY * GUIScale)$" ("$int(X)$", "$int(Y)$")");
00203	
00204		*/
00205	}
00206	
00207	function bool CheckCaptureMouseUp()
00208	{
00209		local float X, Y;
00210	
00211		if(bMouseCapture) {
00212			MouseWindow.GetMouseXY(X, Y);
00213			MouseWindow.LMouseUp(X, Y);
00214			bMouseCapture = False;
00215			return True;
00216		}
00217		return False;
00218	}
00219	
00220	function bool CheckCaptureMouseDown()
00221	{
00222		local float X, Y;
00223	
00224		if(bMouseCapture) {
00225			MouseWindow.GetMouseXY(X, Y);
00226			MouseWindow.LMouseDown(X, Y);
00227			bMouseCapture = False;
00228			return True;
00229		}
00230		return False;
00231	}
00232	
00233	
00234	function CancelCapture()
00235	{
00236		bMouseCapture = False;
00237	}
00238	
00239	
00240	function CaptureMouse(optional UWindowWindow W)
00241	{
00242		bMouseCapture = True;
00243		if(W != None)
00244			MouseWindow = W;
00245		//Log(MouseWindow.Class$": Captured Mouse");
00246	}
00247	
00248	function Texture GetLookAndFeelTexture()
00249	{
00250		Return LookAndFeel.Active;
00251	}
00252	
00253	function bool IsActive()
00254	{
00255		Return True;
00256	}
00257	
00258	function AddHotkeyWindow(UWindowWindow W)
00259	{
00260	//	Log("Adding hotkeys for "$W);
00261		UWindowHotkeyWindowList(HotkeyWindows.Insert(class'UWindowHotkeyWindowList')).Window = W;
00262	}
00263	
00264	function RemoveHotkeyWindow(UWindowWindow W)
00265	{
00266		local UWindowHotkeyWindowList L;
00267	
00268	//	Log("Removing hotkeys for "$W);
00269	
00270		L = HotkeyWindows.FindWindow(W);
00271		if(L != None)
00272			L.Remove();
00273	}
00274	
00275	
00276	function WindowEvent(WinMessage Msg, Canvas C, float X, float Y, int Key) 
00277	{
00278		switch(Msg) {
00279		case WM_KeyDown:
00280			if(HotKeyDown(Key, X, Y))
00281				return;
00282			break;
00283		case WM_KeyUp:
00284			if(HotKeyUp(Key, X, Y))
00285				return;
00286			break;
00287		}
00288	
00289		Super.WindowEvent(Msg, C, X, Y, Key);
00290	}
00291	
00292	
00293	function bool HotKeyDown(int Key, float X, float Y)
00294	{
00295		local UWindowHotkeyWindowList l;
00296	
00297		l = UWindowHotkeyWindowList(HotkeyWindows.Next);
00298		while(l != None) 
00299		{
00300			if(l.Window != Self && l.Window.HotKeyDown(Key, X, Y)) return True;
00301			l = UWindowHotkeyWindowList(l.Next);
00302		}
00303	
00304		return False;
00305	}
00306	
00307	function bool HotKeyUp(int Key, float X, float Y)
00308	{
00309		local UWindowHotkeyWindowList l;
00310	
00311		l = UWindowHotkeyWindowList(HotkeyWindows.Next);
00312		while(l != None) 
00313		{
00314			if(l.Window != Self && l.Window.HotKeyUp(Key, X, Y)) return True;
00315			l = UWindowHotkeyWindowList(l.Next);
00316		}
00317	
00318		return False;
00319	}
00320	
00321	function CloseActiveWindow()
00322	{
00323		if(ActiveWindow != None)
00324			ActiveWindow.EscClose();
00325		else
00326			Console.CloseUWindow();
00327	}
00328	
00329	function Resized()
00330	{
00331		ResolutionChanged(WinWidth, WinHeight);
00332	}
00333	
00334	function SetScale(float NewScale)
00335	{
00336		WinWidth = RealWidth / NewScale;
00337		WinHeight = RealHeight / NewScale;
00338	
00339		GUIScale = NewScale;
00340	
00341		ClippingRegion.X = 0;
00342		ClippingRegion.Y = 0;
00343		ClippingRegion.W = WinWidth;
00344		ClippingRegion.H = WinHeight;
00345	
00346		SetupFonts();
00347	
00348		Resized();
00349	}
00350	
00351	function SetupFonts()
00352	{
00353		//!! Japanese text (experimental).
00354		/*if( true )
00355		{
00356			Fonts[F_Normal]    = Font(DynamicLoadObject("Japanese.Japanese", class'Font'));
00357			Fonts[F_Bold]      = Font(DynamicLoadObject("Japanese.Japanese", class'Font'));
00358			Fonts[F_Large]     = Font(DynamicLoadObject("Japanese.Japanese", class'Font'));
00359			Fonts[F_LargeBold] = Font(DynamicLoadObject("Japanese.Japanese", class'Font'));
00360			return;
00361		}*/
00362		if(GUIScale == 2)
00363		{
00364			Fonts[F_Normal] = Font(DynamicLoadObject("UWindowFonts.Tahoma20", class'Font'));
00365			Fonts[F_Bold] = Font(DynamicLoadObject("UWindowFonts.TahomaB20", class'Font'));
00366			Fonts[F_Large] = Font(DynamicLoadObject("UWindowFonts.Tahoma30", class'Font'));
00367			Fonts[F_LargeBold] = Font(DynamicLoadObject("UWindowFonts.TahomaB30", class'Font'));
00368		}
00369		else
00370		{
00371			Fonts[F_Normal] = Font(DynamicLoadObject("UWindowFonts.Tahoma10", class'Font'));
00372			Fonts[F_Bold] = Font(DynamicLoadObject("UWindowFonts.TahomaB10", class'Font'));
00373			Fonts[F_Large] = Font(DynamicLoadObject("UWindowFonts.Tahoma20", class'Font'));
00374			Fonts[F_LargeBold] = Font(DynamicLoadObject("UWindowFonts.TahomaB20", class'Font'));
00375		}	
00376	}
00377	
00378	function ChangeLookAndFeel(string NewLookAndFeel)
00379	{
00380		LookAndFeelClass = NewLookAndFeel;
00381		SaveConfig();
00382	
00383		// Completely restart UWindow system on the next paint
00384		Console.ResetUWindow();
00385	}
00386	
00387	function HideWindow()
00388	{
00389	}
00390	
00391	function SetMousePos(float X, float Y)
00392	{
00393		Console.MouseX = X;
00394		Console.MouseY = Y;
00395	}
00396	
00397	function QuitGame()
00398	{
00399		bRequestQuit = True;
00400		QuitTime = 0;
00401		NotifyQuitUnreal();
00402	}
00403	
00404	function DoQuitGame()
00405	{
00406		SaveConfig();
00407		Console.SaveConfig();
00408		Console.ViewPort.Actor.SaveConfig();
00409		Close();
00410		Console.Viewport.Actor.ConsoleCommand("exit");
00411	}
00412	
00413	function Tick(float Delta)
00414	{
00415		if(bRequestQuit)
00416		{
00417			// Give everything time to close itself down (ie sockets).
00418			if(QuitTime > 0.25)
00419				DoQuitGame();
00420			QuitTime += Delta;
00421		}
00422	
00423		Super.Tick(Delta);
00424	}
00425	
00426	defaultproperties
00427	{
00428	     GUIScale=1.000000
00429	     bAllowConsole=True
00430	}

End Source Code