Skip to content

Commit

Permalink
Pretty much finished UI. Switched around right click and left click f…
Browse files Browse the repository at this point in the history
…or select/pan. Also added zooming via scroll
  • Loading branch information
basimkhajwal committed Sep 13, 2017
1 parent 60f1be0 commit f864b5e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ An intelligent tool for mind mapping ideas using Wikipedia data

#### TODO

User Interface:
- Fix file saving interface (duplicate files, proper extensions, etc.)
- Add zoom by mouse scroll onto Main View

Suggestions:
- ...

Expand Down
12 changes: 9 additions & 3 deletions src/main/kotlin/wikimap/views/MainView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ class MainView : View("WikiMap") {
clickX = event.x
clickY = event.y

if (event.button == MouseButton.SECONDARY) {
selectNodes()
if (event.button != MouseButton.SECONDARY) {
oldCenter = gridView.gridCenter
} else {
selectNodes()
mindMapView.requestFocus()
rectangleSelect.x = event.x
rectangleSelect.y = event.y
Expand All @@ -129,7 +129,7 @@ class MainView : View("WikiMap") {
}

mindMapView.onMouseDragged = EventHandler { event ->
if (event.button == MouseButton.SECONDARY) {
if (event.button != MouseButton.SECONDARY) {
val dx = (event.x - clickX) / gridView.root.width
val dy = (event.y - clickY) / gridView.root.height
gridView.gridCenter = Pair(oldCenter.first + dx, oldCenter.second + dy)
Expand Down Expand Up @@ -159,6 +159,12 @@ class MainView : View("WikiMap") {
mousePointerY = event.y
}

mindMapView.onScroll = EventHandler { event ->
gridView.spacing = (gridView.spacing * (1 + event.deltaY / 100.0)).toInt()
gridView.spacing = maxOf(15, minOf(60, gridView.spacing))
refresh()
}

mindMapView.isFocusTraversable = true
loadModel(mindMap)
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/wikimap/views/NodeView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,21 @@ class NodeView(val main: MainView, val model: MindMapNode, val isSuggestion: Boo
CornerRadii.EMPTY, BorderWidths(1.0)
))

private fun epsilonEq(a: Double, b: Double, epsilon: Double = 1e-5) = a > b-epsilon && a < b+epsilon

private val resizeListener = object : DragResizeMod.OnDragResizeEventListener {
override fun onResize(n: Node?, x: Double, y: Double, h: Double, w: Double) {
val (nx, ny) = main.gridView.toGridCoords(x, y)
val cx = Math.round(nx).toInt()
val cy = Math.round(ny).toInt()

if (nx != model.x.toDouble()) {
if (!epsilonEq(nx, model.x.toDouble())) {
model.width = (model.x + model.width) - cx
} else {
model.width = Math.round(w / main.gridView.spacing).toInt()
}

if (ny != model.y.toDouble()) {
if (!epsilonEq(ny, model.y.toDouble())) {
model.height = (model.y + model.height) - cy
} else {
model.height = Math.round(h / main.gridView.spacing).toInt()
Expand Down

0 comments on commit f864b5e

Please sign in to comment.