mirror of
https://github.com/penpot/penpot.git
synced 2025-05-10 09:16:38 +02:00
🐛 Fix blend mode against background
This commit is contained in:
parent
579a5729e6
commit
21da6ddd4a
5 changed files with 34 additions and 2 deletions
|
@ -49,6 +49,14 @@ pub extern "C" fn set_render_options(debug: u32, dpr: f32) {
|
|||
render_state.set_dpr(dpr);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn set_canvas_background(raw_color: u32) {
|
||||
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
|
||||
|
||||
let color = skia::Color::new(raw_color);
|
||||
state.set_background_color(color);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn render() {
|
||||
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
|
||||
|
|
|
@ -49,6 +49,7 @@ pub(crate) struct RenderState {
|
|||
options: RenderOptions,
|
||||
pub viewbox: Viewbox,
|
||||
images: ImageStore,
|
||||
background_color: skia::Color,
|
||||
}
|
||||
|
||||
impl RenderState {
|
||||
|
@ -72,6 +73,7 @@ impl RenderState {
|
|||
options: RenderOptions::default(),
|
||||
viewbox: Viewbox::new(width as f32, height as f32),
|
||||
images: ImageStore::new(),
|
||||
background_color: skia::Color::TRANSPARENT,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,6 +99,11 @@ impl RenderState {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn set_background_color(&mut self, color: skia::Color) {
|
||||
self.background_color = color;
|
||||
let _ = self.render_all_from_cache();
|
||||
}
|
||||
|
||||
pub fn resize(&mut self, width: i32, height: i32) {
|
||||
let dpr_width = (width as f32 * self.options.dpr()).floor() as i32;
|
||||
let dpr_height = (height as f32 * self.options.dpr()).floor() as i32;
|
||||
|
@ -136,7 +143,7 @@ impl RenderState {
|
|||
.reset_matrix();
|
||||
self.final_surface
|
||||
.canvas()
|
||||
.clear(skia::Color::TRANSPARENT)
|
||||
.clear(self.background_color)
|
||||
.reset_matrix();
|
||||
self.debug_surface
|
||||
.canvas()
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use skia_safe as skia;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::render::RenderState;
|
||||
|
@ -57,4 +59,9 @@ impl<'a> State<'a> {
|
|||
pub fn current_shape(&'a mut self) -> Option<&'a mut Shape> {
|
||||
self.current_shape.as_deref_mut()
|
||||
}
|
||||
|
||||
pub fn set_background_color(&mut self, color: skia::Color) {
|
||||
self.render_state.set_background_color(color);
|
||||
self.render_all(true);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue