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))/20; /* 20 ? */
32 d2_l->dfb->CreateFont(d2_l->dfb,FONT,&font_dsc,&(d2_l->font));
33 d2_l->p_surface->SetFont(d2_l->p_surface,d2_l->font);
35 d2_l->fakt_y=(d2_l->s_height)/(d2_l->max_y+(2*Y_GAP));
36 d2_l->fakt_x=(d2_l->s_height)/(d2_l->max_x+X_GAP); /* bullshit, i can't imagine atm */
37 d2_l->info_x=d2_l->fakt_x*d2_l->max_x+2*X_GAP;
39 d2_l->info_w=d2_l->s_width-d2_l->info_x-2*X_GAP;
40 d2_l->info_h=d2_l->max_y*d2_l->fakt_y;
42 if((d2_l->s_height<(d2_l->max_y+2*Y_GAP)) || (d2_l->s_height<(d2_l->max_x+X_GAP)))
44 puts("resolution too low!");
49 int d2_lattice_release(d2_lattice *d2_l)
51 d2_l->font->Release(d2_l->font);
52 d2_l->p_surface->Release(d2_l->p_surface);
53 d2_l->dfb->Release(d2_l->dfb);
58 int d2_lattice_get_color(unsigned char *status,unsigned char *r,unsigned char *g,unsigned char *b)
75 int d2_lattice_draw(d2_lattice *d2_l,int x,int y,int arg_c,char **arg_v)
79 unsigned char r,g,b,a;
81 a=0xff; /* no alpha blending */
83 for(x_c=0;x_c<d2_l->max_x;x_c++)
85 for(y_c=0;y_c<d2_l->max_y;y_c++)
87 d2_lattice_get_color((*d2_l).status+x_c+y_c*d2_l->max_x,&r,&g,&b);
94 d2_l->p_surface->SetColor(d2_l->p_surface,r,g,b,a);
95 d2_l->p_surface->DrawRectangle(d2_l->p_surface,
96 x_c*d2_l->fakt_x+X_GAP,
97 y_c*d2_l->fakt_y+Y_GAP,
98 d2_l->fakt_x,d2_l->fakt_y);
105 d2_l->p_surface->SetColor(d2_l->p_surface,0,0,0,0);
106 d2_l->p_surface->FillRectangle(d2_l->p_surface,
107 d2_l->info_x,d2_l->info_y,
108 d2_l->info_w,d2_l->info_h);
109 d2_l->p_surface->SetColor(d2_l->p_surface,r,g,b,a);
110 d2_l->p_surface->DrawRectangle(d2_l->p_surface,
111 d2_l->info_x,d2_l->info_y,
112 d2_l->info_w,d2_l->info_h);
113 d2_l->p_surface->SetColor(d2_l->p_surface,0x80,0x80,0xff,0xff);
114 for(i=1;i<=arg_c;i++)
116 d2_l->p_surface->DrawString(d2_l->p_surface,arg_v[1],-1,
117 d2_l->info_x+d2_l->fakt_x,
118 d2_l->info_y+d2_l->fakt_x+(i-1)*d2_l->fakt_x,
121 /* now we flip all to surface */
122 d2_l->p_surface->Flip(d2_l->p_surface,NULL,0);