00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <stdio.h>
00027 #include <stdlib.h>
00028 #include <stdarg.h>
00029 #include <ctype.h>
00030 #include <cstring>
00031 #include <iostream>
00032
00033 #include "typen.h"
00034 #include "basegfx.h"
00035 #include "newfont.h"
00036 #include "spfst.h"
00037 #include "loaders.h"
00038 #include "misc.h"
00039 #include "events.h"
00040 #include "stack.h"
00041 #include "dlg_box.h"
00042 #include "paradialog.h"
00043 #include "widgets/textrenderer.h"
00044
00045
00046 #ifdef _WIN32_
00047 #include <windows.h>
00048 #include <winuser.h>
00049 #endif
00050
00051
00052
00053 char strrstring[200];
00054
00055 void strrd8d(int l, char* s)
00056 {
00057 itoa ( l / minmalq, s, 10);
00058 }
00059
00060 void strrd8u(int l, char* s)
00061 {
00062 itoa ( (l + minmalq - 1) / minmalq, s, 10);
00063 }
00064
00065 void strrd8n(int l, char* s)
00066 {
00067 itoa ( (l + minmalq/2) / minmalq, s, 10);
00068 }
00069
00070
00071 char* strrrd8d(int l)
00072 {
00073 itoa ( l / minmalq, strrstring, 10);
00074
00075 return strrstring;
00076 }
00077
00078 char* strrrd8u(int l)
00079 {
00080 itoa ( (l + minmalq - 1) / minmalq, strrstring, 10);
00081
00082 return strrstring;
00083 }
00084
00085 char* strrrd8n(int l)
00086 {
00087 itoa ( (l + minmalq/2) / minmalq, strrstring, 10);
00088
00089 return strrstring;
00090 }
00091
00092
00093 void *dialogtexture = NULL;
00094
00095 int actdisplayedmessage = 0;
00096 long int lastdisplayedmessageticker = 0xffffff;
00097
00098
00099 tvirtualscreenbuf virtualscreenbuf;
00100
00101
00102 tvirtualscreenbuf :: tvirtualscreenbuf ( void )
00103 {
00104 buf = NULL;
00105 size = 0;
00106 }
00107
00108 void tvirtualscreenbuf:: init ( void )
00109 {
00110 size = hgmp->bytesperscanline * hgmp->resolutiony;
00111 buf = asc_malloc( size );
00112 }
00113
00114 tvirtualscreenbuf:: ~tvirtualscreenbuf ()
00115 {
00116 asc_free( buf );
00117 buf = NULL;
00118 }
00119
00120
00121 char getletter( const char * s)
00122 {
00123 const char* c = s;
00124
00125 while ( *c && (*c != 126 ))
00126 c++;
00127
00128 if (*c == '~' ) {
00129 c++;
00130 return *c;
00131 } else {
00132 return 0;
00133 }
00134 }
00135
00136
00137 collategraphicoperations* tdialogbox::pcgo = NULL;
00138
00139 tdialogbox::tdialogbox()
00140 {
00141 eventQueue = setEventRouting ( false, true );
00142
00143 npush ( activefontsettings );
00144 activefontsettings.font = schriften.smallarial;
00145 activefontsettings.color = black;
00146 activefontsettings.background = 255;
00147 activefontsettings.markcolor = red;
00148
00149
00150 virtualbufoffset = 0;
00151 boxstatus = 0;
00152
00153 dlg_mode = 0;
00154 int rdw = 0;
00155
00156 if ( first ) {
00157 pdialogbox rn = first;
00158 rdw &= rn->getcapabilities() & 1;
00159 while ( rn->next ) {
00160 rn = rn->next;
00161 rdw &= rn->getcapabilities() & 1;
00162 }
00163
00164
00165 prev = rn;
00166 rn->next = this;
00167 } else {
00168 first = this;
00169 prev = NULL;
00170 }
00171 next = NULL;
00172
00173 if ( rdw )
00174 dlg_mode |= 2;
00175 }
00176
00177
00178 int tdialogbox::getcapabilities ( void )
00179 {
00180 return 0;
00181 }
00182
00183 extern void repaintdisplay ( void );
00184
00185
00186 void tdialogbox::repaintdisplay( void )
00187 {
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220 }
00221
00222 void tdialogbox::redrawall ( void )
00223 {
00224 paint();
00225 if ( prev )
00226 prev->redrawall();
00227 else
00228 repaintDisplay();
00229 }
00230
00231 void tdialogbox::redrawall2 ( int xx1, int yy1, int xx2, int yy2 )
00232 {
00233 paint ();
00234 if ( x1 > xx1 || y1 > yy1 || x1+xsize < xx2 || y1+ysize < yy2 ) {
00235 if ( prev )
00236 prev->redrawall2 ( xx1, yy1, xx2, yy2 );
00237 else
00238 repaintDisplay();
00239 }
00240 }
00241
00242
00243 pdialogbox tdialogbox::first = NULL;
00244
00245 void tdialogbox::setvirtualframebuf ( void )
00246 {
00247 agmp->linearaddress = (PointerSizedInt) virtualscreenbuf.buf;
00248 agmp->windowstatus = 100;
00249 agmp->scanlinelength = hgmp->scanlinelength;
00250 }
00251
00252 void tdialogbox::setclipping ( void )
00253 {
00254 bar ( x1, y1, x1 + xsize, y1 + ysize, 255 );
00255 if ( next )
00256 next->setclipping ( );
00257 }
00258
00259 void tdialogbox::copyvirtualframebuf ( void )
00260 {
00261 ms = getmousestatus();
00262 if (ms == 2)
00263 mousevisible(false);
00264
00265 npush ( *agmp );
00266 void* buf = (void*) agmp->linearaddress;
00267 *agmp = *hgmp;
00268
00269 putspritetexture ( x1, y1, x1 + xsize, y1 + ysize, buf );
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283 npop ( *agmp );
00284
00285 if (ms == 2)
00286 mousevisible(true);
00287
00288 }
00289
00290 void tdialogbox::paint ( void )
00291 {
00292 setvirtualframebuf();
00293 redraw();
00294 if ( next )
00295 next->setclipping();
00296 copyvirtualframebuf();
00297 *agmp = *hgmp;
00298 }
00299
00300
00301 int getplayercolor ( int i )
00302 {
00303 if ( actmap ) {
00304 int textcolor = i * 8 + 21;
00305 if ( i == 7 || i == 2 )
00306 textcolor += 1;
00307 return textcolor;
00308 } else
00309 return 20;
00310 }
00311
00312 void tdialogbox::init(void)
00313 {
00314 imagesaved = false;
00315 if ( actmap && actmap->actplayer != -1 ) {
00316 textcolor = getplayercolor ( actmap->actplayer );
00317 }
00318 else
00319 textcolor = 20;
00320
00321 firstbutton = NULL;
00322 windowstyle = dlg_in3d | dlg_3dtitle;
00323 x1 = 50;
00324 xsize = 540;
00325 y1 = 50;
00326 ysize = 380;
00327 starty = 40;
00328 title = "dialogbox";
00329 npush( activefontsettings );
00330 activefontsettings.height = 0;
00331 activefontsettings.length = 0;
00332 memset(taborder, 0, sizeof(taborder));
00333 tabcount = 0;
00334 markedtab = 0;
00335 disablecolor = darkgray;
00336 boxstatus = 1;
00337 dlg_mode = 0;
00338 }
00339
00340
00341
00342
00343
00344 #include "dlgraph.cpp"
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354 void tdialogbox::changecoordinates(void)
00355 {
00356
00357 }
00358
00359 tdlgengine::pbutton tdlgengine :: getbutton ( int id )
00360 {
00361 pbutton pb = firstbutton;
00362 while ( pb && (pb->id != id))
00363 pb = pb->next;
00364 return pb;
00365 }
00366
00367 void tdlgengine::buttonpressed(int id)
00368 {
00369 pbutton pb;
00370 int w;
00371 Uint16 *pw, *pw2;
00372
00373 pb = firstbutton;
00374 while ( pb ) {
00375 if ((pb->art == 5)) {
00376 pw = (Uint16*) pb->data;
00377 pw2 = (Uint16*) pb->data2;
00378 w = *pw;
00379 if ((pb->id + 1 == id)) {
00380 if (taste == ct_pup) {
00381 if (*pw >= pb->max)
00382 *pw -= pb->max - 1;
00383 else
00384 *pw = 0;
00385 }
00386 else
00387 if (taste == ct_pos1) {
00388 *pw = 0;
00389 }
00390 else
00391 if (*pw > 0) {
00392 if ( pb->newpressed == 0 )
00393 (*pw) --;
00394 else
00395 if ( pb->newpressed == 1) {
00396 (*pw) --;
00397 pb->lasttick = ticker;
00398 } else
00399 if ( pb->newpressed == 2) {
00400 int dst = ticker - pb->lasttick;
00401 if ( *pw < dst )
00402 (*pw) = 0;
00403 else
00404 (*pw) -= dst;
00405 pb->lasttick = ticker;
00406 }
00407 }
00408 }
00409 if ((pb->id + 2 == id)) {
00410 if (taste == ct_pdown) {
00411 if (*pw + (pb->max * 2) - 1 <= *pw2)
00412 *pw += pb->max - 1;
00413 else
00414 *pw = *pw2 - pb->max;
00415 }
00416 else
00417 if (taste == ct_ende) {
00418 *pw = *pw2 - pb->max;
00419 }
00420 else
00421 if ( *pw + pb->max < *pw2 ) {
00422
00423 if ( pb->newpressed == 0 )
00424 (*pw)++;
00425 else
00426 if ( pb->newpressed == 1) {
00427 (*pw) ++;
00428 pb->lasttick = ticker;
00429 } else
00430 if ( pb->newpressed == 2) {
00431 int dst = ticker - pb->lasttick;
00432 if ( *pw + dst + pb->max >= *pw2 )
00433 *pw = *pw2 - pb->max;
00434
00435 else
00436 (*pw) += dst;
00437 pb->lasttick = ticker;
00438 }
00439 }
00440 }
00441 if (w != *pw) {
00442 char mss = getmousestatus();
00443 if (mss == 2 )
00444 mousevisible(false);
00445 showbutton(pb->id);
00446 buttonpressed(pb->id);
00447 if (mss == 2 )
00448 mousevisible(true);
00449 }
00450
00451 }
00452 pb = pb->next;
00453 }
00454 }
00455
00456
00457 void tdlgengine::addbutton( const char * ltxt,
00458 tmouserect rect1,
00459 int lart,
00460 int lstyle,
00461 int lid,
00462 char enabled)
00463 {
00464 addbutton ( ltxt, rect1.x1, rect1.y1, rect1.x2, rect1.y2, lart, lstyle, lid, enabled );
00465 }
00466
00467 const char* emptystring = "";
00468
00469 void tdlgengine::addbutton( const char * ltxt,
00470 int lx1,
00471 int ly1,
00472 int lx2,
00473 int ly2,
00474 int lart,
00475 int lstyle,
00476 int lid,
00477 char enabled)
00478 {
00479 pbutton pb;
00480 char ch;
00481
00482 pb = firstbutton;
00483 if (lid <= 0)
00484 displaymessage("tdialogbox: \n id equal or less then 0\n:%d\n",2, lid);
00485 while ( pb ) {
00486 if (pb->id == lid)
00487 displaymessage("tdialogbox: duplicate button id: %d\n",2, lid);
00488
00489 pb = pb->next;
00490 }
00491 pb = new tbutton;
00492 pb->x1 = lx1;
00493 pb->x2 = lx2;
00494 pb->y1 = ly1;
00495 pb->y2 = ly2;
00496 pb->style = lstyle;
00497 pb->id = lid;
00498 pb->next = firstbutton;
00499 if ( ltxt )
00500 pb->text = ltxt;
00501 else
00502 pb->text = emptystring;
00503 pb->art = lart;
00504 pb->active = enabled;
00505 pb->status = 1;
00506 pb->scrollspeed = 30;
00507 pb->pressed = 0;
00508 pb->newpressed = 0;
00509
00510 firstbutton = pb;
00511
00512 ch = getletter(pb->text);
00513 if (ch != 0) {
00514 pb->key[0] = char2key( tolower(ch) );
00515 pb->keynum = 1;
00516 }
00517 else
00518 pb->keynum = 0;
00519 pb->markedkeynum = 1;
00520 pb->markedkey[0] = ct_enter;
00521
00522 }
00523
00524
00525 void tdlgengine::addscrollbar(tmouserect rec,
00526 int* numberofitems,
00527 int itemsvisible,
00528 int* actitem,
00529 int lid,
00530 int keys)
00531 {
00532 addscrollbar ( rec.x1, rec.y1, rec.x2, rec.y2, numberofitems, itemsvisible, actitem, lid, keys );
00533 }
00534
00535 void tdialogbox :: bar ( tmouserect rect, int color )
00536 {
00537 ::bar ( rect.x1, rect.y1, rect.x2, rect.y2, color );
00538 }
00539
00540 void tdialogbox :: bar ( int x1, int y1, int x2, int y2, int color )
00541 {
00542 ::bar ( x1, y1, x2, y2, color );
00543 }
00544
00545
00546 void tdlgengine::addDropDown( int x1, int y1, int x2, int y2, int ID, const char** entries, int entrynum, int* pos )
00547 {
00548 pbutton pb = firstbutton;
00549 if ( ID <= 0)
00550 displaymessage("tdialogbox: id equal or less then 0", 2);
00551 while (pb != NULL) {
00552 if (pb->id == ID)
00553 displaymessage("tdialogbox: duplicate button id: %d\n",2, ID);
00554 pb = pb->next;
00555 }
00556 pb = new tbutton;
00557 pb->x1 = x1;
00558 pb->x2 = x2;
00559 pb->y1 = y1;
00560 pb->y2 = y2;
00561 pb->style = 0;
00562 pb->id = ID;
00563 pb->next = firstbutton;
00564 pb->text = NULL;
00565 pb->art = 6;
00566 pb->active = true;
00567 pb->status = 1;
00568 pb->keynum = 0;
00569 pb->markedkeynum = 0;
00570 pb->scrollspeed = 30;
00571 pb->pressed = 0;
00572 pb->newpressed = 0;
00573 pb->entries = entries;
00574 pb->entrynum = entrynum;
00575 pb->data = pos;
00576 firstbutton = pb;
00577 }
00578
00579
00580 void tdlgengine::addscrollbar(int lx1,
00581 int ly1,
00582 int lx2,
00583 int ly2,
00584 int* numberofitems,
00585 int itemsvisible,
00586 int* actitem,
00587 int lid,
00588 int keys)
00589 {
00590 pbutton pb;
00591
00592 pb = firstbutton;
00593 if (lid <= 0)
00594 displaymessage("tdialogbox: id equal or less then 0", 2);
00595 while (pb != NULL) {
00596 if (pb->id == lid)
00597 displaymessage("tdialogbox: duplicate button id: %d\n",2, lid);
00598 pb = pb->next;
00599 }
00600 pb = new tbutton;
00601 pb->x1 = lx1;
00602 pb->x2 = lx2;
00603 pb->y1 = ly1 + 13;
00604 pb->y2 = ly2 - 13;
00605 pb->style = 0;
00606 pb->id = lid;
00607 pb->next = firstbutton;
00608 pb->text = NULL;
00609 pb->art = 5;
00610 pb->active = true;
00611 pb->status = 1;
00612 pb->keynum = 0;
00613 pb->markedkeynum = 0;
00614 pb->scrollspeed = 30;
00615 pb->pressed = 0;
00616 pb->newpressed = 0;
00617 firstbutton = pb;
00618
00619 addbutton("",lx1+1, ly1 + 1 , lx2 - 1, ly1 + 10, 0, 2, lid + 1, true);
00620 addbutton("",lx1+1, ly2 - 10 , lx2 - 1, ly2 - 1, 0, 2, lid + 2, true);
00621
00622 if (keys == 2) {
00623 addmarkedkey(lid + 1,ct_up);
00624 addmarkedkey(lid + 1,ct_pup);
00625 addmarkedkey(lid + 1,ct_pos1);
00626
00627 addmarkedkey(lid + 2,ct_down);
00628 addmarkedkey(lid + 2,ct_pdown);
00629 addmarkedkey(lid + 2,ct_ende);
00630 }
00631 if (keys == 1) {
00632 addkey(lid + 1,ct_up);
00633 addkey(lid + 1,ct_pup);
00634 addkey(lid + 1,ct_pos1);
00635
00636 addkey(lid + 2,ct_down);
00637 addkey(lid + 2,ct_pdown);
00638 addkey(lid + 2,ct_ende);
00639 }
00640
00641
00642 pb->data = actitem;
00643 pb->data2 = numberofitems;
00644 pb->max = itemsvisible;
00645
00646 }
00647
00648
00649 void tdialogbox::rebuildtaborder(void)
00650 {
00651 pbutton pb = firstbutton;
00652 int i = 0;
00653 ttaborder b;
00654
00655 tabcount = 0;
00656 while (pb != NULL) {
00657 if ((pb->art >= 0) && (pb->art <= 3))
00658 if ((pb->status == 1) && pb->active) {
00659 tabcount++;
00660 taborder[tabcount].id = pb->id;
00661 taborder[tabcount].x1 = pb->x1;
00662 taborder[tabcount].y1 = pb->y1;
00663 taborder[tabcount].x2 = pb->x2;
00664 taborder[tabcount].y2 = pb->y2;
00665 taborder[tabcount].button = pb;
00666
00667 }
00668 pb = pb->next;
00669 }
00670
00671 if (tabcount > 1)
00672 for (i = 1; i <= tabcount - 1; i++) {
00673 if ((taborder[i].y1 > taborder[i + 1].y1) || ((taborder[i].y1 == taborder[i + 1].y1) && (taborder[i].x1 > taborder[i + 1].x1)))
00674 {
00675 b = taborder[i];
00676 taborder[i] = taborder[i + 1];
00677 taborder[i + 1] = b;
00678 if (i > 1)
00679 i -= 2;
00680 }
00681 }
00682
00683
00684 pbutton pb2 = NULL;
00685 if (i > 0) {
00686 if (markedtab > 0)
00687 pb2 = taborder[i].button;
00688 }
00689
00690 showtabmark(markedtab);
00691
00692 if ( markedtab ) {
00693 markedtab = 0;
00694 if (tabcount > 0) {
00695 for (i = 1; i <= tabcount; i++)
00696 if (taborder[i].button == pb2)
00697 markedtab = i;
00698 }
00699 }
00700
00701 showtabmark(markedtab);
00702 }
00703
00704
00705 void tdialogbox::showbutton(int id)
00706 {
00707 pbutton pb;
00708 int c;
00709 char mss = getmousestatus();
00710
00711 if (mss == 2)
00712 mousevisible(false);
00713 pb = firstbutton;
00714 while (pb != NULL) {
00715 if (pb->id == id)
00716 if ( pb->pressed == 0) {
00717 c = pb->status;
00718 pb->status = 1;
00719 if (pb->active)
00720 enablebutton(id);
00721 else
00722 disablebutton(id);
00723
00724 if (pb->art == 5) {
00725 showbutton ( id + 1);
00726 showbutton ( id + 2);
00727 }
00728
00729 if (c != 1)
00730 rebuildtaborder();
00731 }
00732
00733 pb = pb->next;
00734 }
00735 if (mss == 2)
00736 mousevisible(true);
00737 }
00738
00739
00740 void tdialogbox::hidebutton(int id)
00741 {
00742 pbutton pb;
00743
00744 pb = firstbutton;
00745 while (pb != NULL) {
00746 if (pb->id == id) {
00747 pb->status = 0;
00748 if (pb->art == 5) {
00749 hidebutton ( id + 1);
00750 hidebutton ( id + 2);
00751 }
00752 }
00753 pb = pb->next;
00754 }
00755 rebuildtaborder();
00756 }
00757
00758
00759
00760 void tdlgengine::clearkey ( char id )
00761 {
00762 pbutton pb = firstbutton;
00763 while ( pb ) {
00764 if ( pb->id == id ) {
00765 pb->keynum = 0;
00766 pb->markedkeynum = 0;
00767 }
00768 pb = pb->next;
00769 }
00770 }
00771
00772 void tdlgengine::addkey( int id, tkey key )
00773 {
00774 pbutton pb = firstbutton;
00775 while ( pb ) {
00776 if (pb->id == id) {
00777 int exist = 0;
00778 for ( int i = 0; i < pb->keynum; i++ )
00779 if ( pb->key[i] == key )
00780 exist++;
00781 if ( !exist ) {
00782 pb->key [ pb->keynum ] = key;
00783 pb->keynum++;
00784 }
00785 }
00786 pb = pb->next;
00787 }
00788 }
00789
00790
00791 void tdlgengine::addmarkedkey(int id, tkey key)
00792 {
00793 pbutton pb;
00794
00795 pb = firstbutton;
00796 while ( pb ) {
00797 if (pb->id == id) {
00798 int exist = 0;
00799 for ( int i = 0; i < pb->markedkeynum; i++ )
00800 if ( pb->markedkey[i]== key )
00801 exist++;
00802 if ( !exist ) {
00803 pb->markedkey [ pb->markedkeynum ] = key;
00804 pb->markedkeynum++;
00805 }
00806 }
00807 pb = pb->next;
00808 }
00809 }
00810
00811
00812 void tdialogbox::setscrollspeed(char id , int speed)
00813 {
00814 pbutton pb;
00815
00816 pb = firstbutton;
00817 while (pb != NULL) {
00818 if (pb->id == id) {
00819 if (pb->art == 5) {
00820 setscrollspeed( id + 1, speed );
00821 setscrollspeed( id + 2, speed );
00822 } else
00823 pb->scrollspeed = speed;
00824 }
00825
00826 pb = pb->next;
00827 }
00828 }
00829
00830
00831 void tdlgengine::addeingabe(int lid,
00832 void* data,
00833 int min,
00834 int max)
00835 {
00836 pbutton pb;
00837
00838 pb = firstbutton;
00839 while (pb != NULL) {
00840 if (pb->id == lid) {
00841 pb->data = data;
00842 if ( min > max ) {
00843 pb->min = max;
00844 pb->max = min;
00845 } else {
00846 pb->min = min;
00847 pb->max = max;
00848 }
00849 addmarkedkey(pb->id,ct_enter);
00850 addmarkedkey(pb->id,ct_space);
00851 }
00852 pb = pb->next;
00853 }
00854 }
00855
00856
00857
00858 void tdialogbox::enablebutton(int id)
00859 {
00860
00861 pbutton pb = firstbutton;
00862 if ( !pb )
00863 return;
00864
00865
00866 while ( pb && pb->id != id )
00867 pb = pb->next;
00868
00869 if ( !pb )
00870 return;
00871
00872 npush( activefontsettings );
00873
00874 collategraphicoperations cgo ( x1 + pb->x1, max ( y1 + pb->y1 - 20, 0 ), x1 + pb->x2, y1 + pb->y2 );
00875
00876 char strng[200];
00877 activefontsettings.font = schriften.smallarial;
00878 activefontsettings.justify = lefttext;
00879 activefontsettings.length = pb->x2 - pb->x1 - 10;
00880 activefontsettings.markcolor = textcolor - 2;
00881 activefontsettings.color = textcolor;
00882 activefontsettings.background = 255;
00883
00884
00885 if (pb->art == 0) {
00886 if ((pb->style == 1) || (pb->style == 2))
00887 newknopf(x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2);
00888
00889 if ( pb->text )
00890 if (pb->text[0] ) {
00891 activefontsettings.justify = centertext;
00892 showtext3( pb->text,x1 + pb->x1,y1 + (pb->y1 + pb->y2) / 2 - activefontsettings.font->height / 2);
00893 }
00894 }
00895
00896 if ((pb->art == 1) || ( pb->art == 2 )) {
00897 rahmen(true,x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2);
00898 paintsurface( pb->x1 + 1, pb->y1 + 1, pb->x2 - 1, pb->y2 - 1 );
00899 if ( pb->text )
00900 if (pb->text[0] ) {
00901 if ( pb->style != 3 ) {
00902 showtext3(pb->text,x1 + pb->x1,y1 + pb->y1 - activefontsettings.font->height);
00903 } else {
00904 npush ( activefontsettings.length );
00905 activefontsettings.length = 300;
00906 cgo.off();
00907 showtext3(pb->text,x1 + pb->x2 + 10,y1 + pb->y1 );
00908 cgo.on();
00909 npop ( activefontsettings.length );
00910 }
00911 }
00912
00913 if (pb->art == 1)
00914 showtext2((char*) pb->data , x1 + pb->x1 + 5,y1 + pb->y1 + 2);
00915
00916 if (pb->art == 2) {
00917 if (pb->max <= 255 && pb->min >= 0) {
00918 char* pbt = (char*) pb->data;
00919 itoa ( *pbt, strng, 10 );
00920 showtext2( strng, x1 + pb->x1 + 5,y1 + pb->y1 + 2);
00921 }
00922 else
00923 if (pb->max <= 65535 && pb->min >= 0) {
00924 Uint16* pw = (Uint16*) pb->data;
00925 itoa ( *pw, strng, 10 );
00926 showtext2(strng, x1 + pb->x1 + 5,y1 + pb->y1 + 2);
00927 }
00928 else {
00929 int* pl = (int*) pb->data;
00930 itoa ( *pl, strng, 10 );
00931 showtext2(strng, x1 + pb->x1 + 5,y1 + pb->y1 + 2);
00932 }
00933 }
00934 }
00935 if (pb->art == 3) {
00936 rahmen(true,x1 + pb->x1,y1 + pb->y1,x1 + pb->x1 + (pb->y2 - pb->y1),y1 + pb->y2);
00937
00938 showtext3(pb->text,x1 + pb->x1 + (pb->y2 - pb->y1) + 5,y1 + (pb->y1 + pb->y2 - activefontsettings.font->height) / 2);
00939
00940 char* pbl = (char*) pb->data;
00941
00942 int cl;
00943 if (*pbl)
00944 cl = pb->min;
00945 else
00946 cl = pb->max;
00947
00948 line(x1 + pb->x1,y1 + pb->y1,x1 + pb->x1 + (pb->y2 - pb->y1),y1 + pb->y2, cl);
00949 line(x1 + pb->x1 + (pb->y2 - pb->y1),y1 + pb->y1,x1 + pb->x1,y1 + pb->y2, cl);
00950 }
00951
00952 if (pb->art == 5) {
00953 Uint16* pw = (Uint16*) pb->data;
00954 Uint16* pw2 =(Uint16*) pb->data2;
00955 rahmen(true,x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2);
00956
00957 paintsurface2(x1 + pb->x1 + 1,y1 + pb->y1 + 1,x1 + pb->x2 - 1,y1 + pb->y2 - 1 );
00958
00959
00960 int l = pb->y2 - pb->y1 - 2;
00961 rahmen(false, x1 + pb->x1 + 1, y1 + pb->y1 + 1 + l * *pw / *pw2,
00962 x1 + pb->x2 - 1, y1 + pb->y1 + 1 + l * (*pw + pb->max) / *pw2);
00963
00964
00965
00966
00967 }
00968
00969 if ( pb->art == 6 ) {
00970 bar ( x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2, lightgray );
00971 rahmen(true,x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2);
00972 int pos = *( (int*) pb->data );
00973 if ( pos < 0 || pos >= pb->entrynum )
00974 fatalError("invalid pos in dropdown",2);
00975
00976 showtext3(pb->entries[pos], x1 + pb->x1 + (pb->y2 - pb->y1) + 5, y1 + (pb->y1 + pb->y2 - activefontsettings.font->height) / 2);
00977
00978 line ( x1 + pb->x2 - 20, y1 + pb->y1 + 4, x1 + pb->x2 - 10, y1 + pb->y1 + 4, textcolor );
00979 line ( x1 + pb->x2 - 20, y1 + pb->y1 + 4, x1 + pb->x2 - 15, y1 + pb->y1 + 14, textcolor );
00980 line ( x1 + pb->x2 - 10, y1 + pb->y1 + 4, x1 + pb->x2 - 15, y1 + pb->y1 + 14, textcolor );
00981 }
00982
00983 pb->active = true;
00984 npop( activefontsettings );
00985 rebuildtaborder();
00986 }
00987
00988
00989
00990
00991 void tdialogbox::disablebutton(int id)
00992 {
00993 pbutton pb;
00994 int *pl;
00995 Uint16 *pw, *pw2;
00996 char *pbt;
00997 char *pbl;
00998 char* s;
00999 char* t;
01000 int l;
01001 char cl;
01002
01003 pb = firstbutton;
01004 if ( !pb )
01005 return;
01006 while ((pb != NULL) && (pb->id != id))
01007 pb = pb->next;
01008 if (pb == NULL)
01009 return;
01010
01011 npush(activefontsettings);
01012 activefontsettings.font = schriften.smallarial;
01013 activefontsettings.justify = lefttext;
01014 activefontsettings.length = pb->x2 - pb->x1 - 10;
01015 activefontsettings.color = disablecolor;
01016
01017 s = new char[200];
01018 strcpy(s, pb->text);
01019
01020 t = strchr( s, 126 );
01021 while ( t != NULL ) {
01022 do {
01023 t[0] = t[1];
01024 t++;
01025 } while ( t[0] !=0 ) ;
01026 t = strchr( s, 126 );
01027 }
01028
01029 if (pb->art == 0) {
01030 if (pb->text != NULL)
01031 if (pb->text[0] != 0) {
01032 activefontsettings.justify = centertext;
01033 showtext2(s, x1 + pb->x1, y1 + (pb->y1 + pb->y2) / 2 - activefontsettings.font->height / 2);
01034 }
01035 if ((pb->style == 1) || (pb->style == 2)) {
01036 rectangle(x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2,disablecolor);
01037 rectangle(x1 + pb->x1 - 1,y1 + pb->y1 - 1,x1 + pb->x2 + 1,y1 + pb->y2 + 1,disablecolor);
01038 }
01039 }
01040 if ((pb->art == 1) || (pb->art == 2)) {
01041 rectangle(x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2,disablecolor);
01042 if (pb->text != NULL)
01043 if (pb->text[0] != 0) {
01044 if ( pb->style != 3 )
01045
01046 showtext2(pb->text,x1 + pb->x1,y1 + pb->y1 - activefontsettings.font->height);
01047 else {
01048 npush ( activefontsettings );
01049 activefontsettings.length = 0;
01050 showtext2(pb->text,x1 + pb->x2 + 10,y1 + pb->y1 );
01051 npop ( activefontsettings );
01052 }
01053 }
01054
01055 if (pb->art == 1) {
01056 showtext2( (char*)pb->data,x1 + pb->x1 + 5,y1 + pb->y1 + 2);
01057 }
01058 if (pb->art == 2) {
01059 if (pb->max <= 255 && pb->min >= 0) {
01060 pbt = (char*) pb->data;
01061 itoa ( *pbt, s, 10 );
01062 showtext2(s,x1 + pb->x1 + 5,y1 + pb->y1 + 2);
01063 }
01064 else
01065 if (pb->max <= 65535 && pb->min >= 0) {
01066 pw = (Uint16*) pb->data;
01067 itoa ( *pw, s , 10);
01068 showtext2(s, x1 + pb->x1 + 5,y1 + pb->y1 + 2);
01069 }
01070 else {
01071 pl = (int*) pb->data;
01072 itoa ( *pl, s, 10);
01073 showtext2(s, x1 + pb->x1 + 5,y1 + pb->y1 + 2);
01074 }
01075 }
01076 }
01077 if (pb->art == 3) {
01078 rectangle(x1 + pb->x1,y1 + pb->y1,x1 + pb->x1 + (pb->y2 - pb->y1),y1 + pb->y2,disablecolor);
01079 showtext2(s,x1 + pb->x1 + (pb->y2 - pb->y1) + 5,y1 + (pb->y1 + pb->y2 - activefontsettings.font->height) / 2);
01080 pbl = (char*) pb->data;
01081 if (*pbl)
01082 cl = disablecolor;
01083 else
01084 cl = pb->max;
01085 line(x1 + pb->x1,y1 + pb->y1,x1 + pb->x1 + (pb->y2 - pb->y1),y1 + pb->y2, cl);
01086 line(x1 + pb->x1 + (pb->y2 - pb->y1),y1 + pb->y1,x1 + pb->x1,y1 + pb->y2, cl);
01087 }
01088 if (pb->art == 5) {
01089 pw = (Uint16*) pb->data;
01090 pw2 = (Uint16*) pb->data2;
01091
01092 rectangle(x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2,disablecolor);
01093
01094 paintsurface2(x1 + pb->x1 + 1,y1 + pb->y1 + 1,x1 + pb->x2 - 1,y1 + pb->y2 - 1);
01095
01096 if (pb->max <= *pw2) {
01097 l = pb->y2 - pb->y1 - 2;
01098 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);
01099 }
01100 else
01101 rectangle(x1 + pb->x1 + 1,y1 + pb->y1 + 1,x1 + pb->x2 - 1,y1 + pb->y2 - 1,disablecolor);
01102
01103 }
01104 delete[] s;
01105 pb->active = false;
01106 npop( activefontsettings );
01107 rebuildtaborder();
01108 }
01109
01110
01111 void tdialogbox::redraw(void)
01112 {
01113 pbutton pb;
01114
01115
01116 knopf(x1,y1,x1 + xsize,y1 + ysize);
01117
01118
01119 rahmen(false, x1,y1,x1 + xsize, y1 + ysize);
01120
01121
01122 activefontsettings.color = white;
01123 activefontsettings.background = 255;
01124 activefontsettings.font = schriften.smallarial;
01125 activefontsettings.justify = centertext;
01126 activefontsettings.length = xsize - 10;
01127 activefontsettings.height = 00;
01128
01129 if (windowstyle & dlg_wintitle ) {
01130 starty = 25;
01131 rahmen(true,x1 + 5,y1 + 3,x1 + xsize - 5,y1 + 20);
01132 bar(x1 + 6,y1 + 4,x1 + xsize - 6,y1 + 19,blue);
01133
01134 activefontsettings.color = textcolor;
01135 showtext2(title, x1 + 5,y1 + 3);
01136 }
01137 else {
01138 starty = 5;
01139 if ((windowstyle & dlg_notitle) == 0)
01140 if (title != NULL)
01141 if (title[0] ) {
01142 activefontsettings.font = schriften.large;
01143 if ( windowstyle & dlg_3dtitle ) {
01144 if ( actmap && actmap->actplayer == 7 ) {
01145 activefontsettings.color = xlattables.a.dark1[textcolor];
01146 showtext2(title, x1 + 4, y1 + 4 );
01147 activefontsettings.color = xlattables.a.light[textcolor];
01148 showtext2(title, x1 + 6, y1 + 6 );
01149 } else {
01150 activefontsettings.color = textcolor + 2;
01151 showtext2(title, x1 + 4, y1 + 4 );
01152 activefontsettings.color = textcolor - 2;
01153 showtext2(title, x1 + 6, y1 + 6 );
01154 }
01155 }
01156
01157 activefontsettings.color = textcolor;
01158 showtext2(title, x1 + 5, y1 + 5 );
01159 starty = 40;
01160 }
01161 }
01162 if (windowstyle & dlg_in3d )
01163 rahmen(true,x1 + 5,y1 + starty,x1 + xsize - 5,y1 + ysize - 5);
01164
01165 pb = firstbutton;
01166 while (pb != NULL) {
01167 if (pb->status) {
01168 if (pb->active)
01169 enablebutton(pb->id);
01170 else
01171 disablebutton(pb->id);
01172 }
01173 pb = pb->next;
01174 }
01175 }
01176
01177
01178 void tdialogbox::buildgraphics(void)
01179 {
01180
01181 if ( x1 == -1 )
01182 x1 = ( agmp->resolutionx - xsize ) / 2;
01183 else
01184 if ( x1 + xsize < 640 )
01185 x1 += (agmp->resolutionx - 640) / 2;
01186
01187 if ( y1 == -1 )
01188 y1 = ( agmp->resolutiony - ysize ) / 2;
01189 else
01190 if ( y1 + ysize < 480 )
01191 y1 += (agmp->resolutiony - 480) / 2;
01192
01193 if ( xsize == -1)
01194 xsize = agmp->resolutionx - xsize*2;
01195 if ( ysize == -1)
01196 ysize = agmp->resolutiony - ysize*2;
01197
01198 if ( pcgo )
01199 delete pcgo;
01200 pcgo = new collategraphicoperations ( x1, y1, x1 + xsize, y1 + ysize );
01201
01202 if (windowstyle & dlg_notitle )
01203 if (windowstyle & dlg_wintitle )
01204 windowstyle ^= dlg_wintitle;
01205
01206 ms = getmousestatus();
01207 if (ms == 2)
01208 mousevisible(false);
01209
01210 if ( !(dlg_mode & 2) ) {
01211 tp = asc_malloc ( imagesize (x1,y1,x1 + xsize,y1 + ysize ) );
01212 getimage(x1,y1,x1 + xsize,y1 + ysize,tp);
01213 imagesaved = true;
01214 }
01215
01216 if ( dlg_mode & 1 ) {
01217 paint ();
01218 } else {
01219 redraw ();
01220 }
01221
01222 rebuildtaborder();
01223 activefontsettings.color = textcolor;
01224 boxstatus = 2;
01225
01226
01227
01228
01229 }
01230
01231
01232
01233 void tdialogbox::done(void)
01234 {
01235 pbutton pb;
01236 pbutton pb2;
01237
01238 if ( boxstatus ) {
01239 ms = getmousestatus();
01240 if (ms == 2)
01241 mousevisible(false);
01242 pb = firstbutton;
01243 while (pb != NULL) {
01244 pb2 = pb->next;
01245 delete ( pb );
01246 pb = pb2;
01247 }
01248
01249 if (imagesaved) {
01250 if ( first == this )
01251 ::repaintDisplay();
01252 else
01253 putimage(x1,y1,tp);
01254 asc_free ( tp );
01255 }
01256 npop( activefontsettings );
01257 if (ms == 2)
01258 mousevisible(true);
01259 }
01260 boxstatus = 0;
01261 }
01262
01263
01264 void tdialogbox::execbutton( pbutton pb, char mouse )
01265 {
01266 int t, l;
01267 Uint16 *pw, *pw2;
01268
01269
01270 if (mouse == false) {
01271 if (pb->art == 0) {
01272 if ((pb->style == 1) || (pb->style == 2))
01273 buttonpressed(pb->id);
01274 }
01275 if (pb->art == 3)
01276 toggleswitch(pb);
01277 }
01278 else {
01279 if (pb->art == 0) {
01280 if (pb->style == 1) {
01281 newknopfdruck(x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2);
01282 if (knopfsuccessful)
01283 buttonpressed(pb->id);
01284 }
01285 if (pb->style == 2) {
01286 mousevisible(false);
01287 pb->pressed = 1;
01288 pb->newpressed = 1;
01289 newknopfdruck4(x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2);
01290 mousevisible(true);
01291 t = ticker;
01292 buttonpressed(pb->id);
01293 pb->newpressed = 2;
01294 while ((mouseparams.x >= x1 + pb->x1) && (mouseparams.x <= x1 + pb->x2) && (mouseparams.y >= y1 + pb->y1) && (mouseparams.y <= y1 + pb->y2) && (mouseparams.taste & 1)) {
01295 if (ticker - t > pb->scrollspeed ) {
01296 t = ticker;
01297 buttonpressed(pb->id);
01298 }
01299 releasetimeslice();
01300 }
01301 mousevisible(false);
01302 newknopfdruck3(x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2);
01303 pb->newpressed = 0;
01304 pb->pressed = 0;
01305 mousevisible(true);
01306 }
01307
01308 }
01309 if (pb->art == 3) {
01310 toggleswitch(pb);
01311 do {
01312 releasetimeslice();
01313 } while (!(mouseparams.taste == 0));
01314 }
01315
01316 if (pb->art == 5) {
01317 pw = (Uint16*) pb->data;
01318 pw2 = (Uint16*) pb->data2;
01319
01320 l = pb->y2 - pb->y1 - 2;
01321
01322 int xb1 = x1 + pb->x1;
01323 int yb1 = y1 + pb->y1;
01324 int xb2 = x1 + pb->x2;
01325 int yb2 = y1 + pb->y2;
01326
01327
01328 if ( mouseparams.y >= yb1 + 1 + l * *pw / *pw2 && mouseparams.y <= yb1 + 1 + l * (*pw + pb->max) / *pw2) {
01329 char mss = getmousestatus ();
01330 if (mss == 2)
01331 mousevisible(false);
01332
01333 int ys1 = yb1 + 1 + l * *pw / *pw2;
01334 int ys1a = ys1;
01335 int ys1b = ys1a;
01336 int ysd = yb1 + 1 + l * (*pw + pb->max) / *pw2 - ys1;
01337 rahmen(true, xb1 + 1, ys1,
01338 xb2 - 1, ys1 + ysd);
01339 int mousestarty = mouseparams.y;
01340
01341 mousevisible( true );
01342
01343 while (mouseparams.taste & 1) {
01344 int i = mouseparams.y - mousestarty ;
01345 ys1 = ys1a + i;
01346 if ( ys1 <= yb1)
01347 ys1 = yb1+1;
01348 if ( ys1 + ysd >= yb2 )
01349 ys1 = yb2 - ysd - 1;
01350
01351 if ( ys1 != ys1b ) {
01352 collategraphicoperations cgo ( x1 + pb->x1, y1 + pb->y1, x1 + pb->x2, y1 + pb->y2 );
01353 ys1b = ys1;
01354
01355 mousevisible(false);
01356 paintsurface2(x1 + pb->x1 + 1,y1 + pb->y1 + 1,x1 + pb->x2 - 1,y1 + pb->y2 - 1 );
01357 rahmen(true, xb1 + 1, ys1, xb2 - 1, ys1 + ysd);
01358 cgo.off();
01359 int j = (ys1 - yb1 - 1) * (*pw2) / l;
01360 if (j != *pw) {
01361 *pw = j;
01362 buttonpressed(pb->id);
01363 }
01364 mousevisible( true );
01365 }
01366 releasetimeslice();
01367 }
01368 mousevisible( false );
01369 showbutton( pb->id );
01370 if (mss == 2)
01371 mousevisible(true);
01372 } else {
01373
01374 l = *pw;
01375 t = mouseparams.y - (pb->y1 + y1);
01376 *pw = (10 * t * (*pw2 - pb->max) / (pb->y2 - pb->y1 - 2) + 5) / 10;
01377 if (*pw != l) {
01378 l = getmousestatus();
01379 if (l == 2)
01380 mousevisible(false);
01381 showbutton(pb->id);
01382 buttonpressed(pb->id);
01383 if (l == 2)
01384 mousevisible(true);
01385 }
01386 }
01387 }
01388
01389 if (pb->art == 6) {
01390
01391 int height = pb->entrynum * 25 + 10;
01392 int starty = y1 + pb->y2;
01393 if ( starty + height > agmp->resolutiony )
01394 starty = agmp->resolutiony - height;
01395
01396 mousevisible(false);
01397
01398 int* pos = (int*) pb->data ;
01399
01400 activefontsettings.font = schriften.smallarial;
01401 activefontsettings.background = lightgray;
01402 activefontsettings.justify = lefttext;
01403 activefontsettings.length = (Uint16) (pb->x2 - pb->x1 - 20 );
01404
01405 void* buf = asc_malloc ( imagesize ( x1 + pb->x1, starty, x1 + pb->x2, starty + height ));
01406 getimage( x1 + pb->x1, starty, x1 + pb->x2, starty + height, buf );
01407
01408 bar ( x1 + pb->x1, starty, x1 + pb->x2, starty + height, lightgray );
01409 rectangle ( x1 + pb->x1, starty, x1 + pb->x2, starty + height, black );
01410
01411 bool first = true;
01412 int oldpos = *pos;
01413
01414 mousevisible(true);
01415 do {
01416 int p = (mouseparams.y - starty - 5);
01417 if ( p < 0 )
01418 p = -1;
01419 else
01420 p /= 25;
01421
01422 if ( (p >= 0 && p < pb->entrynum ) || first )
01423 if ( p != *pos || first ) {
01424 if ( p != *pos && p >= 0 && p < pb->entrynum )
01425 *pos = p;
01426 for ( int i = 0; i < pb->entrynum; ++i ) {
01427 if ( i == *pos )
01428 activefontsettings.color = textcolor;
01429 else
01430 activefontsettings.color = black ;
0143