summaryrefslogtreecommitdiff
path: root/src/drawcursor.c
blob: b24897f92b43c6b64c5cd22bd2407f52937e6437 (plain)
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
/* drawcursor.c
 * functions for drawing the cursor
 *
 * for Denemo, a gtk+ frontend to GNU Lilypond
 * (c) 1999-2005  Matthew Hiller, Adam Tee, 2010 Richard Shann
 */
#include <math.h>
#include "drawingprims.h"
#include "gcs.h"
#include "utils.h"


#define CURSOR_WIDTH 10
#define CURSOR_HEIGHT 6
#define CURSOR_MINUS (CURSOR_HEIGHT/2)

/**
 * Draw the cursor on the canvas at the given position
 * insert_control is the last gap from the previous note except when the cursor is on a measure boundary in which case it is +1 or -1 to indicate where next inserted note will go.
 */
void
draw_cursor (cairo_t *cr, DenemoScore * si,
	     gint xx, gint y, gint insert_control, input_mode mode, gint dclef)
{
  if(!cr) return;
  gint height = calculateheight (si->cursor_y, dclef);

  static GdkGC *blackgc = NULL;
  static GdkGC *graygc;
  static GdkGC *greengc;
  static GdkGC *redgc;
  static GdkGC *bluegc;
  static GdkGC *purplegc;
  GdkGC *paintgc;
  //xx -=5;
  if (!blackgc)
    {
      blackgc = gcs_blackgc ();
      graygc = gcs_graygc ();
      greengc = gcs_greengc ();
      redgc = gcs_redgc ();
      bluegc = gcs_bluegc ();
      purplegc = gcs_purplegc ();
    }

  paintgc = (mode & INPUTREST) ? graygc :
    (mode & INPUTBLANK) ? bluegc : si->cursoroffend ? redgc : greengc;

  if(si->cursor_appending)
    paintgc = si->cursoroffend ? redgc :bluegc;

  cairo_save( cr );
  setcairocolor( cr, paintgc );
  if(si->cursor_appending)
    cairo_rectangle( cr, xx-(si->cursoroffend?CURSOR_WIDTH:0), height + y - CURSOR_HEIGHT, 2*CURSOR_WIDTH, 2*CURSOR_HEIGHT );
  else
    cairo_rectangle( cr, xx, height + y - CURSOR_MINUS, CURSOR_WIDTH, CURSOR_HEIGHT );
  cairo_fill( cr );

  {
    gdouble length = 20/si->zoom;
    gdouble insert_pos = CURSOR_WIDTH*0.8;
    if(!si->cursor_appending) {
      insert_pos = -insert_control/4;
    }
    else
      if(si->cursoroffend)
	insert_pos = insert_control * CURSOR_WIDTH;
    static gboolean on;
    on = !on;
    // g_print("on is %d %d\n", on,  Denemo.prefs.cursor_highlight);
    if( (!Denemo.prefs.cursor_highlight) || (on && Denemo.prefs.cursor_highlight)) {
      setcairocolor( cr, bluegc );
      cairo_set_line_width (cr, 4);
      cairo_move_to( cr, xx+insert_pos, y + 4);
      cairo_rel_line_to( cr, 0, STAFF_HEIGHT - 8);
      cairo_stroke( cr );
      setcairocolor( cr, paintgc );
      
      if (Denemo.gui->view == DENEMO_PAGE_VIEW)  {
	cairo_set_line_width (cr, 6.0/si->zoom);
	cairo_set_source_rgba (cr, 0, 1, 0, 0.40);    
	cairo_arc(cr, xx + CURSOR_WIDTH/2, height + y, length, 0, 2 * M_PI);
	cairo_stroke( cr );
      }
    }
  }
    cairo_restore( cr );
    
    /* Now draw ledgers if necessary and we're done */
    draw_ledgers (cr, height, height, xx, y, CURSOR_WIDTH);
 }