neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
gradient_widget.hpp
Go to the documentation of this file.
1// gradient_widget.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#pragma once
20
21#include <neogfx/neogfx.hpp>
24#include <neogfx/gfx/color.hpp>
28
29namespace neogfx
30{
31 class gradient_dialog;
32
33 class gradient_widget : public widget<>
34 {
36 public:
37 define_event(GradientChanged, gradient_changed)
38 define_event(ColorStopSelected, color_stop_selected)
39 define_event(ColorStopDeselected, color_stop_deselected)
40 define_event(AlphaStopSelected, alpha_stop_selected)
41 define_event(AlphaStopDeselected, alpha_stop_deselected)
42 private:
43 typedef std::variant<std::monostate, neogfx::gradient::color_stop_list::const_iterator, neogfx::gradient::alpha_stop_list::const_iterator> stop_const_iterator;
44 typedef std::variant<std::monostate, neogfx::gradient::color_stop_list::iterator, neogfx::gradient::alpha_stop_list::iterator> stop_iterator;
45 public:
46 gradient_widget(i_gradient const& aGradient = neogfx::gradient{});
47 gradient_widget(i_widget& aParent, i_gradient const& aGradient = neogfx::gradient{});
48 gradient_widget(i_layout& aLayout, i_gradient const& aGradient = neogfx::gradient{});
49 gradient_widget(gradient_dialog& aParent, i_layout& aLayout, i_gradient const& aGradient = neogfx::gradient{});
50 public:
51 i_gradient const& gradient() const;
52 void set_gradient(i_gradient const& aGradient);
53 void set_gradient(i_ref_ptr<i_gradient> const& aGradient);
54 const std::optional<color_dialog::custom_color_list>& custom_colors() const;
55 std::optional<color_dialog::custom_color_list>& custom_colors();
56 public:
57 gradient::color_stop_list::const_iterator selected_color_stop() const;
58 gradient::alpha_stop_list::const_iterator selected_alpha_stop() const;
59 void select_color_stop(gradient::color_stop_list::const_iterator aStop);
60 void select_alpha_stop(gradient::alpha_stop_list::const_iterator aStop);
61 public:
62 neogfx::size_policy size_policy() const override;
63 size minimum_size(optional_size const& aAvailableSpace = optional_size{}) const override;
64 public:
65 void paint(i_graphics_context& aGc) const override;
66 public:
67 void mouse_button_pressed(mouse_button aButton, point const& aPosition, key_modifiers_e aKeyModifiers) override;
68 void mouse_button_double_clicked(mouse_button aButton, point const& aPosition, key_modifiers_e aKeyModifiers) override;
69 void mouse_button_released(mouse_button aButton, point const& aPosition) override;
70 void mouse_moved(point const& aPosition, key_modifiers_e aKeyModifiers) override;
72 private:
73 rect contents_rect() const;
74 bool is_stop_at(point const& aPosition) const;
75 stop_const_iterator stop_at(point const& aPosition) const;
76 stop_iterator stop_at(point const& aPosition);
77 void set_current_color_stop(std::optional<gradient::color_stop_list::iterator> const& aStop);
78 void set_current_alpha_stop(std::optional<gradient::alpha_stop_list::iterator> const& aStop);
79 rect color_stop_rect(neogfx::gradient::color_stop const& aColorStop) const;
80 rect alpha_stop_rect(neogfx::gradient::alpha_stop const& aAlphaStop) const;
81 void draw_color_stop(i_graphics_context& aGc, neogfx::gradient::color_stop const& aColorStop) const;
82 void draw_alpha_stop(i_graphics_context& aGc, neogfx::gradient::alpha_stop const& aAlphaStop) const;
83 private:
84 dimension stop_width() const;
85 dimension stop_height() const;
86 dimension control_height() const;
87 dimension alpha_pattern_size() const;
88 dimension small_alpha_pattern_size() const;
89 dimension border_thickness() const;
90 dimension border_spacer_thickness() const;
91 private:
92 bool iInGradientDialog;
93 unique_gradient iSelection;
94 optional_point iClicked;
95 std::optional<gradient::color_stop_list::iterator> iCurrentColorStop;
96 std::optional<gradient::alpha_stop_list::iterator> iCurrentAlphaStop;
97 bool iTracking;
98 std::unique_ptr<context_menu> iMenu;
99 mutable std::map<resource::hash_digest_type, texture> iStopTextures;
100 std::optional<color_dialog::custom_color_list> iCustomColors;
101 };
102}
gradient::color_stop_list::const_iterator selected_color_stop() const
std::optional< color_dialog::custom_color_list > & custom_colors()
void mouse_button_double_clicked(mouse_button aButton, point const &aPosition, key_modifiers_e aKeyModifiers) override
gradient::alpha_stop_list::const_iterator selected_alpha_stop() const
void mouse_button_released(mouse_button aButton, point const &aPosition) override
neogfx::mouse_cursor mouse_cursor() const override
const std::optional< color_dialog::custom_color_list > & custom_colors() const
void set_gradient(i_ref_ptr< i_gradient > const &aGradient)
neogfx::size_policy size_policy() const override
gradient_widget(i_layout &aLayout, i_gradient const &aGradient=neogfx::gradient{})
void set_gradient(i_gradient const &aGradient)
void mouse_moved(point const &aPosition, key_modifiers_e aKeyModifiers) override
void select_color_stop(gradient::color_stop_list::const_iterator aStop)
gradient_widget(i_gradient const &aGradient=neogfx::gradient{})
void paint(i_graphics_context &aGc) const override
void mouse_button_pressed(mouse_button aButton, point const &aPosition, key_modifiers_e aKeyModifiers) override
void select_alpha_stop(gradient::alpha_stop_list::const_iterator aStop)
gradient_widget(gradient_dialog &aParent, i_layout &aLayout, i_gradient const &aGradient=neogfx::gradient{})
gradient_widget(i_widget &aParent, i_gradient const &aGradient=neogfx::gradient{})
i_gradient const & gradient() const
size minimum_size(optional_size const &aAvailableSpace=optional_size{}) const override
default_geometry_value_type dimension
mouse_button
Definition i_mouse.hpp:31
#define meta_object(...)
Definition i_object.hpp:28
#define define_event(name, declName,...)
Definition event.hpp:200