2019-11-08 05:38:28 +08:00
|
|
|
import { observes } from "discourse-common/utils/decorators";
|
2016-09-22 04:09:18 +08:00
|
|
|
import { createPreviewComponent, drawHeader } from "wizard/lib/preview";
|
2016-09-17 04:12:56 +08:00
|
|
|
|
|
|
|
export default createPreviewComponent(400, 100, {
|
|
|
|
image: null,
|
|
|
|
|
|
|
|
@observes("field.value")
|
|
|
|
imageChanged() {
|
|
|
|
this.reload();
|
|
|
|
},
|
|
|
|
|
2016-09-22 04:09:18 +08:00
|
|
|
images() {
|
|
|
|
return { image: this.get("field.value") };
|
2016-09-17 04:12:56 +08:00
|
|
|
},
|
|
|
|
|
2020-08-31 18:14:09 +08:00
|
|
|
paint(ctx, colors, font, width, height) {
|
2016-09-17 04:12:56 +08:00
|
|
|
const headerHeight = height / 2;
|
|
|
|
|
|
|
|
drawHeader(ctx, colors, width, headerHeight);
|
|
|
|
|
|
|
|
const image = this.image;
|
|
|
|
const headerMargin = headerHeight * 0.2;
|
|
|
|
|
|
|
|
const imageHeight = headerHeight - headerMargin * 2;
|
|
|
|
const ratio = imageHeight / image.height;
|
2016-09-22 04:48:48 +08:00
|
|
|
this.scaleImage(
|
|
|
|
image,
|
|
|
|
headerMargin,
|
|
|
|
headerMargin,
|
|
|
|
image.width * ratio,
|
|
|
|
imageHeight
|
|
|
|
);
|
2016-09-17 04:12:56 +08:00
|
|
|
|
2020-08-31 18:14:09 +08:00
|
|
|
this.drawPills(colors, font, height / 2);
|
2016-09-17 04:12:56 +08:00
|
|
|
},
|
|
|
|
});
|