void vgaputi(int16_t x, int16_t y, uint8_t * p, int16_t w, int16_t h) { VGLBitmap *tmp; struct PendNode tmpn; struct PendNode *newn; static int pending_match = 0; tmpn.realx = virt2scrx(x); tmpn.realy = virt2scry(y); tmpn.realw = virt2scrw(w * 4); tmpn.realh = virt2scrh(h); newn = find_pending(&tmpn); if (newn == NULL) { newn = malloc(sizeof (struct PendNode)); memset(newn, 0x00, (sizeof (struct PendNode))); newn->realx = tmpn.realx; newn->realy = tmpn.realy; newn->realw = tmpn.realw; newn->realh = tmpn.realh; pendappend(newn); } else { rect_merge(newn, &tmpn); pending_match += 1; if (pending_match < 10 || pending_match % 50 == 0) { fprintf(stderr, "vgaputi: pending_match = %d\n", pending_match); } } memcpy(&tmp, p, (sizeof(VGLBitmap *))); VGLBitmapCopy(tmp, 0, 0, sVGLDisplay, tmpn.realx, tmpn.realy, tmpn.realw, tmpn.realh); }
void doscreenupdate(void) { struct PendNode *ptr; int pendnum = 0; fprintf(stderr, "doscreenupdate: pendnum =%d\n", pendups.pendnum); for (ptr = pendups.First; ptr != NULL; ptr = pendups.First) { VGLBitmapCopy(sVGLDisplay, ptr->realx, ptr->realy, VGLDisplay, ptr->realx, ptr->realy + yoffset, ptr->realw, ptr->realh); pendups.First = ptr->nextnode; free(ptr); pendnum += 1; } assert(pendnum == pendups.pendnum); pendups.pendnum = 0; #if 0 VGLBitmapCopy(sVGLDisplay, 0, 0, VGLDisplay, 0, yoffset, 640, 400); #endif }
void vgageti(int16_t x, int16_t y, uint8_t * p, int16_t w, int16_t h) { struct PendNode *ptr; VGLBitmap *tmp; int16_t realx, realy, realh, realw; memcpy(&tmp, p, (sizeof(VGLBitmap *))); if (tmp != NULL) VGLBitmapDestroy(tmp); /* Destroy previously allocated bitmap */ realx = virt2scrx(x); realy = virt2scry(y); realw = virt2scrw(w * 4); realh = virt2scrh(h); tmp = VGLBitmapCreate(MEMBUF, realw, realh, NULL); VGLBitmapAllocateBits(tmp); VGLBitmapCopy(sVGLDisplay, realx, realy, tmp, 0, 0, realw, realh); memcpy(p, &tmp, (sizeof(VGLBitmap *))); }
void display( VGLBitmap *pic, byte *red, byte *green, byte *blue, struct action *e) { VGLBitmap target; int x,y,i=0,j=0; VGLMouseMode(VGL_MOUSEHIDE); VGLRestorePalette(); /* XXX Broken in r!=2. Libvgl bug. */ //VGLClear(VGLDisplay,0); VGLBitmapCopy(&bkg,0,0,VGLDisplay,0,0,bkg.Xsize,bkg.Ysize); if(e!=NULL) { if(e->zoom!=1 || e->rotate) { target.Bitmap=(byte *)calloc(pic->Xsize*pic->Ysize*e->zoom*e->zoom,1); if(e->rotate) { target.Xsize=pic->Ysize*e->zoom; target.Ysize=pic->Xsize*e->zoom; } else { target.Xsize=pic->Xsize*e->zoom; target.Ysize=pic->Ysize*e->zoom; } target.Type=pic->Type; for(x=0;x<pic->Xsize;x++) { for(y=0;y<pic->Ysize;y++) { for(i=0;i<e->zoom;i++) { for(j=0;j<e->zoom;j++) { if(e->rotate) { VGLSetXY(&target,target.Xsize-(e->zoom*y+i),e->zoom*x+j,VGLGetXY(pic,x,y)); } else { VGLSetXY(&target,e->zoom*x+i,e->zoom*y+j,VGLGetXY(pic,x,y)); } } } } } } else { target.Bitmap=(byte *)calloc(pic->Xsize*pic->Ysize,sizeof(byte)); target.Xsize=pic->Xsize; target.Ysize=pic->Ysize; target.Type=pic->Type; VGLBitmapCopy(pic,0,0,&target,0,0,pic->Xsize,pic->Ysize); } } else { target.Bitmap=(byte *)calloc(pic->Xsize*pic->Ysize,sizeof(byte)); target.Xsize=pic->Xsize; target.Ysize=pic->Ysize; target.Type=pic->Type; VGLBitmapCopy(pic,0,0,&target,0,0,pic->Xsize,pic->Ysize); } VGLSetPalette(red, green, blue); if(e!=NULL) { VGLBitmapCopy(&target,0,0,VGLDisplay,e->Xshift,e->Yshift,target.Xsize,target.Ysize); } else { VGLBitmapCopy(&target,0,0,VGLDisplay,0,0,target.Xsize,target.Ysize); } VGLMouseMode(VGL_MOUSESHOW); free(target.Bitmap); }
int pop_up(char *title,int x, int y) { VGLBitmap sav,clr; int x1,y1,width,height,i,j; int last_pos,cur_pos,max_item; char buttons; char *t; sav.Type=VGLDisplay->Type; clr.Type=VGLDisplay->Type; width=0; height=0; max_item=0; i=0; while(std_menu[i].descr!=NULL) { height++; max_item++; if(strlen(std_menu[i].descr)>width) width=strlen(std_menu[i].descr); i++; } width=width*8+2; height=height*9+4+8; sav.Xsize=width; sav.Ysize=height; clr.Xsize=width; clr.Ysize=height; sav.Bitmap=(byte *)calloc(width*height,1); clr.Bitmap=(byte *)calloc(width*height,1); if(x>(VGLDisplay->Xsize-width)) x1=VGLDisplay->Xsize-width; else x1=x; if(y>(VGLDisplay->Ysize-height)) y1=VGLDisplay->Ysize-height; else y1=y; VGLMouseMode(VGL_MOUSEHIDE); VGLBitmapCopy(VGLDisplay,x1,y1,&sav,0,0,width,height); VGLFilledBox(VGLDisplay,x1,y1,x1+width-1,y1+height-1,pal_colors-1); VGLBitmapString(VGLDisplay,x1+1,y1+1,title,0,pal_colors-1,0,0); VGLLine(VGLDisplay,x1,y1+9,x1+width,y1+9,0); i=0; while(std_menu[i].descr!=NULL) { VGLBitmapString(VGLDisplay,x1+1,y1+11+i*9,std_menu[i].descr,0,pal_colors-1,0,0); i++; } last_pos=-1; VGLMouseMode(VGL_MOUSESHOW); do { pause(); VGLMouseStatus(&x,&y,&buttons); cur_pos=(y-y1-11)/9; if((cur_pos<0)||(cur_pos>max_item-1)) { if(last_pos==-1) last_pos=0; VGLBitmapString(VGLDisplay,x1+1,y1+11+last_pos*9,std_menu[last_pos].descr,0,pal_colors-1,0,0); last_pos=-1; } else if(last_pos!=cur_pos) { if(last_pos==-1) last_pos=0; VGLBitmapString(VGLDisplay,x1+1,y1+11+last_pos*9,std_menu[last_pos].descr,0,pal_colors-1,0,0); VGLBitmapString(VGLDisplay,x1+1,y1+11+cur_pos*9,std_menu[cur_pos].descr,pal_colors/2+1,pal_colors-1,0,0); last_pos=cur_pos; } } while (buttons & MOUSE_BUTTON3DOWN); VGLMouseMode(VGL_MOUSEHIDE); /* XXX Screws up totally when r==3. Libvgl bug! */ VGLBitmapCopy(&clr,0,0,VGLDisplay,x1,y1,width,height); VGLBitmapCopy(&sav,0,0,VGLDisplay,x1,y1,width,height); VGLMouseMode(VGL_MOUSESHOW); free(sav.Bitmap); free(clr.Bitmap); changed++; if((cur_pos>=0) && (cur_pos<max_item)) { std_menu[cur_pos].func(x,y,std_menu[cur_pos].hotkey); } changed++; return(0); }
int main(int argc, char **argv) { int y, xsize, ysize, i,j; VGLBitmap *tmp; // set graphics mode, here 320x240 256 colors // supported modes are (from <sys/consio.h>): // SW_VGA_CG320: std VGA 320x200 256 colors // SW_VGA_MODEX: Modex VGA 320x240 256 colors // SW_VGA_VG640: std VGA 640x480 16 colors VGLInit(SW_VGA_MODEX); // initialize mouse and show pointer VGLMouseInit(VGL_MOUSESHOW); // VGLDisplay is a ptr to a struct Bitmap defined and initialized by // libvgl. The Bitmap points directly to screen memory etc. xsize=VGLDisplay->Xsize; ysize=VGLDisplay->Ysize; // alloc a new bitmap tmp = VGLBitmapCreate(MEMBUF, 256, 256, NULL); VGLBitmapAllocateBits(tmp); VGLClear(tmp, 0); // fill the screen with colored lines for (y=0; y<ysize; y++) VGLLine(VGLDisplay, 0, y, xsize-1, y, y/2 % 256); // draw some lines and circles just to show off VGLLine(VGLDisplay, 0, 0, xsize-1, ysize-1, 63); VGLLine(VGLDisplay, 0, ysize-1, xsize-1, 0, 63); VGLLine(VGLDisplay, 0, 0, 0, ysize-1, 63); VGLLine(VGLDisplay, xsize-1, 0, xsize-1, ysize-1, 63); VGLEllipse(VGLDisplay, 256, 0, 256, 256, 63); VGLEllipse(VGLDisplay, 0, 256, 256, 256, 0); // some text is also useful VGLBitmapString(VGLDisplay, 100,100, "This is text", 63, 0, 0, VGL_DIR_RIGHT); sleep(2); VGLBitmapString(VGLDisplay, 100,100, "This is text", 63, 0, 0, VGL_DIR_UP); sleep(2); VGLBitmapString(VGLDisplay, 100,100, "This is text", 63, 0, 0, VGL_DIR_LEFT); sleep(2); VGLBitmapString(VGLDisplay, 100,100, "This is text", 63, 0, 0, VGL_DIR_DOWN); sleep(2); // now show some simple bitblit for (i=0; i<256; i++) for (j=0; j<256; j++) tmp->Bitmap[i+256*j] = i%16; VGLBitmapCopy(tmp, 0, 0, VGLDisplay, 0, 0, 128, 128); for (i=0; i<256; i++) for (j=0; j<256; j++) tmp->Bitmap[i+256*j] = j%16; VGLBitmapCopy(tmp, 0, 0, VGLDisplay, 3, 128, 128, 128); sleep(2); VGLBitmapCopy(VGLDisplay, 237, 311, tmp, 64, 64, 128, 128); VGLBitmapCopy(tmp, 32, 32, VGLDisplay, 400, 128, 128, 128); sleep(2); VGLBitmapCopy(VGLDisplay, 300, 300, VGLDisplay, 500, 128, 128, 128); sleep(5); i=0; // loop around drawing and copying while (++i) { VGLBitmapCopy(VGLDisplay, rand()%xsize, rand()%ysize, VGLDisplay, rand()%xsize, rand()%ysize, rand()%xsize, rand()%ysize); VGLLine(VGLDisplay, rand()%xsize, rand()%ysize, rand()%xsize, rand()%ysize, rand()%256); VGLEllipse(VGLDisplay, rand()%xsize, rand()%ysize, rand()%xsize/2, rand()%ysize/2, rand()%256); rand(); if (i > 1000) break; } // restore screen to its original mode VGLEnd(); return 0; }