Free Hero Mesh

Check-in [9dce768c07]
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:Implement possibility of user-defined macros in picture editor.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 9dce768c07620712ab0d88d26f3b53b4f96fc4b4
User & Date: user on 2021-12-03 23:44:41
Other Links: manifest | tags
Context
2021-12-04
06:13
Corrections in picedit.c due to recent things added check-in: 33fb27825a user: user tags: trunk
2021-12-03
23:44
Implement possibility of user-defined macros in picture editor. check-in: 9dce768c07 user: user tags: trunk
20:32
Implement the spare page in the picture editor. check-in: 72f318849b user: user tags: trunk
Changes

Modified config.doc from [b814633d5f] to [f22e7e5fbd].

78
79
80
81
82
83
84




85
86
87
88
89
90
91
  internal palette is used instead). The file format is hex rrggbb format
  separated by any kind of whitespaces.

.pasteCommand
  The command to use for pasting text from the clipboard. When it asks for
  a single line of text, you can push SHIFT+INSERT to paste.





.progress
  If positive, how many steps between dots in the progress report for the
  auto testing mode. If negative, number of milliseconds to sleep before
  each level is executed.

.replaySpeed
  When the slow replay is used, sets the playback speed; this is a number







>
>
>
>







78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
  internal palette is used instead). The file format is hex rrggbb format
  separated by any kind of whitespaces.

.pasteCommand
  The command to use for pasting text from the clipboard. When it asks for
  a single line of text, you can push SHIFT+INSERT to paste.

.picedit.macro.?
  Define a macro in the picture editor, if you push ALT and a letter,
  will execute a SQL statement.

.progress
  If positive, how many steps between dots in the progress report for the
  auto testing mode. If negative, number of milliseconds to sleep before
  each level is executed.

.replaySpeed
  When the slow replay is used, sets the playback speed; this is a number

Modified picedit.c from [fdf7a1a60f] to [38f77ed3d9].

62
63
64
65
66
67
68

69
70
71
72
73
74
75
  int pos;
} Cursor;

static Uint8 cur_type;
static Uint8 gsizes[16];
static Picture*cur_pic;
static Picture*spare_page;


static void fn_valid_name(sqlite3_context*cxt,int argc,sqlite3_value**argv) {
  const char*s=sqlite3_value_text(*argv);
  if(!s || !*s || s[strspn(s,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-0123456789")]) {
    sqlite3_result_error(cxt,"Invalid name",-1);
    return;
  }







>







62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
  int pos;
} Cursor;

static Uint8 cur_type;
static Uint8 gsizes[16];
static Picture*cur_pic;
static Picture*spare_page;
static sqlite3_stmt**macro[26];

static void fn_valid_name(sqlite3_context*cxt,int argc,sqlite3_value**argv) {
  const char*s=sqlite3_value_text(*argv);
  if(!s || !*s || s[strspn(s,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-0123456789")]) {
    sqlite3_result_error(cxt,"Invalid name",-1);
    return;
  }
156
157
158
159
160
161
162













163
164
165
166
167
168
169
  .xEof=vt_graph_eof,
  .xFilter=vt_graph_filter,
  .xNext=vt_graph_next,
  .xOpen=vt_graph_open,
  .xRowid=vt_graph_rowid,
  .xUpdate=vt_graph_update,
};














static int load_picture_file(void) {
  sqlite3_stmt*st=0;
  FILE*fp;
  char*nam;
  char*buf=0;
  int r=0;







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







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
  .xEof=vt_graph_eof,
  .xFilter=vt_graph_filter,
  .xNext=vt_graph_next,
  .xOpen=vt_graph_open,
  .xRowid=vt_graph_rowid,
  .xUpdate=vt_graph_update,
};

static void*load_macros_1(xrm_db*db,void*usr,int loose,xrm_quark q) {
  const char*txt;
  if(q<Q_A || q>Q_Z) return 0;
  if(!(db=xrm_sub(db,loose,q)) || !(txt=xrm_get(db))) return 0;
  if(sqlite3_prepare_v3(userdb,txt,-1,SQLITE_PREPARE_PERSISTENT,macro+(q-Q_A),0)) fatal("Error in macro:  %s\n%s\n",txt,sqlite3_errmsg(userdb));
  return 0;
}

static void*load_macros(xrm_db*db,void*usr) {
  xrm_enumerate(db,load_macros_1,0);
  return 0;
}

static int load_picture_file(void) {
  sqlite3_stmt*st=0;
  FILE*fp;
  char*nam;
  char*buf=0;
  int r=0;
908
909
910
911
912
913
914































915
916
917
918
919
920
921
              if(!m.w) m.x=m.y=m.h=0;
              flood(x,y,m.x,m.y,m.w?:pict[sel]->size,m.h?:pict[sel]->size,cc,pict[sel]->data[(y+1)*pict[sel]->size+x],i);
          }
          goto redraw;
        }
        break;
      case SDL_KEYDOWN:































        switch(ev.key.keysym.sym) {
          case SDLK_ESCAPE: return;
          case SDLK_LEFTBRACKET: case SDLK_LEFTPAREN: --sel; m.x=m.y=m.w=m.h=0; goto redraw;
          case SDLK_RIGHTBRACKET: case SDLK_RIGHTPAREN: ++sel; m.x=m.y=m.w=m.h=0; goto redraw;
          case SDLK_1 ... SDLK_9: sel=ev.key.keysym.sym-SDLK_1; m.x=m.y=m.w=m.h=0; goto redraw;
          case SDLK_c: t=6; xx=yy=-1; goto redraw;
          case SDLK_d: t=0; xx=yy=-1; goto redraw;







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







922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
              if(!m.w) m.x=m.y=m.h=0;
              flood(x,y,m.x,m.y,m.w?:pict[sel]->size,m.h?:pict[sel]->size,cc,pict[sel]->data[(y+1)*pict[sel]->size+x],i);
          }
          goto redraw;
        }
        break;
      case SDL_KEYDOWN:
        if((ev.key.keysym.mod&(KMOD_ALT|KMOD_META)) && ev.key.keysym.sym>=SDLK_a && ev.key.keysym.sym<=SDLK_z) {
          sqlite3_stmt*st=macro[ev.key.keysym.sym-SDLK_a];
          if(!st) goto redraw;
          sqlite3_reset(st);
          sqlite3_bind_int(st,sqlite3_bind_parameter_index(st,"$cc"),cc);
          sqlite3_bind_int(st,sqlite3_bind_parameter_index(st,"$xx"),xx);
          sqlite3_bind_int(st,sqlite3_bind_parameter_index(st,"$yy"),yy);
          sqlite3_bind_int(st,sqlite3_bind_parameter_index(st,"$mx"),m.x);
          sqlite3_bind_int(st,sqlite3_bind_parameter_index(st,"$my"),m.y);
          sqlite3_bind_int(st,sqlite3_bind_parameter_index(st,"$mw"),m.w);
          sqlite3_bind_int(st,sqlite3_bind_parameter_index(st,"$mh"),m.h);
          while((i=sqlite3_step(st))==SQLITE_ROW) {
            for(j=0;j<sqlite3_data_count(st);) switch(sqlite3_column_int(st,j++)) {
              case 1:
                xx=sqlite3_column_int(st,j++);
                yy=sqlite3_column_int(st,j++);
                break;
              case 2:
                m.x=sqlite3_column_int(st,j++);
                m.y=sqlite3_column_int(st,j++);
                m.w=sqlite3_column_int(st,j++);
                m.h=sqlite3_column_int(st,j++);
                break;
              case 3:
                cc=sqlite3_column_int(st,j++);
                break;
            }
          }
          if(i!=SQLITE_DONE) screen_message(sqlite3_errmsg(userdb));
          goto redraw;
        }
        switch(ev.key.keysym.sym) {
          case SDLK_ESCAPE: return;
          case SDLK_LEFTBRACKET: case SDLK_LEFTPAREN: --sel; m.x=m.y=m.w=m.h=0; goto redraw;
          case SDLK_RIGHTBRACKET: case SDLK_RIGHTPAREN: ++sel; m.x=m.y=m.w=m.h=0; goto redraw;
          case SDLK_1 ... SDLK_9: sel=ev.key.keysym.sym-SDLK_1; m.x=m.y=m.w=m.h=0; goto redraw;
          case SDLK_c: t=6; xx=yy=-1; goto redraw;
          case SDLK_d: t=0; xx=yy=-1; goto redraw;
1624
1625
1626
1627
1628
1629
1630



1631
1632
1633
1634
1635
1636
1637
  int max=load_picture_file();
  int i,n;
  sqlite3_create_function(userdb,"VALID_NAME",1,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_valid_name,0,0);
  sqlite3_create_module(userdb,"GRAPH",&vt_graph,0);
  init_palette();
  optionquery[1]=Q_imageSize;
  picture_size=strtol(xrm_get_resource(resourcedb,optionquery,optionquery,2)?:"16",0,10);



  if(!*gsizes) *gsizes=picture_size;
  set_cursor(XC_arrow);
  set_caption();
  i=sqlite3_prepare_v3(userdb,"SELECT `ID`,SUBSTR(`NAME`,1,LENGTH(`NAME`)-4),`TYPE` FROM `PICEDIT` WHERE `TYPE` ORDER BY `NAME` LIMIT ?1 OFFSET ?2;",-1,SQLITE_PREPARE_PERSISTENT,&st,0);
  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");







>
>
>







1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
  int max=load_picture_file();
  int i,n;
  sqlite3_create_function(userdb,"VALID_NAME",1,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_valid_name,0,0);
  sqlite3_create_module(userdb,"GRAPH",&vt_graph,0);
  init_palette();
  optionquery[1]=Q_imageSize;
  picture_size=strtol(xrm_get_resource(resourcedb,optionquery,optionquery,2)?:"16",0,10);
  optionquery[1]=Q_picedit;
  optionquery[2]=Q_macro;
  xrm_search(resourcedb,optionquery,optionquery,3,load_macros,0);
  if(!*gsizes) *gsizes=picture_size;
  set_cursor(XC_arrow);
  set_caption();
  i=sqlite3_prepare_v3(userdb,"SELECT `ID`,SUBSTR(`NAME`,1,LENGTH(`NAME`)-4),`TYPE` FROM `PICEDIT` WHERE `TYPE` ORDER BY `NAME` LIMIT ?1 OFFSET ?2;",-1,SQLITE_PREPARE_PERSISTENT,&st,0);
  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");

Modified quarks from [6c4bb42f1f] to [26a85bfadd].

194
195
196
197
198
199
200




201
202
203
204
205
206
207
class
quiz

! Solutions
saveSolutions
solutionComment
solutionTimestamp





! SQL settings
sqlFile
sqlInit
sqlExtensions
sqlMemStatus
sqlSmallAllocations







>
>
>
>







194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
class
quiz

! Solutions
saveSolutions
solutionComment
solutionTimestamp

! Picture editor
picedit
macro

! SQL settings
sqlFile
sqlInit
sqlExtensions
sqlMemStatus
sqlSmallAllocations

Modified quarks.h from [2d3b356f67] to [e74f951205].

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
#define Q_allowMouseWarp 164
#define Q_middle 165
#define Q_class 166
#define Q_quiz 167
#define Q_saveSolutions 168
#define Q_solutionComment 169
#define Q_solutionTimestamp 170


#define Q_sqlFile 171
#define Q_sqlInit 172
#define Q_sqlExtensions 173
#define Q_sqlMemStatus 174
#define Q_sqlSmallAllocations 175
#define Q_sqlCoveringIndexScan 176
#define Q_sqlPowerSafe 177
#define Q_level 178
#define Q_tracePrefix 179
#define Q_stackProtection 180
#define Q_maxObjects 181
#define Q_traceAll 182
#define Q_traceObject 183
#define Q_showInventory 184
#define Q_progress 185
#define Q_autoSave 186
#define Q_maxTrigger 187
#define Q_pasteCommand 188
#define Q_codepage 189
#define Q_replaySpeed 190
#define Q_autoWin 191
static const char*const global_quarks[]={
  "screenWidth",
  "screenHeight",
  "margin",
  "palette",
  "popupColors",
  "imageSize",







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







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
#define Q_allowMouseWarp 164
#define Q_middle 165
#define Q_class 166
#define Q_quiz 167
#define Q_saveSolutions 168
#define Q_solutionComment 169
#define Q_solutionTimestamp 170
#define Q_picedit 171
#define Q_macro 172
#define Q_sqlFile 173
#define Q_sqlInit 174
#define Q_sqlExtensions 175
#define Q_sqlMemStatus 176
#define Q_sqlSmallAllocations 177
#define Q_sqlCoveringIndexScan 178
#define Q_sqlPowerSafe 179
#define Q_level 180
#define Q_tracePrefix 181
#define Q_stackProtection 182
#define Q_maxObjects 183
#define Q_traceAll 184
#define Q_traceObject 185
#define Q_showInventory 186
#define Q_progress 187
#define Q_autoSave 188
#define Q_maxTrigger 189
#define Q_pasteCommand 190
#define Q_codepage 191
#define Q_replaySpeed 192
#define Q_autoWin 193
static const char*const global_quarks[]={
  "screenWidth",
  "screenHeight",
  "margin",
  "palette",
  "popupColors",
  "imageSize",
354
355
356
357
358
359
360


361
362
363
364
365
366
367
  "allowMouseWarp",
  "middle",
  "class",
  "quiz",
  "saveSolutions",
  "solutionComment",
  "solutionTimestamp",


  "sqlFile",
  "sqlInit",
  "sqlExtensions",
  "sqlMemStatus",
  "sqlSmallAllocations",
  "sqlCoveringIndexScan",
  "sqlPowerSafe",







>
>







356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
  "allowMouseWarp",
  "middle",
  "class",
  "quiz",
  "saveSolutions",
  "solutionComment",
  "solutionTimestamp",
  "picedit",
  "macro",
  "sqlFile",
  "sqlInit",
  "sqlExtensions",
  "sqlMemStatus",
  "sqlSmallAllocations",
  "sqlCoveringIndexScan",
  "sqlPowerSafe",