]> git.cworth.org Git - scherzo/blobdiff - score.c
Draw a second staff (and vertical lines at the beginning and end of staff).
[scherzo] / score.c
diff --git a/score.c b/score.c
index 4f0efdd2f8ba7dcc4aab9a191ce32cdd73a8a5db..89371622453998b9536e879922662254d580b9f3 100644 (file)
--- a/score.c
+++ b/score.c
 
 #include "score.h"
 
+struct score
+{
+    /* Height of a single staff */
+    int staff_height;
+
+    /* Height of one space within a staff */
+    int space_height;
+
+    /* Full width of staff */
+    int width;
+};
+
 void
 score_init (score_t *score)
 {
-    score->space_height = 6;
+    score_set_staff_height (score, 24);
+}
+
+int
+score_set_staff_height (score_t *score, int height)
+{
+    score->space_height = (int) height / 4;
+    score->staff_height = score->space_height * 4;
+    return score->staff_height;
 }
 
 void
+score_set_width (score_t *score, int width)
+{
+    score->width = width;
+}
+
+static void
 _draw_staff (score_t *score, cairo_t *cr)
 {
     int i;
 
     cairo_save (cr);
 
-    for (i = 0; i < 5; i++) {
+    cairo_rectangle (cr,
+                    0.5, 0.5,
+                    score->width - 1.0, score->space_height * 4);
+    
+    for (i = 1; i < 4; i++) {
        cairo_move_to (cr, 0, i * score->space_height + 0.5);
        cairo_rel_line_to (cr, score->width, 0);
     }
@@ -46,14 +76,32 @@ _draw_staff (score_t *score, cairo_t *cr)
     cairo_restore (cr);
 }
 
-void
-score_set_width (score_t *score, int width)
+static void
+_draw_grand_staff (score_t *score, cairo_t *cr)
 {
-    score->width = width;
+    cairo_save (cr);
+
+    /* Vertical lines at each end */
+    cairo_rectangle (cr,
+                    0.5, 0.5,
+                    score->width - 1.0,
+                    score->staff_height * 3);
+    cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
+    cairo_set_line_width (cr, 1.0);
+    cairo_stroke (cr);
+
+    /* Top staff */
+    _draw_staff (score, cr);
+
+    /* Bottom staff */
+    cairo_translate (cr, 0, score->staff_height * 2);
+    _draw_staff (score, cr);
+
+    cairo_restore (cr);
 }
 
 void
 score_draw (score_t *score, cairo_t *cr)
 {
-    _draw_staff (score, cr);
+    _draw_grand_staff (score, cr);
 }