2022-01-13 21:38:35 +00:00
|
|
|
package org.er2.fireplace;
|
|
|
|
|
|
|
|
import android.view.View;
|
|
|
|
import android.graphics.Canvas;
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.Paint;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
2022-02-10 17:45:10 +00:00
|
|
|
/* Fireplace frontend
|
|
|
|
* TODO: Optimize this..
|
|
|
|
*
|
|
|
|
* (c) Er2 2022 <er2@dismail.de>
|
|
|
|
* Zlib License
|
|
|
|
*/
|
|
|
|
|
2022-01-13 21:38:35 +00:00
|
|
|
public class FireplaceView extends View {
|
2022-02-10 17:45:10 +00:00
|
|
|
Paint paint; /* Android paint */
|
|
|
|
Fireplace fpl; /* Our backend */
|
|
|
|
Bitmap bmp; /* Screenshot of previous frame (thing to be optimized) */
|
2022-01-13 21:38:35 +00:00
|
|
|
|
|
|
|
public FireplaceView(Context ctx, AttributeSet attrs) {
|
|
|
|
super(ctx, attrs);
|
|
|
|
paint = new Paint();
|
|
|
|
fpl = new Fireplace();
|
|
|
|
bmp = Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void drawFire(Canvas canv) {
|
2022-02-10 17:45:10 +00:00
|
|
|
/* draw previous frame and apply transparency
|
|
|
|
thing to be optimized
|
|
|
|
*/
|
2022-01-13 21:38:35 +00:00
|
|
|
canv.drawBitmap(bmp, 0, 0, null);
|
|
|
|
paint.setColor(0x1E000000);
|
|
|
|
canv.drawRect(0, 0, getWidth(), getHeight(), paint);
|
2022-02-10 17:45:10 +00:00
|
|
|
|
|
|
|
/* going through columns */
|
2022-01-13 21:38:35 +00:00
|
|
|
for(int i = 0; i < fpl.col; i++) {
|
|
|
|
fpl.next();
|
|
|
|
paint.setColor(fpl.getCol());
|
|
|
|
int[] xy = fpl.getXY();
|
|
|
|
canv.drawText("" + fpl.getChr(),
|
|
|
|
xy[0], xy[1], paint);
|
|
|
|
}
|
|
|
|
fpl.row();
|
|
|
|
//postInvalidateDelayed(60);
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDraw(Canvas c) {
|
2022-02-10 17:45:10 +00:00
|
|
|
/* TODO: To be optimized */
|
2022-01-13 21:38:35 +00:00
|
|
|
Bitmap bip = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
|
|
|
|
Canvas canv = new Canvas(bip);
|
|
|
|
drawFire(canv);
|
|
|
|
bmp.recycle();
|
|
|
|
bmp = bip;
|
|
|
|
c.drawBitmap(bmp, 0, 0, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onSizeChanged(int w, int h, int ow, int oh) {
|
2022-02-10 17:45:10 +00:00
|
|
|
/* Set size directly */
|
2022-01-13 21:38:35 +00:00
|
|
|
fpl.setSize(w, h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|