Exemplo n.º 1
0
void
seqkeys::set_hint_key (int a_key)
{
    draw_key(m_hint_key, false);
    m_hint_key = a_key;
    if (m_hint_state)
        draw_key(a_key, true);
}
Exemplo n.º 2
0
void
seqkeys::set_hint_state (bool a_state)
{
    m_hint_state = a_state;
    if (!a_state)
        draw_key(m_hint_key, false);
}
Exemplo n.º 3
0
void RegionChooser::draw_keyboard(const Cairo::RefPtr<Cairo::Context>& cr,
                                  int clip_low, int clip_high) {
    const int h = KEYBOARD_HEIGHT;
    const int w = get_width() - 1;
    const int bh = int(h * 0.55);

    Gdk::Cairo::set_source_rgba(cr, black);
    cr->rectangle(0.5, h1 + 0.5, w, h - 1);
    cr->stroke();

    int x1 = key_to_x(20.5, w);
    Gdk::Cairo::set_source_rgba(cr, grey1);
    cr->rectangle(1, h1 + 1, x1 - 1, h - 2);
    cr->fill();

    int x2 = key_to_x(109.5, w);
    Gdk::Cairo::set_source_rgba(cr, white);
    cr->rectangle(x1 + 1, h1 + 1, x2 - x1 - 1, h - 2);
    cr->fill();

    Gdk::Cairo::set_source_rgba(cr, grey1);
    cr->rectangle(x2 + 1, h1 + 1, w - x2 - 1, h - 2);
    cr->fill();

    Gdk::Cairo::set_source_rgba(cr, black);

    int clipkey1 = std::max(0, x_to_key_right(clip_low - 1, w));
    int clipkey2 = std::min(x_to_key_right(clip_high - 1, w) + 1, 128);

    for (int i = clipkey1 ; i < clipkey2 ; i++) {
        int note = (i + 3) % 12;
        int x = key_to_x(i, w);

        if (note == 1 || note == 4 || note == 6 ||
            note == 9 || note == 11) {
            // black key: short line in the middle, with a rectangle
            // on top
            int x2 = key_to_x(i + 0.5, w);
            cr->move_to(x2 + 0.5, h1 + bh + 0.5);
            cr->line_to(x2 + 0.5, h1 + h - 1);
            cr->stroke();

            int x3 = key_to_x(i + 1, w);
            cr->rectangle(x, h1 + 1, x3 - x + 1, bh);
            cr->fill();
        } else if (note == 3 || note == 8) {
            // C or F: long line to the left
            cr->move_to(x + 0.5, h1 + 1);
            cr->line_to(x + 0.5, h1 + h - 1);
            cr->stroke();
        }

        if (key_pressed[i]) draw_key(cr, i);

        if (note == 3) draw_digit(cr, i);
    }
}
Exemplo n.º 4
0
void Key::resize( const Declaration &decl ) {
    num_keys = decl.size;
    current_declaration = decl;
    compute_key_size();

    wxClientDC base( this );
    wxBufferedDC dc( &base, *buffer );
    dc.Clear();

    for (int i = 0; i < num_keys; i++)
        draw_key( i, dc );

    wxString str( decl.unit.c_str(), wxConvUTF8 );
    label->SetLabel(wxT("Key (in ") + str + wxT(")"));
}
Exemplo n.º 5
0
void Key::OnResize( wxSizeEvent& )
{
    wxSize size = GetClientSize();
    if ( size == current_size ) return;
    current_size = size;
    buffer.reset( new wxBitmap( size.GetWidth(), size.GetHeight() ) );
    wxClientDC base( this );
    wxBufferedDC dc( &base, *buffer );
    dc.SetBackground( this->GetBackgroundColour() );
    dc.Clear();

    compute_key_size();
    for (int i = 0; i < num_keys; i++)
        draw_key( i, dc );
}
Exemplo n.º 6
0
static void
redraw_handler(struct widget *widget, void *data)
{
	struct keyboard *keyboard = data;
	cairo_surface_t *surface;
	struct rectangle allocation;
	cairo_t *cr;
	unsigned int i;
	unsigned int row = 0, col = 0;
	const struct layout *layout;

	layout = get_current_layout(keyboard->keyboard);

	surface = window_get_surface(keyboard->window);
	widget_get_allocation(keyboard->widget, &allocation);

	cr = cairo_create(surface);
	cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height);
	cairo_clip(cr);

	cairo_select_font_face(cr, "sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
	cairo_set_font_size(cr, 16);

	cairo_translate(cr, allocation.x, allocation.y);

	cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
	cairo_set_source_rgba(cr, 1, 1, 1, 0.75);
	cairo_rectangle(cr, 0, 0, layout->columns * key_width, layout->rows * key_height);
	cairo_paint(cr);

	cairo_set_operator(cr, CAIRO_OPERATOR_OVER);

	for (i = 0; i < layout->count; ++i) {
		cairo_set_source_rgb(cr, 0, 0, 0);
		draw_key(keyboard, &layout->keys[i], cr, row, col);
		col += layout->keys[i].width;
		if (col >= layout->columns) {
			row += 1;
			col = 0;
		}
	}

	cairo_destroy(cr);
	cairo_surface_destroy(surface);
}
Exemplo n.º 7
0
static void draw_keyboard(PhatKeyboard* self)
{
    gint i, pos, note;

    /* make sure our construction properties are set (this is
     * _lame_ass_) */
    if (self->nkeys < 0
        || self->orientation < 0
        || self->label < 0)
        return;

    self->keys = g_new(_Key, self->nkeys);
    self->hold = 0;
    /* orientation */
    if (self->orientation == GTK_ORIENTATION_VERTICAL)
    {
        gtk_widget_set_size_request(GTK_WIDGET(self), PHAT_KEYBOARD_KEY_LENGTH, 0);
        gtk_widget_set_size_request(GTK_WIDGET(self->canvas), PHAT_KEYBOARD_KEY_LENGTH, (PHAT_KEYBOARD_KEY_WIDTH * self->nkeys));
        gnome_canvas_set_scroll_region(self->canvas, 0, 0, PHAT_KEYBOARD_KEY_LENGTH-1, (PHAT_KEYBOARD_KEY_WIDTH * self->nkeys) - 1);
    }
    else
    {
        gtk_widget_set_size_request(GTK_WIDGET(self), 0, PHAT_KEYBOARD_KEY_LENGTH);
        gtk_widget_set_size_request(GTK_WIDGET(self->canvas), (PHAT_KEYBOARD_KEY_WIDTH * self->nkeys), PHAT_KEYBOARD_KEY_LENGTH);
        gnome_canvas_set_scroll_region(self->canvas, 0, 0, (PHAT_KEYBOARD_KEY_WIDTH * self->nkeys) - 1, PHAT_KEYBOARD_KEY_LENGTH-1);
    }

    /* keys */
    if (self->orientation == GTK_ORIENTATION_VERTICAL)
    {
        for (i = note = 0, pos = (PHAT_KEYBOARD_KEY_WIDTH * self->nkeys) - 1; i < self->nkeys; ++i, ++note, pos -= PHAT_KEYBOARD_KEY_WIDTH)
        {
            if (note > 11)
                note = 0;

            switch (note)
            {
            case 0:
            case 2:
            case 4:
            case 5:
            case 7:
            case 9:
            case 11:
                draw_key(self, i, pos, KEY_NAT_BG, KEY_NAT_HI,
                         KEY_NAT_LOW, KEY_NAT_PRE,
                         KEY_NAT_ON, KEY_NAT_SHAD);
                break;
            default:
                draw_key(self, i, pos, KEY_ACC_BG, KEY_ACC_HI,
                         KEY_ACC_LOW, KEY_ACC_PRE,
                         KEY_ACC_ON, KEY_ACC_SHAD);
                break;
            }
        }
    }
    else                        /* gaarrrrrr */
    {
        for (i = note = 0, pos = 0; i < self->nkeys; ++i, ++note, pos += PHAT_KEYBOARD_KEY_WIDTH)
        {
            if (note > 11)
                note = 0;

            switch (note)
            {
            case 0:
            case 2:
            case 4:
            case 5:
            case 7:
            case 9:
            case 11:
                draw_key(self, i, pos, KEY_NAT_BG, KEY_NAT_HI,
                         KEY_NAT_LOW, KEY_NAT_PRE,
                         KEY_NAT_ON, KEY_NAT_SHAD);
                break;
            default:
                draw_key(self, i, pos, KEY_ACC_BG, KEY_ACC_HI,
                         KEY_ACC_LOW, KEY_ACC_PRE,
                         KEY_ACC_ON, KEY_ACC_SHAD);
                break;
            }
        }
    }
}
Exemplo n.º 8
0
/*
void layout_paint(GtkWidget *widget,
                  cairo_t   *cr,
                  GtkRange  *range)
*/
extern gboolean 
layout_expose(GtkWidget *widget,
              GdkEventExpose *event,
              Score_t *score)
{
        cairo_t *cr = gdk_cairo_create(widget->window);

        GList * listrunner_staff = NULL;
        GList * listrunner_object = NULL;

        gint width, height;
        gint i;


        g_assert( score );

        width  = widget->allocation.width;
        height = widget->allocation.height;

        /*
	 * enclosing the painting function in a save/restore pair is a
         * good idea since we'll return to a sane state then
         */

        cairo_save (cr);

        /* clear background */

        cairo_rectangle (cr, 0, 0, width, height);
        cairo_set_source_rgb (cr, 1,1,1);
        cairo_fill (cr);


        /* enclosing in a save/restore pair since we alter the
         * font size
         */
        cairo_save (cr);


        /***************
         * Draw Staves *
         ***************/
        /* We walk through staves */
        listrunner_staff = g_list_first(score->Staff_list);
        while ( listrunner_staff ) {
                measure_number = 1;

                Staff_t *staff;
                staff = (Staff_t *)listrunner_staff->data;

                object_x = staff->extremity_begin_x + Spacings.Clefs.sb + (score->zoom * TREBLE_CLEF_WIDTH_FACTOR) + Spacings.Clefs.sa + get_key_signature_spacing(score, staff) + Spacings.KeySignatures.saks + Spacings.TimeSignatures.width + Spacings.TimeSignatures.sats;

                draw_staff(score, cr, 
                           staff->nb_lines, staff->space_btw_lines,
                           staff->extremity_begin_x, staff->extremity_begin_y,
                           score->staff_extremity_end_x, staff->is_selected);
                
/*                 if ( display->clefs ) */
                        draw_key(score, staff, cr, FALSE);

/*                 if ( display->key_signature ) */
                        draw_key_signature(score, staff, cr, FALSE);

/*                 if ( display->time_signature ) */
                        draw_time_signature(score, staff, cr, FALSE);

		listrunner_object = g_list_first(staff->Object_list);
 		while ( listrunner_object ) { 
 			Object_t *object = NULL;
 			object = (Object_t *)listrunner_object->data;

/*                         g_print("object->pitch = %d \n", object->pitch); */
/*                         g_print("%s:%d: x = %f\n", __FILE__, __LINE__, object_x); */
			
			if (object) {

                                draw_staff_extension(score, staff, cr, object->pitch, object_x);
/*                                 g_print("layout engine, object_type = %d\n", object->type); */

				switch(object->type) {

				case PITCH_CURSOR:
					object_x = draw_pitch_cursor(score, staff, cr, object_x, object->pitch);
				        break;
                                case BARLINE_SINGLE:
                                        object_x = draw_barline_single(score, staff, object, cr, object_x);
                                        break;
				case DOUBLEWHOLE:
                                case DOUBLEWHOLEREST:
				case WHOLE:
                                case WHOLEREST:
				case HALF:
                                case HALFREST:
				case QUARTER:
                                case QUARTERREST:
				case EIGHTH:
                                case EIGHTHREST:
				case SIXTEENTH:
                                case SIXTEENTHREST:
                                        object_x = draw_note_rest(score, staff, object, cr, object_x);
					break;
                                default:
                                        g_print("Unknown object type: %d\n", object->type);

				}
			}
			
			listrunner_object = g_list_next(listrunner_object);
		}
		
                listrunner_staff = g_list_next(listrunner_staff);
        } /* while ( listrunner_staff ) */


        cairo_set_source_rgb (cr, 0, 0, 0);

        /* Show the quarter note head */
/*         cairo_select_font (cr, "gscore", CAIRO_FONT_SLANT_NORMAL, */
/*                            CAIRO_FONT_WEIGHT_BOLD); */
/*         cairo_save (cr); */
/*         cairo_scale_font (cr, 30); */
/*         cairo_move_to (cr, 100.5, 54); */
/*         cairo_set_rgb_color (cr, 0,0,0); */
/*         cairo_show_text (cr, QUARTER_GLYPH); */

        /* Show the stem */
        /* Line */
/*         cairo_move_to(cr, 100.5, 54); */
/*         cairo_rel_line_to(cr, 0, 30.5); */
/*         cairo_stroke(cr); */
/*         /\* Sixteenth *\/ */
/*         cairo_move_to (cr, 101, 84.5); */
/*         cairo_show_text (cr, SIXTEENTH_STEM_DOWN_GLYPH); */


/*         /\* Add a sharp to the note *\/ */
/*         cairo_move_to (cr, 90, 54); */
/*         cairo_scale_font (cr, 1); */
/*         cairo_set_rgb_color (cr, 0,0,0); */
/*         cairo_show_text (cr, SHARP_GLYPH); */
/*         cairo_stroke(cr); */

/*         /\* Show the key *\/ */
/*         cairo_move_to (cr, 15.5, 75); */
/*         cairo_scale_font (cr, 1); */
/*         cairo_set_rgb_color (cr, 0,0,0); */
/*         cairo_show_text (cr, TREBLE_GLYPH); */
/*         cairo_stroke(cr); */

/*         /\* Add 2/4 *\/ */
/*         cairo_move_to (cr, 40, 66.5); */
/*         cairo_scale_font (cr, 0.5); */
/*         cairo_show_text (cr, "2"); */

/*         cairo_move_to (cr, 40, 82.5); */
/*         cairo_show_text (cr, "4"); */


/*         cairo_restore (cr); */

/*         cairo_set_rgb_color (cr, 1,0,0); */
/*         cairo_scale_font (cr, 15); */
/*         cairo_move_to (cr, 50, 100); */


        cairo_stroke (cr);

        cairo_restore (cr);

        selection_paint(cr, score);
}