@fmsim/machine 0.0.77 → 0.0.79

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,7 @@ import { MCSStatusMixin } from './features/mcs-status-mixin'
4
4
  import { LEGEND_CAPACITY, Legend } from './features/mcs-status-default'
5
5
  import { safeRound } from './utils/safe-round'
6
6
  import { getVaueOnRanges } from './utils/get-value-on-ranges'
7
+ import { roundRect } from './utils/round-rect'
7
8
 
8
9
  const NATURE: ComponentNature = {
9
10
  mutable: false,
@@ -143,7 +144,7 @@ export default class StockerCapacityBar extends MCSStatusMixin(RectPath(Shape))
143
144
  context.beginPath()
144
145
 
145
146
  context.fillStyle = fillStyle
146
- context.roundRect(0, 0, width, height, round)
147
+ roundRect(context, 0, 0, width, height, round)
147
148
 
148
149
  context.fill()
149
150
 
@@ -195,7 +196,7 @@ export default class StockerCapacityBar extends MCSStatusMixin(RectPath(Shape))
195
196
  context.setLineDash([])
196
197
  context.strokeStyle = strokeStyle
197
198
  context.lineWidth = lineWidth
198
- context.roundRect(0, 0, width, height, round)
199
+ roundRect(context, 0, 0, width, height, round)
199
200
  context.stroke()
200
201
 
201
202
  context.beginPath()
@@ -215,7 +216,7 @@ export default class StockerCapacityBar extends MCSStatusMixin(RectPath(Shape))
215
216
  context.beginPath()
216
217
 
217
218
  context.fillStyle = fillStyle
218
- context.roundRect(0, 0, width, height, round)
219
+ roundRect(context, 0, 0, width, height, round)
219
220
 
220
221
  context.fill()
221
222
 
@@ -267,7 +268,7 @@ export default class StockerCapacityBar extends MCSStatusMixin(RectPath(Shape))
267
268
  context.setLineDash([])
268
269
  context.strokeStyle = strokeStyle
269
270
  context.lineWidth = lineWidth
270
- context.roundRect(0, 0, width, height, round)
271
+ roundRect(context, 0, 0, width, height, round)
271
272
  context.stroke()
272
273
 
273
274
  context.beginPath()
@@ -0,0 +1,40 @@
1
+ import { safeRound } from './safe-round'
2
+
3
+ /**
4
+ * Draws a rounded rectangle using the current state of the canvas.
5
+ * If you omit the last three params, it will draw a rectangle
6
+ * outline with a 5 pixel border radius
7
+ * @param {CanvasRenderingContext2D} context
8
+ * @param {Number} x The top left x coordinate
9
+ * @param {Number} y The top left y coordinate
10
+ * @param {Number} width The width of the rectangle
11
+ * @param {Number} height The height of the rectangle
12
+ * @param {Number|Array<Number>} [radius = 0] The corner radius; It can also be an object
13
+ * to specify different radii for corners
14
+ * @param {Number} [radius.tl = 0] Top left
15
+ * @param {Number} [radius.tr = 0] Top right
16
+ * @param {Number} [radius.br = 0] Bottom right
17
+ * @param {Number} [radius.bl = 0] Bottom left
18
+ * @param {Boolean} [fill = false] Whether to fill the rectangle.
19
+ * @param {Boolean} [stroke = true] Whether to stroke the rectangle.
20
+ */
21
+ export function roundRect(
22
+ context: CanvasRenderingContext2D,
23
+ x: number,
24
+ y: number,
25
+ width: number,
26
+ height: number,
27
+ round: number = 0
28
+ ) {
29
+ round = safeRound(round, width, height)
30
+
31
+ if (round > 0) {
32
+ context.moveTo(x + round, y)
33
+ context.arcTo(x + width, y, x + width, y + height, round)
34
+ context.arcTo(x + width, y + height, x, y + height, round)
35
+ context.arcTo(x, y + height, x, y, round)
36
+ context.arcTo(x, y, x + width, y, round)
37
+ } else {
38
+ context.rect(x, y, width, height)
39
+ }
40
+ }
@@ -5,6 +5,7 @@ import { safeRound } from './utils/safe-round'
5
5
  import { getVaueOnRanges } from './utils/get-value-on-ranges'
6
6
  import { MCSZoneMixin, MCSZoneMixinProperties } from './features/mcs-zone-mixin'
7
7
  import MCSUnit from './mcs-unit'
8
+ import { roundRect } from './utils/round-rect'
8
9
 
9
10
  const NATURE: ComponentNature = {
10
11
  mutable: false,
@@ -129,7 +130,7 @@ export default class ZoneCapacityBar extends MCSZoneMixin(MCSUnit) {
129
130
  context.beginPath()
130
131
 
131
132
  context.fillStyle = fillStyle
132
- context.roundRect(0, 0, width, height, round)
133
+ roundRect(context, 0, 0, width, height, round)
133
134
 
134
135
  context.fill()
135
136
  context.stroke()
@@ -182,7 +183,7 @@ export default class ZoneCapacityBar extends MCSZoneMixin(MCSUnit) {
182
183
  context.setLineDash([])
183
184
  context.strokeStyle = strokeStyle
184
185
  context.lineWidth = lineWidth
185
- context.roundRect(0, 0, width, height, round)
186
+ roundRect(context, 0, 0, width, height, round)
186
187
  context.stroke()
187
188
 
188
189
  context.beginPath()
@@ -202,7 +203,7 @@ export default class ZoneCapacityBar extends MCSZoneMixin(MCSUnit) {
202
203
  context.beginPath()
203
204
 
204
205
  context.fillStyle = fillStyle
205
- context.roundRect(0, 0, width, height, round)
206
+ roundRect(context, 0, 0, width, height, round)
206
207
 
207
208
  context.fill()
208
209
 
@@ -254,7 +255,7 @@ export default class ZoneCapacityBar extends MCSZoneMixin(MCSUnit) {
254
255
  context.setLineDash([])
255
256
  context.strokeStyle = strokeStyle
256
257
  context.lineWidth = lineWidth
257
- context.roundRect(0, 0, width, height, round)
258
+ roundRect(context, 0, 0, width, height, round)
258
259
  context.stroke()
259
260
 
260
261
  context.beginPath()