Improves chip placement

hh
Laurent 5 years ago
parent 608dd60136
commit 2270304b5e
  1. 9
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerAnimator.kt
  2. 2
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/TableDrawer.kt
  3. 31
      app/src/main/java/net/pokeranalytics/android/util/MathUtils.kt

@ -296,13 +296,18 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) {
val top = rectCenterY - this.playerItemsHeight / 2 val top = rectCenterY - this.playerItemsHeight / 2
val right = rectCenterX + this.playerItemsWidth / 2 val right = rectCenterX + this.playerItemsWidth / 2
val bottom = rectCenterY + this.playerItemsHeight / 2 val bottom = rectCenterY + this.playerItemsHeight / 2
this.playerStackRects.add(RectF(left, top, right, bottom)) val pRect = RectF(left, top, right, bottom)
this.playerStackRects.add(pRect)
// val chipCircleY = rectCenterY + chipYOffset - chipTextYOffsetCoef * chipRadius // val chipCircleY = rectCenterY + chipYOffset - chipTextYOffsetCoef * chipRadius
val line = MathUtils.Line(point.x, point.y, tableRect.centerX(), tableRect.centerY()) val line = MathUtils.Line(point.x, point.y, tableRect.centerX(), tableRect.centerY())
val chipPoint = line.pointForDistance(this.playerItemsWidth * 0.8f) val prp = line.intersects(pRect) ?: throw PAIllegalStateException("should not happen")
val boxToCenterLine = MathUtils.Line(prp.x, prp.y, tableRect.centerX(), tableRect.centerY())
val boxToChipDistance = if (bottomOriented) 3 * chipRadius else 2 * chipRadius // because the chip text needs space
val chipPoint = boxToCenterLine.pointForDistance(boxToChipDistance)
this.chipCircles.add(Circle(chipPoint.x, chipPoint.y, chipRadius)) this.chipCircles.add(Circle(chipPoint.x, chipPoint.y, chipRadius))

@ -445,8 +445,10 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
val cards = animator.handHistory.cardsForStreet(street) val cards = animator.handHistory.cardsForStreet(street)
animator.boardCardRects.take(street.totalBoardCards).forEachIndexed { index, rectF -> animator.boardCardRects.take(street.totalBoardCards).forEachIndexed { index, rectF ->
if (index < cards.size) {
drawCard(cards[index], rectF, animator, canvas, context) drawCard(cards[index], rectF, animator, canvas, context)
} }
}
} }

@ -26,6 +26,37 @@ class MathUtils {
val slope: Float val slope: Float
get() { return (x2 - x1) / (y2 - y1) } get() { return (x2 - x1) / (y2 - y1) }
private fun intersects(line: Line): PointF? {
val s1_x = this.x2 - this.x1
val s1_y = this.y2 - this.y1
val s2_x = line.x2 - line.x1
val s2_y = line.y2 - line.y1
val s = (-s1_y * (this.x1 - line.x1) + s1_x * (this.y1 - line.y1)) / (-s2_x * s1_y + s1_x * s2_y);
val t = ( s2_x * (this.y1 - line.y1) - s2_y * (this.x1 - line.x1)) / (-s2_x * s1_y + s1_x * s2_y);
return if (s >= 0 && s <= 1 && t >= 0 && t <= 1) {
PointF(this.x1 + (t * s1_x), this.y1 + (t * s1_y))
} else {
null
}
}
fun intersects(rect: RectF): PointF? {
val p1 = this.intersects(Line(rect.left, rect.top, rect.right, rect.top))
if (p1 != null) return p1
val p2 = this.intersects(Line(rect.right, rect.top, rect.right, rect.bottom))
if (p2 != null) return p2
val p3 = this.intersects(Line(rect.left, rect.bottom, rect.right, rect.bottom))
if (p3 != null) return p3
val p4 = this.intersects(Line(rect.left, rect.top, rect.left, rect.bottom))
if (p4 != null) return p4
return null
}
} }
private class EllipseQuarter(val x1: Float, val y1: Float, val xRadius: Float, val yRadius: Float, val direction: Direction): Path { private class EllipseQuarter(val x1: Float, val y1: Float, val xRadius: Float, val yRadius: Float, val direction: Direction): Path {

Loading…
Cancel
Save