Index: bindings.c ================================================================== --- bindings.c +++ bindings.c @@ -1,7 +1,7 @@ #if 0 -gcc ${CFLAGS:--s -O2} -c -Wno-unused-result bindings.c `sdl-config --cflags` +gcc ${CFLAGS:--s -O2} -c -Wno-multichar bindings.c `sdl-config --cflags` exit #endif /* This program is part of Free Hero Mesh and is public domain. @@ -155,5 +155,31 @@ if(m&KMOD_META) i|=MOD_META; if((m&KMOD_NUM) && kb->m[i|MOD_NUMLOCK].cmd) i|=MOD_NUMLOCK; return kb->m+i; } +int exec_key_binding(SDL_Event*ev,int editing,int x,int y,int(*cb)(int prev,int cmd,int number,int argc,sqlite3_stmt*args,void*aux),void*aux) { + const UserCommand*cmd=find_key_binding(ev,editing); + int prev=0; + int i; + switch(cmd->cmd) { + case 0: + return 0; + case '^': + return cb(0,cmd->n*'\0\1'+'^\0',0,0,0,aux); + case '=': case '-': case '+': + return cb(0,cmd->cmd*'\1\0'+'\0 ',cmd->n,0,0,aux); + case '\'': + return cb(0,'\' ',cmd->n,0,0,aux); + case '!': + system(cmd->txt); + return 0; + case 's': + sqlite3_reset(cmd->stmt); + sqlite3_clear_bindings(cmd->stmt); + + break; + default: + fprintf(stderr,"Confusion in exec_key_binding()\n"); + return 0; + } +} Index: edit.c ================================================================== --- edit.c +++ edit.c @@ -8,9 +8,59 @@ #include #include #include "sqlite3.h" #include "smallxrm.h" #include "heromesh.h" +#include "quarks.h" + +static void redraw_editor(void) { + SDL_Rect r; + int x,y; + r.x=r.y=0; + r.h=screen->h; + r.w=left_margin; + SDL_FillRect(screen,&r,0xF0); + r.x=left_margin-1; + r.w=1; + SDL_FillRect(screen,&r,0xF7); + r.x=left_margin; + r.w=screen->w-r.x; + SDL_FillRect(screen,&r,back_color); + for(x=1;x<=pfwidth;x++) for(y=1;y<=pfheight;y++) draw_cell(x,y); + SDL_Flip(screen); +} + +static void set_caption(void) { + const char*r; + char*s; + sqlite3_str*m; + int c; + optionquery[1]=Q_editTitle; + r=xrm_get_resource(resourcedb,optionquery,optionquery,2)?:"Free Hero Mesh - ~ - Edit"; + m=sqlite3_str_new(0); + c=strcspn(r,"~"); + sqlite3_str_append(m,r,c); + if(r[c]=='~') { + sqlite3_str_appendall(m,basefilename); + sqlite3_str_appendall(m,r+c+1); + } + s=sqlite3_str_finish(m); + if(s) SDL_WM_SetCaption(s,s); else SDL_WM_SetCaption("Free Hero Mesh","Free Hero Mesh"); + sqlite3_free(s); +} void run_editor(void) { - fatal("[Editor not implemented yet]\n"); // so far just a stub + SDL_Event ev; + set_caption(); + load_level(level_id); + redraw_editor(); + while(SDL_WaitEvent(&ev)) { + switch(ev.type) { + case SDL_VIDEOEXPOSE: + redraw_editor(); + break; + case SDL_QUIT: + exit(0); + break; + } + } } Index: picture.c ================================================================== --- picture.c +++ picture.c @@ -95,15 +95,16 @@ Uint32 o; Class*c; SDL_Rect dst={x,y,picture_size,picture_size}; if(x<1 || x>64 || y<1 || y>64) return; SDL_FillRect(screen,&dst,back_color); - o=playfield[y*64+x+65]; + o=playfield[y*64+x-65]; while(o!=VOIDLINK) { if(!(objects[o]->oflags&OF_INVISIBLE)) { c=classes[objects[o]->class]; - if(objects[o]->imagenimages) draw_picture(x*picture_size+left_margin,y*picture_size,c->images[objects[o]->image]&0x7FFF); + if(objects[o]->imagenimages) + draw_picture((x-1)*picture_size+left_margin,(y-1)*picture_size,c->images[objects[o]->image]&0x7FFF); } o=objects[o]->up; } }