Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleanup some color handling with constants

  • Loading branch information...
commit 0eb70accdcd0acd68003402e48daf587d9fb2439 1 parent a6cee50
@chellmuth authored
Showing with 14 additions and 6 deletions.
  1. +2 −2 lib/bench.dart
  2. +7 −0 lib/color.dart
  3. +5 −4 lib/view.dart
View
4 lib/bench.dart
@@ -70,7 +70,7 @@ class Bench {
void _drawBugCount(CanvasRenderingContext2D context, Rectangle bounds, Player player, int count) {
context.save();
- context.fillStyle = player == Player.WHITE ? '#595959' : '#FFFFF7';
+ context.fillStyle = player == Player.WHITE ? Color.WhiteTile : Color.BlackTile;
context.beginPath();
context.arc(bounds.left + bounds.width / 2, bounds.top + bounds.height / 2, bounds.width / 2, 0, PI * 2, true);
@@ -79,7 +79,7 @@ class Bench {
var fontSize = 14;
context.font = '${fontSize}pt Futura';
- context.fillStyle = player == Player.WHITE ? '#FFFFF7' : '#595959';
+ context.fillStyle = player == Player.WHITE ? Color.WhiteTile : Color.BlackTile;
var metrics = context.measureText(count.toString());
context.fillText(count.toString(), bounds.left + bounds.width / 2 - metrics.width / 2, bounds.top + bounds.height / 2 + fontSize / 2);
context.restore();
View
7 lib/color.dart
@@ -0,0 +1,7 @@
+library color;
+
+abstract class Color {
+ static String WhiteTile = '#FFFFF7';
+ static String BlackTile = '#595959';
+ static String TileBorder = '#333';
+}
View
9 lib/view.dart
@@ -6,6 +6,7 @@ import 'dart:math' show PI, max;
import 'assets.dart';
import 'gamemodel.dart';
import 'gamestate.dart';
+import 'color.dart';
part 'bench.dart';
@@ -71,7 +72,7 @@ class MoveView extends HexView {
int get row => location.row;
int get col => location.col;
String get fillColor => 'rgba(255, 153, 154, 0.8)';
- String get strokeColor => '#333';
+ String get strokeColor => Color.TileBorder;
}
class TileView extends HexView {
@@ -86,8 +87,8 @@ class TileView extends HexView {
int get row => tile.row;
int get col => tile.col;
int get stackHeight => tile.height;
- String get fillColor => tile.piece.player == Player.WHITE ? '#595959' : '#FFFFF7';
- String get strokeColor => '#333';
+ String get fillColor => tile.piece.player == Player.WHITE ? Color.BlackTile : Color.WhiteTile;
+ String get strokeColor => Color.TileBorder;
void draw(CanvasRenderingContext2D context) {
//super.draw(context);
@@ -187,7 +188,7 @@ class CoveredPieceView {
var fontSize = 14;
context.font = '${fontSize}pt Futura';
- context.fillStyle = piece.player == Player.WHITE ? '#FFFFF7' : '#595959';
+ context.fillStyle = piece.player == Player.WHITE ? Color.WhiteTile : Color.BlackTile;
var metrics = context.measureText(letter);
context.fillText(letter, bounds.left + bounds.width / 2 - metrics.width / 2, bounds.top + bounds.height / 2 + fontSize / 2);
context.restore();
Please sign in to comment.
Something went wrong with that request. Please try again.