Skip to content

Commit

Permalink
refactor SelectionArea (#1642)
Browse files Browse the repository at this point in the history
  • Loading branch information
dyeh123 authored Oct 5, 2020
1 parent 37c1f47 commit a1f4ac9
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions app/src/main/kotlin/io/treehouses/remote/SSH/beans/SelectionArea.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ class SelectionArea {
isSelectingOrigin = true
}

/**
* @param columns
* @param rows
*/
fun setBounds(columns: Int, rows: Int) {
maxColumns = columns - 1
maxRows = rows - 1
}
// /**
// * @param columns
// * @param rows
// */
// fun setBounds(columns: Int, rows: Int) {
// maxColumns = columns - 1
// maxRows = rows - 1
// }

private fun checkBounds(value: Int, max: Int): Int {
return if (value < 0) 0 else if (value > max) max else value
Expand All @@ -60,20 +60,26 @@ class SelectionArea {
}

fun decrementRow() {
if (isSelectingOrigin) setTop(top - 1) else setBottom(bottom - 1)
changeAttr("row", -1)
}

fun incrementRow() {
if (isSelectingOrigin) setTop(top + 1) else setBottom(bottom + 1)
changeAttr("row", 1)
}

fun setRow(row: Int) {
if (isSelectingOrigin) setTop(row) else setBottom(row)
private fun setTop(top: Int) {
setInverses("top", top, maxRows)
}

private fun setTop(top: Int) {
bottom = checkBounds(top, maxRows)
this.top = bottom
private fun setInverses(kind: String, value: Int, max: Int) {
val result = checkBounds(value, max)
if (kind == "top") {
bottom = result
this.top = bottom
} else {
right = result
this.left = right
}
}

fun getTop(): Int {
Expand All @@ -89,20 +95,22 @@ class SelectionArea {
}

fun decrementColumn() {
if (isSelectingOrigin) setLeft(left - 1) else setRight(right - 1)
changeAttr("col", -1)
}

fun incrementColumn() {
if (isSelectingOrigin) setLeft(left + 1) else setRight(right + 1)
changeAttr("col", 1)
}

fun setColumn(column: Int) {
if (isSelectingOrigin) setLeft(column) else setRight(column)
private fun changeAttr(type: String, change: Int) {
if (isSelectingOrigin && type == "row") setTop(top + change)
else if (isSelectingOrigin && type == "col") setLeft(left + change)
else if (type == "row") setBottom(bottom + change)
else setRight(right + change)
}

private fun setLeft(left: Int) {
right = checkBounds(left, maxColumns)
this.left = right
setInverses("left", left, maxColumns)
}

fun getLeft(): Int {
Expand Down

0 comments on commit a1f4ac9

Please sign in to comment.