Example #1
0
static void
vehicle_android_callback(struct vehicle_priv *v, jobject location)
{
	time_t tnow;
	struct tm *tm;
	dbg(1,"enter\n");

	v->geo.lat = (*jnienv)->CallDoubleMethod(jnienv, location, v->Location_getLatitude);
	v->geo.lng = (*jnienv)->CallDoubleMethod(jnienv, location, v->Location_getLongitude);
	v->speed = (*jnienv)->CallFloatMethod(jnienv, location, v->Location_getSpeed)*3.6;
	v->direction = (*jnienv)->CallFloatMethod(jnienv, location, v->Location_getBearing);
	v->height = (*jnienv)->CallDoubleMethod(jnienv, location, v->Location_getAltitude);
	tnow=(*jnienv)->CallLongMethod(jnienv, location, v->Location_getTime)/1000;
	tm = gmtime(&tnow);
	strftime(v->fixiso8601, sizeof(v->fixiso8601), "%Y-%m-%dT%TZ", tm);
	dbg(1,"lat %f lon %f time %s\n",v->geo.lat,v->geo.lng,v->fixiso8601);
	v->have_coords=1;
	callback_list_call_0(v->cbl);
}
Example #2
0
static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{

    struct graphics_priv* gra_priv = (struct graphics_priv*)GetWindowLongPtr( hwnd , DWLP_USER );

    switch (Message)
    {
    case WM_CREATE:
    {
        if ( gra_priv )
        {
            RECT rc ;

            GetClientRect( hwnd, &rc );
            gra_priv->width = rc.right;
            gra_priv->height = rc.bottom;
            create_memory_dc(gra_priv);
        }
    }
    break;
    case WM_COMMAND:
        switch (LOWORD(wParam))
        {
        case WM_USER + 1:
            break;
        }
        break;
    case WM_CLOSE:
        DestroyWindow(hwnd);
        break;
    case WM_USER+1:
        if ( gra_priv )
        {
            RECT rc ;

            GetClientRect( hwnd, &rc );
            gra_priv->width = rc.right;
            gra_priv->height = rc.bottom;

            create_memory_dc(gra_priv);
            callback_list_call_attr_2(gra_priv->cbl, attr_resize, (void *)gra_priv->width, (void *)gra_priv->height);
        }
        break;
    case WM_USER+2:
    {
        struct callback_list *cbl = (struct callback_list*)wParam;
#ifdef HAVE_API_WIN32_CE
        /* FIXME: Reset the idle timer  need a better place */
        SystemIdleTimerReset();
#endif
        callback_list_call_0(cbl);
    }
    break;

    case WM_SIZE:
        if ( gra_priv )
        {
            gra_priv->width = LOWORD( lParam );
            gra_priv->height  = HIWORD( lParam );
            create_memory_dc(gra_priv);
            dbg(0, "resize gfx to: %d %d \n", gra_priv->width, gra_priv->height );
            callback_list_call_attr_2(gra_priv->cbl, attr_resize, (void *)gra_priv->width, (void *)gra_priv->height);
        }
        break;
    case WM_DESTROY:
#ifdef HAVE_API_WIN32_CE
        if ( gra_priv && gra_priv->window.priv )
        {
            struct window_priv *win_priv = gra_priv->window.priv;
            if (win_priv->hBackLight)
            {
                ReleasePowerRequirement(win_priv->hBackLight);
            }
        }
#endif
        PostQuitMessage(0);
        break;
    case WM_PAINT:
        if ( gra_priv && gra_priv->hMemDC)
        {
    	    struct graphics_priv* overlay;
            PAINTSTRUCT ps = { 0 };
            HDC hdc;
            profile(0, NULL);
            dbg(1, "WM_PAINT\n");
            overlay = gra_priv->overlays;

#ifndef FAST_TRANSPARENCY
			BitBlt( gra_priv->hPrebuildDC, 0, 0, gra_priv->width , gra_priv->height, gra_priv->hMemDC, 0, 0, SRCCOPY);
#endif
			while ( !gra_priv->disabled && overlay)
			{
				if ( !overlay->disabled && overlay->p.x >= 0 &&
					 overlay->p.y >= 0 &&
					 overlay->p.x < gra_priv->width &&
					 overlay->p.y < gra_priv->height )
				{
					int x,y;
					int destPixel, srcPixel;
                    int h,w;
#ifdef FAST_TRANSPARENCY
					if ( !overlay->hPrebuildDC )
					{
						overlay->hPrebuildBitmap = CreateBitmap(overlay->width,overlay->height,1,1,NULL);
						overlay->hPrebuildDC = CreateCompatibleDC(NULL);
						overlay->hOldPrebuildBitmap = SelectBitmap( overlay->hPrebuildDC, overlay->hPrebuildBitmap);
						SetBkColor(overlay->hMemDC,RGB(overlay->transparent_color.r >> 8,overlay->transparent_color.g >> 8,overlay->transparent_color.b >> 8));
						BitBlt(overlay->hPrebuildDC,0,0,overlay->width,overlay->height,overlay->hMemDC,0,0,SRCCOPY);
						BitBlt(overlay->hMemDC,0,0,overlay->width,overlay->height,overlay->hPrebuildDC,0,0,SRCINVERT);
					}

#else
					const COLORREF transparent_color = RGB(overlay->transparent_color.r >> 8,overlay->transparent_color.g >> 8,overlay->transparent_color.b >> 8);

					BitBlt( overlay->hPrebuildDC, 0, 0, overlay->width , overlay->height, overlay->hMemDC, 0, 0, SRCCOPY);

					h=overlay->height;
					w=overlay->width;
					if (w > gra_priv->width-overlay->p.x)
						w=gra_priv->width-overlay->p.x;
					if (h > gra_priv->height-overlay->p.y)
						h=gra_priv->height-overlay->p.y;
					for ( y = 0; y < h ;y++ )
					{
						for ( x = 0; x < w; x++ )
						{
							srcPixel = y*overlay->width+x;
							destPixel = ((overlay->p.y + y) * gra_priv->width) + (overlay->p.x + x);
							if ( overlay->pPixelData[srcPixel] == transparent_color )
							{
								destPixel = ((overlay->p.y + y) * gra_priv->width) + (overlay->p.x + x);

								gra_priv->pPixelData[destPixel] = RGB ( ((65535 - overlay->transparent_color.a) * GetRValue(gra_priv->pPixelData[destPixel]) + overlay->transparent_color.a * GetRValue(overlay->pPixelData[srcPixel])) / 65535,
																((65535 - overlay->transparent_color.a) * GetGValue(gra_priv->pPixelData[destPixel]) + overlay->transparent_color.a * GetGValue(overlay->pPixelData[srcPixel])) / 65535,
																((65535 - overlay->transparent_color.a) * GetBValue(gra_priv->pPixelData[destPixel]) + overlay->transparent_color.a * GetBValue(overlay->pPixelData[srcPixel])) / 65535);

							}
							else
							{
								gra_priv->pPixelData[destPixel] = overlay->pPixelData[srcPixel];
							}
						}

					}
#endif
				}
				overlay = overlay->next;
			}


#ifndef FAST_TRANSPARENCY
            hdc = BeginPaint(hwnd, &ps);
            BitBlt( hdc, 0, 0, gra_priv->width , gra_priv->height, gra_priv->hPrebuildDC, 0, 0, SRCCOPY );
#else
            HDC hdc = BeginPaint(hwnd, &ps);

            BitBlt( hdc, 0, 0, gra_priv->width , gra_priv->height, gra_priv->hMemDC, 0, 0, SRCCOPY );

            overlay = gra_priv->overlays;
            while ( !gra_priv->disabled && overlay && !overlay->disabled )
            {
                if ( overlay->p.x > 0 &&
                        overlay->p.y > 0 &&
                        overlay->p.x + overlay->width < gra_priv->width &&
                        overlay->p.y + overlay->height < gra_priv->height )
                {
                    BitBlt(hdc,overlay->p.x,overlay->p.y,overlay->width,overlay->height,overlay->hPrebuildDC,0,0,SRCAND);
                    BitBlt(hdc,overlay->p.x,overlay->p.y,overlay->width,overlay->height,overlay->hMemDC,0,0,SRCPAINT);
                }
                overlay = overlay->next;
            }
#endif
            EndPaint(hwnd, &ps);
            profile(0, "WM_PAINT\n");
        }
Example #3
0
static void
vehicle_demo_timer(struct vehicle_priv *priv)
{
	struct coord c, c2, pos, ci;
	int slen, len, dx, dy;
	struct route *route=NULL;
	struct map *route_map=NULL;
	struct map_rect *mr=NULL;
	struct item *item=NULL;

	len = (priv->config_speed * priv->interval / 1000)/ 3.6;
	dbg(1, "###### Entering simulation loop\n");
	if (priv->navit) 
		route=navit_get_route(priv->navit);
	if (route)
		route_map=route_get_map(route);
	if (route_map)
		mr=map_rect_new(route_map, NULL);
	if (mr) 
		item=map_rect_get_item(mr);
	if (item && item->type == type_route_start)
		item=map_rect_get_item(mr);
	if (item && item_coord_get(item, &pos, 1)) {
		priv->position_set=0;
		dbg(1, "current pos=0x%x,0x%x\n", pos.x, pos.y);
		dbg(1, "last pos=0x%x,0x%x\n", priv->last.x, priv->last.y);
		if (priv->last.x == pos.x && priv->last.y == pos.y) {
			dbg(1, "endless loop\n");
		}
		priv->last = pos;
		while (item && priv->config_speed) {
			if (!item_coord_get(item, &c, 1)) {
				item=map_rect_get_item(mr);
				continue;
			}
			dbg(1, "next pos=0x%x,0x%x\n", c.x, c.y);
			slen = transform_distance(projection_mg, &pos, &c);
			dbg(1, "len=%d slen=%d\n", len, slen);
			if (slen < len) {
				len -= slen;
				pos = c;
			} else {
				if (item_coord_get(item, &c2, 1) || map_rect_get_item(mr)) {
					dx = c.x - pos.x;
					dy = c.y - pos.y;
					ci.x = pos.x + dx * len / slen;
					ci.y = pos.y + dy * len / slen;
					priv->direction =
					    transform_get_angle_delta(&pos, &c, 0);
					priv->speed=priv->config_speed;
				} else {
					ci.x = pos.x;
					ci.y = pos.y;
					priv->speed=0;
					dbg(0,"destination reached\n");
				}
				dbg(1, "ci=0x%x,0x%x\n", ci.x, ci.y);
				transform_to_geo(projection_mg, &ci,
						 &priv->geo);
				callback_list_call_0(priv->cbl);
				break;
			}
		}
	} else {
		if (priv->position_set) 
			callback_list_call_0(priv->cbl);
	}
	if (mr)
		map_rect_destroy(mr);
}
Example #4
0
static int
vehicle_demo_timer(struct vehicle_priv *priv)
{
	struct route_path_coord_handle *h;
	struct coord *c, *pos, ci;
	int slen, len, dx, dy;

	priv->speed = 40;
	len = priv->speed / 3.6;
	dbg(1, "###### Entering simulation loop\n");
	if (!priv->navit) {
		dbg(1, "vehicle->navit is not set. Can't simulate\n");
		return 1;
	}
	struct route *vehicle_route = navit_get_route(priv->navit);
	if (!vehicle_route) {
		dbg(1, "navit_get_route NOK\n");
		return 1;
	}

	h = route_path_coord_open(vehicle_route);
	if (!h) {
		dbg(1, "navit_path_coord_open NOK\n");
		return 1;
	}
	pos = route_path_coord_get(h);
	dbg(1, "current pos=%p\n", pos);
	if (pos) {
		dbg(1, "current pos=0x%x,0x%x\n", pos->x, pos->y);
		if (priv->last.x == pos->x && priv->last.y == pos->y) {
			dbg(1, "endless loop\n");
		}
		priv->last = *pos;
		for (;;) {
			c = route_path_coord_get(h);
			dbg(1, "next pos=%p\n", c);
			if (!c)
				break;
			dbg(1, "next pos=0x%x,0x%x\n", c->x, c->y);
			slen = transform_distance(projection_mg, pos, c);
			dbg(1, "len=%d slen=%d\n", len, slen);
			if (slen < len) {
				len -= slen;
				pos = c;
			} else {
				dx = c->x - pos->x;
				dy = c->y - pos->y;
				ci.x = pos->x + dx * len / slen;
				ci.y = pos->y + dy * len / slen;
				priv->direction =
				    transform_get_angle_delta(pos, c, 0);
				dbg(1, "ci=0x%x,0x%x\n", ci.x, ci.y);
				transform_to_geo(projection_mg, &ci,
						 &priv->geo);
				callback_list_call_0(priv->cbl);
				break;
			}
		}
	}
	return 1;
}