Przeglądaj źródła

Added Size(), Width() and Height() to IntRect.

Lasse Öörni 13 lat temu
rodzic
commit
ba890672dd

+ 12 - 9
Docs/ScriptAPI.dox

@@ -291,15 +291,6 @@ Properties:<br>
 - bool empty (readonly)
 
 
-IntRect
-
-Properties:<br>
-- int left
-- int top
-- int right
-- int bottom
-
-
 IntVector2
 
 Methods:<br>
@@ -310,6 +301,18 @@ Properties:<br>
 - int y
 
 
+IntRect
+
+Properties:<br>
+- IntVector2 size (readonly)
+- int width (readonly)
+- int height (readonly)
+- int left
+- int top
+- int right
+- int bottom
+
+
 Vector2
 
 Methods:<br>

+ 4 - 1
Engine/Engine/MathAPI.cpp

@@ -123,6 +123,9 @@ static void RegisterIntRect(asIScriptEngine* engine)
     engine->RegisterObjectBehaviour("IntRect", asBEHAVE_CONSTRUCT, "void f(int, int, int, int)", asFUNCTION(ConstructIntRectInit), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("IntRect", "IntRect& opAssign(const IntRect&in)", asMETHOD(IntRect, operator =), asCALL_THISCALL);
     engine->RegisterObjectMethod("IntRect", "bool opEquals(const IntRect&in) const", asMETHOD(IntRect, operator ==), asCALL_THISCALL);
+    engine->RegisterObjectMethod("IntRect", "IntVector2 get_size() const", asMETHOD(IntRect, Size), asCALL_THISCALL);
+    engine->RegisterObjectMethod("IntRect", "int get_width() const", asMETHOD(IntRect, Width), asCALL_THISCALL);
+    engine->RegisterObjectMethod("IntRect", "int get_height() const", asMETHOD(IntRect, Height), asCALL_THISCALL);
     engine->RegisterObjectProperty("IntRect", "int left", offsetof(IntRect, left_));
     engine->RegisterObjectProperty("IntRect", "int top", offsetof(IntRect, top_));
     engine->RegisterObjectProperty("IntRect", "int right", offsetof(IntRect, right_));
@@ -1000,8 +1003,8 @@ static void RegisterColor(asIScriptEngine* engine)
 void RegisterMathAPI(asIScriptEngine* engine)
 {
     RegisterMathFunctions(engine);
-    RegisterIntRect(engine);
     RegisterIntVector2(engine);
+    RegisterIntRect(engine);
     RegisterVector2(engine);
     RegisterVector3(engine);
     RegisterVector4(engine);

+ 4 - 4
Engine/Graphics/Batch.cpp

@@ -95,8 +95,8 @@ void CalculateShadowMatrix(Matrix4& dest, LightBatchQueue* queue, unsigned split
     );
     
     Vector2 scale(
-        0.5f * (float)(viewport.right_ - viewport.left_) / width,
-        0.5f * (float)(viewport.bottom_ - viewport.top_) / height
+        0.5f * (float)viewport.Width() / width,
+        0.5f * (float)viewport.Height() / height
     );
     
     #ifdef USE_OPENGL
@@ -264,8 +264,8 @@ void Batch::Prepare(Graphics* graphics, Renderer* renderer, bool setModelTransfo
     {
         float rtWidth = (float)rtSize.x_;
         float rtHeight = (float)rtSize.y_;
-        float widthRange = 0.5f * (viewport.right_ - viewport.left_) / rtWidth;
-        float heightRange = 0.5f * (viewport.bottom_ - viewport.top_) / rtHeight;
+        float widthRange = 0.5f * viewport.Width() / rtWidth;
+        float heightRange = 0.5f * viewport.Height() / rtHeight;
         
         #ifdef USE_OPENGL
         Vector4 bufferUVOffset(((float)viewport.left_) / rtWidth + widthRange,

+ 4 - 4
Engine/Graphics/Direct3D9/D3D9Graphics.cpp

@@ -1414,8 +1414,8 @@ void Graphics::SetViewport(const IntRect& rect)
     vp.MaxZ = 1.0f;
     vp.X = rectCopy.left_;
     vp.Y = rectCopy.top_;
-    vp.Width = rectCopy.right_ - rectCopy.left_;
-    vp.Height = rectCopy.bottom_ - rectCopy.top_;
+    vp.Width = rectCopy.Width();
+    vp.Height = rectCopy.Height();
     
     impl_->device_->SetViewport(&vp);
     viewport_ = rectCopy;
@@ -1535,7 +1535,7 @@ void Graphics::SetScissorTest(bool enable, const Rect& rect, bool borderInclusiv
     if (enable)
     {
         IntVector2 rtSize(GetRenderTargetDimensions());
-        IntVector2 viewSize(viewport_.right_ - viewport_.left_, viewport_.bottom_ - viewport_.top_);
+        IntVector2 viewSize(viewport_.Size());
         IntVector2 viewPos(viewport_.left_, viewport_.top_);
         IntRect intRect;
         int expand = borderInclusive ? 1 : 0;
@@ -1578,7 +1578,7 @@ void Graphics::SetScissorTest(bool enable, const Rect& rect, bool borderInclusiv
 void Graphics::SetScissorTest(bool enable, const IntRect& rect)
 {
     IntVector2 rtSize(GetRenderTargetDimensions());
-    IntVector2 viewSize(viewport_.right_ - viewport_.left_, viewport_.bottom_ - viewport_.top_);
+    IntVector2 viewSize(viewport_.Size());
     IntVector2 viewPos(viewport_.left_, viewport_.top_);
     
     if (enable)

+ 7 - 7
Engine/Graphics/OpenGL/OGLGraphics.cpp

@@ -523,7 +523,7 @@ void Graphics::Clear(unsigned flags, const Color& color, float depth, unsigned s
     /// \todo Any user-set scissor test will be lost
     IntVector2 viewSize = GetRenderTargetDimensions();
     if (viewport_.left_ != 0 || viewport_.top_ != 0 || viewport_.right_ != viewSize.x_ || viewport_.bottom_ != viewSize.y_)
-        SetScissorTest(true, IntRect(0, 0, viewport_.right_ - viewport_.left_, viewport_.bottom_ - viewport_.top_));
+        SetScissorTest(true, IntRect(0, 0, viewport_.Width(), viewport_.Height()));
     else
         SetScissorTest(false);
     
@@ -558,7 +558,7 @@ bool Graphics::ResolveToTexture(Texture2D* destination, const IntRect& viewport)
     // Use Direct3D convention with the vertical coordinates ie. 0 is top
     SetTextureForUpdate(destination);
     glCopyTexSubImage2D(GL_TEXTURE_2D, 0, vpCopy.left_, height_ - vpCopy.bottom_, vpCopy.left_, height_ - vpCopy.bottom_,
-        vpCopy.right_ - vpCopy.left_, vpCopy.bottom_ - vpCopy.top_);
+        vpCopy.Width(), vpCopy.Height());
     SetTexture(0, 0);
     
     return true;
@@ -1372,7 +1372,7 @@ void Graphics::SetViewport(const IntRect& rect)
     rectCopy.bottom_ = Clamp(rectCopy.bottom_, 0, rtSize.y_);
     
     // Use Direct3D convention with the vertical coordinates ie. 0 is top
-    glViewport(rectCopy.left_, rtSize.y_ - rectCopy.bottom_, rectCopy.right_ - rectCopy.left_, rectCopy.bottom_ - rectCopy.top_);
+    glViewport(rectCopy.left_, rtSize.y_ - rectCopy.bottom_, rectCopy.Width(), rectCopy.Height());
     viewport_ = rectCopy;
     
     // Disable scissor test, needs to be re-enabled by the user
@@ -1486,7 +1486,7 @@ void Graphics::SetScissorTest(bool enable, const Rect& rect, bool borderInclusiv
     if (enable)
     {
         IntVector2 rtSize(GetRenderTargetDimensions());
-        IntVector2 viewSize(viewport_.right_ - viewport_.left_, viewport_.bottom_ - viewport_.top_);
+        IntVector2 viewSize(viewport_.Size());
         IntVector2 viewPos(viewport_.left_, viewport_.top_);
         IntRect intRect;
         int expand = borderInclusive ? 1 : 0;
@@ -1507,7 +1507,7 @@ void Graphics::SetScissorTest(bool enable, const Rect& rect, bool borderInclusiv
         if (enable && scissorRect_ != intRect)
         {
             // Use Direct3D convention with the vertical coordinates ie. 0 is top
-            glScissor(intRect.left_, rtSize.y_ - intRect.bottom_, intRect.right_ - intRect.left_, intRect.bottom_ - intRect.top_);
+            glScissor(intRect.left_, rtSize.y_ - intRect.bottom_, intRect.Width(), intRect.Height());
             scissorRect_ = intRect;
         }
     }
@@ -1527,7 +1527,7 @@ void Graphics::SetScissorTest(bool enable, const Rect& rect, bool borderInclusiv
 void Graphics::SetScissorTest(bool enable, const IntRect& rect)
 {
     IntVector2 rtSize(GetRenderTargetDimensions());
-    IntVector2 viewSize(viewport_.right_ - viewport_.left_, viewport_.bottom_ - viewport_.top_);
+    IntVector2 viewSize(viewport_.Size());
     IntVector2 viewPos(viewport_.left_, viewport_.top_);
     
     if (enable)
@@ -1549,7 +1549,7 @@ void Graphics::SetScissorTest(bool enable, const IntRect& rect)
         if (enable && scissorRect_ != intRect)
         {
             // Use Direct3D convention with the vertical coordinates ie. 0 is top
-            glScissor(intRect.left_, rtSize.y_ - intRect.bottom_, intRect.right_ - intRect.left_, intRect.bottom_ - intRect.top_);
+            glScissor(intRect.left_, rtSize.y_ - intRect.bottom_, intRect.Width(), intRect.Height());
             scissorRect_ = intRect;
         }
     }

+ 1 - 1
Engine/Graphics/Renderer.cpp

@@ -630,7 +630,7 @@ void Renderer::Update(float timeStep)
         if (!updatedOctrees_.Contains(octree))
         {
             frame_.camera_ = viewport->GetCamera();
-            frame_.viewSize_ = IntVector2(viewRect.right_ - viewRect.left_, viewRect.bottom_ - viewRect.top_);
+            frame_.viewSize_ = viewRect.Size();
             if (frame_.viewSize_ == IntVector2::ZERO)
                 frame_.viewSize_ = IntVector2(graphics_->GetWidth(), graphics_->GetHeight());
             octree->Update(frame_);

+ 3 - 3
Engine/Graphics/View.cpp

@@ -358,7 +358,7 @@ bool View::Define(RenderSurface* renderTarget, Viewport* viewport)
     else
         viewRect_ = IntRect(0, 0, rtWidth, rtHeight);
     
-    viewSize_ = IntVector2(viewRect_.right_ - viewRect_.left_, viewRect_.bottom_ - viewRect_.top_);
+    viewSize_ = viewRect_.Size();
     rtSize_ = IntVector2(rtWidth, rtHeight);
     
     // On OpenGL flip the viewport if rendering to a texture for consistent UV addressing with Direct3D9
@@ -2124,7 +2124,7 @@ void View::FinalizeShadowCamera(Camera* shadowCamera, Light* light, const IntRec
     const BoundingBox& shadowCasterBox)
 {
     const FocusParameters& parameters = light->GetShadowFocus();
-    float shadowMapWidth = (float)(shadowViewport.right_ - shadowViewport.left_);
+    float shadowMapWidth = (float)(shadowViewport.Width());
     LightType type = light->GetLightType();
     
     if (type == LIGHT_DIRECTIONAL)
@@ -2179,7 +2179,7 @@ void View::QuantizeDirLightShadowCamera(Camera* shadowCamera, Light* light, cons
 {
     Node* shadowCameraNode = shadowCamera->GetNode();
     const FocusParameters& parameters = light->GetShadowFocus();
-    float shadowMapWidth = (float)(shadowViewport.right_ - shadowViewport.left_);
+    float shadowMapWidth = (float)(shadowViewport.Width());
     
     float minX = viewBox.min_.x_;
     float minY = viewBox.min_.y_;

+ 1 - 1
Engine/IO/Deserializer.cpp

@@ -117,7 +117,7 @@ float Deserializer::ReadFloat()
 IntRect Deserializer::ReadIntRect()
 {
     IntRect ret;
-    Read((void*)ret.GetData(), sizeof ret);
+    Read((void*)ret.Data(), sizeof ret);
     return ret;
 }
 

+ 1 - 1
Engine/IO/Serializer.cpp

@@ -79,7 +79,7 @@ bool Serializer::WriteFloat(float value)
 
 bool Serializer::WriteIntRect(const IntRect& value)
 {
-    return Write(value.GetData(), sizeof value) == sizeof value;
+    return Write(value.Data(), sizeof value) == sizeof value;
 }
 
 bool Serializer::WriteIntVector2(const IntVector2& value)

+ 8 - 1
Engine/Math/Rect.h

@@ -200,8 +200,15 @@ public:
     bool operator == (const IntRect& rhs) const { return left_ == rhs.left_ && top_ == rhs.top_ && right_ == rhs.right_ && bottom_ == rhs.bottom_; }
     /// Test for inequality with another rect.
     bool operator != (const IntRect& rhs) const { return left_ != rhs.left_ || top_ != rhs.top_ || right_ != rhs.right_ || bottom_ != rhs.bottom_; }
+    
+    /// Return size.
+    IntVector2 Size() const { return IntVector2(Width(), Height()); }
+    /// Return width.
+    int Width() const { return right_ - left_; }
+    /// Return height.
+    int Height() const { return bottom_ - top_; }
     /// Return integer data.
-    const int* GetData() const { return &left_; }
+    const int* Data() const { return &left_; }
     /// Return as string.
     String ToString() const;
     

+ 1 - 1
Engine/UI/Cursor.cpp

@@ -104,7 +104,7 @@ void Cursor::SetShape(CursorShape shape)
     CursorShapeInfo& info = shapeInfos_[shape_];
     texture_ = info.texture_;
     imageRect_ = info.imageRect_;
-    SetSize(info.imageRect_.right_ - info.imageRect_.left_, info.imageRect_.bottom_ - info.imageRect_.top_);
+    SetSize(info.imageRect_.Size());
 }
 
 void Cursor::GetBatches(PODVector<UIBatch>& batches, PODVector<UIQuad>& quads, const IntRect& currentScissor)