| 1 | // Aseprite | 
|---|---|
| 2 | // Copyright (C) 2020 Igara Studio S.A. | 
| 3 | // Copyright (C) 2001-2018 David Capello | 
| 4 | // | 
| 5 | // This program is distributed under the terms of | 
| 6 | // the End-User License Agreement for Aseprite. | 
| 7 | |
| 8 | #ifndef APP_UI_COLOR_POPUP_H_INCLUDED | 
| 9 | #define APP_UI_COLOR_POPUP_H_INCLUDED | 
| 10 | #pragma once | 
| 11 | |
| 12 | #include "app/color.h" | 
| 13 | #include "app/shade.h" | 
| 14 | #include "app/ui/button_set.h" | 
| 15 | #include "app/ui/color_button_options.h" | 
| 16 | #include "app/ui/color_shades.h" | 
| 17 | #include "app/ui/color_sliders.h" | 
| 18 | #include "app/ui/hex_color_entry.h" | 
| 19 | #include "app/ui/palette_view.h" | 
| 20 | #include "app/ui/popup_window_pin.h" | 
| 21 | #include "obs/connection.h" | 
| 22 | #include "obs/signal.h" | 
| 23 | #include "ui/grid.h" | 
| 24 | #include "ui/label.h" | 
| 25 | #include "ui/tooltips.h" | 
| 26 | #include "ui/view.h" | 
| 27 | |
| 28 | namespace app { | 
| 29 | class PaletteIndexChangeEvent; | 
| 30 | |
| 31 | class ColorPopup : public PopupWindowPin | 
| 32 | , public PaletteViewDelegate { | 
| 33 | public: | 
| 34 | enum SetColorOptions { | 
| 35 | ChangeType, | 
| 36 | DontChangeType | 
| 37 | }; | 
| 38 | |
| 39 | ColorPopup(const ColorButtonOptions& options); | 
| 40 | ~ColorPopup(); | 
| 41 | |
| 42 | void setColor(const app::Color& color, | 
| 43 | const SetColorOptions options); | 
| 44 | app::Color getColor() const; | 
| 45 | |
| 46 | // Signals | 
| 47 | obs::signal<void(const app::Color&)> ColorChange; | 
| 48 | |
| 49 | protected: | 
| 50 | bool onProcessMessage(ui::Message* msg) override; | 
| 51 | void onWindowResize() override; | 
| 52 | void onMakeFloating() override; | 
| 53 | void onMakeFixed() override; | 
| 54 | void onColorSlidersChange(ColorSlidersChangeEvent& ev); | 
| 55 | void onColorHexEntryChange(const app::Color& color); | 
| 56 | void onSelectOldColor(ColorShades::ClickEvent& ev); | 
| 57 | void onSimpleColorClick(); | 
| 58 | void onColorTypeClick(); | 
| 59 | void onPaletteChange(); | 
| 60 | |
| 61 | // PaletteViewDelegate impl | 
| 62 | void onPaletteViewIndexChange(int index, ui::MouseButton button) override; | 
| 63 | |
| 64 | private: | 
| 65 | void selectColorType(app::Color::Type type); | 
| 66 | void setColorWithSignal(const app::Color& color, | 
| 67 | const SetColorOptions options); | 
| 68 | void findBestfitIndex(const app::Color& color); | 
| 69 | bool inEditMode(); | 
| 70 | |
| 71 | class SimpleColors; | 
| 72 | class CustomButtonSet : public ButtonSet { | 
| 73 | public: | 
| 74 | CustomButtonSet(); | 
| 75 | private: | 
| 76 | void onSelectItem(Item* item, bool focusItem, ui::Message* msg) override; | 
| 77 | }; | 
| 78 | |
| 79 | ui::Box m_vbox; | 
| 80 | ui::TooltipManager m_tooltips; | 
| 81 | ui::Box m_topBox; | 
| 82 | app::Color m_color; | 
| 83 | Widget* m_closeButton; | 
| 84 | ui::View* m_colorPaletteContainer; | 
| 85 | PaletteView* m_colorPalette; | 
| 86 | SimpleColors* m_simpleColors; | 
| 87 | CustomButtonSet m_colorType; | 
| 88 | HexColorEntry m_hexColorEntry; | 
| 89 | ColorShades m_oldAndNew; | 
| 90 | ColorSliders m_sliders; | 
| 91 | ui::Label m_maskLabel; | 
| 92 | obs::scoped_connection m_onPaletteChangeConn; | 
| 93 | bool m_canPin; | 
| 94 | bool m_insideChange; | 
| 95 | |
| 96 | // This variable is used to avoid updating the m_hexColorEntry text | 
| 97 | // when the color change is generated from a | 
| 98 | // HexColorEntry::ColorChange signal. In this way we don't override | 
| 99 | // what the user is writting in the text field. | 
| 100 | bool m_disableHexUpdate; | 
| 101 | }; | 
| 102 | |
| 103 | } // namespace app | 
| 104 | |
| 105 | #endif | 
| 106 | 
