|
|
|
|
@ -22,6 +22,8 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { |
|
|
|
|
private const val playerStrokeWidth = 8f |
|
|
|
|
private const val cardStrokeWidth = 8f |
|
|
|
|
|
|
|
|
|
private val backgroundColor = R.color.green_darker |
|
|
|
|
private val backgroundPaint = Paint() |
|
|
|
|
private val strokePaint = Paint() |
|
|
|
|
private val fillPaint = Paint() |
|
|
|
|
|
|
|
|
|
@ -32,6 +34,9 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { |
|
|
|
|
private val chipBorderPaint = Paint() |
|
|
|
|
|
|
|
|
|
fun configurePaints(context: Context) { |
|
|
|
|
|
|
|
|
|
backgroundPaint.color = context.getColor(backgroundColor) |
|
|
|
|
|
|
|
|
|
tablePaint.isAntiAlias = true |
|
|
|
|
tablePaint.style = Paint.Style.STROKE |
|
|
|
|
tablePaint.strokeWidth = tableStrokeWidth |
|
|
|
|
@ -65,36 +70,54 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { |
|
|
|
|
*/ |
|
|
|
|
fun initializeTable(config: ReplayerConfiguration, canvas: Canvas, context: Context) { |
|
|
|
|
|
|
|
|
|
canvas.drawColor(context.getColor(backgroundColor)) |
|
|
|
|
|
|
|
|
|
canvas.drawRoundRect(config.tableRect, config.tableCornerRadius, config.tableCornerRadius, this.tablePaint) |
|
|
|
|
cardTextPaint.textSize = config.cardSpecs.height * .38f |
|
|
|
|
this.cardTextPaint.textSize = config.cardSpecs.height * .38f |
|
|
|
|
|
|
|
|
|
val hh = config.handHistory |
|
|
|
|
for (i in 0 until hh.numberOfPlayers) { |
|
|
|
|
Timber.d("Getting player $i setup ") |
|
|
|
|
val playerSetup = hh.playerSetupForPosition(i) |
|
|
|
|
|
|
|
|
|
drawPlayerRectangle(i, playerSetup?.stack, false, config, canvas, context) |
|
|
|
|
drawPlayerRectangle(i,false, config, canvas, context) |
|
|
|
|
drawPositionAndStack(i, playerSetup?.stack, config, canvas, context) |
|
|
|
|
|
|
|
|
|
// Player portrait zone |
|
|
|
|
val circle = config.circleForPlayer(i) |
|
|
|
|
val radius = circle.radius |
|
|
|
|
canvas.drawCircle(circle.x, circle.y, radius, this.fillPaint) |
|
|
|
|
canvas.drawCircle(circle.x, circle.y, radius, this.strokePaint) |
|
|
|
|
val playerInitials = playerSetup?.player?.initials ?: RANDOM_PLAYER |
|
|
|
|
this.textPaint.textSize = radius |
|
|
|
|
canvas.drawText(playerInitials, circle.x, circle.y + radius * 0.4f, this.textPaint) |
|
|
|
|
drawPlayerCircle(i, config, canvas, context) |
|
|
|
|
|
|
|
|
|
drawDealerButton(config, canvas, context) |
|
|
|
|
|
|
|
|
|
drawCards(i, config, canvas, context) |
|
|
|
|
|
|
|
|
|
// val chipCircle = config.chipCircle(i) |
|
|
|
|
// val chipText = config.chipText(i) |
|
|
|
|
// drawChip(2000.0, chipText, chipCircle, canvas, context) |
|
|
|
|
|
|
|
|
|
drawStreet(Street.RIVER, config, canvas, context) |
|
|
|
|
|
|
|
|
|
// drawPot(100.0, 200.0, config, canvas, context) |
|
|
|
|
|
|
|
|
|
// Player picture |
|
|
|
|
playerSetup?.player?.picture?.let { picturePath -> |
|
|
|
|
val pictureBitmap = RoundedBitmapDrawableFactory.create(context.resources, picturePath) |
|
|
|
|
pictureBitmap.setAntiAlias(true) |
|
|
|
|
pictureBitmap.cornerRadius = circle.radius |
|
|
|
|
pictureBitmap.bitmap?.let { bitmap -> |
|
|
|
|
val pictureRect = RectF(circle.x - radius, circle.y - radius, circle.x + radius, circle.y + radius) |
|
|
|
|
canvas.drawBitmap(bitmap, null, pictureRect, null) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val blinds = config.actionList.filter { it.action.type?.isBlind ?: false } |
|
|
|
|
blinds.forEach { action -> |
|
|
|
|
action.action.amount?.let { amount -> |
|
|
|
|
drawChip(amount, action.positionIndex, config, canvas, context) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val pot = config.actionList.potSizeForStreet(action.street) |
|
|
|
|
val totalPot = config.actionList.totalPotSize(action.action.index + 1) |
|
|
|
|
|
|
|
|
|
drawPot(pot, totalPot, config, canvas, context) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// drawAction(action, false, config, canvas, context) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun drawDealerButton(config: ReplayerConfiguration, canvas: Canvas, context: Context) { |
|
|
|
|
|
|
|
|
|
// Dealer button |
|
|
|
|
val dealerCircle = config.dealerCircle |
|
|
|
|
this.fillPaint.color = context.getColor(R.color.red) |
|
|
|
|
@ -104,27 +127,19 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { |
|
|
|
|
this.textPaint.textSize = dealerCircle.radius |
|
|
|
|
canvas.drawText("D", dealerCircle.x, dealerCircle.y + this.textPaint.textSize / 3, this.textPaint) |
|
|
|
|
|
|
|
|
|
drawCards(i, config, canvas, context) |
|
|
|
|
|
|
|
|
|
// val blinds = config.actionList.filter { it.action.type?.isBlind ?: false } |
|
|
|
|
// blinds.forEach { action -> |
|
|
|
|
// drawAction(i, action, config, canvas, context) |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
val chipCircle = config.chipCircle(i) |
|
|
|
|
val chipText = config.chipText(i) |
|
|
|
|
drawChip(2000.0, chipText, chipCircle, canvas, context) |
|
|
|
|
|
|
|
|
|
drawStreet(Street.RIVER, config, canvas, context) |
|
|
|
|
|
|
|
|
|
drawPot(100.0, 200.0, config, canvas, context) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun drawChip(amount: Double, playerIndex: Int, config: ReplayerConfiguration, canvas: Canvas, context: Context) { |
|
|
|
|
val circle = config.chipCircle(playerIndex) |
|
|
|
|
val text = config.chipText(playerIndex) |
|
|
|
|
drawChip(amount, text, circle, canvas, context) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun drawChip(amount: Double, chipText: ReplayerConfiguration.TextPoint, chipCircle: ReplayerConfiguration.Circle, canvas: Canvas, context: Context) { |
|
|
|
|
|
|
|
|
|
clearText(chipText, canvas) |
|
|
|
|
clearCircle(chipCircle, canvas) |
|
|
|
|
|
|
|
|
|
this.fillPaint.color = context.getColor(R.color.green) |
|
|
|
|
canvas.drawCircle(chipCircle.x, chipCircle.y, chipCircle.radius, this.fillPaint) |
|
|
|
|
this.chipBorderPaint.color = context.getColor(R.color.white) |
|
|
|
|
@ -140,6 +155,18 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun clearText(textPoint: ReplayerConfiguration.TextPoint, canvas: Canvas) { |
|
|
|
|
this.clearZone(textPoint.toRect(), canvas) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun clearCircle(circle: ReplayerConfiguration.Circle, canvas: Canvas) { |
|
|
|
|
this.clearZone(circle.toRect(), canvas) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun clearZone(rect: RectF, canvas: Canvas) { |
|
|
|
|
canvas.drawRect(rect, this.backgroundPaint) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun drawCards(playerIndex: Int, config: ReplayerConfiguration, canvas: Canvas, context: Context) { |
|
|
|
|
|
|
|
|
|
val playerSetup = config.handHistory.playerSetupForPosition(playerIndex) |
|
|
|
|
@ -178,24 +205,52 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun drawAction(i: Int, action: ComputedAction, config: ReplayerConfiguration, canvas: Canvas, context: Context) { |
|
|
|
|
fun drawAction(action: ComputedAction, highlighted: Boolean = true, config: ReplayerConfiguration, canvas: Canvas, context: Context) { |
|
|
|
|
|
|
|
|
|
// show that action is on the player by highlighting |
|
|
|
|
drawPlayerRectangle(i, null, true, config, canvas, context) |
|
|
|
|
drawPlayerRectangle(action.positionIndex, highlighted, config, canvas, context) |
|
|
|
|
|
|
|
|
|
// show action name : call, bet, check... |
|
|
|
|
drawAction(i, action.action.type!!, config, canvas, context) |
|
|
|
|
drawAction(action.positionIndex, action.action.type!!, config, canvas, context) |
|
|
|
|
|
|
|
|
|
// show chips image + text, if applicable |
|
|
|
|
|
|
|
|
|
// show pot updates, if applicable |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun drawPlayerCircle(i: Int, config: ReplayerConfiguration, canvas: Canvas, context: Context) { |
|
|
|
|
|
|
|
|
|
val playerSetup = config.handHistory.playerSetupForPosition(i) |
|
|
|
|
|
|
|
|
|
// Player portrait zone |
|
|
|
|
val circle = config.circleForPlayer(i) |
|
|
|
|
val radius = circle.radius |
|
|
|
|
this.fillPaint.color = context.getColor(R.color.green_darker) |
|
|
|
|
canvas.drawCircle(circle.x, circle.y, radius, this.fillPaint) |
|
|
|
|
this.strokePaint.color = context.getColor(R.color.green) |
|
|
|
|
canvas.drawCircle(circle.x, circle.y, radius, this.strokePaint) |
|
|
|
|
val playerInitials = playerSetup?.player?.initials ?: RANDOM_PLAYER |
|
|
|
|
this.textPaint.textSize = radius |
|
|
|
|
canvas.drawText(playerInitials, circle.x, circle.y + radius * 0.4f, this.textPaint) |
|
|
|
|
|
|
|
|
|
// Player picture |
|
|
|
|
playerSetup?.player?.picture?.let { picturePath -> |
|
|
|
|
val pictureBitmap = RoundedBitmapDrawableFactory.create(context.resources, picturePath) |
|
|
|
|
pictureBitmap.setAntiAlias(true) |
|
|
|
|
pictureBitmap.cornerRadius = circle.radius |
|
|
|
|
pictureBitmap.bitmap?.let { bitmap -> |
|
|
|
|
val pictureRect = RectF(circle.x - radius, circle.y - radius, circle.x + radius, circle.y + radius) |
|
|
|
|
canvas.drawBitmap(bitmap, null, pictureRect, null) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* [i] is the player position in the hand |
|
|
|
|
*/ |
|
|
|
|
private fun drawPlayerRectangle(i: Int, stack: Double?, highlighted: Boolean, config: ReplayerConfiguration, canvas: Canvas, context: Context) { |
|
|
|
|
private fun drawPlayerRectangle(i: Int, highlighted: Boolean, config: ReplayerConfiguration, canvas: Canvas, context: Context) { |
|
|
|
|
|
|
|
|
|
val rect = config.stackRectForPlayer(i) |
|
|
|
|
val rectRadius = (rect.bottom - rect.top) / 4 |
|
|
|
|
@ -206,8 +261,9 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { |
|
|
|
|
strokePaint.color = context.getColor(R.color.green) |
|
|
|
|
canvas.drawRoundRect(config.stackRectForPlayer(i), rectRadius, rectRadius, this.strokePaint) |
|
|
|
|
|
|
|
|
|
drawPositionAndStack(i, stack, config, canvas, context) |
|
|
|
|
|
|
|
|
|
if (i == config.handHistory.heroIndex) { // refresh dealer button |
|
|
|
|
drawDealerButton(config, canvas, context) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun drawPositionAndStack(i: Int, stack: Double?, config: ReplayerConfiguration, canvas: Canvas, context: Context) { |
|
|
|
|
@ -243,12 +299,14 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun drawPot(pot: Double, totalPot: Double, config: ReplayerConfiguration, canvas: Canvas, context: Context) { |
|
|
|
|
private fun drawPot(pot: Double, totalPot: Double, config: ReplayerConfiguration, canvas: Canvas, context: Context) { |
|
|
|
|
|
|
|
|
|
drawChip(pot, config.potTextPoint, config.potChipCircle, canvas, context) |
|
|
|
|
val tpTextPoint = config.totalPotTextPoint |
|
|
|
|
this.textPaint.textSize = tpTextPoint.fontSize |
|
|
|
|
this.textPaint.color = context.getColor(R.color.white) |
|
|
|
|
|
|
|
|
|
clearText(config.totalPotTextPoint, canvas) |
|
|
|
|
canvas.drawText(totalPot.formatted, config.totalPotTextPoint.x, config.totalPotTextPoint.y, this.textPaint) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|