Skip to content

Commit bf0282e

Browse files
committed
Added NanoGUI (OSX)
1 parent 2f626b0 commit bf0282e

38 files changed

+4453
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Nuparu currently consists of:
2424
* [Embree](https://embree.github.io) 2.7 (OSX/Win)
2525
* [Leonhard Gruenschloss's Sobol Generator](http://gruenschloss.org) (OSX/Linux/Win)
2626
* [tinyformat](https://github.com/c42f/tinyformat) 2.0.1 (OSX/Linux/Win)
27+
* [NanoGUI](https://github.com/wjakob/nanogui) (OSX)
2728

2829
Notes:
2930

include/nanogui/LICENSE.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Copyright (c) 2015 Wenzel Jakob <[email protected]>, All rights reserved.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are met:
5+
6+
1. Redistributions of source code must retain the above copyright notice, this
7+
list of conditions and the following disclaimer.
8+
9+
2. Redistributions in binary form must reproduce the above copyright notice,
10+
this list of conditions and the following disclaimer in the documentation
11+
and/or other materials provided with the distribution.
12+
13+
3. Neither the name of the copyright holder nor the names of its contributors
14+
may be used to endorse or promote products derived from this software
15+
without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+
28+
You are under no obligation whatsoever to provide any bug fixes, patches, or
29+
upgrades to the features, functionality or performance of the source code
30+
("Enhancements") to anyone; however, if you choose to make your Enhancements
31+
available either publicly, or directly to the author of this software, without
32+
imposing a separate written license agreement for such Enhancements, then you
33+
hereby grant the following license: a non-exclusive, royalty-free perpetual
34+
license to install, use, modify, prepare derivative works, incorporate into
35+
other computer software, distribute, and sublicense such enhancements or
36+
derivative works thereof, in binary and source code form.

include/nanogui/button.h

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
nanogui/button.h -- [Normal/Toggle/Radio/Popup] Button widget
3+
4+
NanoGUI was developed by Wenzel Jakob <[email protected]>.
5+
The widget drawing code is based on the NanoVG demo application
6+
by Mikko Mononen.
7+
8+
All rights reserved. Use of this source code is governed by a
9+
BSD-style license that can be found in the LICENSE.txt file.
10+
*/
11+
12+
#pragma once
13+
14+
#include <nanogui/widget.h>
15+
16+
NAMESPACE_BEGIN(nanogui)
17+
18+
class NANOGUI_EXPORT Button : public Widget {
19+
public:
20+
/// Flags to specify the button behavior (can be combined with binary OR)
21+
enum Flags {
22+
NormalButton = 1,
23+
RadioButton = 2,
24+
ToggleButton = 4,
25+
PopupButton = 8
26+
};
27+
28+
enum class IconPosition {
29+
Left,
30+
LeftCentered,
31+
RightCentered,
32+
Right
33+
};
34+
35+
Button(Widget *parent, const std::string &caption = "Untitled", int icon = 0);
36+
37+
const std::string &caption() const { return mCaption; }
38+
void setCaption(const std::string &caption) { mCaption = caption; }
39+
40+
const Color &backgroundColor() const { return mBackgroundColor; }
41+
void setBackgroundColor(const Color &backgroundColor) { mBackgroundColor = backgroundColor; }
42+
43+
const Color &textColor() const { return mTextColor; }
44+
void setTextColor(const Color &textColor) { mTextColor = textColor; }
45+
46+
int icon() const { return mIcon; }
47+
void setIcon(int icon) { mIcon = icon; }
48+
49+
int flags() const { return mFlags; }
50+
void setFlags(int buttonFlags) { mFlags = buttonFlags; }
51+
52+
IconPosition iconPosition() const { return mIconPosition; }
53+
void setIconPosition(IconPosition iconPosition) { mIconPosition = iconPosition; }
54+
55+
bool pushed() const { return mPushed; }
56+
void setPushed(bool pushed) { mPushed = pushed; }
57+
58+
/// Set the push callback (for any type of button)
59+
std::function<void()> callback() const { return mCallback; }
60+
void setCallback(const std::function<void()> &callback) { mCallback = callback; }
61+
62+
/// Set the change callback (for toggle buttons)
63+
std::function<void(bool)> changeCallback() const { return mChangeCallback; }
64+
void setChangeCallback(const std::function<void(bool)> &callback) { mChangeCallback = callback; }
65+
66+
/// Set the button group (for radio buttons)
67+
void setButtonGroup(const std::vector<Button *> &buttonGroup) { mButtonGroup = buttonGroup; }
68+
const std::vector<Button *> &buttonGroup() const { return mButtonGroup; }
69+
70+
virtual Vector2i preferredSize(NVGcontext *ctx) const override;
71+
virtual bool mouseButtonEvent(const Vector2i &p, int button, bool down, int modifiers) override;
72+
virtual void draw(NVGcontext *ctx) override;
73+
74+
virtual void save(Serializer &s) const override;
75+
virtual bool load(Serializer &s) override;
76+
protected:
77+
std::string mCaption;
78+
int mIcon;
79+
IconPosition mIconPosition;
80+
bool mPushed;
81+
int mFlags;
82+
Color mBackgroundColor;
83+
Color mTextColor;
84+
std::function<void()> mCallback;
85+
std::function<void(bool)> mChangeCallback;
86+
std::vector<Button *> mButtonGroup;
87+
};
88+
89+
NAMESPACE_END(nanogui)

include/nanogui/checkbox.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
nanogui/checkbox.h -- Two-state check box widget
3+
4+
NanoGUI was developed by Wenzel Jakob <[email protected]>.
5+
The widget drawing code is based on the NanoVG demo application
6+
by Mikko Mononen.
7+
8+
All rights reserved. Use of this source code is governed by a
9+
BSD-style license that can be found in the LICENSE.txt file.
10+
*/
11+
12+
#pragma once
13+
14+
#include <nanogui/widget.h>
15+
16+
NAMESPACE_BEGIN(nanogui)
17+
18+
class NANOGUI_EXPORT CheckBox : public Widget {
19+
public:
20+
CheckBox(Widget *parent, const std::string &caption = "Untitled",
21+
const std::function<void(bool)> &callback = std::function<void(bool)>());
22+
23+
const std::string &caption() const { return mCaption; }
24+
void setCaption(const std::string &caption) { mCaption = caption; }
25+
26+
const bool &checked() const { return mChecked; }
27+
void setChecked(const bool &checked) { mChecked = checked; }
28+
29+
const bool &pushed() const { return mPushed; }
30+
void setPushed(const bool &pushed) { mPushed = pushed; }
31+
32+
std::function<void(bool)> callback() const { return mCallback; }
33+
void setCallback(const std::function<void(bool)> &callback) { mCallback = callback; }
34+
35+
virtual bool mouseButtonEvent(const Vector2i &p, int button, bool down, int modifiers) override;
36+
virtual Vector2i preferredSize(NVGcontext *ctx) const override;
37+
virtual void draw(NVGcontext *ctx) override;
38+
39+
virtual void save(Serializer &s) const override;
40+
virtual bool load(Serializer &s) override;
41+
protected:
42+
std::string mCaption;
43+
bool mPushed, mChecked;
44+
std::function<void(bool)> mCallback;
45+
};
46+
47+
NAMESPACE_END(nanogui)

include/nanogui/colorpicker.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
nanogui/colorpicker.h -- push button with a popup to tweak a color value
3+
4+
This widget was contributed by Christian Schueller.
5+
6+
NanoGUI was developed by Wenzel Jakob <[email protected]>.
7+
The widget drawing code is based on the NanoVG demo application
8+
by Mikko Mononen.
9+
10+
All rights reserved. Use of this source code is governed by a
11+
BSD-style license that can be found in the LICENSE.txt file.
12+
*/
13+
14+
#pragma once
15+
16+
#include <nanogui/popupbutton.h>
17+
18+
NAMESPACE_BEGIN(nanogui)
19+
20+
class NANOGUI_EXPORT ColorPicker : public PopupButton {
21+
public:
22+
ColorPicker(Widget *parent, const Color& color = { 1.f, 0.f, 0.f, 1.f });
23+
24+
/// Set the change callback
25+
std::function<void(const Color &)> callback() const { return mCallback; }
26+
void setCallback(const std::function<void(const Color &)> &callback) { mCallback = callback; }
27+
28+
/// Get the current color
29+
Color color() const;
30+
/// Set the current color
31+
void setColor(const Color& color);
32+
protected:
33+
std::function<void(const Color &)> mCallback;
34+
ColorWheel *mColorWheel;
35+
Button *mPickButton;
36+
};
37+
38+
NAMESPACE_END(nanogui)

include/nanogui/colorwheel.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
nanogui/colorwheel.h -- fancy analog widget to select a color value
3+
4+
This widget was contributed by Dmitriy Morozov.
5+
6+
NanoGUI was developed by Wenzel Jakob <[email protected]>.
7+
The widget drawing code is based on the NanoVG demo application
8+
by Mikko Mononen.
9+
10+
All rights reserved. Use of this source code is governed by a
11+
BSD-style license that can be found in the LICENSE.txt file.
12+
*/
13+
14+
#pragma once
15+
16+
#include <nanogui/widget.h>
17+
18+
NAMESPACE_BEGIN(nanogui)
19+
20+
class NANOGUI_EXPORT ColorWheel : public Widget {
21+
public:
22+
ColorWheel(Widget *parent, const Color& color = { 1.f, 0.f, 0.f, 1.f });
23+
24+
/// Set the change callback
25+
std::function<void(const Color &)> callback() const { return mCallback; }
26+
void setCallback(const std::function<void(const Color &)> &callback) { mCallback = callback; }
27+
28+
/// Get the current color
29+
Color color() const;
30+
/// Set the current color
31+
void setColor(const Color& color);
32+
33+
virtual Vector2i preferredSize(NVGcontext *ctx) const override;
34+
virtual void draw(NVGcontext *ctx) override;
35+
virtual bool mouseButtonEvent(const Vector2i &p, int button, bool down, int modifiers) override;
36+
virtual bool mouseDragEvent(const Vector2i &p, const Vector2i &rel, int button, int modifiers) override;
37+
38+
virtual void save(Serializer &s) const override;
39+
virtual bool load(Serializer &s) override;
40+
private:
41+
enum Region {
42+
None = 0,
43+
InnerTriangle = 1,
44+
OuterCircle = 2,
45+
Both = 3
46+
};
47+
48+
Color hue2rgb(float h) const;
49+
Region adjustPosition(const Vector2i &p, Region consideredRegions = Both);
50+
51+
protected:
52+
float mHue;
53+
float mWhite;
54+
float mBlack;
55+
Region mDragRegion;
56+
std::function<void(const Color &)> mCallback;
57+
};
58+
59+
NAMESPACE_END(nanogui)

include/nanogui/combobox.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
nanogui/combobox.h -- simple combo box widget based on a popup button
3+
4+
NanoGUI was developed by Wenzel Jakob <[email protected]>.
5+
The widget drawing code is based on the NanoVG demo application
6+
by Mikko Mononen.
7+
8+
All rights reserved. Use of this source code is governed by a
9+
BSD-style license that can be found in the LICENSE.txt file.
10+
*/
11+
12+
#pragma once
13+
14+
#include <nanogui/popupbutton.h>
15+
16+
NAMESPACE_BEGIN(nanogui)
17+
18+
class NANOGUI_EXPORT ComboBox : public PopupButton {
19+
public:
20+
/// Create an empty combo box
21+
ComboBox(Widget *parent);
22+
23+
/// Create a new combo box with the given items
24+
ComboBox(Widget *parent, const std::vector<std::string> &items);
25+
26+
/**
27+
* \brief Create a new combo box with the given items, providing both short and
28+
* long descriptive labels for each item
29+
*/
30+
ComboBox(Widget *parent, const std::vector<std::string> &items,
31+
const std::vector<std::string> &itemsShort);
32+
33+
std::function<void(int)> callback() const { return mCallback; }
34+
void setCallback(const std::function<void(int)> &callback) { mCallback = callback; }
35+
36+
int selectedIndex() const { return mSelectedIndex; }
37+
void setSelectedIndex(int idx);
38+
39+
void setItems(const std::vector<std::string> &items, const std::vector<std::string> &itemsShort);
40+
void setItems(const std::vector<std::string> &items) { setItems(items, items); }
41+
const std::vector<std::string> &items() const { return mItems; }
42+
const std::vector<std::string> &itemsShort() const { return mItemsShort; }
43+
44+
virtual void save(Serializer &s) const override;
45+
virtual bool load(Serializer &s) override;
46+
protected:
47+
std::vector<std::string> mItems, mItemsShort;
48+
std::function<void(int)> mCallback;
49+
int mSelectedIndex;
50+
};
51+
52+
NAMESPACE_END(nanogui)

0 commit comments

Comments
 (0)