UWindow
Class UWindowRootWindow

source: c:\runehov\UWindow\Classes\UWindowRootWindow.uc
Core.Object
   |
   +--UWindow.UWindowBase
      |
      +--UWindow.UWindowWindow
         |
         +--UWindow.UWindowRootWindow
Direct Known Subclasses:RuneRootWindow, UBrowserRootWindow

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 ComputeGuiScale(float width, float height)
 void Created()
 void DoQuitGame()
 void DrawDropShadowed(Canvas C, float X, float Y, string text)
 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	
00048	function UWindowLookAndFeel GetLookAndFeel(String LFClassName)
00049	{
00050		local int i;
00051		local class<UWindowLookAndFeel> LFClass;
00052	
00053		LFClass = class<UWindowLookAndFeel>(DynamicLoadObject(LFClassName, class'Class'));
00054	
00055		for(i=0;i<20;i++)
00056		{
00057			if(LooksAndFeels[i] == None)
00058			{
00059				LooksAndFeels[i] = new LFClass;
00060				LooksAndFeels[i].Setup();
00061				return LooksAndFeels[i];
00062			}
00063	
00064			if(LooksAndFeels[i].Class == LFClass)
00065				return LooksAndFeels[i];
00066		}
00067		Log("Out of LookAndFeel array space!!");
00068		return None;
00069	}
00070	
00071	
00072	function Created() 
00073	{
00074		LookAndFeel = GetLookAndFeel(LookAndFeelClass);
00075		SetupFonts();
00076	
00077		NormalCursor.tex = Texture'MouseCursor';
00078		NormalCursor.HotX = 0;
00079		NormalCursor.HotY = 0;
00080		NormalCursor.WindowsCursor = Console.Viewport.IDC_ARROW;
00081	
00082		MoveCursor.tex = Texture'MouseMove';
00083		MoveCursor.HotX = 8;
00084		MoveCursor.HotY = 8;
00085		MoveCursor.WindowsCursor = Console.Viewport.IDC_SIZEALL;
00086		
00087		DiagCursor1.tex = Texture'MouseDiag1';
00088		DiagCursor1.HotX = 8;
00089		DiagCursor1.HotY = 8;
00090		DiagCursor1.WindowsCursor = Console.Viewport.IDC_SIZENWSE;
00091		
00092		HandCursor.tex = Texture'MouseHand';
00093		HandCursor.HotX = 11;
00094		HandCursor.HotY = 1;
00095		HandCursor.WindowsCursor = Console.Viewport.IDC_ARROW;
00096	
00097		HSplitCursor.tex = Texture'MouseHSplit';
00098		HSplitCursor.HotX = 9;
00099		HSplitCursor.HotY = 9;
00100		HSplitCursor.WindowsCursor = Console.Viewport.IDC_SIZEWE;
00101	
00102		VSplitCursor.tex = Texture'MouseVSplit';
00103		VSplitCursor.HotX = 9;
00104		VSplitCursor.HotY = 9;
00105		VSplitCursor.WindowsCursor = Console.Viewport.IDC_SIZENS;
00106	
00107		DiagCursor2.tex = Texture'MouseDiag2';
00108		DiagCursor2.HotX = 7;
00109		DiagCursor2.HotY = 7;
00110		DiagCursor2.WindowsCursor = Console.Viewport.IDC_SIZENESW;
00111	
00112		NSCursor.tex = Texture'MouseNS';
00113		NSCursor.HotX = 3;
00114		NSCursor.HotY = 7;
00115		NSCursor.WindowsCursor = Console.Viewport.IDC_SIZENS;
00116	
00117		WECursor.tex = Texture'MouseWE';
00118		WECursor.HotX = 7;
00119		WECursor.HotY = 3;
00120		WECursor.WindowsCursor = Console.Viewport.IDC_SIZEWE;
00121	
00122		WaitCursor.tex = Texture'MouseWait';
00123		WECursor.HotX = 6;
00124		WECursor.HotY = 9;
00125		WECursor.WindowsCursor = Console.Viewport.IDC_WAIT;
00126	
00127	
00128		HotkeyWindows = New class'UWindowHotkeyWindowList';
00129		HotkeyWindows.Last = HotkeyWindows;
00130		HotkeyWindows.Next = None;
00131		HotkeyWindows.Sentinel = HotkeyWindows;
00132	
00133		Cursor = NormalCursor;
00134	}
00135	
00136	function MoveMouse(float X, float Y)
00137	{
00138		local UWindowWindow NewMouseWindow;
00139		local float tx, ty;
00140	
00141		MouseX = X;
00142		MouseY = Y;
00143	
00144		if(!bMouseCapture)
00145			NewMouseWindow = FindWindowUnder(X, Y);
00146		else
00147			NewMouseWindow = MouseWindow;
00148	
00149		if(NewMouseWindow != MouseWindow)
00150		{
00151			MouseWindow.MouseLeave();
00152			NewMouseWindow.MouseEnter();
00153			MouseWindow = NewMouseWindow;
00154		}
00155	
00156		if(MouseX != OldMouseX || MouseY != OldMouseY)
00157		{
00158			OldMouseX = MouseX;
00159			OldMouseY = MouseY;
00160	
00161			MouseWindow.GetMouseXY(tx, ty);
00162			MouseWindow.MouseMove(tx, ty);
00163		}
00164	}
00165	
00166	function DrawMouse(Canvas C) 
00167	{
00168		local float X, Y;
00169	
00170		if(Console.Viewport.bWindowsMouseAvailable)
00171		{
00172			// Set the windows cursor...
00173			Console.Viewport.SelectedCursor = MouseWindow.Cursor.WindowsCursor;
00174		}
00175		else
00176		{
00177			C.DrawColor.R = 255;
00178			C.DrawColor.G = 255;
00179			C.DrawColor.B = 255;
00180			C.bNoSmooth = True;
00181	
00182			C.SetPos(MouseX * GUIScale - MouseWindow.Cursor.HotX, MouseY * GUIScale - MouseWindow.Cursor.HotY);
00183			C.DrawIcon(MouseWindow.Cursor.tex, 1.0);
00184		}
00185	
00186	
00187	
00188		/* DEBUG - show which window mouse is over
00189	
00190		MouseWindow.GetMouseXY(X, Y);
00191		C.Font = Font'Engine.SmallFont';
00192	
00193		DrawDropShadowed(C, 
00194			MouseX * GUIScale - MouseWindow.Cursor.HotX,
00195			MouseY * GUIScale - MouseWindow.Cursor.HotY,
00196			GetPlayerOwner().GetItemName(string(MouseWindow))$" "$int(MouseX * GUIScale)$", "$int(MouseY * GUIScale)$" ("$int(X)$", "$int(Y)$")");
00197	
00198		DrawDropShadowed(C, 
00199			MouseX * GUIScale - MouseWindow.Cursor.HotX,
00200			MouseY * GUIScale - MouseWindow.Cursor.HotY + 10,
00201			" Parent:      " @ MouseWindow.ParentWindow);
00202	
00203		DrawDropShadowed(C, 
00204			MouseX * GUIScale - MouseWindow.Cursor.HotX,
00205			MouseY * GUIScale - MouseWindow.Cursor.HotY + 20,
00206			" FirstChild:  " @ MouseWindow.FirstChildWindow);
00207	
00208		DrawDropShadowed(C, 
00209			MouseX * GUIScale - MouseWindow.Cursor.HotX,
00210			MouseY * GUIScale - MouseWindow.Cursor.HotY + 30,
00211			" LastChild:   " @ MouseWindow.LastChildWindow);
00212	
00213		DrawDropShadowed(C, 
00214			MouseX * GUIScale - MouseWindow.Cursor.HotX,
00215			MouseY * GUIScale - MouseWindow.Cursor.HotY + 40,
00216			" NextSibling: " @ MouseWindow.NextSiblingWindow);
00217	
00218		DrawDropShadowed(C, 
00219			MouseX * GUIScale - MouseWindow.Cursor.HotX,
00220			MouseY * GUIScale - MouseWindow.Cursor.HotY + 50,
00221			" PrevSibling: " @ MouseWindow.PrevSiblingWindow);
00222	
00223		DrawDropShadowed(C, 
00224			MouseX * GUIScale - MouseWindow.Cursor.HotX,
00225			MouseY * GUIScale - MouseWindow.Cursor.HotY + 60,
00226			" ActiveWindow:" @ MouseWindow.ActiveWindow);
00227	
00228		DrawDropShadowed(C, 
00229			MouseX * GUIScale - MouseWindow.Cursor.HotX,
00230			MouseY * GUIScale - MouseWindow.Cursor.HotY + 70,
00231			" Root:        " @ MouseWindow.Root);
00232	
00233		DrawDropShadowed(C, 
00234			MouseX * GUIScale - MouseWindow.Cursor.HotX,
00235			MouseY * GUIScale - MouseWindow.Cursor.HotY + 80,
00236			" OwnerWindow: " @ MouseWindow.OwnerWindow);
00237	
00238		DrawDropShadowed(C, 
00239			MouseX * GUIScale - MouseWindow.Cursor.HotX,
00240			MouseY * GUIScale - MouseWindow.Cursor.HotY + 90,
00241			" ModalWindow: " @ MouseWindow.ModalWindow);
00242	
00243		DrawDropShadowed(C, 
00244			MouseX * GUIScale - MouseWindow.Cursor.HotX,
00245			MouseY * GUIScale - MouseWindow.Cursor.HotY + 100,
00246			" IsActive:   " @ MouseWindow.IsActive());
00247	
00248		DrawDropShadowed(C, 
00249			MouseX * GUIScale - MouseWindow.Cursor.HotX,
00250			MouseY * GUIScale - MouseWindow.Cursor.HotY + 110,
00251			" Dimensions: " @ MouseWindow.WinLeft @ MouseWindow.WinTop @ MouseWindow.WinWidth @ MouseWindow.WinHeight);
00252	
00253		*/
00254	}
00255	
00256	function DrawDropShadowed(Canvas C, float X, float Y, string text)
00257	{
00258		C.SetColor(0,0,0);
00259		C.SetPos(X-1,Y-1);
00260		C.DrawText(text);
00261	
00262		C.SetColor(255,255,0);
00263		C.SetPos(X,Y);
00264		C.DrawText(text);
00265	}
00266	
00267	function bool CheckCaptureMouseUp()
00268	{
00269		local float X, Y;
00270	
00271		if(bMouseCapture) {
00272			MouseWindow.GetMouseXY(X, Y);
00273			MouseWindow.LMouseUp(X, Y);
00274			bMouseCapture = False;
00275			return True;
00276		}
00277		return False;
00278	}
00279	
00280	function bool CheckCaptureMouseDown()
00281	{
00282		local float X, Y;
00283	
00284		if(bMouseCapture) {
00285			MouseWindow.GetMouseXY(X, Y);
00286			MouseWindow.LMouseDown(X, Y);
00287			bMouseCapture = False;
00288			return True;
00289		}
00290		return False;
00291	}
00292	
00293	
00294	function CancelCapture()
00295	{
00296		bMouseCapture = False;
00297	}
00298	
00299	
00300	function CaptureMouse(optional UWindowWindow W)
00301	{
00302		bMouseCapture = True;
00303		if(W != None)
00304			MouseWindow = W;
00305		//Log(MouseWindow.Class$": Captured Mouse");
00306	}
00307	
00308	function Texture GetLookAndFeelTexture()
00309	{
00310		Return LookAndFeel.Active;
00311	}
00312	
00313	function bool IsActive()
00314	{
00315		Return True;
00316	}
00317	
00318	function AddHotkeyWindow(UWindowWindow W)
00319	{
00320	//	Log("Adding hotkeys for "$W);
00321		UWindowHotkeyWindowList(HotkeyWindows.Insert(class'UWindowHotkeyWindowList')).Window = W;
00322	}
00323	
00324	function RemoveHotkeyWindow(UWindowWindow W)
00325	{
00326		local UWindowHotkeyWindowList L;
00327	
00328	//	Log("Removing hotkeys for "$W);
00329	
00330		L = HotkeyWindows.FindWindow(W);
00331		if(L != None)
00332			L.Remove();
00333	}
00334	
00335	
00336	function WindowEvent(WinMessage Msg, Canvas C, float X, float Y, int Key) 
00337	{
00338		switch(Msg) {
00339		case WM_KeyDown:
00340			if(HotKeyDown(Key, X, Y))
00341				return;
00342			break;
00343		case WM_KeyUp:
00344			if(HotKeyUp(Key, X, Y))
00345				return;
00346			break;
00347		}
00348	
00349		Super.WindowEvent(Msg, C, X, Y, Key);
00350	}
00351	
00352	
00353	function bool HotKeyDown(int Key, float X, float Y)
00354	{
00355		local UWindowHotkeyWindowList l;
00356	
00357		l = UWindowHotkeyWindowList(HotkeyWindows.Next);
00358		while(l != None) 
00359		{
00360			if(l.Window != Self && l.Window.HotKeyDown(Key, X, Y)) return True;
00361			l = UWindowHotkeyWindowList(l.Next);
00362		}
00363	
00364		return False;
00365	}
00366	
00367	function bool HotKeyUp(int Key, float X, float Y)
00368	{
00369		local UWindowHotkeyWindowList l;
00370	
00371		l = UWindowHotkeyWindowList(HotkeyWindows.Next);
00372		while(l != None) 
00373		{
00374			if(l.Window != Self && l.Window.HotKeyUp(Key, X, Y)) return True;
00375			l = UWindowHotkeyWindowList(l.Next);
00376		}
00377	
00378		return False;
00379	}
00380	
00381	function CloseActiveWindow()
00382	{
00383		if(ActiveWindow != None)
00384			ActiveWindow.EscClose();
00385		else
00386			Console.CloseUWindow();
00387	}
00388	
00389	function Resized()
00390	{
00391		ResolutionChanged(WinWidth, WinHeight);
00392	}
00393	
00394	function ComputeGuiScale(float width, float height)
00395	{
00396		local float aspect;
00397	
00398		aspect = height/width;
00399	
00400		if (aspect < 0.75)
00401		{
00402			GUIScale = height/480.0;
00403		}
00404		else
00405		{
00406			GUIScale = width/640.0;
00407		}
00408	
00409		SetupFonts();
00410	}
00411	
00412	function SetScale(float NewScale)
00413	{
00414		WinWidth = RealWidth / NewScale;
00415		WinHeight = RealHeight / NewScale;
00416	
00417		GUIScale = NewScale;
00418	
00419		ClippingRegion.X = 0;
00420		ClippingRegion.Y = 0;
00421		ClippingRegion.W = WinWidth;
00422		ClippingRegion.H = WinHeight;
00423	
00424		SetupFonts();
00425	
00426		Resized();
00427	}
00428	
00429	function SetupFonts()
00430	{
00431		//!! Japanese text (experimental).
00432		/*if( true )
00433		{
00434			Fonts[F_Normal]    = Font(DynamicLoadObject("Japanese.Japanese", class'Font'));
00435			Fonts[F_Bold]      = Font(DynamicLoadObject("Japanese.Japanese", class'Font'));
00436			Fonts[F_Large]     = Font(DynamicLoadObject("Japanese.Japanese", class'Font'));
00437			Fonts[F_LargeBold] = Font(DynamicLoadObject("Japanese.Japanese", class'Font'));
00438			return;
00439		}*/
00440		if(GUIScale == 2)
00441		{
00442			Fonts[F_Normal] = Font(DynamicLoadObject("UWindowFonts.Tahoma20", class'Font'));
00443			Fonts[F_Bold] = Font(DynamicLoadObject("UWindowFonts.TahomaB20", class'Font'));
00444			Fonts[F_Large] = Font(DynamicLoadObject("UWindowFonts.Tahoma30", class'Font'));
00445			Fonts[F_LargeBold] = Font(DynamicLoadObject("UWindowFonts.TahomaB30", class'Font'));
00446		}
00447		else
00448		{
00449			Fonts[F_Normal] = Font(DynamicLoadObject("UWindowFonts.Tahoma10", class'Font'));
00450			Fonts[F_Bold] = Font(DynamicLoadObject("UWindowFonts.TahomaB10", class'Font'));
00451			Fonts[F_Large] = Font(DynamicLoadObject("UWindowFonts.Tahoma20", class'Font'));
00452			Fonts[F_LargeBold] = Font(DynamicLoadObject("UWindowFonts.TahomaB20", class'Font'));
00453		}	
00454	}
00455	
00456	function ChangeLookAndFeel(string NewLookAndFeel)
00457	{
00458		LookAndFeelClass = NewLookAndFeel;
00459		SaveConfig();
00460	
00461		// Completely restart UWindow system on the next paint
00462		Console.ResetUWindow();
00463	}
00464	
00465	function HideWindow()
00466	{
00467	}
00468	
00469	function SetMousePos(float X, float Y)
00470	{
00471		Console.MouseX = X;
00472		Console.MouseY = Y;
00473	}
00474	
00475	function QuitGame()
00476	{
00477		bRequestQuit = True;
00478		QuitTime = 0;
00479		NotifyQuitUnreal();
00480	}
00481	
00482	function DoQuitGame()
00483	{
00484		SaveConfig();
00485		Console.SaveConfig();
00486		Console.ViewPort.Actor.SaveConfig();
00487		Close();
00488		Console.Viewport.Actor.ConsoleCommand("exit");
00489	}
00490	
00491	function Tick(float Delta)
00492	{
00493		if(bRequestQuit)
00494		{
00495			// Give everything time to close itself down (ie sockets).
00496			if(QuitTime > 0.25)
00497				DoQuitGame();
00498			QuitTime += Delta;
00499		}
00500	
00501		Super.Tick(Delta);
00502	}
00503	
00504	defaultproperties
00505	{
00506	     GUIScale=1.000000
00507	     bAllowConsole=True
00508	}

End Source Code