1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
/* drawkey.c
*
* Function for drawing the key signature
*
* for Denemo, a gtk+ frontend to GNU Lilypond
* (c) 1999, 2000, 2001 Matthew Hiller
*/
#include "accwidths.h"
#include "datastructures.h"
#include "drawingprims.h"
#include "utils.h"
#define SPACE_BETWEEN_ACCS 8
#define m * HALF_LINE_SPACE
/* This function draws the key, if desired, and returns the width required
* to draw it
* number describes the number of the new key, prevnumber the number of
* the preceding key */
gint
draw_key (GdkPixmap * pixmap, GdkGC * gc, gint xx, gint y,
gint number, gint prevnumber, gint dclef, gboolean wetrun)
{
/* These are just hard-coded offsets in pixels from the top of the staff.
* mid_c_offset arrays. There's probably
* a better way to do this, but I haven't thought of it */
static gint treble_flat_ys[7] = { 4 m, 1 m, 5 m, 2 m, 6 m, 3 m, 7 m };
static gint treble_sharp_ys[7] = { 0, 3 m, -1 m, 2 m, 5 m, 1 m, 4 m };
static gint bass_flat_ys[7] = { 6 m, 3 m, 7 m, 4 m, 8 m, 5 m, 9 m };
static gint bass_sharp_ys[7] = { 2 m, 5 m, 1 m, 4 m, 7 m, 3 m, 6 m };
static gint alto_flat_ys[7] = { 5 m, 2 m, 6 m, 3 m, 7 m, 4 m, 8 m };
static gint alto_sharp_ys[7] = { 1 m, 4 m, 0, 3 m, 6 m, 2 m, 5 m };
static gint tenor_flat_ys[7] = { 2 m, 0, 4 m, 1 m, 5 m, 2 m, 6 m };
static gint tenor_sharp_ys[7] = { -1 m, 2 m, 5 m, 1 m, 4 m, 0 m, 3 m };
static gint soprano_flat_ys[7] = { 2 m, 6 m, 3 m, 7 m, 4 m, 8 m, 5 m };
static gint soprano_sharp_ys[7] = { 5 m, 8 m, 4 m, 7 m, 3 m, 6 m, 2 m };
gint *theys = NULL;
gint *theprevys = NULL;
gint i;
gint startindex, endindex;
gint origx = xx;
/* first, set the arrays we're using to something useful */
if (wetrun)
{
switch (dclef)
{
case TREBLE:
theprevys = (prevnumber < 0) ? treble_flat_ys : treble_sharp_ys;
theys = (number < 0) ? treble_flat_ys : treble_sharp_ys;
break;
case BASS:
theprevys = (prevnumber < 0) ? bass_flat_ys : bass_sharp_ys;
theys = (number < 0) ? bass_flat_ys : bass_sharp_ys;
break;
case ALTO:
theprevys = (prevnumber < 0) ? alto_flat_ys : alto_sharp_ys;
theys = (number < 0) ? alto_flat_ys : alto_sharp_ys;
break;
case G_8:
theprevys = (prevnumber < 0) ? treble_flat_ys : treble_sharp_ys;
theys = (number < 0) ? treble_flat_ys : treble_sharp_ys;
break;
case TENOR:
theprevys = (prevnumber < 0) ? tenor_flat_ys : tenor_sharp_ys;
theys = (number < 0) ? tenor_flat_ys : tenor_sharp_ys;
break;
case SOPRANO:
theprevys = (prevnumber < 0) ? soprano_flat_ys : soprano_sharp_ys;
theys = (number < 0) ? soprano_flat_ys : soprano_sharp_ys;
break;
default:
/* Silently default to the treble stuff. Fix me. */
theprevys = (prevnumber < 0) ? treble_flat_ys : treble_sharp_ys;
theys = (number < 0) ? treble_flat_ys : treble_sharp_ys;
break;
}
}
/* First, check to see if we ought to draw naturals. */
if (prevnumber < 0)
{
/* Draw as many accidentals as we need. */
if (number < 0)
startindex = -number;
else
startindex = 0;
endindex = -prevnumber;
/* Note that the loop will immediately exit if number <= prevnumber */
for (i = startindex; i < endindex; i++, xx += NATURAL_WIDTH + 2)
{
if (wetrun)
draw_accidental (pixmap, gc, xx, y + theprevys[i], 0);
}
}
else if (prevnumber > 0)
{
/* Analogous to above */
if (number > 0)
startindex = number;
else
startindex = 0;
for (i = startindex; i < prevnumber; i++, xx += NATURAL_WIDTH + 2)
{
if (wetrun)
draw_accidental (pixmap, gc, xx, y + theprevys[i], 0);
}
}
/* Now draw the new indicators themselves */
if (number < 0)
{
number = -number;
for (i = 0; i < number; i++, xx += FLAT_WIDTH + 2)
if (wetrun)
draw_accidental (pixmap, gc, xx, y + theys[i], -1);
}
else
for (i = 0; i < number; i++, xx += SHARP_WIDTH + 2)
if (wetrun)
draw_accidental (pixmap, gc, xx, y + theys[i], 1);
return xx - origx;
}
|