supertux
item_colorchannel.hpp
1 // SuperTux
2 // Copyright (C) 2015 Hume2 <teratux.mail@gmail.com>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef HEADER_SUPERTUX_GUI_ITEM_COLORCHANNEL_HPP
18 #define HEADER_SUPERTUX_GUI_ITEM_COLORCHANNEL_HPP
19 
20 #include "gui/menu_item.hpp"
21 
22 #include "util/colorspace_oklab.hpp"
23 #include "video/color.hpp"
24 
25 
26 class ItemColorChannelRGBA final : public MenuItem
27 {
28 public:
29  ItemColorChannelRGBA(float* input_, Color channel_, int id_ = -1,
30  bool is_linear = false);
31 
33  virtual void draw(DrawingContext&, const Vector& pos, int menu_width, bool active) override;
34 
36  virtual int get_width() const override;
37 
39  virtual void process_action(const MenuAction& action) override;
40 
42  virtual void event(const SDL_Event& ev) override;
43 
44  virtual Color get_color() const override;
45 
46  virtual bool changes_width() const override { return true; }
47 
48  void change_input(const std::string& input_) { set_text(input_); }
49 
50 private:
51  void enable_edit_mode();
52  void add_char(char c);
53  void remove_char();
54 
55 private:
56  float* m_number;
57  float m_number_prev;
58  bool m_is_linear;
59  bool m_edit_mode;
60  int m_flickw;
61  Color m_channel;
62 
63 private:
65  ItemColorChannelRGBA& operator=(const ItemColorChannelRGBA&) = delete;
66 };
67 
68 
69 class ItemColorChannelOKLab final : public MenuItem
70 {
71 public:
72  enum class ChannelType { CHANNEL_L, CHANNEL_C, CHANNEL_H };
73 
74 public:
75  ItemColorChannelOKLab(Color* col, int channel, Menu* menu);
76  virtual void draw(DrawingContext&, const Vector& pos, int menu_width,
77  bool active) override;
79  virtual int get_width() const override { return 64; }
80  virtual void process_action(const MenuAction& action) override;
81  virtual void event(const SDL_Event& ev) override;
82  virtual bool changes_width() const override { return true; }
83 
84 private:
85  void set_color(ColorOKLCh& col_oklch_clipped, ColorOKLCh& col_oklch_store);
86 
87 private:
88  Color* m_color;
89  ColorOKLCh m_col_prev;
90  ChannelType m_channel;
91  Menu* m_menu;
92  bool m_mousedown;
93 
94 private:
96  ItemColorChannelOKLab& operator=(const ItemColorChannelOKLab&) = delete;
97 };
98 
99 #endif
100 
101 /* EOF */
virtual int get_width() const override
Returns the minimum width of the menu item.
Definition: item_colorchannel_rgba.cpp:78
virtual void draw(DrawingContext &, const Vector &pos, int menu_width, bool active) override
Draws the menu item.
Definition: item_colorchannel_rgba.cpp:62
Definition: item_colorchannel.hpp:26
Definition: item_colorchannel.hpp:69
virtual bool changes_width() const override
Returns true when the width must be recalculated when an action is processed.
Definition: item_colorchannel.hpp:82
Definition: colorspace_oklab.hpp:24
virtual int get_width() const override
Returns the minimum width of the menu item.
Definition: item_colorchannel.hpp:79
virtual void process_action(const MenuAction &action) override
Processes the menu action.
Definition: item_colorchannel_rgba.cpp:164
Definition: menu_item.hpp:23
virtual void event(const SDL_Event &ev) override
Processes the given event.
Definition: item_colorchannel_rgba.cpp:95
virtual bool changes_width() const override
Returns true when the width must be recalculated when an action is processed.
Definition: item_colorchannel.hpp:46
Definition: menu.hpp:55
Definition: color.hpp:26
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42