Index: bindings.c ================================================================== --- bindings.c +++ bindings.c @@ -158,11 +158,16 @@ } 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; + int i,j,k; + const char*name; + if(ev->type==SDL_MOUSEBUTTONDOWN && !x && !y && ev->button.x>=left_margin) { + x=(ev->button.x-left_margin)/picture_size+1; + y=ev->button.y/picture_size+1; + } switch(cmd->cmd) { case 0: return 0; case '^': return cb(0,cmd->n*'\0\1'+'^\0',0,0,0,aux); @@ -169,17 +174,51 @@ 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); + i=system(cmd->txt); return 0; case 's': sqlite3_reset(cmd->stmt); sqlite3_clear_bindings(cmd->stmt); - - break; + if(sqlite3_bind_parameter_count(cmd->stmt)) { + for(i=sqlite3_bind_parameter_count(cmd->stmt);i;--i) if(name=sqlite3_bind_parameter_name(cmd->stmt,i)) { + if(*name=='$') { + if(!sqlite3_stricmp(name+1,"X")) { + if(x) sqlite3_bind_int(cmd->stmt,i,x); + } else if(!sqlite3_stricmp(name+1,"Y")) { + if(y) sqlite3_bind_int(cmd->stmt,i,y); + } else if(!sqlite3_stricmp(name+1,"LEVEL")) { + sqlite3_bind_int(cmd->stmt,i,level_ord); + } else if(!sqlite3_stricmp(name+1,"LEVEL_ID")) { + sqlite3_bind_int(cmd->stmt,i,level_id); + } + } else if(*name==':') { + name=screen_prompt(name); + if(!name) return 0; + sqlite3_bind_text(cmd->stmt,i,name,-1,SQLITE_TRANSIENT); + } + } + } + while((i=sqlite3_step(cmd->stmt))==SQLITE_ROW) { + if(i=sqlite3_data_count(cmd->stmt)) { + j=i>1?sqlite3_column_int(cmd->stmt,1):0; + if((name=sqlite3_column_text(cmd->stmt,0)) && *name) { + k=name[0]*'\1\0'+name[1]*'\0\1'; + prev=cb(prev,k,j,i,cmd->stmt,aux); + if(prev<0) { + i=SQLITE_DONE; + break; + } + } + } + } + sqlite3_reset(cmd->stmt); + sqlite3_clear_bindings(cmd->stmt); + if(i!=SQLITE_DONE) fprintf(stderr,"SQL error in key binding: %s\n",sqlite3_errmsg(userdb)?:"unknown error"); + return prev; default: fprintf(stderr,"Confusion in exec_key_binding()\n"); return 0; } } Index: cursorshapes.h ================================================================== --- cursorshapes.h +++ cursorshapes.h @@ -75,10 +75,11 @@ #define XC_umbrella 146 #define XC_ur_angle 148 #define XC_watch 150 #define XC_xterm 152 #endif +#ifdef HEROMESH_MAIN static const Uint8 cursorimg[]={ 0,0,112,14,120,30,124,62,62,124,31,248,15,240,7,224,7,224,15,240,31,248,62,124,124,62,120,30,112,14,0,0, 240,15,248,31,252,63,254,127,127,254,63,252,31,248,15,240,15,240,31,248,63,252,127,254,254,127,252,63,248,31,240,15, 0,0,0,6,0,30,0,124,1,252,7,248,31,248,1,240,3,240,7,96,14,96,28,64,56,64,112,0,32,0,0,0, 0,7,0,31,0,127,1,254,7,254,31,252,63,252,63,248,7,248,15,240,31,240,62,224,124,224,248,64,112,0,32,0, @@ -309,5 +310,6 @@ 130, 161, 249, 72, }; +#endif Index: edit.c ================================================================== --- edit.c +++ edit.c @@ -1,7 +1,7 @@ #if 0 -gcc ${CFLAGS:--s -O2} -c edit.c `sdl-config --cflags` +gcc ${CFLAGS:--s -O2} -c -Wno-multichar edit.c `sdl-config --cflags` exit #endif #include "SDL.h" #include @@ -9,10 +9,11 @@ #include #include "sqlite3.h" #include "smallxrm.h" #include "heromesh.h" #include "quarks.h" +#include "cursorshapes.h" static void redraw_editor(void) { SDL_Rect r; int x,y; r.x=r.y=0; @@ -24,10 +25,13 @@ 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_LockSurface(screen); + draw_text(0,0,"EDIT",0xF0,0xF7); + SDL_UnlockSurface(screen); SDL_Flip(screen); } static void set_caption(void) { const char*r; @@ -45,13 +49,25 @@ } 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); } + +static int editor_command(int prev,int cmd,int number,int argc,sqlite3_stmt*args,void*aux) { + switch(cmd) { + case '^P': // Play + return -2; + case '^Q': // Quit + return -1; + default: + return prev; + } +} void run_editor(void) { SDL_Event ev; + int i; set_caption(); load_level(level_id); redraw_editor(); while(SDL_WaitEvent(&ev)) { switch(ev.type) { @@ -58,9 +74,24 @@ case SDL_VIDEOEXPOSE: redraw_editor(); break; case SDL_QUIT: exit(0); + break; + case SDL_MOUSEMOTION: + set_cursor(ev.motion.xw,16}; + int m=r.w>>3; + SDL_Event ev; + if(!t) { + t=malloc(m+2); + if(!t) fatal("Allocation failed\n"); + } + *t=0; + SDL_FillRect(screen,&r,0xF1); + r.y=16; + r.h=1; + SDL_FillRect(screen,&r,0xF8); + SDL_LockSurface(screen); + draw_text(0,0,txt,0xF1,0xFE); + draw_text(0,8,"\xB1",0xF1,0xFB); + SDL_UnlockSurface(screen); + set_cursor(XC_iron_cross); + SDL_Flip(screen); + r.y=8; + r.h=8; + while(SDL_WaitEvent(&ev)) { + switch(ev.type) { + case SDL_QUIT: + SDL_PushEvent(&ev); + return 0; + case SDL_KEYDOWN: + SDL_FillRect(screen,&r,0xF1); + switch(ev.key.keysym.sym) { + case SDLK_RETURN: case SDLK_KP_ENTER: + r.y=0; + r.h=17; + SDL_FillRect(screen,&r,0xF0); + t[n]=0; + return t; + case SDLK_BACKSPACE: case SDLK_DELETE: + if(n) t[n--]=0; + break; + case SDLK_CLEAR: + t[n=0]=0; + break; + default: + if(ev.key.keysym.sym==SDLK_u && (ev.key.keysym.mod&KMOD_CTRL)) { + t[n=0]=0; + } else if(ev.key.keysym.sym==SDLK_c && (ev.key.keysym.mod&KMOD_CTRL)) { + r.y=0; + r.h=17; + SDL_FillRect(screen,&r,0xF0); + return 0; + } else if(n=32 && !(ev.key.keysym.mod&KMOD_CTRL)) { + t[n++]=ev.key.keysym.unicode; + t[n]=0; + } + } + t[n]=0; + SDL_FillRect(screen,&r,0xF1); + SDL_LockSurface(screen); + draw_text(0,8,t,0xF1,0xFF); + draw_text(n<<3,8,"\xB1",0xF1,0xFB); + SDL_UnlockSurface(screen); + SDL_Flip(screen); + } + } +} static Uint16 decide_picture_size(int nwantsize,const Uint8*wantsize,const Uint16*havesize,int n) { int i,j; if(!nwantsize) fatal("Unable to determine what picture size is wanted\n"); for(i=0;i