summaryrefslogtreecommitdiffstats
path: root/src/ui/widget/color-scales.h
blob: f3007fd7bd3255b4f516918e59ba96e559e2794d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// SPDX-License-Identifier: GPL-2.0-or-later
/** @file
 * TODO: insert short description here
 *//*
 * Authors: see git history
 *
 * Copyright (C) 2018 Authors
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */
#ifndef SEEN_SP_COLOR_SCALES_H
#define SEEN_SP_COLOR_SCALES_H

#include <gtkmm/grid.h>

#include "ui/selected-color.h"

namespace Inkscape {
namespace UI {
namespace Widget {

class ColorSlider;

enum SPColorScalesMode {
    SP_COLOR_SCALES_MODE_NONE = 0,
    SP_COLOR_SCALES_MODE_RGB = 1,
    SP_COLOR_SCALES_MODE_HSL = 2,
    SP_COLOR_SCALES_MODE_CMYK = 3,
    SP_COLOR_SCALES_MODE_HSV = 4
};

class ColorScales
    : public Gtk::Grid
{
public:
    static const gchar *SUBMODE_NAMES[];

    static gfloat getScaled(const GtkAdjustment *a);
    static void setScaled(GtkAdjustment *a, gfloat v, bool constrained = false);

    ColorScales(SelectedColor &color, SPColorScalesMode mode);
    ~ColorScales() override;

    virtual void _initUI(SPColorScalesMode mode);

    void setMode(SPColorScalesMode mode);
    SPColorScalesMode getMode() const;

protected:
    void _onColorChanged();
    void on_show() override;

    static void _adjustmentAnyChanged(GtkAdjustment *adjustment, ColorScales *cs);
    void _sliderAnyGrabbed();
    void _sliderAnyReleased();
    void _sliderAnyChanged();
    static void _adjustmentChanged(ColorScales *cs, guint channel);

    void _getRgbaFloatv(gfloat *rgba);
    void _getCmykaFloatv(gfloat *cmyka);
    guint32 _getRgba32();
    void _updateSliders(guint channels);
    void _recalcColor();
    void _updateDisplay();

    void _setRangeLimit(gdouble upper);

    SelectedColor &_color;
    SPColorScalesMode _mode;
    gdouble _rangeLimit;
    gboolean _updating : 1;
    gboolean _dragging : 1;
    GtkAdjustment *_a[5];                     /* Channel adjustments */
    Inkscape::UI::Widget::ColorSlider *_s[5]; /* Channel sliders */
    GtkWidget *_b[5];                         /* Spinbuttons */
    GtkWidget *_l[5];                         /* Labels */

private:
    // By default, disallow copy constructor and assignment operator
    ColorScales(ColorScales const &obj) = delete;
    ColorScales &operator=(ColorScales const &obj) = delete;
};

class ColorScalesFactory : public Inkscape::UI::ColorSelectorFactory
{
public:
    ColorScalesFactory(SPColorScalesMode submode);
    ~ColorScalesFactory() override;

    Gtk::Widget *createWidget(Inkscape::UI::SelectedColor &color) const override;
    Glib::ustring modeName() const override;

private:
    SPColorScalesMode _submode;
};

}
}
}

#endif /* !SEEN_SP_COLOR_SCALES_H */
/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :