2
0

UITexturedQuad.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. #include <Renderer/Texture.h>
  5. /// Helper class that points to a subsection of a texture for rendering it as a quad. Can specify borders which won't scale (only inner part of the quad will scale).
  6. class UITexturedQuad
  7. {
  8. public:
  9. /// Constructor
  10. UITexturedQuad() = default;
  11. UITexturedQuad(const Texture *inTexture) : mTexture(inTexture), mWidth(inTexture->GetWidth()), mHeight(inTexture->GetHeight()) { }
  12. UITexturedQuad(const Texture *inTexture, int inX, int inY, int inWidth, int inHeight) : mTexture(inTexture), mX(inX), mY(inY), mWidth(inWidth), mHeight(inHeight) { }
  13. UITexturedQuad(const Texture *inTexture, int inX, int inY, int inWidth, int inHeight, int inInnerX, int inInnerY, int inInnerWidth, int inInnerHeight) : mTexture(inTexture), mX(inX), mY(inY), mWidth(inWidth), mHeight(inHeight), mInnerX(inInnerX), mInnerY(inInnerY), mInnerWidth(inInnerWidth), mInnerHeight(inInnerHeight) { }
  14. /// Check if this quad consists of 9 parts
  15. bool HasInnerPart() const { return mInnerX >= 0 && mInnerY >= 0 && mInnerWidth >= 0 && mInnerHeight >= 0; }
  16. /// The texture to use
  17. RefConst<Texture> mTexture;
  18. /// These are the normal texel coordinates for the quad
  19. int mX = 0;
  20. int mY = 0;
  21. int mWidth = 0;
  22. int mHeight = 0;
  23. /// This quad can also scale its inner part leaving borders in tact, in this case the inner scaling part is defined here
  24. int mInnerX = -1;
  25. int mInnerY = -1;
  26. int mInnerWidth = -1;
  27. int mInnerHeight = -1;
  28. };