home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / RESOURCES / KOOB / common / client / cursor.cs < prev    next >
Encoding:
Text File  |  2005-11-23  |  2.8 KB  |  98 lines

  1. //-----------------------------------------------------------------------------
  2. // Torque Game Engine 
  3. // Copyright (C) GarageGames.com, Inc.
  4. //-----------------------------------------------------------------------------
  5.  
  6. //------------------------------------------------------------------------------
  7. // Cursor Control
  8. //------------------------------------------------------------------------------
  9.  
  10. $cursorControlled = true;
  11.  
  12. function cursorOff()
  13. {
  14.    if ( $cursorControlled )
  15.       lockMouse(true);
  16.    Canvas.cursorOff();
  17. }
  18.  
  19. function cursorOn()
  20. {
  21.    if ( $cursorControlled )
  22.       lockMouse(false);
  23.    Canvas.cursorOn();
  24.    Canvas.setCursor(DefaultCursor); 
  25. }
  26.  
  27. // In the CanvasCursor package we add some additional functionality to the
  28. // built-in GuiCanvas class, of which the global Canvas object is an instance.
  29. // In this case, the behavior we want is for the cursor to automatically display,
  30. // except when the only guis visible want no cursor - most notably,
  31. // in the case of the example, the play gui.
  32. // In order to override or extend an existing class, we use the script package
  33. // feature.
  34.  
  35. package CanvasCursor
  36. {
  37.  
  38. // The checkCursor method iterates through all the root controls on the canvas
  39. // (basically the content control and any visible dialogs).  If all of them
  40. // have the .noCursor attribute set, the cursor is turned off, otherwise it is
  41. // turned on.
  42.  
  43. function GuiCanvas::checkCursor(%this)
  44. {
  45.    %cursorShouldBeOn = false;
  46.    for(%i = 0; %i < %this.getCount(); %i++)
  47.    {
  48.       %control = %this.getObject(%i);
  49.       if(%control.noCursor == 0)
  50.       {
  51.          %cursorShouldBeOn = true;
  52.          break;
  53.       }
  54.    }
  55.    if(%cursorShouldBeOn != %this.isCursorOn())
  56.    {
  57.       if(%cursorShouldBeOn)
  58.          cursorOn();
  59.       else
  60.          cursorOff();
  61.    }
  62. }
  63.  
  64. // below, all functions which can alter which content controls are visible
  65. // are extended to call the checkCursor function.  For package'd functions,
  66. // the Parent:: call refers to the original implementation of that function,
  67. // or a version that was declared in a previously activated package.
  68. // In this case the parent calls should point to the built in versions
  69. // of GuiCanvas functions.
  70.  
  71. function GuiCanvas::setContent(%this, %ctrl)
  72. {
  73.    Parent::setContent(%this, %ctrl);
  74.    %this.checkCursor();
  75. }
  76.  
  77. function GuiCanvas::pushDialog(%this, %ctrl, %layer)
  78. {
  79.    Parent::pushDialog(%this, %ctrl, %layer);
  80.    %this.checkCursor();
  81. }
  82.  
  83. function GuiCanvas::popDialog(%this, %ctrl)
  84. {
  85.    Parent::popDialog(%this, %ctrl);
  86.    %this.checkCursor();
  87. }
  88.  
  89. function GuiCanvas::popLayer(%this, %layer)
  90. {
  91.    Parent::popLayer(%this, %layer);
  92.    %this.checkCursor();
  93. }
  94.  
  95. };
  96.  
  97. // activate the package when the script loads.
  98. activatePackage(CanvasCursor);