Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

190 lines
5.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. #include "HapticControlBox.h"
  3. #include <vgui_controls/Controls.h>
  4. #include <vgui_controls/Panel.h>
  5. #include "cvarslider.h"
  6. #include "mathlib/vmatrix.h"
  7. #include <vgui/ISurface.h>
  8. #include "KeyValues.h"
  9. #include <vgui/ISystem.h>
  10. ControlBoxVisual::ControlBoxVisual(vgui::Panel *parent,const char *panelName, CCvarSlider *n, CCvarSlider *r, CCvarSlider *u, CCvarSlider *f, CCvarSlider *l, CCvarSlider *d) :
  11. BaseClass(parent,panelName)
  12. {
  13. m_iMouseOver = -1;
  14. m_flTime=0;
  15. //disable mouse input.
  16. SetMouseInputEnabled(false);
  17. SlideValues = new CCvarSliderCube(n, r, u, f, l, d);
  18. SlideValues->Down->AddActionSignalTarget(GetVPanel());
  19. SlideValues->Far->AddActionSignalTarget(GetVPanel());
  20. SlideValues->Up->AddActionSignalTarget(GetVPanel());
  21. SlideValues->Near->AddActionSignalTarget(GetVPanel());
  22. SlideValues->Left->AddActionSignalTarget(GetVPanel());
  23. SlideValues->Right->AddActionSignalTarget(GetVPanel());
  24. SetWide(64);
  25. SetTall(64);
  26. }
  27. void ControlBoxVisual::OnSlideEnter(KeyValues*data)
  28. {
  29. vgui::VPANEL fromPanel = data->GetInt("VPANEL");
  30. if(fromPanel == SlideValues->Up->GetVPanel())
  31. m_iMouseOver = HUI_BOX_UP;
  32. else if(fromPanel == SlideValues->Down->GetVPanel())
  33. m_iMouseOver = HUI_BOX_DOWN;
  34. else if(fromPanel == SlideValues->Right->GetVPanel())
  35. m_iMouseOver = HUI_BOX_RIGHT;
  36. else if(fromPanel == SlideValues->Left->GetVPanel())
  37. m_iMouseOver = HUI_BOX_LEFT;
  38. else if(fromPanel == SlideValues->Far->GetVPanel())
  39. m_iMouseOver = HUI_BOX_FAR;
  40. else if(fromPanel == SlideValues->Near->GetVPanel())
  41. m_iMouseOver = HUI_BOX_NEAR;
  42. }
  43. void ControlBoxVisual::OnSlideExit(KeyValues*data)
  44. {
  45. //vgui::VPANEL fromPanel = data->GetInt("VPANEL");
  46. m_iMouseOver=-1;
  47. }
  48. void ControlBoxVisual::Paint()
  49. {
  50. m_flTime = vgui::system()->GetFrameTime();
  51. BaseClass::Paint();
  52. vgui::surface()->DrawSetColor(0,0,0,255);
  53. DrawCube();
  54. vgui::surface()->DrawSetColor(255,255,255,255);
  55. //first draw the cube once.
  56. DrawCube( SlideValues->Near->GetSliderValue()*-1,
  57. SlideValues->Right->GetSliderValue()*-1,
  58. SlideValues->Up->GetSliderValue()*-1,
  59. SlideValues->Far->GetSliderValue(),
  60. SlideValues->Left->GetSliderValue(),
  61. SlideValues->Down->GetSliderValue());
  62. //then check if we have something selected
  63. if(m_iMouseOver!=-1)
  64. {
  65. vgui::surface()->DrawSetColor(255,0,0,255);
  66. // if we do, draw a special cube.
  67. DrawCube( SlideValues->Near->GetSliderValue()*-1,
  68. SlideValues->Right->GetSliderValue()*-1,
  69. SlideValues->Up->GetSliderValue()*-1,
  70. SlideValues->Far->GetSliderValue(),
  71. SlideValues->Left->GetSliderValue(),
  72. SlideValues->Down->GetSliderValue(),
  73. m_iMouseOver);
  74. }
  75. }
  76. void ControlBoxVisual::DrawCube(float n, float r, float u, float f, float l, float d, int specialside)
  77. {
  78. l*=-1;
  79. r*=-1;//flip
  80. Vector right[4];
  81. //right side
  82. right[0]= Vector(f,r,d);
  83. right[1]= Vector(f,r,u);
  84. right[2]= Vector(n,r,u);
  85. right[3]= Vector(n,r,d);
  86. Vector left[4];
  87. //left side
  88. left[0]= Vector(f,l,d);
  89. left[1]= Vector(f,l,u);
  90. left[2]= Vector(n,l,u);
  91. left[3]= Vector(n,l,d);
  92. //yikes, this is kind of alot of typing.
  93. switch(specialside)
  94. {
  95. case HUI_BOX_UP:
  96. left[0] = left[1];
  97. left[3] = left[2];
  98. left[1] =Vector(1,-1,-1);
  99. left[2] =Vector(-1,-1,-1);
  100. right[0]= right[1];
  101. right[3]= right[2];
  102. right[1]=Vector(1,1,-1);
  103. right[2]=Vector(-1,1,-1);
  104. break;
  105. case HUI_BOX_DOWN:
  106. left[1] = left[0];
  107. left[2] = left[3];
  108. left[0] =Vector(1,-1,1);
  109. left[3] =Vector(-1,-1,1);
  110. right[1] = right[0];
  111. right[2] = right[3];
  112. right[0] =Vector(1,1,1);
  113. right[3] =Vector(-1,1,1);
  114. break;
  115. case HUI_BOX_LEFT:
  116. right[0] = left[0];
  117. right[1] = left[1];
  118. right[2] = left[2];
  119. right[3] = left[3];
  120. left[0] =Vector(1,-1,1);
  121. left[1] =Vector(1,-1,-1);
  122. left[2] =Vector(-1,-1,-1);
  123. left[3] =Vector(-1,-1,1);
  124. break;
  125. case HUI_BOX_RIGHT:
  126. left[0] = right[0];
  127. left[1] = right[1];
  128. left[2] = right[2];
  129. left[3] = right[3];
  130. right[0] =Vector(1,1,1);
  131. right[1] =Vector(1,1,-1);
  132. right[2] =Vector(-1,1,-1);
  133. right[3] =Vector(-1,1,1);
  134. break;
  135. case HUI_BOX_FAR:
  136. left[3] = left[0];
  137. left[2] = left[1];
  138. left[0] =Vector(1,-1,1);
  139. left[1] =Vector(1,-1,-1);
  140. right[3] = right[0];
  141. right[2] = right[1];
  142. right[0] =Vector(1,1,1);
  143. right[1] =Vector(1,1,-1);
  144. break;
  145. case HUI_BOX_NEAR:
  146. left[0] = left[3];
  147. left[1] = left[2];
  148. left[3] =Vector(-1,-1,1);
  149. left[2] =Vector(-1,-1,-1);
  150. right[0] = right[3];
  151. right[1] = right[2];
  152. right[3] =Vector(-1,1,1);
  153. right[2] =Vector(-1,1,-1);
  154. break;
  155. default:
  156. break;
  157. }
  158. Vector pos = Vector(0,0.25 + sin(m_flTime),0.5);
  159. VMatrix Project = SetupMatrixProjection(pos,VPlane(Vector(1,0,0),-3));
  160. Vector vdrawsize = Vector(1,(float)GetWide()/10.0f,(float)GetTall()/10.0f);
  161. for(int i=0;i!=4;i++)
  162. {
  163. right[i] = Project.VMul3x3(right[i])*vdrawsize;
  164. left[i] = Project.VMul3x3(left[i])*vdrawsize;
  165. }
  166. vdrawsize *=5;
  167. for(int i = 0;i!=4;i++)
  168. {
  169. int next = i+1;
  170. if(next>3)
  171. next = 0;
  172. vgui::surface()->DrawLine(vdrawsize.y+left[i].y,vdrawsize.z+left[i].z,vdrawsize.y+left[next].y,vdrawsize.z+left[next].z);
  173. vgui::surface()->DrawLine(vdrawsize.y+right[i].y,vdrawsize.z+right[i].z,vdrawsize.y+right[next].y,vdrawsize.z+right[next].z);
  174. vgui::surface()->DrawLine(vdrawsize.y+left[i].y,vdrawsize.z+left[i].z,vdrawsize.y+right[i].y,vdrawsize.z+right[i].z);
  175. }
  176. }