PageRenderTime 59ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/source/dlg_box.cpp

https://bitbucket.org/val_haris/asc-ai
C++ | 4147 lines | 3250 code | 774 blank | 123 comment | 1020 complexity | c96722b9ba1f8e4e8207503a82359f9c MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  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;

Large files files are truncated, but you can click here to view the full file