aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gui.rs71
1 files changed, 45 insertions, 26 deletions
diff --git a/src/gui.rs b/src/gui.rs
index 98c29c0..c633dac 100644
--- a/src/gui.rs
+++ b/src/gui.rs
@@ -252,11 +252,11 @@ impl BoardGUI {
}
}
- fn draw_stone(&self, win: &Window, top: bool, player: &Player, stone: &Stone) {
- if self.has_colours {
+ fn draw_stone(&self, win: &Window, top: bool, buried: bool, player: &Player, stone: &Stone) {
+ if self.has_colours && (!buried) {
match player {
- Player::Black => win.attrset(ColorPair(self.black_colour)),
- Player::White => win.attrset(ColorPair(self.white_colour)),
+ Player::Black => win.attron(ColorPair(self.black_colour)),
+ Player::White => win.attron(ColorPair(self.white_colour)),
};
if top {
win.addch(match stone {
@@ -267,7 +267,11 @@ impl BoardGUI {
} else {
win.addstr(format!("{}", player));
}
+ win.attrset(Attribute::Normal);
} else {
+ if buried {
+ win.attron(Attribute::Underline);
+ }
win.addstr(format!("{}", player));
if top {
win.addstr(format!("{}", stone));
@@ -278,21 +282,36 @@ impl BoardGUI {
fn draw_stack(&self, pos: &Position, stack: &Stack) {
if let Some(win) = self.cell_windows.get(self.pos_to_idx(pos)) {
win.clear();
- let height = stack.len() as usize;
+ let height = stack.len() as i32;
if height > 0 {
- let carry_capacity = self.size as usize;
- let tall = height > carry_capacity;
- if tall {
- win.attrset(Attribute::Normal);
- win.addch('(');
- }
+ let carry_capacity = self.size;
+
+ let my = win.get_max_y();
+ let mut cy = 0;
+ let mut cx = 0;
+
for i in 0..height {
- let piece = &stack[i];
- self.draw_stone(win, i + 1 == height, &piece.player, &piece.stone);
- if tall && i + 1 == height - carry_capacity {
+ let piece = &stack[(height - i - 1) as usize];
+ self.draw_stone(
+ win,
+ i == 0,
+ i >= carry_capacity as i32,
+ &piece.player,
+ &piece.stone,
+ );
+ cy += 1;
+ if (cy >= my) && (i + 1 < height) {
+ cx += 1;
+ if i + my - 1 >= height {
+ cy = i + my - height + 1;
+ } else {
+ cy = 1;
+ }
+ win.mv(0, cx);
win.attrset(Attribute::Normal);
- win.addch(')');
+ win.addch('v');
}
+ win.mv(cy, cx);
}
}
win.refresh();
@@ -342,16 +361,16 @@ impl BoardGUI {
}
let bg = BoardGUI {
- board_window: board_window,
- cell_windows: cell_windows,
- size: size,
- cell_height: cell_height,
- cell_width: cell_width,
- hoff: hoff,
+ board_window,
+ cell_windows,
+ size,
+ cell_height,
+ cell_width,
+ hoff,
cur_cell: Position { x: 0, y: 0 },
- has_colours: has_colours,
- black_colour: black_colour,
- white_colour: white_colour,
+ has_colours,
+ black_colour,
+ white_colour,
};
bg.board_window.keypad(true);
@@ -389,8 +408,8 @@ impl ActionEntry {
let ae = ActionEntry {
window: newwin(1, width, ypos, xpos),
- max_len: max_len,
- xstart: xstart,
+ max_len,
+ xstart,
};
ae.window.nodelay(false);