This repository has been archived by the owner on May 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmetro_callback_v1.c
117 lines (96 loc) · 2.62 KB
/
metro_callback_v1.c
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
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <gtk/gtk.h>
#include <cairo.h>
#include "liste.h"
#define STA_R 3
#define BORD 6
#define BORDD 140
extern Une_coord lim_no;
extern Une_coord lim_se;
extern Un_elem *liste_sta;
extern Un_elem *liste_con;
extern Une_ligne *liste_ligne;
extern GtkWidget *pDA;
int w,h;
double lontox(double lon)
{
return ((lon - lim_no.lon) * w) / (lim_se.lon - lim_no.lon) + BORD;
}
double lattoy(double lat)
{
return ((lim_no.lat - lat) * h) / (lim_no.lat - lim_se.lat) + BORD;
}
double xtolon(int x)
{
return (((x - BORD) * (lim_se.lon - lim_no.lon)) / w) + lim_no.lon;
}
double ytolat(int y)
{
return lim_no.lon - (((y - BORD) * (lim_no.lat - lim_se.lat)) / h);
}
void tracer_liste(Un_elem *liste, cairo_t *cr)
{
double xc, yc;
double xd, yd, xa, ya;
double angle;
double r, v, b;
unsigned int rvb;
Une_coord coord_dep, coord_arr;
cairo_set_line_width (cr, 2);
while(liste)
{
switch (liste->truc->type)
{
case STA :
cairo_set_source_rgb( cr, 0.0, 0.0, 0.0);
xc = lontox(liste->truc->coord.lon);
yc = lattoy(liste->truc->coord.lat);
cairo_new_sub_path(cr);
cairo_arc(cr, xc , yc , STA_R, 0.0, 2 * M_PI);
cairo_move_to (cr, xc + STA_R + 2 ,yc + STA_R);
cairo_show_text(cr, liste->truc->data.sta.nom);
cairo_stroke (cr);
break;
case CON :
// couleur ligne
rvb = strtol(liste->truc->data.con.ligne->color + 1, NULL, 16);
r = (rvb >> 16) / 255.0;
v = ((rvb >> 8) & 0xff) / 255.0;
b = (rvb & 0xff) / 255.0;
cairo_set_source_rgb( cr, r, v, b);
coord_arr = liste->truc->data.con.sta_arr->coord;
coord_dep = liste->truc->data.con.sta_dep->coord;
angle = atan2(coord_arr.lat - coord_dep.lat, coord_arr.lon - coord_dep.lon);
xd = lontox(coord_dep.lon) + (STA_R * cos(angle));
yd = lattoy(coord_dep.lat) - (STA_R * sin(angle));
xa = lontox(coord_arr.lon) + (STA_R * cos(angle + M_PI));
ya = lattoy(coord_arr.lat) - (STA_R * sin(angle + M_PI));
cairo_move_to (cr, xd, yd);
cairo_line_to(cr, xa, ya);
cairo_stroke (cr);
break;
default :
fprintf(stderr, "Erreur : type truc inconnu!!\n");
}
liste = liste->suiv;
}
}
// affichage de l image drawing_area
void OnExpose(GtkWidget* widget, gpointer data)
{
cairo_t *cr;
cr = gdk_cairo_create (pDA->window);
w = pDA->allocation.width - BORD - BORDD;
h = pDA->allocation.height - (2 * BORD);
// peinture du fond
cairo_set_source_rgb( cr, 1.0, 1.0, 1.0);
cairo_paint(cr);
// trace stations
tracer_liste(liste_sta, cr);
// trace connexions
tracer_liste(liste_con, cr);
cairo_destroy(cr);
//cairo_surface_destroy(image);
}