discourse/app/assets/javascripts/wizard/components/theme-preview.js.es6

90 lines
2.5 KiB
Plaintext
Raw Normal View History

2016-09-02 23:42:14 +08:00
import { observes } from 'ember-addons/ember-computed-decorators';
2016-09-17 04:12:56 +08:00
import {
createPreviewComponent,
darkLightDiff,
chooseBrighter,
2016-09-17 04:39:12 +08:00
LOREM
2016-09-17 04:12:56 +08:00
} from 'wizard/lib/preview';
2016-09-21 22:43:43 +08:00
export default createPreviewComponent(659, 320, {
2016-09-02 23:42:14 +08:00
logo: null,
2016-09-17 04:12:56 +08:00
avatar: null,
2016-09-02 23:42:14 +08:00
@observes('step.fieldsById.base_scheme_id.value')
2016-09-17 04:12:56 +08:00
themeChanged() {
this.triggerRepaint();
},
2016-09-02 23:42:14 +08:00
images() {
return { logo: this.get('wizard').getLogoUrl(), avatar: '/images/wizard/trout.png' };
2016-09-02 23:42:14 +08:00
},
2016-09-17 04:12:56 +08:00
paint(ctx, colors, width, height) {
const headerHeight = height * 0.15;
2016-09-02 23:42:14 +08:00
this.drawFullHeader(colors);
2016-09-02 23:42:14 +08:00
2016-09-17 04:12:56 +08:00
const margin = width * 0.02;
const avatarSize = height * 0.1;
2016-09-21 22:43:43 +08:00
const lineHeight = height / 19.0;
2016-09-02 23:42:14 +08:00
// Draw a fake topic
this.scaleImage(this.avatar, margin, headerHeight + (height * 0.17), avatarSize, avatarSize);
2016-09-02 23:42:14 +08:00
const titleFontSize = headerHeight / 44;
2016-09-02 23:42:14 +08:00
ctx.beginPath();
ctx.fillStyle = colors.primary;
ctx.font = `bold ${titleFontSize}em 'Arial'`;
2016-09-17 04:12:56 +08:00
ctx.fillText("Welcome to Discourse", margin, (height * 0.25));
2016-09-02 23:42:14 +08:00
2016-09-21 22:43:43 +08:00
const bodyFontSize = height / 440.0;
ctx.font = `${bodyFontSize}em 'Arial'`;
2016-09-02 23:42:14 +08:00
let line = 0;
const lines = LOREM.split("\n");
for (let i=0; i<10; i++) {
2016-09-21 22:43:43 +08:00
line = (height * 0.3) + (i * lineHeight);
2016-09-02 23:42:14 +08:00
ctx.fillText(lines[i], margin + avatarSize + margin, line);
}
// Reply Button
ctx.beginPath();
2016-09-21 22:43:43 +08:00
ctx.rect(width * 0.57, line + lineHeight, width * 0.1, height * 0.07);
2016-09-02 23:42:14 +08:00
ctx.fillStyle = colors.tertiary;
ctx.fill();
ctx.fillStyle = chooseBrighter(colors.primary, colors.secondary);
2016-09-21 22:43:43 +08:00
ctx.font = `${bodyFontSize}em 'Arial'`;
ctx.fillText("Reply", width * 0.595, line + (lineHeight * 1.85));
2016-09-02 23:42:14 +08:00
// Icons
2016-09-21 22:43:43 +08:00
ctx.font = `${bodyFontSize}em FontAwesome`;
2016-09-02 23:42:14 +08:00
ctx.fillStyle = colors.love;
2016-09-21 22:43:43 +08:00
ctx.fillText("\uf004", width * 0.48, line + (lineHeight * 1.8));
2016-09-02 23:42:14 +08:00
ctx.fillStyle = darkLightDiff(colors.primary, colors.secondary, 65, 55);
2016-09-21 22:43:43 +08:00
ctx.fillText("\uf040", width * 0.525, line + (lineHeight * 1.8));
2016-09-02 23:42:14 +08:00
// Draw Timeline
2016-09-17 04:12:56 +08:00
const timelineX = width * 0.8;
2016-09-02 23:42:14 +08:00
ctx.beginPath();
ctx.strokeStyle = colors.tertiary;
ctx.lineWidth = 0.5;
2016-09-17 04:12:56 +08:00
ctx.moveTo(timelineX, height * 0.3);
ctx.lineTo(timelineX, height * 0.6);
2016-09-02 23:42:14 +08:00
ctx.stroke();
// Timeline
ctx.beginPath();
ctx.strokeStyle = colors.tertiary;
ctx.lineWidth = 2;
2016-09-17 04:12:56 +08:00
ctx.moveTo(timelineX, height * 0.3);
ctx.lineTo(timelineX, height * 0.4);
2016-09-02 23:42:14 +08:00
ctx.stroke();
2016-09-21 22:43:43 +08:00
ctx.font = `Bold ${bodyFontSize}em Arial`;
2016-09-02 23:42:14 +08:00
ctx.fillStyle = colors.primary;
2016-09-17 04:12:56 +08:00
ctx.fillText("1 / 20", timelineX + margin, (height * 0.3) + (margin * 1.5));
2016-09-02 23:42:14 +08:00
}
});