SMTK  @SMTK_VERSION@
Simulation Modeling Tool Kit
Badge.h
1 //=========================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //=========================================================================
10 
11 #ifndef smtk_view_Badge_h
12 #define smtk_view_Badge_h
13 
14 #include "smtk/view/Configuration.h"
15 
16 #include "smtk/PublicPointerDefs.h"
17 #include "smtk/SharedFromThis.h"
18 
19 #include <array>
20 
21 namespace smtk
22 {
23 namespace view
24 {
25 
34 class SMTKCORE_EXPORT BadgeAction
35 {
36 public:
40  using PhraseVisitor = std::function<bool(DescriptivePhrase*)>;
41 
46  virtual void visitRelatedPhrases(PhraseVisitor visitor) const { (void)visitor; }
47 };
48 
56 class SMTKCORE_EXPORT BadgeActionToggle : public BadgeAction
57 {
58 };
59 
78 class SMTKCORE_EXPORT Badge : smtkEnableSharedPtr(Badge)
79 {
80 public:
82  Badge() = default;
83  Badge(const Badge&) = delete;
84  Badge& operator=(const Badge&) = delete;
85  virtual ~Badge() = default;
86 
88  virtual bool appliesToPhrase(const DescriptivePhrase*) const { return false; }
89 
100  virtual std::string tooltip(const DescriptivePhrase*) const { return std::string(); }
101 
110  virtual std::string icon(const DescriptivePhrase* phrase, const std::array<float, 4>& background)
111  const = 0;
112 
117  virtual bool action(const DescriptivePhrase*, const BadgeAction&) { return false; }
118 
122  bool isDefault() const { return m_isDefault; }
123 
125  void setIsDefault(bool isDefault) { m_isDefault = isDefault; }
126 
127 protected:
129  bool m_isDefault{ false };
130 };
131 } // namespace view
132 } // namespace smtk
133 #endif
smtk
The main namespace for the Simulation Modeling Tool Kit (SMTK).
Definition: doc.h:33
smtk::view::Badge::tooltip
virtual std::string tooltip(const DescriptivePhrase *) const
Return a tool-tip string for the badge that is relevant to this phrase.
Definition: Badge.h:100
smtk::view::Badge::appliesToPhrase
virtual bool appliesToPhrase(const DescriptivePhrase *) const
Returns true if the badge should appear next to the given phrase:
Definition: Badge.h:88
PublicPointerDefs.h
smtk::view::Badge
A base class for descriptive-phrase badges.
Definition: Badge.h:78
smtk::view::BadgeAction::visitRelatedPhrases
virtual void visitRelatedPhrases(PhraseVisitor visitor) const
Some actions may apply to multiple phrases (e.g., those selected when a key is pressed).
Definition: Badge.h:46
smtk::view::BadgeAction::PhraseVisitor
std::function< bool(DescriptivePhrase *)> PhraseVisitor
When visiting multiple phrases to which a badge action should apply, this function is supplied by the...
Definition: Badge.h:40
smtkEnableSharedPtr
#define smtkEnableSharedPtr(...)
An abbreviation for enabling shared pointers.
Definition: SharedFromThis.h:154
smtk::view::Badge::action
virtual bool action(const DescriptivePhrase *, const BadgeAction &)
Take an action when the badge is clicked.
Definition: Badge.h:117
smtk::view::Badge::isDefault
bool isDefault() const
Return whether this badge be invoked by non-specific user gestures.
Definition: Badge.h:122
smtk::view::DescriptivePhrase
A base class for phrases describing an SMTK model.
Definition: DescriptivePhrase.h:76
smtk::view::Badge::setIsDefault
void setIsDefault(bool isDefault)
Set this badge as a default.
Definition: Badge.h:125
smtk::view::BadgeAction
A base class for actions taken on badges.
Definition: Badge.h:34
smtk::view::BadgeActionToggle
The basic badge action: the user clicked on a badge.
Definition: Badge.h:56
SharedFromThis.h
Macros for dealing with shared-pointer classes.
smtkTypeMacroBase
#define smtkTypeMacroBase(...)
Add typedefs to a class for identifcation.
Definition: SharedFromThis.h:55