Add simplistic blueprint background.

This commit is contained in:
kenkeiras 2017-07-04 00:21:44 +02:00
parent 078b06ab57
commit cb2ca6c47c
2 changed files with 23 additions and 2 deletions

View File

@ -21,13 +21,15 @@ class DrawView extends View {
public DrawView(Context context) { public DrawView(Context context) {
super(context); super(context);
paint.setColor(Color.RED); this.setBackgroundColor(Color.rgb(4, 69, 99));
parts.add(new RoundButton(500, 1200, 80, 100)); parts.add(new RoundButton(500, 1200, 80, 100));
} }
@Override @Override
public void onDraw(Canvas canvas){ public void onDraw(Canvas canvas){
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
drawBackground(canvas);
for (Part part : parts){ for (Part part : parts){
part.draw(canvas); part.draw(canvas);
} }
@ -35,6 +37,26 @@ class DrawView extends View {
Log.d("Render time", System.currentTimeMillis() - time + "ms"); Log.d("Render time", System.currentTimeMillis() - time + "ms");
} }
private void drawBackground(Canvas canvas) {
// Blueprint background
final int width = getWidth() + getLeft();
final int height = getHeight() + getTop();
final int cellSize = 50;
Paint blueprintLines = new Paint(Paint.ANTI_ALIAS_FLAG);
blueprintLines.setColor(Color.argb(100, 255, 255, 255));
// Vertical lines
for (int x = cellSize; x < width; x += cellSize){
canvas.drawLine(x, 0, x, height, blueprintLines);
}
// Horizontal lines
for (int y = cellSize; y < height; y += cellSize){
canvas.drawLine(0, y, width, y, blueprintLines);
}
}
@Override @Override
public boolean onTouchEvent(MotionEvent event){ public boolean onTouchEvent(MotionEvent event){
int x = (int) event.getX() - this.getLeft(); int x = (int) event.getX() - this.getLeft();

View File

@ -14,7 +14,6 @@ public class TestActivity extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
drawView = new DrawView(this); drawView = new DrawView(this);
drawView.setBackgroundColor(Color.BLACK);
setContentView(drawView); setContentView(drawView);
} }