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.

223 lines
5.0KB

  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. #ifndef DGL_BASE_HPP_INCLUDED
  17. #define DGL_BASE_HPP_INCLUDED
  18. #include "../distrho/extra/LeakDetector.hpp"
  19. #include "../distrho/extra/ScopedPointer.hpp"
  20. // -----------------------------------------------------------------------
  21. // Define namespace
  22. #ifndef DGL_NAMESPACE
  23. # define DGL_NAMESPACE DGL
  24. #endif
  25. #define START_NAMESPACE_DGL namespace DGL_NAMESPACE {
  26. #define END_NAMESPACE_DGL }
  27. #define USE_NAMESPACE_DGL using namespace DGL_NAMESPACE;
  28. #ifdef DISTRHO_OS_WINDOWS
  29. // -----------------------------------------------------------------------
  30. // Fix OpenGL includes for Windows, based on glfw code
  31. #ifndef APIENTRY
  32. # define APIENTRY __stdcall
  33. #endif // APIENTRY
  34. /* We need WINGDIAPI defined */
  35. #ifndef WINGDIAPI
  36. # if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__POCC__)
  37. # define WINGDIAPI __declspec(dllimport)
  38. # elif defined(__LCC__)
  39. # define WINGDIAPI __stdcall
  40. # else
  41. # define WINGDIAPI extern
  42. # endif
  43. # define DGL_WINGDIAPI_DEFINED
  44. #endif // WINGDIAPI
  45. /* Some <GL/glu.h> files also need CALLBACK defined */
  46. #ifndef CALLBACK
  47. # if defined(_MSC_VER)
  48. # if (defined(_M_MRX000) || defined(_M_IX86) || defined(_M_ALPHA) || defined(_M_PPC)) && !defined(MIDL_PASS)
  49. # define CALLBACK __stdcall
  50. # else
  51. # define CALLBACK
  52. # endif
  53. # else
  54. # define CALLBACK __stdcall
  55. # endif
  56. # define DGL_CALLBACK_DEFINED
  57. #endif // CALLBACK
  58. /* Most GL/glu.h variants on Windows need wchar_t */
  59. #include <cstddef>
  60. #endif // DISTRHO_OS_WINDOWS
  61. // -----------------------------------------------------------------------
  62. // OpenGL includes
  63. #ifdef HAVE_DGL
  64. #ifdef DISTRHO_OS_MAC
  65. # include <OpenGL/gl.h>
  66. #else
  67. # ifndef DISTRHO_OS_WINDOWS
  68. # define GL_GLEXT_PROTOTYPES
  69. # endif
  70. # include <GL/gl.h>
  71. # include <GL/glext.h>
  72. #endif
  73. #endif
  74. // -----------------------------------------------------------------------
  75. // Cairo includes
  76. #ifdef HAVE_DCAIRO
  77. # include <cairo/cairo.h>
  78. #endif
  79. // -----------------------------------------------------------------------
  80. // Missing OpenGL defines
  81. #ifdef HAVE_DGL
  82. #if defined(GL_BGR_EXT) && ! defined(GL_BGR)
  83. # define GL_BGR GL_BGR_EXT
  84. #endif
  85. #if defined(GL_BGRA_EXT) && ! defined(GL_BGRA)
  86. # define GL_BGRA GL_BGRA_EXT
  87. #endif
  88. #ifndef GL_CLAMP_TO_BORDER
  89. # define GL_CLAMP_TO_BORDER 0x812D
  90. #endif
  91. #endif
  92. #ifdef DISTRHO_OS_WINDOWS
  93. // -----------------------------------------------------------------------
  94. // Fix OpenGL includes for Windows, based on glfw code
  95. #ifdef DGL_WINGDIAPI_DEFINED
  96. # undef WINGDIAPI
  97. # undef DGL_WINGDIAPI_DEFINED
  98. #endif
  99. #ifdef DGL_CALLBACK_DEFINED
  100. # undef CALLBACK
  101. # undef DGL_CALLBACK_DEFINED
  102. #endif
  103. #endif // DISTRHO_OS_WINDOWS
  104. START_NAMESPACE_DGL
  105. // -----------------------------------------------------------------------
  106. // Base DGL enums
  107. /**
  108. Convenience symbols for ASCII control characters.
  109. */
  110. enum Char {
  111. kCharBackspace = 0x08,
  112. kCharEscape = 0x1B,
  113. kCharDelete = 0x7F
  114. };
  115. /**
  116. Keyboard modifier flags.
  117. */
  118. enum Modifier {
  119. kModifierShift = 1 << 0, /**< Shift key */
  120. kModifierControl = 1 << 1, /**< Control key */
  121. kModifierAlt = 1 << 2, /**< Alt/Option key */
  122. kModifierSuper = 1 << 3 /**< Mod4/Command/Windows key */
  123. };
  124. /**
  125. Special (non-Unicode) keyboard keys.
  126. */
  127. enum Key {
  128. kKeyF1 = 1,
  129. kKeyF2,
  130. kKeyF3,
  131. kKeyF4,
  132. kKeyF5,
  133. kKeyF6,
  134. kKeyF7,
  135. kKeyF8,
  136. kKeyF9,
  137. kKeyF10,
  138. kKeyF11,
  139. kKeyF12,
  140. kKeyLeft,
  141. kKeyUp,
  142. kKeyRight,
  143. kKeyDown,
  144. kKeyPageUp,
  145. kKeyPageDown,
  146. kKeyHome,
  147. kKeyEnd,
  148. kKeyInsert,
  149. kKeyShift,
  150. kKeyControl,
  151. kKeyAlt,
  152. kKeySuper
  153. };
  154. // -----------------------------------------------------------------------
  155. // Base DGL classes
  156. /**
  157. Idle callback.
  158. */
  159. class IdleCallback
  160. {
  161. public:
  162. virtual ~IdleCallback() {}
  163. virtual void idleCallback() = 0;
  164. };
  165. /**
  166. Graphics context.
  167. */
  168. struct Context
  169. {
  170. #ifdef HAVE_DCAIRO
  171. cairo_t* cairo;
  172. #endif
  173. };
  174. // -----------------------------------------------------------------------
  175. END_NAMESPACE_DGL
  176. #ifndef DONT_SET_USING_DGL_NAMESPACE
  177. // If your code uses a lot of DGL classes, then this will obviously save you
  178. // a lot of typing, but can be disabled by setting DONT_SET_USING_DGL_NAMESPACE.
  179. using namespace DGL_NAMESPACE;
  180. #endif
  181. // -----------------------------------------------------------------------
  182. #endif // DGL_BASE_HPP_INCLUDED