[DEV] continue integration of gradient
This commit is contained in:
parent
7e67a54e32
commit
9c5496f857
@ -335,7 +335,8 @@ std::pair<etk::Color<float,4>, std::string> esvg::Base::parseColor(const std::st
|
|||||||
&& _inputData[2] == 'l'
|
&& _inputData[2] == 'l'
|
||||||
&& _inputData[3] == '(') {
|
&& _inputData[3] == '(') {
|
||||||
if (_inputData[4] == '#') {
|
if (_inputData[4] == '#') {
|
||||||
localColor = std::pair<etk::Color<float,4>, std::string>(etk::color::none, &(_inputData[5]));
|
std::string color(_inputData.begin() + 5, _inputData.end()-1);
|
||||||
|
localColor = std::pair<etk::Color<float,4>, std::string>(etk::color::none, color);
|
||||||
} else {
|
} else {
|
||||||
SVG_ERROR(" pb in parsing the color : \"" << _inputData << "\" == > url(XXX) is not supported now ...");
|
SVG_ERROR(" pb in parsing the color : \"" << _inputData << "\" == > url(XXX) is not supported now ...");
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,12 @@ void esvg::Renderer::print(const esvg::render::Weight& _weightFill,
|
|||||||
float _opacity) {
|
float _opacity) {
|
||||||
int32_t sizeX = m_size.x();
|
int32_t sizeX = m_size.x();
|
||||||
int32_t sizeY = m_size.y();
|
int32_t sizeY = m_size.y();
|
||||||
|
if (_colorFill != nullptr) {
|
||||||
|
_colorFill->generate(m_document);
|
||||||
|
}
|
||||||
|
if (_colorStroke != nullptr) {
|
||||||
|
_colorStroke->generate(m_document);
|
||||||
|
}
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
sizeX *= m_factor;
|
sizeX *= m_factor;
|
||||||
sizeY *= m_factor;
|
sizeY *= m_factor;
|
||||||
@ -80,10 +86,16 @@ void esvg::Renderer::print(const esvg::render::Weight& _weightFill,
|
|||||||
float valueFill = _weightFill.get(pos);
|
float valueFill = _weightFill.get(pos);
|
||||||
float valueStroke = _weightStroke.get(pos);
|
float valueStroke = _weightStroke.get(pos);
|
||||||
// calculate merge of stroke and fill value:
|
// calculate merge of stroke and fill value:
|
||||||
etk::Color<float,4> intermediateColorFill = _colorFill->getColor(pos);
|
etk::Color<float,4> intermediateColorFill(etk::color::none);
|
||||||
|
etk::Color<float,4> intermediateColorStroke(etk::color::none);
|
||||||
|
if (_colorFill != nullptr) {
|
||||||
|
intermediateColorFill = _colorFill->getColor(pos);
|
||||||
intermediateColorFill.setA(intermediateColorFill.a()*valueFill);
|
intermediateColorFill.setA(intermediateColorFill.a()*valueFill);
|
||||||
etk::Color<float,4> intermediateColorStroke = _colorStroke->getColor(pos);
|
}
|
||||||
|
if (_colorStroke != nullptr) {
|
||||||
|
intermediateColorStroke = _colorStroke->getColor(pos);
|
||||||
intermediateColorStroke.setA(intermediateColorStroke.a()*valueStroke);
|
intermediateColorStroke.setA(intermediateColorStroke.a()*valueStroke);
|
||||||
|
}
|
||||||
etk::Color<float,4> intermediateColor = mergeColor(intermediateColorFill, intermediateColorStroke);
|
etk::Color<float,4> intermediateColor = mergeColor(intermediateColorFill, intermediateColorStroke);
|
||||||
intermediateColor.setA(intermediateColor.a() * _opacity);
|
intermediateColor.setA(intermediateColor.a() * _opacity);
|
||||||
m_buffer[sizeX*yyy + xxx] = mergeColor(m_buffer[sizeX*yyy + xxx], intermediateColor);
|
m_buffer[sizeX*yyy + xxx] = mergeColor(m_buffer[sizeX*yyy + xxx], intermediateColor);
|
||||||
|
@ -352,3 +352,22 @@ bool esvg::Document::parseXMLData(const std::shared_ptr<exml::Element>& _root, b
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
std::shared_ptr<esvg::Base> esvg::Document::getReference(const std::string& _name) {
|
||||||
|
if (_name == "") {
|
||||||
|
SVG_ERROR("request a reference with no name ... ");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
for (auto &it : m_refList) {
|
||||||
|
if (it == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (it->getId() == _name) {
|
||||||
|
return it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SVG_ERROR("Can not find reference name : '" << _name << "'");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -92,6 +92,7 @@ namespace esvg {
|
|||||||
vec2 getDefinedSize() {
|
vec2 getDefinedSize() {
|
||||||
return m_size;
|
return m_size;
|
||||||
};
|
};
|
||||||
|
std::shared_ptr<esvg::Base> getReference(const std::string& _name);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8,9 +8,13 @@
|
|||||||
|
|
||||||
#include <esvg/debug.h>
|
#include <esvg/debug.h>
|
||||||
#include <esvg/render/DynamicColor.h>
|
#include <esvg/render/DynamicColor.h>
|
||||||
|
#include <esvg/LinearGradient.h>
|
||||||
|
#include <esvg/esvg.h>
|
||||||
|
|
||||||
esvg::render::DynamicColorLinear::DynamicColorLinear(const std::string& _link, const mat2& _mtx, const vec2 _objectSize, const vec2 _objectPos)
|
esvg::render::DynamicColorLinear::DynamicColorLinear(const std::string& _link, const mat2& _mtx, const vec2 _size) :
|
||||||
{
|
m_colorName(_link),
|
||||||
|
m_matrix(_mtx),
|
||||||
|
m_size(_size) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,6 +23,25 @@ etk::Color<float,4> esvg::render::DynamicColorLinear::getColor(const ivec2& _pos
|
|||||||
return etk::color::purple;
|
return etk::color::purple;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void esvg::render::DynamicColorLinear::generate(esvg::Document* _document) {
|
||||||
|
if (_document == nullptr) {
|
||||||
|
SVG_ERROR("Get nullptr input for document");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::shared_ptr<esvg::Base> base = _document->getReference(m_colorName);
|
||||||
|
if (base == nullptr) {
|
||||||
|
SVG_ERROR("Can not get base : '" << m_colorName << "'");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::shared_ptr<esvg::LinearGradient> gradient = std::dynamic_pointer_cast<esvg::LinearGradient>(base);
|
||||||
|
if (gradient == nullptr) {
|
||||||
|
SVG_ERROR("Can not cast in a linear gradient: '" << m_colorName << "' ==> wrong type");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SVG_INFO("get for color linear:");
|
||||||
|
gradient->display(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::shared_ptr<esvg::render::DynamicColor> esvg::render::createColor(std::pair<etk::Color<float,4>, std::string> _color, const mat2& _mtx, const vec2 _size) {
|
std::shared_ptr<esvg::render::DynamicColor> esvg::render::createColor(std::pair<etk::Color<float,4>, std::string> _color, const mat2& _mtx, const vec2 _size) {
|
||||||
// Check if need to create a color:
|
// Check if need to create a color:
|
||||||
|
@ -9,12 +9,14 @@
|
|||||||
#ifndef __ESVG_RENDER_DYNAMIC_COLOR_H__
|
#ifndef __ESVG_RENDER_DYNAMIC_COLOR_H__
|
||||||
#define __ESVG_RENDER_DYNAMIC_COLOR_H__
|
#define __ESVG_RENDER_DYNAMIC_COLOR_H__
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <etk/types.h>
|
#include <etk/types.h>
|
||||||
#include <etk/Color.h>
|
#include <etk/Color.h>
|
||||||
#include <etk/math/Vector2D.h>
|
#include <etk/math/Vector2D.h>
|
||||||
#include <etk/math/Matrix2.h>
|
#include <etk/math/Matrix2.h>
|
||||||
|
|
||||||
namespace esvg {
|
namespace esvg {
|
||||||
|
class Document;
|
||||||
namespace render {
|
namespace render {
|
||||||
class DynamicColor {
|
class DynamicColor {
|
||||||
public:
|
public:
|
||||||
@ -23,6 +25,7 @@ namespace esvg {
|
|||||||
}
|
}
|
||||||
virtual ~DynamicColor() {};
|
virtual ~DynamicColor() {};
|
||||||
virtual etk::Color<float,4> getColor(const ivec2& _pos) = 0;
|
virtual etk::Color<float,4> getColor(const ivec2& _pos) = 0;
|
||||||
|
virtual void generate(esvg::Document* _document) = 0;
|
||||||
};
|
};
|
||||||
class DynamicColorUni : public esvg::render::DynamicColor {
|
class DynamicColorUni : public esvg::render::DynamicColor {
|
||||||
public:
|
public:
|
||||||
@ -32,16 +35,22 @@ namespace esvg {
|
|||||||
m_color(_color) {
|
m_color(_color) {
|
||||||
|
|
||||||
}
|
}
|
||||||
etk::Color<float,4> getColor(const ivec2& _pos) {
|
virtual etk::Color<float,4> getColor(const ivec2& _pos) {
|
||||||
return m_color;
|
return m_color;
|
||||||
}
|
}
|
||||||
|
virtual void generate(esvg::Document* _document) {
|
||||||
|
// nothing to do ...
|
||||||
|
}
|
||||||
};
|
};
|
||||||
class DynamicColorLinear : public esvg::render::DynamicColor {
|
class DynamicColorLinear : public esvg::render::DynamicColor {
|
||||||
public:
|
public:
|
||||||
etk::Color<float,4> m_color;
|
std::string m_colorName;
|
||||||
|
mat2 m_matrix;
|
||||||
|
vec2 m_size;
|
||||||
public:
|
public:
|
||||||
DynamicColorLinear(const std::string& _link, const mat2& _mtx, const vec2 _objectSize, const vec2 _objectPos);
|
DynamicColorLinear(const std::string& _link, const mat2& _mtx, const vec2 _size);
|
||||||
etk::Color<float,4> getColor(const ivec2& _pos);
|
virtual etk::Color<float,4> getColor(const ivec2& _pos);
|
||||||
|
virtual void generate(esvg::Document* _document);
|
||||||
};
|
};
|
||||||
|
|
||||||
std::shared_ptr<DynamicColor> createColor(std::pair<etk::Color<float,4>, std::string> _color, const mat2& _mtx, const vec2 _size);
|
std::shared_ptr<DynamicColor> createColor(std::pair<etk::Color<float,4>, std::string> _color, const mat2& _mtx, const vec2 _size);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user