summaryrefslogtreecommitdiff
path: root/libs/dgl/ntk/NtkWidget.hpp
blob: 2247be3841a9cf0c3b87e22ac41bb428a351fec4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
 * DISTRHO Plugin Framework (DPF)
 * Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com>
 *
 * Permission to use, copy, modify, and/or distribute this software for any purpose with
 * or without fee is hereby granted, provided that the above copyright notice and this
 * permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
 * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef DGL_NTK_WIDGET_HPP_INCLUDED
#define DGL_NTK_WIDGET_HPP_INCLUDED

#include "NtkWindow.hpp"

START_NAMESPACE_DGL

// -----------------------------------------------------------------------

/**
   DGL compatible Widget class that uses NTK instead of OpenGL.
   @see Widget
 */
class NtkWidget : public Fl_Double_Window
{
public:
   /**
      Constructor.
    */
    explicit NtkWidget(NtkWindow& parent)
        : Fl_Double_Window(100, 100),
          fParent(parent)
    {
        fParent.add(this);
        show();
    }

   /**
      Destructor.
    */
    ~NtkWidget() override
    {
        hide();
        fParent.remove(this);
    }

   /**
      Check if this widget is visible within its parent window.
      Invisible widgets do not receive events except resize.
    */
    bool isVisible() const
    {
        return visible();
    }

   /**
      Set widget visible (or not) according to @a yesNo.
    */
    void setVisible(bool yesNo)
    {
        if (yesNo)
            show();
        else
            hide();
    }

   /**
      Get width.
    */
    int getWidth() const
    {
        return w();
    }

   /**
      Get height.
    */
    int getHeight() const
    {
        return h();
    }

   /**
      Set width.
    */
    void setWidth(int width)
    {
        resize(x(), y(), width, h());
    }

   /**
      Set height.
    */
    void setHeight(int height)
    {
        resize(x(), y(), w(), height);
    }

   /**
      Set size using @a width and @a height values.
    */
    void setSize(int width, int height)
    {
        resize(x(), y(), width, height);
    }

   /**
      Get absolute X.
    */
    int getAbsoluteX() const
    {
        return x();
    }

   /**
      Get absolute Y.
    */
    int getAbsoluteY() const
    {
        return y();
    }

   /**
      Set absolute X.
    */
    void setAbsoluteX(int x)
    {
        resize(x, y(), w(), h());
    }

   /**
      Set absolute Y.
    */
    void setAbsoluteY(int y)
    {
        resize(x(), y, w(), h());
    }

   /**
      Set absolute position using @a x and @a y values.
    */
    void setAbsolutePos(int x, int y)
    {
        resize(x, y, w(), h());
    }

   /**
      Get this widget's window application.
      Same as calling getParentWindow().getApp().
    */
    NtkApp& getParentApp() const noexcept
    {
        return fParent.getApp();
    }

   /**
      Get parent window, as passed in the constructor.
    */
    NtkWindow& getParentWindow() const noexcept
    {
        return fParent;
    }

   /**
      Check if this widget contains the point defined by @a x and @a y.
    */
    bool contains(int x, int y) const
    {
        return (x >= 0 && y >= 0 && x < w() && y < h());
    }

   /**
      Tell this widget's window to repaint itself.
    */
    void repaint()
    {
        redraw();
    }

protected:
   /** @internal used for DGL compatibility. */
    void setNeedsFullViewport(bool) noexcept {}
   /** @internal used for DGL compatibility. */
    void setNeedsScaling(bool) noexcept {}

private:
    NtkWindow& fParent;

    DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(NtkWidget)
};

// -----------------------------------------------------------------------

END_NAMESPACE_DGL

#endif // DGL_NTK_WIDGET_HPP_INCLUDED