FIX:build: Make --disable-nls and --with-included-gettext work.
[navit-package] / navit / gui / directfb / gui_directfb.c
1 /*
2  * Navit, a modular navigation system.
3  * Copyright (C) 2005-2008 Navit Team
4  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include "glib.h"
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <unistd.h>
25
26 //  FIXME temporary fix for enum
27 #include "projection.h"
28
29 #include "item.h"
30 #include "navit.h"
31 #include "vehicle.h"    
32 #include "profile.h"
33 #include "transform.h"
34 #include "gui.h"
35 #include "coord.h"
36 #include "config.h"
37 #include "plugin.h"
38 #include "callback.h"
39 #include "point.h"
40 #include "graphics.h"
41 #include "gui_directfb.h"
42 #include "navigation.h"
43 #include "debug.h"
44 #include "attr.h"
45 #include "track.h"
46 #include "menu.h"
47 #include "map.h"
48 #include "navit_nls.h"
49
50 #include <directfb.h>
51
52
53
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;
58
59 IDirectFBFont           *DFB_primary_layer_surface_font__i;
60 IDirectFBFont           *DFB_gui_surface_font__i;
61
62 IDirectFBWindow         *DFB_gui_window__i;
63 IDirectFBWindow         *DFB_graphics_window__i;
64
65 static int screen_width  = 0;
66 static int screen_height = 0;
67
68 struct navit *dfb_gui_navit;
69
70
71
72
73 static int run_main_loop(struct gui_priv *this_)
74 {
75         int frames;
76
77         dbg(0,"Entering main directfb loop\n");
78
79         
80         for(frames=0;frames<100;frames++)
81         {
82                 sleep(3);
83                 dbg(0,"debug >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>< frame n° %d",frames);                      
84         }
85
86         return 0;
87 }
88
89 static void vehicle_callback_handler( struct navit *nav, struct vehicle *v){
90
91         dbg(0,"debut vehicle callback\n");      
92
93 /*      
94         char buffer [50];
95         struct attr attr;
96         int sats=0, sats_used=0;
97         int err;
98         
99         if (vehicle_get_attr(v, attr_position_speed, &attr))
100                 sprintf (buffer, "Speed : %02.02f km/h", *attr.u.numd);
101         else
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);
105
106         if (vehicle_get_attr(v, attr_position_height, &attr))
107                 sprintf (buffer, "Altimeter : %.f m", *attr.u.numd);
108         else
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);
112
113         if (vehicle_get_attr(v, attr_position_sats, &attr))
114                 sats=attr.u.num;
115         if (vehicle_get_attr(v, attr_position_sats_used, &attr))
116                 sats_used=attr.u.num;
117         
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);
122
123 */
124
125 }
126
127 struct gui_methods gui_dfb_methods = {
128         run_main_loop,
129 };
130
131 static int
132 gui_directfb_set_graphics(struct gui_priv *this, struct graphics *gra)
133 {
134         dbg(0,"gui_directfb_set_graphics !!!\n");
135         return 0;
136 }
137
138 static struct gui_priv *
139 gui_directfb_new(struct navit *nav, struct gui_methods *meth, struct attr **attrs) 
140 {
141         dbg(0,"Begin DirectFB init\n");
142         
143
144         struct gui_priv *this_;
145         dfb_gui_navit=nav;
146         
147         /* DirectFB specifics */
148         
149         DFBResult                       DFB_ret;
150         IDirectFB                       *DFB_main__i;
151         IDirectFBDisplayLayer           *DFB_primary_layer__i;
152
153         IDirectFBImageProvider          *DFB_zoomin__img;
154         DFBRectangle                    DFB_zoomin_img__zone;
155         
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;
161
162         int                             fontheight;
163
164         //char  *       DFB_argc[];
165
166         /*******DirectFB*******/
167
168
169         if(dfb_gui_navit)
170         {       
171                 dbg(0,"VALID navit instance in gui\n");
172         }
173         else
174         {
175                 dbg(0,"Invalid navit instance in gui\n");
176         }
177         if(nav)
178         {       
179                 dbg(0,"VALID source navit instance in gui\n");
180         }
181         else 
182         {
183                 dbg(0,"Invalid source navit instance in gui\n");
184         }
185         
186         *meth=gui_dfb_methods;
187
188         this_=g_new0(struct gui_priv, 1);
189     
190         /* INITIALISATION INTERFACE PRIMAIRE */
191         DFB_ret = DirectFBInit(NULL,NULL);
192         if (DFB_ret != DFB_OK) 
193         {
194                 DirectFBError( "DirectFBInit() failed", DFB_ret );
195                 return NULL;
196         }
197
198         DFB_ret = DirectFBCreate( &DFB_main__i );
199         if (DFB_ret != DFB_OK) 
200         {
201                 DirectFBError( "DirectFBCreate() failed", DFB_ret );
202                 return NULL;
203         }
204         
205         
206         DFB_ret = DFB_main__i->GetDisplayLayer( DFB_main__i, DLID_PRIMARY, &DFB_primary_layer__i );
207         if (DFB_ret != DFB_OK) 
208         {
209                 dbg( 0, "IDirectFB::GetDisplayLayer() failed!\n" );
210                 DFB_main__i->Release(DFB_main__i);
211                 return NULL;
212         }
213         
214         DFB_ret = DFB_primary_layer__i->SetCooperativeLevel(DFB_primary_layer__i,DLSCL_ADMINISTRATIVE);
215         if (DFB_ret != DFB_OK) 
216         {
217                 dbg( 0, "IDirectFB::SetCooperativeLevel() failed!\n" );
218                 DFB_main__i->Release(DFB_main__i);
219                 return NULL;
220         }
221
222         /* FIN INITIALISATION INTERFACE PRIMAIRE */
223
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)
227         {
228                 dbg( 0, "IDirectFBDisplayLayer::GetSurface failed!\n" );
229                 DFB_main__i->Release(DFB_main__i);
230                 return NULL;
231         }
232         
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)
236         {
237                 dbg( 0, "IDirectFBDisplayLayer::GetConfiguration failed!\n" );
238                 DFB_main__i->Release(DFB_main__i);
239                 return NULL;
240         }
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);
245
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)
248         {
249                 dbg( 0, "IDirectFB : CreateFont failed!\n" );
250                 DFB_main__i->Release(DFB_main__i);
251                 return NULL;
252         }
253         
254         /* BUTTON TEST
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)
257         {
258                 dbg( 0, "IDirectFB : CreateImageProvider failed!\n" );
259                 DFB_main__i->Release(DFB_main__i);
260                 return NULL;
261         }
262         */
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;
268         
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)
271         {
272                 dbg( 0, "IDirectFB : CreateSurface failed!\n" );
273                 DFB_main__i->Release(DFB_main__i);
274                 return NULL;
275         }
276
277         //DFB_primary_layer_surface_font__i->GetHeight( DFB_primary_layer_surface_font__i, &fontheight );
278         
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);
282         
283         /*
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);
290         */
291         
292         DFB_gui_surface__i->Flip(DFB_gui_surface__i,NULL,DSFLIP_NONE);
293         
294         /* FIN CREATION FENETRE GUI SUR INTERFACE PRIMAIRE */
295
296
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;
304
305         //DFB_graphics_window__d->pixelformat = DSPF_RGB32;
306         //      DFB_graphics_window__d->options = DWOP_KEEP_POSITION;
307
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)
310         {
311                 dbg( 0, "IDirectFBDisplayLayer::CreateWindow failed!\n" );
312                 DFB_main__i->Release(DFB_main__i);
313                 return NULL;
314         }
315
316         DFB_ret = DFB_graphics_window__i->Resize(DFB_graphics_window__i,600,400);
317         if (DFB_ret != DFB_OK)
318         {
319                 dbg( 0, "IDirectFBWindow::Resize failed!\n" );
320                 DFB_main__i->Release(DFB_main__i);
321                 return NULL;
322         }
323         DFB_ret = DFB_graphics_window__i->MoveTo(DFB_graphics_window__i,20,78);
324         if (DFB_ret != DFB_OK)
325         {
326                 dbg( 0, "IDirectFBWindow::MoveTo failed!\n" );
327                 DFB_main__i->Release(DFB_main__i);
328                 return NULL;
329         }
330         
331         DFB_ret = DFB_graphics_window__i->SetOpacity(DFB_graphics_window__i, 0xff );
332         if (DFB_ret != DFB_OK)
333         {
334                 dbg( 0, "IDirectFBWindow::SetOpacity failed!\n" );
335                 DFB_main__i->Release(DFB_main__i);
336                 return NULL;
337         }
338
339         DFB_ret = DFB_graphics_window__i->GetSurface(DFB_graphics_window__i,&DFB_graphics_surface__i);
340         if (DFB_ret != DFB_OK)
341         {
342                 dbg( 0, "IDirectFBWindow::GetSurface failed!\n" );
343                 DFB_main__i->Release(DFB_main__i);
344                 return NULL;
345         }
346         
347         dbg(0,"End of directfb gui initialization\n");
348         
349         
350         /* add callback for position updates */
351         //struct callback *cb=callback_new_attr_0(callback_cast(vehicle_callback_handler), attr_position_coord_geo);
352         
353         //navit_add_callback(nav,cb);
354         //this_->nav=nav;
355         return this_;
356 }
357
358
359 void
360 plugin_init(void)
361 {
362         dbg(0,"registering directfb plugin\n");
363         plugin_register_gui_type("directfb", gui_directfb_new);
364 }
365
366
367
368