CmViewport.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. -----------------------------------------------------------------------------
  3. This source file is part of OGRE
  4. (Object-oriented Graphics Rendering Engine)
  5. For the latest info, see http://www.ogre3d.org/
  6. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #include "CmViewport.h"
  25. #include "CmException.h"
  26. #include "CmRenderTarget.h"
  27. #include "CmMath.h"
  28. #include "CmRenderSystem.h"
  29. namespace CamelotEngine {
  30. //---------------------------------------------------------------------
  31. Viewport::Viewport()
  32. :mTarget(nullptr)
  33. , mRelLeft(0)
  34. , mRelTop(0)
  35. , mRelWidth(0)
  36. , mRelHeight(0)
  37. // Actual dimensions will update later
  38. , mZOrder(0)
  39. {
  40. // Calculate actual dimensions
  41. updateDimensions();
  42. }
  43. //---------------------------------------------------------------------
  44. Viewport::Viewport(RenderTargetPtr target, float left, float top, float width, float height, int ZOrder)
  45. :mTarget(target)
  46. , mRelLeft(left)
  47. , mRelTop(top)
  48. , mRelWidth(width)
  49. , mRelHeight(height)
  50. // Actual dimensions will update later
  51. , mZOrder(ZOrder)
  52. {
  53. // Calculate actual dimensions
  54. updateDimensions();
  55. }
  56. //---------------------------------------------------------------------
  57. Viewport::~Viewport()
  58. {
  59. }
  60. //---------------------------------------------------------------------
  61. void Viewport::updateDimensions(void)
  62. {
  63. if(mTarget != nullptr)
  64. {
  65. float height = (float) mTarget->getHeight();
  66. float width = (float) mTarget->getWidth();
  67. mActLeft = (int) (mRelLeft * width);
  68. mActTop = (int) (mRelTop * height);
  69. mActWidth = (int) (mRelWidth * width);
  70. mActHeight = (int) (mRelHeight * height);
  71. }
  72. }
  73. //---------------------------------------------------------------------
  74. int Viewport::getZOrder(void) const
  75. {
  76. return mZOrder;
  77. }
  78. //---------------------------------------------------------------------
  79. RenderTargetPtr Viewport::getTarget(void) const
  80. {
  81. return mTarget;
  82. }
  83. //---------------------------------------------------------------------
  84. float Viewport::getLeft(void) const
  85. {
  86. return mRelLeft;
  87. }
  88. //---------------------------------------------------------------------
  89. float Viewport::getTop(void) const
  90. {
  91. return mRelTop;
  92. }
  93. //---------------------------------------------------------------------
  94. float Viewport::getWidth(void) const
  95. {
  96. return mRelWidth;
  97. }
  98. //---------------------------------------------------------------------
  99. float Viewport::getHeight(void) const
  100. {
  101. return mRelHeight;
  102. }
  103. //---------------------------------------------------------------------
  104. int Viewport::getActualLeft(void) const
  105. {
  106. return mActLeft;
  107. }
  108. //---------------------------------------------------------------------
  109. int Viewport::getActualTop(void) const
  110. {
  111. return mActTop;
  112. }
  113. //---------------------------------------------------------------------
  114. int Viewport::getActualWidth(void) const
  115. {
  116. return mActWidth;
  117. }
  118. //---------------------------------------------------------------------
  119. int Viewport::getActualHeight(void) const
  120. {
  121. return mActHeight;
  122. }
  123. //---------------------------------------------------------------------
  124. void Viewport::setDimensions(float left, float top, float width, float height)
  125. {
  126. mRelLeft = left;
  127. mRelTop = top;
  128. mRelWidth = width;
  129. mRelHeight = height;
  130. updateDimensions();
  131. }
  132. //---------------------------------------------------------------------
  133. void Viewport::getActualDimensions(int &left, int&top, int &width, int &height) const
  134. {
  135. left = mActLeft;
  136. top = mActTop;
  137. width = mActWidth;
  138. height = mActHeight;
  139. }
  140. }