docs/html/glWidget_8h_source.html
| | Jetson Inference
DNN Vision Library |
glWidget.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
22
23 #ifndef __GL_WIDGET_H__
24 #define __GL_WIDGET_H__
25
26
27 #include <stdint.h>
28 #include <stdio.h>
29 #include <vector>
30
31
32 // forward declarations
33 class glDisplay;
34
35
41 {
42 public:
47 {
51 };
52
56glWidget( Shape shape=Rect );
57
61glWidget( float x, float y, float width, float height, Shape shape=Rect );
62
66virtual ~glWidget();
67
71bool Contains( float x, float y ) const;
72
76inline void Move( float x, float y ) { mX += x; mY += y; }
77
81inline float X() const { return mX; }
82
86inline float Y() const { return mY; }
87
91inline void SetX( float x ) { mX = x; }
92
96inline void SetY( float y ) { mY = y; }
97
101inline float Width() const { return mWidth; }
102
106inline float Height() const { return mHeight; }
107
111inline void SetWidth( float width ) { mWidth = width; }
112
116inline void SetHeight( float height ) { mHeight = height; }
117
121inline void GetPosition( float* x, float* y ) const { if(x) *x=mX; if(y) *y=mY; }
122
126inline void SetPosition( float x, float y ) { mX = x; mY = y; }
127
131inline void GetCoords( float* x1, float* y1, float* x2, float* y2 ) const { if(x1) *x1=mX; if(y1) *y1=mY; if(x2) *x2=mX+mWidth; if(y2) *y2=mY+mHeight; }
132
136inline void SetCoords( float x1, float y1, float x2, float y2 ) { mX = x1; mY = y1; mWidth=x2-x1; mHeight=y2-y1; }
137
141inline void GetSize( float* width, float* height ) const { if(width) *width=mWidth; if(height) *height=mHeight; }
142
146inline void SetSize( float width, float height ) { mWidth = width; mHeight = height; }
147
151inline Shape GetShape() const { return mShape; }
152
156inline void SetShape( Shape shape ) { mShape = shape; }
157
161inline void SetFillAlpha( float a ) { mFillColor[3] = a; }
162
166inline void SetLineAlpha( float a ) { mLineColor[3] = a; }
167
171inline void SetLineWidth( float width ) { mLineWidth = width; }
172
176inline void SetFillColor( float r, float g, float b, float a=1.0f ) { mFillColor[0] = r; mFillColor[1] = g; mFillColor[2] = b; mFillColor[3] = a; }
177
181inline void SetLineColor( float r, float g, float b, float a=1.0f ) { mLineColor[0] = r; mLineColor[1] = g; mLineColor[2] = b; mLineColor[3] = a; }
182
186inline void SetSelectedFillColor( float r, float g, float b, float a=1.0f ) { mSelectedFillColor[0] = r; mSelectedFillColor[1] = g; mSelectedFillColor[2] = b; mSelectedFillColor[3] = a; }
187
191inline void SetSelectedLineColor( float r, float g, float b, float a=1.0f ) { mSelectedLineColor[0] = r; mSelectedLineColor[1] = g; mSelectedLineColor[2] = b; mSelectedLineColor[3] = a; }
192
196inline bool IsMoveable() const { return mMoveable; }
197
201inline void SetMoveable( bool moveable ) { mMoveable = moveable; }
202
206inline bool IsResizeable() const { return mResizeable; }
207
211inline void SetResizeable( bool resizeable ) { mResizeable = resizeable; }
212
216inline bool IsSelected() const { return mSelected; }
217
221inline void SetSelected( bool selected ) { mSelected = true; }
222
226inline bool IsVisible() const { return mVisible; }
227
231inline void SetVisible( bool visible ) { mVisible = visible; }
232
236inline void* GetUserData() const { return mUserData; }
237
241inline void SetUserData( void* user ) { mUserData = user; }
242
246inline glDisplay* GetDisplay() const { return mDisplay; }
247
251int GetIndex() const;
252
256void Render();
257
261void GlobalToLocal( float x, float y, float* x_out, float* y_out ) const;
262
266void LocalToGlobal( float x, float y, float* x_out, float* y_out ) const;
267
281typedef bool (*glWidgetEventHandler)(glWidget* widget, uint16_t event, int a, int b, void* user);
282
289void AddEventHandler( glWidgetEventHandler callback, void* user=NULL );
290
297void RemoveEventHandler( glWidgetEventHandler callback, void* user=NULL );
298
302bool OnEvent( uint16_t event, int a, int b, void* user );
303
304
305 protected:
307
309 {
320 };
321
322struct eventHandler
323 {
324glWidgetEventHandler callback;
326 };
327
328void initDefaults();
329void setCursor( DragState cursor );
330void setDisplay( glDisplay* display );
331void dispatchEvent( uint16_t msg, int a, int b );
332
333DragState coordToBorder( float x, float y, float max_distance=10.0f );
334
339
340float mSelectedFillColor[4];
341float mSelectedLineColor[4];
342
343float mFillColor[4];
344float mLineColor[4];
345float mLineWidth;
346
348boolmResizeable;
351
354
357
358 std::vector<eventHandler> mEventHandlers;
359 };
360
361 #endif
362
int GetIndex() const
Get the index of the widget in the window (or -1 if none)
void SetFillAlpha(float a)
Set fill alpha.
Definition: glWidget.h:161
std::vector< eventHandler > mEventHandlers
Definition: glWidget.h:358
void SetVisible(bool visible)
Show/hide the widget.
Definition: glWidget.h:231
void * user
Definition: glWidget.h:325
void SetSelected(bool selected)
Select/de-select the widget.
Definition: glWidget.h:221
void setCursor(DragState cursor)
bool OnEvent(uint16_t event, int a, int b, void *user)
bool mResizeable
Definition: glWidget.h:348
void SetFillColor(float r, float g, float b, float a=1.0f)
Set fill color.
Definition: glWidget.h:176
void SetHeight(float height)
Set the widget's height.
Definition: glWidget.h:116
OpenGL graphics widget for rendering moveable/resizable shapes.
Definition: glWidget.h:40
@ DragResizeS
Definition: glWidget.h:315
void GetSize(float *width, float *height) const
Get the widget's size.
Definition: glWidget.h:141
void SetMoveable(bool moveable)
Toggle if the user can move/drag the widget.
Definition: glWidget.h:201
float Width() const
Get the widget's width.
Definition: glWidget.h:101
@ DragResizeE
Definition: glWidget.h:319
DragState mDragState
Definition: glWidget.h:356
glWidget::eventHandler::callback
glWidgetEventHandler callback
Definition: glWidget.h:324
Definition: glWidget.h:322
OpenGL display window and image/video renderer with CUDA interoperability.
Definition: glDisplay.h:47
void GetPosition(float *x, float *y) const
Get position of widget in global window coordinates.
Definition: glWidget.h:121
void SetShape(Shape shape)
Set the shape.
Definition: glWidget.h:156
bool IsVisible() const
Is the widget visible.
Definition: glWidget.h:226
float mY
Definition: glWidget.h:336
void * GetUserData() const
Retrieve user data.
Definition: glWidget.h:236
float mLineWidth
Definition: glWidget.h:345
@ DragResizeNW
Definition: glWidget.h:313
void SetLineWidth(float width)
Set outline width.
Definition: glWidget.h:171
float mX
Definition: glWidget.h:335
glDisplay * mDisplay
Definition: glWidget.h:355
void RemoveEventHandler(glWidgetEventHandler callback, void *user=NULL)
Remove an event message handler from being called by the widget.
void dispatchEvent(uint16_t msg, int a, int b)
@ DragResizeNE
Definition: glWidget.h:314
void SetResizeable(bool resizeable)
Toggle if the user can resize the widget.
Definition: glWidget.h:211
void SetCoords(float x1, float y1, float x2, float y2)
Set the bounding coordinates of the widget.
Definition: glWidget.h:136
bool mSelected
Definition: glWidget.h:349
void SetSize(float width, float height)
Set the widget's size.
Definition: glWidget.h:146
bool IsSelected() const
Is the widget selected?
Definition: glWidget.h:216
@ DragNone
Definition: glWidget.h:310
void * mUserData
Definition: glWidget.h:353
void SetX(float x)
Set the widget's X coordinate.
Definition: glWidget.h:91
glWidget(Shape shape=Rect)
Constructor.
float mSelectedFillColor[4]
Definition: glWidget.h:340
@ DragMove
Definition: glWidget.h:311
float mSelectedLineColor[4]
Definition: glWidget.h:341
@ DragResizeW
Definition: glWidget.h:318
Shape
Shape enum.
Definition: glWidget.h:46
void GetCoords(float *x1, float *y1, float *x2, float *y2) const
Get the bounding coordinates of the widget.
Definition: glWidget.h:131
glWidget::SetSelectedFillColor
void SetSelectedFillColor(float r, float g, float b, float a=1.0f)
Set selected fill color.
Definition: glWidget.h:186
DragState coordToBorder(float x, float y, float max_distance=10.0f)
glWidget::SetSelectedLineColor
void SetSelectedLineColor(float r, float g, float b, float a=1.0f)
Set selected outline color.
Definition: glWidget.h:191
float Y() const
Get the widget's Y coordinate.
Definition: glWidget.h:86
float mLineColor[4]
Definition: glWidget.h:344
bool mMoveable
Definition: glWidget.h:347
void Move(float x, float y)
Move the widget's position by the specified offset.
Definition: glWidget.h:76
void LocalToGlobal(float x, float y, float *x_out, float *y_out) const
Convert from local widget offset to global window coordinates.
glWidget::glWidgetEventHandler
bool(* glWidgetEventHandler)(glWidget *widget, uint16_t event, int a, int b, void *user)
Event message handler callback for recieving UI messages from widgets.
Definition: glWidget.h:281
bool IsResizeable() const
Is the widget resizeable by the user?
Definition: glWidget.h:206
@ DragResizeSE
Definition: glWidget.h:317
void GlobalToLocal(float x, float y, float *x_out, float *y_out) const
Convert from global window coordinates to local widget offset.
@ Line
Definition: glWidget.h:49
Shape mShape
Definition: glWidget.h:352
@ Rect
Definition: glWidget.h:48
@ Ellipse
Definition: glWidget.h:50
bool mVisible
Definition: glWidget.h:350
DragState
Definition: glWidget.h:308
Shape GetShape() const
Get the shape.
Definition: glWidget.h:151
float mHeight
Definition: glWidget.h:338
bool Contains(float x, float y) const
Test if the point is inside the widget.
void SetLineAlpha(float a)
Set outline alpha.
Definition: glWidget.h:166
void SetLineColor(float r, float g, float b, float a=1.0f)
Set outline color.
Definition: glWidget.h:181
float X() const
Get the widget's X coordinate.
Definition: glWidget.h:81
float mWidth
Definition: glWidget.h:337
@ DragResizeN
Definition: glWidget.h:312
void setDisplay(glDisplay *display)
void AddEventHandler(glWidgetEventHandler callback, void *user=NULL)
Register an event message handler the widget will send events to.
void SetWidth(float width)
Set the widget's width.
Definition: glWidget.h:111
virtual ~glWidget()
Destructor.
void initDefaults()
void SetPosition(float x, float y)
Set position of widget in global window coordinates.
Definition: glWidget.h:126
@ DragResizeSW
Definition: glWidget.h:316
void SetY(float y)
Set the widget's Y coordinate.
Definition: glWidget.h:96
glDisplay * GetDisplay() const
Get the root window of the widget.
Definition: glWidget.h:246
float Height() const
Get the widget's height.
Definition: glWidget.h:106
bool IsMoveable() const
Is the widget moveable/draggable by the user?
Definition: glWidget.h:196
float mFillColor[4]
Definition: glWidget.h:343
void SetUserData(void *user)
Set user-defined data.
Definition: glWidget.h:241
void Render()
Render (automatically called by parent)