DISTRHO Plugin Framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
3.3KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "WidgetPrivateData.hpp"
  17. #ifdef DGL_CAIRO
  18. # include "../Cairo.hpp"
  19. #endif
  20. #ifdef DGL_OPENGL
  21. # include "../OpenGL.hpp"
  22. #endif
  23. START_NAMESPACE_DGL
  24. // -----------------------------------------------------------------------
  25. void Widget::PrivateData::display(const uint width,
  26. const uint height,
  27. const double scaling,
  28. const bool renderingSubWidget)
  29. {
  30. if ((skipDisplay && ! renderingSubWidget) || size.isInvalid() || ! visible)
  31. return;
  32. #ifdef DGL_OPENGL
  33. bool needsDisableScissor = false;
  34. // reset color
  35. glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
  36. if (needsFullViewport || (absolutePos.isZero() && size == Size<uint>(width, height)))
  37. {
  38. // full viewport size
  39. glViewport(0,
  40. -(height * scaling - height),
  41. width * scaling,
  42. height * scaling);
  43. }
  44. else if (needsScaling)
  45. {
  46. // limit viewport to widget bounds
  47. glViewport(absolutePos.getX(),
  48. height - self->getHeight() - absolutePos.getY(),
  49. self->getWidth(),
  50. self->getHeight());
  51. }
  52. else
  53. {
  54. // only set viewport pos
  55. glViewport(absolutePos.getX() * scaling,
  56. -std::round((height * scaling - height) + (absolutePos.getY() * scaling)),
  57. std::round(width * scaling),
  58. std::round(height * scaling));
  59. // then cut the outer bounds
  60. glScissor(absolutePos.getX() * scaling,
  61. height - std::round((self->getHeight() + absolutePos.getY()) * scaling),
  62. std::round(self->getWidth() * scaling),
  63. std::round(self->getHeight() * scaling));
  64. glEnable(GL_SCISSOR_TEST);
  65. needsDisableScissor = true;
  66. }
  67. #endif
  68. #ifdef DGL_CAIRO
  69. cairo_t* cr = static_cast<const CairoGraphicsContext&>(parent.getGraphicsContext()).cairo;
  70. cairo_matrix_t matrix;
  71. cairo_get_matrix(cr, &matrix);
  72. cairo_translate(cr, absolutePos.getX(), absolutePos.getY());
  73. // TODO: scaling and cropping
  74. #endif
  75. // display widget
  76. self->onDisplay();
  77. #ifdef DGL_CAIRO
  78. cairo_set_matrix(cr, &matrix);
  79. #endif
  80. #ifdef DGL_OPENGL
  81. if (needsDisableScissor)
  82. {
  83. glDisable(GL_SCISSOR_TEST);
  84. needsDisableScissor = false;
  85. }
  86. #endif
  87. displaySubWidgets(width, height, scaling);
  88. }
  89. // -----------------------------------------------------------------------
  90. END_NAMESPACE_DGL