~robert-ancell/+junk/sudoku-vala

« back to all changes in this revision

Viewing changes to src/sudoku-view.vala

  • Committer: robert.ancell at canonical
  • Date: 2010-10-27 18:43:24 UTC
  • Revision ID: robert.ancell@canonical.com-20101027184324-e4krz724ebj4htm8
Allow entering of numbers

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
private class SudokuCellView : Gtk.DrawingArea
2
2
{
3
3
    private Pango.Layout layout;
4
 
    
 
4
 
 
5
    private SudokuCell _cell;
 
6
    public SudokuCell cell
 
7
    {
 
8
        set
 
9
        {
 
10
            _cell = value;
 
11
            this.value = cell.value;
 
12
            _cell.value_changed.connect (value_changed_cb);
 
13
        }
 
14
        get { return _cell; }
 
15
    }
 
16
 
5
17
    private string _text;
6
18
    public string text
7
19
    {
40
52
        side = width > height ? width : height;
41
53
        requisition.width = requisition.height = side / Pango.SCALE;
42
54
    }
 
55
    
 
56
    public override bool key_release_event (Gdk.EventKey event)
 
57
    {
 
58
        // FIXME: Can't find vala bindings to Gdk keyvals...
 
59
 
 
60
        if (event.keyval >= 49 /* 1 */ && event.keyval <= 58 /* 9 */)
 
61
        {
 
62
            cell.value = (int)event.keyval - 48;
 
63
            return true;
 
64
        }
 
65
 
 
66
        if (event.keyval == 48 || event.keyval == 65288 /* backspace */ || event.keyval == 65535 /* delete */)
 
67
        {
 
68
            cell.value = 0;
 
69
            return true;
 
70
        }
 
71
 
 
72
        return false;
 
73
    }
43
74
 
44
75
    public override bool expose_event (Gdk.EventExpose event)
45
76
    {
61
92
 
62
93
        return false;
63
94
    }
 
95
 
 
96
    private void value_changed_cb (SudokuCell cell)
 
97
    {
 
98
        value = cell.value;
 
99
    }
64
100
}
65
101
 
66
102
public class SudokuView : Gtk.AspectFrame
71
107
    public SudokuView (SudokuGame game)
72
108
    {
73
109
        this.game = game;
74
 
        this.game.cell_changed.connect (cell_changed_cb);
75
110
 
76
111
        shadow_type = Gtk.ShadowType.NONE;
77
112
        
96
131
            {
97
132
                var cell = new SudokuCellView ();
98
133
                cells[row, col] = cell;
99
 
                cell.value = game.cells[row, col].value;
 
134
                cell.cell = game.cells[row, col];
100
135
                cell.show ();
101
136
                table.attach_defaults (cell, col, col+1, row, row+1);
102
137
            }
103
138
        box.add (table);
104
139
        table.show ();
105
140
    }
106
 
    
107
 
    private void cell_changed_cb (SudokuGame game, SudokuCell cell)
108
 
    {
109
 
        cells[cell.row, cell.col].value = cell.value;
110
 
    }
111
141
}