質問編集履歴

1

2017/02/05 09:35

投稿

hidemaru
hidemaru

スコア30

test CHANGED
File without changes
test CHANGED
@@ -204,6 +204,202 @@
204
204
 
205
205
  ```
206
206
 
207
+ **Graphics.java**
208
+
209
+ ```lang-java
210
+
211
+
212
+
213
+ package net.npaka.puzzlegame;
214
+
215
+ import android.graphics.Bitmap;
216
+
217
+ import android.graphics.Canvas;
218
+
219
+ import android.graphics.Paint;
220
+
221
+ import android.graphics.Paint.FontMetrics;
222
+
223
+ import android.graphics.Rect;
224
+
225
+
226
+
227
+ //グラフィックス(9)
228
+
229
+ public class Graphics {
230
+
231
+ private Paint paint; //ペイント
232
+
233
+ private Bitmap bmp; //ビットマップ
234
+
235
+ private Canvas canvas; //キャンバス
236
+
237
+ private int originX;//原点X
238
+
239
+ private int originY;//原点Y
240
+
241
+
242
+
243
+ //コンストラクタ
244
+
245
+ public Graphics(int w, int h) {
246
+
247
+ bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
248
+
249
+ canvas = new Canvas(bmp);
250
+
251
+ paint = new Paint();
252
+
253
+ paint.setAntiAlias(true);
254
+
255
+ }
256
+
257
+
258
+
259
+ //ビットマップの取得
260
+
261
+ public Bitmap getBitmap() {
262
+
263
+ return bmp;
264
+
265
+ }
266
+
267
+
268
+
269
+ //描画原点の指定
270
+
271
+ public void setOrigin(int x, int y) {
272
+
273
+ canvas.translate(x, y);
274
+
275
+ originX = x;
276
+
277
+ originY = y;
278
+
279
+ }
280
+
281
+
282
+
283
+ //描画原点のX座標の取得
284
+
285
+ public int getOriginX() {
286
+
287
+ return originX;
288
+
289
+ }
290
+
291
+
292
+
293
+ //描画原点のY座標の取得
294
+
295
+ public int getOriginY() {
296
+
297
+ return originY;
298
+
299
+ }
300
+
301
+
302
+
303
+ //色の指定
304
+
305
+ public void setColor(int color) {
306
+
307
+ paint.setColor(color);
308
+
309
+ }
310
+
311
+
312
+
313
+ //フォントサイズの指定
314
+
315
+ public void setTextSize(int fontSize) {
316
+
317
+ paint.setTextSize(fontSize);
318
+
319
+ }
320
+
321
+
322
+
323
+ //フォントメトリックスの取得
324
+
325
+ public FontMetrics getFontMetrics() {
326
+
327
+ return paint.getFontMetrics();
328
+
329
+ }
330
+
331
+
332
+
333
+ //文字幅の取得
334
+
335
+ public int measureText(String string) {
336
+
337
+ return (int)paint.measureText(string);
338
+
339
+ }
340
+
341
+
342
+
343
+ //塗り潰し矩形の描画
344
+
345
+ public void fillRect(int x, int y, int w, int h) {
346
+
347
+ if (canvas == null) return;
348
+
349
+ paint.setStyle(Paint.Style.FILL);
350
+
351
+ canvas.drawRect(new Rect(x, y, x+w, y+h), paint);
352
+
353
+ }
354
+
355
+
356
+
357
+ //ビットマップの描画
358
+
359
+ public void drawBitmap(Bitmap bitmap, int x, int y) {
360
+
361
+ if (canvas == null) return;
362
+
363
+ int w = bitmap.getWidth();
364
+
365
+ int h = bitmap.getHeight();
366
+
367
+ Rect src = new Rect(0, 0, w, h);
368
+
369
+ Rect dst = new Rect(x, y, x+w, y+h);
370
+
371
+ canvas.drawBitmap(bitmap, src, dst, null);
372
+
373
+ }
374
+
375
+
376
+
377
+ //ビットマップの描画
378
+
379
+ public void drawBitmap(Bitmap bitmap, Rect src, Rect dst) {
380
+
381
+ if (canvas == null) return;
382
+
383
+ canvas.drawBitmap(bitmap, src, dst, null);
384
+
385
+ }
386
+
387
+
388
+
389
+ //文字列の描画
390
+
391
+ public void drawText(String string, int x, int y) {
392
+
393
+ if (canvas == null) return;
394
+
395
+ canvas.drawText(string, x, y, paint);
396
+
397
+ }
398
+
399
+ }
400
+
401
+ ```
402
+
207
403
 
208
404
 
209
405
  ちなみに、画像の場所は、