Can change canvas background color
This commit is contained in:
parent
0b1cc8d4c2
commit
6cec654d4c
12 changed files with 93 additions and 25 deletions
|
|
@ -8,20 +8,33 @@
|
|||
#define GRID_CACHE_SIZE_INT 10
|
||||
#define GRID_DOT_SIZE 0.5f
|
||||
|
||||
// NOTE: Skia shaders return premultiplied alpha colors
|
||||
|
||||
const char* squareDotGridSkSl =
|
||||
R"V(half4 main(float2 fragCoord) {
|
||||
R"V(
|
||||
uniform vec4 pointColor;
|
||||
|
||||
vec4 main(float2 fragCoord) {
|
||||
float m1 = step(mod(fragCoord.x + 0.25, 10.0), 0.5);
|
||||
float m2 = step(mod(fragCoord.y + 0.25, 10.0), 0.5);
|
||||
float fin = m1 * m2;
|
||||
return half4(fin);
|
||||
|
||||
vec4 pointColorUnmultiplied = vec4(pointColor.rgb, 1.0);
|
||||
|
||||
return pointColorUnmultiplied * pointColor.a * fin;
|
||||
})V";
|
||||
|
||||
const char* circleDotGridSkSl =
|
||||
R"V(half4 main(float2 fragCoord) {
|
||||
R"V(
|
||||
uniform vec4 pointColor;
|
||||
|
||||
vec4 main(float2 fragCoord) {
|
||||
float2 modCoord = mod(fragCoord + float2(5.0), float2(10.0));
|
||||
float fin = step(distance(float2(5.0), modCoord), 0.25);
|
||||
|
||||
return half4(fin);
|
||||
vec4 pointColorUnmultiplied = vec4(pointColor.rgb, 1.0);
|
||||
|
||||
return pointColorUnmultiplied * pointColor.a * fin;
|
||||
})V";
|
||||
|
||||
GridManager::GridManager(MainProgram& initMain):
|
||||
|
|
@ -32,16 +45,21 @@ GridManager::GridManager(MainProgram& initMain):
|
|||
std::cout << "[GridManager::GridManager] Circle dot shader construction error\n";
|
||||
std::cout << err.c_str() << std::endl;
|
||||
}
|
||||
else
|
||||
circleDotShader = effect->makeShader(nullptr, {nullptr, 0});
|
||||
circleDotEffect = effect;
|
||||
|
||||
auto [effect2, err2] = SkRuntimeEffect::MakeForShader(SkString(squareDotGridSkSl));
|
||||
if(!err2.isEmpty()) {
|
||||
std::cout << "[GridManager::GridManager] Square dot shader construction error\n";
|
||||
std::cout << err2.c_str() << std::endl;
|
||||
}
|
||||
else
|
||||
squareDotShader = effect2->makeShader(nullptr, {nullptr, 0});
|
||||
squareDotEffect = effect2;
|
||||
}
|
||||
|
||||
sk_sp<SkShader> GridManager::get_shader(const sk_sp<SkRuntimeEffect>& runtimeEffect, const SkColor4f& pointColor) {
|
||||
SkRuntimeShaderBuilder builder(runtimeEffect);
|
||||
builder.uniform("pointColor") = pointColor;
|
||||
sk_sp<SkShader> s = builder.makeShader();
|
||||
return s;
|
||||
}
|
||||
|
||||
void GridManager::draw(SkCanvas* canvas, const DrawData& drawData) {
|
||||
|
|
@ -73,11 +91,12 @@ void GridManager::draw(SkCanvas* canvas, const DrawData& drawData) {
|
|||
|
||||
SkPaint linePaint;
|
||||
if(gridType == GRIDTYPE_CIRCLEDOT || gridType == GRIDTYPE_SQUAREDOT) {
|
||||
linePaint.setShader(gridType == 1 ? circleDotShader : squareDotShader);
|
||||
linePaint.setAlphaf(std::clamp(alteredZoom / 20.0f, 0.0f, 0.4f));
|
||||
SkColor4f pointColor = main.world->canvasTheme.toolFrontColor;
|
||||
pointColor.fA = std::clamp(alteredZoom / 20.0f, 0.0f, 0.4f);
|
||||
linePaint.setShader(get_shader(gridType == 1 ? circleDotEffect : squareDotEffect, pointColor));
|
||||
}
|
||||
else if(gridType == GRIDTYPE_LINE) {
|
||||
linePaint.setColor4f({1.0f, 1.0f, 1.0f, 1.0f});
|
||||
linePaint.setColor4f(main.world->canvasTheme.toolFrontColor);
|
||||
linePaint.setStyle(SkPaint::kStroke_Style);
|
||||
linePaint.setStrokeWidth(0.0f);
|
||||
linePaint.setAlphaf(std::clamp(alteredZoom / 35.0f, 0.0f, 0.3f));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue