summaryrefslogtreecommitdiff
path: root/libcaribou/level-model.vala
diff options
context:
space:
mode:
authorEitan Isaacson <eitan@monotonous.org>2011-05-28 12:52:20 -0700
committerEitan Isaacson <eitan@monotonous.org>2011-05-28 12:52:20 -0700
commit458fb0f30376fa795828bdbf550730057a3c1e24 (patch)
tree8ac67b1f912bf0e8f9bdebc3ce34a8f03ec88a68 /libcaribou/level-model.vala
parentc0b23433f89b91bb08c5d6da65a26b32ff739baa (diff)
downloadcaribou-458fb0f30376fa795828bdbf550730057a3c1e24.tar.gz
Add Column model. Use Gee collections (I give up).
Diffstat (limited to 'libcaribou/level-model.vala')
-rw-r--r--libcaribou/level-model.vala46
1 files changed, 31 insertions, 15 deletions
diff --git a/libcaribou/level-model.vala b/libcaribou/level-model.vala
index 321a355..c80490e 100644
--- a/libcaribou/level-model.vala
+++ b/libcaribou/level-model.vala
@@ -3,31 +3,36 @@ using GLib;
namespace Caribou {
public class LevelModel : GLib.Object {
public signal void level_toggled (string new_level);
-
public string mode { get; private set; default = ""; }
- public int n_rows {
- get {
- return _rows.length;
- }
- }
- private RowModel[] _rows;
+ private Gee.ArrayList<RowModel> rows;
- public LevelModel (string mode, uint nrows) {
- uint i;
+ public LevelModel (string mode) {
this.mode = mode;
- _rows = new RowModel[nrows];
- for (i=0;i<nrows;i++)
- _rows[i] = new RowModel ();
+ rows = new Gee.ArrayList<RowModel> ();
}
- public void add_key (uint rownum, KeyModel key) {
+ internal void add_key (int rownum, int colnum, KeyModel key) {
+ int rowindex = rownum;
+ RowModel row = null;
+
+ if (rownum < 0)
+ rowindex = rows.size + rownum;
+
+ if (rownum >= rows.size) {
+ row = new RowModel ();
+ rows.add(row);
+ } else {
+ row = rows[rowindex];
+ }
+
+ row.add_key (colnum, key);
+
key.key_clicked.connect (on_key_clicked);
- _rows[rownum].add_key (key);
}
public RowModel[] get_rows () {
- return _rows;
+ return (RowModel[]) rows.to_array ();
}
private void on_key_clicked (KeyModel key) {
@@ -37,5 +42,16 @@ namespace Caribou {
level_toggled ("default");
}
+ public KeyModel[] get_keys () {
+ Gee.ArrayList<KeyModel> keys = new Gee.ArrayList<KeyModel> ();
+ foreach (RowModel row in rows) {
+ KeyModel[] row_keys = row.get_keys();
+ foreach (KeyModel key in row_keys) {
+ keys.add(key);
+ }
+ }
+
+ return (KeyModel[]) keys.to_array ();
+ }
}
} \ No newline at end of file