]> hackdaworld.org Git - physik/nlsop.git/commitdiff
initial checkin of dfbapi
authorhackbard <hackbard>
Mon, 12 May 2003 21:00:11 +0000 (21:00 +0000)
committerhackbard <hackbard>
Mon, 12 May 2003 21:00:11 +0000 (21:00 +0000)
dfbapi.c [new file with mode: 0644]
dfbapi.h [new file with mode: 0644]

diff --git a/dfbapi.c b/dfbapi.c
new file mode 100644 (file)
index 0000000..3d0e4d0
--- /dev/null
+++ b/dfbapi.c
@@ -0,0 +1,275 @@
+/*
+ * scientific visualization api for direct framebuffer
+ *
+ * author: hackbard@hackdaworld.dyndns.org
+ *
+ */
+
+#include <stdio.h>
+#include "dfbapi.h"
+
+/* two dimensional lattice */
+
+int d2_lattice_init(int *argc,char **argv,d2_lattice *d2_l,int x,int y)
+{
+ DFBSurfaceDescription surface_dsc;
+ DFBFontDescription font_dsc;
+ d2_l->max_x=x;
+ d2_l->max_y=y;
+
+ DirectFBInit(argc,&argv);
+ DirectFBCreate(&(d2_l->dfb));
+ d2_l->dfb->SetCooperativeLevel(d2_l->dfb,DFSCL_FULLSCREEN);
+
+ surface_dsc.flags=DSDESC_CAPS;
+ surface_dsc.caps=DSCAPS_PRIMARY|DSCAPS_FLIPPING;
+ d2_l->dfb->CreateSurface(d2_l->dfb,&surface_dsc,&(d2_l->p_surface));
+ 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->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-(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;
+ d2_l->info_h=d2_l->max_y*d2_l->fakt_y;
+
+ if((d2_l->s_height<(d2_l->max_y+2*Y_GAP)) || (d2_l->s_height<(d2_l->max_x+X_GAP)))
+ {
+  puts("resolution too low!");
+  return -1;
+ } 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);
+ d2_l->p_surface->Release(d2_l->p_surface);
+ d2_l->dfb->Release(d2_l->dfb);
+
+ return 1;
+}
+
+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)
+ {
+  *r=0xff;
+  *g=0;
+  *b=0;
+ } else
+ {
+  *r=0;
+  *g=0;
+  *b=0xff;
+ }
+ return 1;
+}
+
+int d2_lattice_draw(d2_lattice *d2_l,int x,int y,int arg_c,char **arg_v)
+{
+ int x_c,y_c;
+ int i;
+ unsigned char r,g,b,a;
+
+ a=0xff; /* no alpha blending */
+ for(x_c=0;x_c<d2_l->max_x;x_c++)
+ {
+  for(y_c=0;y_c<d2_l->max_y;y_c++)
+  {
+   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;
+    g=0xff;
+    b=0;
+   }
+   d2_l->p_surface->SetColor(d2_l->p_surface,r,g,b,a);
+   d2_l->p_surface->DrawRectangle(d2_l->p_surface,
+                                  x_c*d2_l->fakt_x+X_GAP,
+                                  y_c*d2_l->fakt_y+Y_GAP,
+                                  d2_l->fakt_x,d2_l->fakt_y);
+  }
+ }
+ r=0xff;
+ g=0xff;
+ b=0;
+ /* clear info box */
+ d2_l->p_surface->SetColor(d2_l->p_surface,0,0,0,0);
+ d2_l->p_surface->FillRectangle(d2_l->p_surface,
+                                d2_l->info_x,d2_l->info_y,
+                                d2_l->info_w,d2_l->info_h);
+ d2_l->p_surface->SetColor(d2_l->p_surface,r,g,b,a);
+ d2_l->p_surface->DrawRectangle(d2_l->p_surface,
+                                d2_l->info_x,d2_l->info_y,
+                                d2_l->info_w,d2_l->info_h);
+ d2_l->p_surface->SetColor(d2_l->p_surface,0x80,0x80,0xff,0xff);
+ for(i=1;i<=arg_c;i++)
+ {
+  d2_l->p_surface->DrawString(d2_l->p_surface,arg_v[i],-1,
+                              d2_l->info_x+d2_l->fakt_x,
+                              d2_l->info_y+d2_l->fakt_y+d2_l->font_h+(i-1)*2*d2_l->font_h,
+                              DSTF_LEFT);
+ }
+ /* now we flip all to surface */
+ d2_l->p_surface->Flip(d2_l->p_surface,NULL,0);
+ 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_x+d3_l->info_x,
+                                  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);
+  }
+ }
+
+ return 1;
+} 
diff --git a/dfbapi.h b/dfbapi.h
new file mode 100644 (file)
index 0000000..3692601
--- /dev/null
+++ b/dfbapi.h
@@ -0,0 +1,56 @@
+/* 
+ * scientific visualization api for direct framebuffer
+ *
+ * author: hackbard@hackdaworld.dyndns.org
+ *
+ */
+
+#include <directfb.h>
+
+/* two dimensional lattice */
+
+#define X_GAP 5
+#define Y_GAP X_GAP
+#define RED 1
+
+typedef struct __d2_lattice
+{
+ int max_x,max_y;
+ 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 */
+ IDirectFB *dfb;
+ IDirectFBSurface *p_surface;
+ IDirectFBFont *font;
+ IDirectFBInputDevice *keyboard;
+ 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 */
+ 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_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 dx_lattice_get_color(unsigned char *status,unsigned char *r,unsigned char *g,unsigned char *b);
+