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,u32 *p1,u32 max1,u32 *p2,u32 max2)
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)||mode==3) 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 if(d3_l->max_x*p1[z_c]/max1==x_c)
214 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);
215 dx_lattice_get_color(&foobar,&r,&g,&b,mode);
219 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));
220 dx_lattice_get_color(&foobar,&r,&g,&b,mode);
228 d3_l->p_surface->SetColor(d3_l->p_surface,r,g,b,a);
229 d3_l->p_surface->DrawRectangle(d3_l->p_surface,
230 x_c*d3_l->fakt_x+X_GAP,
231 z_c*d3_l->fakt_y+Y_GAP,
232 d3_l->fakt_x,d3_l->fakt_y);
237 for(y_c=0;y_c<d3_l->max_y;y_c++)
239 for(z_c=0;z_c<d3_l->max_z;z_c++)
241 if((!mode)||mode==3) 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);
244 if((int)(d3_l->max_y*(1.0*p2[z_c]/max2))==y_c)
253 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);
254 dx_lattice_get_color(&foobar,&r,&g,&b,mode);
258 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));
259 dx_lattice_get_color(&foobar,&r,&g,&b,mode);
267 d3_l->p_surface->SetColor(d3_l->p_surface,r,g,b,a);
268 d3_l->p_surface->DrawRectangle(d3_l->p_surface,
269 y_c*d3_l->fakt_x+d3_l->o_x,
270 z_c*d3_l->fakt_y+Y_GAP,
271 d3_l->fakt_x,d3_l->fakt_y);
276 for(x_c=0;x_c<d3_l->max_x;x_c++)
278 for(y_c=0;y_c<d3_l->max_y;y_c++)
280 if((!mode)||mode==3) 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);
283 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);
284 dx_lattice_get_color(&foobar,&r,&g,&b,mode);
288 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));
289 dx_lattice_get_color(&foobar,&r,&g,&b,mode);
297 d3_l->p_surface->SetColor(d3_l->p_surface,r,g,b,a);
298 d3_l->p_surface->DrawRectangle(d3_l->p_surface,
299 x_c*d3_l->fakt_x+d3_l->info_x,
300 y_c*d3_l->fakt_y+Y_GAP,
301 d3_l->fakt_x,d3_l->fakt_y);
309 d3_l->p_surface->SetColor(d3_l->p_surface,0,0,0,0);
310 d3_l->p_surface->FillRectangle(d3_l->p_surface,
311 d3_l->info_x,d3_l->info_y,
312 d3_l->info_w,d3_l->info_h);
313 d3_l->p_surface->SetColor(d3_l->p_surface,r,g,b,a);
314 d3_l->p_surface->DrawRectangle(d3_l->p_surface,
315 d3_l->info_x,d3_l->info_y,
316 d3_l->info_w,d3_l->info_h);
317 d3_l->p_surface->SetColor(d3_l->p_surface,0x80,0x80,0xff,0xff);
318 for(i=1;i<=arg_c;i++)
319 d3_l->p_surface->DrawString(d3_l->p_surface,arg_v[i],-1,
320 d3_l->info_x+d3_l->fakt_x,
321 d3_l->info_y+2*d3_l->fakt_y+d3_l->font_h+(i-1)*d3_l->font_h,
324 /* now we flip all to surface */
325 d3_l->p_surface->Flip(d3_l->p_surface,NULL,0);
330 int d2_event_init(d2_lattice *d2_l)
332 d2_l->dfb->GetInputDevice(d2_l->dfb,DIDID_KEYBOARD,&(d2_l->keyboard));
333 d2_l->keyboard->CreateEventBuffer(d2_l->keyboard,&(d2_l->k_buffer));
338 int d3_event_init(d3_lattice *d3_l)
340 d3_l->dfb->GetInputDevice(d3_l->dfb,DIDID_KEYBOARD,&(d3_l->keyboard));
341 d3_l->keyboard->CreateEventBuffer(d3_l->keyboard,&(d3_l->k_buffer));
346 int scan_event(d3_lattice *d3_l,int *x,int *y,int *z,int *q,int *esc,int *switchmode,int *bmp,int *ac_distr)
350 d3_l->k_buffer->WaitForEvent(d3_l->k_buffer);
351 d3_l->k_buffer->GetEvent(d3_l->k_buffer,DFB_EVENT(&ke));
352 if(ke.type==DIET_KEYPRESS)
354 if(ke.key_id==DIKI_LEFT && *x!=0) *x-=1;
355 if(ke.key_id==DIKI_RIGHT && *x!=d3_l->max_x-1) *x+=1;
356 if(ke.key_id==DIKI_UP && *y!=0) *y-=1;
357 if(ke.key_id==DIKI_DOWN && *y!=d3_l->max_y-1) *y+=1;
358 if(ke.key_id==DIKI_PAGE_UP && *z!=0) *z-=1;
359 if(ke.key_id==DIKI_PAGE_DOWN && *z!=d3_l->max_z-1) *z+=1;
360 if(ke.key_id==DIKI_Q) *q=1;
361 if(ke.key_id==DIKI_ESCAPE) *esc=1;
362 if(ke.key_id==DIKI_M) *switchmode=(*switchmode+1)%4;
363 if(ke.key_id==DIKI_1) *bmp=1;
364 if(ke.key_id==DIKI_2) *bmp=2;
365 if(ke.key_id==DIKI_3) *bmp=3;
366 if(ke.key_id==DIKI_4) *bmp=4;
367 if(ke.key_id==DIKI_5) *bmp=5;
368 if(ke.key_id==DIKI_6) *bmp=6;
369 if(ke.key_id==DIKI_7) *bmp=7;
370 if(ke.key_id==DIKI_8) *bmp=8;
371 if(ke.key_id==DIKI_9) *bmp=9;
372 if(ke.key_id==DIKI_W) *bmp=10;
373 if(ke.key_id==DIKI_E) *bmp=11;
374 if(ke.key_id==DIKI_R) *bmp=12;
375 if(ke.key_id==DIKI_A) *ac_distr=1;
376 if(ke.key_id==DIKI_C) *ac_distr=2;
377 if(ke.key_id==DIKI_B) *ac_distr=3;
378 if(ke.key_id==DIKI_X) *ac_distr=4;