From f131f836ed2b4652aa24937bb254ae00bab7c1ef Mon Sep 17 00:00:00 2001 From: Pierrot Date: Wed, 1 May 2019 10:08:01 +0200 Subject: [PATCH] Improve the dot indicator rendering, and change the default values. It fixes the clipping seen with hairline stroking (width=0 or 1). --- .../lightning_launcher/data/PageIndicator.java | 4 ++-- .../views/item/PageIndicatorView.java | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/llx/core/src/main/java/net/pierrox/lightning_launcher/data/PageIndicator.java b/app/llx/core/src/main/java/net/pierrox/lightning_launcher/data/PageIndicator.java index 0c9973a..c18e601 100644 --- a/app/llx/core/src/main/java/net/pierrox/lightning_launcher/data/PageIndicator.java +++ b/app/llx/core/src/main/java/net/pierrox/lightning_launcher/data/PageIndicator.java @@ -35,8 +35,8 @@ public class PageIndicator extends Item implements ShortcutConfigStylable { public int dotsMarginX = 10; public int dotsMarginY = 10; public int dotsOuterRadius = 8; - public int dotsInnerRadius = 6; - public int dotsOuterStrokeWidth = 0; + public int dotsInnerRadius = 5; + public int dotsOuterStrokeWidth = 2; public int dotsOuterColor = Color.WHITE; public int dotsInnerColor = Color.WHITE; public String rawFormat = "%1$+5.0f %2$+5.0f | %3$6.3f"; diff --git a/app/llx/core/src/main/java/net/pierrox/lightning_launcher/views/item/PageIndicatorView.java b/app/llx/core/src/main/java/net/pierrox/lightning_launcher/views/item/PageIndicatorView.java index 8f02710..96281ca 100644 --- a/app/llx/core/src/main/java/net/pierrox/lightning_launcher/views/item/PageIndicatorView.java +++ b/app/llx/core/src/main/java/net/pierrox/lightning_launcher/views/item/PageIndicatorView.java @@ -142,7 +142,8 @@ public class PageIndicatorView extends ItemView { protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { final int px = mMaxX - mMinX; final int py = mMaxY - mMinY; - float radius = Math.max(mPageIndicator.dotsInnerRadius, mPageIndicator.dotsOuterRadius + mPageIndicator.dotsOuterStrokeWidth /2); + float stroke_width = mPageIndicator.dotsOuterStrokeWidth == 0 ? 1 : mPageIndicator.dotsOuterStrokeWidth; + float radius = Math.max(mPageIndicator.dotsInnerRadius, mPageIndicator.dotsOuterRadius + stroke_width); int width = (int) Math.ceil((radius * 2) * px + mPageIndicator.dotsMarginX * (px>0 ? px-1 : 0)); int height = (int) Math.ceil((radius * 2) * py + mPageIndicator.dotsMarginY * (py>0 ? py-1 : 0)); setMeasuredDimension(width, height); @@ -161,7 +162,13 @@ public class PageIndicatorView extends ItemView { return; } - float radius = Math.max(mPageIndicator.dotsInnerRadius, mPageIndicator.dotsOuterRadius + mPageIndicator.dotsOuterStrokeWidth /2); + + float stroke_width = mPageIndicator.dotsOuterStrokeWidth == 0 ? 1 : mPageIndicator.dotsOuterStrokeWidth; + + // compute the anti aliasing delta : shift the drawing so that the outer circle is always perfectly aligned + float ad = (stroke_width % 2) == 0 ? 0 : 0.5f; + + float radius = Math.max(mPageIndicator.dotsInnerRadius, mPageIndicator.dotsOuterRadius + stroke_width); float scaled_cont_x = -(mContainerX-mContainerWidth/2)/mContainerScale; float scaled_cont_y = -(mContainerY-mContainerHeight/2)/mContainerScale; float pos_x_f = scaled_cont_x / mContainerWidth - 0.5f; @@ -172,7 +179,7 @@ public class PageIndicatorView extends ItemView { for(int y=mMinY; y mMaxX-1) { pos_x_f = x - mMaxX + pos_x_f; @@ -189,7 +196,7 @@ public class PageIndicatorView extends ItemView { if(dx>1) dx=1; dx = 1-dx; if(dy>1) dy=1; dy = 1-dy; mInnerCirclePaint.setAlpha((int) (255*dx*dy*max_alpha)); - canvas.drawCircle(cx, cy, mPageIndicator.dotsInnerRadius, mInnerCirclePaint); + canvas.drawCircle(cx+ad, cy+ad, mPageIndicator.dotsInnerRadius, mInnerCirclePaint); cx += radius*2 + mPageIndicator.dotsMarginX; }