|
1 | 1 | import { css, html, LitElement } from 'lit'; |
2 | | -import { customElement } from 'lit/decorators.js'; |
| 2 | +import { customElement, property } from 'lit/decorators.js'; |
3 | 3 | import { ElementPin, spi } from './pin'; |
4 | 4 |
|
5 | 5 | @customElement('wokwi-ili9341') |
6 | 6 | export class ILI9341Element extends LitElement { |
7 | 7 | readonly screenWidth = 240; |
8 | 8 | readonly screenHeight = 320; |
9 | 9 |
|
| 10 | + @property() flipHorizontal = false; |
| 11 | + @property() flipVertical = false; |
| 12 | + |
10 | 13 | readonly pinInfo: ElementPin[] = [ |
11 | 14 | { name: 'VCC', x: 48.3, y: 287.2, signals: [{ type: 'power', signal: 'VCC' }] }, |
12 | 15 | { name: 'GND', x: 57.9012, y: 287.2, signals: [{ type: 'power', signal: 'GND' }] }, |
@@ -49,7 +52,11 @@ export class ILI9341Element extends LitElement { |
49 | 52 | } |
50 | 53 |
|
51 | 54 | render() { |
52 | | - const { screenWidth, screenHeight } = this; |
| 55 | + const { screenWidth, screenHeight, flipHorizontal, flipVertical } = this; |
| 56 | + const flip = flipHorizontal || flipVertical; |
| 57 | + const scaleX = flipHorizontal ? -1 : 1; |
| 58 | + const scaleY = flipVertical ? -1 : 1; |
| 59 | + const canvasStyle = flip ? `transform: scaleX(${scaleX}) scaleY(${scaleY});` : ''; |
53 | 60 | return html` |
54 | 61 | <div class="container"> |
55 | 62 | <svg |
@@ -112,7 +119,12 @@ export class ILI9341Element extends LitElement { |
112 | 119 | <tspan x="14.2" y="4.3" font-size="4.6px">ILI9341</tspan> |
113 | 120 | </text> |
114 | 121 | </svg> |
115 | | - <canvas width="${screenWidth}" height="${screenHeight}" class="pixelated"></canvas> |
| 122 | + <canvas |
| 123 | + width="${screenWidth}" |
| 124 | + height="${screenHeight}" |
| 125 | + class="pixelated" |
| 126 | + style=${canvasStyle} |
| 127 | + ></canvas> |
116 | 128 | </div> |
117 | 129 | `; |
118 | 130 | } |
|
0 commit comments