draw.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790
  1. /******************************************************************************
  2. * This file is part of TinTin++ *
  3. * *
  4. * Copyright 2004-2020 Igor van den Hoven *
  5. * *
  6. * TinTin++ is free software; you can redistribute it and/or modify *
  7. * it under the terms of the GNU General Public License as published by *
  8. * the Free Software Foundation; either version 3 of the License, or *
  9. * (at your option) any later version. *
  10. * *
  11. * This program is distributed in the hope that it will be useful, *
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  14. * GNU General Public License for more details. *
  15. * *
  16. * You should have received a copy of the GNU General Public License *
  17. * along with TinTin++. If not, see https://www.gnu.org/licenses. *
  18. ******************************************************************************/
  19. /******************************************************************************
  20. * T I N T I N + + *
  21. * *
  22. * coded by Igor van den Hoven 2019 *
  23. ******************************************************************************/
  24. static char draw_buf[100][10];
  25. static int draw_cnt;
  26. #include "tintin.h"
  27. DO_COMMAND(do_draw)
  28. {
  29. char *sub_arg, arg1[BUFFER_SIZE], arg2[BUFFER_SIZE], color[BUFFER_SIZE], code[BUFFER_SIZE], arg3[BUFFER_SIZE], input[BUFFER_SIZE];
  30. int index, flags;
  31. int top_row, top_col, bot_row, bot_col, rows, cols;
  32. substitute(ses, arg, input, SUB_VAR|SUB_FUN);
  33. arg = input;
  34. arg = get_arg_in_braces(ses, arg, arg1, GET_ONE);
  35. draw_cnt = 0;
  36. *color = 0;
  37. *code = 0;
  38. if (*arg1 == 0)
  39. {
  40. tintin_header(ses, " DRAW OPTIONS ");
  41. for (index = 0 ; *draw_table[index].fun ; index++)
  42. {
  43. if (*draw_table[index].name)
  44. {
  45. tintin_printf2(ses, " [%-24s] %s", draw_table[index].name, draw_table[index].desc);
  46. }
  47. }
  48. tintin_header(ses, "");
  49. }
  50. else
  51. {
  52. flags = HAS_BIT(ses->charset, CHARSET_FLAG_UTF8) ? DRAW_FLAG_UTF8 : 0;
  53. while (*arg)
  54. {
  55. if (!HAS_BIT(flags, DRAW_FLAG_COLOR) && translate_color_names(ses, arg1, code))
  56. {
  57. get_color_names(ses, arg1, color);
  58. SET_BIT(flags, DRAW_FLAG_COLOR);
  59. }
  60. else if (!HAS_BIT(flags, DRAW_FLAG_COLOR) && strip_vt102_strlen(ses, arg1) == 0)
  61. {
  62. strcpy(color, arg1);
  63. SET_BIT(flags, DRAW_FLAG_COLOR);
  64. }
  65. else if (is_abbrev(arg1, "ASCII"))
  66. {
  67. DEL_BIT(flags, DRAW_FLAG_UTF8);
  68. }
  69. else if (is_abbrev(arg1, "BLANKED"))
  70. {
  71. SET_BIT(flags, DRAW_FLAG_BLANKED);
  72. }
  73. else if (is_abbrev(arg1, "BOTTOM"))
  74. {
  75. SET_BIT(flags, DRAW_FLAG_BOT);
  76. }
  77. else if (is_abbrev(arg1, "BUMPED"))
  78. {
  79. SET_BIT(flags, DRAW_FLAG_BUMP);
  80. }
  81. else if (is_abbrev(arg1, "CIRCLED"))
  82. {
  83. SET_BIT(flags, DRAW_FLAG_CIRCLED);
  84. }
  85. else if (is_abbrev(arg1, "CONVERT"))
  86. {
  87. SET_BIT(flags, DRAW_FLAG_CONVERT);
  88. }
  89. else if (is_abbrev(arg1, "CROSSED"))
  90. {
  91. SET_BIT(flags, DRAW_FLAG_CROSSED);
  92. }
  93. else if (is_abbrev(arg1, "FILLED"))
  94. {
  95. SET_BIT(flags, DRAW_FLAG_FILLED);
  96. }
  97. else if (is_abbrev(arg1, "HORIZONTAL"))
  98. {
  99. SET_BIT(flags, DRAW_FLAG_HOR);
  100. }
  101. else if (is_abbrev(arg1, "JEWELED"))
  102. {
  103. SET_BIT(flags, DRAW_FLAG_JEWELED);
  104. }
  105. else if (is_abbrev(arg1, "JOINTED"))
  106. {
  107. SET_BIT(flags, DRAW_FLAG_CORNERED);
  108. }
  109. else if (is_abbrev(arg1, "LEFT"))
  110. {
  111. SET_BIT(flags, DRAW_FLAG_LEFT);
  112. }
  113. else if (is_abbrev(arg1, "GRID"))
  114. {
  115. SET_BIT(flags, DRAW_FLAG_GRID);
  116. }
  117. else if (is_abbrev(arg1, "HUGE"))
  118. {
  119. SET_BIT(flags, DRAW_FLAG_HUGE);
  120. }
  121. else if (is_abbrev(arg1, "NUMBERED"))
  122. {
  123. SET_BIT(flags, DRAW_FLAG_NUMBERED);
  124. }
  125. else if (is_abbrev(arg1, "PRUNED"))
  126. {
  127. SET_BIT(flags, DRAW_FLAG_PRUNED);
  128. }
  129. else if (is_abbrev(arg1, "RIGHT"))
  130. {
  131. SET_BIT(flags, DRAW_FLAG_RIGHT);
  132. }
  133. else if (is_abbrev(arg1, "ROUNDED"))
  134. {
  135. SET_BIT(flags, DRAW_FLAG_ROUNDED);
  136. }
  137. else if (is_abbrev(arg1, "SHADOWED"))
  138. {
  139. SET_BIT(flags, DRAW_FLAG_SHADOWED);
  140. }
  141. else if (is_abbrev(arg1, "TEED"))
  142. {
  143. SET_BIT(flags, DRAW_FLAG_TEED);
  144. }
  145. else if (is_abbrev(arg1, "TOP"))
  146. {
  147. SET_BIT(flags, DRAW_FLAG_TOP);
  148. }
  149. else if (is_abbrev(arg1, "TRACED"))
  150. {
  151. SET_BIT(flags, DRAW_FLAG_TRACED);
  152. }
  153. else if (is_abbrev(arg1, "TUBED"))
  154. {
  155. SET_BIT(flags, DRAW_FLAG_TUBED);
  156. }
  157. else if (is_abbrev(arg1, "UNICODE"))
  158. {
  159. SET_BIT(flags, DRAW_FLAG_UTF8);
  160. }
  161. else if (is_abbrev(arg1, "VERTICAL"))
  162. {
  163. SET_BIT(flags, DRAW_FLAG_VER);
  164. }
  165. else
  166. {
  167. break;
  168. }
  169. arg = get_arg_in_braces(ses, arg, arg1, GET_ONE);
  170. }
  171. for (index = 0 ; *draw_table[index].name ; index++)
  172. {
  173. if (is_abbrev(arg1, draw_table[index].name))
  174. {
  175. arg = sub_arg_in_braces(ses, arg, arg1, GET_ONE, SUB_VAR|SUB_FUN);
  176. sub_arg = get_arg_in_braces(ses, arg1, arg3, GET_ONE);
  177. if (*sub_arg)
  178. {
  179. strcpy(arg1, arg3);
  180. sub_arg = get_arg_in_braces(ses, sub_arg, arg2, GET_ONE);
  181. }
  182. else
  183. {
  184. arg = get_arg_in_braces(ses, arg, arg2, GET_ONE);
  185. }
  186. top_row = get_row_index(ses, arg1);
  187. top_col = get_col_index(ses, arg2);
  188. if (*sub_arg)
  189. {
  190. sub_arg = get_arg_in_braces(ses, sub_arg, arg1, GET_ONE);
  191. sub_arg = get_arg_in_braces(ses, sub_arg, arg2, GET_ONE);
  192. }
  193. else
  194. {
  195. arg = get_arg_in_braces(ses, arg, arg1, GET_ONE);
  196. arg = get_arg_in_braces(ses, arg, arg2, GET_ONE);
  197. }
  198. bot_row = get_row_index(ses, arg1);
  199. bot_col = get_col_index(ses, arg2);
  200. if (top_row == 0 && top_col == 0)
  201. {
  202. show_error(ses, LIST_COMMAND, "#SYNTAX: #DRAW [COLOR] [OPTIONS] {%s} <TOP_ROW> <TOP_COL> <BOT_ROW> <BOT_COL> [TEXT]", draw_table[index].name);
  203. return ses;
  204. }
  205. if (top_row == 0)
  206. {
  207. top_row = 1;
  208. SET_BIT(flags, DRAW_FLAG_SCROLL);
  209. }
  210. if (top_col == 0)
  211. {
  212. top_col = 1;
  213. }
  214. if (bot_row == 0)
  215. {
  216. bot_row = 1;
  217. }
  218. if (bot_col == 0)
  219. {
  220. bot_col = 1;
  221. }
  222. if (top_row > bot_row || top_col > bot_col)
  223. {
  224. show_error(ses, LIST_COMMAND, "#ERROR: #DRAW INVALID SQUARE: %s {%d %d %d %d} ROWS: %d COLS: %d", draw_table[index].name, top_row, top_col, bot_row, bot_col, 1 + bot_row - top_row, 1 + bot_col - top_col);
  225. return ses;
  226. }
  227. rows = URANGE(1, 1 + bot_row - top_row, gtd->screen->rows);
  228. cols = URANGE(1, 1 + bot_col - top_col, gtd->screen->cols);
  229. *arg1 = 0;
  230. *arg2 = 0;
  231. *arg3 = 0;
  232. if (*arg == 0)
  233. {
  234. arg = arg3;
  235. }
  236. save_pos(ses);
  237. if (HAS_BIT(flags, DRAW_FLAG_BUMP))
  238. {
  239. tintin_printf2(ses, "");
  240. }
  241. strcpy(arg2, code);
  242. draw_table[index].fun(ses, top_row, top_col, bot_row, bot_col, rows, cols, draw_table[index].flags | flags, color, arg, arg1, arg2);
  243. print_stdout("\e[0m");
  244. restore_pos(ses);
  245. return ses;
  246. }
  247. }
  248. show_error(ses, LIST_COMMAND, "#ERROR: #DRAW {%s} IS NOT A VALID OPTION.", capitalize(arg1));
  249. }
  250. return ses;
  251. }
  252. // utilities
  253. int find_stamp(char *in, char *out)
  254. {
  255. int cnt;
  256. for (cnt = 0 ; huge_stamp_table[cnt].name != NULL ; cnt++)
  257. {
  258. if (!strcmp(in, huge_stamp_table[cnt].name))
  259. {
  260. strcpy(out, huge_stamp_table[cnt].desc);
  261. return huge_stamp_table[cnt].length;
  262. }
  263. }
  264. tintin_printf2(gtd->ses, "debug: didn't find stamp {%s}", in);
  265. return 0;
  266. }
  267. void stamp_cat(char *color, int flags, char *str, char *cat, char *out)
  268. {
  269. char *pts = str;
  270. char *ptc = cat;
  271. char *pto = out;
  272. while (*pts || *ptc)
  273. {
  274. while (*pts && *pts != '\n')
  275. {
  276. *pto++ = *pts++;
  277. }
  278. pto += sprintf(pto, "%s", color);
  279. while (*ptc && *ptc != '\n')
  280. {
  281. if (HAS_BIT(flags, DRAW_FLAG_SHADOWED))
  282. {
  283. *pto++ = *ptc++;
  284. }
  285. else if (HAS_BIT(flags, DRAW_FLAG_TRACED))
  286. {
  287. if (!strncmp(ptc, "╗", 3))
  288. {
  289. pto += sprintf(pto, "┐");
  290. ptc += strlen("╗");
  291. }
  292. else if (!strncmp(ptc, "║", 3))
  293. {
  294. pto += sprintf(pto, "│");
  295. ptc += strlen("║");
  296. }
  297. else if (!strncmp(ptc, "╝", 3))
  298. {
  299. pto += sprintf(pto, "┘");
  300. ptc += strlen("╝");
  301. }
  302. else if (!strncmp(ptc, "╚", 3))
  303. {
  304. pto += sprintf(pto, "└");
  305. ptc += strlen("╚");
  306. }
  307. else if (!strncmp(ptc, "╔", 3))
  308. {
  309. pto += sprintf(pto, "┌");
  310. ptc += strlen("╔");
  311. }
  312. else if (!strncmp(ptc, "═", 3))
  313. {
  314. pto += sprintf(pto, "─");
  315. ptc += strlen("═");
  316. }
  317. else
  318. {
  319. *pto++ = *ptc++;
  320. }
  321. }
  322. else
  323. {
  324. if (!strncmp(ptc, "╗", 3))
  325. {
  326. pto += sprintf(pto, " ");
  327. ptc += strlen("╗");
  328. }
  329. else if (!strncmp(ptc, "║", 3))
  330. {
  331. pto += sprintf(pto, " ");
  332. ptc += strlen("║");
  333. }
  334. else if (!strncmp(ptc, "╝", 3))
  335. {
  336. pto += sprintf(pto, " ");
  337. ptc += strlen("╝");
  338. }
  339. else if (!strncmp(ptc, "╚", 3))
  340. {
  341. pto += sprintf(pto, " ");
  342. ptc += strlen("╚");
  343. }
  344. else if (!strncmp(ptc, "╔", 3))
  345. {
  346. pto += sprintf(pto, " ");
  347. ptc += strlen("╔");
  348. }
  349. else if (!strncmp(ptc, "═", 3))
  350. {
  351. pto += sprintf(pto, " ");
  352. ptc += strlen("═");
  353. }
  354. else
  355. {
  356. *pto++ = *ptc++;
  357. }
  358. }
  359. }
  360. if (*pts == '\n' && *ptc == '\n')
  361. {
  362. *pto++ = *pts++;
  363. ptc++;
  364. }
  365. else if (*ptc == '\n')
  366. {
  367. *pto++ = *ptc++;
  368. }
  369. }
  370. *pto = 0;
  371. }
  372. void string_to_stamp(struct session *ses, int flags, char *in, char *out)
  373. {
  374. char *pti, buf1[BUFFER_SIZE], buf2[BUFFER_SIZE], buf3[BUFFER_SIZE], chr1[CHAR_SIZE], color[COLOR_SIZE] = { 0 };
  375. int skip;
  376. push_call("string_to_stamp(%p,%d,%p,%p)",ses,flags,in,out);
  377. sub_arg_in_braces(ses, in, buf1, GET_ALL, SUB_COL|SUB_ESC);
  378. pti = buf1;
  379. buf3[0] = 0;
  380. while (*pti)
  381. {
  382. skip = skip_vt102_codes(pti);
  383. if (skip)
  384. {
  385. get_color_codes(color, pti, color, GET_ONE);
  386. pti += skip;
  387. continue;
  388. }
  389. pti = get_char(ses, pti, chr1);
  390. find_stamp(chr1, buf2);
  391. stamp_cat(color, flags, buf3, buf2, out);
  392. strcpy(buf3, out);
  393. }
  394. strcat(out, "\n");
  395. pop_call();
  396. return;
  397. }
  398. char *get_draw_corner(int flags, char *str)
  399. {
  400. draw_cnt = (draw_cnt + 1) % 100;
  401. if (HAS_BIT(flags, DRAW_FLAG_BLANKED))
  402. {
  403. strcpy(draw_buf[draw_cnt], " ");
  404. }
  405. else if (HAS_BIT(flags, DRAW_FLAG_NUMBERED))
  406. {
  407. sprintf(draw_buf[draw_cnt], "%d", draw_cnt % 10);
  408. }
  409. else if (HAS_BIT(flags, DRAW_FLAG_UTF8))
  410. {
  411. if (HAS_BIT(flags, DRAW_FLAG_PRUNED))
  412. {
  413. if (HAS_BIT(flags, DRAW_FLAG_SCROLL))
  414. {
  415. strcpy(draw_buf[draw_cnt], " ");
  416. }
  417. else
  418. {
  419. strcpy(draw_buf[draw_cnt], "\e[C");
  420. }
  421. }
  422. else if (HAS_BIT(flags, DRAW_FLAG_CIRCLED))
  423. {
  424. if (HAS_BIT(flags, DRAW_FLAG_CROSSED))
  425. {
  426. strcpy(draw_buf[draw_cnt], "ϴ");
  427. }
  428. else if (HAS_BIT(flags, DRAW_FLAG_FILLED))
  429. {
  430. strcpy(draw_buf[draw_cnt], "⬤");
  431. }
  432. else if (HAS_BIT(flags, DRAW_FLAG_VER))
  433. {
  434. strcpy(draw_buf[draw_cnt], "O");
  435. }
  436. else
  437. {
  438. strcpy(draw_buf[draw_cnt], "○");
  439. }
  440. }
  441. else if (HAS_BIT(flags, DRAW_FLAG_CROSSED))
  442. {
  443. if (HAS_BIT(flags, DRAW_FLAG_TUBED))
  444. {
  445. strcpy(draw_buf[draw_cnt], "╬");
  446. }
  447. else
  448. {
  449. strcpy(draw_buf[draw_cnt], "┼");
  450. }
  451. }
  452. else if (HAS_BIT(flags, DRAW_FLAG_JEWELED))
  453. {
  454. if (HAS_BIT(flags, DRAW_FLAG_FILLED))
  455. {
  456. strcpy(draw_buf[draw_cnt], "⧫");
  457. }
  458. else
  459. {
  460. strcpy(draw_buf[draw_cnt], "◊");
  461. }
  462. }
  463. else if (HAS_BIT(flags, DRAW_FLAG_TEED))
  464. {
  465. if (HAS_BIT(flags, DRAW_FLAG_HOR))
  466. {
  467. if (HAS_BIT(flags, DRAW_FLAG_LEFT))
  468. {
  469. if (HAS_BIT(flags, DRAW_FLAG_TUBED))
  470. {
  471. strcpy(draw_buf[draw_cnt], "╠");
  472. }
  473. else
  474. {
  475. strcpy(draw_buf[draw_cnt], "├");
  476. }
  477. }
  478. else
  479. {
  480. if (HAS_BIT(flags, DRAW_FLAG_TUBED))
  481. {
  482. strcpy(draw_buf[draw_cnt], "╣");
  483. }
  484. else
  485. {
  486. strcpy(draw_buf[draw_cnt], "┤");
  487. }
  488. }
  489. }
  490. else
  491. {
  492. if (HAS_BIT(flags, DRAW_FLAG_TOP))
  493. {
  494. if (HAS_BIT(flags, DRAW_FLAG_TUBED))
  495. {
  496. strcpy(draw_buf[draw_cnt], "╦");
  497. }
  498. else
  499. {
  500. strcpy(draw_buf[draw_cnt], "┬");
  501. }
  502. }
  503. else
  504. {
  505. if (HAS_BIT(flags, DRAW_FLAG_TUBED))
  506. {
  507. strcpy(draw_buf[draw_cnt], "╩");
  508. }
  509. else
  510. {
  511. strcpy(draw_buf[draw_cnt], "┴");
  512. }
  513. }
  514. }
  515. }
  516. else if (HAS_BIT(flags, DRAW_FLAG_BOXED) || HAS_BIT(flags, DRAW_FLAG_CORNERED))
  517. {
  518. if (HAS_BIT(flags, DRAW_FLAG_LEFT))
  519. {
  520. if (HAS_BIT(flags, DRAW_FLAG_TOP))
  521. {
  522. if (HAS_BIT(flags, DRAW_FLAG_ROUNDED))
  523. {
  524. strcpy(draw_buf[draw_cnt], "╭");
  525. }
  526. else
  527. {
  528. if (HAS_BIT(flags, DRAW_FLAG_TUBED))
  529. {
  530. strcpy(draw_buf[draw_cnt], "╔");
  531. }
  532. else
  533. {
  534. strcpy(draw_buf[draw_cnt], "┌");
  535. }
  536. }
  537. }
  538. else if (HAS_BIT(flags, DRAW_FLAG_BOT))
  539. {
  540. if (HAS_BIT(flags, DRAW_FLAG_ROUNDED))
  541. {
  542. strcpy(draw_buf[draw_cnt], "╰");
  543. }
  544. else
  545. {
  546. if (HAS_BIT(flags, DRAW_FLAG_TUBED))
  547. {
  548. strcpy(draw_buf[draw_cnt], "╚");
  549. }
  550. else
  551. {
  552. strcpy(draw_buf[draw_cnt], "└");
  553. }
  554. }
  555. }
  556. else
  557. {
  558. if (HAS_BIT(flags, DRAW_FLAG_HOR))
  559. {
  560. if (HAS_BIT(flags, DRAW_FLAG_TUBED))
  561. {
  562. strcpy(draw_buf[draw_cnt], "═");
  563. }
  564. else
  565. {
  566. strcpy(draw_buf[draw_cnt], "─");
  567. }
  568. }
  569. else
  570. {
  571. if (HAS_BIT(flags, DRAW_FLAG_TUBED))
  572. {
  573. strcpy(draw_buf[draw_cnt], "║");
  574. }
  575. else
  576. {
  577. strcpy(draw_buf[draw_cnt], "│");
  578. }
  579. }
  580. }
  581. }
  582. else if (HAS_BIT(flags, DRAW_FLAG_RIGHT))
  583. {
  584. if (HAS_BIT(flags, DRAW_FLAG_TOP))
  585. {
  586. if (HAS_BIT(flags, DRAW_FLAG_ROUNDED))
  587. {
  588. strcpy(draw_buf[draw_cnt], "╮");
  589. }
  590. else
  591. {
  592. if (HAS_BIT(flags, DRAW_FLAG_TUBED))
  593. {
  594. strcpy(draw_buf[draw_cnt], "╗");
  595. }
  596. else
  597. {
  598. strcpy(draw_buf[draw_cnt], "┐");
  599. }
  600. }
  601. }
  602. else if (HAS_BIT(flags, DRAW_FLAG_BOT))
  603. {
  604. if (HAS_BIT(flags, DRAW_FLAG_ROUNDED))
  605. {
  606. strcpy(draw_buf[draw_cnt], "╯");
  607. }
  608. else
  609. {
  610. if (HAS_BIT(flags, DRAW_FLAG_TUBED))
  611. {
  612. strcpy(draw_buf[draw_cnt], "╝");
  613. }
  614. else
  615. {
  616. strcpy(draw_buf[draw_cnt], "┘");
  617. }
  618. }
  619. }
  620. else
  621. {
  622. if (HAS_BIT(flags, DRAW_FLAG_HOR))
  623. {
  624. if (HAS_BIT(flags, DRAW_FLAG_TUBED))
  625. {
  626. strcpy(draw_buf[draw_cnt], "═");
  627. }
  628. else
  629. {
  630. strcpy(draw_buf[draw_cnt], "─");
  631. }
  632. }
  633. else
  634. {
  635. if (HAS_BIT(flags, DRAW_FLAG_TUBED))
  636. {
  637. strcpy(draw_buf[draw_cnt], "║");
  638. }
  639. else
  640. {
  641. strcpy(draw_buf[draw_cnt], "│");
  642. }
  643. }
  644. }
  645. }
  646. else
  647. {
  648. if (HAS_BIT(flags, DRAW_FLAG_HOR))
  649. {
  650. if (HAS_BIT(flags, DRAW_FLAG_TUBED))
  651. {
  652. strcpy(draw_buf[draw_cnt], "═");
  653. }
  654. else
  655. {
  656. strcpy(draw_buf[draw_cnt], "─");
  657. }
  658. }
  659. else
  660. {
  661. if (HAS_BIT(flags, DRAW_FLAG_TUBED))
  662. {
  663. strcpy(draw_buf[draw_cnt], "║");
  664. }
  665. else
  666. {
  667. strcpy(draw_buf[draw_cnt], "│");
  668. }
  669. }
  670. }
  671. }
  672. else
  673. {
  674. if (HAS_BIT(flags, DRAW_FLAG_HOR))
  675. {
  676. if (HAS_BIT(flags, DRAW_FLAG_TUBED))
  677. {
  678. strcpy(draw_buf[draw_cnt], "═");
  679. }
  680. else
  681. {
  682. strcpy(draw_buf[draw_cnt], "─");
  683. }
  684. }
  685. else if (HAS_BIT(flags, DRAW_FLAG_VER))
  686. {
  687. if (HAS_BIT(flags, DRAW_FLAG_TUBED))
  688. {
  689. strcpy(draw_buf[draw_cnt], "║");
  690. }
  691. else
  692. {
  693. strcpy(draw_buf[draw_cnt], "│");
  694. }
  695. }
  696. else
  697. {
  698. strcpy(draw_buf[draw_cnt], "?");
  699. }
  700. }
  701. }
  702. else
  703. {
  704. if (HAS_BIT(flags, DRAW_FLAG_PRUNED))
  705. {
  706. strcpy(draw_buf[draw_cnt], "\e[C");
  707. }
  708. else if (HAS_BIT(flags, DRAW_FLAG_CIRCLED) || HAS_BIT(flags, DRAW_FLAG_ROUNDED))
  709. {
  710. strcpy(draw_buf[draw_cnt], "o");
  711. }
  712. else if (HAS_BIT(flags, DRAW_FLAG_CROSSED))
  713. {
  714. strcpy(draw_buf[draw_cnt], "+");
  715. }
  716. else
  717. {
  718. strcpy(draw_buf[draw_cnt], "+");
  719. }
  720. }
  721. return draw_buf[draw_cnt];
  722. }
  723. char *draw_horizontal(int flags, char *str)
  724. {
  725. draw_cnt = (draw_cnt + 1) % 100;
  726. if (HAS_BIT(flags, DRAW_FLAG_BLANKED))
  727. {
  728. strcpy(draw_buf[draw_cnt], " ");
  729. }
  730. else if (HAS_BIT(flags, DRAW_FLAG_NUMBERED))
  731. {
  732. sprintf(draw_buf[draw_cnt], "%d", draw_cnt % 10);
  733. }
  734. else if (HAS_BIT(flags, DRAW_FLAG_UTF8))
  735. {
  736. if (HAS_BIT(flags, DRAW_FLAG_TUBED))
  737. {
  738. strcpy(draw_buf[draw_cnt], "═");
  739. }
  740. else
  741. {
  742. strcpy(draw_buf[draw_cnt], "─");
  743. }
  744. }
  745. else
  746. {
  747. strcpy(draw_buf[draw_cnt], "-");
  748. }
  749. return draw_buf[draw_cnt];
  750. }
  751. char *draw_vertical(int flags, char *str)
  752. {
  753. draw_cnt = (draw_cnt + 1) % 100;
  754. if (HAS_BIT(flags, DRAW_FLAG_BLANKED))
  755. {
  756. strcpy(draw_buf[draw_cnt], " ");
  757. }
  758. else if (HAS_BIT(flags, DRAW_FLAG_NUMBERED))
  759. {
  760. sprintf(draw_buf[draw_cnt], "%d", draw_cnt % 10);
  761. }
  762. else if (HAS_BIT(flags, DRAW_FLAG_UTF8))
  763. {
  764. if (HAS_BIT(flags, DRAW_FLAG_TUBED))
  765. {
  766. strcpy(draw_buf[draw_cnt], "║");
  767. }
  768. else
  769. {
  770. strcpy(draw_buf[draw_cnt], "│");
  771. }
  772. }
  773. else
  774. {
  775. strcpy(draw_buf[draw_cnt], "|");
  776. }
  777. return draw_buf[draw_cnt];
  778. }
  779. // options
  780. DO_DRAW(draw_bot_side)
  781. {
  782. int col, corner;
  783. if (!HAS_BIT(flags, DRAW_FLAG_LEFT) && !HAS_BIT(flags, DRAW_FLAG_RIGHT) && !HAS_BIT(flags, DRAW_FLAG_BOT))
  784. {
  785. return;
  786. }
  787. SET_BIT(flags, HAS_BIT(flags, DRAW_FLAG_VER) ? DRAW_FLAG_VER : DRAW_FLAG_HOR);
  788. corner = flags;
  789. DEL_BIT(corner, DRAW_FLAG_RIGHT|DRAW_FLAG_TOP);
  790. arg = arg1;
  791. if (HAS_BIT(flags, DRAW_FLAG_LEFT) || HAS_BIT(flags, DRAW_FLAG_BOT))
  792. {
  793. SET_BIT(corner, DRAW_FLAG_LEFT|DRAW_FLAG_BOT);
  794. arg1 += sprintf(arg1, "%s%s", color, get_draw_corner(corner, "└"));
  795. }
  796. if (cols - 2 >= 0)
  797. {
  798. if (HAS_BIT(flags, DRAW_FLAG_BOT))
  799. {
  800. for (col = top_col + 1 ; col < bot_col ; col++)
  801. {
  802. arg1 += sprintf(arg1, "%s", draw_horizontal(flags, "─"));
  803. }
  804. }
  805. else if (HAS_BIT(flags, DRAW_FLAG_RIGHT) && cols - 2 > 0)
  806. {
  807. arg1 += sprintf(arg1, "\e[%dC", cols - 2);
  808. }
  809. corner = flags;
  810. DEL_BIT(corner, DRAW_FLAG_LEFT|DRAW_FLAG_TOP);
  811. if (HAS_BIT(flags, DRAW_FLAG_RIGHT) || HAS_BIT(flags, DRAW_FLAG_BOT))
  812. {
  813. arg1 += sprintf(arg1, "%s", get_draw_corner(corner, "┘"));
  814. }
  815. }
  816. if (HAS_BIT(flags, DRAW_FLAG_SCROLL))
  817. {
  818. tintin_printf2(ses, "%s%s", indent_one(top_col - 1), arg);
  819. }
  820. else
  821. {
  822. goto_pos(ses, bot_row, top_col);
  823. print_stdout("%s", arg);
  824. }
  825. }
  826. DO_DRAW(draw_box)
  827. {
  828. if (HAS_BIT(flags, DRAW_FLAG_TOP))
  829. {
  830. draw_top_side(ses, top_row, top_col, bot_row, bot_col, rows, cols, flags, color, arg, arg1, arg2);
  831. }
  832. draw_vertical_lines(ses, top_row, top_col, bot_row, bot_col, rows, cols, flags, color, arg, arg1, arg2);
  833. if (HAS_BIT(flags, DRAW_FLAG_BOT))
  834. {
  835. draw_bot_side(ses, top_row, top_col, bot_row, bot_col, rows, cols, flags, color, arg, arg1, arg2);
  836. }
  837. }
  838. DO_DRAW(draw_corner)
  839. {
  840. if (*arg)
  841. {
  842. strcpy(arg1, arg);
  843. }
  844. else
  845. {
  846. strcpy(arg1, get_draw_corner(flags, " "));
  847. }
  848. if (HAS_BIT(flags, DRAW_FLAG_SCROLL))
  849. {
  850. tintin_printf2(ses, "%s%s%s", indent_one(top_col - 1), color, arg1);
  851. }
  852. else
  853. {
  854. goto_pos(ses, top_row, top_col);
  855. print_stdout("%s%s", color, arg1);
  856. }
  857. }
  858. DO_DRAW(draw_line)
  859. {
  860. SET_BIT(flags, DRAW_FLAG_LINED);
  861. if (top_row == bot_row && !HAS_BIT(flags, DRAW_FLAG_VER))
  862. {
  863. SET_BIT(flags, DRAW_FLAG_LINED|DRAW_FLAG_HOR|DRAW_FLAG_LEFT|DRAW_FLAG_RIGHT);
  864. if (!HAS_BIT(flags, DRAW_FLAG_BOT))
  865. {
  866. SET_BIT(flags, DRAW_FLAG_TOP);
  867. }
  868. }
  869. if (top_col == bot_col && !HAS_BIT(flags, DRAW_FLAG_HOR))
  870. {
  871. SET_BIT(flags, DRAW_FLAG_LINED|DRAW_FLAG_VER|DRAW_FLAG_TOP|DRAW_FLAG_BOT);
  872. if (!HAS_BIT(flags, DRAW_FLAG_RIGHT))
  873. {
  874. SET_BIT(flags, DRAW_FLAG_LEFT);
  875. }
  876. }
  877. /*
  878. if (HAS_BIT(flags, DRAW_FLAG_TOP))
  879. {
  880. draw_top_side(ses, top_row, top_col, bot_row, bot_col, rows, cols, flags, color, arg, arg1, arg2);
  881. }
  882. if (HAS_BIT(flags, DRAW_FLAG_LEFT) || HAS_BIT(flags, DRAW_FLAG_RIGHT))
  883. {
  884. draw_vertical_lines(ses, top_row, top_col, bot_row, bot_col, rows, cols, flags, color, arg, arg1, arg2);
  885. }
  886. if (HAS_BIT(flags, DRAW_FLAG_BOT))
  887. {
  888. draw_bot_side(ses, top_row, top_col, bot_row, bot_col, rows, cols, flags, color, arg, arg1, arg2);
  889. }
  890. */
  891. draw_box(ses, top_row, top_col, bot_row, bot_col, rows, cols, flags, color, arg, arg1, arg2);
  892. }
  893. DO_DRAW(draw_map)
  894. {
  895. arg = get_arg_in_braces(ses, arg, arg1, GET_ONE);
  896. top_row = get_row_index(ses, arg1);
  897. arg = get_arg_in_braces(ses, arg, arg1, GET_ONE);
  898. top_col = get_col_index(ses, arg1);
  899. arg = get_arg_in_braces(ses, arg, arg1, GET_ONE);
  900. bot_row = get_row_index(ses, arg1);
  901. arg = get_arg_in_braces(ses, arg, arg1, GET_ONE);
  902. bot_col = get_col_index(ses, arg1);
  903. rows = URANGE(1, 1 + bot_row - top_row, gtd->screen->rows);
  904. cols = URANGE(1, 1 + bot_col - top_col, gtd->screen->cols);
  905. save_pos(ses);
  906. draw_text(ses, top_row, top_col, bot_row, bot_col, rows, cols, flags, color, arg2, arg1, arg);
  907. restore_pos(ses);
  908. }
  909. char *rain_symbols = "ロヲアウエオカキケコサシスセソタツテナニヌネハヒホマミムメモヤユラリワ01SԐ45789Z=*+-¦|_ʺ╌";
  910. char *braille_symbols = "⠁⠂⠃⠄⠅⠆⠇⠈⠊⠌⠎⠐⠑⠔⠕⠘⠜⠠⠡⠢⠣⠨⠪⠰⠱⠸⡀⡁⡂⡃⡄⡅⡆⡇⡈⡊⡌⡎⡐⡑⡔⡕⡘⡜⡠⡡⡢⡣⡨⡪⡰⡱⡸⢀⢁⢂⢃⢄⢅⢆⢇⢈⢉⢊⢌⢎⢐⢑⢔⢕⢘⢜⢠⢡⢢⢣⢨⢪⢰⢱";
  911. DO_DRAW(draw_rain)
  912. {
  913. char code[BUFFER_SIZE], arg3[BUFFER_SIZE], arg4[BUFFER_SIZE], *rain[400];
  914. struct listnode *node;
  915. int row, col, len, rand, cnt, size, max, utfs[400];
  916. long double density, fade;
  917. strcpy(code, arg2);
  918. arg = get_arg_in_braces(ses, arg, arg1, GET_ONE);
  919. if (!valid_variable(ses, arg1))
  920. {
  921. show_error(ses, LIST_COMMAND, "#SYNTAX: #DRAW {<COLOR>} RAIN %d %d %d %d {<VARIABLE>} {[SPAWN]} {[FADE]} {[LEGEND]}.", top_row, top_col, bot_row, bot_col);
  922. return;
  923. }
  924. node = search_nest_node_ses(ses, arg1);
  925. if (node == NULL || node->root == NULL)
  926. {
  927. node = set_nest_node(ses->list[LIST_VARIABLE], arg1, "{0}{}");
  928. }
  929. arg = get_arg_in_braces(ses, arg, arg1, GET_ONE);
  930. if (*arg1 == 0)
  931. {
  932. density = 1;
  933. }
  934. else
  935. {
  936. density = URANGE(0.01, get_number(ses, arg1), 100);
  937. }
  938. arg = get_arg_in_braces(ses, arg, arg1, GET_ONE);
  939. if (*arg1 == 0)
  940. {
  941. fade = 10;
  942. }
  943. else
  944. {
  945. fade = URANGE(1, get_number(ses, arg1), 100);
  946. }
  947. arg = get_arg_in_braces(ses, arg, arg4, GET_ONE);
  948. if (*arg4 == 0)
  949. {
  950. if (HAS_BIT(ses->flags, SES_FLAG_SCREENREADER))
  951. {
  952. for (max = len = 0 ; braille_symbols[len] ; max++)
  953. {
  954. rain[max] = &braille_symbols[len];
  955. utfs[max] = get_utf8_size(&braille_symbols[len]);
  956. len += utfs[max];
  957. }
  958. }
  959. else
  960. {
  961. for (max = len = 0 ; rain_symbols[len] ; max++)
  962. {
  963. rain[max] = &rain_symbols[len];
  964. utfs[max] = get_utf8_size(&rain_symbols[len]);
  965. len += utfs[max];
  966. }
  967. }
  968. }
  969. else
  970. {
  971. for (max = len = 0 ; arg4[len] && max < 400 ; max++)
  972. {
  973. rain[max] = &arg4[len];
  974. utfs[max] = get_utf8_size(&arg4[len]);
  975. len += utfs[max];
  976. }
  977. }
  978. // tintin_printf2(ses, "debug: [%s] (%s) <%s>", code, fuzzy_color_code(ses, code), dim_color_code(ses, code, 20));
  979. for (col = 0 ; col < 1 + bot_col - top_col ; col++)
  980. {
  981. if (node->root->used <= col)
  982. {
  983. set_nest_node(node->root, ntos(col), "");
  984. }
  985. if (node->root->list[col]->val16[0] == 0)
  986. {
  987. if (generate_rand(ses) % 10000 / (long double) 100 < density)
  988. {
  989. rand = generate_rand(ses) % rows;
  990. node->root->list[col]->val16[0] = 1;
  991. node->root->list[col]->val16[1] = rand;
  992. node->root->list[col]->val16[2] = rand < rows / 2 ? 2 : 0;
  993. node->root->list[col]->val16[3] = 0;
  994. str_cpy_printf(&node->root->list[col]->arg2, "%*s", rand, "");
  995. }
  996. continue;
  997. }
  998. else if (node->root->list[col]->val16[0] == 1)
  999. {
  1000. if (node->root->list[col]->val16[2])
  1001. {
  1002. node->root->list[col]->val16[3]++;
  1003. if (node->root->list[col]->val16[3] % 2)
  1004. {
  1005. goto_pos(ses, top_row + node->root->list[col]->val16[1], top_col + col);
  1006. rand = generate_rand(ses) % max;
  1007. sprintf(arg2, "%s%.*s", lit_color_code(ses, code, 10), utfs[rand], rain[rand]);
  1008. substitute(ses, arg2, arg3, SUB_COL);
  1009. print_stdout("%s", arg3);
  1010. continue;
  1011. }
  1012. }
  1013. rand = generate_rand(ses) % max;
  1014. str_cat_printf(&node->root->list[col]->arg2, "%.*s", utfs[rand], rain[rand]);
  1015. node->root->list[col]->val16[1]++;
  1016. if (generate_rand(ses) % 10000 / (long double) 100 < fade)
  1017. {
  1018. node->root->list[col]->val16[0] = 2;
  1019. }
  1020. else if (node->root->list[col]->val16[1] > rows - generate_rand(ses) % 8)
  1021. {
  1022. node->root->list[col]->val16[0] = 2;
  1023. }
  1024. }
  1025. else
  1026. {
  1027. node->root->list[col]->val16[0]++;
  1028. }
  1029. len = str_len(node->root->list[col]->arg2);
  1030. row = 0;
  1031. cnt = 0;
  1032. if (node->root->list[col]->val16[0] == 1)
  1033. {
  1034. while (row < len)
  1035. {
  1036. if (node->root->list[col]->arg2[row] == ' ')
  1037. {
  1038. cnt++;
  1039. row++;
  1040. continue;
  1041. }
  1042. goto_pos(ses, top_row + cnt, top_col + col);
  1043. cnt++;
  1044. size = get_utf8_size(&node->root->list[col]->arg2[row]);
  1045. if (cnt == node->root->list[col]->val16[1])
  1046. {
  1047. sprintf(arg2, "%s%.*s", lit_color_code(ses, code, 5), size, &node->root->list[col]->arg2[row]);
  1048. }
  1049. else
  1050. {
  1051. if (node->root->list[col]->val16[1] % 2 == 0)
  1052. {
  1053. row += size;
  1054. continue;
  1055. }
  1056. sprintf(arg2, "%s%.*s", fuzzy_color_code(ses, code), size, &node->root->list[col]->arg2[row]);
  1057. }
  1058. substitute(ses, arg2, arg3, SUB_COL);
  1059. print_stdout("%s", arg3);
  1060. row += size;
  1061. }
  1062. }
  1063. else if (node->root->list[col]->val16[0] > 1)
  1064. {
  1065. while (row < len)
  1066. {
  1067. if (node->root->list[col]->arg2[row] == ' ')
  1068. {
  1069. cnt++;
  1070. row++;
  1071. continue;
  1072. }
  1073. goto_pos(ses, top_row + cnt, top_col + col);
  1074. cnt++;
  1075. size = get_utf8_size(&node->root->list[col]->arg2[row]);
  1076. if (node->root->list[col]->val16[0] - cnt > 15)
  1077. {
  1078. sprintf(arg2, "%s ", dim_color_code(ses, code, node->root->list[col]->val16[0] - cnt));
  1079. substitute(ses, arg2, arg3, SUB_COL);
  1080. print_stdout("%s", arg3);
  1081. }
  1082. else if (node->root->list[col]->val16[0] - cnt < 0)
  1083. {
  1084. sprintf(arg2, "%s%.*s", fuzzy_color_code(ses, code), size, &node->root->list[col]->arg2[row]);
  1085. substitute(ses, arg2, arg3, SUB_COL);
  1086. print_stdout("%s", arg3);
  1087. }
  1088. else
  1089. {
  1090. sprintf(arg2, "%s%.*s", dim_color_code(ses, code, node->root->list[col]->val16[0] - cnt), size, &node->root->list[col]->arg2[row]);
  1091. substitute(ses, arg2, arg3, SUB_COL);
  1092. print_stdout("%s", arg3);
  1093. }
  1094. row += size;
  1095. }
  1096. if (node->root->list[col]->val16[0] - cnt > 20)
  1097. {
  1098. node->root->list[col]->val16[0] = 0;
  1099. node->root->list[col]->val16[1] = 0;
  1100. str_cpy(&node->root->list[col]->arg2, "");
  1101. }
  1102. }
  1103. else
  1104. {
  1105. tintin_printf2(ses, "debug: problemo");
  1106. }
  1107. }
  1108. }
  1109. DO_DRAW(draw_side)
  1110. {
  1111. push_call("draw_side()");
  1112. draw_box(ses, top_row, top_col, bot_row, bot_col, rows, cols, flags, color, arg, arg1, arg2);
  1113. pop_call();
  1114. return;
  1115. }
  1116. DO_DRAW(draw_square)
  1117. {
  1118. draw_text(ses, top_row, top_col, bot_row, bot_col, rows, cols, flags, color, arg, arg1, arg2);
  1119. }
  1120. DO_DRAW(draw_stamp)
  1121. {
  1122. draw_text(ses, top_row, top_col, bot_row, bot_col, rows, cols, flags, color, arg, arg1, arg2);
  1123. }
  1124. DO_DRAW(draw_table_grid)
  1125. {
  1126. char buf1[BUFFER_SIZE], *str, buf2[BUFFER_SIZE], buf3[BUFFER_SIZE], row_color[COLOR_SIZE];
  1127. int corner, row, col, max_r, max_c, r, c, top_r, top_c, bot_r, bot_c, tot_r, tot_c;
  1128. row = cnt_arg_all(ses, arg, GET_ONE);
  1129. get_arg_in_braces(ses, arg, buf1, GET_ONE);
  1130. col = cnt_arg_all(ses, buf1, GET_ONE);
  1131. if (row == 0 || col == 0)
  1132. {
  1133. tintin_printf2(ses, "#ERROR: #DRAW TABLE: NEED AT LEAST 1 ROW AND 1 COLUMN.");
  1134. return;
  1135. }
  1136. row_color[0] = 0;
  1137. corner = flags;
  1138. DEL_BIT(corner, DRAW_FLAG_LEFT | DRAW_FLAG_RIGHT | DRAW_FLAG_TOP | DRAW_FLAG_BOT);
  1139. if (HAS_BIT(flags, DRAW_FLAG_GRID))
  1140. {
  1141. max_r = (rows - 1) / row;
  1142. max_c = (cols - 1) / col;
  1143. tot_r = 1 + max_r * row;
  1144. tot_c = 1 + max_c * col;
  1145. for (r = 0 ; r < tot_r ; r++)
  1146. {
  1147. buf3[0] = 0;
  1148. if (r % max_r == 0)
  1149. {
  1150. arg = get_arg_in_braces(ses, arg, buf1, GET_ONE);
  1151. str = buf1;
  1152. if (*arg == COMMAND_SEPARATOR)
  1153. {
  1154. arg++;
  1155. }
  1156. }
  1157. for (c = 0 ; c < tot_c ; c++)
  1158. {
  1159. if (r == 0)
  1160. {
  1161. if (c == 0)
  1162. {
  1163. strcat(buf3, get_draw_corner(corner | DRAW_FLAG_LEFT | DRAW_FLAG_TOP, "┌"));
  1164. }
  1165. else if (c == tot_c - 1)
  1166. {
  1167. strcat(buf3, get_draw_corner(corner | DRAW_FLAG_RIGHT | DRAW_FLAG_TOP, "┐"));
  1168. }
  1169. else if (c % max_c == 0)
  1170. {
  1171. strcat(buf3, get_draw_corner(corner | DRAW_FLAG_TEED | DRAW_FLAG_TOP, "┬"));
  1172. }
  1173. else
  1174. {
  1175. strcat(buf3, draw_horizontal(flags, "?"));
  1176. }
  1177. }
  1178. else if (r == tot_r - 1)
  1179. {
  1180. if (c == 0)
  1181. {
  1182. strcat(buf3, get_draw_corner(corner | DRAW_FLAG_LEFT | DRAW_FLAG_BOT, "?"));
  1183. }
  1184. else if (c == tot_c - 1)
  1185. {
  1186. strcat(buf3, get_draw_corner(corner | DRAW_FLAG_RIGHT | DRAW_FLAG_BOT, "?"));
  1187. }
  1188. else if (c % max_c == 0)
  1189. {
  1190. strcat(buf3, get_draw_corner(corner | DRAW_FLAG_TEED | DRAW_FLAG_BOT, "┬"));
  1191. }
  1192. else
  1193. {
  1194. strcat(buf3, draw_horizontal(flags, "?"));
  1195. }
  1196. }
  1197. else if (r % max_r == 0)
  1198. {
  1199. if (c == 0)
  1200. {
  1201. strcat(buf3, get_draw_corner(corner | DRAW_FLAG_TEED | DRAW_FLAG_HOR | DRAW_FLAG_LEFT, "?"));
  1202. }
  1203. else if (c == tot_c - 1)
  1204. {
  1205. strcat(buf3, get_draw_corner(corner | DRAW_FLAG_TEED | DRAW_FLAG_HOR | DRAW_FLAG_RIGHT, "?"));
  1206. }
  1207. else if (c % max_c == 0)
  1208. {
  1209. strcat(buf3, get_draw_corner(corner | DRAW_FLAG_CROSSED, "?"));
  1210. }
  1211. else
  1212. {
  1213. strcat(buf3, draw_horizontal(flags, "?"));
  1214. }
  1215. }
  1216. else if (r % max_r == 1)
  1217. {
  1218. if (c == tot_c - 1)
  1219. {
  1220. if (HAS_BIT(flags, DRAW_FLAG_SCROLL))
  1221. {
  1222. cat_sprintf(buf3, "%s", draw_vertical(flags, "│"));
  1223. }
  1224. else
  1225. {
  1226. goto_pos(ses, top_row + r, top_col + c);
  1227. print_stdout("%s%s", color, draw_vertical(flags, "│"));
  1228. }
  1229. }
  1230. else if (c == 0 || c % max_c == 0)
  1231. {
  1232. strcpy(buf2, row_color);
  1233. str = sub_arg_in_braces(ses, str, buf2 + strlen(buf2), GET_ONE, SUB_VAR|SUB_FUN|SUB_ESC|SUB_COL);
  1234. get_color_codes(row_color, buf2, row_color, GET_ALL);
  1235. top_r = top_row + r - 1;
  1236. top_c = top_col + c;
  1237. bot_r = top_row + r - 1 + max_r;
  1238. bot_c = top_col + c + max_c;
  1239. draw_vertical_lines(ses, top_r, top_c, top_r, bot_c, 1 + max_r, 1 + max_c, corner | DRAW_FLAG_LEFT, color, buf2, arg1, arg2);
  1240. if (HAS_BIT(flags, DRAW_FLAG_SCROLL))
  1241. {
  1242. strcat(buf3, arg2);
  1243. }
  1244. if (*str == COMMAND_SEPARATOR)
  1245. {
  1246. str++;
  1247. }
  1248. }
  1249. }
  1250. else
  1251. {
  1252. if (c == tot_c - 1)
  1253. {
  1254. if (HAS_BIT(flags, DRAW_FLAG_SCROLL))
  1255. {
  1256. cat_sprintf(buf3, "%s", draw_vertical(flags, "│"));
  1257. }
  1258. else
  1259. {
  1260. goto_pos(ses, top_row + r, top_col + c);
  1261. print_stdout("%s%s", color, draw_vertical(flags, "│"));
  1262. }
  1263. }
  1264. }
  1265. }
  1266. if (*buf3)
  1267. {
  1268. if (HAS_BIT(flags, DRAW_FLAG_SCROLL))
  1269. {
  1270. tintin_printf2(ses, "%s%s%s", indent_one(top_col - 1), color, buf3);
  1271. }
  1272. else
  1273. {
  1274. goto_pos(ses, top_row + r, top_col);
  1275. print_stdout("%s%s", color, buf3);
  1276. }
  1277. }
  1278. }
  1279. return;
  1280. }
  1281. max_r = rows / row;
  1282. max_c = cols / col;
  1283. for (r = 0 ; r < row ; r++)
  1284. {
  1285. arg = get_arg_in_braces(ses, arg, buf1, GET_ONE);
  1286. str = buf1;
  1287. for (c = 0 ; c < col ; c++)
  1288. {
  1289. str = get_arg_in_braces(ses, str, buf2, GET_ONE);
  1290. top_r = top_row + r * max_r;
  1291. top_c = top_col + c * max_c;
  1292. bot_r = top_row + r * max_r + max_r - 1;
  1293. bot_c = top_col + c * max_c + max_c - 1;
  1294. draw_box(ses, top_r, top_c, bot_r, bot_c, 1 + bot_r - top_r, 1 + bot_c - top_c, flags, color, buf2, arg1, arg2);
  1295. // tintin_printf2(ses, "#draw box %d %d %d %d %s", top_row + r * max_r, top_col + c * max_c, top_row + r * max_r + max_r, top_col + c * max_c + max_c, buf1);
  1296. if (*str == COMMAND_SEPARATOR)
  1297. {
  1298. str++;
  1299. }
  1300. }
  1301. if (*arg == COMMAND_SEPARATOR)
  1302. {
  1303. arg++;
  1304. }
  1305. }
  1306. }
  1307. DO_DRAW(draw_text)
  1308. {
  1309. char *txt, buf1[BUFFER_SIZE], buf2[BUFFER_SIZE], buf3[BUFFER_SIZE], side1[100], side2[100];
  1310. int row, col, height, width;
  1311. push_call("draw_text(%p,%d,%p,%p,%p)",ses,flags,arg,arg1,arg2);
  1312. buf1[0] = buf2[0] = side1[0] = side2[0] = arg2[0] = 0;
  1313. txt = buf2;
  1314. substitute(ses, arg, buf3, SUB_VAR|SUB_FUN);
  1315. arg = buf3;
  1316. if (HAS_BIT(flags, DRAW_FLAG_HUGE))
  1317. {
  1318. string_to_stamp(ses, flags, arg, txt);
  1319. }
  1320. else
  1321. {
  1322. while (*arg)
  1323. {
  1324. arg = sub_arg_in_braces(ses, arg, buf1, GET_ALL, SUB_COL|SUB_ESC|SUB_VAR|SUB_FUN);
  1325. txt += sprintf(txt, "%s\n", buf1);
  1326. if (*arg == COMMAND_SEPARATOR)
  1327. {
  1328. arg++;
  1329. }
  1330. }
  1331. }
  1332. if (HAS_BIT(flags, DRAW_FLAG_BOXED) /*|| HAS_BIT(flags, DRAW_FLAG_LINED)*/ || HAS_BIT(flags, DRAW_FLAG_TOP) || HAS_BIT(flags, DRAW_FLAG_PRUNED))
  1333. {
  1334. top_row++;
  1335. rows--;
  1336. }
  1337. if (HAS_BIT(flags, DRAW_FLAG_BOXED) /*|| HAS_BIT(flags, DRAW_FLAG_LINED)*/ || HAS_BIT(flags, DRAW_FLAG_BOT) || HAS_BIT(flags, DRAW_FLAG_PRUNED))
  1338. {
  1339. bot_row--;
  1340. rows--;
  1341. }
  1342. if (HAS_BIT(flags, DRAW_FLAG_BOXED) || HAS_BIT(flags, DRAW_FLAG_LEFT) || HAS_BIT(flags, DRAW_FLAG_PRUNED))
  1343. {
  1344. strcpy(side1, " ");
  1345. cols--;
  1346. }
  1347. if (HAS_BIT(flags, DRAW_FLAG_BOXED) || HAS_BIT(flags, DRAW_FLAG_RIGHT) || HAS_BIT(flags, DRAW_FLAG_PRUNED))
  1348. {
  1349. if (!HAS_BIT(flags, DRAW_FLAG_GRID) || HAS_BIT(flags, DRAW_FLAG_RIGHT))
  1350. {
  1351. strcpy(side2, " ");
  1352. }
  1353. cols--;
  1354. }
  1355. word_wrap_split(ses, buf2, buf1, cols, 0, 0, FLAG_NONE, &height, &width);
  1356. height--;
  1357. txt = buf1;
  1358. while (*txt && height > rows)
  1359. {
  1360. txt = strchr(txt, '\n');
  1361. txt++;
  1362. height--;
  1363. }
  1364. arg = txt;
  1365. row = top_row;
  1366. col = top_col;
  1367. while (*arg)
  1368. {
  1369. arg = strchr(arg, '\n');
  1370. *arg++ = 0;
  1371. justify_string(ses, txt, buf2, 0 - cols, cols);
  1372. if (HAS_BIT(flags, DRAW_FLAG_LEFT))
  1373. {
  1374. strcpy(side1, draw_vertical(flags, "│"));
  1375. }
  1376. if (HAS_BIT(flags, DRAW_FLAG_RIGHT))
  1377. {
  1378. strcpy(side2, draw_vertical(flags, "│"));
  1379. }
  1380. if (HAS_BIT(flags, DRAW_FLAG_CONVERT))
  1381. {
  1382. convert_meta(buf2, buf3, FALSE);
  1383. strcpy(buf2, buf3);
  1384. }
  1385. if (HAS_BIT(flags, DRAW_FLAG_SCROLL))
  1386. {
  1387. if (HAS_BIT(flags, DRAW_FLAG_GRID))
  1388. {
  1389. cat_sprintf(arg2, "%s%s%s%s%s", color, side1, buf2, color, side2);
  1390. }
  1391. else
  1392. {
  1393. tintin_printf2(ses, "%s%s%s%s%s%s", indent_one(top_col - 1), color, side1, buf2, color, side2);
  1394. }
  1395. }
  1396. else
  1397. {
  1398. goto_pos(ses, row++, col);
  1399. print_stdout("%s%s%s%s%s", color, side1, buf2, color, side2);
  1400. }
  1401. txt = arg;
  1402. }
  1403. while (height < rows)
  1404. {
  1405. if (HAS_BIT(flags, DRAW_FLAG_LEFT))
  1406. {
  1407. strcpy(side1, draw_vertical(flags, "│"));
  1408. }
  1409. if (HAS_BIT(flags, DRAW_FLAG_RIGHT))
  1410. {
  1411. strcpy(side2, draw_vertical(flags, "│"));
  1412. }
  1413. if (HAS_BIT(flags, DRAW_FLAG_SCROLL))
  1414. {
  1415. if (HAS_BIT(flags, DRAW_FLAG_GRID))
  1416. {
  1417. cat_sprintf(arg2, "%s%s%*s%s%s", color, side1, cols, "", color, side2);
  1418. }
  1419. else
  1420. {
  1421. tintin_printf2(ses, "%s%s%s%-*s%s%s", indent_one(top_col - 1), color, side1, cols, "", color, side2);
  1422. }
  1423. }
  1424. else
  1425. {
  1426. goto_pos(ses, row++, col);
  1427. print_stdout("%s%s%*s%s%s", color, side1, cols, "", color, side2);
  1428. }
  1429. height++;
  1430. }
  1431. pop_call();
  1432. return;
  1433. }
  1434. DO_DRAW(draw_top_side)
  1435. {
  1436. int col, corner;
  1437. SET_BIT(flags, HAS_BIT(flags, DRAW_FLAG_VER) ? DRAW_FLAG_VER : DRAW_FLAG_HOR);
  1438. corner = flags;
  1439. DEL_BIT(corner, DRAW_FLAG_RIGHT|DRAW_FLAG_BOT);
  1440. arg = arg1;
  1441. if (HAS_BIT(flags, DRAW_FLAG_LEFT) || HAS_BIT(flags, DRAW_FLAG_TOP))
  1442. {
  1443. SET_BIT(corner, DRAW_FLAG_LEFT|DRAW_FLAG_RIGHT);
  1444. arg1 += sprintf(arg1, "%s%s", color, get_draw_corner(corner, "┌"));
  1445. }
  1446. if (cols - 2 >= 0)
  1447. {
  1448. if (HAS_BIT(flags, DRAW_FLAG_TOP))
  1449. {
  1450. for (col = top_col + 1 ; col < bot_col ; col++)
  1451. {
  1452. arg1 += sprintf(arg1, "%s", draw_horizontal(flags, "─"));
  1453. }
  1454. }
  1455. else if (HAS_BIT(flags, DRAW_FLAG_RIGHT) && cols - 2 > 0)
  1456. {
  1457. arg1 += sprintf(arg1, "\e[%dC", cols - 2);
  1458. }
  1459. corner = flags;
  1460. DEL_BIT(corner, DRAW_FLAG_LEFT|DRAW_FLAG_BOT);
  1461. if (HAS_BIT(flags, DRAW_FLAG_TOP) || HAS_BIT(flags, DRAW_FLAG_RIGHT))
  1462. {
  1463. SET_BIT(corner, DRAW_FLAG_RIGHT|DRAW_FLAG_TOP);
  1464. arg1 += sprintf(arg1, "%s", get_draw_corner(corner, "┐"));
  1465. }
  1466. }
  1467. if (HAS_BIT(flags, DRAW_FLAG_SCROLL))
  1468. {
  1469. tintin_printf2(ses, "%*s%s", top_col - 1, "", arg);
  1470. }
  1471. else
  1472. {
  1473. goto_pos(ses, top_row, top_col);
  1474. print_stdout("%s", arg);
  1475. }
  1476. }
  1477. DO_DRAW(draw_vertical_lines)
  1478. {
  1479. int row, col, lines;
  1480. push_call("draw_vertical_lines(%p,%d,%p,%p,%p)",ses,flags,arg,arg1,arg2);
  1481. if (HAS_BIT(flags, DRAW_FLAG_SCROLL) || *arg)
  1482. {
  1483. draw_text(ses, top_row, top_col, bot_row, top_col, rows, cols, flags, color, arg, arg1, arg2);
  1484. pop_call();
  1485. return;
  1486. }
  1487. arg1[0] = arg2[0] = 0;
  1488. if (HAS_BIT(flags, DRAW_FLAG_BOXED) || HAS_BIT(flags, DRAW_FLAG_TOP))
  1489. {
  1490. top_row++;
  1491. rows--;
  1492. }
  1493. if (HAS_BIT(flags, DRAW_FLAG_BOXED) || HAS_BIT(flags, DRAW_FLAG_BOT))
  1494. {
  1495. bot_row--;
  1496. rows--;
  1497. }
  1498. if (HAS_BIT(flags, DRAW_FLAG_LEFT))
  1499. {
  1500. if (HAS_BIT(flags, DRAW_FLAG_PRUNED))
  1501. {
  1502. strcpy(arg1, " ");
  1503. }
  1504. else
  1505. {
  1506. strcpy(arg1, draw_vertical(flags, "│"));
  1507. }
  1508. cols--;
  1509. }
  1510. if (HAS_BIT(flags, DRAW_FLAG_RIGHT))
  1511. {
  1512. if (HAS_BIT(flags, DRAW_FLAG_PRUNED))
  1513. {
  1514. strcpy(arg1, " ");
  1515. }
  1516. else
  1517. {
  1518. strcpy(arg2, draw_vertical(flags, "│"));
  1519. }
  1520. cols--;
  1521. }
  1522. // tintin_printf2(ses, "debug: rows = %d", rows);
  1523. lines = 0;
  1524. row = top_row;
  1525. col = top_col;
  1526. while (lines < rows)
  1527. {
  1528. goto_pos(ses, row, col);
  1529. print_stdout("%s%s\e[%dG%s%s", color, arg1, col + cols + strip_vt102_strlen(ses, arg1), color, arg2);
  1530. row++;
  1531. lines++;
  1532. }
  1533. pop_call();
  1534. return;
  1535. }