-
Notifications
You must be signed in to change notification settings - Fork 537
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added interactive resizing for rectangles
- Loading branch information
Showing
16 changed files
with
171 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
// TODO: make this stricter (could give false positive on some degenerate paths) | ||
export function pathIsRectangle(ids, arcs) { | ||
var bbox = arcs.getSimpleShapeBounds(ids).toArray(); | ||
var iter = arcs.getShapeIter(ids); | ||
while (iter.hasNext()) { | ||
if (iter.x != bbox[0] && iter.x != bbox[2] || | ||
iter.y != bbox[1] && iter.y != bbox[3]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
export function bboxToCoords(bbox) { | ||
return [[bbox[0], bbox[1]], [bbox[0], bbox[3]], [bbox[2], bbox[3]], | ||
[bbox[2], bbox[1]], [bbox[0], bbox[1]]]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { HighlightBox } from './gui-highlight-box'; | ||
import { internal } from './gui-core'; | ||
import { setRectangleCoords } from './gui-display-utils'; | ||
|
||
export function RectangleControl(gui, hit) { | ||
var box = new HighlightBox(gui, {persistent: true, handles: true, classname: 'rectangles'}); | ||
var _on = false; | ||
var dragInfo; | ||
|
||
gui.addMode('rectangle_tool', turnOn, turnOff); | ||
|
||
gui.on('interaction_mode_change', function(e) { | ||
if (e.mode === 'rectangles') { | ||
gui.enterMode('rectangle_tool'); | ||
} else if (gui.getMode() == 'rectangle_tool') { | ||
gui.clearMode(); | ||
} | ||
}); | ||
|
||
hit.on('change', function(e) { | ||
if (!_on) return; | ||
// TODO: handle multiple hits (see gui-inspection-control2) | ||
var id = e.id; | ||
if (e.id > -1 && e.pinned) { | ||
var target = hit.getHitTarget(); | ||
var path = target.layer.shapes[e.id][0]; | ||
var bbox = target.arcs.getSimpleShapeBounds(path).toArray(); | ||
box.setDataCoords(bbox); | ||
dragInfo = { | ||
id: e.id, | ||
target: target, | ||
ids: [], | ||
points: [] | ||
}; | ||
var iter = target.arcs.getShapeIter(path); | ||
while (iter.hasNext()) { | ||
dragInfo.points.push([iter.x, iter.y]); | ||
dragInfo.ids.push(iter._arc.i); | ||
} | ||
gui.container.findChild('.map-layers').classed('dragging', true); | ||
|
||
} else if (dragInfo) { | ||
// TODO: handle this event: add undo/redo states | ||
gui.dispatchEvent('rectangle_dragend', dragInfo); | ||
gui.container.findChild('.map-layers').classed('dragging', false); | ||
reset(); | ||
} else { | ||
box.hide(); | ||
} | ||
|
||
}); | ||
|
||
box.on('handle_drag', function(e) { | ||
if (!_on || !dragInfo) return; | ||
var coords = internal.bboxToCoords(box.getDataCoords()); | ||
setRectangleCoords(dragInfo.target, dragInfo.ids, coords); | ||
gui.dispatchEvent('map-needs-refresh'); | ||
}); | ||
|
||
function turnOn() { | ||
box.turnOn(); | ||
_on = true; | ||
} | ||
|
||
function turnOff() { | ||
box.turnOff(); | ||
if (gui.interaction.getMode() == 'rectangles') { | ||
// mode change was not initiated by interactive menu -- turn off interactivity | ||
gui.interaction.turnOff(); | ||
} | ||
_on = false; | ||
reset(); | ||
} | ||
|
||
function reset() { | ||
box.hide(); | ||
dragInfo = null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters