Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README Covers #1

Open
meloalright opened this issue Jan 25, 2023 · 13 comments
Open

README Covers #1

meloalright opened this issue Jan 25, 2023 · 13 comments

Comments

@meloalright
Copy link
Member

demo spec

@meloalright
Copy link
Member Author

slogan2

@meloalright
Copy link
Member Author

meloalright commented Jun 17, 2023

vue-live

@meloalright
Copy link
Member Author

WX20230619-002122@2x

@meloalright
Copy link
Member Author

截屏2023-08-16 01 11 48

@meloalright
Copy link
Member Author

截屏2023-08-16 01 16 00

@meloalright
Copy link
Member Author

截屏2023-08-16 01 18 38

@meloalright
Copy link
Member Author

meloalright commented Aug 15, 2023

截屏2023-08-16 01 28 58

@meloalright meloalright changed the title Slogan README Covers Aug 20, 2023
@meloalright
Copy link
Member Author

meloalright commented Jul 14, 2024

cover

cover

@meloalright
Copy link
Member Author

impl Shape for Image {
fn default() -> Self {
todo!()
}
fn draw(&self, pixmap: &mut Pixmap, context: &DrawContext) -> () {
let u8_array = base64::decode(&self.image).expect("base64 decode failed");
let mut bytes: Vec<u8> = Vec::new();
let mut img = ImageReader::new(Cursor::new(&u8_array as &[u8])).with_guessed_format().unwrap().decode().unwrap();
if let Some(blur) = self.blur {
img = img.blur(blur);
}
if let Some(grayscale) = self.grayscale {
if grayscale {
img = img.grayscale();
}
}
if let Some(brighten) = self.brighten {
img = img.brighten(brighten);
}
if let Some(invert) = self.invert {
if invert {
img.invert();
}
}
img.write_to(&mut Cursor::new(&mut bytes), image::ImageFormat::Png).unwrap();
let p = Pixmap::decode_png(&bytes).expect("decode png failed");
let scale_x = self.width as f32 / p.width() as f32;
let scale_y = self.height as f32 / p.height() as f32;
pixmap.draw_pixmap(
self.x,
self.y,
p.as_ref(),
&PixmapPaint::default(),
Transform::from_row(scale_x, 0.0, 0.0, scale_y, 0.0, 0.0),
None,
);
}
}

WASMShapesAttr::I(WASMImageAttr {
x,
y,
image,
width,
height,
blur,
grayscale,
brighten,
invert,
}) => self.0.set_shape_to_child(
id,
Shapes::I(Image {
image,
x,
y,
width,
height,
blur,
grayscale,
brighten,
invert,
}),
),

@meloalright
Copy link
Member Author

meloalright commented Aug 18, 2024

onBeforeMount(() => {
const instance = getCurrentInstance() as ComponentInternalInstanceWithSoftSkiaWASM;
var root = instance as ComponentInternalInstanceWithSoftSkiaWASM;
while (!root.ssw) {
root = root.parent as ComponentInternalInstanceWithSoftSkiaWASM;
}
const core = root.ssw;
instance._ssw_id = SelfIncreaseCount.count;
var parent = instance.parent;
while (!('_ssw_id' in parent)) {
parent = parent.parent;
}
core.createChildAppendToContainer(instance._ssw_id, (parent as ComponentInternalInstanceWithSoftSkiaWASM)._ssw_id);
updateInstance(core, name, instance, attrs);
(
parent as ComponentInternalInstanceWithSoftSkiaWASM
)._ssw_grouped?.(instance);
root._ssw_batchDraw?.()
});

function updateInstance(core: SoftSkiaWASM, name: string, instance: ComponentInternalInstanceWithSoftSkiaWASM, attrs: SetupContext['attrs']) {
if (name === 'Rect') {
core.setAttrBySerde(instance._ssw_id, { attr: { R: { x: attrs.x, y: attrs.y, width: attrs.width, height: attrs.height, color: attrs.color, style: attrs.style } } })
}
if (name === 'Circle') {
core.setAttrBySerde(instance._ssw_id, { attr: { C: { cx: attrs.cx, cy: attrs.cy, r: attrs.r, color: attrs.color, style: attrs.style } } })
}
if (name === 'RoundRect') {
core.setAttrBySerde(instance._ssw_id, { attr: { RR: { x: attrs.x, y: attrs.y, r: attrs.r, width: attrs.width, height: attrs.height, color: attrs.color, style: attrs.style } } })
}
if (name === 'Line') {
core.setAttrBySerde(instance._ssw_id, { attr: { L: { p1: attrs.p1, p2: attrs.p2, stroke_width: attrs.strokeWidth, color: attrs.color } } })
}
if (name === 'Points') {
core.setAttrBySerde(instance._ssw_id, { attr: { P: { points: attrs.points, stroke_width: attrs.strokeWidth, color: attrs.color, style: attrs.style } } })
}
if (name === 'Group') {
core.setAttrBySerde(instance._ssw_id, {
attr: {
G: {
x: attrs.x,
y: attrs.y,
color: attrs.color,
stroke_width: attrs.strokeWidth,
style: attrs.style,
invert_clip: attrs.invertClip,
},
},
});
}
if (name === "Image") {
core.setAttrBySerde(instance._ssw_id, {
attr: {
I: {
image: attrs.image,
x: attrs.x,
y: attrs.y,
width: attrs.width,
height: attrs.height,
blur: attrs.blur,
grayscale: attrs.grayscale,
brighten: attrs.brighten,
invert: attrs.invert,
},
},
});
}
if (name === "Text") {
core.setAttrBySerde(instance._ssw_id, {
attr: {
T: {
text: attrs.text,
x: attrs.x,
y: attrs.y,
font_size: attrs.fontSize,
color: attrs.color,
max_width: attrs.maxWidth,
},
},
});
}
}

onBeforeUnmount(() => {
const instance = getCurrentInstance() as ComponentInternalInstanceWithSoftSkiaWASM;
var root = instance as ComponentInternalInstanceWithSoftSkiaWASM;
while (!root.ssw) {
root = root.parent as ComponentInternalInstanceWithSoftSkiaWASM;
}
const core = root.ssw;
const child_id = instance._ssw_id;
var parent = instance.parent;
while (!('_ssw_id' in parent)) {
parent = parent.parent;
}
core.removeChildFromContainer(child_id, (parent as ComponentInternalInstanceWithSoftSkiaWASM)._ssw_id)
});

@meloalright
Copy link
Member Author

meloalright commented Aug 31, 2024

#[derive(Debug)]
pub struct Points {
pub points: Vec<[u32; 2]>,
pub color: Option<ColorU8>,
pub stroke_width: Option<u32>,
pub style: Option<PaintStyle>,
}

#[derive(Debug)]
pub struct Image {
pub image: String,
pub x: i32,
pub y: i32,
pub width: u32,
pub height: u32,
pub blur: Option<f32>,
pub grayscale: Option<bool>,
pub brighten: Option<i32>,
pub invert: Option<bool>,
}

fn draw(&self, pixmap: &mut Pixmap, context: &DrawContext) -> () {
let DrawContext {
color,
style,
stroke_width,
..
} = context;
let path = self.get_path(context);
let mut paint = Paint::default();
let color = self
.color
.unwrap_or(color.unwrap_or(ColorU8::from_rgba(0, 0, 0, 255)));
let style = self.style.unwrap_or(style.unwrap_or(PaintStyle::Fill));
let stroke_width = self.stroke_width.unwrap_or(stroke_width.unwrap_or(1));
paint.set_color_rgba8(color.red(), color.green(), color.blue(), color.alpha());
match style {

fn draw(&self, pixmap: &mut Pixmap, context: &DrawContext) -> () {
let u8_array = base64::decode(&self.image).expect("base64 decode failed");
let mut bytes: Vec<u8> = Vec::new();
let mut img = ImageReader::new(Cursor::new(&u8_array as &[u8])).with_guessed_format().unwrap().decode().unwrap();
if let Some(blur) = self.blur {
img = img.blur(blur);
}
if let Some(grayscale) = self.grayscale {
if grayscale {
img = img.grayscale();
}
}
if let Some(brighten) = self.brighten {
img = img.brighten(brighten);
}
if let Some(invert) = self.invert {
if invert {
img.invert();
}
}

@meloalright
Copy link
Member Author

meloalright commented Aug 31, 2024

#[derive(Serialize, Deserialize, Debug)]
pub struct WASMPointsAttr {
points: Vec<[u32; 2]>,
color: Option<String>,
stroke_width: Option<u32>,
style: Option<String>,
}

WASMShapesAttr::P(WASMPointsAttr {
points,
color,
stroke_width,
style,
}) => {
let color = parse_color(color);
let style = parse_style(style);
self.0.set_shape_to_child(
id,
Shapes::P(Points {
points,
stroke_width,
color,
style,
}),
)
}

#[derive(Serialize, Deserialize, Debug)]
pub struct WASMImageAttr {
image: String,
x: i32,
y: i32,
width: u32,
height: u32,
blur: Option<f32>,
grayscale: Option<bool>,
brighten: Option<i32>,
invert: Option<bool>,
}

WASMShapesAttr::I(WASMImageAttr {
x,
y,
image,
width,
height,
blur,
grayscale,
brighten,
invert,
}) => self.0.set_shape_to_child(
id,
Shapes::I(Image {
image,
x,
y,
width,
height,
blur,
grayscale,
brighten,
invert,
}),
),

@meloalright
Copy link
Member Author

meloalright commented Aug 31, 2024

<template>
<v-sk-points :points="points" :strokeWidth="strokeWidth" :style="style" :color="color" />
</template>

points: {
type: Array as PropType<[number, number][]>,
required: true
},
strokeWidth: {
type: Number as PropType<number>,
required: false
},
style: {
type: String as PropType<'fill' | 'stroke'>,
required: false
},
color: {
type: String as PropType<string>,
required: false
},
},
});

<template >
<v-sk-image v-if="loaded" :image="base64String" :x="x" :y="y" :width="width" :height="height" :blur="blur" :grayscale="grayscale" :brighten="brighten" :invert="invert" />
</template>

blur: {
type: Number as PropType<number>,
required: false,
},
grayscale: {
type: Boolean as PropType<boolean>,
required: false,
},
brighten: {
type: Number as PropType<number>,
required: false,
},
invert: {
type: Boolean as PropType<boolean>,
required: false,
}
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant