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.

138 lines
3.9KB

  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* const rawData,
  49. const uint width,
  50. const uint height);
  51. /**
  52. Constructor using raw image data.
  53. @note @a rawData must remain valid for the lifetime of this Image.
  54. */
  55. CairoImage(const char* const rawData,
  56. const Size<uint>& size);
  57. /**
  58. Constructor using another image data.
  59. */
  60. CairoImage(const CairoImage& image);
  61. /**
  62. Destructor.
  63. */
  64. ~CairoImage() override;
  65. /**
  66. Draw this image at position @a pos using the graphics context @a context.
  67. */
  68. void drawAt(const GraphicsContext& context, const Point<int>& pos) override;
  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. Cairo TopLevelWidget, handy class that takes graphics context during onDisplay and passes it in a new function.
  90. */
  91. class CairoTopLevelWidget : public TopLevelWidget
  92. {
  93. public:
  94. CairoTopLevelWidget(Window& windowToMapTo)
  95. : TopLevelWidget(windowToMapTo) {}
  96. protected:
  97. void onDisplay() override
  98. {
  99. const CairoGraphicsContext& context((const CairoGraphicsContext&)getGraphicsContext());
  100. onCairoDisplay(context);
  101. }
  102. virtual void onCairoDisplay(const CairoGraphicsContext& context) = 0;
  103. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CairoTopLevelWidget);
  104. };
  105. // --------------------------------------------------------------------------------------------------------------------
  106. typedef ImageBaseAboutWindow<CairoImage> CairoImageAboutWindow;
  107. // --------------------------------------------------------------------------------------------------------------------
  108. END_NAMESPACE_DGL
  109. #endif