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

SO COOL: borders

parent 15c50471
package edu.liu.floodgame; package edu.liu.floodgame;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint; import android.graphics.Paint;
import android.support.v7.widget.GridLayout; import android.support.v7.widget.GridLayout;
import android.view.View; import android.view.View;
...@@ -46,7 +47,8 @@ public class GridCellView extends View { ...@@ -46,7 +47,8 @@ public class GridCellView extends View {
else return Corner.NO_NO; 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}; 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) { void setNeighbors(Corner nw, Corner ne, Corner se, Corner sw) {
...@@ -74,30 +76,41 @@ public class GridCellView extends View { ...@@ -74,30 +76,41 @@ public class GridCellView extends View {
protected void onDraw(Canvas canvas) { protected void onDraw(Canvas canvas) {
super.onDraw(canvas); super.onDraw(canvas);
GridActivity activity = (GridActivity) getContext(); GridActivity activity = (GridActivity) getContext();
paint.setStyle(Paint.Style.FILL); fill.setStyle(Paint.Style.FILL);
paint.setColor(activity.colorFromPalette(color)); 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 z = getWidth();
final float c = z * 0.5f; final float c = z * 0.5f;
final float m = z * 0.1f; final float m = z * 0.07f;
for(Quadrant q : Quadrant.values()) { for(Quadrant q : Quadrant.values()) {
System.out.print(" " + q.value + "=" + q + ":" + neighbors[q.value]); System.out.print(" " + q.value + "=" + q + ":" + neighbors[q.value]);
switch(neighbors[q.value]) { switch(neighbors[q.value]) {
case NO_NO: 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; break;
case NO_YES: 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; break;
case YES_NO: 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; break;
case YES_YES_YES: 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; break;
case YES_NO_YES: case YES_NO_YES:
drawRect(canvas, q, m, 0, c, c, paint); // vert drawRect(canvas, q, m, 0, c, c, fill); // vert
drawRect(canvas, q, 0, m, c, c, paint); // horiz 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; break;
} }
} }
...@@ -123,4 +136,18 @@ public class GridCellView extends View { ...@@ -123,4 +136,18 @@ public class GridCellView extends View {
// Now draw // Now draw
canvas.drawRect(left, top, right, bottom, paint); 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