neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
i_action.hpp
Go to the documentation of this file.
1// i_action.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2015, 2020 Leigh Johnston. All Rights Reserved.
5
6 This program is free software: you can redistribute it and / or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
23#include <optional>
24#include <neogfx/core/event.hpp>
27#include <neogfx/gfx/image.hpp>
28
29namespace neogfx
30{
32 {
33 public:
35 public:
36 declare_event(triggered)
37 declare_event(hovered)
38 declare_event(enabled)
39 declare_event(disabled)
40 declare_event(checked)
41 declare_event(unchecked)
42 declare_event(changed)
43 public:
44 typedef optional<string> optional_text;
45 public:
46 virtual bool is_enabled() const = 0;
47 virtual bool is_disabled() const = 0;
48 virtual bool is_checkable() const = 0;
49 virtual bool is_checked() const = 0;
50 virtual bool is_unchecked() const = 0;
51 virtual uuid const& group() const = 0;
52 virtual bool is_separator() const = 0;
53 virtual i_string const& text() const = 0;
54 virtual i_string const& menu_text() const = 0;
55 virtual i_string const& button_text() const = 0;
56 virtual i_string const& tool_tip_text() const = 0;
57 virtual i_string const& help_text() const = 0;
58 virtual i_texture const& image() const = 0;
59 virtual i_texture const& checked_image() const = 0;
60 virtual optional_key_sequence const& shortcut() const = 0;
61 virtual i_action& set_enabled(bool aEnabled) = 0;
62 virtual i_action& set_checkable(bool aCheckable = true) = 0;
63 virtual i_action& set_checked(bool aChecked) = 0;
64 virtual i_action& set_group(uuid const& aGroup) = 0;
65 virtual i_action& set_separator(bool aIsSeparator) = 0;
66 virtual i_action& set_text(i_optional<i_string> const& aText) = 0;
67 virtual i_action& set_menu_text(i_optional<i_string> const& aMenuText) = 0;
68 virtual i_action& set_button_text(i_optional<i_string> const& aButtonText) = 0;
69 virtual i_action& set_tool_tip_text(i_optional<i_string> const& aToolTipText) = 0;
70 virtual i_action& set_help_text(i_optional<i_string> const& aHelpText) = 0;
71 virtual i_action& set_image(i_texture const& aTexture) = 0;
72 virtual i_action& set_checked_image(i_texture const& aTexture) = 0;
73 virtual i_action& set_shortcut(optional_key_sequence const& aShortcut) = 0;
74 virtual i_action& set_shortcut(i_string const& aShortcut) = 0;
75 public:
76 i_action& enable(bool aEnabled = true)
77 {
78 return set_enabled(aEnabled);
79 }
80 i_action& disable(bool aDisabled = true)
81 {
82 return set_enabled(!aDisabled);
83 }
84 i_action& check(bool aChecked = true)
85 {
86 return set_checked(aChecked);
87 }
88 i_action& uncheck(bool aUnchecked = true)
89 {
90 return set_checked(!aUnchecked);
91 }
93 {
94 if (is_checked())
95 return uncheck();
96 else
97 return check();
98 }
99 i_action& set_text(optional_text const& aText = optional_text{})
100 {
101 return set_text(to_abstract(aText));
102 }
103 i_action& set_menu_text(optional_text const& aMenuText = optional_text{})
104 {
105 return set_menu_text(to_abstract(aMenuText));
106 }
107 i_action& set_button_text(optional_text const& aButtonText = optional_text{})
108 {
109 return set_button_text(to_abstract(aButtonText));
110 }
111 i_action& set_tool_tip_text(optional_text const& aToolTipText = optional_text{})
112 {
113 return set_tool_tip_text(to_abstract(aToolTipText));
114 }
115 i_action& set_help_text(optional_text const& aHelpText = optional_text{})
116 {
117 return set_help_text(to_abstract(aHelpText));
118 }
119 i_action& set_image(std::string const& aUri, dimension aDpiScaleFactor = 1.0, texture_sampling aSampling = texture_sampling::Scaled)
120 {
121 return set_image(texture{ neogfx::image{aUri, aDpiScaleFactor, aSampling} });
122 }
123 i_action& set_image(i_image const& aImage)
124 {
125 return set_image(texture{ aImage });
126 }
127 i_action& set_checked_image(std::string const& aUri, dimension aDpiScaleFactor = 1.0, texture_sampling aSampling = texture_sampling::Scaled)
128 {
129 return set_checked_image(texture{ neogfx::image{ aUri, aDpiScaleFactor, aSampling } });
130 }
132 {
133 return set_checked_image(texture{ aImage });
134 }
135 i_action& set_shortcut(std::string const& aShortcut)
136 {
137 return set_shortcut(string(aShortcut));
138 }
139 };
140
142 {
143 public:
144 virtual i_action& add_action(i_action& aAction) = 0;
145 virtual i_action& add_action(i_ref_ptr<i_action> const& aAction) = 0;
146 };
147}
virtual i_action & add_action(i_action &aAction)=0
virtual i_action & add_action(i_ref_ptr< i_action > const &aAction)=0
virtual i_action & set_shortcut(optional_key_sequence const &aShortcut)=0
virtual i_action & set_group(uuid const &aGroup)=0
virtual i_action & set_checked(bool aChecked)=0
virtual i_action & set_help_text(i_optional< i_string > const &aHelpText)=0
virtual optional_key_sequence const & shortcut() const =0
virtual bool is_checkable() const =0
virtual i_action & set_checked_image(i_texture const &aTexture)=0
virtual i_action & set_button_text(i_optional< i_string > const &aButtonText)=0
virtual i_texture const & checked_image() const =0
virtual i_action & set_image(i_texture const &aTexture)=0
virtual i_action & set_text(i_optional< i_string > const &aText)=0
i_action & set_image(i_image const &aImage)
Definition i_action.hpp:123
virtual i_action & set_enabled(bool aEnabled)=0
i_action & set_image(std::string const &aUri, dimension aDpiScaleFactor=1.0, texture_sampling aSampling=texture_sampling::Scaled)
Definition i_action.hpp:119
i_action & set_shortcut(std::string const &aShortcut)
Definition i_action.hpp:135
virtual bool is_checked() const =0
i_action & set_button_text(optional_text const &aButtonText=optional_text{})
Definition i_action.hpp:107
i_action & uncheck(bool aUnchecked=true)
Definition i_action.hpp:88
virtual uuid const & group() const =0
virtual bool is_enabled() const =0
virtual i_string const & tool_tip_text() const =0
virtual i_action & set_menu_text(i_optional< i_string > const &aMenuText)=0
virtual i_string const & text() const =0
i_action & set_tool_tip_text(optional_text const &aToolTipText=optional_text{})
Definition i_action.hpp:111
virtual bool is_unchecked() const =0
i_action & set_checked_image(i_image const &aImage)
Definition i_action.hpp:131
virtual i_string const & button_text() const =0
virtual i_action & set_shortcut(i_string const &aShortcut)=0
virtual i_string const & menu_text() const =0
i_action & set_checked_image(std::string const &aUri, dimension aDpiScaleFactor=1.0, texture_sampling aSampling=texture_sampling::Scaled)
Definition i_action.hpp:127
i_action abstract_type
Definition i_action.hpp:34
virtual bool is_separator() const =0
virtual i_action & set_checkable(bool aCheckable=true)=0
i_action & set_menu_text(optional_text const &aMenuText=optional_text{})
Definition i_action.hpp:103
virtual bool is_disabled() const =0
i_action & toggle()
Definition i_action.hpp:92
i_action & disable(bool aDisabled=true)
Definition i_action.hpp:80
virtual i_texture const & image() const =0
i_action & set_help_text(optional_text const &aHelpText=optional_text{})
Definition i_action.hpp:115
virtual i_action & set_separator(bool aIsSeparator)=0
i_action & check(bool aChecked=true)
Definition i_action.hpp:84
virtual i_string const & help_text() const =0
i_action & enable(bool aEnabled=true)
Definition i_action.hpp:76
i_action & set_text(optional_text const &aText=optional_text{})
Definition i_action.hpp:99
virtual i_action & set_tool_tip_text(i_optional< i_string > const &aToolTipText)=0
default_geometry_value_type dimension
std::optional< key_sequence > optional_key_sequence
texture_sampling
Definition i_texture.hpp:42
#define declare_event(declName,...)
Definition i_event.hpp:305