DPF OpenGL examples
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.

140 lines
3.3KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2014 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. // ------------------------------------------------------
  17. // DGL Stuff
  18. #include "ImageButton.hpp"
  19. #include "StandaloneWindow.hpp"
  20. #include "widgets/ExampleColorWidget.hpp"
  21. #include "widgets/ExampleImagesWidget.hpp"
  22. #include "widgets/ExampleRectanglesWidget.hpp"
  23. #include "widgets/ExampleShapesWidget.hpp"
  24. // ------------------------------------------------------
  25. // Images
  26. #include "images_res/CatPics.cpp"
  27. // ------------------------------------------------------
  28. // use namespace
  29. using DGL::App;
  30. using DGL::ImageButton;
  31. using DGL::Size;
  32. // ------------------------------------------------------
  33. // Our Demo Window
  34. class LeftSizeWidget : public Widget
  35. {
  36. public:
  37. LeftSizeWidget(Window& parent)
  38. : Widget(parent),
  39. rect(0, 0, 100, 0)
  40. {
  41. }
  42. protected:
  43. void onDisplay() override
  44. {
  45. glColor3f(0.302f/5, 0.337f/5, 0.361f/5);
  46. rect.draw();
  47. // reset color
  48. glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
  49. }
  50. void onReshape(int, int height) override
  51. {
  52. // always 100px width
  53. rect.setHeight(height);
  54. setSize(100, height);
  55. }
  56. private:
  57. Rectangle<int> rect;
  58. };
  59. // ------------------------------------------------------
  60. // Our Demo Window
  61. class DemoWindow : public Window
  62. {
  63. public:
  64. DemoWindow(App& app)
  65. : Window(app),
  66. wColor(*this),
  67. wImages(*this),
  68. wRects(*this),
  69. wShapes(*this),
  70. wLeft(*this),
  71. b1(*this, Image()),
  72. b2(*this, Image())
  73. {
  74. //wColor.hide();
  75. wImages.hide();
  76. wRects.hide();
  77. wShapes.hide();
  78. wColor.setX(100);
  79. wImages.setX(100);
  80. wRects.setX(100);
  81. wShapes.setX(100);
  82. setSize(600, 500);
  83. setTitle("DGL Demo");
  84. //wLeft.toFront();
  85. }
  86. void onReshape(int width, int height) override
  87. {
  88. Size<int> size(width-100, height);
  89. wColor.setSize(size);
  90. wImages.setSize(size);
  91. wRects.setSize(size);
  92. wShapes.setSize(size);
  93. Window::onReshape(width, height);
  94. }
  95. private:
  96. ExampleColorWidget wColor;
  97. ExampleImagesWidget wImages;
  98. ExampleRectanglesWidget wRects;
  99. ExampleShapesWidget wShapes;
  100. LeftSizeWidget wLeft;
  101. ImageButton b1, b2;
  102. };
  103. // ------------------------------------------------------
  104. // main entry point
  105. int main()
  106. {
  107. App app;
  108. DemoWindow win(app);
  109. win.show();
  110. app.exec();
  111. return 0;
  112. }
  113. // ------------------------------------------------------