Index: config.doc ================================================================== --- config.doc +++ config.doc @@ -65,14 +65,16 @@ n = no window frame, p = hardware palette, r = allow the window to be resized, y = asynchronous blit, z = no parachute. Some flags might not work if the window manager does not support them. .screenHeight - Height of the window (not counting the border), in pixels. + Height of the window (not counting the border), in pixels. This should + be at least 480; the default is 600. .screenWidth - Width of the window (not counting the border), in pixels. + Width of the window (not counting the border), in pixels. This should + be at least 640; the default is 800. .showInventory True means to show the inventory in the margin by default; false means to show the move list in the margin by default. Either way, it is possible to change the display at run time. Index: picedit.c ================================================================== --- picedit.c +++ picedit.c @@ -163,10 +163,32 @@ if(t==2) c=fgetc(fp); if(t==3) c=p[-pic->size]; *p++=c; } } + +static inline void load_rotate(Picture*pic) { + int x,y; + int m=pic->meth; + int s=pic->size; + Uint8*d=pic->data+s; + static Uint8*buf; + Uint8*p; + if(!buf) { + buf=malloc(255*255); + if(!buf) fatal("Allocation failed\n"); + } + p=buf; + for(y=0;ydata,0,pict[i]->size=j); - j=(i?buf[n+1+((i-1)>>1)]>>(i&1?0:4):*buf>>4); + j=(i?buf[n+1+((i-1)>>1)]>>(i&1?0:4):*buf>>4)&15; pict[i]->meth=j^((j==5 || j==6)?3:0); } for(i=0;isize; if(pict[i]->meth==15) fread(pict[i]->data+j,j,j,fp),pict[i]->meth=0; else uncompress_picture(fp,pict[i]); - // Rotation - + if(pict[i]->meth) load_rotate(pict[i]); } fclose(fp); } + +static inline void show_cursor_xy(int x,int y) { + char buf[64]; + if(x>=0) snprintf(buf,64,"(%d,%d)%63s",x,y,""); + else snprintf(buf,64,"%63s",""); + SDL_LockSurface(screen); + draw_text(0,32,buf,0xF0,0xF9); + SDL_UnlockSurface(screen); + SDL_Flip(screen); +} static inline void edit_picture_1(Picture**pict,const char*name) { + static const Uint8 shade[64]= + "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F" + "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F" + "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F" + "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F" + ; + static const Uint8 gridlines[32]= + "\xF8\xFF\xF8\xFF\xF8\xFF\xF8\xFF\xF8\xFF\xF8\xFF\xF8\xFF\xF8\xFF" + "\xF8\xFF\xF8\xFF\xF8\xFF\xF8\xFF\xF8\xFF\xF8\xFF\xF8\xFF\xF8\xFF" + ; static Picture*pclip=0; + Uint8*p; + Uint8*q; Uint8 sel=0; + Uint8 cc=0; SDL_Rect r; SDL_Event ev; - int i,j,x; + int i,j,x,y,z; unsigned char buf[256]; set_cursor(XC_arrow); redraw: + if((sel&~15) || !pict[sel]) sel=0; + z=screen->w-pict[sel]->size-169; + if(z>screen->h-49) z=screen->h-49; + z/=pict[sel]->size; + if(z<2) return; + if(z>32) z=32; SDL_LockSurface(screen); + p=screen->pixels; r.x=r.y=0; r.w=screen->w; r.h=screen->h; SDL_FillRect(screen,&r,0xF0); draw_text(0,0,name,0xF0,0xF5); x=strlen(name)+1; for(i=0;i<16;i++) if(pict[i]) { j=snprintf(buf,255,"%c%d%c",i==sel?'<':' ',pict[i]->size,i==sel?'>':' '); draw_text(x<<3,0,buf,0xF0,i==sel?0xFF:0xF8); x+=j; } - + p=screen->pixels+40*screen->pitch; + q=pict[sel]->data+pict[sel]->size; + for(y=0;ysize;y++) { + memcpy(p,q,pict[sel]->size); + p+=screen->pitch; + q+=pict[sel]->size; + } + p=screen->pixels+40*screen->pitch-screen->w-161; + for(x=0;x<256;x++) { + for(y=0;y<10;y++) memset(p+y*screen->pitch,x,10); + if(x==cc) { + memset(p+1,0xF0,8); + for(y=1;y<9;y++) { + p[y*screen->pitch]=0xF0; + p[y*screen->pitch+(y&1)+4]=(y&1)+0xF7; + p[y*screen->pitch+9]=0xFF; + } + memset(p+9*screen->pitch+1,0xFF,8); + } + if(15&~x) p+=10; else p+=10*screen->pitch-150; + } + p=screen->pixels+41*screen->pitch+pict[sel]->size+2; + q=pict[sel]->data+pict[sel]->size; + for(y=0;ysize;y++) { + for(x=0;xsize;x++) { + memcpy(p,gridlines,z); + for(i=1;ipitch]=i&1?0xF8:0xFF; + if(*q) memset(p+i*screen->pitch+1,*q,z-1); + else memcpy(p+i*screen->pitch+1,shade+(i&15),z-1); + } + p+=z; + q++; + } + for(i=1;ipitch]=i&1?0xF8:0xFF; + p+=z*(screen->pitch-pict[sel]->size); + } + for(x=0;xsize;x++) { + memcpy(p,gridlines,z); + p+=z; + } SDL_UnlockSurface(screen); SDL_Flip(screen); while(SDL_WaitEvent(&ev)) { switch(ev.type) { case SDL_QUIT: exit(0); return; + case SDL_MOUSEMOTION: + if(ev.motion.xsize+2 || ev.motion.x>=pict[sel]->size*(z+1)+2 + || ev.motion.y<41 || ev.motion.y>=z*pict[sel]->size+41) { + x=-1; + set_cursor(XC_arrow); + } else { + x=(ev.motion.x-pict[sel]->size-2)/z; + y=(ev.motion.y-41)/z; + set_cursor(XC_tcross); + } + show_cursor_xy(x,y); + break; + case SDL_MOUSEBUTTONDOWN: + if(ev.button.x>=screen->w-161 && ev.button.xw-1 && ev.button.y>=40 && ev.button.y<200) { + x=(ev.button.x+161-screen->w)/10; + y=(ev.button.y-40)/10; + i=y*16+x; + switch(ev.button.button) { + case 1: cc=i; break; + } + goto redraw; + } + break; case SDL_KEYDOWN: switch(ev.key.keysym.sym) { case SDLK_ESCAPE: return; + case SDLK_LEFTBRACKET: case SDLK_LEFTPAREN: --sel; goto redraw; + case SDLK_RIGHTBRACKET: case SDLK_RIGHTPAREN: ++sel; goto redraw; + case SDLK_1 ... SDLK_9: sel=ev.key.keysym.sym-SDLK_1; goto redraw; } break; case SDL_VIDEOEXPOSE: goto redraw; } @@ -293,11 +410,11 @@ if(i) fatal("SQL error (%d): %s\n",i,sqlite3_errmsg(userdb)); ids=calloc(screen->h/8,sizeof(sqlite3_int64)); if(!ids) fatal("Allocation failed\n"); redraw: sqlite3_reset(st); - if(sc>max-screen->h/8) sc=max-screen->h/8; + if(sc>max-screen->h/8+1) sc=max-screen->h/8+1; if(sc<0) sc=0; sqlite3_bind_int(st,1,screen->h/8-1); sqlite3_bind_int(st,2,sc); SDL_LockSurface(screen); r.x=r.y=0; r.w=screen->w; r.h=screen->h; @@ -326,16 +443,16 @@ return; case SDLK_q: if(!(ev.key.keysym.mod&KMOD_CTRL)) break; if(!(ev.key.keysym.mod&KMOD_SHIFT)) save_picture_file(); return; - case SDLK_HOME: sc=0; goto redraw; - case SDLK_UP: if(sc) --sc; goto redraw; - case SDLK_DOWN: ++sc; goto redraw; - case SDLK_END: sc=max-screen->h/8; goto redraw; - case SDLK_PAGEUP: sc-=screen->h/8-1; goto redraw; - case SDLK_PAGEDOWN: sc+=screen->h/8-1; goto redraw; + case SDLK_HOME: case SDLK_KP7: sc=0; goto redraw; + case SDLK_UP: case SDLK_KP8: if(sc) --sc; goto redraw; + case SDLK_DOWN: case SDLK_KP2: ++sc; goto redraw; + case SDLK_END: case SDLK_KP1: sc=max-screen->h/8+1; goto redraw; + case SDLK_PAGEUP: case SDLK_KP9: sc-=screen->h/8-1; goto redraw; + case SDLK_PAGEDOWN: case SDLK_KP3: sc+=screen->h/8-1; goto redraw; case SDLK_F3: *ids=ask_picture_id("Edit:"); if(*ids) edit_picture(*ids); goto redraw; }