*/
#include <stdio.h>
+#include <directfb.h>
#include "dfbapi.h"
/* two dimensional lattice */
d2_l->p_surface->GetSize(d2_l->p_surface,&(d2_l->s_width),&(d2_l->s_height));
font_dsc.flags=DFDESC_HEIGHT;
- font_dsc.height=d2_l->max_y*((d2_l->s_height)/(d2_l->max_y))/40; /* 40 ? */
+ font_dsc.height=d2_l->s_height/40; /* 40 ? */
d2_l->font_h=font_dsc.height;
d2_l->dfb->CreateFont(d2_l->dfb,FONT,&font_dsc,&(d2_l->font));
d2_l->p_surface->SetFont(d2_l->p_surface,d2_l->font);
- d2_l->fakt_y=(d2_l->s_height)/(d2_l->max_y+(2*Y_GAP));
- d2_l->fakt_x=(d2_l->s_height)/(d2_l->max_x+X_GAP); /* bullshit, i can't imagine atm */
+ d2_l->fakt_y=(d2_l->s_height-(2*Y_GAP))/(d2_l->max_y);
+ d2_l->fakt_x=(d2_l->s_height-X_GAP)/(d2_l->max_x); /* bullshit, i can't imagine atm */
d2_l->info_x=d2_l->fakt_x*d2_l->max_x+2*X_GAP;
d2_l->info_y=Y_GAP;
d2_l->info_w=d2_l->s_width-d2_l->info_x-2*X_GAP;
} else return 1;
}
+int d3_lattice_init(int *argc,char **argv,d3_lattice *d3_l,int x,int y,int z)
+{
+ DFBSurfaceDescription surface_dsc;
+ DFBFontDescription font_dsc;
+
+ d3_l->max_x=x;
+ d3_l->max_y=y;
+ d3_l->max_z=z;
+
+ DirectFBInit(argc,&argv);
+ DirectFBCreate(&(d3_l->dfb));
+ d3_l->dfb->SetCooperativeLevel(d3_l->dfb,DFSCL_FULLSCREEN);
+
+ surface_dsc.flags=DSDESC_CAPS;
+ surface_dsc.caps=DSCAPS_PRIMARY|DSCAPS_FLIPPING;
+ d3_l->dfb->CreateSurface(d3_l->dfb,&surface_dsc,&(d3_l->p_surface));
+ d3_l->p_surface->GetSize(d3_l->p_surface,&(d3_l->s_width),&(d3_l->s_height));
+
+ font_dsc.flags=DFDESC_HEIGHT;
+ font_dsc.height=d3_l->s_height/40; /* 40 ? */
+ d3_l->font_h=font_dsc.height;
+ d3_l->dfb->CreateFont(d3_l->dfb,FONT,&font_dsc,&(d3_l->font));
+ d3_l->p_surface->SetFont(d3_l->p_surface,d3_l->font);
+
+ d3_l->fakt_y=(d3_l->s_height-(3*Y_GAP))/(d3_l->max_z+d3_l->max_y);
+ d3_l->fakt_x=(d3_l->s_width-(3*X_GAP))/(d3_l->max_x+d3_l->max_y);
+ d3_l->info_x=d3_l->fakt_x*d3_l->max_x+(2*X_GAP);
+ d3_l->info_y=d3_l->fakt_y*d3_l->max_z+(2*Y_GAP);
+ d3_l->info_w=d3_l->fakt_x*d3_l->max_y;
+ d3_l->info_h=d3_l->fakt_y*d3_l->max_y;
+
+ return 1;
+}
+
int d2_lattice_release(d2_lattice *d2_l)
{
d2_l->font->Release(d2_l->font);
return 1;
}
-int d2_lattice_get_color(unsigned char *status,unsigned char *r,unsigned char *g,unsigned char *b)
+int d3_lattice_release(d3_lattice *d3_l)
+{
+ d3_l->font->Release(d3_l->font);
+ d3_l->p_surface->Release(d3_l->p_surface);
+ d3_l->dfb->Release(d3_l->dfb);
+
+ return 1;
+}
+
+int dx_lattice_get_color(unsigned char *status,unsigned char *r,unsigned char *g,unsigned char *b)
{
if((*status)&RED)
{
{
for(y_c=0;y_c<d2_l->max_y;y_c++)
{
- d2_lattice_get_color((*d2_l).status+x_c+y_c*d2_l->max_x,&r,&g,&b);
+ dx_lattice_get_color((*d2_l).status+x_c+y_c*d2_l->max_x,&r,&g,&b);
if(x_c==x && y_c==y)
{
r=0xff;
return 1;
}
-
+
+int d3_lattice_draw(d3_lattice *d3_l,int x,int y,int z,int arg_c,char **arg_v)
+{
+ int x_c,y_c,z_c;
+ int i;
+ unsigned char r,g,b,a;
+
+ a=0xff; /* no alpha blending */
+
+ y_c=y;
+ for(x_c=0;x_c<d3_l->max_x;x_c++)
+ {
+ for(z_c=0;z_c<d3_l->max_z;z_c++)
+ {
+ 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);
+ if(x_c==x && z_c==z)
+ {
+ r=0xff;
+ g=0xff;
+ b=0;
+ }
+ d3_l->p_surface->SetColor(d3_l->p_surface,r,g,b,a);
+ d3_l->p_surface->DrawRectangle(d3_l->p_surface,
+ x_c*d3_l->fakt_x+X_GAP,
+ z_c*d3_l->fakt_y+Y_GAP,
+ d3_l->fakt_x,d3_l->fakt_y);
+ }
+ }
+
+ x_c=x;
+ for(y_c=0;y_c<d3_l->max_y;y_c++)
+ {
+ for(z_c=0;z_c<d3_l->max_z;z_c++)
+ {
+ 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);
+ if(y_c==y && z_c==z)
+ {
+ r=0xff;
+ g=0xff;
+ b=0;
+ }
+ d3_l->p_surface->SetColor(d3_l->p_surface,r,g,b,a);
+ d3_l->p_surface->DrawRectangle(d3_l->p_surface,
+ y_c*d3_l->fakt_x+d3_l->info_x,
+ z_c*d3_l->fakt_y+Y_GAP,
+ d3_l->fakt_x,d3_l->fakt_y);
+ }
+ }
+
+ z_c=z;
+ for(x_c=0;x_c<d3_l->max_x;x_c++)
+ {
+ for(y_c=0;y_c<d3_l->max_y;y_c++)
+ {
+ 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);
+ if(x_c==x && y_c==y)
+ {
+ r=0xff;
+ g=0xff;
+ b=0;
+ }
+ d3_l->p_surface->SetColor(d3_l->p_surface,r,g,b,a);
+ d3_l->p_surface->DrawRectangle(d3_l->p_surface,
+ x_c*d3_l->fakt_x+X_GAP,
+ y_c*d3_l->fakt_y+d3_l->info_y,
+ d3_l->fakt_x,d3_l->fakt_y);
+ }
+ }
+
+ r=0xff;
+ g=0xff;
+ b=0;
+ /* clear info box */
+ d3_l->p_surface->SetColor(d3_l->p_surface,0,0,0,0);
+ d3_l->p_surface->FillRectangle(d3_l->p_surface,
+ d3_l->info_x,d3_l->info_y,
+ d3_l->info_w,d3_l->info_h);
+ d3_l->p_surface->SetColor(d3_l->p_surface,r,g,b,a);
+ d3_l->p_surface->DrawRectangle(d3_l->p_surface,
+ d3_l->info_x,d3_l->info_y,
+ d3_l->info_w,d3_l->info_h);
+ d3_l->p_surface->DrawLine(d3_l->p_surface,
+ d3_l->info_x+d3_l->info_w/2,
+ d3_l->info_y,
+ d3_l->info_x+d3_l->info_w/2,
+ d3_l->info_y+d3_l->info_h);
+ d3_l->p_surface->SetColor(d3_l->p_surface,0x80,0x80,0xff,0xff);
+ for(i=1;i<=arg_c;i++)
+ {
+ if(i<8)
+ {
+ d3_l->p_surface->DrawString(d3_l->p_surface,arg_v[i],-1,
+ d3_l->info_x+d3_l->fakt_x,
+ d3_l->info_y+d3_l->fakt_y+d3_l->font_h+(i-1)*2*d3_l->font_h,
+ DSTF_LEFT);
+ } else
+ {
+ d3_l->p_surface->DrawString(d3_l->p_surface,arg_v[i],-1,
+ d3_l->info_x+d3_l->info_w/2+d3_l->fakt_x,
+ d3_l->info_y+d3_l->fakt_y+d3_l->font_h+(i%8-1)*2*d3_l->font_h,
+ DSTF_LEFT);
+ }
+ }
+
+ /* now we flip all to surface */
+ d3_l->p_surface->Flip(d3_l->p_surface,NULL,0);
+
+ return 1;
+}
+
+int d2_event_init(d2_lattice *d2_l)
+{
+ d2_l->dfb->GetInputDevice(d2_l->dfb,DIDID_KEYBOARD,&(d2_l->keyboard));
+ d2_l->keyboard->CreateEventBuffer(d2_l->keyboard,&(d2_l->k_buffer));
+
+ return 1;
+}
+
+int d3_event_init(d3_lattice *d3_l)
+{
+ d3_l->dfb->GetInputDevice(d3_l->dfb,DIDID_KEYBOARD,&(d3_l->keyboard));
+ d3_l->keyboard->CreateEventBuffer(d3_l->keyboard,&(d3_l->k_buffer));
+
+ return 1;
+}
+
+int scan_event(d3_lattice *d3_l,int *x,int *y,int *z,int *q,int *esc)
+{
+ DFBInputEvent ke;
+
+ d3_l->k_buffer->GetEvent(d3_l->k_buffer,DFB_EVENT(&ke));
+ if(ke.type==DIET_KEYPRESS)
+ {
+ if(ke.key_id==DIKI_LEFT && *x!=0) *x-=1;
+ if(ke.key_id==DIKI_RIGHT && *x!=d3_l->max_x-1) *x+=1;
+ if(ke.key_id==DIKI_DOWN && *y!=0) *y-=1;
+ if(ke.key_id==DIKI_UP && *y!=d3_l->max_y-1) *y+=1;
+ if(ke.key_id==DIKI_PAGE_DOWN && *z!=0) *z-=1;
+ if(ke.key_id==DIKI_PAGE_UP && *z!=d3_l->max_z-1) *z+=1;
+ if(ke.key_id==DIKI_Q) *q=1;
+ if(ke.key_id==DIKI_ESCAPE) *esc=1;
+ }
+
+ return 1;
+}
+
*
*/
+#ifndef DFBAPI_H
+#define DFBAPI_H
+
#include <directfb.h>
/* two dimensional lattice */
int info_w,info_h;
int font_h;
unsigned char *status; /* status&1 -> red, else blue */
+ int *extra; /* store extra values */
+ void *v_ptr; /* void ptr, for any use */
IDirectFB *dfb;
IDirectFBSurface *p_surface;
IDirectFBFont *font;
IDirectFBEventBuffer *k_buffer;
} d2_lattice;
+typedef struct __d3_lattice
+{
+ int max_x,max_y,max_z;
+ int s_height,s_width;
+ int fakt_x,fakt_y;
+ int info_x,info_y;
+ int info_w,info_h;
+ int font_h;
+ unsigned char *status; /* status&1 -> red, else blue */
+ int *extra; /* store extra values */
+ void *v_ptr; /* void ptr, for any use */
+ IDirectFB *dfb;
+ IDirectFBSurface *p_surface;
+ IDirectFBFont *font;
+ IDirectFBInputDevice *keyboard;
+ IDirectFBEventBuffer *k_buffer;
+} d3_lattice;
+
/* function prototypes */
int d2_lattice_init(int *argc,char **argv,d2_lattice *d2_l,int x,int y);
int d2_lattice_release(d2_lattice *d2_l);
-int d2_lattice_get_color(unsigned char *status,unsigned char *r,unsigned char *g,unsigned char *b);
int d2_lattice_draw(d2_lattice *d2_l,int x,int y,int arg_c,char **arg_v);
+int d3_lattice_init(int *argc,char **argv,d3_lattice *d3_l,int x,int y,int z);
+int d3_lattice_release(d3_lattice *d3_l);
+int d3_lattice_draw(d3_lattice *d3_l,int x,int y,int z,int arg_c,char **arg_v);
+int d2_event_init(d2_lattice *d2_l);
+int d3_event_init(d3_lattice *d3_l);
+int scan_event(d3_lattice *d3_l,int *x,int *y,int *z,int *q,int *esc);
+int dx_lattice_get_color(unsigned char *status,unsigned char *r,unsigned char *g,unsigned char *b);
+#endif /* DFBAPI_H */