Free Hero Mesh

Diff
Login
This is a mirror of the main repository for Free Hero Mesh. New tickets and changes will not be accepted at this mirror.

Differences From Artifact [ec2dd85ae4]:

To Artifact [59715bfb2c]:


13
14
15
16
17
18
19

20
21
22
23
24
25
26
#include <stdlib.h>
#include <string.h>
#include "SDL.h"
#include "sqlite3.h"
#include "smallxrm.h"
#include "quarks.h"
#include "heromesh.h"


#define MOD_SHIFT 1
#define MOD_CTRL 2
#define MOD_ALT 4
#define MOD_META 8
#define MOD_NUMLOCK 14
typedef struct {







>







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <stdlib.h>
#include <string.h>
#include "SDL.h"
#include "sqlite3.h"
#include "smallxrm.h"
#include "quarks.h"
#include "heromesh.h"
#include "cursorshapes.h"

#define MOD_SHIFT 1
#define MOD_CTRL 2
#define MOD_ALT 4
#define MOD_META 8
#define MOD_NUMLOCK 14
typedef struct {
215
216
217
218
219
220
221






































































222
223
224
225
226
227
228
      goto redraw;
    case SDL_QUIT:
      SDL_PushEvent(&ev);
      goto done;
  }
  done: if(tab) sqlite3_free_table(tab); sqlite3_free(err);
}







































































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) {







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







216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
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
295
296
297
298
299
      goto redraw;
    case SDL_QUIT:
      SDL_PushEvent(&ev);
      goto done;
  }
  done: if(tab) sqlite3_free_table(tab); sqlite3_free(err);
}

static int key_xy(void) {
  char buf[32];
  SDL_Rect r;
  SDL_Event ev;
  int x,y;
  int xc=pfwidth/2+1;
  int yc=pfheight/2+1;
  set_cursor(XC_hand1);
  redraw:
  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_LockSurface(screen);
  snprintf(buf,8,"(%2d,%2d)",xc,yc);
  draw_text(0,0,buf,0xF0,0xF7);
  SDL_UnlockSurface(screen);
  r.x=left_margin+(xc-1)*picture_size+picture_size/2;
  r.y=(yc-1)*picture_size;
  r.w=1;
  r.h=picture_size;
  SDL_FillRect(screen,&r,0xF6);
  r.x=left_margin+(xc-1)*picture_size;
  r.y=(yc-1)*picture_size+picture_size/2;
  r.w=picture_size;
  r.h=1;
  SDL_FillRect(screen,&r,0xF6);
  r.x=left_margin+(xc-1)*picture_size+picture_size/2;
  r.y=(yc-1)*picture_size+picture_size/2;
  r.w=r.h=2;
  SDL_FillRect(screen,&r,0xFE);
  SDL_Flip(screen);
  while(SDL_WaitEvent(&ev)) switch(ev.type) {
    case SDL_KEYDOWN:
      switch(ev.key.keysym.sym) {
        case SDLK_h: case SDLK_LEFT: case SDLK_KP4: if(xc>1) xc--; break;
        case SDLK_j: case SDLK_DOWN: case SDLK_KP2: if(yc<pfheight) yc++; break;
        case SDLK_k: case SDLK_UP: case SDLK_KP8: if(yc>1) yc--; break;
        case SDLK_l: case SDLK_RIGHT: case SDLK_KP6: if(xc<pfwidth) xc++; break;
        case SDLK_RETURN: case SDLK_KP_ENTER: case SDLK_SPACE: return xc+yc*64;
        case SDLK_ESCAPE: case SDLK_DELETE: case SDLK_q: return -1;
      }
      goto redraw;
    case SDL_MOUSEBUTTONDOWN:
      if(ev.button.x<left_margin) break;
      x=(ev.button.x-left_margin)/picture_size+1;
      y=ev.button.y/picture_size+1;
      if(x>0 && x<=pfwidth && y>0 && y<=pfheight) {
        xc=x,yc=y;
        if(ev.button.button==2) return xc+yc*64;
        if(ev.button.button==3) return -1;
        goto redraw;
      }
      break;
    case SDL_VIDEOEXPOSE:
      goto redraw;
    case SDL_QUIT:
      SDL_PushEvent(&ev);
      return -1;
  }
  return -1;
}

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) {
252
253
254
255
256
257
258




259
260
261
262
263
264
265
              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);
          }
        }







>
>
>
>







323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
              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(!sqlite3_stricmp(name+1,"KEY_XY")) {
              j=key_xy();
              if(j<0) return 0;
              sqlite3_bind_int(cmd->stmt,i,j);
            }
          } else if(*name==':') {
            name=screen_prompt(name);
            if(!name) return 0;
            sqlite3_bind_text(cmd->stmt,i,name,-1,SQLITE_TRANSIENT);
          }
        }