FractalWidgetUtils.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include "FractalWidgetUtils.h"
  2. CellImage::~CellImage(void)
  3. {
  4. }
  5. ImageClip::ImageClip(std::shared_ptr<ETVImage> tex,
  6. float tx, float ty, float tw, float th) :
  7. etvImage{ std::move(tex) },
  8. tx{ tx }, ty{ ty }, tw{ tw }, th{ th }
  9. {
  10. }
  11. ImageClip::~ImageClip(void)
  12. {
  13. }
  14. void ImageClip::drawRect(float x, float y, float width, float height)
  15. {
  16. etvImage->draw(x, y, width, height, tx, ty, tw, th);
  17. }
  18. ImageClip ImageClip::clip(float x, float y, float w, float h)
  19. {
  20. float tx = this->tx + x * this->tw;
  21. float ty = this->ty + y * this->th;
  22. float tw = this->tw * w;
  23. float th = this->th * h;
  24. return ImageClip{ this->etvImage, tx, ty, tw, th };
  25. }
  26. std::shared_ptr<CellImage> ImageClip::clip(short i, short j)
  27. {
  28. return std::make_shared<ImageClip>(clip(i * 0.5f, j * 0.5f, 0.5f, 0.5f));
  29. }
  30. int ImageClip::getRecalcPriority() const
  31. {
  32. return int(1.0f / tw);
  33. }
  34. QuadImage::QuadImage(std::shared_ptr<CellImage> i00,
  35. std::shared_ptr<CellImage> i01,
  36. std::shared_ptr<CellImage> i10,
  37. std::shared_ptr<CellImage> i11) :
  38. cells{ { std::move(i00), std::move(i01) },
  39. { std::move(i10), std::move(i11) } }
  40. {
  41. }
  42. QuadImage::~QuadImage(void)
  43. {
  44. }
  45. void QuadImage::drawRect(QOpenGLShaderProgram* program,
  46. float x, float y, float width, float height)
  47. {
  48. for (int i = 0; i < 2; i++) {
  49. for (int j = 0; j < 2; j++) {
  50. this->cells[i][j]->drawRect(program,
  51. x + i * 0.5f * width,
  52. y + j * 0.5f * height,
  53. width * 0.5f,
  54. height * 0.5f);
  55. }
  56. }
  57. }
  58. std::shared_ptr<CellImage> QuadImage::clip(short i, short j)
  59. {
  60. return cells[i][j];
  61. }
  62. int QuadImage::getRecalcPriority() const
  63. {
  64. return 1;
  65. }