Skip to content

Commit 2347c5e

Browse files
committed
Fixed drawShadow bug
1 parent 4078eac commit 2347c5e

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

CodenameOne/src/com/codename1/ui/Graphics.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,9 @@ public void fillRect(int x, int y, int width, int height) {
383383
impl.fillRect(nativeGraphics, xTranslate + x, yTranslate + y, width, height);
384384
}
385385

386+
/**
387+
* @deprecated this method should have been internals
388+
*/
386389
public void drawShadow(Image img, int x, int y, int offsetX, int offsetY, int blurRadius, int spreadRadius, int color, float opacity) {
387390
impl.drawShadow(nativeGraphics, img.getImage(), xTranslate + x, yTranslate + y, offsetX, offsetY, blurRadius, spreadRadius, color, opacity);
388391
}

Ports/Android/src/com/codename1/impl/android/AndroidGraphics.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009 Pader-Sync Ltd. & Co. KG. All Rights Reserved.
2+
* Copyright 2009 Pader-Sync Ltd. & Co. KG. All Rights Reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -144,18 +144,18 @@ public void drawImage(Object img, int x, int y) {
144144
}
145145

146146
public void drawShadow(Object image, int x, int y, int offsetX, int offsetY, int blurRadius, int spreadRadius, int color, float opacity) {
147-
if (image == null) return;
147+
if (image == null || canvas == null) {
148+
return;
149+
}
148150
Bitmap bmp = (Bitmap)image;
149151
float bmpW = bmp.getWidth();
150152
float bmpH = bmp.getHeight();
151-
if (bmpW == 0 || bmpH == 0) return;
152-
153-
153+
if (bmpW == 0 || bmpH == 0) {
154+
return;
155+
}
154156

155157
Bitmap scaledBmp = Bitmap.createScaledBitmap(bmp, bmp.getWidth() + 2 * spreadRadius, bmp.getHeight() + 2 * spreadRadius, false);
156-
157158
Paint alphaPaint = new Paint();
158-
159159
alphaPaint.setMaskFilter(new BlurMaskFilter(blurRadius, BlurMaskFilter.Blur.NORMAL));
160160
int[] offsetXY = new int[2];
161161
Bitmap bmAlpha = scaledBmp.extractAlpha(alphaPaint, offsetXY);
@@ -164,13 +164,11 @@ public void drawShadow(Object image, int x, int y, int offsetX, int offsetY, int
164164
applyTransform();
165165
Paint shadowPaint = new Paint();
166166
int alpha = (int)Math.floor(opacity * 255);
167-
shadowPaint.setColor((0xff000000 | color));
168-
shadowPaint.setAlpha((int)Math.floor(opacity * 255));
169-
167+
shadowPaint.setColor(0xff000000 | color);
168+
shadowPaint.setAlpha(alpha);
170169
canvas.drawBitmap(bmAlpha, x + offsetXY[0] - spreadRadius + offsetX, y + offsetXY[1] - spreadRadius + offsetY, shadowPaint);
171170
bmAlpha.recycle();
172171

173-
174172
unapplyTransform();
175173
canvas.restore();
176174
}

0 commit comments

Comments
 (0)