/source/dlg_box.cpp
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
- /*! \file dlg_box.cpp
- \brief Some basic classes from which all of ASC's dialogs are derived
- */
- /*
- This file is part of Advanced Strategic Command; http://www.asc-hq.de
- Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- Boston, MA 02111-1307 USA
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdarg.h>
- #include <ctype.h>
- #include <cstring>
- #include <iostream>
- #include "typen.h"
- #include "basegfx.h"
- #include "newfont.h"
- #include "spfst.h"
- #include "loaders.h"
- #include "misc.h"
- #include "events.h"
- #include "stack.h"
- #include "dlg_box.h"
- #include "paradialog.h"
- #include "widgets/textrenderer.h"
- #include "spfst-legacy.h"
- #ifdef _WIN32_
- #include <windows.h>
- #include <winuser.h>
- #endif
- char strrstring[200];
- void strrd8d(int l, char* s)
- {
- itoa ( l / minmalq, s, 10);
- }
- void strrd8u(int l, char* s)
- {
- itoa ( (l + minmalq - 1) / minmalq, s, 10);
- }
- void strrd8n(int l, char* s)
- {
- itoa ( (l + minmalq/2) / minmalq, s, 10);
- }
- char* strrrd8d(int l)
- {
- itoa ( l / minmalq, strrstring, 10);
- return strrstring;
- }
- char* strrrd8u(int l)
- {
- itoa ( (l + minmalq - 1) / minmalq, strrstring, 10);
- return strrstring;
- }
- char* strrrd8n(int l)
- {
- itoa ( (l + minmalq/2) / minmalq, strrstring, 10);
- return strrstring;
- }
- void *dialogtexture = NULL;
- int actdisplayedmessage = 0;
- long int lastdisplayedmessageticker = 0xffffff;
- tvirtualscreenbuf virtualscreenbuf;
- tvirtualscreenbuf :: tvirtualscreenbuf ( void )
- {
- buf = NULL;
- size = 0;
- }
- void tvirtualscreenbuf:: init ( void )
- {
- size = hgmp->bytesperscanline * hgmp->resolutiony;
- buf = malloc( size );
- }
- tvirtualscreenbuf:: ~tvirtualscreenbuf ()
- {
- free( buf );
- buf = NULL;
- }
- char getletter( const char * s)
- {
- const char* c = s;
- while ( *c && (*c != 126 ))
- c++;
- if (*c == '~' ) {
- c++;
- return *c;
- } else {
- return 0;
- } /* endif */
- }
- collategraphicoperations* tdialogbox::pcgo = NULL;
- tdialogbox::tdialogbox()
- {
- eventQueue = setEventRouting ( false, true );
- npush ( activefontsettings );
- activefontsettings.font = schriften.smallarial;
- activefontsettings.color = black;
- activefontsettings.background = 255;
- activefontsettings.markcolor = red;
- virtualbufoffset = 0;
- boxstatus = 0;
- dlg_mode = 0;
- int rdw = 0;
- if ( first ) {
- pdialogbox rn = first;
- rdw &= rn->getcapabilities() & 1;
- while ( rn->next ) {
- rn = rn->next;
- rdw &= rn->getcapabilities() & 1;
- }
- prev = rn;
- rn->next = this;
- } else {
- first = this;
- prev = NULL;
- }
- next = NULL;
- if ( rdw )
- dlg_mode |= 2;
- }
- int tdialogbox::getcapabilities ( void )
- {
- return 0;
- }
- extern void repaintdisplay ( void );
- void tdialogbox::repaintdisplay( void )
- {/*
- int ms = getmousestatus();
- if ( ms == 2 )
- mousevisible ( false );
- npush ( *agmp );
- npush ( *hgmp );
- hgmp->linearaddress = (PointerSizedInt) virtualscreenbuf.buf;
- hgmp->windowstatus = 100;
- *agmp = *hgmp;
-
- ::repaintdisplay();
- npop ( *hgmp );
- setvirtualframebuf();
- if ( first )
- first->setclipping();
- *agmp = *hgmp;
- putspritetexture ( 0, 0, hgmp->resolutionx-1, hgmp->resolutiony-1, virtualscreenbuf.buf );
- npop ( *agmp );
- if ( ms == 2 )
- mousevisible ( true );
- */
- }
- void tdialogbox::redrawall ( void )
- {
- paint();
- if ( prev )
- prev->redrawall();
- else
- repaintDisplay();
- }
- void tdialogbox::redrawall2 ( int xx1, int yy1, int xx2, int yy2 )
- {
- paint ();
- if ( x1 > xx1 || y1 > yy1 || x1+xsize < xx2 || y1+ysize < yy2 ) {
- if ( prev )
- prev->redrawall2 ( xx1, yy1, xx2, yy2 );
- else
- repaintDisplay();
- }
- }
- pdialogbox tdialogbox::first = NULL;
- void tdialogbox::setvirtualframebuf ( void )
- {
- agmp->linearaddress = (PointerSizedInt) virtualscreenbuf.buf;
- agmp->windowstatus = 100;
- agmp->scanlinelength = hgmp->scanlinelength;
- }
- void tdialogbox::setclipping ( void )
- {
- bar ( x1, y1, x1 + xsize, y1 + ysize, 255 );
- if ( next )
- next->setclipping ( );
- }
- void tdialogbox::copyvirtualframebuf ( void )
- {
- ms = getmousestatus();
- if (ms == 2)
- mousevisible(false);
- npush ( *agmp );
- void* buf = (void*) agmp->linearaddress;
- *agmp = *hgmp;
- putspritetexture ( x1, y1, x1 + xsize, y1 + ysize, buf );
- /*
- for ( int y = y1; y <= y1 + ysize; y++ )
- for ( int x = x1; x <= x1 + xsize; x++ ) {
- char c = buf[ virtualbufoffset + y * agmp->scanlinelength + x ];
- char d = buf[ virtualbufoffset + y * agmp->scanlinelength + x+1 ];
- if ( d != 255 )
- putpixel ( x+1, y, lightblue );
- if ( c != 255 )
- putpixel ( x, y, c );
- }
- */
- npop ( *agmp );
- if (ms == 2)
- mousevisible(true);
- }
- void tdialogbox::paint ( void )
- {
- setvirtualframebuf();
- redraw();
- if ( next )
- next->setclipping();
- copyvirtualframebuf();
- *agmp = *hgmp;
- }
- int getplayercolor ( int i )
- {
- if ( actmap ) {
- int textcolor = i * 8 + 21;
- if ( i == 7 || i == 2 )
- textcolor += 1;
- return textcolor;
- } else
- return 20;
- }
- void tdialogbox::init(void)
- {
- imagesaved = false;
- if ( actmap && actmap->actplayer != -1 ) {
- textcolor = getplayercolor ( actmap->actplayer );
- }
- else
- textcolor = 20;
- firstbutton = NULL;
- windowstyle = dlg_in3d | dlg_3dtitle;
- x1 = 50;
- xsize = 540;
- y1 = 50;
- ysize = 380;
- starty = 40;
- title = "dialogbox";
- npush( activefontsettings );
- activefontsettings.height = 0;
- activefontsettings.length = 0;
- memset(taborder, 0, sizeof(taborder));
- tabcount = 0;
- markedtab = 0;
- disablecolor = darkgray;
- boxstatus = 1;
- dlg_mode = 0; // |= getcapabilities();
- }
- #include "dlgraph.cpp"
- void tdialogbox::changecoordinates(void)
- {
- /* runerror(211); */
- }
- tdlgengine::pbutton tdlgengine :: getbutton ( int id )
- {
- pbutton pb = firstbutton;
- while ( pb && (pb->id != id))
- pb = pb->next;
- return pb;
- }
- void tdlgengine::buttonpressed(int id)
- {
- pbutton pb;
- int w;
- Uint16 *pw, *pw2;
- pb = firstbutton;
- while ( pb ) {
- if ((pb->art == 5)) { /* Scrollbar */
- pw = (Uint16*) pb->data;
- pw2 = (Uint16*) pb->data2;
- w = *pw;
- if ((pb->id + 1 == id)) {
- if (taste == ct_pup) {
- if (*pw >= pb->max)
- *pw -= pb->max - 1;
- else
- *pw = 0;
- }
- else
- if (taste == ct_pos1) {
- *pw = 0;
- }
- else
- if (*pw > 0) {
- if ( pb->newpressed == 0 ) // Tastatur
- (*pw) --;
- else
- if ( pb->newpressed == 1) {
- (*pw) --;
- pb->lasttick = ticker;
- } else
- if ( pb->newpressed == 2) {
- int dst = ticker - pb->lasttick;
- if ( *pw < dst )
- (*pw) = 0;
- else
- (*pw) -= dst;
- pb->lasttick = ticker;
- }
- }
- }
- if ((pb->id + 2 == id)) {
- if (taste == ct_pdown) {
- if (*pw + (pb->max * 2) - 1 <= *pw2)
- *pw += pb->max - 1;
- else
- *pw = *pw2 - pb->max;
- }
- else
- if (taste == ct_ende) {
- *pw = *pw2 - pb->max;
- }
- else
- if ( *pw + pb->max < *pw2 ) {
- if ( pb->newpressed == 0 ) // Tastatur
- (*pw)++;
- else
- if ( pb->newpressed == 1) {
- (*pw) ++;
- pb->lasttick = ticker;
- } else
- if ( pb->newpressed == 2) {
- int dst = ticker - pb->lasttick;
- if ( *pw + dst + pb->max >= *pw2 )
- *pw = *pw2 - pb->max;
- else
- (*pw) += dst;
- pb->lasttick = ticker;
- }
- }
- }
- if (w != *pw) {
- char mss = getmousestatus();
- if (mss == 2 )
- mousevisible(false);
- showbutton(pb->id);
- buttonpressed(pb->id);
- if (mss == 2 )
- mousevisible(true);
- }
- }
- pb = pb->next;
- }
- }
- void tdlgengine::addbutton( const char * ltxt,
- tmouserect rect1,
- int lart,
- int lstyle,
- int lid,
- char enabled)
- {
- addbutton ( ltxt, rect1.x1, rect1.y1, rect1.x2, rect1.y2, lart, lstyle, lid, enabled );
- }
- const char* emptystring = "";
- void tdlgengine::addbutton( const char * ltxt,
- int lx1,
- int ly1,
- int lx2,
- int ly2,
- int lart,
- int lstyle,
- int lid,
- char enabled)
- {
- pbutton pb;
- char ch;
- pb = firstbutton;
- if (lid <= 0)
- displaymessage("tdialogbox: \n id equal or less then 0\n:%d\n",2, lid);
- while ( pb ) {
- if (pb->id == lid)
- displaymessage("tdialogbox: duplicate button id: %d\n",2, lid);
-
- pb = pb->next;
- }
- pb = new tbutton;
- pb->x1 = lx1;
- pb->x2 = lx2;
- pb->y1 = ly1;
- pb->y2 = ly2;
- pb->style = lstyle;
- pb->id = lid;
- pb->next = firstbutton;
- if ( ltxt )
- pb->text = ltxt;
- else
- pb->text = emptystring;
- pb->art = lart;
- pb->active = enabled;
- pb->status = 1;
- pb->scrollspeed = 30;
- pb->pressed = 0;
- pb->newpressed = 0;
- firstbutton = pb;
- ch = getletter(pb->text);
- if (ch != 0) {
- pb->key[0] = char2key( tolower(ch) );
- pb->keynum = 1;
- }
- else
- pb->keynum = 0;
- pb->markedkeynum = 1;
- pb->markedkey[0] = ct_enter;
- }
- void tdlgengine::addscrollbar(tmouserect rec,
- int* numberofitems,
- int itemsvisible,
- int* actitem,
- int lid,
- int keys)
- {
- addscrollbar ( rec.x1, rec.y1, rec.x2, rec.y2, numberofitems, itemsvisible, actitem, lid, keys );
- }
- void tdialogbox :: bar ( tmouserect rect, int color )
- {
- ::bar ( rect.x1, rect.y1, rect.x2, rect.y2, color );
- }
- void tdialogbox :: bar ( int x1, int y1, int x2, int y2, int color )
- {
- ::bar ( x1, y1, x2, y2, color );
- }
- void tdlgengine::addDropDown( int x1, int y1, int x2, int y2, int ID, const char** entries, int entrynum, int* pos )
- {
- pbutton pb = firstbutton;
- if ( ID <= 0)
- displaymessage("tdialogbox: id equal or less then 0", 2);
- while (pb != NULL) {
- if (pb->id == ID)
- displaymessage("tdialogbox: duplicate button id: %d\n",2, ID);
- pb = pb->next;
- }
- pb = new tbutton;
- pb->x1 = x1;
- pb->x2 = x2;
- pb->y1 = y1;
- pb->y2 = y2;
- pb->style = 0;
- pb->id = ID;
- pb->next = firstbutton;
- pb->text = NULL;
- pb->art = 6;
- pb->active = true;
- pb->status = 1;
- pb->keynum = 0;
- pb->markedkeynum = 0;
- pb->scrollspeed = 30;
- pb->pressed = 0;
- pb->newpressed = 0;
- pb->entries = entries;
- pb->entrynum = entrynum;
- pb->data = pos;
- firstbutton = pb;
- }
- void tdlgengine::addscrollbar(int lx1,
- int ly1,
- int lx2,
- int ly2,
- int* numberofitems,
- int itemsvisible,
- int* actitem,
- int lid,
- int keys)
- {
- pbutton pb;
- pb = firstbutton;
- if (lid <= 0)
- displaymessage("tdialogbox: id equal or less then 0", 2);
- while (pb != NULL) {
- if (pb->id == lid)
- displaymessage("tdialogbox: duplicate button id: %d\n",2, lid);
- pb = pb->next;
- }
- pb = new tbutton;
- pb->x1 = lx1;
- pb->x2 = lx2;
- pb->y1 = ly1 + 13;
- pb->y2 = ly2 - 13;
- pb->style = 0;
- pb->id = lid;
- pb->next = firstbutton;
- pb->text = NULL;
- pb->art = 5;
- pb->active = true;
- pb->status = 1;
- pb->keynum = 0;
- pb->markedkeynum = 0;
- pb->scrollspeed = 30;
- pb->pressed = 0;
- pb->newpressed = 0;
- firstbutton = pb;
- addbutton("",lx1+1, ly1 + 1 , lx2 - 1, ly1 + 10, 0, 2, lid + 1, true);
- addbutton("",lx1+1, ly2 - 10 , lx2 - 1, ly2 - 1, 0, 2, lid + 2, true);
- if (keys == 2) {
- addmarkedkey(lid + 1,ct_up);
- addmarkedkey(lid + 1,ct_pup);
- addmarkedkey(lid + 1,ct_pos1);
- addmarkedkey(lid + 2,ct_down);
- addmarkedkey(lid + 2,ct_pdown);
- addmarkedkey(lid + 2,ct_ende);
- }
- if (keys == 1) {
- addkey(lid + 1,ct_up);
- addkey(lid + 1,ct_pup);
- addkey(lid + 1,ct_pos1);
- addkey(lid + 2,ct_down);
- addkey(lid + 2,ct_pdown);
- addkey(lid + 2,ct_ende);
- }
- pb->data = actitem;
- pb->data2 = numberofitems;
- pb->max = itemsvisible;
- }
- void tdialogbox::rebuildtaborder(void)
- {
- pbutton pb = firstbutton;
- int i = 0;
- ttaborder b;
- tabcount = 0;
- while (pb != NULL) {
- if ((pb->art >= 0) && (pb->art <= 3))
- if ((pb->status == 1) && pb->active) {
- tabcount++;
- taborder[tabcount].id = pb->id;
- taborder[tabcount].x1 = pb->x1;
- taborder[tabcount].y1 = pb->y1;
- taborder[tabcount].x2 = pb->x2;
- taborder[tabcount].y2 = pb->y2;
- taborder[tabcount].button = pb;
-
- }
- pb = pb->next;
- }
- if (tabcount > 1)
- for (i = 1; i <= tabcount - 1; i++) {
- if ((taborder[i].y1 > taborder[i + 1].y1) || ((taborder[i].y1 == taborder[i + 1].y1) && (taborder[i].x1 > taborder[i + 1].x1)))
- {
- b = taborder[i];
- taborder[i] = taborder[i + 1];
- taborder[i + 1] = b;
- if (i > 1)
- i -= 2;
- }
- }
-
- pbutton pb2 = NULL;
- if (i > 0) {
- if (markedtab > 0)
- pb2 = taborder[i].button;
- }
- showtabmark(markedtab);
- if ( markedtab ) {
- markedtab = 0;
- if (tabcount > 0) {
- for (i = 1; i <= tabcount; i++)
- if (taborder[i].button == pb2)
- markedtab = i;
- }
- }
- showtabmark(markedtab);
- }
- void tdialogbox::showbutton(int id)
- {
- pbutton pb;
- int c;
- char mss = getmousestatus();
- if (mss == 2)
- mousevisible(false);
- pb = firstbutton;
- while (pb != NULL) {
- if (pb->id == id)
- if ( pb->pressed == 0) {
- c = pb->status;
- pb->status = 1;
- if (pb->active)
- enablebutton(id);
- else
- disablebutton(id);
-
- if (pb->art == 5) {
- showbutton ( id + 1);
- showbutton ( id + 2);
- } /* endif */
-
- if (c != 1)
- rebuildtaborder();
- }
- pb = pb->next;
- }
- if (mss == 2)
- mousevisible(true);
- }
- void tdialogbox::hidebutton(int id)
- {
- pbutton pb;
- pb = firstbutton;
- while (pb != NULL) {
- if (pb->id == id) {
- pb->status = 0;
- if (pb->art == 5) {
- hidebutton ( id + 1);
- hidebutton ( id + 2);
- } /* endif */
- }
- pb = pb->next;
- }
- rebuildtaborder();
- }
- void tdlgengine::clearkey ( char id )
- {
- pbutton pb = firstbutton;
- while ( pb ) {
- if ( pb->id == id ) {
- pb->keynum = 0;
- pb->markedkeynum = 0;
- }
- pb = pb->next;
- }
- }
- void tdlgengine::addkey( int id, tkey key )
- {
- pbutton pb = firstbutton;
- while ( pb ) {
- if (pb->id == id) {
- int exist = 0;
- for ( int i = 0; i < pb->keynum; i++ )
- if ( pb->key[i] == key )
- exist++;
- if ( !exist ) {
- pb->key [ pb->keynum ] = key;
- pb->keynum++;
- }
- }
- pb = pb->next;
- }
- }
- void tdlgengine::addmarkedkey(int id, tkey key)
- {
- pbutton pb;
- pb = firstbutton;
- while ( pb ) {
- if (pb->id == id) {
- int exist = 0;
- for ( int i = 0; i < pb->markedkeynum; i++ )
- if ( pb->markedkey[i]== key )
- exist++;
- if ( !exist ) {
- pb->markedkey [ pb->markedkeynum ] = key;
- pb->markedkeynum++;
- }
- }
- pb = pb->next;
- }
- }
- void tdialogbox::setscrollspeed(char id , int speed)
- {
- pbutton pb;
- pb = firstbutton;
- while (pb != NULL) {
- if (pb->id == id) {
- if (pb->art == 5) {
- setscrollspeed( id + 1, speed );
- setscrollspeed( id + 2, speed );
- } else
- pb->scrollspeed = speed;
- }
- pb = pb->next;
- }
- }
- void tdlgengine::addeingabe(int lid,
- void* data,
- int min,
- int max)
- {
- pbutton pb;
- pb = firstbutton;
- while (pb != NULL) {
- if (pb->id == lid) {
- pb->data = data;
- if ( min > max ) {
- pb->min = max;
- pb->max = min;
- } else {
- pb->min = min;
- pb->max = max;
- }
- addmarkedkey(pb->id,ct_enter);
- addmarkedkey(pb->id,ct_space);
- }
- pb = pb->next;
- }
- }
- void tdialogbox::enablebutton(int id)
- {
- pbutton pb = firstbutton;
- if ( !pb )
- return;
- while ( pb && pb->id != id )
- pb = pb->next;
- if ( !pb )
- return;
- npush( activefontsettings );
- collategraphicoperations cgo ( x1 + pb->x1, max ( y1 + pb->y1 - 20, 0 ), x1 + pb->x2, y1 + pb->y2 );
- char strng[200];
- activefontsettings.font = schriften.smallarial;
- activefontsettings.justify = lefttext;
- activefontsettings.length = pb->x2 - pb->x1 - 10;
- activefontsettings.markcolor = textcolor - 2;
- activefontsettings.color = textcolor;
- activefontsettings.background = 255;
- if (pb->art == 0) {
- if ((pb->style == 1) || (pb->style == 2))
- newknopf(x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2);
-
- if ( pb->text )
- if (pb->text[0] ) {
- activefontsettings.justify = centertext;
- showtext3( pb->text,x1 + pb->x1,y1 + (pb->y1 + pb->y2) / 2 - activefontsettings.font->height / 2);
- }
- }
- if ((pb->art == 1) || ( pb->art == 2 )) {
- rahmen(true,x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2);
- paintsurface( pb->x1 + 1, pb->y1 + 1, pb->x2 - 1, pb->y2 - 1 );
- if ( pb->text )
- if (pb->text[0] ) {
- if ( pb->style != 3 ) {
- showtext3(pb->text,x1 + pb->x1,y1 + pb->y1 - activefontsettings.font->height);
- } else {
- npush ( activefontsettings.length );
- activefontsettings.length = 300;
- cgo.off();
- showtext3(pb->text,x1 + pb->x2 + 10,y1 + pb->y1 );
- cgo.on();
- npop ( activefontsettings.length );
- }
- }
- if (pb->art == 1)
- showtext2((char*) pb->data , x1 + pb->x1 + 5,y1 + pb->y1 + 2);
-
- if (pb->art == 2) {
- if (pb->max <= 255 && pb->min >= 0) {
- char* pbt = (char*) pb->data;
- itoa ( *pbt, strng, 10 );
- showtext2( strng, x1 + pb->x1 + 5,y1 + pb->y1 + 2);
- }
- else
- if (pb->max <= 65535 && pb->min >= 0) {
- Uint16* pw = (Uint16*) pb->data;
- itoa ( *pw, strng, 10 );
- showtext2(strng, x1 + pb->x1 + 5,y1 + pb->y1 + 2);
- }
- else {
- int* pl = (int*) pb->data;
- itoa ( *pl, strng, 10 );
- showtext2(strng, x1 + pb->x1 + 5,y1 + pb->y1 + 2);
- }
- }
- }
- if (pb->art == 3) {
- rahmen(true,x1 + pb->x1,y1 + pb->y1,x1 + pb->x1 + (pb->y2 - pb->y1),y1 + pb->y2);
- showtext3(pb->text,x1 + pb->x1 + (pb->y2 - pb->y1) + 5,y1 + (pb->y1 + pb->y2 - activefontsettings.font->height) / 2);
- char* pbl = (char*) pb->data;
- int cl;
- if (*pbl)
- cl = pb->min;
- else
- cl = pb->max;
- line(x1 + pb->x1,y1 + pb->y1,x1 + pb->x1 + (pb->y2 - pb->y1),y1 + pb->y2, cl);
- line(x1 + pb->x1 + (pb->y2 - pb->y1),y1 + pb->y1,x1 + pb->x1,y1 + pb->y2, cl);
- }
- if (pb->art == 5) { // Scrollbar
- Uint16* pw = (Uint16*) pb->data;
- Uint16* pw2 =(Uint16*) pb->data2;
- rahmen(true,x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2);
- paintsurface2(x1 + pb->x1 + 1,y1 + pb->y1 + 1,x1 + pb->x2 - 1,y1 + pb->y2 - 1 );
- // if (pb->max <= *pw2) {
- int l = pb->y2 - pb->y1 - 2;
- rahmen(false, x1 + pb->x1 + 1, y1 + pb->y1 + 1 + l * *pw / *pw2,
- x1 + pb->x2 - 1, y1 + pb->y1 + 1 + l * (*pw + pb->max) / *pw2);
- // }
- // else
- // rahmen(true,x1 + pb->x1 + 1,y1 + pb->y1 + 1,x1 + pb->x2 - 1,y1 + pb->y2 - 1);
- }
- if ( pb->art == 6 ) {
- bar ( x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2, lightgray );
- rahmen(true,x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2);
- int pos = *( (int*) pb->data );
- if ( pos < 0 || pos >= pb->entrynum )
- fatalError("invalid pos in dropdown",2);
- showtext3(pb->entries[pos], x1 + pb->x1 + (pb->y2 - pb->y1) + 5, y1 + (pb->y1 + pb->y2 - activefontsettings.font->height) / 2);
- line ( x1 + pb->x2 - 20, y1 + pb->y1 + 4, x1 + pb->x2 - 10, y1 + pb->y1 + 4, textcolor );
- line ( x1 + pb->x2 - 20, y1 + pb->y1 + 4, x1 + pb->x2 - 15, y1 + pb->y1 + 14, textcolor );
- line ( x1 + pb->x2 - 10, y1 + pb->y1 + 4, x1 + pb->x2 - 15, y1 + pb->y1 + 14, textcolor );
- }
- pb->active = true;
- npop( activefontsettings );
- rebuildtaborder();
- }
- void tdialogbox::disablebutton(int id)
- {
- pbutton pb;
- int *pl;
- Uint16 *pw, *pw2;
- char *pbt;
- char *pbl;
- char* s;
- char* t;
- int l;
- char cl;
- pb = firstbutton;
- if ( !pb )
- return;
- while ((pb != NULL) && (pb->id != id))
- pb = pb->next;
- if (pb == NULL)
- return;
- npush(activefontsettings);
- activefontsettings.font = schriften.smallarial;
- activefontsettings.justify = lefttext;
- activefontsettings.length = pb->x2 - pb->x1 - 10;
- activefontsettings.color = disablecolor;
-
- s = new char[200];
- strcpy(s, pb->text);
- t = strchr( s, 126 );
- while ( t != NULL ) {
- do {
- t[0] = t[1];
- t++;
- } while ( t[0] !=0 ) ;
- t = strchr( s, 126 );
- }
- if (pb->art == 0) {
- if (pb->text != NULL)
- if (pb->text[0] != 0) {
- activefontsettings.justify = centertext;
- showtext2(s, x1 + pb->x1, y1 + (pb->y1 + pb->y2) / 2 - activefontsettings.font->height / 2);
- }
- if ((pb->style == 1) || (pb->style == 2)) {
- rectangle(x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2,disablecolor);
- rectangle(x1 + pb->x1 - 1,y1 + pb->y1 - 1,x1 + pb->x2 + 1,y1 + pb->y2 + 1,disablecolor);
- }
- }
- if ((pb->art == 1) || (pb->art == 2)) {
- rectangle(x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2,disablecolor);
- if (pb->text != NULL)
- if (pb->text[0] != 0) {
- if ( pb->style != 3 )
- showtext2(pb->text,x1 + pb->x1,y1 + pb->y1 - activefontsettings.font->height);
- else {
- npush ( activefontsettings );
- activefontsettings.length = 0;
- showtext2(pb->text,x1 + pb->x2 + 10,y1 + pb->y1 );
- npop ( activefontsettings );
- }
- }
- if (pb->art == 1) {
- showtext2( (char*)pb->data,x1 + pb->x1 + 5,y1 + pb->y1 + 2);
- }
- if (pb->art == 2) {
- if (pb->max <= 255 && pb->min >= 0) {
- pbt = (char*) pb->data;
- itoa ( *pbt, s, 10 );
- showtext2(s,x1 + pb->x1 + 5,y1 + pb->y1 + 2);
- }
- else
- if (pb->max <= 65535 && pb->min >= 0) {
- pw = (Uint16*) pb->data;
- itoa ( *pw, s , 10);
- showtext2(s, x1 + pb->x1 + 5,y1 + pb->y1 + 2);
- }
- else {
- pl = (int*) pb->data;
- itoa ( *pl, s, 10);
- showtext2(s, x1 + pb->x1 + 5,y1 + pb->y1 + 2);
- }
- }
- }
- if (pb->art == 3) {
- rectangle(x1 + pb->x1,y1 + pb->y1,x1 + pb->x1 + (pb->y2 - pb->y1),y1 + pb->y2,disablecolor);
- showtext2(s,x1 + pb->x1 + (pb->y2 - pb->y1) + 5,y1 + (pb->y1 + pb->y2 - activefontsettings.font->height) / 2);
- pbl = (char*) pb->data;
- if (*pbl)
- cl = disablecolor;
- else
- cl = pb->max;
- line(x1 + pb->x1,y1 + pb->y1,x1 + pb->x1 + (pb->y2 - pb->y1),y1 + pb->y2, cl);
- line(x1 + pb->x1 + (pb->y2 - pb->y1),y1 + pb->y1,x1 + pb->x1,y1 + pb->y2, cl);
- }
- if (pb->art == 5) {
- pw = (Uint16*) pb->data;
- pw2 = (Uint16*) pb->data2;
- // waitretrace();
- rectangle(x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2,disablecolor);
- paintsurface2(x1 + pb->x1 + 1,y1 + pb->y1 + 1,x1 + pb->x2 - 1,y1 + pb->y2 - 1);
- if (pb->max <= *pw2) {
- l = pb->y2 - pb->y1 - 2;
- 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);
- }
- else
- rectangle(x1 + pb->x1 + 1,y1 + pb->y1 + 1,x1 + pb->x2 - 1,y1 + pb->y2 - 1,disablecolor);
- }
- delete[] s;
- pb->active = false;
- npop( activefontsettings );
- rebuildtaborder();
- }
- void tdialogbox::redraw(void)
- {
- pbutton pb;
- knopf(x1,y1,x1 + xsize,y1 + ysize);
- rahmen(false, x1,y1,x1 + xsize, y1 + ysize);
- activefontsettings.color = white;
- activefontsettings.background = 255;
- activefontsettings.font = schriften.smallarial;
- activefontsettings.justify = centertext;
- activefontsettings.length = xsize - 10;
- activefontsettings.height = 00;
-
- if (windowstyle & dlg_wintitle ) {
- starty = 25;
- rahmen(true,x1 + 5,y1 + 3,x1 + xsize - 5,y1 + 20);
- bar(x1 + 6,y1 + 4,x1 + xsize - 6,y1 + 19,blue);
- activefontsettings.color = textcolor;
- showtext2(title, x1 + 5,y1 + 3);
- }
- else {
- starty = 5;
- if ((windowstyle & dlg_notitle) == 0)
- if (title != NULL)
- if (title[0] ) {
- activefontsettings.font = schriften.large;
- if ( windowstyle & dlg_3dtitle ) {
- if ( actmap && actmap->actplayer == 7 ) {
- activefontsettings.color = xlattables.a.dark1[textcolor];
- showtext2(title, x1 + 4, y1 + 4 );
- activefontsettings.color = xlattables.a.light[textcolor];
- showtext2(title, x1 + 6, y1 + 6 );
- } else {
- activefontsettings.color = textcolor + 2;
- showtext2(title, x1 + 4, y1 + 4 );
- activefontsettings.color = textcolor - 2;
- showtext2(title, x1 + 6, y1 + 6 );
- }
- }
- activefontsettings.color = textcolor;
- showtext2(title, x1 + 5, y1 + 5 );
- starty = 40;
- }
- }
- if (windowstyle & dlg_in3d )
- rahmen(true,x1 + 5,y1 + starty,x1 + xsize - 5,y1 + ysize - 5);
- pb = firstbutton;
- while (pb != NULL) {
- if (pb->status) {
- if (pb->active)
- enablebutton(pb->id);
- else
- disablebutton(pb->id);
- }
- pb = pb->next;
- }
- }
- void tdialogbox::buildgraphics(void)
- {
- if ( x1 == -1 )
- x1 = ( agmp->resolutionx - xsize ) / 2;
- else
- if ( x1 + xsize < 640 )
- x1 += (agmp->resolutionx - 640) / 2;
- if ( y1 == -1 )
- y1 = ( agmp->resolutiony - ysize ) / 2;
- else
- if ( y1 + ysize < 480 )
- y1 += (agmp->resolutiony - 480) / 2;
- if ( xsize == -1)
- xsize = agmp->resolutionx - xsize*2;
- if ( ysize == -1)
- ysize = agmp->resolutiony - ysize*2;
- if ( pcgo )
- delete pcgo;
- pcgo = new collategraphicoperations ( x1, y1, x1 + xsize, y1 + ysize );
- if (windowstyle & dlg_notitle )
- if (windowstyle & dlg_wintitle )
- windowstyle ^= dlg_wintitle;
- ms = getmousestatus();
- if (ms == 2)
- mousevisible(false);
- if ( !(dlg_mode & 2) ) {
- tp = malloc ( imagesize (x1,y1,x1 + xsize,y1 + ysize ) );
- getimage(x1,y1,x1 + xsize,y1 + ysize,tp);
- imagesaved = true;
- }
- if ( dlg_mode & 1 ) {
- paint ();
- } else {
- redraw ();
- }
- rebuildtaborder();
- activefontsettings.color = textcolor;
- boxstatus = 2;
- // if (ms == 2)
- // mousevisible(true);
- }
- void tdialogbox::done(void)
- {
- pbutton pb;
- pbutton pb2;
- if ( boxstatus ) {
- ms = getmousestatus();
- if (ms == 2)
- mousevisible(false);
- pb = firstbutton;
- while (pb != NULL) {
- pb2 = pb->next;
- delete ( pb );
- pb = pb2;
- }
- if (imagesaved) {
- if ( first == this )
- ::repaintDisplay();
- else
- putimage(x1,y1,tp);
- free ( tp );
- }
- npop( activefontsettings );
- if (ms == 2)
- mousevisible(true);
- }
- boxstatus = 0;
- }
- void tdialogbox::execbutton( pbutton pb, char mouse )
- {
- int t, l;
- Uint16 *pw, *pw2;
- if (mouse == false) {
- if (pb->art == 0) {
- if ((pb->style == 1) || (pb->style == 2))
- buttonpressed(pb->id);
- }
- if (pb->art == 3)
- toggleswitch(pb);
- }
- else {
- if (pb->art == 0) {
- if (pb->style == 1) {
- newknopfdruck(x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2);
- if (knopfsuccessful)
- buttonpressed(pb->id);
- }
- if (pb->style == 2) {
- mousevisible(false);
- pb->pressed = 1;
- pb->newpressed = 1;
- newknopfdruck4(x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2);
- mousevisible(true);
- t = ticker;
- buttonpressed(pb->id);
- pb->newpressed = 2;
- while ((mouseparams.x >= x1 + pb->x1) && (mouseparams.x <= x1 + pb->x2) && (mouseparams.y >= y1 + pb->y1) && (mouseparams.y <= y1 + pb->y2) && (mouseparams.taste & 1)) {
- if (ticker - t > pb->scrollspeed ) {
- t = ticker;
- buttonpressed(pb->id);
- }
- releasetimeslice();
- }
- mousevisible(false);
- newknopfdruck3(x1 + pb->x1,y1 + pb->y1,x1 + pb->x2,y1 + pb->y2);
- pb->newpressed = 0;
- pb->pressed = 0;
- mousevisible(true);
- }
- }
- if (pb->art == 3) {
- toggleswitch(pb);
- do {
- releasetimeslice();
- } while (!(mouseparams.taste == 0));
- }
- if (pb->art == 5) { // Scrollbar
- pw = (Uint16*) pb->data;
- pw2 = (Uint16*) pb->data2;
- l = pb->y2 - pb->y1 - 2;
- int xb1 = x1 + pb->x1;
- int yb1 = y1 + pb->y1;
- int xb2 = x1 + pb->x2;
- int yb2 = y1 + pb->y2;
- if ( mouseparams.y >= yb1 + 1 + l * *pw / *pw2 && mouseparams.y <= yb1 + 1 + l * (*pw + pb->max) / *pw2) {
- char mss = getmousestatus ();
- if (mss == 2)
- mousevisible(false);
- int ys1 = yb1 + 1 + l * *pw / *pw2;
- int ys1a = ys1;
- int ys1b = ys1a;
- int ysd = yb1 + 1 + l * (*pw + pb->max) / *pw2 - ys1;
- rahmen(true, xb1 + 1, ys1,
- xb2 - 1, ys1 + ysd);
- int mousestarty = mouseparams.y;
- mousevisible( true );
- while (mouseparams.taste & 1) {
- int i = mouseparams.y - mousestarty ;
- ys1 = ys1a + i;
- if ( ys1 <= yb1)
- ys1 = yb1+1;
- if ( ys1 + ysd >= yb2 )
- ys1 = yb2 - ysd - 1;
- if ( ys1 != ys1b ) {
- collategraphicoperations cgo ( x1 + pb->x1, y1 + pb->y1, x1 + pb->x2, y1 + pb->y2 );
- ys1b = ys1;
- // waitretrace();
- mousevisible(false);
- paintsurface2(x1 + pb->x1 + 1,y1 + pb->y1 + 1,x1 + pb->x2 - 1,y1 + pb->y2 - 1 );
- rahmen(true, xb1 + 1, ys1, xb2 - 1, ys1 + ysd);
- cgo.off();
- int j = (ys1 - yb1 - 1) * (*pw2) / l;
- if (j != *pw) {
- *pw = j;
- buttonpressed(pb->id);
- }
- mousevisible( true );
- }
- releasetimeslice();
- }
- mousevisible( false );
- showbutton( pb->id );
- if (mss == 2)
- mousevisible(true);
- } else {
- l = *pw;
- t = mouseparams.y - (pb->y1 + y1);
- *pw = (10 * t * (*pw2 - pb->max) / (pb->y2 - pb->y1 - 2) + 5) / 10;
- if (*pw != l) {
- l = getmousestatus();
- if (l == 2)
- mousevisible(false);
- showbutton(pb->id);
- buttonpressed(pb->id);
- if (l == 2)
- mousevisible(true);
- }
- }
- }
- if (pb->art == 6) {
- int height = pb->entrynum * 25 + 10;
- int starty = y1 + pb->y2;
- if ( starty + height > agmp->resolutiony )
- starty = agmp->resolutiony - height;
- mousevisible(false);
- int* pos = (int*) pb->data ;
- activefontsettings.font = schriften.smallarial;
- activefontsettings.background = lightgray;
- activefontsettings.justify = lefttext;
- activefontsettings.length = (Uint16) (pb->x2 - pb->x1 - 20 );
- void* buf = malloc ( imagesize ( x1 + pb->x1, starty, x1 + pb->x2, starty + height ));
- getimage( x1 + pb->x1, starty, x1 + pb->x2, starty + height, buf );
- bar ( x1 + pb->x1, starty, x1 + pb->x2, starty + height, lightgray );
- rectangle ( x1 + pb->x1, starty, x1 + pb->x2, starty + height, black );
- bool first = true;
- int oldpos = *pos;
- mousevisible(true);
- do {
- int p = (mouseparams.y - starty - 5);
- if ( p < 0 )
- p = -1;
- else
- p /= 25;
- if ( (p >= 0 && p < pb->entrynum ) || first )
- if ( p != *pos || first ) {
- if ( p != *pos && p >= 0 && p < pb->entrynum )
- *pos = p;
- for ( int i = 0; i < pb->entrynum; ++i ) {
- if ( i == *pos )
- activefontsettings.color = textcolor;
- else
- activefontsettings.color = black ;
- showtext2 ( pb->entries[i], x1 + pb->x1 + 5, starty + i * 25 + 5 );
- }
- }
- releasetimeslice();
- first = false;
- } 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)) ;
- mousevisible(false);
- putimage ( x1 + pb->x1, starty, buf );
- free ( buf );
- mousevisible(true);
- enablebutton( pb->id );
- if ( oldpos != *pos )
- buttonpressed( pb->id );
- }
- if ( pb->art > 10 ) {
- buttonpressed(pb->id);
- while ( mouseinrect ( x1 + pb->x1 , y1 + pb->y1 , x1 + pb->x2 , y1 + pb->y2 ) && ( mouseparams.taste & 1))
- releasetimeslice();
- }
- /*
- rahmen(true,x1+pb^.x1,y1+pb^.y1,x1+pb^.x2,y1+pb^.y2);
- nbar(x1+pb^.x1+1,y1+pb^.y1+1,x1+pb^.x2-1,y1+pb^.y2-1,dblue);
- rahmen(false,x1 + pb^.x1+1,y1 + pb^.y1+1+ l * pw^ div pw2^ ,
- x1 + pb^.x2-1,y1 + pb^.y1+1+ l * (pw^+ pb^.max) div pw2^); */
- }
- if ((pb->art == 1) || (pb->art == 2)) {
- editfield(pb);
- buttonpressed(pb->id);
- }
- }
- void tdialogbox::showtabmark(int b)
- {
- if (b != 0)
- xorrectangle(x1 + taborder[b].x1 - 2,y1 + taborder[b].y1 - 2,x1 + taborder[b].x2 + 2,y1 + taborder[b].y2 + 2,15);
- }
- void tdialogbox::run(void)
- {
- if ( pcgo ) {
- delete pcgo;
- pcgo = NULL;
- }
- int xm, ym, xp, yp;
- int i, oldx, oldy, xp2, yp2;
- pbutton pb;
- taste = ct_invvalue;
- if (getmousestatus() == 2) {
- 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 ) {
- oldx = x1;
- oldy = y1;
- xp2 = oldx;
- yp2 = oldy;
- xm = mouseparams.x;
- ym = mouseparams.y;
- xp = xm;
- yp = ym;
- while (mouseparams.taste == 1) {
- if ((mouseparams.x != xp) || (mouseparams.y != yp)) {
- x1 = oldx + (mouseparams.x - xm);
- y1 = oldy + (mouseparams.y - ym);
- if (x1 < 0) x1 = 0;
- if (y1 < 0) y1 = 0;
- if (x1 + xsize >= agmp->resolutionx) x1 = agmp->resolutionx - xsize - 1;
- if (y1 + ysize >= agmp->resolutiony) y1 = agmp->resolutiony - ysize - 1;
- if ((x1 != xp2) || (y1 != yp2)) {
-
- mousevisible(false);
- xorrectangle(xp2,yp2,xp2 + xsize,yp2 + ysize,14);
- xorrectangle(x1,y1,x1 + xsize,y1 + ysize,14);
- mousevisible(true);
- xp2 = x1;
- yp2 = y1;
- /*
- int ox = xp2;
- int oy = yp2;
- paint();
- if ( prev )
- prev->redrawall2( ox, oy, ox + xsize, oy + ysize );
- else
- repaintdisplay();
- */
- }
- xp = mouseparams.x;
- yp = mouseparams.y;
- }
- releasetimeslice();
- }
-
- if ((oldx != x1) || (oldy != y1)) {
- paint();
- if ( prev )
- prev->redrawall2( oldx, oldy, oldx + xsize, oldy + ysize );
- else
- repaintDisplay();
- }
- }
- if (mouseparams.taste == 1) {
- pb = firstbutton;
- while (pb != NULL) {
- if (pb->status)
- if (pb->active) {
- if ((mouseparams.x >= x1 + pb->x1) && (mouseparams.x <= x1 + pb->x2) && (mouseparams.y >= y1 + pb->y1) && (mouseparams.y <= y1 + pb->y2)) {
- execbutton(pb,true);
- break;
- }
- }
- pb = pb->next;
- }
- }
- }
- if (keypress()) {
- getkeysyms ( &taste, &prntkey );
- }
- else {
- taste = ct_invvalue;
- prntkey = cto_invvalue;
- }
- releasetimeslice();
- if (((taste == ct_tab) || (taste == ct_shift_tab)) && (tabcount > 0)) {
- showtabmark(markedtab);
- if (taste == ct_tab)
- markedtab++;
- else
- markedtab--;
- if (markedtab > tabcount)
- markedtab = 1;
- if (markedtab < 1)
- markedtab = tabcount;
- showtabmark(markedtab);
- }
- else {
- pb = firstbutton;
- while (pb != NULL) {
- if (pb->markedkeynum > 0)
- for (i = 0; i < pb->markedkeynum; i++)
- if (markedtab > 0)
- if ((pb->markedkey[i] == prntkey) && (taborder[markedtab].id == pb->id))
- if (pb->active)
- if (pb->status == 1) {
- execbutton(pb,false);
- taste = ct_invvalue;
- prntkey = ct_invvalue;
- }
- if (pb->keynum > 0)
- for (i = 0; i < pb->keynum; i++)
- if (pb->key[i] == prntkey)
- if (pb->active)
- if (pb->status == 1) {
- execbutton(pb,false);
- taste = ct_invvalue;
- prntkey = ct_invvalue;
- }
- pb = pb->next;
- }
- }
- }
- void tdialogbox::toggleswitch(pbutton pb)
- {
-
- char *pbl = (char*) pb->data;
- if ( pb->style == 10 )
- *pbl = 1;
- else
- *pbl = ! *pbl;
- int col;
- if (*pbl)
- col = pb->min;
- else
- col = pb->max;
- line(x1 + pb->x1,y1 + pb->y1,x1 + pb->x1 + (pb->y2 - pb->y1),y1 + pb->y2, col);
- line(x1 + pb->x1 + (pb->y2 - pb->y1),y1 + pb->y1,x1 + pb->x1,y1 + pb->y2, col);
- buttonpressed(pb->id);
- }
- char tdialogbox::checkvalue(int id,
- void* p)
- {
- return true;
- }
- void tdialogbox::editfield( int id )
- {
- pbutton pb = firstbutton;
- while ( pb ) {
- if (pb->id == id )
- editfield ( pb );
- pb = pb->next;
- }
- }
- void tdialogbox::editfield(pbutton pb)
- {
- char *ps = NULL;
- int *pl = NULL;
- Uint16 *pw = NULL;
- char *pbt = NULL;
- int l;
- activefontsettings.font = schriften.smallarial;
- activefontsettings.color = textcolor;
- activefontsettings.background = dblue;
- activefontsettings.length = (Uint16) (pb->x2 - pb->x1 - 10 );
- if (pb->art == 1) {
- ps = (char*) pb->data;
- // mousevisible(false);
- do {
- stredit(ps, x1 + pb->x1 + 5,y1 + pb->y1 + 2,pb->x2 - pb->x1 - 10, pb->max);
- } while ( !checkvalue(pb->id,ps) );
- // mousevisible(true);
- }
- if (pb->art == 2) {
- if (pb->max <= 255 && pb->min >= 0) {
- pbt = (char*) pb->data;
- l = *pbt;
- }
- else
- if (pb->max <= 65535 && pb->min >= 0) {
- pw = (Uint16*) pb->data;
- l = *pw;
- }
- else {
- pl = (int*) pb->data;
- l = *pl;
- }
- // mousevisible(false);
- do {
- intedit( &l,x1 + pb->x1 + 5,y1 + pb->y1 + 2,pb->x2 - pb->x1 - 10,pb->min,pb->max);
- } while ( !checkvalue(pb->id, &l) );
- // mousevisible(true);
- if (pb->max <= 255 && pb->min >= 0) {
- *pbt = l;
- }
- else
- if (pb->max <= 65535 && pb->min >= 0) {
- *pw = l;
- }
- else {
- *pl = l;
- }
- }
- }
- void tdialogbox::rahmen3(const char * txt,
- int x1,
- int y1,
- int x2,
- int y2,
- int style)
- {
- collategraphicoperations cgs( x1, y1, x2, y2 );
- Uint16 w;
- npush( activefontsettings );
- activefontsettings.font = schriften.smallarial;
- w = gettextwdth(txt,NULL);
- if (style == 1) {
- line(x1,y1,x1,y2,black);
- line(x1,y2,x2,y2,black);
- line(x2,y1,x2,y2,black);
- line(x1,y1,x1 + 9,y1,black);
- line(x1 + 10 + w + 5,y1,x2,y1,black);
- }
- activefontsettings.justify = lefttext;
- activefontsettings.length = 0;
- showtext2(txt,x1 + 12,y1 - activefontsettings.font->height / 2);
- npop( activefontsettings );
- }
- typedef char* tstringa[30];
- typedef tstringa* pstringa;
- class tdisplaymessage : public tdialogbox {
- char status;
- int mode;
- public:
- void init ( tstringa a, int md, int linenum, const char* buttonText = NULL );
- virtual void buttonpressed ( int id );
- virtual void run ( void );
- };
- extern tdisplaymessage* messagebox;
- void tdisplaymessage::init ( tstringa a, int md, int linenum, const char* buttonText )
- {
- if ( !buttonText )
- buttonText = "~O~K";
- tdialogbox::init();
- int i,j;
- int maxlength = 0;
- mode = md;
- for (i=0;i<=linenum ;i++ ) {
- j = gettextwdth ( a[i], schriften.smallarial );
- while ( j > agmp->resolutionx ) {
- a[i][strlen(a[i])-1] = 0;
- j = gettextwdth ( a[i], schriften.smallarial );
- }
- if (maxlength < j)
- maxlength = j;
- } /* endfor */
- x1 = 50;
- y1 = 50;
- if (maxlength < 150)
- xsize = 200;
- else
- xsize = maxlength + 50;
- if ( maxlength > agmp->resolutionx - 100 )
- x1 = 0;
- if ( xsize > agmp->resolutionx )
- xsize = agmp->resolutionx;
- ysize = 55 + linenum * 20;
- windowstyle |= dlg_notitle;
- if (mode != 0) {
- ysize+=25;
- addbutton ( buttonText, 10, ysize - 35 , xsize - 10 , ysize - 10 ,0,1,1,true );
- addkey(1, ct_enter);
- addkey(1, ct_esc);
- addkey(1, ct_enterk );
- addkey(1, ct_space );
- };
- buildgraphics();
- activefontsettings.justify = lefttext;
- if (mode == 1) {
- activefontsettings.color = lightred;
- } else {
- activefontsettings.color = black;
- } /* endif */
- activefontsettings.font = schriften.smallarial;
- for (i=0;i <= linenum ;i++ ) {
- showtext2( a[i], x1+10, y1+20+i*20 );
- } /* endfor */
- status = 0;
- if ( pcgo ) {
- delete pcgo;
- pcgo = NULL;
- }
- }
- void tdisplaymessage::buttonpressed ( int id )
- {
- if ( id == 1) {
- status = 1;
- } /* endif */
- }
- void tdisplaymessage::run ( void )
- {
- mousevisible(true);
- do {
- tdialogbox::run();
- } while ( status == 0 ); /* enddo */
- }
- // num 0: Box bleibt aufgeklappt,
- // 1 box wird geschlossen , text rot (Fehler),
- // 2 : Programm wird beendet;
- // 3 : normaler text ( OK)
- void displaymessage( const char* formatstring, int num, ... )
- {
- va_list paramlist;
- va_start ( paramlist, num );
- char tempbuf[1000];
- int lng = vsprintf( tempbuf, formatstring, paramlist );
- if ( lng >= 1000 )
- displaymessage ( "dlg_box.cpp / displaymessage: string to long !\nPlease report this error",1 );
- va_end ( paramlist );
- displaymessage ( ASCString ( tempbuf ), num );
- }
- void displaymessage( const ASCString& text, int num )
- {
- const char* a = text.c_str();
- tstringa stringtooutput;
- memset (stringtooutput, 0, sizeof ( stringtooutput ));
- stringtooutput[0] = new char[200];
- stringtooutput[0][0] = 0;
- char* b = stringtooutput[0];
- int linenum = 0;
- while ( *a ) {
- if (*a == '\n') {
- *b = 0;
- linenum++;
- stringtooutput[linenum] = new char[200];
- b = stringtooutput[linenum];
- *b = 0;
- } else {
- *b = *a;
- b++;
- }
- a++;
- }
- *b = 0;
- bool displayInternally = true;
- /*
- if ( num == 2 )
- displayLogMessage ( 0, "fatal error" + text + "\n" );
- else
- displayLogMessage ( 0, text + "\n" );
- */
- #ifndef NoStdio
- if ( num == 2 )
- displayInternally = false;
- #endif
- if ( num == 2 )
- displayLogMessage(1, text );
- if ( !displayInternally ) {
- for ( int i=0; i<= linenum ;i++ )
- fprintf(stderr,"%s\n",stringtooutput[i]);
- fflush( stderr );
- } else {
- #ifdef _WIN322_
- if ( !gameStartupComplete && num==2 ) {
- MessageBox(NULL, text.c_str(), "Fatal Error", MB_ICONERROR | MB_OK | MB_TASKMODAL );
- exit(1);
- }
- #endif
- if ( legacyEventSystemActive() ) {
- static int messageboxopen = 0;
- if ( messageboxopen )
- return;
-
- messageboxopen++;
- if ( messagebox ) {
- if ( messagebox->boxstatus )
- messagebox->done();
- delete messagebox;
- messagebox = NULL;
- }
-
- messagebox = new tdisplaymessage;
-
- if ( num== 2 )
- messagebox->init( stringtooutput, num, linenum, "~q~uit program");
- else
- messagebox->init( stringtooutput, num, linenum);
-
- if (num != 0 ) {
- messagebox->run();
- messagebox->done();
- delete messagebox;
- messagebox = NULL;
- …
Large files files are truncated, but you can click here to view the full file