Skip to content

Commit 2d95b9a

Browse files
committed
Add lineargradient
1 parent 3812b12 commit 2d95b9a

File tree

11 files changed

+53
-39
lines changed

11 files changed

+53
-39
lines changed

src/apps/qutils/canvas.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,12 @@ void BaseCanvas::text(const Geom::Rect &rect, const std::string &text)
199199
QString::fromStdString(text));
200200
}
201201

202-
void BaseCanvas::setBrushGradient(const Geom::Line &line,
203-
const Gfx::ColorGradient &gradient)
204-
{
205-
QLinearGradient qGradient(toQPoint(line.begin),
206-
toQPoint(line.end));
207-
for (auto stop : gradient.stops) {
208-
qGradient.setColorAt(stop.pos, toQColor(stop.value));
209-
}
202+
void BaseCanvas::setBrushGradient(const Gfx::LinearGradient &gradient)
203+
{
204+
QLinearGradient qGradient(toQPoint(gradient.line.begin),
205+
toQPoint(gradient.line.end));
206+
for (auto &&[pos, value] : gradient.colors.stops)
207+
qGradient.setColorAt(pos, toQColor(value));
210208
painter.setBrush(QBrush(qGradient));
211209
painter.setPen(brushToPen(painter.brush()));
212210
}

src/apps/qutils/canvas.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ class BaseCanvas : public Gfx::ICanvas, public Vizzu::Draw::Painter
4646
void text(const Geom::Rect &rect,
4747
const std::string &text) override;
4848

49-
void setBrushGradient(const Geom::Line &line,
50-
const Gfx::ColorGradient &gradient) override;
49+
void setBrushGradient(
50+
const Gfx::LinearGradient &gradient) override;
5151

5252
void frameBegin() override {}
5353
void frameEnd() override {}

src/apps/weblib/jscriptcanvas.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ void JScriptCanvas::text(const Geom::Rect &rect,
170170
text.c_str());
171171
}
172172

173-
void JScriptCanvas::setBrushGradient(const Geom::Line &line,
174-
const Gfx::ColorGradient &gradient)
173+
void JScriptCanvas::setBrushGradient(
174+
const Gfx::LinearGradient &gradient)
175175
{
176-
typedef decltype(gradient.stops)::value_type Stop;
176+
typedef decltype(gradient.colors.stops)::value_type Stop;
177177
static_assert(sizeof(double) == 8);
178178
static_assert(sizeof(Stop) == sizeof(double) * 5);
179179

@@ -189,12 +189,12 @@ void JScriptCanvas::setBrushGradient(const Geom::Line &line,
189189
std::is_same_v<decltype(Stop::value.alpha), double>);
190190

191191
::canvas_setBrushGradient(this,
192-
line.begin.x,
193-
line.begin.y,
194-
line.end.x,
195-
line.end.y,
196-
gradient.stops.size(),
197-
gradient.stops.data());
192+
gradient.line.begin.x,
193+
gradient.line.begin.y,
194+
gradient.line.end.x,
195+
gradient.line.end.y,
196+
gradient.colors.stops.size(),
197+
gradient.colors.stops.data());
198198
}
199199

200200
void JScriptCanvas::frameEnd() { ::canvas_frameEnd(this); }

src/apps/weblib/jscriptcanvas.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class JScriptCanvas : public Gfx::ICanvas, public Draw::Painter
4444
void text(const Geom::Rect &rect,
4545
const std::string &text) override;
4646

47-
void setBrushGradient(const Geom::Line &line,
48-
const Gfx::ColorGradient &gradient) override;
47+
void setBrushGradient(
48+
const Gfx::LinearGradient &gradient) override;
4949

5050
void frameBegin() override;
5151
void frameEnd() override;

src/base/conv/auto_json.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ struct JSONObj : protected JSONRepeat<'{', '}'>
326326
return std::move(*this);
327327
}
328328

329-
template <class T> JSONObj &&mergeObj(T &&obj) &&
329+
template <class T> JSONObj &&mergeObj(const T &obj) &&
330330
{
331331
auto pre_size = json.size();
332332

src/base/gfx/canvas.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#include "base/geom/point.h"
1111
#include "base/geom/rect.h"
1212
#include "base/gfx/color.h"
13-
#include "base/gfx/colorgradient.h"
1413
#include "base/gfx/colortransform.h"
1514
#include "base/gfx/font.h"
15+
#include "base/gfx/lineargradient.h"
1616

1717
namespace Gfx
1818
{
@@ -55,8 +55,7 @@ struct ICanvas
5555
virtual void text(const Geom::Rect &rect,
5656
const std::string &text) = 0;
5757

58-
virtual void setBrushGradient(const Geom::Line &line,
59-
const ColorGradient &gradient) = 0;
58+
virtual void setBrushGradient(const LinearGradient &gradient) = 0;
6059

6160
virtual void frameBegin() = 0;
6261
virtual void frameEnd() = 0;

src/base/gfx/lineargradient.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef GFX_LINEARGRADIENT_H
2+
#define GFX_LINEARGRADIENT_H
3+
4+
#include "base/geom/line.h"
5+
6+
#include "colorgradient.h"
7+
8+
namespace Gfx
9+
{
10+
11+
struct LinearGradient
12+
{
13+
Geom::Line line;
14+
ColorGradient colors;
15+
};
16+
17+
}
18+
19+
#endif // GFX_LINEARGRADIENT_H

src/chart/rendering/drawlegend.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void DrawLegend::ColorGradientSetter::operator()(Gfx::ICanvas &canvas,
108108
modifiableStops[0].value.alpha = 0.0;
109109
modifiableStops[3].value.alpha = 0.0;
110110

111-
canvas.setBrushGradient(transform(line), gradient);
111+
canvas.setBrushGradient({transform(line), gradient});
112112
}
113113

114114
void DrawLegend::drawTitle(const Info &info) const
@@ -340,9 +340,9 @@ void DrawLegend::colorBar(const Info &info,
340340
{
341341
info.canvas.save();
342342

343-
info.canvas.setBrushGradient(rect.leftSide(),
343+
info.canvas.setBrushGradient({rect.leftSide(),
344344
Gfx::ColorGradient{*rootStyle.plot.marker.colorGradient
345-
* info.measureWeight});
345+
* info.measureWeight}});
346346
info.canvas.setLineColor(Gfx::Color::Transparent());
347347
info.canvas.setLineWidth(0);
348348

@@ -372,8 +372,8 @@ void DrawLegend::lightnessBar(const Info &info,
372372

373373
info.canvas.save();
374374

375-
info.canvas.setBrushGradient(rect.leftSide(),
376-
Gfx::ColorGradient{gradient * info.measureWeight});
375+
info.canvas.setBrushGradient({rect.leftSide(),
376+
Gfx::ColorGradient{gradient * info.measureWeight}});
377377
info.canvas.setLineColor(Gfx::Color::Transparent());
378378
info.canvas.setLineWidth(0);
379379

test/e2e/tests/features.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"refs": ["d7c6dee"]
1212
},
1313
"data_input/object_records": {
14-
"refs": ["3a584a1"]
14+
"refs": ["9d5443f"]
1515
},
1616
"events/drawing_events": {
1717
"refs": ["a92ae15"]
@@ -26,7 +26,7 @@
2626
"refs": ["7b07504"]
2727
},
2828
"presets": {
29-
"refs": ["b49796d"]
29+
"refs": ["f154a71"]
3030
},
3131
"detach": {
3232
"refs": ["e3b0c44"]

test/e2e/tests/fixes.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
"refs": ["e03918d"]
3333
},
3434
"536": {
35-
"refs": ["8d89406"]
35+
"refs": ["40a70bd"]
3636
},
3737
"540": {
38-
"refs": ["13feb5d"]
38+
"refs": ["bc34559"]
3939
},
4040
"32303048": {
4141
"refs": ["b5d95ea"]
@@ -44,10 +44,10 @@
4444
"refs": ["2ad1738"]
4545
},
4646
"41932946": {
47-
"refs": ["7a80484"]
47+
"refs": ["eb411c5"]
4848
},
4949
"42836788": {
50-
"refs": ["514c798"]
50+
"refs": ["9a7a020"]
5151
},
5252
"47977099": {
5353
"refs": ["5f58727"]

0 commit comments

Comments
 (0)