Free Hero Mesh

Check-in [df17ecd054]
Login
This is a mirror of the main repository for Free Hero Mesh. New tickets and changes will not be accepted at this mirror.
Overview
Comment:Add some mode-independent binding commands
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: df17ecd054480685c3301b68cf471d5b1e074508
User & Date: user on 2020-12-15 03:23:55
Other Links: manifest | tags
Context
2020-12-15
05:21
Add some documentation files. check-in: b9ac4c0116 user: user tags: trunk
03:23
Add some mode-independent binding commands check-in: df17ecd054 user: user tags: trunk
02:26
Change the command code of the "select level" command from '^L' to 'go' since a ^ command is not helpful for this situation check-in: 870cc89301 user: user tags: trunk
Changes

Modified bindings.c from [21ad796e4d] to [ff3e323781].

152
153
154
155
156
157
158

























































159
160
161
162
163
164
165
  if(m&KMOD_CTRL) i|=MOD_CTRL;
  if(m&KMOD_SHIFT) i|=MOD_SHIFT;
  if(m&KMOD_ALT) i|=MOD_ALT;
  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,j,k;
  const char*name;
  if(ev->type==SDL_MOUSEBUTTONDOWN && !x && !y && ev->button.x>=left_margin) {







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
  if(m&KMOD_CTRL) i|=MOD_CTRL;
  if(m&KMOD_SHIFT) i|=MOD_SHIFT;
  if(m&KMOD_ALT) i|=MOD_ALT;
  if(m&KMOD_META) i|=MOD_META;
  if((m&KMOD_NUM) && kb->m[i|MOD_NUMLOCK].cmd) i|=MOD_NUMLOCK;
  return kb->m+i;
}

static void sql_interactive(void) {
  const char*t=screen_prompt("<SQL>");
  const char*u;
  SDL_Rect r;
  SDL_Event ev;
  sqlite3_stmt*st=0;
  int i,j,y;
  int k=0;
  if(!t) return;
  if(sqlite3_prepare_v2(userdb,t,-1,&st,0)) screen_message(sqlite3_errmsg(userdb));
  if(!st) return;
  redraw:
  r.x=r.y=0;
  r.w=screen->w;
  r.h=screen->h;
  SDL_FillRect(screen,&r,0xF0);
  SDL_LockSurface(screen);
  if(!k) draw_text(0,0,t,0xF8,0xFB);
  y=8-k;
  while((i=sqlite3_step(st))==SQLITE_ROW) {
    if(y>=0) {
      if(y>screen->h-8) break;
      for(i=j=0;i<sqlite3_data_count(st);i++) {
        u=sqlite3_column_text(st,i);
        draw_text(j,y,"\xB3",0xF0,0xF9),j+=8;
        if(u) draw_text(j,y,u,0xF0,0xF7),j+=strlen(u)*8; else draw_text(j,y,"\x04",0xF0,0xF4),j+=8;
      }
    }
    y+=8;
  }
  if(y>=0 && y<=screen->h-8) {
    if(i==SQLITE_DONE) draw_text(0,y,"--END--",0xF8,0xFA); else draw_text(0,y,sqlite3_errmsg(userdb),0xF8,0xFC);
  }
  SDL_UnlockSurface(screen);
  sqlite3_reset(st);
  SDL_Flip(screen);
  while(SDL_WaitEvent(&ev)) switch(ev.type) {
    case SDL_KEYDOWN:
      switch(ev.key.keysym.sym) {
        case SDLK_ESCAPE: case SDLK_RETURN: case SDLK_KP_ENTER: goto done;
        case SDLK_UP: k-=8; if(k<0) k=0; break;
        case SDLK_DOWN: k+=8; break;
        case SDLK_HOME: k=0; break;
        case SDLK_PAGEUP: k-=screen->h; if(k<0) k=0; break;
        case SDLK_PAGEDOWN: k+=screen->h; break;
      }
      goto redraw;
    case SDL_VIDEOEXPOSE:
      goto redraw;
    case SDL_QUIT:
      SDL_PushEvent(&ev);
      goto done;
  }
  done:
  sqlite3_finalize(st);
}

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,j,k;
  const char*name;
  if(ev->type==SDL_MOUSEBUTTONDOWN && !x && !y && ev->button.x>=left_margin) {
201
202
203
204
205
206
207









208
209
210
211
212
213

214
215
216
217

218
219
220
221
222
223
224
225
226
          }
        }
      }
      while((i=sqlite3_step(cmd->stmt))==SQLITE_ROW) {
        if(i=sqlite3_data_count(cmd->stmt)) {
          j=(i>1&&sqlite3_column_type(cmd->stmt,1)!=SQLITE_NULL)?sqlite3_column_int(cmd->stmt,1):y*64+x;
          if((name=sqlite3_column_text(cmd->stmt,0)) && *name) {









            k=name[0]*'\1\0'+name[1]*'\0\1';
            while(i && sqlite3_column_type(cmd->stmt,i-1)==SQLITE_NULL) i--;
            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;
  }
}







>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
>




>









258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
          }
        }
      }
      while((i=sqlite3_step(cmd->stmt))==SQLITE_ROW) {
        if(i=sqlite3_data_count(cmd->stmt)) {
          j=(i>1&&sqlite3_column_type(cmd->stmt,1)!=SQLITE_NULL)?sqlite3_column_int(cmd->stmt,1):y*64+x;
          if((name=sqlite3_column_text(cmd->stmt,0)) && *name) {
            if(name[0]==':') {
              switch(name[1]) {
                case '!': if(i>1) i=system(sqlite3_column_text(cmd->stmt,1)?:(const unsigned char*)"# "); break;
                case ';': i=SQLITE_DONE; goto done;
                case '?': if(i>1) puts(sqlite3_column_text(cmd->stmt,1)?:(const unsigned char*)"(null)"); break;
                case 'm': if(i>1) screen_message(sqlite3_column_text(cmd->stmt,1)?:(const unsigned char*)"(null)"); break;
                case 'x': sql_interactive(); break;
              }
            } else {
              k=name[0]*'\1\0'+name[1]*'\0\1';
              while(i && sqlite3_column_type(cmd->stmt,i-1)==SQLITE_NULL) i--;
              prev=cb(prev,k,j,i,cmd->stmt,aux);
              if(prev<0) {
                i=SQLITE_DONE;
                goto done;
              }
            }
          }
        }
      }
      done:
      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;
  }
}