cellip.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //---------------------------------------------------------------------------
  2. //
  3. // cellip.cpp - This file contains the code for the VFX Ellipse Element
  4. //
  5. //---------------------------------------------------------------------------//
  6. // Copyright (C) Microsoft Corporation. All rights reserved. //
  7. //===========================================================================//
  8. //---------------------------------------------------------------------------
  9. // Include files
  10. #ifndef CELLIP_H
  11. #include "cellip.h"
  12. #endif
  13. #ifndef VPORT_H
  14. #include "vport.h"
  15. #endif
  16. #ifndef TXMMGR_H
  17. #include "txmmgr.h"
  18. #endif
  19. unsigned long EllipseElement::s_textureHandle = 0;
  20. //---------------------------------------------------------------------------
  21. // Static Globals
  22. //---------------------------------------------------------------------------
  23. EllipseElement::EllipseElement (Stuff::Vector2DOf<long> &cntr, Stuff::Vector2DOf<long> &ortho, long clr, long depth) : Element(depth)
  24. {
  25. for ( int i = 0; i < 5; ++i )
  26. {
  27. location[i].argb = clr;
  28. location[i].frgb = 0;
  29. location[i].u = 0.f;
  30. location[i].v = 0.f;
  31. location[i].rhw = .5;
  32. location[i].z =0.f;
  33. }
  34. location[0].x = location[1].x = cntr.x - ortho.x/2;
  35. location[2].x = location[3].x = cntr.x + ortho.x/2;
  36. location[0].y = location[3].y = cntr.y - ortho.y/2;
  37. location[1].y = location[2].y = cntr.y + ortho.y/2;
  38. location[3].u = location[2].u = 1.0f;
  39. location[1].v = location[2].v = 1.0f;
  40. location[4] = location[0];
  41. }
  42. //---------------------------------------------------------------------------
  43. void EllipseElement::draw (void)
  44. {
  45. gos_SetRenderState( gos_State_Filter, gos_FilterNone );
  46. gos_SetRenderState( gos_State_AlphaMode, gos_Alpha_AlphaInvAlpha );
  47. gos_SetRenderState( gos_State_AlphaTest, true );
  48. DWORD gosTextureHandle = mcTextureManager->get_gosTextureHandle (s_textureHandle);
  49. gos_SetRenderState( gos_State_Texture, gosTextureHandle );
  50. gos_SetRenderState( gos_State_Clipping, 2);
  51. gos_SetRenderState( gos_State_Specular, 0);
  52. gos_SetRenderState( gos_State_Fog, 0);
  53. if ( clip.left != 0 || clip.right != 0 || clip.top != 0 || clip.bottom != 0 )
  54. {
  55. gos_VERTEX newLocation[4];
  56. for ( int i = 0; i < 4; ++i )
  57. {
  58. newLocation[i] = location[i];
  59. }
  60. if ( location[0].x > clip.right )
  61. return;
  62. if ( location[2].x < clip.left )
  63. return;
  64. if ( location[0].x < clip.left )
  65. {
  66. newLocation[0].u = newLocation[1].u = ((float)clip.left-location[0].x)/(location[2].x - location[0].x);
  67. newLocation[0].x = newLocation[1].x = (float)clip.left;
  68. }
  69. if ( location[2].x > clip.right )
  70. {
  71. newLocation[2].u = newLocation[3].u = ((float)clip.right-location[0].x)/(location[2].x-location[0].x);
  72. newLocation[2].x = newLocation[3].x = (float)clip.right;
  73. }
  74. if ( location[2].y < clip.top )
  75. return;
  76. if ( location[0].y > clip.bottom )
  77. return;
  78. if ( location[0].y < clip.top )
  79. {
  80. newLocation[0].v = newLocation[3].v = ((float)clip.top - location[0].y )/(location[1].y - location[0].y);
  81. newLocation[0].y = newLocation[3].y = (float)clip.top;
  82. }
  83. if ( location[2].y > clip.bottom )
  84. {
  85. newLocation[1].v = newLocation[2].v = ((float)clip.bottom - location[0].y)/(location[2].y-location[0].y);
  86. newLocation[1].y = newLocation[2].y = (float)clip.bottom;
  87. }
  88. gos_DrawQuads( newLocation, 4 );
  89. }
  90. else
  91. {
  92. gos_DrawTriangles( location, 3 );
  93. gos_DrawTriangles( &location[2], 3 );
  94. }
  95. }
  96. void EllipseElement::init()
  97. {
  98. if ( !s_textureHandle )
  99. {
  100. s_textureHandle = mcTextureManager->loadTexture("data\\art\\ring.tga", gos_Texture_Alpha, 0 );
  101. }
  102. }
  103. void EllipseElement::setClip( const GUI_RECT& rect )
  104. {
  105. clip = rect;
  106. }
  107. void EllipseElement::removeTextureHandle (void)
  108. {
  109. if (s_textureHandle)
  110. mcTextureManager->removeTextureNode(s_textureHandle);
  111. s_textureHandle = 0;
  112. }
  113. //---------------------------------------------------------------------------