Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
color-palette-preview.cpp
Go to the documentation of this file.
1
// SPDX-License-Identifier: GPL-2.0-or-later
5
/*
6
* Authors:
7
* Michael Kowalski
8
* Daniel Boles <dboles.src+inkscape@gmail.com>
9
*
10
* Copyright (C) 2021 Michael Kowalski
11
* Copyright (C) 2023 Daniel Boles
12
* Released under GNU GPL v2+, read the file 'COPYING' for more information.
13
*/
14
15
#include "
color-palette-preview.h
"
16
17
#include <utility>
18
#include <cairomm/context.h>
19
#include <sigc++/functors/mem_fun.h>
20
21
namespace
Inkscape::UI::Widget
{
22
23
static
constexpr
int
height
= 2;
24
static
constexpr
int
dx
= 1;
// width per color
25
26
ColorPalettePreview::ColorPalettePreview
(std::vector<rgb_t> colors)
27
:
Glib
::ObjectBase{
"ColorPalettePreview"
}
28
,
Gtk
::DrawingArea{}
29
, _colors{
std
::move(colors)}
30
{
31
set_size_request(-1,
height
);
32
set_draw_func(sigc::mem_fun(*
this
, &
ColorPalettePreview::draw_func
));
33
}
34
35
void
ColorPalettePreview::draw_func
(Cairo::RefPtr<Cairo::Context>
const
&cr,
int
width
,
int
height
)
36
{
37
if
(
_colors
.empty())
return
;
38
if
(
width
<= 0)
return
;
39
40
for
(
int
i = 0, px = 0; i <
width
&& px <
width
; ++i, px +=
dx
) {
41
int
const
index
= i *
_colors
.size() /
width
;
42
auto
&color =
_colors
.at(
index
);
43
cr->set_source_rgb(color.r, color.g, color.b);
44
cr->rectangle(px, 0,
dx
,
height
);
45
cr->fill();
46
}
47
}
48
49
}
// namespace Inkscape::UI::Widget
50
51
/*
52
Local Variables:
53
mode:c++
54
c-file-style:"stroustrup"
55
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
56
indent-tabs-mode:nil
57
fill-column:99
58
End:
59
*/
60
// vim:filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99:
Inkscape::UI::Widget::ColorPalettePreview::_colors
std::vector< rgb_t > _colors
Definition
color-palette-preview.h:33
Inkscape::UI::Widget::ColorPalettePreview::ColorPalettePreview
ColorPalettePreview(std::vector< rgb_t > colors)
Construct with colors that we will preview.
Definition
color-palette-preview.cpp:26
Inkscape::UI::Widget::ColorPalettePreview::draw_func
void draw_func(Cairo::RefPtr< Cairo::Context > const &cr, int, int)
Definition
color-palette-preview.cpp:35
color-palette-preview.h
A Gtk::DrawingArea to preview color palette menu items by showing a small example of the colors.
Glib
Definition
actions-canvas-snapping.h:17
Gtk
Definition
desktop.h:50
Inkscape::UI::Widget
Custom widgets.
Definition
desktop.h:126
Inkscape::UI::Widget::height
static constexpr int height
Definition
color-palette-preview.cpp:23
Inkscape::UI::Widget::dx
static constexpr int dx
Definition
color-palette-preview.cpp:24
std
STL namespace.
index
int index
Definition
tab-strip.cpp:875
width
double width
Definition
convex_hull.cpp:106
src
ui
widget
color-palette-preview.cpp
Generated on Sun Jun 15 2025 04:01:16 for Inkscape by
1.9.8