Skip to content

Commit 4b5633d

Browse files
authored
Merge pull request #16 from adrientremblay/texture-aspect-ratio
Changed default scaling of textures (right panel) to keep aspect ratio
2 parents 4d87130 + 70ba28e commit 4b5633d

4 files changed

Lines changed: 7 additions & 5 deletions

File tree

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464

6565
<!-- Bootstrap JS -->
6666
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
67-
<script src="https://cdn.jsdelivr.net/npm/konva@8.4.3/konva.min.js"></script>
67+
<script src="https://cdn.jsdelivr.net/npm/konva@10.0.12/konva.min.js"></script>
6868
<script src="https://cdnjs.cloudflare.com/ajax/libs/numeric/1.2.6/numeric.min.js"></script>
6969

7070
<script src="scripts/jquery.min.js"></script>

scripts/polygonManager.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const PolygonManager = {
88
_id: Utils.generateId()
99
});
1010

11-
if (group && group._id) dirtyPolygons.add(group._id);
11+
if (group && group._id)
12+
dirtyPolygons.add(group._id);
1213

1314
// Get vertices - either from provided points or create default rectangle
1415
let vertices;

scripts/rightPanelManager.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ const RightPanelManager = {
5151

5252
// Transformer for selection
5353
const tr = new Konva.Transformer({
54-
keepRatio: false,
54+
keepRatio: true,
55+
shiftBehavior: 'inverted',
5556
rotateEnabled: true,
5657
rotationSnaps: [0, 90, 180, 270],
5758
rotationSnapTolerance: 5,

scripts/use-konva-snapping.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ const useKonvaSnapping = (params) => {
158158
const { snapRange } = defaultParams;
159159

160160
let { horizontal, vertical } = getSnappingPoints(e);
161-
if(!e.currentTarget.keepRatio() || (e.currentTarget.keepRatio() && !!!oppositeAnchors[e.currentTarget._movingAnchorName])){
161+
const keepRatio = !e.evt.shiftKey ? e.currentTarget.keepRatio() : ! e.currentTarget.keepRatio();
162+
if(!keepRatio || (keepRatio && !!!oppositeAnchors[e.currentTarget._movingAnchorName])){
162163
e.currentTarget.anchorDragBoundFunc((oldAbsPos, newAbsPos, event) => {
163-
//console.log(e.target)
164164

165165
Layer.find(".guid-line").forEach((line) => line.destroy());
166166
let bounds = { x: newAbsPos.x, y: newAbsPos.y };

0 commit comments

Comments
 (0)