2 * scientific visualization api for direct framebuffer
4 * author: hackbard@hackdaworld.dyndns.org
12 /* two dimensional lattice */
14 int d2_lattice_init(int *argc,char **argv,d2_lattice *d2_l)
16 DFBSurfaceDescription surface_dsc;
17 DFBFontDescription font_dsc;
19 DirectFBInit(argc,&argv);
20 DirectFBCreate(&(d2_l->dfb));
21 d2_l->dfb->SetCooperativeLevel(d2_l->dfb,DFSCL_FULLSCREEN);
23 surface_dsc.flags=DSDESC_CAPS;
24 surface_dsc.caps=DSCAPS_PRIMARY|DSCAPS_FLIPPING;
25 d2_l->dfb->CreateSurface(d2_l->dfb,&surface_dsc,&(d2_l->p_surface));
26 d2_l->p_surface->GetSize(d2_l->p_surface,&(d2_l->s_width),&(d2_l->s_height));
28 font_dsc.flags=DFDESC_HEIGHT;
29 font_dsc.height=d2_l->s_height/60; /* 60 ? */
30 d2_l->font_h=font_dsc.height;
31 d2_l->dfb->CreateFont(d2_l->dfb,FONT,&font_dsc,&(d2_l->font));
32 d2_l->p_surface->SetFont(d2_l->p_surface,d2_l->font);
34 d2_l->fakt_y=(d2_l->s_height-(2*Y_GAP))/(d2_l->max_y);
35 d2_l->fakt_x=(d2_l->s_height-X_GAP)/(d2_l->max_x); /* bullshit, i can't imagine atm */
36 d2_l->info_x=d2_l->fakt_x*d2_l->max_x+2*X_GAP;
38 d2_l->info_w=d2_l->s_width-d2_l->info_x-2*X_GAP;
39 d2_l->info_h=d2_l->max_y*d2_l->fakt_y;
41 if((d2_l->s_height<(d2_l->max_y+2*Y_GAP)) || (d2_l->s_height<(d2_l->max_x+X_GAP)))
43 puts("resolution too low!");
48 int d3_lattice_init(int *argc,char **argv,d3_lattice *d3_l)
50 DFBSurfaceDescription surface_dsc;
51 DFBFontDescription font_dsc;
53 DirectFBInit(argc,&argv);
54 DirectFBCreate(&(d3_l->dfb));
55 d3_l->dfb->SetCooperativeLevel(d3_l->dfb,DFSCL_FULLSCREEN);
57 surface_dsc.flags=DSDESC_CAPS;
58 surface_dsc.caps=DSCAPS_PRIMARY|DSCAPS_FLIPPING;
59 d3_l->dfb->CreateSurface(d3_l->dfb,&surface_dsc,&(d3_l->p_surface));
60 d3_l->p_surface->GetSize(d3_l->p_surface,&(d3_l->s_width),&(d3_l->s_height));
62 font_dsc.flags=DFDESC_HEIGHT;
63 font_dsc.height=d3_l->s_height/40; /* 40 ? */
64 d3_l->font_h=font_dsc.height;
65 d3_l->dfb->CreateFont(d3_l->dfb,FONT,&font_dsc,&(d3_l->font));
66 d3_l->p_surface->SetFont(d3_l->p_surface,d3_l->font);
68 d3_l->fakt_y=(d3_l->s_height-(2*Y_GAP))/d3_l->max_z;
69 d3_l->fakt_x=(d3_l->s_width-(4*X_GAP))/(d3_l->max_x+d3_l->max_y+d3_l->max_x);
70 d3_l->info_x=d3_l->fakt_x*(d3_l->max_x+d3_l->max_y)+(3*X_GAP);
71 d3_l->info_y=d3_l->fakt_y*d3_l->max_y+(2*Y_GAP);
72 d3_l->o_x=d3_l->fakt_x*d3_l->max_x+(2*X_GAP);
73 d3_l->info_w=d3_l->fakt_x*d3_l->max_x;
74 d3_l->info_h=d3_l->fakt_y*(d3_l->max_z-d3_l->max_y)-Y_GAP;
79 int d2_lattice_release(d2_lattice *d2_l)
81 d2_l->font->Release(d2_l->font);
82 d2_l->p_surface->Release(d2_l->p_surface);
83 d2_l->dfb->Release(d2_l->dfb);
88 int d3_lattice_release(d3_lattice *d3_l)
90 d3_l->font->Release(d3_l->font);
91 d3_l->p_surface->Release(d3_l->p_surface);
92 d3_l->dfb->Release(d3_l->dfb);
97 int dx_lattice_get_color(unsigned char *status,unsigned char *r,unsigned char *g,unsigned char *b,unsigned char mode)
125 int d2_lattice_draw(d2_lattice *d2_l,int x,int y,int arg_c,char **arg_v,unsigned char mode,int max_extra)
129 unsigned char r,g,b,a;
130 unsigned char foobar;
132 a=0xff; /* no alpha blending */
134 for(x_c=0;x_c<d2_l->max_x;x_c++)
136 for(y_c=0;y_c<d2_l->max_y;y_c++)
138 if(!mode) dx_lattice_get_color((*d2_l).status+x_c+y_c*d2_l->max_x,&r,&g,&b,mode);
141 foobar=(unsigned char)(*(d2_l->extra+x_c+y_c*d2_l->max_x)*255/max_extra);
142 dx_lattice_get_color(&foobar,&r,&g,&b,mode);
146 foobar=(*(unsigned char *)(d2_l->v_ptr+x_c+y_c*d2_l->max_x));
147 dx_lattice_get_color(&foobar,&r,&g,&b,mode);
155 d2_l->p_surface->SetColor(d2_l->p_surface,r,g,b,a);
156 d2_l->p_surface->DrawRectangle(d2_l->p_surface,
157 x_c*d2_l->fakt_x+X_GAP,
158 y_c*d2_l->fakt_y+Y_GAP,
159 d2_l->fakt_x,d2_l->fakt_y);
166 d2_l->p_surface->SetColor(d2_l->p_surface,0,0,0,0);
167 d2_l->p_surface->FillRectangle(d2_l->p_surface,
168 d2_l->info_x,d2_l->info_y,
169 d2_l->info_w,d2_l->info_h);
170 d2_l->p_surface->SetColor(d2_l->p_surface,r,g,b,a);
171 d2_l->p_surface->DrawRectangle(d2_l->p_surface,
172 d2_l->info_x,d2_l->info_y,
173 d2_l->info_w,d2_l->info_h);
174 d2_l->p_surface->SetColor(d2_l->p_surface,0x80,0x80,0xff,0xff);
175 for(i=1;i<=arg_c;i++)
177 d2_l->p_surface->DrawString(d2_l->p_surface,arg_v[i],-1,
178 d2_l->info_x+d2_l->fakt_x,
179 d2_l->info_y+d2_l->fakt_y+d2_l->font_h+(i-1)*2*d2_l->font_h,
182 /* now we flip all to surface */
183 d2_l->p_surface->Flip(d2_l->p_surface,NULL,0);
188 int d3_lattice_draw(d3_lattice *d3_l,int x,int y,int z,int arg_c,char **arg_v,unsigned char mode,int max_extra)
192 unsigned char foobar;
193 unsigned char r,g,b,a;
195 a=0xff; /* no alpha blending */
198 for(x_c=0;x_c<d3_l->max_x;x_c++)
200 for(z_c=0;z_c<d3_l->max_z;z_c++)
202 if(!mode) dx_lattice_get_color((*d3_l).status+x_c+y_c*d3_l->max_x+z_c*d3_l->max_x*d3_l->max_y,&r,&g,&b,mode);
205 foobar=(unsigned char)(*(d3_l->extra+x_c+y_c*d3_l->max_x+z_c*d3_l->max_x*d3_l->max_y)*255/max_extra);
206 dx_lattice_get_color(&foobar,&r,&g,&b,mode);
210 foobar=(*(unsigned char *)(d3_l->v_ptr+x_c+y_c*d3_l->max_x+z_c*d3_l->max_x*d3_l->max_y));
211 dx_lattice_get_color(&foobar,&r,&g,&b,mode);
219 d3_l->p_surface->SetColor(d3_l->p_surface,r,g,b,a);
220 d3_l->p_surface->DrawRectangle(d3_l->p_surface,
221 x_c*d3_l->fakt_x+X_GAP,
222 z_c*d3_l->fakt_y+Y_GAP,
223 d3_l->fakt_x,d3_l->fakt_y);
228 for(y_c=0;y_c<d3_l->max_y;y_c++)
230 for(z_c=0;z_c<d3_l->max_z;z_c++)
232 if(!mode) dx_lattice_get_color((*d3_l).status+x_c+y_c*d3_l->max_x+z_c*d3_l->max_x*d3_l->max_y,&r,&g,&b,mode);
235 foobar=(unsigned char)(*(d3_l->extra+x_c+y_c*d3_l->max_x+z_c*d3_l->max_x*d3_l->max_y)*255/max_extra);
236 dx_lattice_get_color(&foobar,&r,&g,&b,mode);
240 foobar=(*(unsigned char *)(d3_l->v_ptr+x_c+y_c*d3_l->max_x+z_c*d3_l->max_x*d3_l->max_y));
241 dx_lattice_get_color(&foobar,&r,&g,&b,mode);
249 d3_l->p_surface->SetColor(d3_l->p_surface,r,g,b,a);
250 d3_l->p_surface->DrawRectangle(d3_l->p_surface,
251 y_c*d3_l->fakt_x+d3_l->o_x,
252 z_c*d3_l->fakt_y+Y_GAP,
253 d3_l->fakt_x,d3_l->fakt_y);
258 for(x_c=0;x_c<d3_l->max_x;x_c++)
260 for(y_c=0;y_c<d3_l->max_y;y_c++)
262 if(!mode) dx_lattice_get_color((*d3_l).status+x_c+y_c*d3_l->max_x+z_c*d3_l->max_x*d3_l->max_y,&r,&g,&b,mode);
265 foobar=(unsigned char)(*(d3_l->extra+x_c+y_c*d3_l->max_x+z_c*d3_l->max_x*d3_l->max_y)*255/max_extra);
266 dx_lattice_get_color(&foobar,&r,&g,&b,mode);
270 foobar=(*(unsigned char *)(d3_l->v_ptr+x_c+y_c*d3_l->max_x+z_c*d3_l->max_x*d3_l->max_y));
271 dx_lattice_get_color(&foobar,&r,&g,&b,mode);
279 d3_l->p_surface->SetColor(d3_l->p_surface,r,g,b,a);
280 d3_l->p_surface->DrawRectangle(d3_l->p_surface,
281 x_c*d3_l->fakt_x+d3_l->info_x,
282 y_c*d3_l->fakt_y+Y_GAP,
283 d3_l->fakt_x,d3_l->fakt_y);
291 d3_l->p_surface->SetColor(d3_l->p_surface,0,0,0,0);
292 d3_l->p_surface->FillRectangle(d3_l->p_surface,
293 d3_l->info_x,d3_l->info_y,
294 d3_l->info_w,d3_l->info_h);
295 d3_l->p_surface->SetColor(d3_l->p_surface,r,g,b,a);
296 d3_l->p_surface->DrawRectangle(d3_l->p_surface,
297 d3_l->info_x,d3_l->info_y,
298 d3_l->info_w,d3_l->info_h);
300 d3_l->p_surface->DrawLine(d3_l->p_surface,
301 d3_l->info_x+d3_l->info_w/2,
303 d3_l->info_x+d3_l->info_w/2,
304 d3_l->info_y+d3_l->info_h);
306 d3_l->p_surface->SetColor(d3_l->p_surface,0x80,0x80,0xff,0xff);
307 for(i=1;i<=arg_c;i++)
311 d3_l->p_surface->DrawString(d3_l->p_surface,arg_v[i],-1,
312 d3_l->info_x+d3_l->fakt_x,
313 d3_l->info_y+2*d3_l->fakt_y+d3_l->font_h+(i-1)*d3_l->font_h,
318 d3_l->p_surface->DrawString(d3_l->p_surface,arg_v[i],-1,
319 d3_l->info_x+d3_l->info_w/2+d3_l->fakt_x,
320 d3_l->info_y+2*d3_l->fakt_y+d3_l->font_h+(i%13-1)*d3_l->font_h,
326 /* now we flip all to surface */
327 d3_l->p_surface->Flip(d3_l->p_surface,NULL,0);
332 int d2_event_init(d2_lattice *d2_l)
334 d2_l->dfb->GetInputDevice(d2_l->dfb,DIDID_KEYBOARD,&(d2_l->keyboard));
335 d2_l->keyboard->CreateEventBuffer(d2_l->keyboard,&(d2_l->k_buffer));
340 int d3_event_init(d3_lattice *d3_l)
342 d3_l->dfb->GetInputDevice(d3_l->dfb,DIDID_KEYBOARD,&(d3_l->keyboard));
343 d3_l->keyboard->CreateEventBuffer(d3_l->keyboard,&(d3_l->k_buffer));
348 int scan_event(d3_lattice *d3_l,int *x,int *y,int *z,int *q,int *esc,int *switchmode,int *bmp,int *ac_distr)
352 d3_l->k_buffer->WaitForEvent(d3_l->k_buffer);
353 d3_l->k_buffer->GetEvent(d3_l->k_buffer,DFB_EVENT(&ke));
354 if(ke.type==DIET_KEYPRESS)
356 if(ke.key_id==DIKI_LEFT && *x!=0) *x-=1;
357 if(ke.key_id==DIKI_RIGHT && *x!=d3_l->max_x-1) *x+=1;
358 if(ke.key_id==DIKI_UP && *y!=0) *y-=1;
359 if(ke.key_id==DIKI_DOWN && *y!=d3_l->max_y-1) *y+=1;
360 if(ke.key_id==DIKI_PAGE_UP && *z!=0) *z-=1;
361 if(ke.key_id==DIKI_PAGE_DOWN && *z!=d3_l->max_z-1) *z+=1;
362 if(ke.key_id==DIKI_Q) *q=1;
363 if(ke.key_id==DIKI_ESCAPE) *esc=1;
364 if(ke.key_id==DIKI_M) *switchmode=(*switchmode+1)%3;
365 if(ke.key_id==DIKI_1) *bmp=1;
366 if(ke.key_id==DIKI_2) *bmp=2;
367 if(ke.key_id==DIKI_3) *bmp=3;
368 if(ke.key_id==DIKI_4) *bmp=4;
369 if(ke.key_id==DIKI_5) *bmp=5;
370 if(ke.key_id==DIKI_6) *bmp=6;
371 if(ke.key_id==DIKI_A) *ac_distr=1;
372 if(ke.key_id==DIKI_C) *ac_distr=2;
373 if(ke.key_id==DIKI_B) *ac_distr=3;