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 
17 #ifndef DGL_WIDGET_PRIVATE_DATA_HPP_INCLUDED
18 #define DGL_WIDGET_PRIVATE_DATA_HPP_INCLUDED
19 
20 #include "../Widget.hpp"
21 #include "../Window.hpp"
22 
23 #include <vector>
24 
25 START_NAMESPACE_DGL
26 
27 // -----------------------------------------------------------------------
28 
29 struct Widget::PrivateData {
30     Widget* const self;
31     Window& parent;
32     Point<int> absolutePos;
33     Size<uint> size;
34     std::vector<Widget*> subWidgets;
35 
36     uint id;
37     bool needsFullViewport;
38     bool needsScaling;
39     bool skipDisplay;
40     bool visible;
41 
PrivateDataWidget::PrivateData42     PrivateData(Widget* const s, Window& p, Widget* groupWidget, bool addToSubWidgets)
43         : self(s),
44           parent(p),
45           absolutePos(0, 0),
46           size(0, 0),
47           subWidgets(),
48           id(0),
49           needsFullViewport(false),
50           needsScaling(false),
51           skipDisplay(false),
52           visible(true)
53     {
54         if (addToSubWidgets && groupWidget != nullptr)
55         {
56             skipDisplay = true;
57             groupWidget->pData->subWidgets.push_back(self);
58         }
59     }
60 
~PrivateDataWidget::PrivateData61     ~PrivateData()
62     {
63         subWidgets.clear();
64     }
65 
66     // display function is different depending on build type
67     void display(const uint width, const uint height, const double scaling, const bool renderingSubWidget);
68 
displaySubWidgetsWidget::PrivateData69     void displaySubWidgets(const uint width, const uint height, const double scaling)
70     {
71         for (std::vector<Widget*>::iterator it = subWidgets.begin(); it != subWidgets.end(); ++it)
72         {
73             Widget* const widget(*it);
74             DISTRHO_SAFE_ASSERT_CONTINUE(widget->pData != this);
75 
76             widget->pData->display(width, height, scaling, true);
77         }
78     }
79 
80     DISTRHO_DECLARE_NON_COPY_STRUCT(PrivateData)
81 };
82 
83 // -----------------------------------------------------------------------
84 
85 END_NAMESPACE_DGL
86 
87 #endif // DGL_WIDGET_PRIVATE_DATA_HPP_INCLUDED
88