Commit ba85d70f authored by Christopher League's avatar Christopher League
Browse files

SO COOL: borders

parent 15c50471
package edu.liu.floodgame;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.v7.widget.GridLayout;
import android.view.View;
......@@ -46,7 +47,8 @@ public class GridCellView extends View {
else return Corner.NO_NO;
}
private Paint paint = new Paint();
private Paint fill = new Paint();
private Paint stroke = new Paint();
private Corner[] neighbors = new Corner[] { Corner.NO_NO, Corner.NO_NO,Corner.NO_NO,Corner.NO_NO};
void setNeighbors(Corner nw, Corner ne, Corner se, Corner sw) {
......@@ -74,30 +76,41 @@ public class GridCellView extends View {
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
GridActivity activity = (GridActivity) getContext();
paint.setStyle(Paint.Style.FILL);
paint.setColor(activity.colorFromPalette(color));
fill.setStyle(Paint.Style.FILL);
fill.setColor(activity.colorFromPalette(color));
stroke.setStyle(Paint.Style.STROKE);
stroke.setColor(Color.BLACK);
stroke.setStrokeWidth(3f);
stroke.setAntiAlias(true);
stroke.setAlpha(127);
final float z = getWidth();
final float c = z * 0.5f;
final float m = z * 0.1f;
final float m = z * 0.07f;
for(Quadrant q : Quadrant.values()) {
System.out.print(" " + q.value + "=" + q + ":" + neighbors[q.value]);
switch(neighbors[q.value]) {
case NO_NO:
drawRect(canvas, q, m, m, c, c, paint); // corner (nn)
drawRect(canvas, q, m, m, c, c, fill); // corner (nn)
drawLine(canvas, q, m, m, m, c, stroke);
drawLine(canvas, q, m, m, c, m, stroke);
break;
case NO_YES:
drawRect(canvas, q, m, 0, c, c, paint); // vert (ny)
drawRect(canvas, q, m, 0, c, c, fill); // vert (ny)
drawLine(canvas, q, m, 0, m, c, stroke);
break;
case YES_NO:
drawRect(canvas, q, 0, m, c, c, paint); // horiz (yn)
drawRect(canvas, q, 0, m, c, c, fill); // horiz (yn)
drawLine(canvas, q, 0, m, c, m, stroke);
break;
case YES_YES_YES:
drawRect(canvas, q, 0, 0, c, c, paint); // full (yyy)
drawRect(canvas, q, 0, 0, c, c, fill); // full (yyy)
break;
case YES_NO_YES:
drawRect(canvas, q, m, 0, c, c, paint); // vert
drawRect(canvas, q, 0, m, c, c, paint); // horiz
drawRect(canvas, q, m, 0, c, c, fill); // vert
drawRect(canvas, q, 0, m, c, c, fill); // horiz
drawLine(canvas, q, m, 0, m, m, stroke);
drawLine(canvas, q, 0, m, m, m, stroke);
break;
}
}
......@@ -123,4 +136,18 @@ public class GridCellView extends View {
// Now draw
canvas.drawRect(left, top, right, bottom, paint);
}
void drawLine(Canvas canvas, Quadrant quadrant, float x1, float y1, float x2, float y2, Paint paint) {
switch(quadrant) {
case NE: case SE:
x1 = getWidth() - x1;
x2 = getWidth() - x2;
}
switch(quadrant) {
case SW: case SE:
y1 = getHeight() - y1;
y2 = getHeight() - y2;
}
canvas.drawLine(x1, y1, x2, y2, paint);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment