| 1 | // Aseprite |
| 2 | // Copyright (C) 2021 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_BUTTON_H_INCLUDED |
| 9 | #define APP_UI_COLOR_BUTTON_H_INCLUDED |
| 10 | #pragma once |
| 11 | |
| 12 | #include "app/color.h" |
| 13 | #include "app/context_observer.h" |
| 14 | #include "app/ui/color_button_options.h" |
| 15 | #include "app/ui/color_source.h" |
| 16 | #include "doc/pixel_format.h" |
| 17 | #include "obs/signal.h" |
| 18 | #include "ui/button.h" |
| 19 | |
| 20 | namespace ui { |
| 21 | class CloseEvent; |
| 22 | class InitThemeEvent; |
| 23 | } |
| 24 | |
| 25 | namespace app { |
| 26 | class ; |
| 27 | |
| 28 | class ColorButton : public ui::ButtonBase, |
| 29 | public ContextObserver, |
| 30 | public IColorSource { |
| 31 | public: |
| 32 | ColorButton(const app::Color& color, |
| 33 | const PixelFormat pixelFormat, |
| 34 | const ColorButtonOptions& options); |
| 35 | ~ColorButton(); |
| 36 | |
| 37 | PixelFormat pixelFormat() const; |
| 38 | void setPixelFormat(PixelFormat pixelFormat); |
| 39 | |
| 40 | app::Color getColor() const; |
| 41 | void setColor(const app::Color& color); |
| 42 | |
| 43 | bool (); |
| 44 | void (const bool forcePinned); |
| 45 | void (); |
| 46 | |
| 47 | // IColorSource |
| 48 | app::Color getColorByPosition(const gfx::Point& pos) override; |
| 49 | |
| 50 | // Signals |
| 51 | obs::signal<void(app::Color&)> BeforeChange; |
| 52 | obs::signal<void(const app::Color&)> Change; |
| 53 | |
| 54 | protected: |
| 55 | // Events |
| 56 | void onInitTheme(ui::InitThemeEvent& ev) override; |
| 57 | bool onProcessMessage(ui::Message* msg) override; |
| 58 | void onSizeHint(ui::SizeHintEvent& ev) override; |
| 59 | void onPaint(ui::PaintEvent& ev) override; |
| 60 | void onClick(ui::Event& ev) override; |
| 61 | void onStartDrag() override; |
| 62 | void onSelectWhenDragging() override; |
| 63 | void onLoadLayout(ui::LoadLayoutEvent& ev) override; |
| 64 | void onSaveLayout(ui::SaveLayoutEvent& ev) override; |
| 65 | |
| 66 | private: |
| 67 | // ContextObserver impl |
| 68 | void onActiveSiteChange(const Site& site) override; |
| 69 | |
| 70 | void onWindowClose(ui::CloseEvent& ev); |
| 71 | void onWindowColorChange(const app::Color& color); |
| 72 | bool canPin() const { return m_options.canPinSelector; } |
| 73 | |
| 74 | // Used to convert saved bounds (m_window/hiddenDefaultBounds, |
| 75 | // which can be relative to the display or relative to the screen) |
| 76 | // to the current system of coordinates. |
| 77 | gfx::Rect convertBounds(const gfx::Rect& bounds) const; |
| 78 | |
| 79 | app::Color m_color; |
| 80 | app::Color m_startDragColor; |
| 81 | PixelFormat m_pixelFormat; |
| 82 | ColorPopup* m_window; |
| 83 | gfx::Rect m_windowDefaultBounds; |
| 84 | gfx::Rect ; |
| 85 | bool m_desktopCoords; // True if m_windowDefault/hiddenPopupBounds are screen coordinates |
| 86 | bool m_dependOnLayer; |
| 87 | bool m_mouseLeft; |
| 88 | ColorButtonOptions m_options; |
| 89 | }; |
| 90 | |
| 91 | } // namespace app |
| 92 | |
| 93 | #endif |
| 94 | |