2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
26 // FIXME temporary fix for enum
27 #include "projection.h"
33 #include "transform.h"
41 #include "gui_directfb.h"
42 #include "navigation.h"
48 #include "navit_nls.h"
54 IDirectFBSurface *DFB_primary_layer_surface__i;
55 IDirectFBSurface *DFB_gui_surface__i;
56 IDirectFBSurface *DFB_graphics_surface__i;
57 IDirectFBSurface *DFB_gui_buttons_surface__i;
59 IDirectFBFont *DFB_primary_layer_surface_font__i;
60 IDirectFBFont *DFB_gui_surface_font__i;
62 IDirectFBWindow *DFB_gui_window__i;
63 IDirectFBWindow *DFB_graphics_window__i;
65 static int screen_width = 0;
66 static int screen_height = 0;
68 struct navit *dfb_gui_navit;
73 static int run_main_loop(struct gui_priv *this_)
77 dbg(0,"Entering main directfb loop\n");
80 for(frames=0;frames<100;frames++)
83 dbg(0,"debug >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>< frame n° %d",frames);
89 static void vehicle_callback_handler( struct navit *nav, struct vehicle *v){
91 dbg(0,"debut vehicle callback\n");
96 int sats=0, sats_used=0;
99 if (vehicle_get_attr(v, attr_position_speed, &attr))
100 sprintf (buffer, "Speed : %02.02f km/h", *attr.u.numd);
102 strcpy (buffer, "Speed : N/A");
103 fprintf(stderr,"debug vehicle_callback : %s",buffer);
104 primary->DrawString(primary,buffer,-1,0,50,DSTF_LEFT|DSTF_TOP);
106 if (vehicle_get_attr(v, attr_position_height, &attr))
107 sprintf (buffer, "Altimeter : %.f m", *attr.u.numd);
109 strcpy (buffer, "Altimeter : N/A");
110 fprintf(stderr,"debug vehicle_callback : %s",buffer);
111 primary->DrawString(primary,buffer,-1,0,70,DSTF_LEFT|DSTF_TOP);
113 if (vehicle_get_attr(v, attr_position_sats, &attr))
115 if (vehicle_get_attr(v, attr_position_sats_used, &attr))
116 sats_used=attr.u.num;
118 sprintf(buffer," sats : %i, used %i: \n",sats,sats_used);
119 fprintf(stderr,"debug vehicle_callback : %s",buffer);
120 primary->DrawString(dfbSG,buffer,-1,0,90,DSTF_LEFT|DSTF_TOP);
121 primary->Flip (primary, NULL, DSFLIP_WAITFORSYNC);
127 struct gui_methods gui_dfb_methods = {
132 gui_directfb_set_graphics(struct gui_priv *this, struct graphics *gra)
134 dbg(0,"gui_directfb_set_graphics !!!\n");
138 static struct gui_priv *
139 gui_directfb_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs)
141 dbg(0,"Begin DirectFB init\n");
144 struct gui_priv *this_;
147 /* DirectFB specifics */
150 IDirectFB *DFB_main__i;
151 IDirectFBDisplayLayer *DFB_primary_layer__i;
153 IDirectFBImageProvider *DFB_zoomin__img;
154 DFBRectangle DFB_zoomin_img__zone;
156 DFBDisplayLayerConfig *DFB_primary_layer__c;
157 DFBWindowDescription *DFB_graphics_window__d;
158 DFBFontDescription *DFB_primary_layer_surface_font__d;
159 DFBFontDescription *DFB_gui_surface_font__d;
160 DFBSurfaceDescription DFB_gui_buttons_surface__d;
166 /*******DirectFB*******/
171 dbg(0,"VALID navit instance in gui\n");
175 dbg(0,"Invalid navit instance in gui\n");
179 dbg(0,"VALID source navit instance in gui\n");
183 dbg(0,"Invalid source navit instance in gui\n");
186 *meth=gui_dfb_methods;
188 this_=g_new0(struct gui_priv, 1);
190 /* INITIALISATION INTERFACE PRIMAIRE */
191 DFB_ret = DirectFBInit(NULL,NULL);
192 if (DFB_ret != DFB_OK)
194 DirectFBError( "DirectFBInit() failed", DFB_ret );
198 DFB_ret = DirectFBCreate( &DFB_main__i );
199 if (DFB_ret != DFB_OK)
201 DirectFBError( "DirectFBCreate() failed", DFB_ret );
206 DFB_ret = DFB_main__i->GetDisplayLayer( DFB_main__i, DLID_PRIMARY, &DFB_primary_layer__i );
207 if (DFB_ret != DFB_OK)
209 dbg( 0, "IDirectFB::GetDisplayLayer() failed!\n" );
210 DFB_main__i->Release(DFB_main__i);
214 DFB_ret = DFB_primary_layer__i->SetCooperativeLevel(DFB_primary_layer__i,DLSCL_ADMINISTRATIVE);
215 if (DFB_ret != DFB_OK)
217 dbg( 0, "IDirectFB::SetCooperativeLevel() failed!\n" );
218 DFB_main__i->Release(DFB_main__i);
222 /* FIN INITIALISATION INTERFACE PRIMAIRE */
224 /* CREATION FENETRE GUI SUR INTERFACE PRIMAIRE */
225 DFB_ret = DFB_primary_layer__i->GetSurface(DFB_primary_layer__i,&DFB_gui_surface__i);
226 if (DFB_ret != DFB_OK)
228 dbg( 0, "IDirectFBDisplayLayer::GetSurface failed!\n" );
229 DFB_main__i->Release(DFB_main__i);
233 DFB_primary_layer__c = g_new0(DFBDisplayLayerConfig, 1);
234 DFB_ret = DFB_primary_layer__i->GetConfiguration(DFB_primary_layer__i,DFB_primary_layer__c);
235 if (DFB_ret != DFB_OK)
237 dbg( 0, "IDirectFBDisplayLayer::GetConfiguration failed!\n" );
238 DFB_main__i->Release(DFB_main__i);
241 DFB_primary_layer_surface_font__d = g_new0(DFBFontDescription, 1);
242 DFB_primary_layer_surface_font__d->flags = DFDESC_HEIGHT;
243 DFB_primary_layer_surface_font__d->height = DFB_primary_layer__c->width/50;
244 fprintf(stderr,"debug ============= %d\n",DFB_primary_layer__c->width);
246 DFB_ret = DFB_main__i->CreateFont( DFB_main__i, "/usr/share/fonts/truetype/DejaVuSans.ttf", DFB_primary_layer_surface_font__d, &DFB_primary_layer_surface_font__i );
247 if (DFB_ret != DFB_OK)
249 dbg( 0, "IDirectFB : CreateFont failed!\n" );
250 DFB_main__i->Release(DFB_main__i);
255 * DFB_ret = DFB_main__i->CreateImageProvider(DFB_main__i,"/usr/share/navit/xpm/gui_zoom_in_96_96.png",&DFB_zoomin__img);
256 if (DFB_ret != DFB_OK)
258 dbg( 0, "IDirectFB : CreateImageProvider failed!\n" );
259 DFB_main__i->Release(DFB_main__i);
263 //DFB_gui_surface__i->SetBlittingFlags(DFB_gui_surface__i,DSBLIT_SRC_COLORKEY);
264 //DFB_gui_surface__i->SetSrcColorKey(DFB_gui_surface__i,0x00,0x00,0x00);
265 DFB_gui_buttons_surface__d.flags = DSDESC_WIDTH|DSDESC_HEIGHT;
266 DFB_gui_buttons_surface__d.width = 48;
267 DFB_gui_buttons_surface__d.height = 48;
269 DFB_ret = DFB_main__i->CreateSurface(DFB_main__i,&DFB_gui_buttons_surface__d,&DFB_gui_buttons_surface__i);
270 if (DFB_ret != DFB_OK)
272 dbg( 0, "IDirectFB : CreateSurface failed!\n" );
273 DFB_main__i->Release(DFB_main__i);
277 //DFB_primary_layer_surface_font__i->GetHeight( DFB_primary_layer_surface_font__i, &fontheight );
279 DFB_gui_surface__i->SetFont (DFB_gui_surface__i, DFB_primary_layer_surface_font__i);
280 DFB_gui_surface__i->SetColor(DFB_gui_surface__i,0xff,0xff,0xff,0xff);
281 DFB_gui_surface__i->DrawString(DFB_gui_surface__i,"Navit on DirectFB",-1,0,0,DSTF_LEFT|DSTF_TOP);
284 DFB_zoomin_img__zone.x = 0;
285 DFB_zoomin_img__zone.y = 0;
286 DFB_zoomin_img__zone.w = 48;
287 DFB_zoomin_img__zone.h = 48;
288 DFB_zoomin__img->RenderTo(DFB_zoomin__img,DFB_gui_buttons_surface__i,NULL);
289 DFB_gui_surface__i->Blit(DFB_gui_surface__i,DFB_gui_buttons_surface__i,NULL,20,20);
292 DFB_gui_surface__i->Flip(DFB_gui_surface__i,NULL,DSFLIP_NONE);
294 /* FIN CREATION FENETRE GUI SUR INTERFACE PRIMAIRE */
297 DFB_graphics_window__d = g_new0(DFBWindowDescription, 1);
298 //DFB_graphics_window__d->caps = DWCAPS_NONE;
299 //DFB_graphics_window__d->width = 100;
300 //DFB_graphics_window__d->height = 100;
301 //DFB_graphics_window__d->posy = 10;
302 //DFB_graphics_window__d->posx = 10;
303 DFB_graphics_window__d->stacking = DWSC_UPPER;
305 //DFB_graphics_window__d->pixelformat = DSPF_RGB32;
306 // DFB_graphics_window__d->options = DWOP_KEEP_POSITION;
308 DFB_ret = DFB_primary_layer__i->CreateWindow(DFB_primary_layer__i,DFB_graphics_window__d,&DFB_graphics_window__i);
309 if (DFB_ret != DFB_OK)
311 dbg( 0, "IDirectFBDisplayLayer::CreateWindow failed!\n" );
312 DFB_main__i->Release(DFB_main__i);
316 DFB_ret = DFB_graphics_window__i->Resize(DFB_graphics_window__i,600,400);
317 if (DFB_ret != DFB_OK)
319 dbg( 0, "IDirectFBWindow::Resize failed!\n" );
320 DFB_main__i->Release(DFB_main__i);
323 DFB_ret = DFB_graphics_window__i->MoveTo(DFB_graphics_window__i,20,78);
324 if (DFB_ret != DFB_OK)
326 dbg( 0, "IDirectFBWindow::MoveTo failed!\n" );
327 DFB_main__i->Release(DFB_main__i);
331 DFB_ret = DFB_graphics_window__i->SetOpacity(DFB_graphics_window__i, 0xff );
332 if (DFB_ret != DFB_OK)
334 dbg( 0, "IDirectFBWindow::SetOpacity failed!\n" );
335 DFB_main__i->Release(DFB_main__i);
339 DFB_ret = DFB_graphics_window__i->GetSurface(DFB_graphics_window__i,&DFB_graphics_surface__i);
340 if (DFB_ret != DFB_OK)
342 dbg( 0, "IDirectFBWindow::GetSurface failed!\n" );
343 DFB_main__i->Release(DFB_main__i);
347 dbg(0,"End of directfb gui initialization\n");
350 /* add callback for position updates */
351 //struct callback *cb=callback_new_attr_0(callback_cast(vehicle_callback_handler), attr_position_coord_geo);
353 //navit_add_callback(nav,cb);
362 dbg(0,"registering directfb plugin\n");
363 plugin_register_gui_type("directfb", gui_directfb_new);