q5 2.7.6 → 2.9.0

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.
@@ -97,29 +97,6 @@ fn fragmentMain(@location(0) color: vec4f) -> @location(0) vec4f {
97
97
  vertIndex = i;
98
98
  };
99
99
 
100
- const addTri = (x1, y1, x2, y2, x3, y3, ci, ti) => {
101
- let v = vertexStack,
102
- i = vertIndex;
103
-
104
- v[i++] = x1;
105
- v[i++] = y1;
106
- v[i++] = ci;
107
- v[i++] = ti;
108
-
109
- v[i++] = x2;
110
- v[i++] = y2;
111
- v[i++] = ci;
112
- v[i++] = ti;
113
-
114
- v[i++] = x3;
115
- v[i++] = y3;
116
- v[i++] = ci;
117
- v[i++] = ti;
118
-
119
- vertIndex = i;
120
- drawStack.push(0, 3);
121
- };
122
-
123
100
  const addRect = (x1, y1, x2, y2, x3, y3, x4, y4, ci, ti) => {
124
101
  let v = vertexStack,
125
102
  i = vertIndex;
@@ -203,21 +180,40 @@ fn fragmentMain(@location(0) color: vec4f) -> @location(0) vec4f {
203
180
  if ($._doStroke) {
204
181
  ci = $._strokeIndex;
205
182
 
206
- // outer rectangle coordinates
183
+ // stroke weight adjustment
207
184
  let sw = $._strokeWeight / 2;
208
- let to = t + sw,
209
- bo = b - sw,
210
- lo = l - sw,
211
- ro = r + sw;
212
-
213
- // stroke is simply a bigger rectangle drawn first
214
- addRect(lo, to, ro, to, ro, bo, lo, bo, ci, ti);
215
-
216
- // inner rectangle coordinates
217
- t -= sw;
218
- b += sw;
219
- l += sw;
220
- r -= sw;
185
+
186
+ if ($._doFill) {
187
+ // existing behavior: draw stroke as one big rectangle
188
+ let to = t + sw,
189
+ bo = b - sw,
190
+ lo = l - sw,
191
+ ro = r + sw;
192
+
193
+ // draw stroke rectangle
194
+ addRect(lo, to, ro, to, ro, bo, lo, bo, ci, ti);
195
+
196
+ // adjust inner rectangle coordinates
197
+ t -= sw;
198
+ b += sw;
199
+ l += sw;
200
+ r -= sw;
201
+ } else {
202
+ // new behavior: draw stroke as four rectangles (sides)
203
+ let lsw = l - sw,
204
+ rsw = r + sw,
205
+ tsw = t + sw,
206
+ bsw = b - sw,
207
+ lpsw = l + sw,
208
+ rpsw = r - sw,
209
+ tpsw = t - sw,
210
+ bpsw = b + sw;
211
+
212
+ addRect(lsw, tpsw, rsw, tpsw, rsw, tsw, lsw, tsw, ci, ti); // top
213
+ addRect(lsw, bsw, rsw, bsw, rsw, bpsw, lsw, bpsw, ci, ti); // bottom
214
+ addRect(lsw, tsw, lpsw, tsw, lpsw, bsw, lsw, bsw, ci, ti); // left
215
+ addRect(rpsw, tsw, rsw, tsw, rsw, bsw, rpsw, bsw, ci, ti); // right
216
+ }
221
217
  }
222
218
 
223
219
  if ($._doFill) {
@@ -392,11 +388,16 @@ fn fragmentMain(@location(0) color: vec4f) -> @location(0) vec4f {
392
388
  $.vertex(x1, y1);
393
389
  $.vertex(x2, y2);
394
390
  $.vertex(x3, y3);
395
- $.endShape();
391
+ $.endShape(true);
396
392
  };
397
393
 
398
394
  $.quad = (x1, y1, x2, y2, x3, y3, x4, y4) => {
399
- addRect(x1, y1, x2, y2, x3, y3, x4, y4, $._fillIndex, $._transformIndex);
395
+ $.beginShape();
396
+ $.vertex(x1, y1);
397
+ $.vertex(x2, y2);
398
+ $.vertex(x3, y3);
399
+ $.vertex(x4, y4);
400
+ $.endShape(true);
400
401
  };
401
402
 
402
403
  $.background = (r, g, b, a) => {
@@ -89,7 +89,7 @@ fn fragmentMain(@location(0) texCoord: vec2f) -> @location(0) vec4f {
89
89
  entryPoint: 'fragmentMain',
90
90
  targets: [{ format: 'bgra8unorm', blend: $.blendConfigs.normal }]
91
91
  },
92
- primitive: { topology: 'triangle-list' },
92
+ primitive: { topology: 'triangle-strip', stripIndexFormat: 'uint32' },
93
93
  multisample: { count: 4 }
94
94
  };
95
95
 
@@ -121,7 +121,6 @@ fn fragmentMain(@location(0) texCoord: vec2f) -> @location(0) vec4f {
121
121
  {
122
122
  texture,
123
123
  colorSpace: $.canvas.colorSpace
124
- // premultipliedAlpha: true
125
124
  },
126
125
  textureSize
127
126
  );
@@ -153,6 +152,11 @@ fn fragmentMain(@location(0) texCoord: vec2f) -> @location(0) vec4f {
153
152
  const img = new Image();
154
153
  img.crossOrigin = 'Anonymous';
155
154
  img.onload = () => {
155
+ // calculate the default width and height that the image
156
+ // should be drawn at if the user doesn't specify a display size
157
+ img.defaultWidth = img.width * $._defaultImageScale;
158
+ img.defaultHeight = img.height * $._defaultImageScale;
159
+
156
160
  $._createTexture(img);
157
161
  q._preloadCount--;
158
162
  };
@@ -169,8 +173,8 @@ fn fragmentMain(@location(0) texCoord: vec2f) -> @location(0) vec4f {
169
173
  if ($._matrixDirty) $._saveMatrix();
170
174
  let ti = $._transformIndex;
171
175
 
172
- w ??= img.width / $._pixelDensity;
173
- h ??= img.height / $._pixelDensity;
176
+ w ??= img.defaultWidth;
177
+ h ??= img.defaultHeight;
174
178
 
175
179
  let [l, r, t, b] = $._calcBox(x, y, w, h, $._imageMode);
176
180
 
@@ -179,8 +183,6 @@ fn fragmentMain(@location(0) texCoord: vec2f) -> @location(0) vec4f {
179
183
  l, t, 0, 0, ti,
180
184
  r, t, 1, 0, ti,
181
185
  l, b, 0, 1, ti,
182
- r, t, 1, 0, ti,
183
- l, b, 0, 1, ti,
184
186
  r, b, 1, 1, ti
185
187
  );
186
188