1// Aseprite
2// Copyright (C) 2021-2022 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_WHEEL_H_INCLUDED
9#define APP_UI_COLOR_WHEEL_H_INCLUDED
10#pragma once
11
12#include "app/ui/color_selector.h"
13#include "ui/button.h"
14
15namespace app {
16
17 class ColorWheel : public ColorSelector {
18 public:
19 enum class ColorModel {
20 RGB,
21 RYB,
22 NORMAL_MAP,
23 };
24
25 enum class Harmony {
26 NONE,
27 COMPLEMENTARY,
28 MONOCHROMATIC,
29 ANALOGOUS,
30 SPLIT,
31 TRIADIC,
32 TETRADIC,
33 SQUARE,
34 LAST = SQUARE
35 };
36
37 ColorWheel();
38
39 bool isDiscrete() const { return m_discrete; }
40 void setDiscrete(bool state);
41
42 void setColorModel(ColorModel colorModel);
43 void setHarmony(Harmony harmony);
44
45 protected:
46#if SK_ENABLE_SKSL
47 const char* getMainAreaShader() override;
48 const char* getBottomBarShader() override;
49 void setShaderParams(SkRuntimeShaderBuilder& builder, bool main) override;
50#endif
51 app::Color getMainAreaColor(const int u, const int umax,
52 const int v, const int vmax) override;
53 app::Color getBottomBarColor(const int u, const int umax) override;
54 void onPaintMainArea(ui::Graphics* g, const gfx::Rect& rc) override;
55 void onPaintBottomBar(ui::Graphics* g, const gfx::Rect& rc) override;
56 void onPaintSurfaceInBgThread(os::Surface* s,
57 const gfx::Rect& main,
58 const gfx::Rect& bottom,
59 const gfx::Rect& alpha,
60 bool& stop) override;
61 int onNeedsSurfaceRepaint(const app::Color& newColor) override;
62 bool subColorPicked() override { return m_harmonyPicked; }
63
64 private:
65 void onResize(ui::ResizeEvent& ev) override;
66 void onOptions();
67 int getHarmonies() const;
68 app::Color getColorInHarmony(int i) const;
69
70 // Converts an hue angle from HSV <-> current color model hue.
71 // With dir == +1, the angle is from the color model and it's converted to HSV hue.
72 // With dir == -1, the angle came from HSV and is converted to the current color model.
73 float convertHueAngle(float angle, int dir) const;
74
75 std::string m_mainShader;
76 std::string m_bottomShader;
77 gfx::Rect m_wheelBounds;
78 gfx::Color m_bgColor;
79 double m_wheelRadius;
80 bool m_discrete;
81 ColorModel m_colorModel;
82 Harmony m_harmony;
83 ui::Button m_options;
84
85 // Internal flag used to know if after pickColor() we selected an
86 // harmony.
87 mutable bool m_harmonyPicked;
88 };
89
90} // namespace app
91
92#endif
93