10 #include "transform.h"
11 #include "projection.h"
14 #include "statusbar.h"
22 /* #include "track.h" */
28 struct graphics_gc *cursor_gc;
29 struct transformation *trans;
30 struct point cursor_pnt;
31 struct callback_list *update_cbl;
33 struct callback *vehicle_cb;
41 cursor_pos_get(struct cursor *this)
45 return vehicle_pos_get(this->v);
51 cursor_pos_set(struct cursor *this, struct coord *pos)
55 return vehicle_pos_get(this->v);
61 cursor_draw(struct cursor *this, struct point *pnt, int dir, int draw_dir)
63 int x=this->cursor_pnt.x;
64 int y=this->cursor_pnt.y;
69 struct graphics *gra=this->gra;
71 if (pnt && x == pnt->x && y == pnt->y)
73 if (!graphics_ready(gra))
75 cpnt[0]=this->cursor_pnt;
78 graphics_draw_restore(gra, &cpnt[0], (r+lw)*2, (r+lw)*2);
80 graphics_draw_mode(gra, draw_mode_cursor);
81 this->cursor_pnt=*pnt;
86 graphics_draw_circle(gra, this->cursor_gc, &cpnt[0], r*2);
88 dx=sin(M_PI*dir/180.0);
89 dy=-cos(M_PI*dir/180.0);
93 cpnt[0].x=x-dx*fac1+dy*fac2;
94 cpnt[0].y=y-dy*fac1-dx*fac2;
97 cpnt[2].x=x-dx*fac1-dy*fac2;
98 cpnt[2].y=y-dy*fac1+dx*fac2;
99 graphics_draw_lines(gra, this->cursor_gc, cpnt, 3);
102 graphics_draw_lines(gra, this->cursor_gc, cpnt, 2);
104 graphics_draw_mode(gra, draw_mode_end);
109 cursor_redraw(struct cursor *this)
112 transform(this->trans, this->pro, &this->pos, &pnt);
113 cursor_draw(this, &pnt, this->dir-transform_get_angle(this->trans, 0), this->speed > 2.5);
118 cursor_map_reposition_screen(struct cursor *this, struct coord *c, double *dir, int x_new, int y_new)
121 struct transformation tr;
126 struct container *co=this->co;
133 pnt.x=co->trans->width-x_new;
134 pnt.y=co->trans->height-y_new;
135 graphics_get_view(co, &x, &y, &scale);
137 transform_setup(&tr, c->x, c->y, scale, dir_i);
138 transform_reverse(&tr, &pnt, &c_new);
139 printf("%lx %lx vs %lx %lx\n", c->x, c->y, c_new.x, c_new.y);
142 transform_set_angle(co->trans,dir_i);
143 graphics_set_view(co, &x, &y, &scale);
147 cursor_map_reposition(struct cursor *this, struct coord *c, double *dir)
149 if (this->co->flags->orient_north) {
150 graphics_set_view(this->co, &c->x, &c->y, NULL);
152 cursor_map_reposition_screen(this, c, dir, this->co->trans->width/2, this->co->trans->height*0.8);
157 cursor_map_reposition_boundary(struct cursor *this, struct coord *c, double *dir, struct point *pnt)
159 struct point pnt_new;
160 struct transformation *t=this->co->trans;
164 if (pnt->x < 0.1*t->width) {
165 pnt_new.x=0.8*t->width;
166 pnt_new.y=t->height/2;
168 if (pnt->x > 0.9*t->width) {
169 pnt_new.x=0.2*t->width;
170 pnt_new.y=t->height/2;
172 if (pnt->y < (this->co->flags->orient_north ? 0.1 : 0.5)*t->height) {
173 pnt_new.x=t->width/2;
174 pnt_new.y=0.8*t->height;
176 if (pnt->y > 0.9*t->height) {
177 pnt_new.x=t->width/2;
178 pnt_new.y=0.2*t->height;
180 if (pnt_new.x != -1) {
181 if (this->co->flags->orient_north) {
182 cursor_map_reposition_screen(this, c, NULL, pnt_new.x, pnt_new.y);
184 cursor_map_reposition(this, c, dir);
194 cursor_get_dir(struct cursor *this)
200 cursor_get_speed(struct cursor *this)
206 cursor_update(struct cursor *this, struct vehicle *v)
215 pos=vehicle_pos_get(v);
216 dir=vehicle_dir_get(v);
217 speed=vehicle_speed_get(v);
218 pro=vehicle_projection(v);
223 callback_list_call_1(this->update_cbl, this);
224 transform(this->trans, pro, &this->pos, &pnt);
225 cursor_draw(this, &pnt, *dir-transform_get_angle(this->trans, 0), *speed > 2.5);
228 compass_draw(this->co->compass, this->co);
233 cursor_new(struct graphics *gra, struct vehicle *v, struct color *c, struct transformation *t)
235 dbg(2,"enter gra=%p v=%p c=%p t=%p\n", gra, v, c, t);
236 struct cursor *this=g_new(struct cursor,1);
238 this->offscreen_cbl=callback_list_new();
240 this->update_cbl=callback_list_new();
243 this->cursor_gc=graphics_gc_new(gra);
245 graphics_gc_set_foreground(this->cursor_gc, c);
246 graphics_gc_set_linewidth(this->cursor_gc, 2);
247 this->vehicle_cb=callback_new_1(callback_cast(cursor_update), this);
248 vehicle_callback_add(v, this->vehicle_cb);
249 dbg(2,"ret=%p\n", this);
254 cursor_add_callback(struct cursor *this, struct callback *cb)
256 callback_list_add(this->update_cbl, cb);