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.

157 lines
4.3KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2021 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. #ifndef DGL_CAIRO_HPP_INCLUDED
  17. #define DGL_CAIRO_HPP_INCLUDED
  18. #include "ImageBase.hpp"
  19. #include "ImageBaseWidgets.hpp"
  20. #include "SubWidget.hpp"
  21. #include <cairo/cairo.h>
  22. START_NAMESPACE_DGL
  23. // --------------------------------------------------------------------------------------------------------------------
  24. /**
  25. Cairo Graphics context.
  26. */
  27. struct CairoGraphicsContext : GraphicsContext
  28. {
  29. cairo_t* handle;
  30. };
  31. // --------------------------------------------------------------------------------------------------------------------
  32. /**
  33. Cairo Image class.
  34. TODO ...
  35. */
  36. class CairoImage : public ImageBase
  37. {
  38. public:
  39. /**
  40. Constructor for a null Image.
  41. */
  42. CairoImage();
  43. /**
  44. Constructor using raw image data.
  45. @note @a rawData must remain valid for the lifetime of this Image.
  46. */
  47. CairoImage(const char* rawData, uint width, uint height, ImageFormat format);
  48. /**
  49. Constructor using raw image data.
  50. @note @a rawData must remain valid for the lifetime of this Image.
  51. */
  52. CairoImage(const char* rawData, const Size<uint>& size, ImageFormat format);
  53. /**
  54. Constructor using another image data.
  55. */
  56. CairoImage(const CairoImage& image);
  57. /**
  58. Destructor.
  59. */
  60. ~CairoImage() override;
  61. /**
  62. Draw this image at position @a pos using the graphics context @a context.
  63. */
  64. void drawAt(const GraphicsContext& context, const Point<int>& pos) override;
  65. // FIXME this should not be needed
  66. inline void drawAt(const GraphicsContext& context, int x, int y)
  67. { drawAt(context, Point<int>(x, y)); };
  68. };
  69. // --------------------------------------------------------------------------------------------------------------------
  70. /**
  71. CairoWidget, handy class that takes graphics context during onDisplay and passes it in a new function.
  72. */
  73. template <class BaseWidget>
  74. class CairoWidget : public BaseWidget
  75. {
  76. public:
  77. /**
  78. Constructor for a CairoSubWidget.
  79. @see CreateFlags
  80. */
  81. explicit CairoWidget(Widget* const parentGroupWidget);
  82. /**
  83. Constructor for a CairoTopLevelWidget.
  84. @see CreateFlags
  85. */
  86. explicit CairoWidget(Window& windowToMapTo);
  87. /**
  88. Constructor for a CairoStandaloneWindow without parent window.
  89. @see CreateFlags
  90. */
  91. explicit CairoWidget(Application& app);
  92. /**
  93. Constructor for a CairoStandaloneWindow with parent window.
  94. @see CreateFlags
  95. */
  96. explicit CairoWidget(Application& app, Window& parentWindow);
  97. /**
  98. Destructor.
  99. */
  100. virtual ~CairoWidget() {}
  101. protected:
  102. /**
  103. New virtual onDisplay function.
  104. @see onDisplay
  105. */
  106. virtual void onCairoDisplay(const CairoGraphicsContext& context) = 0;
  107. private:
  108. /**
  109. Widget display function.
  110. Implemented internally to wrap begin/endFrame() automatically.
  111. */
  112. void onDisplay() override
  113. {
  114. const CairoGraphicsContext& context((const CairoGraphicsContext&)BaseWidget::getGraphicsContext());
  115. onCairoDisplay(context);
  116. }
  117. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CairoWidget);
  118. };
  119. typedef CairoWidget<SubWidget> CairoSubWidget;
  120. typedef CairoWidget<TopLevelWidget> CairoTopLevelWidget;
  121. typedef CairoWidget<StandaloneWindow> CairoStandaloneWindow;
  122. // --------------------------------------------------------------------------------------------------------------------
  123. typedef ImageBaseAboutWindow<CairoImage> CairoImageAboutWindow;
  124. // --------------------------------------------------------------------------------------------------------------------
  125. END_NAMESPACE_DGL
  126. #endif