guiMaterialPreview.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. // Original header:
  23. // GuiMaterialPreview Control for Material Editor Written by Travis Vroman of Gaslight Studios
  24. // Updated 2-14-09
  25. // Portions based off Constructor viewport code.
  26. #ifndef _GUIMATERIALPREVIEW_H_
  27. #define _GUIMATERIALPREVIEW_H_
  28. #include "gui/3d/guiTSControl.h"
  29. #include "ts/tsShapeInstance.h"
  30. class LightInfo;
  31. class GuiMaterialPreview : public GuiTSCtrl
  32. {
  33. private:
  34. typedef GuiTSCtrl Parent;
  35. protected:
  36. enum MouseState
  37. {
  38. None,
  39. Rotating,
  40. Zooming,
  41. Panning,
  42. MovingLight
  43. };
  44. MouseState mMouseState;
  45. TSShapeInstance* mModel;
  46. TSShapeInstance* mMountedModel;
  47. U32 mSkinTag;
  48. // For Camera Panning.
  49. F32 mTransStep; //*** Amount of translation with each mouse move
  50. F32 mTranMult; //*** With a modifier, how much faster to translate
  51. // For light translation.
  52. F32 mLightTransStep;
  53. F32 mLightTranMult;
  54. Point3F mCameraPos;
  55. MatrixF mCameraMatrix;
  56. EulerF mCameraRot;
  57. Point3F mOrbitPos;
  58. Point3F mOrbitRelPos;
  59. Point3F mCameraTransform;
  60. TSThread * runThread;
  61. S32 lastRenderTime;
  62. Point2I mLastMousePoint;
  63. LightInfo* mFakeSun;
  64. void renderSunDirection() const;
  65. public:
  66. bool onWake() override;
  67. void onMouseEnter(const GuiEvent &event) override;
  68. void onMouseLeave(const GuiEvent &event) override;
  69. void onMouseDown(const GuiEvent &event) override;
  70. void onMouseUp(const GuiEvent &event) override;
  71. void onMouseDragged(const GuiEvent &event) override;
  72. void onRightMouseDown(const GuiEvent &event) override;
  73. void onRightMouseUp(const GuiEvent &event) override;
  74. void onRightMouseDragged(const GuiEvent &event) override;
  75. bool onMouseWheelUp(const GuiEvent &event) override;
  76. bool onMouseWheelDown(const GuiEvent &event) override;
  77. void onMiddleMouseUp(const GuiEvent &event) override;
  78. void onMiddleMouseDown(const GuiEvent &event) override;
  79. void onMiddleMouseDragged(const GuiEvent &event) override;
  80. // For Camera Panning.
  81. void setTranslate(S32 modifier, F32 xstep, F32 ystep);
  82. // For Light Translation.
  83. void setLightTranslate(S32 modifier, F32 xstep, F32 ystep);
  84. // For changing the light color.
  85. void setLightColor( F32 r, F32 g, F32 b );
  86. // For changing the ambient light color.
  87. void setAmbientLightColor( F32 r, F32 g, F32 b );
  88. void setObjectModel(const char * modelName);
  89. void deleteModel();
  90. void resetViewport();
  91. void setOrbitDistance(F32 distance);
  92. bool processCameraQuery(CameraQuery *query) override;
  93. void renderWorld(const RectI &updateRect) override;
  94. DECLARE_CONOBJECT(GuiMaterialPreview);
  95. DECLARE_CATEGORY( "Gui Editor" );
  96. GuiMaterialPreview();
  97. ~GuiMaterialPreview();
  98. private:
  99. F32 mMaxOrbitDist;
  100. F32 mMinOrbitDist;
  101. F32 mOrbitDist;
  102. };
  103. #endif