Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |
00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 00049 00050 00051 00052 00053 00054 00055 00056 00057 00058 00059 00060 00061 00062 00063 00064 00065 00066 00067 00068 00069 00070 00071 00072 00073 00074 00075 00076 00077 00078 00079 00080 00081 00082 00083 00084 00085 00086 00087 00088 00089 00090 00091 00092 00093 00094 00095 00096 00097 00098 00099 00100 00101 00102 00103 00104 00105 00106 00107 00108 00109 00110 00111 00112 00113 00114 00115 00116 00117 00118 00119 00120 00121 00122 00123 00124 00125 00126 00127 00128 00129 00130 00131 00132 00133 00134 00135 00136 00137 00138 00139 00140 00141 00142 00143 00144 00145 00146 00147 00148 00149 00150 00151 00152 00153 00154 00155 00156 00157 00158 00159 00160 00161 00162 00163 00164 00165 00166 00167 00168 00169 00170 00171 00172 00173 00174 00175 00176 00177 00178 00179 00180 00181 00182 00183 00184 00185 00186 00187 00188 00189 00190 00191 00192 00193 00194 00195 00196 00197 00198 00199 00200 00201 00202 00203 00204 00205 00206 00207 00208 00209 00210 00211 00212 00213 00214 00215 00216 00217 00218 00219 00220 00221 00222 00223 00224 00225 00226 00227 00228 00229 00230 00231 00232 00233 00234 00235 00236 00237 00238 00239 00240 00241 00242 00243 00244 00245 00246 00247 00248 00249 00250 00251 00252 00253 00254 00255 00256 00257 00258 00259 00260 00261 00262 00263 00264 00265 00266 00267 00268 00269 00270 00271 00272 00273 00274 00275 00276 00277 00278 00279 00280 00281 00282 00283 00284 00285 00286 00287 00288 00289 00290 00291 00292 00293 00294 00295 00296 00297 00298 00299 00300 00301 00302 00303 00304 00305 00306 00307 00308 00309 00310 00311 00312 00313 00314 00315 00316 00317 00318 00319 00320 00321 00322 00323 00324 00325 00326 00327 00328 00329 00330 00331 00332 00333 00334 00335 00336 00337 00338 00339 00340 00341 00342 00343 00344 00345 00346 00347 00348 00349 00350 00351 00352 00353 00354 00355 00356 00357 00358 00359 00360 00361 00362 00363 00364 00365 00366 00367 00368 00369 00370 00371 00372 00373 00374 00375 00376 00377 00378 00379 00380 00381 00382 00383 00384 00385 00386 00387 00388 00389 00390 00391 00392 00393 00394 00395 00396 00397 00398 00399 00400 00401 00402 00403 00404 00405 00406 00407 00408 00409 00410 00411 00412 00413 00414 00415 00416 00417 00418 00419 00420 00421 00422 00423 00424 00425 00426 00427 00428 00429 00430 00431 00432 00433 00434 00435 00436 00437 00438 00439 00440 00441 00442 00443 00444 00445 00446 00447 00448 00449 00450 00451 00452 00453 00454 00455 00456 00457 00458 00459 00460 00461 00462 00463 00464 00465 00466 00467 00468 00469 00470 00471 00472 00473 00474 00475 00476 00477 00478 00479 00480 00481 00482 00483 00484 00485 00486 00487 00488 00489 00490 00491 00492 00493 00494 00495 00496 00497 00498 00499 00500 00501 00502 00503 00504 00505 00506 00507 00508 00509 00510 00511 00512 00513 00514 00515 00516 00517 00518 00519 00520 00521 00522 00523 00524 00525 00526 00527 00528 00529 00530 00531 00532 00533 00534 00535 00536 00537 00538 00539 00540 00541 00542 00543 00544 00545 00546 00547 00548 00549 00550 00551 00552 00553 00554 00555 00556 00557 00558 00559 00560 00561 00562 00563 00564 00565 00566 00567 00568 00569 00570 00571 00572 00573 00574 00575 00576 00577 00578 00579 00580 00581 00582 00583 00584 00585 00586 00587 00588 00589 00590 00591 00592 00593 00594 00595 00596 00597 00598 00599 00600 00601 00602 00603 00604 00605 00606 00607 00608 00609 00610 00611 00612 00613 00614 00615 00616 00617 00618 00619 00620 00621 |
// ============================================================================ // JBGUIComponentTabs // Copyright 2003 by Mychaeel <mychaeel@planetjailbreak.com> // $Id: JBGUIComponentTabs.uc,v 1.7 2007-09-03 22:46:11 wormbo Exp $ // // User interface component: Has a column of tabs on the left side, each // containing an instance of a specified component class such as a checkbox. // ============================================================================ class JBGUIComponentTabs extends GUIPanel; // ============================================================================ // Imports // ============================================================================ #exec texture import file=Textures\GUITabBlurred.dds alpha=on mips=off #exec texture import file=Textures\GUITabWatched.dds alpha=on mips=off #exec texture import file=Textures\GUITabFocused.dds alpha=on mips=off #exec texture import file=Textures\GUIPanelTop.dds alpha=on mips=off #exec texture import file=Textures\GUIPanelTopRight.dds alpha=on mips=off #exec texture import file=Textures\GUIPanelRight.dds alpha=on mips=off #exec texture import file=Textures\GUIPanelBottom.dds alpha=on mips=off // ============================================================================ // Properties // ============================================================================ var() float TabWidth; // tab width (relative to component) var() float TabHeight; // tab height (relative to screen) var() float TabSpacing; // tab spacing (relative to screen) var() int iTabFirst; // index of first visible tab var() int nTabsVisibleMax; // maximum number of tabs visible on screen var() Class<GUIMenuOption> TabComponentClass; // component class for tabs var() float TabComponentWidth; // component width (relative to tab width) var() float TabComponentHeight; // component height (relative to screen) // ============================================================================ // Variables // ============================================================================ var private int nTabs; // total number of tabs in this component var private int iTabFirstPrev; // previous number of first visible tab var private int iTabOpen; // index of currently open tab var private int iTabOpenPrev; // index of previously open tab // ============================================================================ // delegate OnTabOpened // delegate OnTabClosed // // Called when a tab is opened or closed, respectively. // ============================================================================ delegate OnTabOpened(GUIComponent GUIComponentSender, GUIMenuOption GUIMenuOptionTab); delegate OnTabClosed(GUIComponent GUIComponentSender, GUIMenuOption GUIMenuOptionTab); // ============================================================================ // delegate OnTabInit // // Called when the component for a new tab button is initialized. Can be used // to perform additional initialization of that component. // ============================================================================ delegate OnTabInit(GUIComponent GUIComponentSender, GUIMenuOption GUIMenuOptionTab) { GUIMenuOptionTab.bSquare = True; GUIMenuOptionTab.CaptionWidth = 0.9; } // ============================================================================ // delegate OnScroll // // Called when the tab component scrolls. Can be used to update any user // interface elements used to scroll the component. // ============================================================================ delegate OnScroll(GUIComponent GUIComponentSender); // ============================================================================ // InitComponent // // Initializes the component and registers several delegates. // ============================================================================ function InitComponent(GUIController GUIController, GUIComponent GUIComponentOwner) { Super.InitComponent(GUIController, GUIComponentOwner); OnPreDraw = PreDraw; OnDraw = Draw; } // ============================================================================ // FocusFirst // // Sets the focus on the currently active tab button control. If no tab is // open, opens the first one. // ============================================================================ event bool FocusFirst(GUIComponent GUIComponentSender) { if (MenuState == MSAT_Disabled || !bVisible) return False; if (iTabOpen < 0) iTabOpen = 0; return GetCurrentTabComponent().FocusFirst(Self); } // ============================================================================ // FocusLast // // Set the focus on the last regular control in this component, or the // currently active tab if none exists. // ============================================================================ event bool FocusLast(GUIComponent GUIComponentSender) { local int iControl; if (MenuState == MSAT_Disabled || !bVisible) return False; for (iControl = Controls.Length - 1; iControl >= nTabs; iControl--) if (Controls[iControl].FocusLast(Self)) return True; return FocusFirst(Self); // focus on tab } // ============================================================================ // PrevControl // // Sets the focus to the previous regular control in this component, or the // currently open tab if the first regular control is active, or leaves the // component otherwise. // ============================================================================ event bool PrevControl(GUIComponent GUIComponentSender) { local int iControl; local int iControlCurrent; iControlCurrent = FindComponentIndex(GUIComponentSender); if (iControlCurrent < nTabs) if (MenuOwner != None) return MenuOwner.PrevControl(Self); else return FocusLast(Self); for (iControl = iControlCurrent - 1; iControl >= nTabs; iControl--) if (Controls[iControl].FocusLast(Self)) return True; return FocusFirst(Self); } // ============================================================================ // NextControl // // Sets the focus to the next regular control in this component, or leaves // the component if none exists. // ============================================================================ event bool NextControl(GUIComponent GUIComponentSender) { local int iControl; local int iControlCurrent; iControlCurrent = FindComponentIndex(GUIComponentSender); for (iControl = Max(nTabs, iControlCurrent + 1); iControl < Controls.Length; iControl++) if (Controls[iControl].FocusFirst(Self)) return True; if (MenuOwner != None) return MenuOwner.NextControl(Self); return FocusFirst(Self); } // ============================================================================ // PrevTab // // Opens the previous tab and optionally sets the focus to the tab button. // ============================================================================ function PrevTab(optional bool bSetFocus) { if (iTabOpen < 0) return; iTabOpen -= 1; if (iTabOpen < 0) iTabOpen = nTabs - 1; if (bSetFocus) GetCurrentTabComponent().SetFocus(None); } // ============================================================================ // NextTab // // Opens the next tab and optionally sets the focus to the tab button. // ============================================================================ function NextTab(optional bool bSetFocus) { if (iTabOpen < 0) return; iTabOpen += 1; if (iTabOpen >= nTabs) iTabOpen = 0; if (bSetFocus) GetCurrentTabComponent().SetFocus(None); } // ============================================================================ // PreDraw // // Adjusts the placement of all tab components. // ============================================================================ function bool PreDraw(Canvas Canvas) { local int iTab; local int iTabFocused; iTabFocused = FindComponentIndex(FocusedControl); if (iTabFocused >= 0 && iTabFocused < nTabs) iTabOpen = iTabFocused; if (nTabsVisibleMax > 0) { if (iTabOpen < iTabFirst) iTabFirst = iTabOpen; else if (iTabOpen >= iTabFirst + nTabsVisibleMax) iTabFirst = iTabOpen - nTabsVisibleMax + 1; if (iTabFirst != iTabFirstPrev) OnScroll(Self); } for (iTab = 0; iTab < nTabs; iTab++) PlaceTab(GUIMenuOption(Controls[iTab]), iTab); if (iTabOpen != iTabOpenPrev) { if (iTabOpenPrev >= 0) OnTabClosed(Self, GUIMenuOption(Controls[iTabOpenPrev])); OnTabOpened(Self, GUIMenuOption(Controls[iTabOpen])); if (iTabOpenPrev >= 0) PlayerOwner().PlayOwnedSound(Controller.EditSound, SLOT_Interface, 1.0); iTabOpenPrev = iTabOpen; } return False; // execute standard code } // ============================================================================ // Draw // // Draws the tabs and the panel background. // ============================================================================ function bool Draw(Canvas Canvas) { local int iTab; for (iTab = 0; iTab < nTabs; iTab++) if (iTab == iTabOpen) DrawTab(Canvas, iTab, MSAT_Focused); else DrawTab(Canvas, iTab, GUIMenuOption(Controls[iTab]).MyLabel.MenuState); DrawPanel(Canvas, iTabOpen); return False; // execute standard code } // ============================================================================ // CalcTabMetrics // // Calculates the metrics of the specified tab and stores them in the out // parameters. // ============================================================================ function CalcTabMetrics(int iTab, optional out vector LocationTab, optional out vector SizeTab) { LocationTab.X = int(ActualLeft()); LocationTab.Y = int(ActualTop() + (iTab - iTabFirst) * (TabHeight + TabSpacing) * ActualHeight() + 32.0); SizeTab.X = int(TabWidth * ActualWidth()); SizeTab.Y = int(TabHeight * ActualHeight()); } // ============================================================================ // DrawTab // // Draws the background for the given tab in the given state. // ============================================================================ function DrawTab(Canvas Canvas, int iTab, EMenuState MenuStateTab) { local vector LocationTab; local vector SizeTab; local Material Material; if (!IsTabVisible(iTab)) return; switch (MenuStateTab) { case EMenuState.MSAT_Blurry: Material = Texture'GUITabBlurred'; break; case EMenuState.MSAT_Watched: Material = Texture'GUITabWatched'; break; case EMenuState.MSAT_Focused: Material = Texture'GUITabFocused'; break; } if (Material == None) return; CalcTabMetrics(iTab, LocationTab, SizeTab); Canvas.Style = EMenuRenderStyle.MSTY_Alpha; Canvas.SetPos(LocationTab.X, LocationTab.Y); Canvas.SetDrawColor(255, 255, 255, 255); Canvas.DrawTileStretched(Material, SizeTab.X, SizeTab.Y); } // ============================================================================ // DrawPanel // // Draws the background panel. // ============================================================================ function DrawPanel(Canvas Canvas, int iTab) { local vector LocationPanel; local vector LocationTab; local vector SizePanel; local vector SizeTab; CalcTabMetrics(iTab, LocationTab, SizeTab); LocationPanel.X = int(LocationTab.X + SizeTab.X); LocationPanel.Y = int(ActualTop()); SizePanel.X = int(ActualWidth() + ActualLeft() - LocationPanel.X); SizePanel.Y = int(ActualHeight()); Canvas.Style = EMenuRenderStyle.MSTY_Alpha; Canvas.SetDrawColor(255, 255, 255, 255); if (IsTabVisible(iTab)) { Canvas.SetPos(LocationPanel.X, LocationPanel.Y); if (iTab == iTabFirst) Canvas.DrawTileStretched(Texture'GUIPanelTopRight', SizePanel.X, 32.0); else Canvas.DrawTileStretched(Texture'GUIPanelTop', SizePanel.X, LocationTab.Y - LocationPanel.Y); Canvas.SetPos(LocationPanel.X, LocationTab.Y); Canvas.DrawTileStretched(Texture'GUIPanelRight', SizePanel.X, SizeTab.Y); Canvas.SetPos(LocationPanel.X, LocationTab.Y + SizeTab.Y); Canvas.DrawTileStretched(Texture'GUIPanelBottom', SizePanel.X, LocationPanel.Y + SizePanel.Y - Canvas.CurY); } else { Canvas.SetPos(LocationPanel.X, LocationPanel.Y); Canvas.DrawTileStretched(Texture'GUIPanelTop', SizePanel.X, 32.0); Canvas.SetPos(LocationPanel.X, LocationPanel.Y + 32.0); Canvas.DrawTileStretched(Texture'GUIPanelTop', SizePanel.X, SizePanel.Y - 32.0); } } // ============================================================================ // AddTab // // Adds a tab to the component given its title and a hint displayed in the // status line when the user hovers the tab title with the mouse. Returns an // object reference unique to the tab that can be used to identify it later. // ============================================================================ function GUIMenuOption AddTab(string TextCaption, optional string TextHint) { local int iTabAdded; local GUIMenuOption GUIMenuOptionTab; GUIMenuOptionTab = new TabComponentClass; GUIMenuOptionTab.Caption = TextCaption; GUIMenuOptionTab.Hint = TextHint; OnTabInit(Self, GUIMenuOptionTab); GUIMenuOptionTab.InitComponent(Controller, Self); GUIMenuOptionTab.MyLabel.bAcceptsInput = True; GUIMenuOptionTab.MyLabel.bMouseOverSound = True; GUIMenuOptionTab.MyLabel.OnClick = GUIMenuOptionTab_LabelClick; GUIMenuOptionTab.OnKeyEvent = GUIMenuOptionTab.MyComponent.OnKeyEvent; GUIMenuOptionTab.MyComponent.OnKeyEvent = GUIMenuOptionTab_ComponentKeyEvent; iTabAdded = nTabs; nTabs += 1; if (iTabOpen < 0) iTabOpen = iTabAdded; Controls .Insert(iTabAdded, 1); Controls [iTabAdded] = GUIMenuOptionTab; Components.Insert(iTabAdded, 1); Components[iTabAdded] = GUIMenuOptionTab; return GUIMenuOptionTab; } // ============================================================================ // AddComponentObject // // Adds an arbitrary control to this component, initializes it and returns a // reference to it. // ============================================================================ function GUIComponent AddComponentObject(GUIComponent GUIComponent) { Controls [Controls .Length] = GUIComponent; Components[Components.Length] = GUIComponent; GUIComponent.InitComponent(Controller, Self); GUIComponent.Opened(Self); return GUIComponent; } // ============================================================================ // GUIMenuOptionTab_LabelClick // // Called when a user clicks the caption of one of the tab button components. // Sets the focus to the main component (which in turn leads to this tab // being opened). // ============================================================================ function bool GUIMenuOptionTab_LabelClick(GUIComponent GUIComponentSender) { if (GUILabel(GUIComponentSender) != None) GUIComponentSender.MenuOwner.SetFocus(None); return True; } // ============================================================================ // GUIMenuOptionTab_ComponentKeyEvent // // Called when a user presses a key while one of the tab button components is // focused. Switches to another tab when the up or down arrow is pressed. // ============================================================================ function bool GUIMenuOptionTab_ComponentKeyEvent(out byte Key, out byte State, float Delta) { local GUIMenuOption GUIMenuOptionTab; if (State == 1 && Key == Controller.EInputKey.IK_Up) { PrevTab(True); return True; } else if (State == 1 && Key == Controller.EInputKey.IK_Down) { NextTab(True); return True; } GUIMenuOptionTab = GetTabComponent(iTabOpen); return GUIMenuOptionTab.OnKeyEvent(Key, State, Delta); } // ============================================================================ // PlaceTab // // Updates the position and size of the given tab button component. // ============================================================================ function PlaceTab(GUIMenuOption GUIMenuOptionTab, int iTab) { if (IsTabVisible(iTab)) { GUIMenuOptionTab.bBoundToParent = True; GUIMenuOptionTab.bScaleToParent = True; GUIMenuOptionTab.WinTop = FMax(0.0, (iTab - iTabFirst) * (TabHeight + TabSpacing)); GUIMenuOptionTab.WinLeft = 0.0; GUIMenuOptionTab.WinWidth = TabComponentWidth * TabWidth * WinWidth; GUIMenuOptionTab.WinHeight = TabComponentHeight; GUIMenuOptionTab.WinTop += (TabHeight - TabComponentHeight) / 2; GUIMenuOptionTab.WinLeft += (TabWidth * (1.0 - TabComponentWidth) * WinWidth) / 2; GUIMenuOptionTab.WinTop = int(GUIMenuOptionTab.WinTop * ActualHeight() + 32.0); } else { GUIMenuOptionTab.bBoundToParent = False; GUIMenuOptionTab.bScaleToParent = False; GUIMenuOptionTab.WinTop = 1.0; } } // ============================================================================ // GetTabComponent // // Returns the tab button component corresponding to the given tab index. // ============================================================================ function GUIMenuOption GetTabComponent(int iTab) { if (iTab < 0 || iTab >= nTabs) return None; return GUIMenuOption(Controls[iTab]); } // ============================================================================ // GetTabIndex // // Returns the tab index corresponding to the given tab button component. // ============================================================================ function int GetTabIndex(GUIMenuOption GUIMenuOptionTab) { local int iTab; iTab = FindComponentIndex(GUIMenuOptionTab); if (iTab < 0 || iTab >= nTabs) return -1; return iTab; } // ============================================================================ // IsTabVisible // // Checks and returns whether the tab with the given index is currently // visible on the screen. // ============================================================================ function bool IsTabVisible(int iTab) { if (nTabsVisibleMax <= 0) return True; return (iTab >= iTabFirst && iTab < iTabFirst + nTabsVisibleMax); } // ============================================================================ // GetCurrentTabComponent // GetCurrentTabIndex // // Return a reference to the tab button component of the currently open tab or // its tab index, respectively. // ============================================================================ function GUIMenuOption GetCurrentTabComponent() { return GetTabComponent(iTabOpen); } function int GetCurrentTabIndex() { return iTabOpen; } // ============================================================================ // CountTabs // CountTabsVisible // // Return the total number of tabs in this component and the number of tabs // currently visible on the screen, respectively. // ============================================================================ function int CountTabs() { return nTabs; } function int CountTabsVisible() { return Max(nTabs - iTabFirst, nTabsVisibleMax); } // ============================================================================ // Defaults // ============================================================================ defaultproperties { bTabStop = True; PropagateVisibility = False; iTabFirstPrev = -1; iTabOpen = -1; iTabOpenPrev = -1; TabWidth = 0.330; TabHeight = 0.080; TabSpacing = 0.020; TabComponentClass = Class'moCheckBox'; TabComponentWidth = 0.850; TabComponentHeight = 0.035; } |
Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |