vertices.cxx
Go to the documentation of this file.
1 #include <gtk/gtk.h>
2 #include <vector>
3 #include <stdint.h>
4 #include "event.h"
5 #include "geo.h"
6 #include "drawing.h"
7 #include "vertices.h"
8 
9 extern std::vector<noeevent> theevents;
10 extern std::vector<screenvertex_t> screenvertices[kXorY];
11 extern int gevi;
12 extern int pixx, pixy;
13 extern int active_vertex;
14 
15 static std::pair<int, int> draw_vertex_in_one_view(cairo_t * cr,
16  const cppoint & pos,
17  const bool active)
18 {
19  std::pair<int, int> screenpoint = cppoint_to_screen(pos);
20 
21  if(active) cairo_set_source_rgb(cr, 1.0, 0.5, 0.5);
22  else cairo_set_source_rgb(cr, 0.8, 0.0, 0.8);
23  cairo_set_line_width(cr, 1);
24 
25  // As with tracks, don't bother checking if we're in view since drawing is
26  // fairly cheap.
27 
28  const int starsize = 6;
29 
30  cairo_move_to(cr, screenpoint.first-starsize+0.5, screenpoint.second-starsize+0.5);
31  cairo_line_to(cr, screenpoint.first+starsize+0.5, screenpoint.second+starsize+0.5);
32  cairo_stroke(cr);
33 
34  cairo_move_to(cr, screenpoint.first+starsize+0.5, screenpoint.second-starsize+0.5);
35  cairo_line_to(cr, screenpoint.first-starsize+0.5, screenpoint.second+starsize+0.5);
36  cairo_stroke(cr);
37 
38  cairo_move_to(cr, screenpoint.first-starsize+0.5, screenpoint.second+0.5);
39  cairo_line_to(cr, screenpoint.first+starsize+0.5, screenpoint.second+0.5);
40  cairo_stroke(cr);
41 
42  cairo_move_to(cr, screenpoint.first+0.5, screenpoint.second-starsize+0.5);
43  cairo_line_to(cr, screenpoint.first+0.5, screenpoint.second+starsize+0.5);
44  cairo_stroke(cr);
45 
46  return screenpoint;
47 }
48 
49 void draw_vertices(cairo_t ** cr, const DRAWPARS * const drawpars)
50 {
51  for(int V = 0; V < kXorY; V++){
52  if(drawpars->clear) screenvertices[V].clear();
53  for(unsigned int i = 0; i < theevents[gevi].vertices.size(); i++){
54  vertex & vert = theevents[gevi].vertices[i];
55  if((int)i != active_vertex &&
56  vert.time >= drawpars->firsttick && vert.time <= drawpars->lasttick){
57  screenvertex_t sv;
58  sv.pos = draw_vertex_in_one_view(cr[V], vert.pos[V], false);
59  sv.i = i;
60  screenvertices[V].push_back(sv);
61  }
62  }
63 
64  // Draw the active vertex last so it is on top
65  if(active_vertex >= 0){
66  vertex & vert = theevents[gevi].vertices[active_vertex];
67  if(vert.time >= drawpars->firsttick && vert.time <= drawpars->lasttick){
68  screenvertex_t sv;
69  sv.pos = draw_vertex_in_one_view(cr[V], vert.pos[V], true);
70  sv.i = active_vertex;
71  screenvertices[V].push_back(sv);
72  }
73  }
74  }
75 }
std::pair< int, int > pos
Definition: vertices.h:3
Definition: event.h:34
Supply basic geometry functions.
int pixx
Definition: geo.cxx:24
Definition: geo.h:1
int gevi
Definition: main.cxx:76
void draw_vertices(cairo_t **cr, const DRAWPARS *const drawpars)
Definition: vertices.cxx:49
cppoint pos[2]
Definition: event.h:35
bool clear
Definition: drawing.h:5
int pixy
Definition: geo.cxx:24
std::pair< int, int > cppoint_to_screen(const cppoint &tp)
Definition: geo.cxx:139
std::vector< screenvertex_t > screenvertices[kXorY]
Definition: active.cxx:24
int32_t firsttick
Definition: drawing.h:4
Definition: event.h:9
int32_t lasttick
Definition: drawing.h:4
static std::pair< int, int > draw_vertex_in_one_view(cairo_t *cr, const cppoint &pos, const bool active)
Definition: vertices.cxx:15
int active_vertex
Definition: main.cxx:78
std::vector< noeevent > theevents
Definition: noe_module.cc:28
int32_t time
Definition: event.h:37