Skip to content

Commit 7aeeb40

Browse files
committed
All keertan opengl work
1 parent fd648d1 commit 7aeeb40

File tree

531 files changed

+149651
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

531 files changed

+149651
-0
lines changed
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
/*
2+
NanoGUI was developed by Wenzel Jakob <wenzel.jakob@epfl.ch>.
3+
The widget drawing code is based on the NanoVG demo application
4+
by Mikko Mononen.
5+
6+
All rights reserved. Use of this source code is governed by a
7+
BSD-style license that can be found in the LICENSE.txt file.
8+
*/
9+
/**
10+
* \file nanogui/button.h
11+
*
12+
* \brief Defines the [Normal/Toggle/Radio/Popup] \ref nanogui::Button widget.
13+
*/
14+
15+
#pragma once
16+
17+
#include <nanogui/widget.h>
18+
19+
NAMESPACE_BEGIN(nanogui)
20+
/**
21+
* \class Button button.h nanogui/button.h
22+
*
23+
* \brief [Normal/Toggle/Radio/Popup] Button widget.
24+
*/
25+
class NANOGUI_EXPORT Button : public Widget {
26+
public:
27+
/// Flags to specify the button behavior (can be combined with binary OR)
28+
enum Flags {
29+
NormalButton = (1 << 0), ///< A normal Button.
30+
RadioButton = (1 << 1), ///< A radio Button.
31+
ToggleButton = (1 << 2), ///< A toggle Button.
32+
PopupButton = (1 << 3) ///< A popup Button.
33+
};
34+
35+
/// The available icon positions.
36+
enum class IconPosition {
37+
Left, ///< Button icon on the far left.
38+
LeftCentered, ///< Button icon on the left, centered (depends on caption text length).
39+
RightCentered,///< Button icon on the right, centered (depends on caption text length).
40+
Right ///< Button icon on the far right.
41+
};
42+
43+
/**
44+
* \brief Creates a button attached to the specified parent.
45+
*
46+
* \param parent
47+
* The \ref nanogui::Widget this Button will be attached to.
48+
*
49+
* \param caption
50+
* The name of the button (default ``"Untitled"``).
51+
*
52+
* \param icon
53+
* The icon to display with this Button. See \ref nanogui::Button::mIcon.
54+
*/
55+
Button(Widget *parent, const std::string &caption = "Untitled", int icon = 0);
56+
57+
/// Returns the caption of this Button.
58+
const std::string &caption() const { return mCaption; }
59+
60+
/// Sets the caption of this Button.
61+
void setCaption(const std::string &caption) { mCaption = caption; }
62+
63+
/// Returns the background color of this Button.
64+
const Color &backgroundColor() const { return mBackgroundColor; }
65+
66+
/// Sets the background color of this Button.
67+
void setBackgroundColor(const Color &backgroundColor) { mBackgroundColor = backgroundColor; }
68+
69+
/// Returns the text color of the caption of this Button.
70+
const Color &textColor() const { return mTextColor; }
71+
72+
/// Sets the text color of the caption of this Button.
73+
void setTextColor(const Color &textColor) { mTextColor = textColor; }
74+
75+
/// Returns the icon of this Button. See \ref nanogui::Button::mIcon.
76+
int icon() const { return mIcon; }
77+
78+
/// Sets the icon of this Button. See \ref nanogui::Button::mIcon.
79+
void setIcon(int icon) { mIcon = icon; }
80+
81+
/// The current flags of this Button (see \ref nanogui::Button::Flags for options).
82+
int flags() const { return mFlags; }
83+
84+
/// Sets the flags of this Button (see \ref nanogui::Button::Flags for options).
85+
void setFlags(int buttonFlags) { mFlags = buttonFlags; }
86+
87+
/// The position of the icon for this Button.
88+
IconPosition iconPosition() const { return mIconPosition; }
89+
90+
/// Sets the position of the icon for this Button.
91+
void setIconPosition(IconPosition iconPosition) { mIconPosition = iconPosition; }
92+
93+
/// Whether or not this Button is currently pushed.
94+
bool pushed() const { return mPushed; }
95+
96+
/// Sets whether or not this Button is currently pushed.
97+
void setPushed(bool pushed) { mPushed = pushed; }
98+
99+
/// The current callback to execute (for any type of button).
100+
std::function<void()> callback() const { return mCallback; }
101+
102+
/// Set the push callback (for any type of button).
103+
void setCallback(const std::function<void()> &callback) { mCallback = callback; }
104+
105+
/// The current callback to execute (for toggle buttons).
106+
std::function<void(bool)> changeCallback() const { return mChangeCallback; }
107+
108+
/// Set the change callback (for toggle buttons).
109+
void setChangeCallback(const std::function<void(bool)> &callback) { mChangeCallback = callback; }
110+
111+
/// Set the button group (for radio buttons).
112+
void setButtonGroup(const std::vector<Button *> &buttonGroup) { mButtonGroup = buttonGroup; }
113+
114+
/// The current button group (for radio buttons).
115+
const std::vector<Button *> &buttonGroup() const { return mButtonGroup; }
116+
117+
/// The preferred size of this Button.
118+
virtual Vector2i preferredSize(NVGcontext *ctx) const override;
119+
120+
/// The callback that is called when any type of mouse button event is issued to this Button.
121+
virtual bool mouseButtonEvent(const Vector2i &p, int button, bool down, int modifiers) override;
122+
123+
/// Responsible for drawing the Button.
124+
virtual void draw(NVGcontext *ctx) override;
125+
126+
/// Saves the state of this Button provided the given Serializer.
127+
virtual void save(Serializer &s) const override;
128+
129+
/// Sets the state of this Button provided the given Serializer.
130+
virtual bool load(Serializer &s) override;
131+
132+
protected:
133+
/// The caption of this Button.
134+
std::string mCaption;
135+
136+
/**
137+
* \brief The icon of this Button (``0`` means no icon).
138+
*
139+
* \rst
140+
* The icon to display with this Button. If not ``0``, may either be a
141+
* picture icon, or one of the icons enumerated in
142+
* :ref:`file_nanogui_entypo.h`. The kind of icon (image or Entypo)
143+
* is determined by the functions :func:`nanogui::nvgIsImageIcon` and its
144+
* reciprocal counterpart :func:`nanogui::nvgIsFontIcon`.
145+
* \endrst
146+
*/
147+
int mIcon;
148+
149+
/// The position to draw the icon at.
150+
IconPosition mIconPosition;
151+
152+
/// Whether or not this Button is currently pushed.
153+
bool mPushed;
154+
155+
/// The current flags of this button (see \ref nanogui::Button::Flags for options).
156+
int mFlags;
157+
158+
/// The background color of this Button.
159+
Color mBackgroundColor;
160+
161+
/// The color of the caption text of this Button.
162+
Color mTextColor;
163+
164+
/// The callback issued for all types of buttons.
165+
std::function<void()> mCallback;
166+
167+
/// The callback issued for toggle buttons.
168+
std::function<void(bool)> mChangeCallback;
169+
170+
/// The button group for radio buttons.
171+
std::vector<Button *> mButtonGroup;
172+
173+
public:
174+
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
175+
};
176+
177+
NAMESPACE_END(nanogui)
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
NanoGUI was developed by Wenzel Jakob <wenzel.jakob@epfl.ch>.
3+
The widget drawing code is based on the NanoVG demo application
4+
by Mikko Mononen.
5+
6+
All rights reserved. Use of this source code is governed by a
7+
BSD-style license that can be found in the LICENSE.txt file.
8+
*/
9+
/**
10+
* \file nanogui/checkbox.h
11+
*
12+
* \brief Two-state check box Widget.
13+
*/
14+
15+
#pragma once
16+
17+
#include <nanogui/widget.h>
18+
19+
NAMESPACE_BEGIN(nanogui)
20+
21+
/**
22+
* \class CheckBox checkbox.h nanogui/checkbox.h
23+
*
24+
* \brief Two-state check box widget.
25+
*
26+
* \remark
27+
* This class overrides \ref nanogui::Widget::mIconExtraScale to be ``1.2f``,
28+
* which affects all subclasses of this Widget. Subclasses must explicitly
29+
* set a different value if needed (e.g., in their constructor).
30+
*/
31+
class NANOGUI_EXPORT CheckBox : public Widget {
32+
public:
33+
/**
34+
* Adds a CheckBox to the specified ``parent``.
35+
*
36+
* \param parent
37+
* The Widget to add this CheckBox to.
38+
*
39+
* \param caption
40+
* The caption text of the CheckBox (default ``"Untitled"``).
41+
*
42+
* \param callback
43+
* If provided, the callback to execute when the CheckBox is checked or
44+
* unchecked. Default parameter function does nothing. See
45+
* \ref nanogui::CheckBox::mPushed for the difference between "pushed"
46+
* and "checked".
47+
*/
48+
CheckBox(Widget *parent, const std::string &caption = "Untitled",
49+
const std::function<void(bool)> &callback = std::function<void(bool)>());
50+
51+
/// The caption of this CheckBox.
52+
const std::string &caption() const { return mCaption; }
53+
54+
/// Sets the caption of this CheckBox.
55+
void setCaption(const std::string &caption) { mCaption = caption; }
56+
57+
/// Whether or not this CheckBox is currently checked.
58+
const bool &checked() const { return mChecked; }
59+
60+
/// Sets whether or not this CheckBox is currently checked.
61+
void setChecked(const bool &checked) { mChecked = checked; }
62+
63+
/// Whether or not this CheckBox is currently pushed. See \ref nanogui::CheckBox::mPushed.
64+
const bool &pushed() const { return mPushed; }
65+
66+
/// Sets whether or not this CheckBox is currently pushed. See \ref nanogui::CheckBox::mPushed.
67+
void setPushed(const bool &pushed) { mPushed = pushed; }
68+
69+
/// Returns the current callback of this CheckBox.
70+
std::function<void(bool)> callback() const { return mCallback; }
71+
72+
/// Sets the callback to be executed when this CheckBox is checked / unchecked.
73+
void setCallback(const std::function<void(bool)> &callback) { mCallback = callback; }
74+
75+
/**
76+
* The mouse button callback will return ``true`` when all three conditions are met:
77+
*
78+
* 1. This CheckBox is "enabled" (see \ref nanogui::Widget::mEnabled).
79+
* 2. ``p`` is inside this CheckBox.
80+
* 3. ``button`` is ``GLFW_MOUSE_BUTTON_1`` (left mouse click).
81+
*
82+
* Since a mouse button event is issued for both when the mouse is pressed, as well
83+
* as released, this function sets \ref nanogui::CheckBox::mPushed to ``true`` when
84+
* parameter ``down == true``. When the second event (``down == false``) is fired,
85+
* \ref nanogui::CheckBox::mChecked is inverted and \ref nanogui::CheckBox::mCallback
86+
* is called.
87+
*
88+
* That is, the callback provided is only called when the mouse button is released,
89+
* **and** the click location remains within the CheckBox boundaries. If the user
90+
* clicks on the CheckBox and releases away from the bounds of the CheckBox,
91+
* \ref nanogui::CheckBox::mPushed is simply set back to ``false``.
92+
*/
93+
virtual bool mouseButtonEvent(const Vector2i &p, int button, bool down, int modifiers) override;
94+
95+
/// The preferred size of this CheckBox.
96+
virtual Vector2i preferredSize(NVGcontext *ctx) const override;
97+
98+
/// Draws this CheckBox.
99+
virtual void draw(NVGcontext *ctx) override;
100+
101+
/// Saves this CheckBox to the specified Serializer.
102+
virtual void save(Serializer &s) const override;
103+
104+
/// Loads the state of the specified Serializer to this CheckBox.
105+
virtual bool load(Serializer &s) override;
106+
107+
protected:
108+
/// The caption text of this CheckBox.
109+
std::string mCaption;
110+
111+
/**
112+
* Internal tracking variable to distinguish between mouse click and release.
113+
* \ref nanogui::CheckBox::mCallback is only called upon release. See
114+
* \ref nanogui::CheckBox::mouseButtonEvent for specific conditions.
115+
*/
116+
bool mPushed;
117+
118+
/// Whether or not this CheckBox is currently checked or unchecked.
119+
bool mChecked;
120+
121+
/// The function to execute when \ref nanogui::CheckBox::mChecked is changed.
122+
std::function<void(bool)> mCallback;
123+
124+
public:
125+
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
126+
};
127+
128+
NAMESPACE_END(nanogui)

0 commit comments

Comments
 (0)