1 /* slurs.cpp
2  *
3  * Functions for drawing slurs
4  *
5  * for Denemo, a gtk+ frontend to GNU Lilypond
6  * (c) 2000-2005 Adam Tee, Matthew Hiller
7  */
8 
9 #include <denemo/denemo.h>
10 #include "core/utils.h"              /* Includes <gdk.h> */
11 #include <math.h>
12 
13 GSList *
push_slur_stack(GSList * slur_stack,gint x,gint y)14 push_slur_stack (GSList * slur_stack, gint x, gint y)
15 {
16   slur_stack = g_slist_prepend (slur_stack, GINT_TO_POINTER ((x&0xFFFF)+(y<<16)));
17   return slur_stack;
18 }
19 
20 static gint
top_slur_stack_x(GSList * slur_stack)21 top_slur_stack_x (GSList * slur_stack)
22 {
23   if (slur_stack)
24     return 0xFFFF & GPOINTER_TO_INT (slur_stack->data);
25   else
26     return -1;
27 }
28 static gint
top_slur_stack_y(GSList * slur_stack)29 top_slur_stack_y (GSList * slur_stack)
30 {
31   if (slur_stack)
32     return  (GPOINTER_TO_INT (slur_stack->data))>>16;
33   else
34     return -1;
35 }
36 GSList *
pop_slur_stack(GSList * slur_stack)37 pop_slur_stack (GSList * slur_stack)
38 {
39   if (slur_stack)
40     {
41       GSList *head = slur_stack;
42 
43       slur_stack = g_slist_remove_link (slur_stack, head);
44       g_slist_free_1 (head);
45       return slur_stack;
46     }
47   else
48     return NULL;
49 }
50 
51 void
draw_slur(cairo_t * cr,GSList ** slur_stack,gint x2,gint y,gint y2)52 draw_slur (cairo_t * cr, GSList ** slur_stack, gint x2, gint y, gint y2)
53 {
54   gint x1 = top_slur_stack_x (*slur_stack);
55   gint y1 = top_slur_stack_y (*slur_stack);
56   gint dir = (y1+y2>40?-1:1);
57 
58 
59   if (x1 != -1)
60     {
61       x1 += 6;//over note head
62       *slur_stack = pop_slur_stack (*slur_stack);
63 
64       cairo_set_line_width (cr, 1.0);
65       cairo_move_to (cr, x1, y1 + y - 12 * dir);
66       cairo_rel_curve_to (cr, (x2 - x1) / 3, (y2 - y1 - 5* dir)*1/3 -8 * dir, (x2 - x1) * 2 / 3, (y2 - y1 - 5* dir)*2/3 - 8* dir, (x2 - x1), y2 - y1 - 5* dir);
67       cairo_stroke (cr);
68     }
69   else
70     {
71       cairo_set_line_width (cr, 1.0);
72       cairo_move_to (cr, 0, y - 15);
73       cairo_rel_curve_to (cr, (x2) / 3, -8, (x2) * 2 / 3, -8, (x2), 0);
74       cairo_stroke (cr);
75     }
76 }
77 
78 void
draw_slur_start(cairo_t * cr,gint x,gint y)79 draw_slur_start (cairo_t * cr, gint x, gint y)
80 {
81   cairo_save (cr);
82   cairo_set_source_rgba (cr, 0.1, 0.9, 0.1, 0.8);
83   cairo_translate (cr, x+6, y - 15);
84   cairo_rotate (cr, -M_PI / 3.0);
85   cairo_scale (cr, 0.7, -0.7);
86   drawfetachar_cr (cr, 0xD8, 0, 0);
87   cairo_fill (cr);
88   cairo_restore (cr);
89 }
90 
91 void
draw_slur_end(cairo_t * cr,gint x,gint y)92 draw_slur_end (cairo_t * cr, gint x, gint y)
93 {
94   cairo_save (cr);
95   cairo_set_source_rgba (cr, 0.9, 0.1, 0.1, 0.8);
96    cairo_translate (cr, x+5, y - 15);
97   cairo_rotate (cr, -M_PI / 1.5);
98   cairo_scale (cr, 0.7, -0.7);
99   drawfetachar_cr (cr, 0xD9, 0, 0);
100   //cairo_arc (cr, x + 5, y - 16, 4, 0.0, 2 * M_PI);
101   cairo_fill (cr);
102   cairo_restore (cr);
103 }
104