PageRenderTime 82ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/source/dlg_box.cpp

https://bitbucket.org/gcubar/asc
C++ | 4147 lines | 3250 code | 774 blank | 123 comment | 1020 complexity | c96722b9ba1f8e4e8207503a82359f9c MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0
  1. /*! \file dlg_box.cpp
  2. \brief Some basic classes from which all of ASC's dialogs are derived
  3. */
  4. /*
  5. This file is part of Advanced Strategic Command; http://www.asc-hq.de
  6. Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  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. You should have received a copy of the GNU General Public License
  16. along with this program; see the file COPYING. If not, write to the
  17. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  18. Boston, MA 02111-1307 USA
  19. */
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <stdarg.h>
  23. #include <ctype.h>
  24. #include <cstring>
  25. #include <iostream>
  26. #include "typen.h"
  27. #include "basegfx.h"
  28. #include "newfont.h"
  29. #include "spfst.h"
  30. #include "loaders.h"
  31. #include "misc.h"
  32. #include "events.h"
  33. #include "stack.h"
  34. #include "dlg_box.h"
  35. #include "paradialog.h"
  36. #include "widgets/textrenderer.h"
  37. #include "spfst-legacy.h"
  38. #ifdef _WIN32_
  39. #include <windows.h>
  40. #include <winuser.h>
  41. #endif
  42. char strrstring[200];
  43. void strrd8d(int l, char* s)
  44. {
  45. itoa ( l / minmalq, s, 10);
  46. }
  47. void strrd8u(int l, char* s)
  48. {
  49. itoa ( (l + minmalq - 1) / minmalq, s, 10);
  50. }
  51. void strrd8n(int l, char* s)
  52. {
  53. itoa ( (l + minmalq/2) / minmalq, s, 10);
  54. }
  55. char* strrrd8d(int l)
  56. {
  57. itoa ( l / minmalq, strrstring, 10);
  58. return strrstring;
  59. }
  60. char* strrrd8u(int l)
  61. {
  62. itoa ( (l + minmalq - 1) / minmalq, strrstring, 10);
  63. return strrstring;
  64. }
  65. char* strrrd8n(int l)
  66. {
  67. itoa ( (l + minmalq/2) / minmalq, strrstring, 10);
  68. return strrstring;
  69. }
  70. void *dialogtexture = NULL;
  71. int actdisplayedmessage = 0;
  72. long int lastdisplayedmessageticker = 0xffffff;
  73. tvirtualscreenbuf virtualscreenbuf;
  74. tvirtualscreenbuf :: tvirtualscreenbuf ( void )
  75. {
  76. buf = NULL;
  77. size = 0;
  78. }
  79. void tvirtualscreenbuf:: init ( void )
  80. {
  81. size = hgmp->bytesperscanline * hgmp->resolutiony;
  82. buf = malloc( size );
  83. }
  84. tvirtualscreenbuf:: ~tvirtualscreenbuf ()
  85. {
  86. free( buf );
  87. buf = NULL;
  88. }
  89. char getletter( const char * s)
  90. {
  91. const char* c = s;
  92. while ( *c && (*c != 126 ))
  93. c++;
  94. if (*c == '~' ) {
  95. c++;
  96. return *c;
  97. } else {
  98. return 0;
  99. } /* endif */
  100. }
  101. collategraphicoperations* tdialogbox::pcgo = NULL;
  102. tdialogbox::tdialogbox()
  103. {
  104. eventQueue = setEventRouting ( false, true );
  105. npush ( activefontsettings );
  106. activefontsettings.font = schriften.smallarial;
  107. activefontsettings.color = black;
  108. activefontsettings.background = 255;
  109. activefontsettings.markcolor = red;
  110. virtualbufoffset = 0;
  111. boxstatus = 0;
  112. dlg_mode = 0;
  113. int rdw = 0;
  114. if ( first ) {
  115. pdialogbox rn = first;
  116. rdw &= rn->getcapabilities() & 1;
  117. while ( rn->next ) {
  118. rn = rn->next;
  119. rdw &= rn->getcapabilities() & 1;
  120. }
  121. prev = rn;
  122. rn->next = this;
  123. } else {
  124. first = this;
  125. prev = NULL;
  126. }
  127. next = NULL;
  128. if ( rdw )
  129. dlg_mode |= 2;
  130. }
  131. int tdialogbox::getcapabilities ( void )
  132. {
  133. return 0;
  134. }
  135. extern void repaintdisplay ( void );
  136. void tdialogbox::repaintdisplay( void )
  137. {/*
  138. int ms = getmousestatus();
  139. if ( ms == 2 )
  140. mousevisible ( false );
  141. npush ( *agmp );
  142. npush ( *hgmp );
  143. hgmp->linearaddress = (PointerSizedInt) virtualscreenbuf.buf;
  144. hgmp->windowstatus = 100;
  145. *agmp = *hgmp;
  146. ::repaintdisplay();
  147. npop ( *hgmp );
  148. setvirtualframebuf();
  149. if ( first )
  150. first->setclipping();
  151. *agmp = *hgmp;
  152. putspritetexture ( 0, 0, hgmp->resolutionx-1, hgmp->resolutiony-1, virtualscreenbuf.buf );
  153. npop ( *agmp );
  154. if ( ms == 2 )
  155. mousevisible ( true );
  156. */
  157. }
  158. void tdialogbox::redrawall ( void )
  159. {
  160. paint();
  161. if ( prev )
  162. prev->redrawall();
  163. else
  164. repaintDisplay();
  165. }
  166. void tdialogbox::redrawall2 ( int xx1, int yy1, int xx2, int yy2 )
  167. {
  168. paint ();
  169. if ( x1 > xx1 || y1 > yy1 || x1+xsize < xx2 || y1+ysize < yy2 ) {
  170. if ( prev )
  171. prev->redrawall2 ( xx1, yy1, xx2, yy2 );
  172. else
  173. repaintDisplay();
  174. }
  175. }
  176. pdialogbox tdialogbox::first = NULL;
  177. void tdialogbox::setvirtualframebuf ( void )
  178. {
  179. agmp->linearaddress = (PointerSizedInt) virtualscreenbuf.buf;
  180. agmp->windowstatus = 100;
  181. agmp->scanlinelength = hgmp->scanlinelength;
  182. }
  183. void tdialogbox::setclipping ( void )
  184. {
  185. bar ( x1, y1, x1 + xsize, y1 + ysize, 255 );
  186. if ( next )
  187. next->setclipping ( );
  188. }
  189. void tdialogbox::copyvirtualframebuf ( void )
  190. {
  191. ms = getmousestatus();
  192. if (ms == 2)
  193. mousevisible(false);
  194. npush ( *agmp );
  195. void* buf = (void*) agmp->linearaddress;
  196. *agmp = *hgmp;
  197. putspritetexture ( x1, y1, x1 + xsize, y1 + ysize, buf );
  198. /*
  199. for ( int y = y1; y <= y1 + ysize; y++ )
  200. for ( int x = x1; x <= x1 + xsize; x++ ) {
  201. char c = buf[ virtualbufoffset + y * agmp->scanlinelength + x ];
  202. char d = buf[ virtualbufoffset + y * agmp->scanlinelength + x+1 ];
  203. if ( d != 255 )
  204. putpixel ( x+1, y, lightblue );
  205. if ( c != 255 )
  206. putpixel ( x, y, c );
  207. }
  208. */
  209. npop ( *agmp );
  210. if (ms == 2)
  211. mousevisible(true);
  212. }
  213. void tdialogbox::paint ( void )
  214. {
  215. setvirtualframebuf();
  216. redraw();
  217. if ( next )
  218. next->setclipping();
  219. copyvirtualframebuf();
  220. *agmp = *hgmp;
  221. }
  222. int getplayercolor ( int i )
  223. {
  224. if ( actmap ) {
  225. int textcolor = i * 8 + 21;
  226. if ( i == 7 || i == 2 )
  227. textcolor += 1;
  228. return textcolor;
  229. } else
  230. return 20;
  231. }
  232. void tdialogbox::init(void)
  233. {
  234. imagesaved = false;
  235. if ( actmap && actmap->actplayer != -1 ) {
  236. textcolor = getplayercolor ( actmap->actplayer );
  237. }
  238. else
  239. textcolor = 20;
  240. firstbutton = NULL;
  241. windowstyle = dlg_in3d | dlg_3dtitle;
  242. x1 = 50;
  243. xsize = 540;
  244. y1 = 50;
  245. ysize = 380;
  246. starty = 40;
  247. title = "dialogbox";
  248. npush( activefontsettings );
  249. activefontsettings.height = 0;
  250. activefontsettings.length = 0;
  251. memset(taborder, 0, sizeof(taborder));
  252. tabcount = 0;
  253. markedtab = 0;
  254. disablecolor = darkgray;
  255. boxstatus = 1;
  256. dlg_mode = 0; // |= getcapabilities();
  257. }
  258. #include "dlgraph.cpp"
  259. void tdialogbox::changecoordinates(void)
  260. {
  261. /* runerror(211); */
  262. }
  263. tdlgengine::pbutton tdlgengine :: getbutton ( int id )
  264. {
  265. pbutton pb = firstbutton;
  266. while ( pb && (pb->id != id))
  267. pb = pb->next;
  268. return pb;
  269. }
  270. void tdlgengine::buttonpressed(int id)
  271. {
  272. pbutton pb;
  273. int w;
  274. Uint16 *pw, *pw2;
  275. pb = firstbutton;
  276. while ( pb ) {
  277. if ((pb->art == 5)) { /* Scrollbar */
  278. pw = (Uint16*) pb->data;
  279. pw2 = (Uint16*) pb->data2;
  280. w = *pw;
  281. if ((pb->id + 1 == id)) {
  282. if (taste == ct_pup) {
  283. if (*pw >= pb->max)
  284. *pw -= pb->max - 1;
  285. else
  286. *pw = 0;
  287. }
  288. else
  289. if (taste == ct_pos1) {
  290. *pw = 0;
  291. }
  292. else
  293. if (*pw > 0) {
  294. if ( pb->newpressed == 0 ) // Tastatur
  295. (*pw) --;
  296. else
  297. if ( pb->newpressed == 1) {
  298. (*pw) --;
  299. pb->lasttick = ticker;
  300. } else
  301. if ( pb->newpressed == 2) {
  302. int dst = ticker - pb->lasttick;
  303. if ( *pw < dst )
  304. (*pw) = 0;
  305. else
  306. (*pw) -= dst;
  307. pb->lasttick = ticker;
  308. }
  309. }
  310. }
  311. if ((pb->id + 2 == id)) {
  312. if (taste == ct_pdown) {
  313. if (*pw + (pb->max * 2) - 1 <= *pw2)
  314. *pw += pb->max - 1;
  315. else
  316. *pw = *pw2 - pb->max;
  317. }
  318. else
  319. if (taste == ct_ende) {
  320. *pw = *pw2 - pb->max;
  321. }
  322. else
  323. if ( *pw + pb->max < *pw2 ) {
  324. if ( pb->newpressed == 0 ) // Tastatur
  325. (*pw)++;
  326. else
  327. if ( pb->newpressed == 1) {
  328. (*pw) ++;
  329. pb->lasttick = ticker;
  330. } else
  331. if ( pb->newpressed == 2) {
  332. int dst = ticker - pb->lasttick;
  333. if ( *pw + dst + pb->max >= *pw2 )
  334. *pw = *pw2 - pb->max;
  335. else
  336. (*pw) += dst;
  337. pb->lasttick = ticker;
  338. }
  339. }
  340. }
  341. if (w != *pw) {
  342. char mss = getmousestatus();
  343. if (mss == 2 )
  344. mousevisible(false);
  345. showbutton(pb->id);
  346. buttonpressed(pb->id);
  347. if (mss == 2 )
  348. mousevisible(true);
  349. }
  350. }
  351. pb = pb->next;
  352. }
  353. }
  354. void tdlgengine::addbutton( const char * ltxt,
  355. tmouserect rect1,
  356. int lart,
  357. int lstyle,
  358. int lid,
  359. char enabled)
  360. {
  361. addbutton ( ltxt, rect1.x1, rect1.y1, rect1.x2, rect1.y2, lart, lstyle, lid, enabled );
  362. }
  363. const char* emptystring = "";
  364. void tdlgengine::addbutton( const char * ltxt,
  365. int lx1,
  366. int ly1,
  367. int lx2,
  368. int ly2,
  369. int lart,
  370. int lstyle,
  371. int lid,
  372. char enabled)
  373. {
  374. pbutton pb;
  375. char ch;
  376. pb = firstbutton;
  377. if (lid <= 0)
  378. displaymessage("tdialogbox: \n id equal or less then 0\n:%d\n",2, lid);
  379. while ( pb ) {
  380. if (pb->id == lid)
  381. displaymessage("tdialogbox: duplicate button id: %d\n",2, lid);
  382. pb = pb->next;
  383. }
  384. pb = new tbutton;
  385. pb->x1 = lx1;
  386. pb->x2 = lx2;
  387. pb->y1 = ly1;
  388. pb->y2 = ly2;
  389. pb->style = lstyle;
  390. pb->id = lid;
  391. pb->next = firstbutton;
  392. if ( ltxt )
  393. pb->text = ltxt;
  394. else
  395. pb->text = emptystring;
  396. pb->art = lart;
  397. pb->active = enabled;
  398. pb->status = 1;
  399. pb->scrollspeed = 30;
  400. pb->pressed = 0;
  401. pb->newpressed = 0;
  402. firstbutton = pb;
  403. ch = getletter(pb->text);
  404. if (ch != 0) {
  405. pb->key[0] = char2key( tolower(ch) );
  406. pb->keynum = 1;
  407. }
  408. else
  409. pb->keynum = 0;
  410. pb->markedkeynum = 1;
  411. pb->markedkey[0] = ct_enter;
  412. }
  413. void tdlgengine::addscrollbar(tmouserect rec,
  414. int* numberofitems,
  415. int itemsvisible,
  416. int* actitem,
  417. int lid,
  418. int keys)
  419. {
  420. addscrollbar ( rec.x1, rec.y1, rec.x2, rec.y2, numberofitems, itemsvisible, actitem, lid, keys );
  421. }
  422. void tdialogbox :: bar ( tmouserect rect, int color )
  423. {
  424. ::bar ( rect.x1, rect.y1, rect.x2, rect.y2, color );
  425. }
  426. void tdialogbox :: bar ( int x1, int y1, int x2, int y2, int color )
  427. {
  428. ::bar ( x1, y1, x2, y2, color );
  429. }
  430. void tdlgengine::addDropDown( int x1, int y1, int x2, int y2, int ID, const char** entries, int entrynum, int* pos )
  431. {
  432. pbutton pb = firstbutton;
  433. if ( ID <= 0)
  434. displaymessage("tdialogbox: id equal or less then 0", 2);
  435. while (pb != NULL) {
  436. if (pb->id == ID)
  437. displaymessage("tdialogbox: duplicate button id: %d\n",2, ID);
  438. pb = pb->next;
  439. }
  440. pb = new tbutton;
  441. pb->x1 = x1;
  442. pb->x2 = x2;
  443. pb->y1 = y1;
  444. pb->y2 = y2;
  445. pb->style = 0;
  446. pb->id = ID;
  447. pb->next = firstbutton;
  448. pb->text = NULL;
  449. pb->art = 6;
  450. pb->active = true;
  451. pb->status = 1;
  452. pb->keynum = 0;
  453. pb->markedkeynum = 0;
  454. pb->scrollspeed = 30;
  455. pb->pressed = 0;
  456. pb->newpressed = 0;
  457. pb->entries = entries;
  458. pb->entrynum = entrynum;
  459. pb->data = pos;
  460. firstbutton = pb;
  461. }
  462. void tdlgengine::addscrollbar(int lx1,
  463. int ly1,
  464. int lx2,
  465. int ly2,
  466. int* numberofitems,
  467. int itemsvisible,
  468. int* actitem,
  469. int lid,
  470. int keys)
  471. {
  472. pbutton pb;
  473. pb = firstbutton;
  474. if (lid <= 0)
  475. displaymessage("tdialogbox: id equal or less then 0", 2);
  476. while (pb != NULL) {
  477. if (pb->id == lid)
  478. displaymessage("tdialogbox: duplicate button id: %d\n",2, lid);
  479. pb = pb->next;
  480. }
  481. pb = new tbutton;
  482. pb->x1 = lx1;
  483. pb->x2 = lx2;
  484. pb->y1 = ly1 + 13;
  485. pb->y2 = ly2 - 13;
  486. pb->style = 0;
  487. pb->id = lid;
  488. pb->next = firstbutton;
  489. pb->text = NULL;
  490. pb->art = 5;
  491. pb->active = true;
  492. pb->status = 1;
  493. pb->keynum = 0;
  494. pb->markedkeynum = 0;
  495. pb->scrollspeed = 30;
  496. pb->pressed = 0;
  497. pb->newpressed = 0;
  498. firstbutton = pb;
  499. addbutton("",lx1+1, ly1 + 1 , lx2 - 1, ly1 + 10, 0, 2, lid + 1, true);
  500. addbutton("",lx1+1, ly2 - 10 , lx2 - 1, ly2 - 1, 0, 2, lid + 2, true);
  501. if (keys == 2) {
  502. addmarkedkey(lid + 1,ct_up);
  503. addmarkedkey(lid + 1,ct_pup);
  504. addmarkedkey(lid + 1,ct_pos1);
  505. addmarkedkey(lid + 2,ct_down);
  506. addmarkedkey(lid + 2,ct_pdown);
  507. addmarkedkey(lid + 2,ct_ende);
  508. }
  509. if (keys == 1) {
  510. addkey(lid + 1,ct_up);
  511. addkey(lid + 1,ct_pup);
  512. addkey(lid + 1,ct_pos1);
  513. addkey(lid + 2,ct_down);
  514. addkey(lid + 2,ct_pdown);
  515. addkey(lid + 2,ct_ende);
  516. }
  517. pb->data = actitem;
  518. pb->data2 = numberofitems;
  519. pb->max = itemsvisible;
  520. }
  521. void tdialogbox::rebuildtaborder(void)
  522. {
  523. pbutton pb = firstbutton;
  524. int i = 0;
  525. ttaborder b;
  526. tabcount = 0;
  527. while (pb != NULL) {
  528. if ((pb->art >= 0) && (pb->art <= 3))
  529. if ((pb->status == 1) && pb->active) {
  530. tabcount++;
  531. taborder[tabcount].id = pb->id;
  532. taborder[tabcount].x1 = pb->x1;
  533. taborder[tabcount].y1 = pb->y1;
  534. taborder[tabcount].x2 = pb->x2;
  535. taborder[tabcount].y2 = pb->y2;
  536. taborder[tabcount].button = pb;
  537. }
  538. pb = pb->next;
  539. }
  540. if (tabcount > 1)
  541. for (i = 1; i <= tabcount - 1; i++) {
  542. if ((taborder[i].y1 > taborder[i + 1].y1) || ((taborder[i].y1 == taborder[i + 1].y1) && (taborder[i].x1 > taborder[i + 1].x1)))
  543. {
  544. b = taborder[i];
  545. taborder[i] = taborder[i + 1];
  546. taborder[i + 1] = b;
  547. if (i > 1)
  548. i -= 2;
  549. }
  550. }
  551. pbutton pb2 = NULL;
  552. if (i > 0) {
  553. if (markedtab > 0)
  554. pb2 = taborder[i].button;
  555. }
  556. showtabmark(markedtab);
  557. if ( markedtab ) {
  558. markedtab = 0;
  559. if (tabcount > 0) {
  560. for (i = 1; i <= tabcount; i++)
  561. if (taborder[i].button == pb2)
  562. markedtab = i;
  563. }
  564. }
  565. showtabmark(markedtab);
  566. }
  567. void tdialogbox::showbutton(int id)
  568. {
  569. pbutton pb;
  570. int c;
  571. char mss = getmousestatus();
  572. if (mss == 2)
  573. mousevisible(false);
  574. pb = firstbutton;
  575. while (pb != NULL) {
  576. if (pb->id == id)
  577. if ( pb->pressed == 0) {
  578. c = pb->status;
  579. pb->status = 1;
  580. if (pb->active)
  581. enablebutton(id);
  582. else
  583. disablebutton(id);
  584. if (pb->art == 5) {
  585. showbutton ( id + 1);
  586. showbutton ( id + 2);
  587. } /* endif */
  588. if (c != 1)
  589. rebuildtaborder();
  590. }
  591. pb = pb->next;
  592. }
  593. if (mss == 2)
  594. mousevisible(true);
  595. }
  596. void tdialogbox::hidebutton(int id)
  597. {
  598. pbutton pb;
  599. pb = firstbutton;
  600. while (pb != NULL) {
  601. if (pb->id == id) {
  602. pb->status = 0;
  603. if (pb->art == 5) {
  604. hidebutton ( id + 1);
  605. hidebutton ( id + 2);
  606. } /* endif */
  607. }
  608. pb = pb->next;
  609. }
  610. rebuildtaborder();
  611. }
  612. void tdlgengine::clearkey ( char id )
  613. {
  614. pbutton pb = firstbutton;
  615. while ( pb ) {
  616. if ( pb->id == id ) {
  617. pb->keynum = 0;
  618. pb->markedkeynum = 0;
  619. }
  620. pb = pb->next;
  621. }
  622. }
  623. void tdlgengine::addkey( int id, tkey key )
  624. {
  625. pbutton pb = firstbutton;
  626. while ( pb ) {
  627. if (pb->id == id) {
  628. int exist = 0;
  629. for ( int i = 0; i < pb->keynum; i++ )
  630. if ( pb->key[i] == key )
  631. exist++;
  632. if ( !exist ) {
  633. pb->key [ pb->keynum ] = key;
  634. pb->keynum++;
  635. }
  636. }
  637. pb = pb->next;
  638. }
  639. }
  640. void tdlgengine::addmarkedkey(int id, tkey key)
  641. {
  642. pbutton pb;
  643. pb = firstbutton;
  644. while ( pb ) {
  645. if (pb->id == id) {
  646. int exist = 0;
  647. for ( int i = 0; i < pb->markedkeynum; i++ )
  648. if ( pb->markedkey[i]== key )
  649. exist++;
  650. if ( !exist ) {
  651. pb->markedkey [ pb->markedkeynum ] = key;
  652. pb->markedkeynum++;
  653. }
  654. }
  655. pb = pb->next;
  656. }
  657. }
  658. void tdialogbox::setscrollspeed(char id , int speed)
  659. {
  660. pbutton pb;
  661. pb = firstbutton;
  662. while (pb != NULL) {
  663. if (pb->id == id) {
  664. if (pb->art == 5) {
  665. setscrollspeed( id + 1, speed );
  666. setscrollspeed( id + 2, speed );
  667. } else
  668. pb->scrollspeed = speed;
  669. }
  670. pb = pb->next;
  671. }
  672. }
  673. void tdlgengine::addeingabe(int lid,
  674. void* data,
  675. int min,
  676. int max)
  677. {
  678. pbutton pb;
  679. pb = firstbutton;
  680. while (pb != NULL) {
  681. if (pb->id == lid) {
  682. pb->data = data;
  683. if ( min > max ) {
  684. pb->min = max;
  685. pb->max = min;
  686. } else {
  687. pb->min = min;
  688. pb->max = max;
  689. }
  690. addmarkedkey(pb->id,ct_enter);
  691. addmarkedkey(pb->id,ct_space);
  692. }
  693. pb = pb->next;
  694. }
  695. }
  696. void tdialogbox::enablebutton(int id)
  697. {
  698. pbutton pb = firstbutton;
  699. if ( !pb )
  700. return;
  701. while ( pb && pb->id != id )
  702. pb = pb->next;
  703. if ( !pb )
  704. return;
  705. npush( activefontsettings );
  706. collategraphicoperations cgo ( x1 + pb->x1, max ( y1 + pb->y1 - 20, 0 ), x1 + pb->x2, y1 + pb->y2 );
  707. char strng[200];
  708. activefontsettings.font = schriften.smallarial;
  709. activefontsettings.justify = lefttext;
  710. activefontsettings.length = pb->x2 - pb->x1 - 10;
  711. activefontsettings.markcolor = textcolor - 2;
  712. activefontsettings.color = textcolor;
  713. activefontsettings.background = 255;
  714. if (pb->art == 0) {
  715. if ((pb->style == 1) || (pb->style == 2))
  716. newknopf(x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2);
  717. if ( pb->text )
  718. if (pb->text[0] ) {
  719. activefontsettings.justify = centertext;
  720. showtext3( pb->text,x1 + pb->x1,y1 + (pb->y1 + pb->y2) / 2 - activefontsettings.font->height / 2);
  721. }
  722. }
  723. if ((pb->art == 1) || ( pb->art == 2 )) {
  724. rahmen(true,x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2);
  725. paintsurface( pb->x1 + 1, pb->y1 + 1, pb->x2 - 1, pb->y2 - 1 );
  726. if ( pb->text )
  727. if (pb->text[0] ) {
  728. if ( pb->style != 3 ) {
  729. showtext3(pb->text,x1 + pb->x1,y1 + pb->y1 - activefontsettings.font->height);
  730. } else {
  731. npush ( activefontsettings.length );
  732. activefontsettings.length = 300;
  733. cgo.off();
  734. showtext3(pb->text,x1 + pb->x2 + 10,y1 + pb->y1 );
  735. cgo.on();
  736. npop ( activefontsettings.length );
  737. }
  738. }
  739. if (pb->art == 1)
  740. showtext2((char*) pb->data , x1 + pb->x1 + 5,y1 + pb->y1 + 2);
  741. if (pb->art == 2) {
  742. if (pb->max <= 255 && pb->min >= 0) {
  743. char* pbt = (char*) pb->data;
  744. itoa ( *pbt, strng, 10 );
  745. showtext2( strng, x1 + pb->x1 + 5,y1 + pb->y1 + 2);
  746. }
  747. else
  748. if (pb->max <= 65535 && pb->min >= 0) {
  749. Uint16* pw = (Uint16*) pb->data;
  750. itoa ( *pw, strng, 10 );
  751. showtext2(strng, x1 + pb->x1 + 5,y1 + pb->y1 + 2);
  752. }
  753. else {
  754. int* pl = (int*) pb->data;
  755. itoa ( *pl, strng, 10 );
  756. showtext2(strng, x1 + pb->x1 + 5,y1 + pb->y1 + 2);
  757. }
  758. }
  759. }
  760. if (pb->art == 3) {
  761. rahmen(true,x1 + pb->x1,y1 + pb->y1,x1 + pb->x1 + (pb->y2 - pb->y1),y1 + pb->y2);
  762. showtext3(pb->text,x1 + pb->x1 + (pb->y2 - pb->y1) + 5,y1 + (pb->y1 + pb->y2 - activefontsettings.font->height) / 2);
  763. char* pbl = (char*) pb->data;
  764. int cl;
  765. if (*pbl)
  766. cl = pb->min;
  767. else
  768. cl = pb->max;
  769. line(x1 + pb->x1,y1 + pb->y1,x1 + pb->x1 + (pb->y2 - pb->y1),y1 + pb->y2, cl);
  770. line(x1 + pb->x1 + (pb->y2 - pb->y1),y1 + pb->y1,x1 + pb->x1,y1 + pb->y2, cl);
  771. }
  772. if (pb->art == 5) { // Scrollbar
  773. Uint16* pw = (Uint16*) pb->data;
  774. Uint16* pw2 =(Uint16*) pb->data2;
  775. rahmen(true,x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2);
  776. paintsurface2(x1 + pb->x1 + 1,y1 + pb->y1 + 1,x1 + pb->x2 - 1,y1 + pb->y2 - 1 );
  777. // if (pb->max <= *pw2) {
  778. int l = pb->y2 - pb->y1 - 2;
  779. rahmen(false, x1 + pb->x1 + 1, y1 + pb->y1 + 1 + l * *pw / *pw2,
  780. x1 + pb->x2 - 1, y1 + pb->y1 + 1 + l * (*pw + pb->max) / *pw2);
  781. // }
  782. // else
  783. // rahmen(true,x1 + pb->x1 + 1,y1 + pb->y1 + 1,x1 + pb->x2 - 1,y1 + pb->y2 - 1);
  784. }
  785. if ( pb->art == 6 ) {
  786. bar ( x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2, lightgray );
  787. rahmen(true,x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2);
  788. int pos = *( (int*) pb->data );
  789. if ( pos < 0 || pos >= pb->entrynum )
  790. fatalError("invalid pos in dropdown",2);
  791. showtext3(pb->entries[pos], x1 + pb->x1 + (pb->y2 - pb->y1) + 5, y1 + (pb->y1 + pb->y2 - activefontsettings.font->height) / 2);
  792. line ( x1 + pb->x2 - 20, y1 + pb->y1 + 4, x1 + pb->x2 - 10, y1 + pb->y1 + 4, textcolor );
  793. line ( x1 + pb->x2 - 20, y1 + pb->y1 + 4, x1 + pb->x2 - 15, y1 + pb->y1 + 14, textcolor );
  794. line ( x1 + pb->x2 - 10, y1 + pb->y1 + 4, x1 + pb->x2 - 15, y1 + pb->y1 + 14, textcolor );
  795. }
  796. pb->active = true;
  797. npop( activefontsettings );
  798. rebuildtaborder();
  799. }
  800. void tdialogbox::disablebutton(int id)
  801. {
  802. pbutton pb;
  803. int *pl;
  804. Uint16 *pw, *pw2;
  805. char *pbt;
  806. char *pbl;
  807. char* s;
  808. char* t;
  809. int l;
  810. char cl;
  811. pb = firstbutton;
  812. if ( !pb )
  813. return;
  814. while ((pb != NULL) && (pb->id != id))
  815. pb = pb->next;
  816. if (pb == NULL)
  817. return;
  818. npush(activefontsettings);
  819. activefontsettings.font = schriften.smallarial;
  820. activefontsettings.justify = lefttext;
  821. activefontsettings.length = pb->x2 - pb->x1 - 10;
  822. activefontsettings.color = disablecolor;
  823. s = new char[200];
  824. strcpy(s, pb->text);
  825. t = strchr( s, 126 );
  826. while ( t != NULL ) {
  827. do {
  828. t[0] = t[1];
  829. t++;
  830. } while ( t[0] !=0 ) ;
  831. t = strchr( s, 126 );
  832. }
  833. if (pb->art == 0) {
  834. if (pb->text != NULL)
  835. if (pb->text[0] != 0) {
  836. activefontsettings.justify = centertext;
  837. showtext2(s, x1 + pb->x1, y1 + (pb->y1 + pb->y2) / 2 - activefontsettings.font->height / 2);
  838. }
  839. if ((pb->style == 1) || (pb->style == 2)) {
  840. rectangle(x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2,disablecolor);
  841. rectangle(x1 + pb->x1 - 1,y1 + pb->y1 - 1,x1 + pb->x2 + 1,y1 + pb->y2 + 1,disablecolor);
  842. }
  843. }
  844. if ((pb->art == 1) || (pb->art == 2)) {
  845. rectangle(x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2,disablecolor);
  846. if (pb->text != NULL)
  847. if (pb->text[0] != 0) {
  848. if ( pb->style != 3 )
  849. showtext2(pb->text,x1 + pb->x1,y1 + pb->y1 - activefontsettings.font->height);
  850. else {
  851. npush ( activefontsettings );
  852. activefontsettings.length = 0;
  853. showtext2(pb->text,x1 + pb->x2 + 10,y1 + pb->y1 );
  854. npop ( activefontsettings );
  855. }
  856. }
  857. if (pb->art == 1) {
  858. showtext2( (char*)pb->data,x1 + pb->x1 + 5,y1 + pb->y1 + 2);
  859. }
  860. if (pb->art == 2) {
  861. if (pb->max <= 255 && pb->min >= 0) {
  862. pbt = (char*) pb->data;
  863. itoa ( *pbt, s, 10 );
  864. showtext2(s,x1 + pb->x1 + 5,y1 + pb->y1 + 2);
  865. }
  866. else
  867. if (pb->max <= 65535 && pb->min >= 0) {
  868. pw = (Uint16*) pb->data;
  869. itoa ( *pw, s , 10);
  870. showtext2(s, x1 + pb->x1 + 5,y1 + pb->y1 + 2);
  871. }
  872. else {
  873. pl = (int*) pb->data;
  874. itoa ( *pl, s, 10);
  875. showtext2(s, x1 + pb->x1 + 5,y1 + pb->y1 + 2);
  876. }
  877. }
  878. }
  879. if (pb->art == 3) {
  880. rectangle(x1 + pb->x1,y1 + pb->y1,x1 + pb->x1 + (pb->y2 - pb->y1),y1 + pb->y2,disablecolor);
  881. showtext2(s,x1 + pb->x1 + (pb->y2 - pb->y1) + 5,y1 + (pb->y1 + pb->y2 - activefontsettings.font->height) / 2);
  882. pbl = (char*) pb->data;
  883. if (*pbl)
  884. cl = disablecolor;
  885. else
  886. cl = pb->max;
  887. line(x1 + pb->x1,y1 + pb->y1,x1 + pb->x1 + (pb->y2 - pb->y1),y1 + pb->y2, cl);
  888. line(x1 + pb->x1 + (pb->y2 - pb->y1),y1 + pb->y1,x1 + pb->x1,y1 + pb->y2, cl);
  889. }
  890. if (pb->art == 5) {
  891. pw = (Uint16*) pb->data;
  892. pw2 = (Uint16*) pb->data2;
  893. // waitretrace();
  894. rectangle(x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2,disablecolor);
  895. paintsurface2(x1 + pb->x1 + 1,y1 + pb->y1 + 1,x1 + pb->x2 - 1,y1 + pb->y2 - 1);
  896. if (pb->max <= *pw2) {
  897. l = pb->y2 - pb->y1 - 2;
  898. rectangle(x1 + pb->x1 + 1,y1 + pb->y1 + 1 + l * *pw / *pw2,x1 + pb->x2 - 1,y1 + pb->y1 + 1 + l * (*pw + pb->max) / *pw2,disablecolor);
  899. }
  900. else
  901. rectangle(x1 + pb->x1 + 1,y1 + pb->y1 + 1,x1 + pb->x2 - 1,y1 + pb->y2 - 1,disablecolor);
  902. }
  903. delete[] s;
  904. pb->active = false;
  905. npop( activefontsettings );
  906. rebuildtaborder();
  907. }
  908. void tdialogbox::redraw(void)
  909. {
  910. pbutton pb;
  911. knopf(x1,y1,x1 + xsize,y1 + ysize);
  912. rahmen(false, x1,y1,x1 + xsize, y1 + ysize);
  913. activefontsettings.color = white;
  914. activefontsettings.background = 255;
  915. activefontsettings.font = schriften.smallarial;
  916. activefontsettings.justify = centertext;
  917. activefontsettings.length = xsize - 10;
  918. activefontsettings.height = 00;
  919. if (windowstyle & dlg_wintitle ) {
  920. starty = 25;
  921. rahmen(true,x1 + 5,y1 + 3,x1 + xsize - 5,y1 + 20);
  922. bar(x1 + 6,y1 + 4,x1 + xsize - 6,y1 + 19,blue);
  923. activefontsettings.color = textcolor;
  924. showtext2(title, x1 + 5,y1 + 3);
  925. }
  926. else {
  927. starty = 5;
  928. if ((windowstyle & dlg_notitle) == 0)
  929. if (title != NULL)
  930. if (title[0] ) {
  931. activefontsettings.font = schriften.large;
  932. if ( windowstyle & dlg_3dtitle ) {
  933. if ( actmap && actmap->actplayer == 7 ) {
  934. activefontsettings.color = xlattables.a.dark1[textcolor];
  935. showtext2(title, x1 + 4, y1 + 4 );
  936. activefontsettings.color = xlattables.a.light[textcolor];
  937. showtext2(title, x1 + 6, y1 + 6 );
  938. } else {
  939. activefontsettings.color = textcolor + 2;
  940. showtext2(title, x1 + 4, y1 + 4 );
  941. activefontsettings.color = textcolor - 2;
  942. showtext2(title, x1 + 6, y1 + 6 );
  943. }
  944. }
  945. activefontsettings.color = textcolor;
  946. showtext2(title, x1 + 5, y1 + 5 );
  947. starty = 40;
  948. }
  949. }
  950. if (windowstyle & dlg_in3d )
  951. rahmen(true,x1 + 5,y1 + starty,x1 + xsize - 5,y1 + ysize - 5);
  952. pb = firstbutton;
  953. while (pb != NULL) {
  954. if (pb->status) {
  955. if (pb->active)
  956. enablebutton(pb->id);
  957. else
  958. disablebutton(pb->id);
  959. }
  960. pb = pb->next;
  961. }
  962. }
  963. void tdialogbox::buildgraphics(void)
  964. {
  965. if ( x1 == -1 )
  966. x1 = ( agmp->resolutionx - xsize ) / 2;
  967. else
  968. if ( x1 + xsize < 640 )
  969. x1 += (agmp->resolutionx - 640) / 2;
  970. if ( y1 == -1 )
  971. y1 = ( agmp->resolutiony - ysize ) / 2;
  972. else
  973. if ( y1 + ysize < 480 )
  974. y1 += (agmp->resolutiony - 480) / 2;
  975. if ( xsize == -1)
  976. xsize = agmp->resolutionx - xsize*2;
  977. if ( ysize == -1)
  978. ysize = agmp->resolutiony - ysize*2;
  979. if ( pcgo )
  980. delete pcgo;
  981. pcgo = new collategraphicoperations ( x1, y1, x1 + xsize, y1 + ysize );
  982. if (windowstyle & dlg_notitle )
  983. if (windowstyle & dlg_wintitle )
  984. windowstyle ^= dlg_wintitle;
  985. ms = getmousestatus();
  986. if (ms == 2)
  987. mousevisible(false);
  988. if ( !(dlg_mode & 2) ) {
  989. tp = malloc ( imagesize (x1,y1,x1 + xsize,y1 + ysize ) );
  990. getimage(x1,y1,x1 + xsize,y1 + ysize,tp);
  991. imagesaved = true;
  992. }
  993. if ( dlg_mode & 1 ) {
  994. paint ();
  995. } else {
  996. redraw ();
  997. }
  998. rebuildtaborder();
  999. activefontsettings.color = textcolor;
  1000. boxstatus = 2;
  1001. // if (ms == 2)
  1002. // mousevisible(true);
  1003. }
  1004. void tdialogbox::done(void)
  1005. {
  1006. pbutton pb;
  1007. pbutton pb2;
  1008. if ( boxstatus ) {
  1009. ms = getmousestatus();
  1010. if (ms == 2)
  1011. mousevisible(false);
  1012. pb = firstbutton;
  1013. while (pb != NULL) {
  1014. pb2 = pb->next;
  1015. delete ( pb );
  1016. pb = pb2;
  1017. }
  1018. if (imagesaved) {
  1019. if ( first == this )
  1020. ::repaintDisplay();
  1021. else
  1022. putimage(x1,y1,tp);
  1023. free ( tp );
  1024. }
  1025. npop( activefontsettings );
  1026. if (ms == 2)
  1027. mousevisible(true);
  1028. }
  1029. boxstatus = 0;
  1030. }
  1031. void tdialogbox::execbutton( pbutton pb, char mouse )
  1032. {
  1033. int t, l;
  1034. Uint16 *pw, *pw2;
  1035. if (mouse == false) {
  1036. if (pb->art == 0) {
  1037. if ((pb->style == 1) || (pb->style == 2))
  1038. buttonpressed(pb->id);
  1039. }
  1040. if (pb->art == 3)
  1041. toggleswitch(pb);
  1042. }
  1043. else {
  1044. if (pb->art == 0) {
  1045. if (pb->style == 1) {
  1046. newknopfdruck(x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2);
  1047. if (knopfsuccessful)
  1048. buttonpressed(pb->id);
  1049. }
  1050. if (pb->style == 2) {
  1051. mousevisible(false);
  1052. pb->pressed = 1;
  1053. pb->newpressed = 1;
  1054. newknopfdruck4(x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2);
  1055. mousevisible(true);
  1056. t = ticker;
  1057. buttonpressed(pb->id);
  1058. pb->newpressed = 2;
  1059. while ((mouseparams.x >= x1 + pb->x1) && (mouseparams.x <= x1 + pb->x2) && (mouseparams.y >= y1 + pb->y1) && (mouseparams.y <= y1 + pb->y2) && (mouseparams.taste & 1)) {
  1060. if (ticker - t > pb->scrollspeed ) {
  1061. t = ticker;
  1062. buttonpressed(pb->id);
  1063. }
  1064. releasetimeslice();
  1065. }
  1066. mousevisible(false);
  1067. newknopfdruck3(x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2);
  1068. pb->newpressed = 0;
  1069. pb->pressed = 0;
  1070. mousevisible(true);
  1071. }
  1072. }
  1073. if (pb->art == 3) {
  1074. toggleswitch(pb);
  1075. do {
  1076. releasetimeslice();
  1077. } while (!(mouseparams.taste == 0));
  1078. }
  1079. if (pb->art == 5) { // Scrollbar
  1080. pw = (Uint16*) pb->data;
  1081. pw2 = (Uint16*) pb->data2;
  1082. l = pb->y2 - pb->y1 - 2;
  1083. int xb1 = x1 + pb->x1;
  1084. int yb1 = y1 + pb->y1;
  1085. int xb2 = x1 + pb->x2;
  1086. int yb2 = y1 + pb->y2;
  1087. if ( mouseparams.y >= yb1 + 1 + l * *pw / *pw2 && mouseparams.y <= yb1 + 1 + l * (*pw + pb->max) / *pw2) {
  1088. char mss = getmousestatus ();
  1089. if (mss == 2)
  1090. mousevisible(false);
  1091. int ys1 = yb1 + 1 + l * *pw / *pw2;
  1092. int ys1a = ys1;
  1093. int ys1b = ys1a;
  1094. int ysd = yb1 + 1 + l * (*pw + pb->max) / *pw2 - ys1;
  1095. rahmen(true, xb1 + 1, ys1,
  1096. xb2 - 1, ys1 + ysd);
  1097. int mousestarty = mouseparams.y;
  1098. mousevisible( true );
  1099. while (mouseparams.taste & 1) {
  1100. int i = mouseparams.y - mousestarty ;
  1101. ys1 = ys1a + i;
  1102. if ( ys1 <= yb1)
  1103. ys1 = yb1+1;
  1104. if ( ys1 + ysd >= yb2 )
  1105. ys1 = yb2 - ysd - 1;
  1106. if ( ys1 != ys1b ) {
  1107. collategraphicoperations cgo ( x1 + pb->x1, y1 + pb->y1, x1 + pb->x2, y1 + pb->y2 );
  1108. ys1b = ys1;
  1109. // waitretrace();
  1110. mousevisible(false);
  1111. paintsurface2(x1 + pb->x1 + 1,y1 + pb->y1 + 1,x1 + pb->x2 - 1,y1 + pb->y2 - 1 );
  1112. rahmen(true, xb1 + 1, ys1, xb2 - 1, ys1 + ysd);
  1113. cgo.off();
  1114. int j = (ys1 - yb1 - 1) * (*pw2) / l;
  1115. if (j != *pw) {
  1116. *pw = j;
  1117. buttonpressed(pb->id);
  1118. }
  1119. mousevisible( true );
  1120. }
  1121. releasetimeslice();
  1122. }
  1123. mousevisible( false );
  1124. showbutton( pb->id );
  1125. if (mss == 2)
  1126. mousevisible(true);
  1127. } else {
  1128. l = *pw;
  1129. t = mouseparams.y - (pb->y1 + y1);
  1130. *pw = (10 * t * (*pw2 - pb->max) / (pb->y2 - pb->y1 - 2) + 5) / 10;
  1131. if (*pw != l) {
  1132. l = getmousestatus();
  1133. if (l == 2)
  1134. mousevisible(false);
  1135. showbutton(pb->id);
  1136. buttonpressed(pb->id);
  1137. if (l == 2)
  1138. mousevisible(true);
  1139. }
  1140. }
  1141. }
  1142. if (pb->art == 6) {
  1143. int height = pb->entrynum * 25 + 10;
  1144. int starty = y1 + pb->y2;
  1145. if ( starty + height > agmp->resolutiony )
  1146. starty = agmp->resolutiony - height;
  1147. mousevisible(false);
  1148. int* pos = (int*) pb->data ;
  1149. activefontsettings.font = schriften.smallarial;
  1150. activefontsettings.background = lightgray;
  1151. activefontsettings.justify = lefttext;
  1152. activefontsettings.length = (Uint16) (pb->x2 - pb->x1 - 20 );
  1153. void* buf = malloc ( imagesize ( x1 + pb->x1, starty, x1 + pb->x2, starty + height ));
  1154. getimage( x1 + pb->x1, starty, x1 + pb->x2, starty + height, buf );
  1155. bar ( x1 + pb->x1, starty, x1 + pb->x2, starty + height, lightgray );
  1156. rectangle ( x1 + pb->x1, starty, x1 + pb->x2, starty + height, black );
  1157. bool first = true;
  1158. int oldpos = *pos;
  1159. mousevisible(true);
  1160. do {
  1161. int p = (mouseparams.y - starty - 5);
  1162. if ( p < 0 )
  1163. p = -1;
  1164. else
  1165. p /= 25;
  1166. if ( (p >= 0 && p < pb->entrynum ) || first )
  1167. if ( p != *pos || first ) {
  1168. if ( p != *pos && p >= 0 && p < pb->entrynum )
  1169. *pos = p;
  1170. for ( int i = 0; i < pb->entrynum; ++i ) {
  1171. if ( i == *pos )
  1172. activefontsettings.color = textcolor;
  1173. else
  1174. activefontsettings.color = black ;
  1175. showtext2 ( pb->entries[i], x1 + pb->x1 + 5, starty + i * 25 + 5 );
  1176. }
  1177. }
  1178. releasetimeslice();
  1179. first = false;
  1180. } while ((mouseparams.x >= x1 + pb->x1) && (mouseparams.x <= x1 + pb->x2) && (mouseparams.y >= min(starty, y1+pb->y1)) && (mouseparams.y <= starty + height) && (mouseparams.taste & 1)) ;
  1181. mousevisible(false);
  1182. putimage ( x1 + pb->x1, starty, buf );
  1183. free ( buf );
  1184. mousevisible(true);
  1185. enablebutton( pb->id );
  1186. if ( oldpos != *pos )
  1187. buttonpressed( pb->id );
  1188. }
  1189. if ( pb->art > 10 ) {
  1190. buttonpressed(pb->id);
  1191. while ( mouseinrect ( x1 + pb->x1 , y1 + pb->y1 , x1 + pb->x2 , y1 + pb->y2 ) && ( mouseparams.taste & 1))
  1192. releasetimeslice();
  1193. }
  1194. /*
  1195. rahmen(true,x1+pb^.x1,y1+pb^.y1,x1+pb^.x2,y1+pb^.y2);
  1196. nbar(x1+pb^.x1+1,y1+pb^.y1+1,x1+pb^.x2-1,y1+pb^.y2-1,dblue);
  1197. rahmen(false,x1 + pb^.x1+1,y1 + pb^.y1+1+ l * pw^ div pw2^ ,
  1198. x1 + pb^.x2-1,y1 + pb^.y1+1+ l * (pw^+ pb^.max) div pw2^); */
  1199. }
  1200. if ((pb->art == 1) || (pb->art == 2)) {
  1201. editfield(pb);
  1202. buttonpressed(pb->id);
  1203. }
  1204. }
  1205. void tdialogbox::showtabmark(int b)
  1206. {
  1207. if (b != 0)
  1208. xorrectangle(x1 + taborder[b].x1 - 2,y1 + taborder[b].y1 - 2,x1 + taborder[b].x2 + 2,y1 + taborder[b].y2 + 2,15);
  1209. }
  1210. void tdialogbox::run(void)
  1211. {
  1212. if ( pcgo ) {
  1213. delete pcgo;
  1214. pcgo = NULL;
  1215. }
  1216. int xm, ym, xp, yp;
  1217. int i, oldx, oldy, xp2, yp2;
  1218. pbutton pb;
  1219. taste = ct_invvalue;
  1220. if (getmousestatus() == 2) {
  1221. if ((mouseparams.x > x1 + 5) && (mouseparams.y > y1 + 3) && (mouseparams.x < x1 + xsize - 5) && (mouseparams.y < y1 + 20) && (mouseparams.taste == 1) && (dlg_mode & 3) == 3 ) {
  1222. oldx = x1;
  1223. oldy = y1;
  1224. xp2 = oldx;
  1225. yp2 = oldy;
  1226. xm = mouseparams.x;
  1227. ym = mouseparams.y;
  1228. xp = xm;
  1229. yp = ym;
  1230. while (mouseparams.taste == 1) {
  1231. if ((mouseparams.x != xp) || (mouseparams.y != yp)) {
  1232. x1 = oldx + (mouseparams.x - xm);
  1233. y1 = oldy + (mouseparams.y - ym);
  1234. if (x1 < 0) x1 = 0;
  1235. if (y1 < 0) y1 = 0;
  1236. if (x1 + xsize >= agmp->resolutionx) x1 = agmp->resolutionx - xsize - 1;
  1237. if (y1 + ysize >= agmp->resolutiony) y1 = agmp->resolutiony - ysize - 1;
  1238. if ((x1 != xp2) || (y1 != yp2)) {
  1239. mousevisible(false);
  1240. xorrectangle(xp2,yp2,xp2 + xsize,yp2 + ysize,14);
  1241. xorrectangle(x1,y1,x1 + xsize,y1 + ysize,14);
  1242. mousevisible(true);
  1243. xp2 = x1;
  1244. yp2 = y1;
  1245. /*
  1246. int ox = xp2;
  1247. int oy = yp2;
  1248. paint();
  1249. if ( prev )
  1250. prev->redrawall2( ox, oy, ox + xsize, oy + ysize );
  1251. else
  1252. repaintdisplay();
  1253. */
  1254. }
  1255. xp = mouseparams.x;
  1256. yp = mouseparams.y;
  1257. }
  1258. releasetimeslice();
  1259. }
  1260. if ((oldx != x1) || (oldy != y1)) {
  1261. paint();
  1262. if ( prev )
  1263. prev->redrawall2( oldx, oldy, oldx + xsize, oldy + ysize );
  1264. else
  1265. repaintDisplay();
  1266. }
  1267. }
  1268. if (mouseparams.taste == 1) {
  1269. pb = firstbutton;
  1270. while (pb != NULL) {
  1271. if (pb->status)
  1272. if (pb->active) {
  1273. if ((mouseparams.x >= x1 + pb->x1) && (mouseparams.x <= x1 + pb->x2) && (mouseparams.y >= y1 + pb->y1) && (mouseparams.y <= y1 + pb->y2)) {
  1274. execbutton(pb,true);
  1275. break;
  1276. }
  1277. }
  1278. pb = pb->next;
  1279. }
  1280. }
  1281. }
  1282. if (keypress()) {
  1283. getkeysyms ( &taste, &prntkey );
  1284. }
  1285. else {
  1286. taste = ct_invvalue;
  1287. prntkey = cto_invvalue;
  1288. }
  1289. releasetimeslice();
  1290. if (((taste == ct_tab) || (taste == ct_shift_tab)) && (tabcount > 0)) {
  1291. showtabmark(markedtab);
  1292. if (taste == ct_tab)
  1293. markedtab++;
  1294. else
  1295. markedtab--;
  1296. if (markedtab > tabcount)
  1297. markedtab = 1;
  1298. if (markedtab < 1)
  1299. markedtab = tabcount;
  1300. showtabmark(markedtab);
  1301. }
  1302. else {
  1303. pb = firstbutton;
  1304. while (pb != NULL) {
  1305. if (pb->markedkeynum > 0)
  1306. for (i = 0; i < pb->markedkeynum; i++)
  1307. if (markedtab > 0)
  1308. if ((pb->markedkey[i] == prntkey) && (taborder[markedtab].id == pb->id))
  1309. if (pb->active)
  1310. if (pb->status == 1) {
  1311. execbutton(pb,false);
  1312. taste = ct_invvalue;
  1313. prntkey = ct_invvalue;
  1314. }
  1315. if (pb->keynum > 0)
  1316. for (i = 0; i < pb->keynum; i++)
  1317. if (pb->key[i] == prntkey)
  1318. if (pb->active)
  1319. if (pb->status == 1) {
  1320. execbutton(pb,false);
  1321. taste = ct_invvalue;
  1322. prntkey = ct_invvalue;
  1323. }
  1324. pb = pb->next;
  1325. }
  1326. }
  1327. }
  1328. void tdialogbox::toggleswitch(pbutton pb)
  1329. {
  1330. char *pbl = (char*) pb->data;
  1331. if ( pb->style == 10 )
  1332. *pbl = 1;
  1333. else
  1334. *pbl = ! *pbl;
  1335. int col;
  1336. if (*pbl)
  1337. col = pb->min;
  1338. else
  1339. col = pb->max;
  1340. line(x1 + pb->x1,y1 + pb->y1,x1 + pb->x1 + (pb->y2 - pb->y1),y1 + pb->y2, col);
  1341. line(x1 + pb->x1 + (pb->y2 - pb->y1),y1 + pb->y1,x1 + pb->x1,y1 + pb->y2, col);
  1342. buttonpressed(pb->id);
  1343. }
  1344. char tdialogbox::checkvalue(int id,
  1345. void* p)
  1346. {
  1347. return true;
  1348. }
  1349. void tdialogbox::editfield( int id )
  1350. {
  1351. pbutton pb = firstbutton;
  1352. while ( pb ) {
  1353. if (pb->id == id )
  1354. editfield ( pb );
  1355. pb = pb->next;
  1356. }
  1357. }
  1358. void tdialogbox::editfield(pbutton pb)
  1359. {
  1360. char *ps = NULL;
  1361. int *pl = NULL;
  1362. Uint16 *pw = NULL;
  1363. char *pbt = NULL;
  1364. int l;
  1365. activefontsettings.font = schriften.smallarial;
  1366. activefontsettings.color = textcolor;
  1367. activefontsettings.background = dblue;
  1368. activefontsettings.length = (Uint16) (pb->x2 - pb->x1 - 10 );
  1369. if (pb->art == 1) {
  1370. ps = (char*) pb->data;
  1371. // mousevisible(false);
  1372. do {
  1373. stredit(ps, x1 + pb->x1 + 5,y1 + pb->y1 + 2,pb->x2 - pb->x1 - 10, pb->max);
  1374. } while ( !checkvalue(pb->id,ps) );
  1375. // mousevisible(true);
  1376. }
  1377. if (pb->art == 2) {
  1378. if (pb->max <= 255 && pb->min >= 0) {
  1379. pbt = (char*) pb->data;
  1380. l = *pbt;
  1381. }
  1382. else
  1383. if (pb->max <= 65535 && pb->min >= 0) {
  1384. pw = (Uint16*) pb->data;
  1385. l = *pw;
  1386. }
  1387. else {
  1388. pl = (int*) pb->data;
  1389. l = *pl;
  1390. }
  1391. // mousevisible(false);
  1392. do {
  1393. intedit( &l,x1 + pb->x1 + 5,y1 + pb->y1 + 2,pb->x2 - pb->x1 - 10,pb->min,pb->max);
  1394. } while ( !checkvalue(pb->id, &l) );
  1395. // mousevisible(true);
  1396. if (pb->max <= 255 && pb->min >= 0) {
  1397. *pbt = l;
  1398. }
  1399. else
  1400. if (pb->max <= 65535 && pb->min >= 0) {
  1401. *pw = l;
  1402. }
  1403. else {
  1404. *pl = l;
  1405. }
  1406. }
  1407. }
  1408. void tdialogbox::rahmen3(const char * txt,
  1409. int x1,
  1410. int y1,
  1411. int x2,
  1412. int y2,
  1413. int style)
  1414. {
  1415. collategraphicoperations cgs( x1, y1, x2, y2 );
  1416. Uint16 w;
  1417. npush( activefontsettings );
  1418. activefontsettings.font = schriften.smallarial;
  1419. w = gettextwdth(txt,NULL);
  1420. if (style == 1) {
  1421. line(x1,y1,x1,y2,black);
  1422. line(x1,y2,x2,y2,black);
  1423. line(x2,y1,x2,y2,black);
  1424. line(x1,y1,x1 + 9,y1,black);
  1425. line(x1 + 10 + w + 5,y1,x2,y1,black);
  1426. }
  1427. activefontsettings.justify = lefttext;
  1428. activefontsettings.length = 0;
  1429. showtext2(txt,x1 + 12,y1 - activefontsettings.font->height / 2);
  1430. npop( activefontsettings );
  1431. }
  1432. typedef char* tstringa[30];
  1433. typedef tstringa* pstringa;
  1434. class tdisplaymessage : public tdialogbox {
  1435. char status;
  1436. int mode;
  1437. public:
  1438. void init ( tstringa a, int md, int linenum, const char* buttonText = NULL );
  1439. virtual void buttonpressed ( int id );
  1440. virtual void run ( void );
  1441. };
  1442. extern tdisplaymessage* messagebox;
  1443. void tdisplaymessage::init ( tstringa a, int md, int linenum, const char* buttonText )
  1444. {
  1445. if ( !buttonText )
  1446. buttonText = "~O~K";
  1447. tdialogbox::init();
  1448. int i,j;
  1449. int maxlength = 0;
  1450. mode = md;
  1451. for (i=0;i<=linenum ;i++ ) {
  1452. j = gettextwdth ( a[i], schriften.smallarial );
  1453. while ( j > agmp->resolutionx ) {
  1454. a[i][strlen(a[i])-1] = 0;
  1455. j = gettextwdth ( a[i], schriften.smallarial );
  1456. }
  1457. if (maxlength < j)
  1458. maxlength = j;
  1459. } /* endfor */
  1460. x1 = 50;
  1461. y1 = 50;
  1462. if (maxlength < 150)
  1463. xsize = 200;
  1464. else
  1465. xsize = maxlength + 50;
  1466. if ( maxlength > agmp->resolutionx - 100 )
  1467. x1 = 0;
  1468. if ( xsize > agmp->resolutionx )
  1469. xsize = agmp->resolutionx;
  1470. ysize = 55 + linenum * 20;
  1471. windowstyle |= dlg_notitle;
  1472. if (mode != 0) {
  1473. ysize+=25;
  1474. addbutton ( buttonText, 10, ysize - 35 , xsize - 10 , ysize - 10 ,0,1,1,true );
  1475. addkey(1, ct_enter);
  1476. addkey(1, ct_esc);
  1477. addkey(1, ct_enterk );
  1478. addkey(1, ct_space );
  1479. };
  1480. buildgraphics();
  1481. activefontsettings.justify = lefttext;
  1482. if (mode == 1) {
  1483. activefontsettings.color = lightred;
  1484. } else {
  1485. activefontsettings.color = black;
  1486. } /* endif */
  1487. activefontsettings.font = schriften.smallarial;
  1488. for (i=0;i <= linenum ;i++ ) {
  1489. showtext2( a[i], x1+10, y1+20+i*20 );
  1490. } /* endfor */
  1491. status = 0;
  1492. if ( pcgo ) {
  1493. delete pcgo;
  1494. pcgo = NULL;
  1495. }
  1496. }
  1497. void tdisplaymessage::buttonpressed ( int id )
  1498. {
  1499. if ( id == 1) {
  1500. status = 1;
  1501. } /* endif */
  1502. }
  1503. void tdisplaymessage::run ( void )
  1504. {
  1505. mousevisible(true);
  1506. do {
  1507. tdialogbox::run();
  1508. } while ( status == 0 ); /* enddo */
  1509. }
  1510. // num 0: Box bleibt aufgeklappt,
  1511. // 1 box wird geschlossen , text rot (Fehler),
  1512. // 2 : Programm wird beendet;
  1513. // 3 : normaler text ( OK)
  1514. void displaymessage( const char* formatstring, int num, ... )
  1515. {
  1516. va_list paramlist;
  1517. va_start ( paramlist, num );
  1518. char tempbuf[1000];
  1519. int lng = vsprintf( tempbuf, formatstring, paramlist );
  1520. if ( lng >= 1000 )
  1521. displaymessage ( "dlg_box.cpp / displaymessage: string to long !\nPlease report this error",1 );
  1522. va_end ( paramlist );
  1523. displaymessage ( ASCString ( tempbuf ), num );
  1524. }
  1525. void displaymessage( const ASCString& text, int num )
  1526. {
  1527. const char* a = text.c_str();
  1528. tstringa stringtooutput;
  1529. memset (stringtooutput, 0, sizeof ( stringtooutput ));
  1530. stringtooutput[0] = new char[200];
  1531. stringtooutput[0][0] = 0;
  1532. char* b = stringtooutput[0];
  1533. int linenum = 0;
  1534. while ( *a ) {
  1535. if (*a == '\n') {
  1536. *b = 0;
  1537. linenum++;
  1538. stringtooutput[linenum] = new char[200];
  1539. b = stringtooutput[linenum];
  1540. *b = 0;
  1541. } else {
  1542. *b = *a;
  1543. b++;
  1544. }
  1545. a++;
  1546. }
  1547. *b = 0;
  1548. bool displayInternally = true;
  1549. /*
  1550. if ( num == 2 )
  1551. displayLogMessage ( 0, "fatal error" + text + "\n" );
  1552. else
  1553. displayLogMessage ( 0, text + "\n" );
  1554. */
  1555. #ifndef NoStdio
  1556. if ( num == 2 )
  1557. displayInternally = false;
  1558. #endif
  1559. if ( num == 2 )
  1560. displayLogMessage(1, text );
  1561. if ( !displayInternally ) {
  1562. for ( int i=0; i<= linenum ;i++ )
  1563. fprintf(stderr,"%s\n",stringtooutput[i]);
  1564. fflush( stderr );
  1565. } else {
  1566. #ifdef _WIN322_
  1567. if ( !gameStartupComplete && num==2 ) {
  1568. MessageBox(NULL, text.c_str(), "Fatal Error", MB_ICONERROR | MB_OK | MB_TASKMODAL );
  1569. exit(1);
  1570. }
  1571. #endif
  1572. if ( legacyEventSystemActive() ) {
  1573. static int messageboxopen = 0;
  1574. if ( messageboxopen )
  1575. return;
  1576. messageboxopen++;
  1577. if ( messagebox ) {
  1578. if ( messagebox->boxstatus )
  1579. messagebox->done();
  1580. delete messagebox;
  1581. messagebox = NULL;
  1582. }
  1583. messagebox = new tdisplaymessage;
  1584. if ( num== 2 )
  1585. messagebox->init( stringtooutput, num, linenum, "~q~uit program");
  1586. else
  1587. messagebox->init( stringtooutput, num, linenum);
  1588. if (num != 0 ) {
  1589. messagebox->run();
  1590. messagebox->done();
  1591. delete messagebox;
  1592. messagebox = NULL;
  1593. }
  1594. messageboxopen--;
  1595. } else {
  1596. MessagingHub::Instance().warning( text );
  1597. }
  1598. } /* endif */
  1599. if ( num == 2 ) {
  1600. #ifdef _WIN32_
  1601. // if ( !gameStartupComplete ) {
  1602. MessageBox(NULL, text.c_str(), "Fatal Error", MB_ICONERROR | MB_OK | MB_TASKMODAL );
  1603. exit(1);
  1604. // }
  1605. #endif
  1606. exit ( 1 );
  1607. }
  1608. for ( int i=linenum; i>=0 ;i-- )
  1609. delete[] stringtooutput[i];
  1610. }
  1611. void removemessage( void )
  1612. {
  1613. if ( messagebox ) {
  1614. if ( messagebox->boxstatus == 2)
  1615. messagebox->done();
  1616. delete messagebox;
  1617. messagebox = NULL;
  1618. }
  1619. }
  1620. void tdialogbox::dispeditstring ( char* st, int x1, int y1 )
  1621. {
  1622. showtext2(st,x1,y1);
  1623. }
  1624. void tdialogbox::stredit(char * s,
  1625. int x1,
  1626. int y1,
  1627. int wdth,
  1628. int max)
  1629. {
  1630. char *ss, *ss2, *ss3;
  1631. char einfuegen;
  1632. int position;
  1633. int i;
  1634. if ( strlen ( s ) > max )
  1635. max = strlen ( s );
  1636. activefontsettings.justify = lefttext;
  1637. ss = new char[max+5];
  1638. ss2 = new char[max+5];
  1639. strcpy(ss,s);
  1640. activefontsettings.length = wdth;
  1641. activefontsettings.height = activefontsettings.font->height;
  1642. {
  1643. collategraphicoperations cgo ( x1, y1, x1 + wdth, y1 + activefontsettings.height );
  1644. dispeditstring ( ss, x1, y1 );
  1645. position = strlen(s);
  1646. einfuegen = true;
  1647. lne(x1,y1,ss,position,einfuegen);
  1648. }
  1649. int cc;
  1650. tkey symkey;
  1651. do {
  1652. if ( keypress() ) {
  1653. getkeysyms ( &symkey, &cc );
  1654. // cc = rp_key();
  1655. } else {
  1656. cc = cto_invvalue;
  1657. symkey = ct_invvalue;
  1658. releasetimeslice();
  1659. }
  1660. if (cc != cto_invvalue ) {
  1661. lne(x1,y1,ss,position,einfuegen);
  1662. #ifdef _DOS_ // I hate this DOS keyboard stuff !!!!!!
  1663. switch (symkey) {
  1664. case cto_einf:
  1665. {
  1666. if (einfuegen == false)
  1667. einfuegen = true;
  1668. else
  1669. einfuegen = false;
  1670. }
  1671. break;
  1672. case cto_left: if (position >= 1)
  1673. position--;
  1674. break;
  1675. case cto_right: if (position < strlen ( ss ) )
  1676. position++;
  1677. break;
  1678. case cto_pos1: position = 0;
  1679. break;
  1680. case cto_ende: position = strlen ( ss ) ;
  1681. break;
  1682. case cto_entf: if ( ss[ position ] != 0 ) {
  1683. for (i=0; i< position ;i++ ) {
  1684. ss2[i] = ss[i];
  1685. } /* endfor */
  1686. while ( ss[i] != 0 ) {
  1687. ss2[i] = ss [ i + 1 ];
  1688. i++;
  1689. } /* endwhile */
  1690. ss3 = ss2;
  1691. ss2 = ss;
  1692. ss = ss3;
  1693. dispeditstring (ss,x1,y1); /* ? */
  1694. }
  1695. break;
  1696. case cto_right + cto_stp: if ( position < strlen ( ss ) ) {
  1697. do {
  1698. position++;
  1699. } while ( (ss[ position ] != ' ') && ( ss[ position ] != 0 ) );
  1700. }
  1701. break;
  1702. case cto_left + cto_stp: if ( position > 0 ) {
  1703. do {
  1704. position--;
  1705. } while ( ( position > 0 ) && ( ss [ position - 1 ] != ' ') );
  1706. }
  1707. break;
  1708. }
  1709. #else
  1710. switch (symkey) {
  1711. case ct_einf:
  1712. {
  1713. if (einfuegen == false)
  1714. einfuegen = true;
  1715. else
  1716. einfuegen = false;
  1717. }
  1718. break;
  1719. case ct_left: if (position >= 1)
  1720. position--;
  1721. break;
  1722. case ct_right: if (position < strlen ( ss ) )
  1723. position++;
  1724. break;
  1725. case ct_pos1: position = 0;
  1726. break;
  1727. case ct_ende: position = strlen ( ss ) ;
  1728. break;
  1729. case ct_entf: if ( ss[ position ] != 0 ) {
  1730. for (i=0; i< position ;i++ ) {
  1731. ss2[i] = ss[i];
  1732. } /* endfor */
  1733. while ( ss[i] != 0 ) {
  1734. ss2[i] = ss [ i + 1 ];
  1735. i++;
  1736. } /* endwhile */
  1737. ss3 = ss2;
  1738. ss2 = ss;
  1739. ss = ss3;
  1740. dispeditstring (ss,x1,y1); /* ? */
  1741. }
  1742. break;
  1743. case ct_right + ct_stp: if ( position < strlen ( ss ) ) {
  1744. do {
  1745. position++;
  1746. } while ( (ss[ position ] != ' ') && ( ss[ position ] != 0 ) );
  1747. }
  1748. break;
  1749. case ct_left + ct_stp: if ( position > 0 ) {
  1750. do {
  1751. position--;
  1752. } while ( ( position > 0 ) && ( ss [ position - 1 ] != ' ') );
  1753. }
  1754. break;
  1755. }
  1756. #endif
  1757. lne(x1,y1,ss,position,einfuegen);
  1758. if ( ( cc > 31 ) && ( cc < 256 ) && (strlen(ss) < max ) ) { // plain ascii
  1759. i=0;
  1760. while ( (ss[i] != 0) && ( i < position ) ) {
  1761. ss2[i] = ss[i];
  1762. i++;
  1763. }
  1764. ss2 [ i ] = cc;
  1765. if (einfuegen) {
  1766. while ( ss[i] != 0) {
  1767. ss2[i+1] = ss[i];
  1768. i++;
  1769. } /* endwhile */
  1770. ss2[i+1] = 0;
  1771. } else {
  1772. if (ss[i] != 0) {
  1773. i++;
  1774. while ( ss[i] != 0) {
  1775. ss2[i+1] = ss[i];
  1776. i++;
  1777. } /* endwhile */
  1778. ss2[i] = 0;
  1779. } else {
  1780. ss2[i+1] = 0;
  1781. }
  1782. } /* endif */
  1783. if (gettextwdth_stredit( ss2, NULL ) < wdth ) {
  1784. collategraphicoperations cgo ( x1, y1, x1 + wdth, y1 + activefontsettings.height );
  1785. lne(x1,y1,ss,position,einfuegen);
  1786. ss3 = ss2;
  1787. ss2 = ss;
  1788. ss = ss3;
  1789. dispeditstring (ss,x1,y1);
  1790. position++;
  1791. lne(x1,y1,ss,position,einfuegen);
  1792. } /* endif */
  1793. }
  1794. if ((cc == cto_bspace ) && (position > 0)) { /* Backspace */
  1795. collategraphicoperations cgo ( x1, y1, x1 + wdth, y1 + activefontsettings.height );
  1796. lne(x1,y1,ss,position,einfuegen);
  1797. for (i=0; i+1< position ; i++ ) {
  1798. ss2[i] = ss[i];
  1799. } /* endfor */
  1800. i--;
  1801. do {
  1802. i++;
  1803. ss2[i] = ss[i+1];
  1804. } while (ss[i+1] != 0 );
  1805. ss3 = ss2;
  1806. ss2 = ss;
  1807. ss = ss3;
  1808. position--;
  1809. dispeditstring (ss,x1,y1);
  1810. lne(x1,y1,ss,position,einfuegen);
  1811. }
  1812. }
  1813. } while ( cc != cto_enter && cc != cto_esc && !( !mouseinrect ( x1, y1, x1 + wdth, y1 + activefontsettings.height) && mouseparams.taste > 0 ) );
  1814. lne(x1,y1,ss,position,einfuegen);
  1815. if (cc != cto_esc )
  1816. strcpy(s,ss);
  1817. delete[] ss;
  1818. delete[] ss2;
  1819. }
  1820. int tdialogbox::gettextwdth_stredit ( char* txt, pfont font )
  1821. {
  1822. return gettextwdth ( txt, font );
  1823. }
  1824. void tdialogbox::lne(int x1,
  1825. int y1,
  1826. char * s,
  1827. int position,
  1828. char einfuegen)
  1829. {
  1830. int i, j, k;
  1831. ASCString ss2 = s;
  1832. if ( position < ss2.length() )
  1833. ss2.erase(position);
  1834. i = x1 + gettextwdth(ss2.c_str(),activefontsettings.font);
  1835. j = y1;
  1836. k = y1 + activefontsettings.font->height;
  1837. collategraphicoperations cgo ( i-1, j, i+1, k );
  1838. xorline(i,j,i,k,3);
  1839. if (einfuegen == false) {
  1840. xorline(i + 1,j,i + 1,k,3);
  1841. xorline(i - 1,j,i - 1,k,3);
  1842. }
  1843. }
  1844. void tdialogbox::intedit(int * st,
  1845. int x1,
  1846. int y1,
  1847. int wdth,
  1848. int min,
  1849. int max)
  1850. {
  1851. char *ss, *ss2, *ss3;
  1852. char einfuegen;
  1853. int position;
  1854. int j;
  1855. int i;
  1856. int ml;
  1857. char ok;
  1858. ml = 12 ;
  1859. activefontsettings.justify = lefttext;
  1860. ss2 = new char[ml];
  1861. ss = new char[ml];
  1862. itoa ( *st, ss, 10 );
  1863. activefontsettings.height = activefontsettings.font->height;
  1864. dispeditstring (ss,x1,y1);
  1865. position = strlen(ss) ;
  1866. einfuegen = true;
  1867. ok = false;
  1868. int cc;
  1869. tkey symkey;
  1870. do {
  1871. lne(x1,y1,ss,position,einfuegen);
  1872. do {
  1873. if ( keypress() ) {
  1874. getkeysyms ( &symkey, &cc );
  1875. } else {
  1876. cc = cto_invvalue;
  1877. releasetimeslice();
  1878. }
  1879. if (cc != cto_invvalue ) {
  1880. collategraphicoperations cgo ( x1, y1, x1 + wdth, y1 + activefontsettings.height );
  1881. lne(x1,y1,ss,position,einfuegen);
  1882. #ifdef _DOS_
  1883. switch (symkey) {
  1884. case cto_einf: {
  1885. if (einfuegen == false)
  1886. einfuegen = true;
  1887. else
  1888. einfuegen = false;
  1889. }
  1890. break;
  1891. case cto_left: if (position >= 1)
  1892. position--;
  1893. break;
  1894. case cto_right: if (position < strlen ( ss ) )
  1895. position++;
  1896. break;
  1897. case cto_pos1: position = 0;
  1898. break;
  1899. case cto_ende: position = strlen ( ss ) ;
  1900. break;
  1901. case cto_entf: if ( ss[ position ] != 0 ) {
  1902. for (i=0; i< position ;i++ ) {
  1903. ss2[i] = ss[i];
  1904. } /* endfor */
  1905. while ( ss[i] != 0 ) {
  1906. ss2[i] = ss [ i + 1 ];
  1907. i++;
  1908. } /* endwhile */
  1909. ss3 = ss2;
  1910. ss2 = ss;
  1911. ss = ss3;
  1912. dispeditstring (ss,x1,y1); /* ? */
  1913. }
  1914. break;
  1915. case cto_right + cto_stp: if ( position < strlen ( ss ) ) {
  1916. do {
  1917. position++;
  1918. } while ( (ss[ position ] != ' ') && ( ss[ position ] != 0 ) );
  1919. }
  1920. break;
  1921. case cto_left + cto_stp: if ( position > 0 ) {
  1922. do {
  1923. position--;
  1924. } while ( ( position > 0 ) && ( ss [ position - 1 ] != ' ') );
  1925. }
  1926. break;
  1927. }
  1928. #else
  1929. switch (symkey) {
  1930. case ct_einf: {
  1931. if (einfuegen == false)
  1932. einfuegen = true;
  1933. else
  1934. einfuegen = false;
  1935. }
  1936. break;
  1937. case ct_left: if (position >= 1)
  1938. position--;
  1939. break;
  1940. case ct_right: if (position < strlen ( ss ) )
  1941. position++;
  1942. break;
  1943. case ct_pos1: position = 0;
  1944. break;
  1945. case ct_ende: position = strlen ( ss ) ;
  1946. break;
  1947. case ct_entf: if ( ss[ position ] != 0 ) {
  1948. for (i=0; i< position ;i++ ) {
  1949. ss2[i] = ss[i];
  1950. } /* endfor */
  1951. while ( ss[i] != 0 ) {
  1952. ss2[i] = ss [ i + 1 ];
  1953. i++;
  1954. } /* endwhile */
  1955. ss3 = ss2;
  1956. ss2 = ss;
  1957. ss = ss3;
  1958. dispeditstring (ss,x1,y1); /* ? */
  1959. }
  1960. break;
  1961. case ct_right + ct_stp: if ( position < strlen ( ss ) ) {
  1962. do {
  1963. position++;
  1964. } while ( (ss[ position ] != ' ') && ( ss[ position ] != 0 ) );
  1965. }
  1966. break;
  1967. case ct_left + ct_stp: if ( position > 0 ) {
  1968. do {
  1969. position--;
  1970. } while ( ( position > 0 ) && ( ss [ position - 1 ] != ' ') );
  1971. }
  1972. break;
  1973. }
  1974. #endif
  1975. if ( (( cc >= '0' && cc <= '9' ) || ( cc == '-' && !position)) && (strlen(ss) < ml-1 ) ) {
  1976. i=0;
  1977. while ( (ss[i] != 0) && ( i < position ) ) {
  1978. ss2[i] = ss[i];
  1979. i++;
  1980. }
  1981. ss2 [ i ] = cc;
  1982. if (einfuegen) {
  1983. while ( ss[i] != 0) {
  1984. ss2[i+1] = ss[i];
  1985. i++;
  1986. } /* endwhile */
  1987. ss2[i+1] = 0;
  1988. } else {
  1989. if (ss[i] != 0) {
  1990. i++;
  1991. while ( ss[i] != 0) {
  1992. ss2[i+1] = ss[i];
  1993. i++;
  1994. } /* endwhile */
  1995. } /* endif */
  1996. ss2[i] = 0;
  1997. } /* endif */
  1998. if (gettextwdth( ss2, NULL ) < wdth ) {
  1999. ss3 = ss2;
  2000. ss2 = ss;
  2001. ss = ss3;
  2002. dispeditstring (ss,x1,y1);
  2003. position++;
  2004. } /* endif */
  2005. }
  2006. if ((cc == 8 ) && (position > 0)) { /* Backspace */
  2007. for (i=0; i+1< position ; i++ )
  2008. ss2[i] = ss[i];
  2009. i--;
  2010. do {
  2011. i++;
  2012. ss2[i] = ss[i+1];
  2013. } while (ss[i+1] != 0 );
  2014. ss3 = ss2;
  2015. ss2 = ss;
  2016. ss = ss3;
  2017. position--;
  2018. dispeditstring (ss,x1,y1);
  2019. }
  2020. lne(x1,y1,ss,position,einfuegen);
  2021. }
  2022. } while ( (cc != cto_enter) && (cc != cto_esc) && !( !mouseinrect ( x1, y1, x1 + wdth, y1 + activefontsettings.height) && mouseparams.taste > 0 ) );
  2023. lne(x1,y1,ss,position,einfuegen);
  2024. if (cc != cto_esc ) {
  2025. j = strtol ( ss, &ss3, 10 );
  2026. if ((ss3 != NULL) && ( (ss3 - ss ) < strlen ( ss ) )) {
  2027. position = (ss3 - ss );
  2028. lne(x1,y1,ss,position,einfuegen);
  2029. ok = false;
  2030. } else {
  2031. if ( j > max || j < min ) {
  2032. ok = false;
  2033. displaymessage( "Invalid range ! \n range is %d to %d !", 1, min, max );
  2034. } else {
  2035. *st = j;
  2036. ok = true;
  2037. }
  2038. } /* endif */
  2039. } else
  2040. ok = true;
  2041. } while ( ! ok );
  2042. delete[] ss;
  2043. delete[] ss2;
  2044. }
  2045. void tdialogbox::paintsurface2 ( int xx1, int yy1, int xx2, int yy2 )
  2046. {
  2047. if ( dialogtexture )
  2048. puttexture( xx1, yy1, xx2, yy2, dialogtexture);
  2049. else
  2050. bar( xx1, yy1, xx2, yy2, lightgray);
  2051. }
  2052. void tdialogbox::paintsurface ( int xx1, int yy1, int xx2, int yy2 )
  2053. {
  2054. paintsurface2( xx1 + x1, yy1 + y1, xx2 + x1, yy2 + y1 );
  2055. }
  2056. tdialogbox::~tdialogbox()
  2057. {
  2058. if ( pcgo ) {
  2059. delete pcgo;
  2060. pcgo = NULL;
  2061. }
  2062. if ( boxstatus )
  2063. done();
  2064. boxstatus = 0;
  2065. if ( prev ) {
  2066. prev->next = NULL;
  2067. if ( dlg_mode & 2 )
  2068. prev->redrawall2( x1, y1, x1 + xsize, y1 + ysize );
  2069. } else {
  2070. first = NULL;
  2071. repaintDisplay();
  2072. }
  2073. npop ( activefontsettings );
  2074. setEventRouting ( eventQueue, !eventQueue );
  2075. }
  2076. void tviewtext::setnewlineheight ( int h )
  2077. {
  2078. activefontsettings.height = h;
  2079. if (tvt_maxlineheight > activefontsettings.font->height + 5)
  2080. activefontsettings.height = tvt_maxlineheight;
  2081. else {
  2082. if ( tvt_dispactive )
  2083. if ( tvt_yp + activefontsettings.height > tvt_starty ) {
  2084. int tvtny1 = tvt_y1 + tvt_yp - tvt_starty + tvt_maxlineheight;
  2085. int tvtny2 = tvt_y1 + tvt_yp - tvt_starty + activefontsettings.height;
  2086. int tvtnx1 = tvt_x1;
  2087. int tvtnx2 = tvt_x1 + tvt_xp;
  2088. if (tvtny1 < tvt_y1) {
  2089. tvtny1 = tvt_y1;
  2090. tvtnx1 = tvt_x1;
  2091. }
  2092. if (tvtny2 > tvt_y2)
  2093. tvtny2 = tvt_y2;
  2094. if (tvtnx2 > tvtnx1)
  2095. if (tvtny2 > tvtny1)
  2096. bar ( tvtnx1, tvtny1, tvtnx2, tvtny2, tvt_background);
  2097. };
  2098. tvt_maxlineheight = activefontsettings.height ;
  2099. }
  2100. }
  2101. void tviewtext::fillline ( int x1, int x2 )
  2102. {
  2103. if ( tvt_dispactive )
  2104. if ( tvt_yp + activefontsettings.height > tvt_starty ) {
  2105. int tvtny1 = tvt_y1 + tvt_yp - tvt_starty;
  2106. int tvtny2 = tvt_y1 + tvt_yp - tvt_starty + tvt_maxlineheight;
  2107. if (tvtny1 < tvt_y1) {
  2108. tvtny1 = tvt_y1;
  2109. // x1 = tvt_x1;
  2110. }
  2111. if (tvtny2 > tvt_y2)
  2112. tvtny2 = tvt_y2;
  2113. if (x2 > x1)
  2114. if (tvtny2 > tvtny1)
  2115. bar ( x1, tvtny1, x2, tvtny2, tvt_background);
  2116. }
  2117. }
  2118. void tviewtext::nextline ( int einzug, const char* txtptr )
  2119. {
  2120. if ( tvt_dispactive == 0 && txtptr ) {
  2121. if ( ( tvt_startpoint == NULL && (tvt_yp > 500) ) || ( tvt_startpoint && ( tvt_yp > (tvt_startpoint->ypos+500) ))) {
  2122. pstartpoint newstartpoint = new ( tstartpoint );
  2123. newstartpoint->ypos = tvt_yp;
  2124. newstartpoint->xpos = tvt_xp;
  2125. newstartpoint->textcolor = tvt_color;
  2126. newstartpoint->background = tvt_background;
  2127. newstartpoint->font = activefontsettings.font;
  2128. newstartpoint->eeinzug = eeinzug;
  2129. newstartpoint->aeinzug = aeinzug;
  2130. newstartpoint->height = activefontsettings.height;
  2131. newstartpoint->next = tvt_startpoint;
  2132. newstartpoint->textpointer = txtptr ;
  2133. newstartpoint->maxlineheight = tvt_maxlineheight ;
  2134. tvt_startpoint = newstartpoint;
  2135. }
  2136. }
  2137. fillline ( tvt_x1 + tvt_xp, tvt_x2 );
  2138. tvt_yp += activefontsettings.height;
  2139. tvt_xp = einzug;
  2140. fillline ( tvt_x1, tvt_x1 + tvt_xp );
  2141. *actline = 0;
  2142. activefontsettings.height = tvt_maxlineheight = activefontsettings.font->height + 5;
  2143. }
  2144. void tviewtext::displaysingleline ( char* t)
  2145. {
  2146. int twdth = gettextwdth ( t , NULL );
  2147. if ( tvt_dispactive ) {
  2148. if ( tvt_yp >= tvt_starty ) {
  2149. if ( tvt_yp < tvt_starty + tvt_y2 - tvt_y1) {
  2150. if ( tvt_yp + activefontsettings.height + 1 > tvt_starty + tvt_y2 - tvt_y1)
  2151. activefontsettings.height = tvt_y2 - tvt_yp + tvt_starty - tvt_y1 + 1;
  2152. if (tvt_x1 + tvt_xp + twdth > tvt_x2)
  2153. twdth = activefontsettings.length = tvt_x2 - tvt_x1 - tvt_xp;
  2154. else
  2155. activefontsettings.length = 0;
  2156. showtext2( t, tvt_x1 + tvt_xp, tvt_y1 + tvt_yp - tvt_starty );
  2157. }
  2158. } else
  2159. if ( t[0] )
  2160. if ( tvt_yp + activefontsettings.height > tvt_starty ) {
  2161. npush ( *agmp );
  2162. *agmp = tvt_firstlinebufparm;
  2163. if ( activefontsettings.height > tvt_firstlinebufheight )
  2164. activefontsettings.height = tvt_firstlinebufheight;
  2165. if (tvt_x1 + tvt_xp + twdth > tvt_x2)
  2166. twdth = activefontsettings.length = tvt_x2 - tvt_x1 - tvt_xp;
  2167. else
  2168. activefontsettings.length = 0;
  2169. showtext2( t, tvt_xp, 0 );
  2170. npop ( *agmp );
  2171. putimageprt ( tvt_x1 + tvt_xp, tvt_y1, tvt_x1 + tvt_xp + twdth, tvt_y1 + activefontsettings.height + ( tvt_yp - tvt_starty ), tvt_firstlinebuf, tvt_xp, tvt_starty - tvt_yp );
  2172. }
  2173. }
  2174. tvt_xp += twdth ;
  2175. }
  2176. void tviewtext::setpos ( int xx1, int yy1, int xx2, int yy2 )
  2177. {
  2178. tvt_x1 = xx1;
  2179. tvt_y1 = yy1;
  2180. tvt_x2 = xx2;
  2181. tvt_y2 = yy2;
  2182. }
  2183. void tviewtext::setparams ( int xx1, int yy1, int xx2, int yy2, const char* ttxt, char clr, char bkgr)
  2184. {
  2185. tvt_x1 = xx1;
  2186. tvt_y1 = yy1;
  2187. tvt_x2 = xx2;
  2188. tvt_y2 = yy2;
  2189. tvt_text = ttxt;
  2190. tvt_color = clr;
  2191. defaulttextcolor = clr;
  2192. tvt_background = bkgr;
  2193. tvt_maxlineheight = activefontsettings.font->height + 5;
  2194. eeinzug = 0;
  2195. aeinzug = 0;
  2196. tvt_dispactive = 0;
  2197. tvt_starty = 0;
  2198. tvt_firstlinebufheight = 35;
  2199. tvt_firstlinebufparm.resolutionx = xx2 - xx1 + 1;
  2200. tvt_firstlinebufparm.resolutiony = tvt_firstlinebufheight;
  2201. tvt_firstlinebufparm.windowstatus = 100;
  2202. tvt_firstlinebufparm.scanlinelength = xx2 - xx1 + 1;
  2203. tvt_firstlinebufparm.scanlinenumber = tvt_firstlinebufheight;
  2204. tvt_firstlinebufparm.bytesperscanline = xx2 - xx1 + 1;
  2205. tvt_firstlinebufparm.byteperpix = 1;
  2206. tvt_startpoint = NULL;
  2207. }
  2208. void tviewtext::displaytext ( void )
  2209. {
  2210. auto_ptr<collategraphicoperations> cgo;
  2211. if ( tvt_dispactive )
  2212. cgo.reset( new collategraphicoperations ( tvt_x1, tvt_y1, tvt_x2, tvt_y2 ) );
  2213. tvt_color = defaulttextcolor;
  2214. tvt_maxlineheight = activefontsettings.font->height + 5;
  2215. eeinzug = 0;
  2216. aeinzug = 0;
  2217. char *actword, *s5;
  2218. const char* s1;
  2219. int i;
  2220. tvt_xp = 0;
  2221. tvt_yp = 0;
  2222. npush ( activefontsettings );
  2223. actline = new char[200];
  2224. actword = new char[200];
  2225. s5 = new char[200];
  2226. {
  2227. tvt_firstlinebuf = new char [ ( tvt_x2 - tvt_x1) * ( tvt_firstlinebufheight + 5 ) ];
  2228. memset ( tvt_firstlinebuf , tvt_background, (tvt_x2 - tvt_x1) * ( tvt_firstlinebufheight + 5 ) );
  2229. Uint16* pw = (Uint16*) tvt_firstlinebuf;
  2230. *pw = (tvt_x2 - tvt_x1);
  2231. pw++;
  2232. *pw = tvt_firstlinebufheight;
  2233. pw++;
  2234. tvt_firstlinebufparm.linearaddress = (PointerSizedInt) pw;
  2235. }
  2236. s1 = tvt_text;
  2237. activefontsettings.background = tvt_background;
  2238. activefontsettings.color = tvt_color;
  2239. activefontsettings.font = schriften.smallarial;
  2240. activefontsettings.justify = lefttext;
  2241. activefontsettings.height = activefontsettings.font->height + 5;
  2242. if (tvt_dispactive) {
  2243. if ( tvt_startpoint ) {
  2244. pstartpoint startpoint = tvt_startpoint;
  2245. while ( startpoint && ( startpoint->ypos+100 > tvt_starty ) )
  2246. startpoint = startpoint->next;
  2247. if ( startpoint ) {
  2248. tvt_color = startpoint->textcolor;
  2249. tvt_background = startpoint->background ;
  2250. activefontsettings.font = startpoint->font ;
  2251. eeinzug = startpoint->eeinzug ;
  2252. aeinzug = startpoint->aeinzug ;
  2253. tvt_xp = startpoint->xpos;
  2254. tvt_yp = startpoint->ypos;
  2255. tvt_maxlineheight = startpoint->maxlineheight;
  2256. activefontsettings.height = startpoint->height ;
  2257. s1 = startpoint->textpointer ;
  2258. }
  2259. }
  2260. }
  2261. if ( tvt_text ) {
  2262. *actline = 0;
  2263. *actword = 0;
  2264. do {
  2265. i = 0;
  2266. while (*s1 != '#' && *s1 != 0 && *s1 != '\n' && *s1 != ' ' && *s1 != '-') {
  2267. actword[i] = *s1;
  2268. i++;
  2269. s1++;
  2270. } /* endwhile */
  2271. if ( *s1 == ' ' || *s1 == '-' ) {
  2272. actword[i] = *s1;
  2273. i++;
  2274. s1++;
  2275. }
  2276. actword[i] = 0;
  2277. strcpy ( s5, actline );
  2278. strcat ( s5, actword );
  2279. if ( tvt_xp + gettextwdth ( s5, NULL ) < tvt_x2 - tvt_x1 )
  2280. strcat ( actline, actword );
  2281. else {
  2282. displaysingleline ( actline );
  2283. nextline ( aeinzug, s1 );
  2284. activefontsettings.length = 0;
  2285. strcpy ( actline, actword );
  2286. }
  2287. if (*s1 == '\n') {
  2288. displaysingleline ( actline );
  2289. nextline ( eeinzug, s1 );
  2290. s1++;
  2291. }
  2292. if (*s1 == 0) {
  2293. displaysingleline ( actline );
  2294. nextline ( 0, s1 );
  2295. }
  2296. if (*s1 == '#') {
  2297. displaysingleline ( actline );
  2298. *actline = 0;
  2299. evalcommand ( &s1 );
  2300. }
  2301. } while ((*s1 != 0) && ((tvt_yp - tvt_starty < tvt_y2 - tvt_y1) || !tvt_dispactive ));
  2302. if ( tvt_dispactive )
  2303. if (tvt_yp - tvt_starty < tvt_y2 - tvt_y1)
  2304. bar ( tvt_x1, tvt_yp + tvt_y1 - tvt_starty, tvt_x2, tvt_y2, tvt_background);
  2305. }
  2306. delete[] s5;
  2307. delete[] actword;
  2308. delete[] actline;
  2309. delete[] tvt_firstlinebuf;
  2310. npop ( activefontsettings );
  2311. }
  2312. void tviewtext::evalcommand ( const char** s)
  2313. {
  2314. const char* s3 = *s;
  2315. char s4[100];
  2316. int k, i = 0,
  2317. j = 0;
  2318. memset( s4, 0, sizeof( s4 ));
  2319. if (strnicmp(s3, "#COLOR", 6) == 0) {
  2320. i+=6;
  2321. while (s3[i] != '#') {
  2322. s4[j] = s3[i];
  2323. j++;
  2324. i++;
  2325. }
  2326. s4[j] = 0;
  2327. k = atoi( s4 );
  2328. if (k == 256)
  2329. activefontsettings.color = tvt_color;
  2330. else
  2331. activefontsettings.color = k;
  2332. }
  2333. if (strnicmp(s3, "#BACKGROUND", 11) == 0) {
  2334. i+=11;
  2335. while (s3[i] != '#') {
  2336. s4[j] = s3[i];
  2337. j++;
  2338. i++;
  2339. }
  2340. s4[j] = 0;
  2341. k = atoi( s4 );
  2342. if (k == 256)
  2343. activefontsettings.background = tvt_background;
  2344. else
  2345. activefontsettings.background = k;
  2346. }
  2347. if (strnicmp(s3, "#FONT", 5) == 0) {
  2348. i+=5;
  2349. while (s3[i] != '#') {
  2350. s4[j] = s3[i];
  2351. j++;
  2352. i++;
  2353. }
  2354. s4[j] = 0;
  2355. k = atoi ( s4 );
  2356. switch (k) {
  2357. case 1: activefontsettings.font = schriften.smallarial;
  2358. break;
  2359. case 2: activefontsettings.font = schriften.arial8;
  2360. break;
  2361. default: activefontsettings.font = schriften.smallarial;
  2362. break;
  2363. } /* endswitch */
  2364. setnewlineheight ( activefontsettings.font->height + 5 );
  2365. }
  2366. if (strnicmp(s3, "#TAB", 4) == 0) {
  2367. i+=4;
  2368. while (s3[i] != '#') {
  2369. s4[j] = s3[i];
  2370. j++;
  2371. i++;
  2372. }
  2373. s4[j] = 0;
  2374. k = atoi ( s4 );
  2375. int tvtxp = 0;
  2376. if (k)
  2377. tvtxp = (tvt_xp / k + 1) * k;
  2378. fillline ( tvt_x1 + tvt_xp, tvt_x1 + tvtxp );
  2379. tvt_xp = tvtxp;
  2380. }
  2381. if (strnicmp(s3, "#POS", 4) == 0) {
  2382. i+=4;
  2383. while (s3[i] != '#') {
  2384. s4[j] = s3[i];
  2385. j++;
  2386. i++;
  2387. }
  2388. s4[j] = 0;
  2389. k = atoi ( s4 );
  2390. fillline ( tvt_x1 + tvt_xp, tvt_x1 + k );
  2391. tvt_xp = k;
  2392. }
  2393. if (strnicmp(s3, "#EEINZUG", 8) == 0) {
  2394. i+=8;
  2395. while (s3[i] != '#') {
  2396. s4[j] = s3[i];
  2397. j++;
  2398. i++;
  2399. }
  2400. s4[j] = 0;
  2401. eeinzug = atoi ( s4 );
  2402. }
  2403. if (strnicmp(s3, "#AEINZUG", 8) == 0) {
  2404. i+=8;
  2405. while (s3[i] != '#') {
  2406. s4[j] = s3[i];
  2407. j++;
  2408. i++;
  2409. }
  2410. s4[j] = 0;
  2411. aeinzug = atoi ( s4 );
  2412. }
  2413. if (strnicmp(s3, "#CRT#", 5) == 0) {
  2414. nextline ( eeinzug, NULL );
  2415. i=4;
  2416. }
  2417. if (strnicmp(s3, "#CRTP", 5) == 0) {
  2418. i+=5;
  2419. while (s3[i] != '#') {
  2420. s4[j] = s3[i];
  2421. j++;
  2422. i++;
  2423. }
  2424. s4[j] = 0;
  2425. if ( s3[i+1] == '\n' )
  2426. i++;
  2427. k = atoi ( s4 );
  2428. setnewlineheight ( activefontsettings.height + k );
  2429. nextline ( eeinzug, NULL );
  2430. }
  2431. (*s)+=i+1;
  2432. }
  2433. tviewtext::tviewtext()
  2434. {
  2435. tvt_startpoint = NULL;
  2436. }
  2437. tviewtext::~tviewtext()
  2438. {
  2439. while ( tvt_startpoint ) {
  2440. pstartpoint startpoint = tvt_startpoint;
  2441. tvt_startpoint = tvt_startpoint->next;
  2442. delete startpoint;
  2443. }
  2444. }
  2445. void tviewtextwithscrolling::checkscrolling ( void )
  2446. {
  2447. int pagepressed_scrollspeedmultiplicator = 8;
  2448. int tick = ticker;
  2449. while ( (skeypress ( ct_down ) || skeypress ( ct_2k )) && (tvt_starty + textsizey < textsizeycomplete)) {
  2450. tvt_starty += ticker - tick;
  2451. tick = ticker;
  2452. if ( tvt_starty + textsizey > textsizeycomplete )
  2453. tvt_starty = textsizeycomplete - textsizey;
  2454. displaytext();
  2455. repaintscrollbar();
  2456. }
  2457. tick = ticker;
  2458. while ( (skeypress ( ct_up ) || skeypress ( ct_8k )) && (tvt_starty > 0) ) {
  2459. tvt_starty -= ticker - tick;
  2460. tick = ticker;
  2461. if ( tvt_starty < 0 )
  2462. tvt_starty = 0;
  2463. displaytext();
  2464. repaintscrollbar();
  2465. }
  2466. if ( (skeypress ( ct_pos1 ) || skeypress ( ct_7k )) && (tvt_starty > 0)) {
  2467. tvt_starty = 0;
  2468. displaytext();
  2469. repaintscrollbar();
  2470. }
  2471. if ( (skeypress ( ct_ende ) || skeypress ( ct_1k )) && (tvt_starty < textsizeycomplete - textsizey )) {
  2472. tvt_starty = textsizeycomplete - textsizey;
  2473. displaytext();
  2474. repaintscrollbar();
  2475. }
  2476. tick = ticker;
  2477. while ( (skeypress ( ct_pdown ) || skeypress ( ct_3k )) && (tvt_starty + textsizey < textsizeycomplete)) {
  2478. tvt_starty += (ticker - tick) * pagepressed_scrollspeedmultiplicator;
  2479. tick = ticker;
  2480. if ( tvt_starty + textsizey > textsizeycomplete )
  2481. tvt_starty = textsizeycomplete - textsizey;
  2482. displaytext();
  2483. repaintscrollbar();
  2484. }
  2485. tick = ticker;
  2486. while ( (skeypress ( ct_pup ) || skeypress ( ct_9k )) && (tvt_starty > 0) ) {
  2487. tvt_starty -= (ticker - tick) * pagepressed_scrollspeedmultiplicator;
  2488. tick = ticker;
  2489. if ( tvt_starty < 0 )
  2490. tvt_starty = 0;
  2491. displaytext();
  2492. repaintscrollbar();
  2493. }
  2494. }
  2495. ASCString readtextmessage( int id )
  2496. {
  2497. char s1[10];
  2498. sprintf ( s1, "##%4d", id );
  2499. {
  2500. char* b = s1;
  2501. while ( *b ) {
  2502. if ( *b == ' ' )
  2503. *b = '0';
  2504. b++;
  2505. }
  2506. }
  2507. ASCString txt;
  2508. int wldcrdnum = 3;
  2509. ASCString tmpstr;
  2510. if ( actmap )
  2511. tmpstr = actmap->preferredFileNames.mapname[0];
  2512. while ( tmpstr.find ( ".map") != string::npos )
  2513. tmpstr.replace ( tmpstr.find ( ".map"), 4, ".msg" );
  2514. while( tmpstr.find ( ".MAP") != string::npos )
  2515. tmpstr.replace ( tmpstr.find ( ".MAP"), 4, ".msg" );
  2516. displayLogMessage(7, ASCString("Retrieving message ") + strrr(id) + "; looking for message file " + tmpstr + "\n");
  2517. tfindfile ff3 ( tmpstr.c_str() );
  2518. tfindfile ff2 ( "*.msg" );
  2519. tfindfile ff ( "helpsys?.txt" );
  2520. tfindfile* ffa[3] = { &ff3, &ff, &ff2 };
  2521. for ( int m = 0; m < wldcrdnum; m++ ) {
  2522. tfindfile* pff = ffa[m];
  2523. ASCString filefound = pff->getnextname();
  2524. while( !filefound.empty() ) {
  2525. tnfilestream stream ( filefound.c_str(), tnstream::reading );
  2526. ASCString tempstr;
  2527. bool data = stream.readTextString ( tempstr );
  2528. int started = 0;
  2529. while ( data ) {
  2530. if ( started ) {
  2531. if ( tempstr[0] != ';' ) {
  2532. if ( tempstr[0] == '#' && tempstr[1] == '#' ) {
  2533. started = 0;
  2534. return txt;
  2535. } else
  2536. txt += tempstr + "\n";
  2537. }
  2538. } else
  2539. if ( tempstr == s1 )
  2540. started = 1;
  2541. data = stream.readTextString ( tempstr );
  2542. } /* endwhile */
  2543. if ( started ) {
  2544. started = 0;
  2545. return txt;
  2546. }
  2547. filefound = pff->getnextname();
  2548. } /* endwhile */
  2549. }
  2550. return txt;
  2551. }
  2552. #define ppicture tpicture*
  2553. struct tpicture {
  2554. void* pict;
  2555. int size;
  2556. int width, height;
  2557. int x, y;
  2558. ppicture next;
  2559. char descrip[20];
  2560. };
  2561. class thelpsystem : public tdialogbox, public tviewtextwithscrolling {
  2562. public:
  2563. ASCString txt;
  2564. char ok;
  2565. char scrollbarvisible;
  2566. ppicture firstpict;
  2567. char action;
  2568. int textstart;
  2569. void init( int id, const char* titlet );
  2570. virtual void setup();
  2571. void buildgraphics ( void );
  2572. virtual void run ( void );
  2573. //void viewtext ( void );
  2574. virtual void buttonpressed( int id);
  2575. void repaintscrollbar( void );
  2576. void done ( void );
  2577. };
  2578. void thelpsystem::setup( void )
  2579. {
  2580. addbutton ( "~O~K", 10, ysize - 30, xsize - 10, ysize - 10, 0, 1, 5, 1 );
  2581. addkey ( 5, ct_esc );
  2582. addkey ( 5, ct_space );
  2583. addkey ( 5, ct_enter );
  2584. }
  2585. void thelpsystem::init(int id, const char* titlet )
  2586. {
  2587. // dialogbox initialisieren
  2588. tdialogbox::init();
  2589. x1 = 70;
  2590. y1 = 20;
  2591. xsize = 500;
  2592. ysize = 440;
  2593. textstart = 42;
  2594. textsizey = (ysize - textstart - 40);
  2595. starty = starty + 10;
  2596. title = titlet;
  2597. windowstyle ^= dlg_in3d;
  2598. action=0;
  2599. txt = readtextmessage( id );
  2600. if ( txt.empty() ) {
  2601. txt = "help topic not found : ";
  2602. txt += strrr (id );
  2603. }
  2604. setup();
  2605. // Koordinaten auch bei setpos ndern
  2606. setparams ( x1 + 13, y1 + textstart, x1 + xsize - 41, y1 + ysize - 40, txt.c_str(), black, dblue);
  2607. tvt_dispactive = 0;
  2608. // buildgraphics();
  2609. displaytext( );
  2610. textsizeycomplete = tvt_yp;
  2611. tvt_dispactive = 1;
  2612. if (textsizeycomplete >= textsizey) {
  2613. scrollbarvisible = true;
  2614. addscrollbar(xsize - 30,starty,xsize - 15,ysize - 40,&textsizeycomplete, textsizey, &tvt_starty,1,0);
  2615. setscrollspeed ( 1 , 1 );
  2616. }
  2617. else
  2618. scrollbarvisible = false;
  2619. tvt_starty = 0;
  2620. }
  2621. void thelpsystem::repaintscrollbar( void )
  2622. {
  2623. enablebutton( 1 );
  2624. }
  2625. void thelpsystem::buildgraphics(void)
  2626. {
  2627. tdialogbox::buildgraphics();
  2628. setpos ( x1 + 13, y1 + textstart, x1 + xsize - 41, y1 + ysize - 40 );
  2629. rahmen(true,x1 + 10,y1 + textstart - 2,x1 + xsize - 40,y1 + textstart + textsizey + 2);
  2630. mousevisible(true);
  2631. activefontsettings.font = schriften.smallarial;
  2632. activefontsettings.color = black;
  2633. activefontsettings.justify = lefttext;
  2634. activefontsettings.background = dblue;
  2635. activefontsettings.height = textsizey / linesshown;
  2636. firstpict = NULL;
  2637. }
  2638. void thelpsystem::buttonpressed( int id )
  2639. {
  2640. tdialogbox::buttonpressed(id);
  2641. if (id == 1)
  2642. displaytext();
  2643. if ( id == 5 )
  2644. action = 11;
  2645. }
  2646. void thelpsystem::run(void)
  2647. {
  2648. displaytext();
  2649. do {
  2650. tdialogbox::run();
  2651. checkscrolling();
  2652. } while (action < 10);
  2653. }
  2654. void thelpsystem::done(void)
  2655. {
  2656. ppicture pic1;
  2657. tdialogbox::done();
  2658. while (firstpict != NULL) {
  2659. pic1 = firstpict;
  2660. firstpict = firstpict->next;
  2661. free ( pic1->pict );
  2662. delete ( pic1 );
  2663. }
  2664. }
  2665. void help( int id)
  2666. {
  2667. ASCString s = readtextmessage( id );
  2668. ViewFormattedText vft( "Help System", s, PG_Rect(-1,-1,450,550));
  2669. vft.Show();
  2670. vft.RunModal();
  2671. }
  2672. void viewtext2 ( int id)
  2673. {
  2674. ASCString s = readtextmessage( id );
  2675. ViewFormattedText vft( "Message", s, PG_Rect(-1,-1,450,550));
  2676. vft.Show();
  2677. vft.RunModal();
  2678. }
  2679. class tviewtextquery : public thelpsystem {
  2680. const char* st1;
  2681. const char* st2;
  2682. public:
  2683. void init( int id, const char* titel, const char* s1, const char* s2);
  2684. virtual void buttonpressed( int id);
  2685. void setup( void );
  2686. };
  2687. void tviewtextquery::setup( void )
  2688. {
  2689. if ( st2 ) {
  2690. addbutton ( st1, 10, ysize - 30, xsize / 2 - 5, ysize - 10, 0, 1,11, 1 );
  2691. addbutton ( st2, xsize / 2 + 5, ysize - 30, xsize - 10, ysize - 10, 0, 1,12, 1 );
  2692. }
  2693. else
  2694. addbutton(st1,10, ysize - 30, xsize - 10, ysize - 10, 0, 1, 11, 1 );
  2695. }
  2696. void tviewtextquery::init( int id, const char* titel, const char* s1, const char* s2 )
  2697. {
  2698. st1 = s1;
  2699. st2 = s2;
  2700. thelpsystem::init(id,titel);
  2701. buildgraphics();
  2702. }
  2703. void tviewtextquery::buttonpressed( int id)
  2704. {
  2705. thelpsystem::buttonpressed(id);
  2706. if (id == 12)
  2707. action = 12;
  2708. if (id == 11)
  2709. action = 11;
  2710. }
  2711. int legacy_viewtextquery( int id,
  2712. const char * title,
  2713. const char * s1,
  2714. const char * s2)
  2715. {
  2716. tviewtextquery vtq;
  2717. char result;
  2718. vtq.init(id,title,s1,s2);
  2719. vtq.run();
  2720. result = vtq.action - 11;
  2721. vtq.done();
  2722. return result;
  2723. }
  2724. class ViewTextQuery : public ASC_PG_Dialog {
  2725. public:
  2726. ViewTextQuery( int id, const ASCString& title, const ASCString& button1, const ASCString& button2 ) : ASC_PG_Dialog( NULL, PG_Rect(-1, -1, 450, 500 ), title )
  2727. {
  2728. PG_Rect r;
  2729. if ( button2.length() ) {
  2730. r = PG_Rect( 10, Height() - 40, Width()/2-15, 30 );
  2731. PG_Button* b = new PG_Button( this, PG_Rect( Width()/2+5, Height() - 40, Width()/2-15, 30 ), button2 );
  2732. b->sigClick.connect( SigC::bind( SigC::slot( *this, &ViewTextQuery::quitModalLoop ), 1));
  2733. b->activateHotkey(0);
  2734. } else
  2735. r = PG_Rect( 10, Height() - 40, Width() - 20, 30 );
  2736. PG_Button* b = new PG_Button( this, r, button1 );
  2737. b->sigClick.connect( SigC::bind( SigC::slot( *this, &ViewTextQuery::quitModalLoop ), 0));
  2738. b->activateHotkey(0);
  2739. new TextRenderer( this, PG_Rect( 10, 30, Width()-20, Height() - 70 ), readtextmessage( id ));
  2740. }
  2741. };
  2742. int viewtextquery( int id,
  2743. const char * title,
  2744. const char * s1,
  2745. const char * s2)
  2746. {
  2747. if ( legacyEventSystemActive() )
  2748. return legacy_viewtextquery( id, title, s1, s2 );
  2749. else {
  2750. ViewTextQuery vtq( id, title, s1, s2 );
  2751. vtq.Show();
  2752. return vtq.RunModal();
  2753. }
  2754. }
  2755. tdisplaymessage* messagebox = NULL;
  2756. tstringselect :: tstringselect ( )
  2757. {
  2758. numberoflines = 0;
  2759. firstvisibleline = 0;
  2760. redline = 0;
  2761. startpos = 0;
  2762. }
  2763. void tstringselect::init(void)
  2764. {
  2765. tdialogbox::init();
  2766. xsize = 570;
  2767. ysize = 320;
  2768. x1 = ( 640 -xsize ) / 2;
  2769. y1 = ( 480 -ysize ) / 2;
  2770. sy = 45;
  2771. sx = 20;
  2772. title = "Text-Box";
  2773. windowstyle = windowstyle ^ dlg_in3d;
  2774. lnshown = 10;
  2775. ey = ysize - 50;
  2776. ex = xsize - 30;
  2777. setup();
  2778. if (startpos >= numberoflines ) startpos = numberoflines-1;
  2779. if (startpos > lnshown -1 ) {
  2780. firstvisibleline = startpos - ( lnshown - 1 );
  2781. redline = startpos;
  2782. } else {
  2783. redline = startpos;
  2784. } /* endif */
  2785. dk = 0;
  2786. action = 0;
  2787. dx = (ey - sy) / lnshown;
  2788. if (numberoflines > lnshown) {
  2789. scrollbarvisible = true;
  2790. addscrollbar(ex + 10 ,sy ,ex + 20,ey ,&numberoflines,lnshown,&firstvisibleline,1,0);
  2791. }
  2792. else scrollbarvisible = false;
  2793. buildgraphics();
  2794. rahmen(true,x1 + sx , y1 + sy,x1 + ex,y1 + ey);
  2795. mousevisible(true);
  2796. activefontsettings.font = schriften.smallarial;
  2797. activefontsettings.color = black;
  2798. activefontsettings.justify = lefttext;
  2799. activefontsettings.background = lightgray;
  2800. activefontsettings.height = 15;
  2801. viewtext();
  2802. }
  2803. void tstringselect::setup(void)
  2804. {
  2805. }
  2806. void tstringselect::buttonpressed(int id)
  2807. {
  2808. tdialogbox::buttonpressed(id);
  2809. if (id == 1) {
  2810. if (firstvisibleline > redline) redline = firstvisibleline;
  2811. if (firstvisibleline + lnshown - 1 < redline) redline = firstvisibleline + lnshown - 1;
  2812. viewtext();
  2813. }
  2814. }
  2815. void tstringselect::run(void)
  2816. {
  2817. char view;
  2818. int my;
  2819. int ms;
  2820. tdialogbox::run();
  2821. if (numberoflines > 0) {
  2822. msel = 0;
  2823. if (getmousestatus() == 2) {
  2824. if ((( ms = mouseparams.taste ) == 0) && (dk == 1)) dk = 2;
  2825. if ((mouseparams.x > x1 + 10) & (mouseparams.x < x1 + xsize - 40) && (ms != 0)) {
  2826. my = mouseparams.y - y1 - sy;
  2827. my = my / dx;
  2828. if ((my >= 0) && (my <= lnshown - 1) && (my <= numberoflines - 1)) {
  2829. mouseselect = firstvisibleline + my;
  2830. if ((mouseselect == redline) && (dk == 2)) {
  2831. msel = ms;
  2832. dk = 0;
  2833. }
  2834. else {
  2835. redline = mouseselect;
  2836. dk = 1;
  2837. ms =0;
  2838. viewtext();
  2839. }
  2840. }
  2841. }
  2842. }
  2843. switch (taste) {
  2844. case ct_up: {
  2845. view = true;
  2846. if (redline > 0) redline--;
  2847. else view = false;
  2848. if ((redline < firstvisibleline) && (firstvisibleline > 0)) {
  2849. firstvisibleline--;
  2850. showbutton( 1 );
  2851. }
  2852. if (view) viewtext();
  2853. }
  2854. break;
  2855. case ct_pos1: {
  2856. view = false;
  2857. if ( (redline > 0) || (firstvisibleline > 0) ) {
  2858. view = true;
  2859. redline = 0;
  2860. firstvisibleline = 0;
  2861. }
  2862. if (view) viewtext();
  2863. }
  2864. break;
  2865. case ct_ende: {
  2866. view = false;
  2867. if (redline < numberoflines -1 ) {
  2868. view = true;
  2869. redline = numberoflines -1 ;
  2870. firstvisibleline = numberoflines - lnshown;
  2871. }
  2872. if (view) viewtext();
  2873. }
  2874. break;
  2875. case ct_down: {
  2876. view = true;
  2877. if (redline < numberoflines - 1) redline++;
  2878. else view = false;
  2879. if ((redline > firstvisibleline + lnshown - 1) && (firstvisibleline + lnshown - 1 <= numberoflines)) {
  2880. firstvisibleline++;
  2881. showbutton( 1 );
  2882. }
  2883. if (view) viewtext();
  2884. }
  2885. break;
  2886. }
  2887. }
  2888. else redline = -1;
  2889. }
  2890. void tstringselect::resettextfield(void)
  2891. {
  2892. bar(x1 + sx,y1 + sy,x1 + ex,y1 + ey,lightgray);
  2893. rahmen(true,x1 + sx ,y1 + sy,x1 + ex,y1 + ey);
  2894. }
  2895. void tstringselect::get_text(int nr) //gibt in txt den string zur?ck
  2896. {
  2897. strcpy(txt,"");
  2898. nr = 0;
  2899. }
  2900. void tstringselect::scrollbar_on(void)
  2901. {
  2902. scrollbarvisible = true;
  2903. addscrollbar(ex + 10 ,sy - 10,ex + 30,ey + 10,&numberoflines,lnshown,&firstvisibleline,1,0);
  2904. }
  2905. void tstringselect::viewtext(void)
  2906. {
  2907. char s1[200];
  2908. Uint16 yp;
  2909. int l;
  2910. mousevisible(false);
  2911. //showbutton(1);
  2912. npush(activefontsettings.length);
  2913. activefontsettings.length = ex - sx - 10;
  2914. yp = y1 + sy + 5;
  2915. l = firstvisibleline;
  2916. if (numberoflines > 0) {
  2917. while ((l<numberoflines) && (l-firstvisibleline < lnshown)) {
  2918. get_text(l);
  2919. strcpy(s1,txt);
  2920. if (l == redline ) activefontsettings.color=red;
  2921. else activefontsettings.color=lightblue;
  2922. showtext2(s1,x1+ sx + 5,yp+( l-firstvisibleline ) * dx );
  2923. l++;
  2924. } /* endwhile */
  2925. }
  2926. // else showtext2("No text available !",x1 + 50,yp + 50);
  2927. //rahmen(true,x1 + sx ,y1 + sy,x1 + ex ,y1 + ey );
  2928. npop(activefontsettings.length);
  2929. mousevisible(true);
  2930. }
  2931. void tstringselect::done(void)
  2932. {
  2933. tdialogbox::done();
  2934. while ( mouseparams.taste )
  2935. releasetimeslice();
  2936. }
  2937. class tgetid : public tdialogbox {
  2938. public :
  2939. tgetid () { onCancel = ReturnZero; };
  2940. enum CancelMode { ReturnZero, ReturnOriginal } onCancel;
  2941. int action;
  2942. int mid;
  2943. char nt[200];
  2944. void init(void);
  2945. int max,min;
  2946. virtual void run(void);
  2947. virtual void buttonpressed(int id);
  2948. };
  2949. void tgetid::init(void)
  2950. {
  2951. tdialogbox::init();
  2952. title = nt;
  2953. x1 = 200;
  2954. xsize = 220;
  2955. y1 = 150;
  2956. ysize = 140;
  2957. action = 0;
  2958. if ((mid < min) || (mid > max)) mid = 42; /* ! */
  2959. windowstyle = windowstyle ^ dlg_in3d;
  2960. addbutton("~D~one",20,ysize - 40,100,ysize - 20,0,1,1,true);
  2961. addkey(1,ct_enter);
  2962. addbutton("~C~ancel",120,ysize - 40,200,ysize - 20,0,1,2,true);
  2963. addbutton("",20,60,xsize - 20,80,2,1,3,true);
  2964. addeingabe(3,&mid,min,max);
  2965. buildgraphics();
  2966. mousevisible(true);
  2967. }
  2968. void tgetid::run(void)
  2969. {
  2970. int orig = mid;
  2971. tdialogbox::run ();
  2972. pbutton pb = firstbutton;
  2973. while ( pb && (pb->id != 3))
  2974. pb = pb->next;
  2975. if ( pb )
  2976. if ( pb->id == 3 )
  2977. execbutton( pb , false );
  2978. do {
  2979. tdialogbox::run();
  2980. } while (!((taste == ct_esc) || ((action == 1) || (action == 2))));
  2981. if ((action == 2) || (taste == ct_esc)){
  2982. if ( onCancel == ReturnZero )
  2983. mid = 0;
  2984. else
  2985. mid = orig;
  2986. }
  2987. }
  2988. void tgetid::buttonpressed(int id)
  2989. {
  2990. tdialogbox::buttonpressed(id);
  2991. switch (id) {
  2992. case 1:
  2993. case 2: action = id;
  2994. break;
  2995. }
  2996. }
  2997. int getid( const char* title, int lval,int min,int max)
  2998. { tgetid gi;
  2999. gi.onCancel = tgetid::ReturnOriginal;
  3000. strcpy( gi.nt, title );
  3001. gi.max = max;
  3002. gi.min = min;
  3003. gi.mid = lval;
  3004. gi.init();
  3005. gi.run();
  3006. gi.done();
  3007. return gi.mid;
  3008. }
  3009. class ChooseString : public tstringselect {
  3010. private:
  3011. const vector<ASCString>& strings;
  3012. const vector<ASCString>& buttons;
  3013. char buf[10000];
  3014. public :
  3015. ChooseString ( const ASCString& _title, const vector<ASCString>& _strings , const vector<ASCString>& _buttons, int defaultEntry );
  3016. void setup( );
  3017. virtual void buttonpressed(int id);
  3018. void run(void);
  3019. virtual void get_text(int nr);
  3020. };
  3021. ChooseString :: ChooseString ( const ASCString& _title, const vector<ASCString>& _strings, const vector<ASCString>& _buttons, int defaultEntry )
  3022. : strings ( _strings ), buttons ( _buttons )
  3023. {
  3024. strcpy ( buf, _title.c_str() );
  3025. startpos = defaultEntry;
  3026. }
  3027. void ChooseString ::setup( )
  3028. {
  3029. action = 0;
  3030. title = buf;
  3031. numberoflines = strings.size();
  3032. ey = ysize - 50;
  3033. if ( buttons.size() > 4 )
  3034. xsize = 640;
  3035. int width = (xsize-40)/buttons.size();
  3036. for ( int i = 0; i< buttons.size(); ++i )
  3037. addbutton( buttons[i].c_str(),25 + i*width,ysize - 45,15 + (i+1)*width,ysize - 20,0,1,20+i,true);
  3038. }
  3039. void ChooseString ::buttonpressed(int id)
  3040. {
  3041. tstringselect::buttonpressed(id);
  3042. if ( id >= 20 )
  3043. action =id ;
  3044. }
  3045. void ChooseString ::get_text(int nr)
  3046. {
  3047. strcpy ( txt, strings[nr].c_str());
  3048. }
  3049. void ChooseString ::run(void)
  3050. {
  3051. do {
  3052. tstringselect::run();
  3053. /*
  3054. if ( taste == ct_enter )
  3055. if ( redline >= 0 )
  3056. action = 2;
  3057. */
  3058. } while ( action == 0 );
  3059. }
  3060. int chooseString ( const ASCString& title, const vector<ASCString>& entries, int defaultEntry )
  3061. {
  3062. vector<ASCString> b;
  3063. b.push_back ( "~O~K");
  3064. return chooseString ( title, entries, b, defaultEntry).second;
  3065. }
  3066. pair<int,int> chooseString ( const ASCString& title, const vector<ASCString>& entries, const vector<ASCString>& buttons, int defaultEntry )
  3067. {
  3068. if ( legacyEventSystemActive() ) {
  3069. ChooseString gps ( title, entries, buttons, defaultEntry );
  3070. gps.init();
  3071. gps.run();
  3072. gps.done();
  3073. return make_pair(gps.action-20,gps.redline);
  3074. } else {
  3075. return new_chooseString ( title, entries, buttons, defaultEntry );
  3076. }
  3077. }
  3078. class StringEdit : public tdialogbox {
  3079. public :
  3080. ASCString org;
  3081. char nt[200];
  3082. StringEdit () { onCancel = ReturnZero; };
  3083. enum { ReturnZero, ReturnOriginal } onCancel;
  3084. int action;
  3085. int mid;
  3086. char text[200];
  3087. void init(void);
  3088. int max,min;
  3089. virtual void run(void);
  3090. virtual void buttonpressed(int id);
  3091. };
  3092. void StringEdit::init(void)
  3093. {
  3094. tdialogbox::init();
  3095. strcpy ( text, org.c_str() );
  3096. title = nt;
  3097. x1 = 200;
  3098. xsize = 220;
  3099. y1 = 150;
  3100. ysize = 140;
  3101. action = 0;
  3102. windowstyle = windowstyle ^ dlg_in3d;
  3103. addbutton("~D~one",20,ysize - 40,100,ysize - 20,0,1,1,true);
  3104. addkey(1,ct_enter);
  3105. addbutton("~C~ancel",120,ysize - 40,200,ysize - 20,0,1,2,true);
  3106. addbutton("",20,60,xsize - 20,80,1,1,3,true);
  3107. addeingabe(3,text,0,99);
  3108. buildgraphics();
  3109. mousevisible(true);
  3110. }
  3111. void StringEdit::run(void)
  3112. {
  3113. tdialogbox::run ();
  3114. pbutton pb = firstbutton;
  3115. while ( pb && (pb->id != 3))
  3116. pb = pb->next;
  3117. if ( pb )
  3118. if ( pb->id == 3 )
  3119. execbutton( pb , false );
  3120. do {
  3121. tdialogbox::run();
  3122. } while (!((taste == ct_esc) || ((action == 1) || (action == 2))));
  3123. if ((action == 2) || (taste == ct_esc)){
  3124. if ( onCancel == ReturnZero )
  3125. text[0] = 0;
  3126. else
  3127. strcpy( text, org.c_str() );
  3128. }
  3129. }
  3130. void StringEdit::buttonpressed(int id)
  3131. {
  3132. tdialogbox::buttonpressed(id);
  3133. switch (id) {
  3134. case 1:
  3135. case 2: action = id;
  3136. break;
  3137. }
  3138. }
  3139. ASCString editString( const ASCString& title, const ASCString& defaultValue )
  3140. {
  3141. StringEdit gi;
  3142. gi.org = defaultValue;
  3143. gi.onCancel = StringEdit::ReturnOriginal ;
  3144. strcpy( gi.nt, title.c_str() );
  3145. gi.init();
  3146. gi.run();
  3147. gi.done();
  3148. return gi.text;
  3149. }
  3150. #if 0
  3151. class StringSelect : public tdialogbox {
  3152. const vector<ASCString>& entries;
  3153. const vector<ASCString>& buttons;
  3154. ASCString myTitle;
  3155. public :
  3156. StringSelect( const ASCString& title, const vector<ASCString>& entries_, const vector<ASCString>& buttons_ );
  3157. protected:
  3158. char ok;
  3159. int sy,ey,sx,ex,action,dx;
  3160. int dk;
  3161. int msel,mouseselect,redline,lnshown,numberoflines,firstvisibleline,startpos;
  3162. char scrollbarvisible;
  3163. void init(void);
  3164. tstringselect ( );
  3165. virtual void run(void);
  3166. virtual void buttonpressed(int id);
  3167. void scrollbar_on(void);
  3168. void viewtext(void);
  3169. virtual void resettextfield(void);
  3170. virtual void get_text( Uint16 nr);
  3171. void done(void);
  3172. };
  3173. StringSelect :: StringSelect( const ASCString& title, const vector<ASCString>& entries_, const vector<ASCString>& buttons_ )
  3174. : entries( entries_ ), buttons ( buttons_ )
  3175. {
  3176. numberoflines = 0;
  3177. firstvisibleline = 0;
  3178. redline = 0;
  3179. startpos = 0;
  3180. myTitle = title;
  3181. }
  3182. void tstringselect::init(void)
  3183. {
  3184. tdialogbox::init();
  3185. xsize = 570;
  3186. ysize = 320;
  3187. x1 = ( 640 -xsize ) / 2;
  3188. y1 = ( 480 -ysize ) / 2;
  3189. sy = 45;
  3190. sx = 20;
  3191. title = myTitle.c_str();
  3192. windowstyle = windowstyle ^ dlg_in3d;
  3193. lnshown = 10;
  3194. ey = ysize - 50;
  3195. ex = xsize - 30;
  3196. setup();
  3197. if (startpos >= numberoflines )
  3198. startpos = numberoflines-1;
  3199. if (startpos > lnshown -1 ) {
  3200. firstvisibleline = startpos - ( lnshown - 1 );
  3201. redline = startpos;
  3202. } else {
  3203. redline = startpos;
  3204. } /* endif */
  3205. dk = 0;
  3206. action = 0;
  3207. dx = (ey - sy) / lnshown;
  3208. if (numberoflines > lnshown) {
  3209. scrollbarvisible = true;
  3210. addscrollbar(ex + 10 ,sy ,ex + 20,ey ,&numberoflines,lnshown,&firstvisibleline,1,0);
  3211. }
  3212. else
  3213. scrollbarvisible = false;
  3214. buildgraphics();
  3215. rahmen(true,x1 + sx , y1 + sy,x1 + ex,y1 + ey);
  3216. mousevisible(true);
  3217. activefontsettings.font = schriften.smallarial;
  3218. activefontsettings.color = black;
  3219. activefontsettings.justify = lefttext;
  3220. activefontsettings.background = lightgray;
  3221. activefontsettings.height = 15;
  3222. viewtext();
  3223. }
  3224. void tstringselect::buttonpressed(int id)
  3225. {
  3226. tdialogbox::buttonpressed(id);
  3227. if (id == 1) {
  3228. if (firstvisibleline > redline) redline = firstvisibleline;
  3229. if (firstvisibleline + lnshown - 1 < redline) redline = firstvisibleline + lnshown - 1;
  3230. viewtext();
  3231. }
  3232. }
  3233. void tstringselect::run(void)
  3234. {
  3235. char view;
  3236. int my;
  3237. int ms;
  3238. tdialogbox::run();
  3239. if (numberoflines > 0) {
  3240. msel = 0;
  3241. if (getmousestatus() == 2) {
  3242. if ((( ms = mouseparams.taste ) == 0) && (dk == 1)) dk = 2;
  3243. if ((mouseparams.x > x1 + 10) & (mouseparams.x < x1 + xsize - 40) && (ms != 0)) {
  3244. my = mouseparams.y - y1 - sy;
  3245. my = my / dx;
  3246. if ((my >= 0) && (my <= lnshown - 1) && (my <= numberoflines - 1)) {
  3247. mouseselect = firstvisibleline + my;
  3248. if ((mouseselect == redline) && (dk == 2)) {
  3249. msel = ms;
  3250. dk = 0;
  3251. }
  3252. else {
  3253. redline = mouseselect;
  3254. dk = 1;
  3255. ms =0;
  3256. viewtext();
  3257. }
  3258. }
  3259. }
  3260. }
  3261. switch (taste) {
  3262. case ct_up: {
  3263. view = true;
  3264. if (redline > 0) redline--;
  3265. else view = false;
  3266. if ((redline < firstvisibleline) && (firstvisibleline > 0)) {
  3267. firstvisibleline--;
  3268. showbutton( 1 );
  3269. }
  3270. if (view) viewtext();
  3271. }
  3272. break;
  3273. case ct_pos1: {
  3274. view = false;
  3275. if ( (redline > 0) || (firstvisibleline > 0) ) {
  3276. view = true;
  3277. redline = 0;
  3278. firstvisibleline = 0;
  3279. }
  3280. if (view) viewtext();
  3281. }
  3282. break;
  3283. case ct_ende: {
  3284. view = false;
  3285. if (redline < numberoflines -1 ) {
  3286. view = true;
  3287. redline = numberoflines -1 ;
  3288. firstvisibleline = numberoflines - lnshown;
  3289. }
  3290. if (view) viewtext();
  3291. }
  3292. break;
  3293. case ct_down: {
  3294. view = true;
  3295. if (redline < numberoflines - 1) redline++;
  3296. else view = false;
  3297. if ((redline > firstvisibleline + lnshown - 1) && (firstvisibleline + lnshown - 1 <= numberoflines)) {
  3298. firstvisibleline++;
  3299. showbutton( 1 );
  3300. }
  3301. if (view) viewtext();
  3302. }
  3303. break;
  3304. }
  3305. }
  3306. else redline = -1;
  3307. }
  3308. void tstringselect::resettextfield(void)
  3309. {
  3310. bar(x1 + sx,y1 + sy,x1 + ex,y1 + ey,lightgray);
  3311. rahmen(true,x1 + sx ,y1 + sy,x1 + ex,y1 + ey);
  3312. }
  3313. void tstringselect::get_text(Uint16 nr) //gibt in txt den string zur?ck
  3314. {
  3315. strcpy(txt,"");
  3316. nr = 0;
  3317. }
  3318. void tstringselect::scrollbar_on(void)
  3319. {
  3320. scrollbarvisible = true;
  3321. addscrollbar(ex + 10 ,sy - 10,ex + 30,ey + 10,&numberoflines,lnshown,&firstvisibleline,1,0);
  3322. }
  3323. void tstringselect::viewtext(void)
  3324. {
  3325. char s1[200];
  3326. Uint16 yp;
  3327. int l;
  3328. mousevisible(false);
  3329. //showbutton(1);
  3330. npush(activefontsettings.length);
  3331. activefontsettings.length = ex - sx - 10;
  3332. yp = y1 + sy + 5;
  3333. l = firstvisibleline;
  3334. if (numberoflines > 0) {
  3335. while ((l<numberoflines) && (l-firstvisibleline < lnshown)) {
  3336. get_text(l);
  3337. strcpy(s1,txt);
  3338. if (l == redline ) activefontsettings.color=red;
  3339. else activefontsettings.color=lightblue;
  3340. showtext2(s1,x1+ sx + 5,yp+( l-firstvisibleline ) * dx );
  3341. l++;
  3342. } /* endwhile */
  3343. }
  3344. // else showtext2("No text available !",x1 + 50,yp + 50);
  3345. //rahmen(true,x1 + sx ,y1 + sy,x1 + ex ,y1 + ey );
  3346. npop(activefontsettings.length);
  3347. mousevisible(true);
  3348. }
  3349. void tstringselect::done(void)
  3350. {
  3351. tdialogbox::done();
  3352. while ( mouseparams.taste )
  3353. releasetimeslice();
  3354. }
  3355. #endif