2 * display.c - visualization api
11 int display_init(u32 x,u32 y,u32 z,display *display,cell *cell,int *argc,char **argv)
14 DFBSurfaceDescription surface_dsc;
17 /* store dimensions */
21 /* store pointer to cells */
26 DirectFBInit(argc,&argv);
27 DirectFBCreate(&(display->dfb));
28 display->dfb->SetCooperativeLevel(display->dfb,DFSCL_FULLSCREEN);
29 surface_dsc.flags=DSDESC_CAPS;
30 surface_dsc.caps=DSCAPS_PRIMARY|DSCAPS_FLIPPING;
31 display->dfb->CreateSurface(display->dfb,&surface_dsc,&(display->primary_surface));
32 display->primary_surface->GetSize(display->primary_surface,&(display->screen_width),&(display->screen_height));
38 int display_release(display *display)
41 display->font->Release(display->font);
42 display->primary_surface->Release(display->primary_surface);
43 display->dfb->Release(display->dfb);
50 int dfb_choose_color(cell *cell_p,unsigned char *r,unsigned char *g,unsigned char *b)
52 if(cell_p->status&AMORPH)
67 int display_draw(display *display,u32 x,u32 y,u32 z)
70 int menu_x,menu_y,menu_w,menu_h; /* for the yellow box */
71 DFBFontDescription font_dsc;
74 unsigned char r,g,b,a;
75 int display_faktor_x,display_faktor_y;
76 a=0xff; /* no alpha blending */
77 if(((display->max_x+display->max_y+DISPLAY_X_FREE)>=display->screen_width)|
78 ((display->max_y+display->max_z+DISPLAY_Y_FREE)>=display->screen_height))
80 puts("resolution too low!");
83 display_faktor_x=display->screen_width/(display->max_x+display->max_y+DISPLAY_X_FREE);
84 display_faktor_y=display->screen_height/(display->max_z+display->max_y+DISPLAY_Y_FREE);
85 // if(display_faktor_x<display_faktor_y) display_faktor_y=display_faktor_x;
86 // if(display_faktor_y<display_faktor_x) display_faktor_x=display_faktor_y;
88 /* draw x-z surface */
90 for(x_c=0;x_c<display->max_x;x_c++)
92 for(z_c=0;z_c<display->max_z;z_c++)
94 dfb_choose_color(display->cell_p+x_c+y_c*display->max_x+z_c*display->max_x*display->max_y,&r,&g,&b);
96 display->primary_surface->SetColor(display->primary_surface,0xff,0xff,0,0);
98 display->primary_surface->SetColor(display->primary_surface,r,g,b,a);
99 display->primary_surface->DrawRectangle(display->primary_surface,x_c*display_faktor_x+DISPLAY_X_FREE/3,z_c*display_faktor_y+DISPLAY_Y_FREE/3,display_faktor_x,display_faktor_y);
102 /* draw y-z surface */
104 for(y_c=0;y_c<display->max_y;y_c++)
106 for(z_c=0;z_c<display->max_z;z_c++)
108 dfb_choose_color(display->cell_p+x_c+y_c*display->max_x+z_c*display->max_x*display->max_y,&r,&g,&b);
110 display->primary_surface->SetColor(display->primary_surface,0xff,0xff,0,0);
112 display->primary_surface->SetColor(display->primary_surface,r,g,b,a);
113 display->primary_surface->DrawRectangle(display->primary_surface,(y_c+display->max_x)*display_faktor_x+2*DISPLAY_X_FREE/3,z_c*display_faktor_y+DISPLAY_Y_FREE/3,display_faktor_x,display_faktor_y);
116 /* draw x-y surface */
118 for(x_c=0;x_c<display->max_x;x_c++)
120 for(y_c=0;y_c<display->max_y;y_c++)
122 dfb_choose_color(display->cell_p+x_c+y_c*display->max_x+z_c*display->max_x*display->max_y,&r,&g,&b);
124 display->primary_surface->SetColor(display->primary_surface,0xff,0xff,0,0);
126 display->primary_surface->SetColor(display->primary_surface,r,g,b,a);
127 display->primary_surface->DrawRectangle(display->primary_surface,x_c*display_faktor_x+DISPLAY_X_FREE/3,(y_c+display->max_z)*display_faktor_y+2*DISPLAY_Y_FREE/3,display_faktor_x,display_faktor_y);
130 /* display info window */
135 menu_x=2*DISPLAY_X_FREE/3+display->max_x*display_faktor_x;
136 menu_y=2*DISPLAY_Y_FREE/3+display->max_z*display_faktor_y;
137 menu_w=display->max_y*display_faktor_x;
138 menu_h=display->max_y*display_faktor_y;
139 display->primary_surface->SetColor(display->primary_surface,0,0,0,0);
140 display->primary_surface->FillRectangle(display->primary_surface,menu_x,menu_y,menu_w,menu_h);
141 display->primary_surface->SetColor(display->primary_surface,r,g,b,a);
142 display->primary_surface->DrawRectangle(display->primary_surface,menu_x,menu_y,menu_w,menu_h);
143 font_dsc.flags=DFDESC_HEIGHT;
144 font_dsc.height=menu_h/10;
145 display->dfb->CreateFont(display->dfb,DISPLAY_FONT,&font_dsc,&(display->font));
146 display->primary_surface->SetFont(display->primary_surface,display->font);
147 display->primary_surface->SetColor(display->primary_surface,0x80,0x80,0xff,0xff);
148 sprintf(text,"x: %u",x);
149 display->primary_surface->DrawString(display->primary_surface,text,-1,menu_x+display_faktor_x,menu_y+display_faktor_y+menu_h/10,DSTF_LEFT);
150 sprintf(text,"y: %u",y);
151 display->primary_surface->DrawString(display->primary_surface,text,-1,menu_x+display_faktor_x,menu_y+display_faktor_y*2+menu_h/10*2,DSTF_LEFT);
152 sprintf(text,"z: %u",z);
153 display->primary_surface->DrawString(display->primary_surface,text,-1,menu_x+display_faktor_x,menu_y+display_faktor_y*3+menu_h/10*3,DSTF_LEFT);
154 sprintf(text,"status: %c",((display->cell_p+x+y*display->max_x+z*display->max_x*display->max_y))->status&AMORPH?'a':'c');
155 display->primary_surface->DrawString(display->primary_surface,text,-1,menu_x+display_faktor_x,menu_y+display_faktor_y*5+menu_h/10*5,DSTF_LEFT);
156 sprintf(text,"c conc.: %u",(display->cell_p+x+y*display->max_x+z*display->max_x*display->max_y)->conc);
157 display->primary_surface->DrawString(display->primary_surface,text,-1,menu_x+display_faktor_x,menu_y+display_faktor_y*6+menu_h/10*6,DSTF_LEFT);
158 /* flip all to surface */
159 display->primary_surface->Flip(display->primary_surface,NULL,0);
164 int display_event_init(display *display)
167 display->dfb->GetInputDevice(display->dfb,DIDID_KEYBOARD,&(display->keyboard));
168 display->keyboard->CreateEventBuffer(display->keyboard,&(display->keyboard_buffer));
173 int display_scan_event(display *display,u32 *x,u32 *y,u32 *z,int *quit)
175 DFBInputEvent keyboard_event;
176 display->keyboard_buffer->WaitForEvent(display->keyboard_buffer);
177 display->keyboard_buffer->GetEvent(display->keyboard_buffer,DFB_EVENT(&keyboard_event));
178 if(keyboard_event.type==DIET_KEYPRESS)
180 if(keyboard_event.key_id==DIKI_LEFT && *x!=0) *x-=1;
181 if(keyboard_event.key_id==DIKI_RIGHT && *x!=display->max_x-1) *x+=1;
182 if(keyboard_event.key_id==DIKI_DOWN && *y!=0) *y-=1;
183 if(keyboard_event.key_id==DIKI_UP && *y!=display->max_y-1) *y+=1;
184 if(keyboard_event.key_id==DIKI_PAGE_UP && *z!=0) *z-=1;
185 if(keyboard_event.key_id==DIKI_PAGE_DOWN && *z!=display->max_z-1) *z+=1;
186 if(keyboard_event.key_id==DIKI_Q) *quit=1;