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.

141 lines
4.1KB

  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 "TopLevelWidget.hpp"
  22. #include <cairo/cairo.h>
  23. START_NAMESPACE_DGL
  24. // --------------------------------------------------------------------------------------------------------------------
  25. /**
  26. Cairo Graphics context.
  27. */
  28. struct CairoGraphicsContext : GraphicsContext
  29. {
  30. cairo_t* handle;
  31. };
  32. // --------------------------------------------------------------------------------------------------------------------
  33. /**
  34. Cairo Image class.
  35. TODO ...
  36. */
  37. class CairoImage : public ImageBase
  38. {
  39. public:
  40. /**
  41. Constructor for a null Image.
  42. */
  43. CairoImage();
  44. /**
  45. Constructor using raw image data.
  46. @note @a rawData must remain valid for the lifetime of this Image.
  47. */
  48. CairoImage(const char* rawData, uint width, uint height, ImageFormat format);
  49. /**
  50. Constructor using raw image data.
  51. @note @a rawData must remain valid for the lifetime of this Image.
  52. */
  53. CairoImage(const char* rawData, const Size<uint>& size, ImageFormat format);
  54. /**
  55. Constructor using another image data.
  56. */
  57. CairoImage(const CairoImage& image);
  58. /**
  59. Destructor.
  60. */
  61. ~CairoImage() override;
  62. /**
  63. Draw this image at position @a pos using the graphics context @a context.
  64. */
  65. void drawAt(const GraphicsContext& context, const Point<int>& pos) override;
  66. // FIXME this should not be needed
  67. inline void drawAt(const GraphicsContext& context, int x, int y)
  68. { drawAt(context, Point<int>(x, y)); };
  69. };
  70. // --------------------------------------------------------------------------------------------------------------------
  71. /**
  72. Cairo SubWidget, handy class that takes graphics context during onDisplay and passes it in a new function.
  73. */
  74. class CairoSubWidget : public SubWidget
  75. {
  76. public:
  77. CairoSubWidget(Widget* widgetToGroupTo)
  78. : SubWidget(widgetToGroupTo) {}
  79. protected:
  80. void onDisplay() override
  81. {
  82. const CairoGraphicsContext& context((const CairoGraphicsContext&)getGraphicsContext());
  83. onCairoDisplay(context);
  84. }
  85. virtual void onCairoDisplay(const CairoGraphicsContext& context) = 0;
  86. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CairoSubWidget);
  87. };
  88. // --------------------------------------------------------------------------------------------------------------------
  89. /**
  90. Cairo TopLevelWidget, handy class that takes graphics context during onDisplay and passes it in a new function.
  91. */
  92. class CairoTopLevelWidget : public TopLevelWidget
  93. {
  94. public:
  95. CairoTopLevelWidget(Window& windowToMapTo)
  96. : TopLevelWidget(windowToMapTo) {}
  97. protected:
  98. void onDisplay() override
  99. {
  100. const CairoGraphicsContext& context((const CairoGraphicsContext&)getGraphicsContext());
  101. onCairoDisplay(context);
  102. }
  103. virtual void onCairoDisplay(const CairoGraphicsContext& context) = 0;
  104. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CairoTopLevelWidget);
  105. };
  106. // --------------------------------------------------------------------------------------------------------------------
  107. typedef ImageBaseAboutWindow<CairoImage> CairoImageAboutWindow;
  108. // --------------------------------------------------------------------------------------------------------------------
  109. END_NAMESPACE_DGL
  110. #endif