/[zanavi_public1]/navit/navit/vehicle.c
ZANavi

Diff of /navit/navit/vehicle.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 28 Revision 30
48#include "plugin.h" 48#include "plugin.h"
49#include "transform.h" 49#include "transform.h"
50#include "util.h" 50#include "util.h"
51#include "event.h" 51#include "event.h"
52#include "coord.h" 52#include "coord.h"
53#include "navit.h"
53#include "transform.h" 54#include "transform.h"
54#include "projection.h" 55#include "projection.h"
55#include "point.h" 56#include "point.h"
56#include "graphics.h" 57#include "graphics.h"
57#include "callback.h" 58#include "callback.h"
58#include "color.h" 59#include "color.h"
59#include "layout.h" 60#include "layout.h"
60#include "vehicle.h" 61#include "vehicle.h"
62
63// forward rev
64struct navit *global_navit;
65
61 66
62struct vehicle 67struct vehicle
63{ 68{
64 struct vehicle_methods meth; 69 struct vehicle_methods meth;
65 struct vehicle_priv *priv; 70 struct vehicle_priv *priv;
286 this_->gpx_desc = attr->u.str; 291 this_->gpx_desc = attr->u.str;
287 } 292 }
288 293
289 if (ret == 1 && attr->type != attr_navit && attr->type != attr_pdl_gps_update) 294 if (ret == 1 && attr->type != attr_navit && attr->type != attr_pdl_gps_update)
290 { 295 {
291 dbg(0,"xx 3\n"); 296 //dbg(0,"xx 3\n");
292 this_->attrs = attr_generic_set_attr(this_->attrs, attr); 297 this_->attrs = attr_generic_set_attr(this_->attrs, attr);
293 } 298 }
294 299
295#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT 300#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
296 dbg(0,"+#+:leave\n"); 301 dbg(0,"+#+:leave\n");
389 struct point sc; 394 struct point sc;
390 if (this_->cursor_fixed && !overwrite) 395 if (this_->cursor_fixed && !overwrite)
391 { 396 {
392 return; 397 return;
393 } 398 }
399
400#if 0
394 if (this_->animate_callback) 401 if (this_->animate_callback)
395 { 402 {
396 event_remove_timeout(this_->animate_timer); 403 event_remove_timeout(this_->animate_timer);
397 this_->animate_timer = NULL; // dangling pointer! prevent double freeing. 404 this_->animate_timer = NULL; // dangling pointer! prevent double freeing.
398 callback_destroy(this_->animate_callback); 405 callback_destroy(this_->animate_callback);
399 this_->animate_callback = NULL; // dangling pointer! prevent double freeing. 406 this_->animate_callback = NULL; // dangling pointer! prevent double freeing.
400 } 407 }
408
401 if (cursor && cursor->interval) 409 if (cursor && cursor->interval)
402 { 410 {
403 this_->animate_callback = callback_new_2(callback_cast(vehicle_draw_do), this_, 0); 411 this_->animate_callback = callback_new_2(callback_cast(vehicle_draw_do), this_, 0);
404 dbg(0, "event_add_timeout %d,%d,%p", cursor->interval, 1, this_->animate_callback); 412 //dbg(0, "event_add_timeout %d,%d,%p", cursor->interval, 1, this_->animate_callback);
405 this_->animate_timer = event_add_timeout(cursor->interval, 1, this_->animate_callback); 413 this_->animate_timer = event_add_timeout(cursor->interval, 1, this_->animate_callback);
406 } 414 }
407 415
408 if (cursor && this_->gra && this_->cursor) 416 if (cursor && this_->gra && this_->cursor)
409 { 417 {
410 this_->cursor_pnt.x += (this_->cursor->w - cursor->w) / 2; 418 this_->cursor_pnt.x += (this_->cursor->w - cursor->w) / 2;
411 this_->cursor_pnt.y += (this_->cursor->h - cursor->h) / 2; 419 this_->cursor_pnt.y += (this_->cursor->h - cursor->h) / 2;
412 graphics_overlay_resize(this_->gra, &this_->cursor_pnt, cursor->w, cursor->h, 65535, 0); 420 graphics_overlay_resize(this_->gra, &this_->cursor_pnt, cursor->w, cursor->h, 65535, 0);
413 } 421 }
422#endif
423
424 // ###############################################
425 // ###############################################
426 // set fixed size of navigation cursor to 50,50 !!
427 if (cursor)
428 {
429 cursor->w = 50;
430 cursor->h = 50;
431 }
432
433 if (this_->cursor)
434 {
435 this_->cursor->w = 50;
436 this_->cursor->h = 50;
437 }
438 // set fixed size of navigation cursor to 50,50 !!
439 // ###############################################
440 // ###############################################
441
414 442
415 if (cursor) 443 if (cursor)
416 { 444 {
417 sc.x = cursor->w / 2; 445 sc.x = cursor->w / 2;
418 sc.y = cursor->h / 2; 446 sc.y = cursor->h / 2;
419 if (!this_->cursor && this_->gra) 447 //if (!this_->cursor && this_->gra)
448 //{
420 graphics_overlay_disable(this_->gra, 0); 449 // graphics_overlay_disable(this_->gra, 0);
450 //}
421 } 451 }
422 else 452 else
423 { 453 {
424 sc.x = sc.y = 0; 454 sc.x = sc.y = 0;
425 if (this_->cursor && this_->gra) 455 //if (this_->cursor && this_->gra)
456 //{
426 graphics_overlay_disable(this_->gra, 1); 457 // graphics_overlay_disable(this_->gra, 1);
458 //}
427 } 459 }
460
428 transform_set_screen_center(this_->trans, &sc); 461 transform_set_screen_center(this_->trans, &sc);
429 462
430 this_->cursor = cursor; 463 this_->cursor = cursor;
431 464
432#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT 465#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
476{ 509{
477#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT 510#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
478 dbg(0,"+#+:enter\n"); 511 dbg(0,"+#+:enter\n");
479#endif 512#endif
480 513
481 if (hold_drawing > 0) 514 //if (hold_drawing > 0)
482 { 515 //{
483 return; 516 // return;
484 } 517 //}
485 518
486 if (angle < 0) 519 if (angle < 0)
520 {
487 angle += 360; 521 angle += 360;
522 }
523
488 //// dbg(1, "enter this=%p gra=%p pnt=%p lazy=%d dir=%d speed=%d\n", this_, gra, 524 //// dbg(1, "enter this=%p gra=%p pnt=%p lazy=%d dir=%d speed=%d\n", this_, gra,
489 // pnt, lazy, angle, speed); 525 // pnt, lazy, angle, speed);
490 //// dbg(1, "point %d,%d\n", pnt->x, pnt->y); 526 //dbg(0, "point %d,%d\n", pnt->x, pnt->y);
491 this_->cursor_pnt = *pnt; 527 this_->cursor_pnt = *pnt;
492 this_->angle = angle; 528 this_->angle = angle;
493 this_->speed = speed; 529 this_->speed = speed;
494 if (!this_->cursor) 530 if (!this_->cursor)
531 {
495 return; 532 return;
533 }
534
535 //dbg(0,"cpx:%d, cpy:%d, cw:%d, ch:%d\n", this_->cursor_pnt.x, this_->cursor_pnt.y, this_->cursor->w, this_->cursor->h);
536
496 this_->cursor_pnt.x -= this_->cursor->w / 2; 537 //*** this_->cursor_pnt.x -= this_->cursor->w / 2;
497 this_->cursor_pnt.y -= this_->cursor->h / 2; 538 //*** this_->cursor_pnt.y -= this_->cursor->h / 2;
539
540#if 0
498 if (!this_->gra) 541 if (!this_->gra)
499 { 542 {
500 struct color c; 543 struct color c;
544 dbg(0,"Create new Vehicle Overlay Graphics\n");
501 this_->gra = graphics_overlay_new(gra, &this_->cursor_pnt, this_->cursor->w, this_->cursor->h, 65535, 0); 545 this_->gra = graphics_overlay_new("type:vehicle",gra, &this_->cursor_pnt, this_->cursor->w, this_->cursor->h, 65535, 0);
502 if (this_->gra) 546 if (this_->gra)
503 { 547 {
504 this_->bg = graphics_gc_new(this_->gra); 548 this_->bg = graphics_gc_new(this_->gra);
505 c.r = 0; 549 c.r = 0;
506 c.g = 0; 550 c.g = 0;
508 c.a = 0; 552 c.a = 0;
509 graphics_gc_set_foreground(this_->bg, &c); 553 graphics_gc_set_foreground(this_->bg, &c);
510 graphics_background_gc(this_->gra, this_->bg); 554 graphics_background_gc(this_->gra, this_->bg);
511 } 555 }
512 } 556 }
557#endif
513 558
559
560 // ++++++++++ // transform_set_yaw(this_->trans, -this_->angle);
514 vehicle_draw_do(this_, lazy); 561 // vehicle_draw_do(this_, lazy);
562
563#ifdef HAVE_API_ANDROID
564 //dbg(0,"x=%d y=%d angle=%d speed=%d\n",this_->cursor_pnt.x, this_->cursor_pnt.y, angle, speed);
565
566 //int dx = 0;
567 //int dy = 0;
568 //int dangle = 0;
569
570 //struct navit_vehicle *nv2 = global_navit->vehicle;
571 //struct point pnt2;
572 //dbg(0,"dir=%d dx=%d, dy=%d\n", nv2->dir, dx, dy);
573 //transform(this_->trans, projection_mg, &nv2->coord, &pnt2, 1, 0, 0, NULL);
574 //dbg(0,"px=%d, py=%d\n", pnt2.x, pnt2.y);
575
576 set_vehicle_values_to_java(this_->cursor_pnt.x, this_->cursor_pnt.y, angle, speed);
577#endif
578
515} 579}
516 580
517int vehicle_get_cursor_data(struct vehicle *this, struct point *pnt, int *angle, int *speed) 581int vehicle_get_cursor_data(struct vehicle *this, struct point *pnt, int *angle, int *speed)
518{ 582{
519#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT 583#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
525 return 1; 589 return 1;
526} 590}
527 591
528static void vehicle_draw_do(struct vehicle *this_, int lazy) 592static void vehicle_draw_do(struct vehicle *this_, int lazy)
529{ 593{
530#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT 594 // UNUSED ---------
531 dbg(0,"+#+:enter\n");
532#endif
533
534 if (hold_drawing > 0)
535 {
536 return;
537 }
538
539 struct point p;
540 struct cursor *cursor = this_->cursor;
541 int speed = this_->speed;
542 int angle = this_->angle;
543 int sequence = this_->sequence;
544 struct attr **attr;
545 char *label = NULL;
546 int match = 0;
547
548 if (!this_->cursor || !this_->cursor->attrs || !this_->gra)
549 return;
550
551 attr = this_->attrs;
552 while (attr && *attr)
553 {
554 if ((*attr)->type == attr_name)
555 label = (*attr)->u.str;
556 attr++;
557 }
558 transform_set_yaw(this_->trans, -this_->angle);
559 graphics_draw_mode(this_->gra, draw_mode_begin);
560 p.x = 0;
561 p.y = 0;
562 graphics_draw_rectangle(this_->gra, this_->bg, &p, cursor->w, cursor->h);
563 attr = cursor->attrs;
564 while (*attr)
565 {
566 if ((*attr)->type == attr_itemgra)
567 {
568 struct itemgra *itm = (*attr)->u.itemgra;
569 //// dbg(1, "speed %d-%d %d\n", itm->speed_range.min,
570 // itm->speed_range.max, speed);
571 if (speed >= itm->speed_range.min && speed <= itm->speed_range.max && angle >= itm->angle_range.min && angle <= itm->angle_range.max && sequence >= itm->sequence_range.min && sequence <= itm->sequence_range.max)
572 {
573 graphics_draw_itemgra(this_->gra, itm, this_->trans, label);
574 }
575 if (sequence < itm->sequence_range.max)
576 match = 1;
577 }
578 ++attr;
579 }
580 graphics_draw_drag(this_->gra, &this_->cursor_pnt);
581 graphics_draw_mode(this_->gra, lazy ? draw_mode_end_lazy : draw_mode_end);
582 if (this_->animate_callback)
583 {
584 ++this_->sequence;
585 if (cursor->sequence_range && cursor->sequence_range->max < this_->sequence)
586 this_->sequence = cursor->sequence_range->min;
587 if (!match && !cursor->sequence_range)
588 this_->sequence = 0;
589 }
590} 595}
591 596
592/** 597/**
593 * Writes to an NMEA log. 598 * Writes to an NMEA log.
594 * 599 *

Legend:
Removed from v.28  
changed lines
  Added in v.30

   
Visit the ZANavi Wiki