2 * scientific visualization api for direct framebuffer
4 * author: hackbard@hackdaworld.dyndns.org
11 /* two dimensional lattice */
13 int d2_lattice_init(int *argc,char **argv,d2_lattice *d2_l,int x,int y)
15 DFBSurfaceDescription surface_dsc;
16 DFBFontDescription font_dsc;
21 DirectFBInit(argc,&argv);
22 DirectFBCreate(&(d2_l->dfb));
23 d2_l->dfb->SetCooperativeLevel(d2_l->dfb,DFSCL_FULLSCREEN);
25 surface_dsc.flags=DSDESC_CAPS;
26 surface_dsc.caps=DSCAPS_PRIMARY|DSCAPS_FLIPPING;
27 d2_l->dfb->CreateSurface(d2_l->dfb,&surface_dsc,&(d2_l->p_surface));
28 d2_l->p_surface->GetSize(d2_l->p_surface,&(d2_l->s_width),&(d2_l->s_height));
30 font_dsc.flags=DFDESC_HEIGHT;
31 font_dsc.height=d2_l->max_y*((d2_l->s_height)/(d2_l->max_y))/40; /* 40 ? */
32 d2_l->font_h=font_dsc.height;
33 d2_l->dfb->CreateFont(d2_l->dfb,FONT,&font_dsc,&(d2_l->font));
34 d2_l->p_surface->SetFont(d2_l->p_surface,d2_l->font);
36 d2_l->fakt_y=(d2_l->s_height)/(d2_l->max_y+(2*Y_GAP));
37 d2_l->fakt_x=(d2_l->s_height)/(d2_l->max_x+X_GAP); /* bullshit, i can't imagine atm */
38 d2_l->info_x=d2_l->fakt_x*d2_l->max_x+2*X_GAP;
40 d2_l->info_w=d2_l->s_width-d2_l->info_x-2*X_GAP;
41 d2_l->info_h=d2_l->max_y*d2_l->fakt_y;
43 if((d2_l->s_height<(d2_l->max_y+2*Y_GAP)) || (d2_l->s_height<(d2_l->max_x+X_GAP)))
45 puts("resolution too low!");
50 int d2_lattice_release(d2_lattice *d2_l)
52 d2_l->font->Release(d2_l->font);
53 d2_l->p_surface->Release(d2_l->p_surface);
54 d2_l->dfb->Release(d2_l->dfb);
59 int d2_lattice_get_color(unsigned char *status,unsigned char *r,unsigned char *g,unsigned char *b)
76 int d2_lattice_draw(d2_lattice *d2_l,int x,int y,int arg_c,char **arg_v)
80 unsigned char r,g,b,a;
82 a=0xff; /* no alpha blending */
84 for(x_c=0;x_c<d2_l->max_x;x_c++)
86 for(y_c=0;y_c<d2_l->max_y;y_c++)
88 d2_lattice_get_color((*d2_l).status+x_c+y_c*d2_l->max_x,&r,&g,&b);
95 d2_l->p_surface->SetColor(d2_l->p_surface,r,g,b,a);
96 d2_l->p_surface->DrawRectangle(d2_l->p_surface,
97 x_c*d2_l->fakt_x+X_GAP,
98 y_c*d2_l->fakt_y+Y_GAP,
99 d2_l->fakt_x,d2_l->fakt_y);
106 d2_l->p_surface->SetColor(d2_l->p_surface,0,0,0,0);
107 d2_l->p_surface->FillRectangle(d2_l->p_surface,
108 d2_l->info_x,d2_l->info_y,
109 d2_l->info_w,d2_l->info_h);
110 d2_l->p_surface->SetColor(d2_l->p_surface,r,g,b,a);
111 d2_l->p_surface->DrawRectangle(d2_l->p_surface,
112 d2_l->info_x,d2_l->info_y,
113 d2_l->info_w,d2_l->info_h);
114 d2_l->p_surface->SetColor(d2_l->p_surface,0x80,0x80,0xff,0xff);
115 for(i=1;i<=arg_c;i++)
117 d2_l->p_surface->DrawString(d2_l->p_surface,arg_v[i],-1,
118 d2_l->info_x+d2_l->fakt_x,
119 d2_l->info_y+d2_l->fakt_y+d2_l->font_h+(i-1)*2*d2_l->font_h,
122 /* now we flip all to surface */
123 d2_l->p_surface->Flip(d2_l->p_surface,NULL,0);