Skip to content

Commit 39e6f02

Browse files
committed
update
1 parent 7262119 commit 39e6f02

1 file changed

Lines changed: 45 additions & 52 deletions

File tree

easy-ui/src/main/java/com/moioio/android/g2d/Graphics.java

Lines changed: 45 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,16 @@
2121
import android.graphics.Typeface;
2222
import android.graphics.Xfermode;
2323
import android.os.Build;
24-
import android.text.TextPaint;
2524

2625

2726
public class Graphics
2827
{
2928

3029

31-
float width;
32-
float height;
30+
private float width;
31+
private float height;
3332

34-
public Canvas grap ;
33+
public Canvas canvas;
3534
public Paint paint;
3635

3736
private RectF clip;
@@ -41,10 +40,14 @@ public class Graphics
4140
private Matrix matrix;
4241
private DashPathEffect dashPathEffect;
4342
private Matrix pathM;
43+
private float offX;
44+
private float offY;
45+
private Rect stringRect;
4446

4547
private int canvasInitSave;
4648
public Graphics()
4749
{
50+
stringRect = new Rect();
4851
oval = new RectF();
4952
rect = new RectF();
5053
clip = new RectF();
@@ -63,7 +66,7 @@ public Graphics()
6366
public Graphics(Canvas canvas)
6467
{
6568
this();
66-
grap = canvas;
69+
this.canvas = canvas;
6770
canvasInitSave = canvas.save();
6871
// textPaint = new TextPaint();
6972
// textPaint.setAntiAlias(true);
@@ -75,7 +78,7 @@ public Graphics(Canvas canvas)
7578

7679
public void setCanvas(Canvas canvas)
7780
{
78-
grap = canvas;
81+
this.canvas = canvas;
7982
canvasInitSave = canvas.save();
8083
}
8184

@@ -84,11 +87,11 @@ public void drawScaleImage(Bitmap img, float x, float y, float sx, float sy) {
8487
matrix.reset();
8588
matrix.setScale(sx, sy);
8689
matrix.postTranslate(x+offX, y+offY);
87-
grap.drawBitmap(img,matrix, paint);
90+
canvas.drawBitmap(img,matrix, paint);
8891
}
8992

9093
public void drawImage(Bitmap img, float x, float y) {
91-
grap.drawBitmap(img, x+offX, y+offY, paint);
94+
canvas.drawBitmap(img, x+offX, y+offY, paint);
9295
}
9396

9497
public void setXfermode(int type)
@@ -138,7 +141,7 @@ public void setMaskFilter(MaskFilter blur) {
138141

139142
public void fillRect(float x, float y, float width, float height) {
140143
paint.setStyle(Paint.Style.FILL);
141-
grap.drawRect(x+offX, y+offY, x+offX + width, y+offY + height, paint);
144+
canvas.drawRect(x+offX, y+offY, x+offX + width, y+offY + height, paint);
142145

143146
}
144147

@@ -147,7 +150,7 @@ public void fillRoundRect(float x, float y, float width, float height,
147150
{
148151
paint.setStyle(Paint.Style.FILL);
149152
rect.set(x+offX, y+offY, x+offX + width, y+offY + height);
150-
grap.drawRoundRect(rect, arcWidth, arcHeight, paint);
153+
canvas.drawRoundRect(rect, arcWidth, arcHeight, paint);
151154
}
152155

153156
public void fillArc(float x, float y, float width, float height, float startAngle,
@@ -156,27 +159,27 @@ public void fillArc(float x, float y, float width, float height, float startAngl
156159
paint.setStyle(Paint.Style.FILL);
157160
rect.set(x+offX, y+offY, x+offX + width, y+offY + height);
158161
// grap.drawArc(rect, -(startAngle+arcAngle), arcAngle, true, paint);
159-
grap.drawArc(rect, startAngle, arcAngle, true, paint);
162+
canvas.drawArc(rect, startAngle, arcAngle, true, paint);
160163
}
161164

162165
public void drawArc(int x, int y, int width, int height, int startAngle,
163166
int arcAngle)
164167
{
165168
paint.setStyle(Paint.Style.STROKE);
166169
rect.set(x+offX, y+offY, x+offX + width, y+offY + height);
167-
grap.drawArc(rect, -(startAngle+arcAngle), arcAngle, true, paint);
170+
canvas.drawArc(rect, -(startAngle+arcAngle), arcAngle, true, paint);
168171
}
169172

170173
public void drawLine(float x1, float y1, float x2, float y2)
171174
{
172175
paint.setStyle(Paint.Style.STROKE);
173-
grap.drawLine(x1+offX, y1+offY, x2+offX, y2+offY, paint);
176+
canvas.drawLine(x1+offX, y1+offY, x2+offX, y2+offY, paint);
174177
}
175178

176179
public void fillLine(float x, float y, float w, float h)
177180
{
178181
paint.setStyle(Paint.Style.STROKE);
179-
grap.drawLine(x+offX, y+offY, x+offX+w, y+offY+h, paint);
182+
canvas.drawLine(x+offX, y+offY, x+offX+w, y+offY+h, paint);
180183
}
181184

182185

@@ -186,42 +189,42 @@ public void drawRotateImage(Bitmap img, int x, int y, int r, float angle) {
186189
matrix.reset();
187190
matrix.setRotate(angle);
188191
matrix.postTranslate(x+offX, y+offY);
189-
grap.drawBitmap(img,matrix, paint);
192+
canvas.drawBitmap(img,matrix, paint);
190193
}
191194

192195
public void setClip(int x, int y, int width, int height)
193196
{
194197
clip.set(x+offX, y+offY, x+offX + width, y+offY + height);
195198
// grap.clipRect(clip, Region.Op.REPLACE);
196199
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P){
197-
grap.restore();
198-
grap.save();
199-
grap.clipRect(clip );//p,
200+
canvas.restore();
201+
canvas.save();
202+
canvas.clipRect(clip );//p,
200203
}else {
201-
grap.clipRect(clip, Region.Op.REPLACE);
204+
canvas.clipRect(clip, Region.Op.REPLACE);
202205
}
203206
}
204207

205208
public void save()
206209
{
207-
grap.save();
210+
canvas.save();
208211
}
209212

210213
public void restore()
211214
{
212-
grap.restore();
215+
canvas.restore();
213216
}
214217

215218

216219
public void setOutClip(int x, int y, int width, int height, Region.Op op)
217220
{
218221
clip.set(x+offX, y+offY, x+offX + width, y+offY + height);
219222
if(Build.VERSION.SDK_INT >= 26){
220-
grap.restore();
221-
grap.save();
222-
grap.clipOutRect(clip );//p, android.graphics.Region.Op.REPLACE
223+
canvas.restore();
224+
canvas.save();
225+
canvas.clipOutRect(clip );//p, android.graphics.Region.Op.REPLACE
223226
}else {
224-
grap.clipRect(clip, op);
227+
canvas.clipRect(clip, op);
225228
}
226229
}
227230

@@ -234,12 +237,12 @@ public void setColor(int A, int R, int G, int B)
234237
public void drawRoundRect(float x, float y, float width, float height, float arcWidth, float arcHeight) {
235238
paint.setStyle(Paint.Style.STROKE);
236239
rect.set(x+offX, y+offY, x+offX + width, y+offY + height);
237-
grap.drawRoundRect(rect, arcWidth, arcHeight, paint);
240+
canvas.drawRoundRect(rect, arcWidth, arcHeight, paint);
238241
}
239242

240243
public void drawRect(float x, float y, float width, float height) {
241244
paint.setStyle(Paint.Style.STROKE);
242-
grap.drawRect(x+offX, y+offY, x+offX + width, y+offY + height, paint);
245+
canvas.drawRect(x+offX, y+offY, x+offX + width, y+offY + height, paint);
243246
}
244247

245248
public void drawRect(RectF rectF,Matrix matrix) {
@@ -251,34 +254,34 @@ public void drawDashRect(float x, float y, float width, float height) {
251254
paint.setStyle(Paint.Style.STROKE);
252255
PathEffect pathEffect =paint.getPathEffect();
253256
paint.setPathEffect(dashPathEffect);
254-
grap.drawRect(x+offX, y+offY, x+offX + width, y+offY + height, paint);
257+
canvas.drawRect(x+offX, y+offY, x+offX + width, y+offY + height, paint);
255258
paint.setPathEffect(pathEffect);
256259
}
257260

258261
public void fillOval(float x, float y, float width, float height)
259262
{
260263
paint.setStyle(Paint.Style.FILL);
261264
oval.set(x+offX, y+offY, x+offX + width, y+offY + height);
262-
grap.drawOval(oval, paint);
265+
canvas.drawOval(oval, paint);
263266
}
264267

265268
public void fillCircle(float x, float y, float radius)
266269
{
267270
paint.setStyle(Paint.Style.FILL);
268-
grap.drawCircle(x+offX, y+offY,radius, paint);
271+
canvas.drawCircle(x+offX, y+offY,radius, paint);
269272
}
270273

271274
public void drawCircle(float x, float y, float radius)
272275
{
273276
paint.setStyle(Paint.Style.STROKE);
274-
grap.drawCircle(x+offX, y+offY,radius, paint);
277+
canvas.drawCircle(x+offX, y+offY,radius, paint);
275278
}
276279

277280
public void drawOval(int x, int y, int width, int height)
278281
{
279282
paint.setStyle(Paint.Style.STROKE);
280283
oval.set(x+offX, y+offY, x+offX + width, y+offY + height);
281-
grap.drawOval(oval, paint);
284+
canvas.drawOval(oval, paint);
282285

283286
}
284287

@@ -305,7 +308,7 @@ public void drawString(String str,float x,float y) {
305308
paint.getTextBounds(str, 0, str.length(), fontTmpRect);
306309
float dx = x+offX - fontTmpRect.left;
307310
float dy = y+offY + fontTmpRect.height() - fontTmpRect.bottom;
308-
grap.drawText(str,dx,dy,paint);
311+
canvas.drawText(str,dx,dy,paint);
309312
}
310313

311314

@@ -315,12 +318,11 @@ public void drawStrokeString(String str,float x,float y,float width) {
315318
paint.getTextBounds(str, 0, str.length(), fontTmpRect);
316319
float dx = x+offX - fontTmpRect.left;
317320
float dy = y+offY + fontTmpRect.height() - fontTmpRect.bottom;
318-
grap.drawText(str,dx,dy,paint);
321+
canvas.drawText(str,dx,dy,paint);
319322
paint.setStrokeWidth(0);
320323
}
321324

322325

323-
Rect stringRect = new Rect();
324326
public int getStringWidth(String str)
325327
{
326328
paint.getTextBounds(str, 0, str.length(), stringRect);
@@ -337,13 +339,9 @@ public int getStringHeight(String str)
337339

338340

339341
public void drawImage(Bitmap bmp, Matrix matrix) {
340-
grap.drawBitmap(bmp,matrix,paint);
342+
canvas.drawBitmap(bmp,matrix,paint);
341343
}
342344

343-
344-
345-
346-
347345
public void fillPath(Path path) {
348346

349347
paint.setStyle(Paint.Style.FILL);
@@ -354,7 +352,7 @@ public void fillPath(Path path) {
354352
path.transform(pathM);
355353
}
356354

357-
grap.drawPath(path, paint);
355+
canvas.drawPath(path, paint);
358356

359357
if(offX!=0&&offY!=0)
360358
{
@@ -388,7 +386,6 @@ public void setFontSpace(float space) {
388386

389387
public void setFakeBoldText(boolean b) {
390388
paint.setFakeBoldText(b);
391-
392389
}
393390

394391
public void setTextSkewX(float v) {
@@ -408,7 +405,7 @@ public void setStrokeWidth(float width) {
408405
}
409406

410407
public void setMatrix(Matrix matrix) {
411-
grap.setMatrix(matrix);
408+
canvas.setMatrix(matrix);
412409
}
413410

414411
public void setShadowLayer(float radius, float dx, float dy, int shadowColor) {
@@ -424,7 +421,7 @@ public void setClipArea(Path path)
424421
path.transform(pathM);
425422
}
426423

427-
grap.clipPath(path);
424+
canvas.clipPath(path);
428425

429426
if(offX!=0&&offY!=0)
430427
{
@@ -444,7 +441,7 @@ public void setClipAreaOut(Path path)
444441
path.transform(pathM);
445442
}
446443

447-
grap.clipOutPath(path);
444+
canvas.clipOutPath(path);
448445

449446
if(offX!=0&&offY!=0)
450447
{
@@ -465,7 +462,7 @@ public void drawPath(Path path)
465462
path.transform(pathM);
466463
}
467464

468-
grap.drawPath(path,paint);
465+
canvas.drawPath(path,paint);
469466

470467
if(offX!=0&&offY!=0)
471468
{
@@ -480,7 +477,7 @@ public Paint getPaint() {
480477
}
481478

482479
public void clear() {
483-
grap.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
480+
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
484481
}
485482

486483
public float getWidth() {
@@ -499,10 +496,6 @@ public void setHeight(float height) {
499496
this.height = height;
500497
}
501498

502-
503-
private float offX;
504-
private float offY;
505-
506499
public void translate(float x, float y) {
507500
offX = x;
508501
offY = y;
@@ -516,7 +509,7 @@ public void reset() {
516509

517510

518511
public Canvas getCanvas() {
519-
return grap;
512+
return canvas;
520513
}
521514

522515
// public ColorMatrix getColorMatrix() {

0 commit comments

Comments
 (0)