home *** CD-ROM | disk | FTP | other *** search
/ WarCraft 2000 - Nuclear Epidemic / W2000.nrg / SOURCE.War2000 / Dialogs.cpp < prev    next >
C/C++ Source or Header  |  1998-11-14  |  34KB  |  1,362 lines

  1. #include "ddini.h"
  2. #include "ResFile.h"
  3. #include "fastdraw.h"
  4. #include "mapdiscr.h"
  5. #include "mouse.h"
  6. #include "Dialogs.h"
  7. #include "fonts.h"
  8. #include <assert.h>
  9. extern bool realLpressed;
  10. extern bool KeyPressed;
  11. extern int LastKey;
  12. extern bool MUSTDRAW;
  13. extern int RealLx;
  14. extern int RealLy;
  15. void ShowString(int x,int y,LPCSTR lps,lpRLCFont lpf);
  16. DialogsSystem::DialogsSystem(int x,int y){
  17.     BaseX=x;
  18.     BaseY=y;
  19.     for(int i=0;i<512;i++)DSS[i]=NULL;
  20.     NDial=0;
  21.     Active=NULL;
  22.     Passive=NULL;
  23.     Disabled=NULL;
  24.     Message=NULL;
  25. };
  26. void DialogsSystem::SetFonts(RLCFont* fActive,
  27.                              RLCFont* fPassive,
  28.                              RLCFont* fDisabled,
  29.                              RLCFont* fMessage){
  30.     Active=fActive;
  31.     Passive=fPassive;
  32.     Disabled=fDisabled;
  33.     Message=fMessage;
  34. };
  35. //-----------------class Picture
  36. bool Picture_OnMouseOver(SimpleDialog* SD){
  37.     Picture* Pic=(Picture*)SD;
  38.     if(Pic->ActivePicture!=Pic->PassivePicture)
  39.         SD->NeedToDraw=true;
  40.     return false;
  41. };
  42. bool Picture_OnDraw(SimpleDialog* SD){
  43.     if(!SD)return false;
  44.     Picture* pic=(Picture*)SD;
  45.     if(!pic->Enabled&&pic->DisabledPicture){
  46.         pic->DisabledPicture->Draw(pic->x,pic->y);
  47.         return true;
  48.     };
  49.     if(pic->MouseOver&&pic->ActivePicture){
  50.         pic->ActivePicture->Draw(pic->x,pic->y);
  51.         return true;
  52.     };
  53.     if(pic->PassivePicture){
  54.         pic->PassivePicture->Draw(pic->x,pic->y);
  55.         return true;
  56.     };
  57.     return false;
  58. };
  59. Picture* DialogsSystem::addPicture(SimpleDialog* Parent,
  60.                         int px,int py,
  61.                         SQPicture* Active,
  62.                         SQPicture* Passive,
  63.                         SQPicture* Disabled){
  64.     for(int i=0;i<512&&DSS[i]!=NULL;i++);
  65.     if(i<512){
  66.         Picture* pic=new Picture;
  67.         DSS[i]=pic;
  68.         if(Active!=Passive)pic->MouseOverActive=true;
  69.         pic->NeedToDraw=true;
  70.         pic->Parent=Parent;
  71.         pic->x=BaseX+px;
  72.         pic->y=BaseY+py;
  73.         pic->x1=pic->x+Passive->PicPtr[0]-1;
  74.         pic->y1=pic->y+Passive->PicPtr[1]-1;
  75.         pic->ActivePicture=Active;
  76.         pic->PassivePicture=Passive;
  77.         pic->DisabledPicture=Disabled;
  78.         pic->OnDraw=&Picture_OnDraw;
  79.         pic->OnMouseOver=&Picture_OnMouseOver;
  80.         pic->Enabled=true;
  81.         pic->Active=false;
  82.         return pic;
  83.     };
  84.     return NULL;
  85. };
  86. //-----------------class RLCPicture
  87. bool RLCPicture_OnDraw(SimpleDialog* SD){
  88.     if(!SD)return false;
  89.     RLCPicture* pic=(RLCPicture*)SD;
  90.     if(!pic->Enabled&&pic->DisabledPicture){
  91.         ShowRLCItem(pic->x,pic->y,pic->DisabledPicture,pic->dpic,0);
  92.         return true;
  93.     };
  94.     if(pic->MouseOver&&pic->ActivePicture){
  95.         ShowRLCItem(pic->x,pic->y,pic->ActivePicture,pic->apic,0);
  96.         return true;
  97.     };
  98.     if(pic->PassivePicture){
  99.         ShowRLCItem(pic->x,pic->y,pic->PassivePicture,pic->dpic,0);
  100.         return true;
  101.     };
  102.     return false;
  103. };
  104. RLCPicture* DialogsSystem::addRLCPicture(SimpleDialog* Parent,int x,int y,
  105.                         RLCTable* Active,byte apic,
  106.                         RLCTable* Passive,byte ppic,
  107.                         RLCTable* Disabled,byte dpic){
  108.     for(int i=0;i<512&&DSS[i]!=NULL;i++);
  109.     if(i<512){
  110.         RLCPicture* pic=new RLCPicture;
  111.         DSS[i]=pic;
  112.         if(Active!=Passive)pic->MouseOverActive=true;
  113.         pic->NeedToDraw=true;
  114.         pic->Parent=Parent;
  115.         pic->x=BaseX+x;
  116.         pic->y=BaseY+y;
  117.         pic->x1=pic->x+GetRLCWidth(*Passive,ppic);
  118.         pic->y1=pic->y+GetRLCHeight(*Passive,ppic);
  119.         pic->ActivePicture=Active;
  120.         pic->apic=apic;
  121.         pic->PassivePicture=Passive;
  122.         pic->ppic=ppic;
  123.         pic->DisabledPicture=Disabled;
  124.         pic->dpic=dpic;
  125.         pic->OnDraw=&Picture_OnDraw;
  126.         pic->OnMouseOver=&Picture_OnMouseOver;
  127.         pic->Enabled=true;
  128.         pic->Active=false;
  129.         return pic;
  130.     };
  131.     return NULL;
  132. };
  133. //------------end of the class Picture
  134.  
  135.  
  136. //------------class TextButton
  137. int GetRLen(char* s,RLCFont* font){
  138.     if(!int(s))return 0;
  139.     int x=0;
  140.     for(int i=0;s[i]!=0;i++)
  141.         x+=GetRLCWidth(font->RLC,font->FirstSymbol+s[i]);
  142.     return x;
  143. };
  144. void DrawString(int x,int y,char* str,RLCFont* fnt,byte Align){
  145.     int xx;
  146.     if(!str)return;
  147.     switch(Align){
  148.     case 0:    ShowString(x,y,str,fnt);
  149.             return;
  150.     case 1: //center align
  151.             xx=x-(GetRLen(str,fnt)>>1);
  152.             ShowString(xx,y,str,fnt);
  153.             return;
  154.     case 2: //right align
  155.             xx=x-GetRLen(str,fnt);
  156.             ShowString(xx,y,str,fnt);
  157.     };
  158. };
  159. bool TextButton_OnDraw(SimpleDialog* SD){
  160.     if(!SD)return false;
  161.     TextButton* tb=(TextButton*)SD;
  162.     RLCFont* CFN=NULL;
  163.     if(!tb->Enabled&&tb->DisabledFont)CFN=tb->DisabledFont;
  164.     else 
  165.     if(tb->MouseOver&&tb->ActiveFont)CFN=tb->ActiveFont;
  166.     else
  167.     if(tb->PassiveFont)CFN=tb->PassiveFont;
  168.     if(CFN){
  169.         int rlen=GetRLen(tb->Message,CFN);
  170.         switch(tb->Align){
  171.         case 1:tb->x=tb->xc-(rlen>>1);
  172.             break;
  173.         case 2:tb->x=tb->yc-rlen;
  174.         };
  175.         tb->x1=tb->x+rlen-1;
  176.         tb->y1=tb->y+GetRLCHeight(CFN->RLC,'W');
  177.         ShowString(tb->x,tb->y,tb->Message,CFN);
  178.         return true;
  179.     };
  180.     return false;
  181. };
  182. bool TextButton_OnMouseOver(SimpleDialog* SD){
  183.     TextButton* tb=(TextButton*)SD;
  184.     if(tb->PassiveFont!=tb->ActiveFont)
  185.         SD->NeedToDraw=true;
  186.     return false;
  187. };
  188. bool TextButton_Destroy(SimpleDialog* SD){
  189.     TextButton* tb=(TextButton*)SD;
  190.     if(tb->Message)free(tb->Message);
  191.     return true;
  192. };
  193.  
  194. TextButton* DialogsSystem::addTextButton(SimpleDialog* Parent,
  195.                         int px,int py,char* str,
  196.                         RLCFont* Active,
  197.                         RLCFont* Passive,
  198.                         RLCFont* Disabled,
  199.                         byte Align){
  200.     for(int i=0;i<512&&DSS[i]!=NULL;i++);
  201.     if(i<512){
  202.         TextButton* tb=new TextButton;
  203.         DSS[i]=tb;
  204.         tb->MouseOverActive=true;
  205.         tb->NeedToDraw=true;
  206.         tb->Parent=Parent;
  207.         tb->x=BaseX+px;
  208.         tb->y=BaseY+py;
  209.         tb->xc=BaseX+px;
  210.         tb->yc=BaseY+py;
  211.         int rlen=GetRLen(str,Passive);
  212.         switch(Align){
  213.         case 1:tb->x-=rlen>>1;
  214.             break;
  215.         case 2:tb->x-=rlen;
  216.         };
  217.         tb->x1=tb->x+rlen-1;
  218.         tb->y1=tb->y+GetRLCHeight(Passive->RLC,'W');
  219.         tb->ActiveFont=Active;
  220.         tb->PassiveFont=Passive;
  221.         tb->DisabledFont=Disabled;
  222.         tb->ActiveDX=0;
  223.         tb->ActiveDY=0;
  224.         tb->Align=Align;
  225.         tb->Message=new char[strlen(str)+1];
  226.         strcpy(tb->Message,str);
  227.         tb->OnDraw=&TextButton_OnDraw;
  228.         tb->OnMouseOver=&TextButton_OnMouseOver;
  229.         tb->Destroy=&TextButton_Destroy;
  230.         tb->Enabled=true;
  231.         tb->Active=false;
  232.         return tb;
  233.     };
  234.     return NULL;
  235. };
  236. //------------end of the class TextButton
  237. //-------class : button with text-----------
  238. bool BpxTextButton_OnDraw(SimpleDialog* SD){
  239.     if(!SD)return false;
  240.     BpxTextButton* tb=(BpxTextButton*)SD;
  241.     //drawing button
  242.     SQPicture* SP;
  243.     tb->xc=(tb->x+tb->x1)>>1;
  244.     tb->yc=(tb->y+tb->y1)>>1;
  245.     if(tb->Enabled){
  246.         if(tb->MouseOver&&realLpressed)SP=tb->ActivePicture;
  247.         else SP=tb->PassivePicture;
  248.     }else SP=tb->DisabledPicture;
  249.     SP->Draw(tb->x,tb->y);
  250.     //drawing text
  251.     RLCFont* CFN=NULL;
  252.     if(!tb->Enabled&&tb->DisabledFont)CFN=tb->DisabledFont;
  253.     else 
  254.     if(tb->MouseOver&&tb->ActiveFont)CFN=tb->ActiveFont;
  255.     else
  256.     if(tb->PassiveFont)CFN=tb->PassiveFont;
  257.     if(CFN){
  258.         int rlen=GetRLen(tb->Message,CFN);
  259.         ShowString(tb->xc-(rlen>>1),tb->yc-(GetRLCHeight(CFN->RLC,'W')>>1),tb->Message,CFN);
  260.         return true;
  261.     };
  262.     return false;
  263. };
  264. bool BpxTextButton_OnMouseOver(SimpleDialog* SD){
  265.     if(SD->MouseOver)SD->NeedToDraw=true;
  266.     return false;
  267. };
  268. BpxTextButton* DialogsSystem::addBpxTextButton(SimpleDialog* Parent,
  269.                         int px,int py,char* str,
  270.                         RLCFont* Active,
  271.                         RLCFont* Passive,
  272.                         RLCFont* Disabled,
  273.                         SQPicture* pActive,
  274.                         SQPicture* pPassive,
  275.                         SQPicture* pDisabled){
  276. for(int i=0;i<512&&DSS[i]!=NULL;i++);
  277.     if(i<512){
  278.         BpxTextButton* tb=new BpxTextButton;
  279.         tb->MouseOverActive=true;
  280.         tb->NeedToDraw=true;
  281.         tb->Parent=Parent;
  282.         tb->x=BaseX+px;
  283.         tb->y=BaseY+py;
  284.         tb->x1=tb->x+pPassive->PicPtr[0]-1;
  285.         tb->y1=tb->y+pPassive->PicPtr[1]-1;
  286.         tb->ActivePicture=pActive;
  287.         tb->PassivePicture=pPassive;
  288.         tb->DisabledPicture=pDisabled;
  289.         DSS[i]=tb;
  290.         tb->ActiveFont=Active;
  291.         tb->PassiveFont=Passive;
  292.         tb->DisabledFont=Disabled;
  293.         tb->ActiveDX=0;
  294.         tb->ActiveDY=0;
  295.         tb->Message=new char[strlen(str)+1];
  296.         strcpy(tb->Message,str);
  297.         tb->OnDraw=&BpxTextButton_OnDraw;
  298.         tb->Destroy=&TextButton_Destroy;
  299.         tb->Enabled=true;
  300.         tb->Active=false;
  301.         tb->OnMouseOver=&BpxTextButton_OnMouseOver;
  302.         return tb;
  303.     };
  304.     return NULL;
  305. };
  306. //--------end of button with text----------//
  307. //------class : Vertical scroll bar--------//
  308. bool MouseIns(int x,int y,int x1,int y1){
  309.     if(mouseX>=x&&mouseY>=y&&mouseX<=x1&&mouseY<=y1)return true;
  310.     else return false;
  311. };
  312. bool MouseInsL(int x,int y,int lx,int ly){
  313.     return MouseIns(x,y,x+lx-1,y+ly-1);
  314. };
  315. bool VScrollBar_Draw(SimpleDialog* SD){
  316.     VScrollBar* tb=(VScrollBar*)SD;
  317.     if(tb->GetMaxPos()>0){
  318.         tb->sbar0->Draw(tb->x,tb->sby+2);
  319.         if(MouseInsL(tb->x,tb->y,tb->sblx,tb->btnly)&&realLpressed)
  320.             tb->btn_up1p->DrawTransparent(tb->x,tb->y);
  321.         else tb->btn_up1->DrawTransparent(tb->x,tb->y);
  322.         if(MouseInsL(tb->x,tb->sby+tb->sbly,tb->sblx,tb->btnly)&&realLpressed)
  323.             tb->btn_dn1p->DrawTransparent(tb->x,tb->sby+tb->sbly);
  324.         else tb->btn_dn1->DrawTransparent(tb->x,tb->sby+tb->sbly);
  325.         tb->marker->DrawTransparent(tb->x+1,tb->y+tb->btnly+div(int(tb->sbly-tb->mkly+2)*tb->SPos,tb->SMaxPos).quot);
  326.     }else{
  327.         tb->sbar1->Draw(tb->x,tb->sby+2);
  328.         tb->btn_up0->DrawTransparent(tb->x,tb->y);
  329.         tb->btn_dn0->DrawTransparent(tb->x,tb->sby+tb->sbly);
  330.     };
  331.     return true;
  332. };
  333. bool VScrollBar_MouseOver(SimpleDialog* SD){
  334.     VScrollBar* tb=(VScrollBar*)SD;
  335.     int dt=GetTickCount()-tb->LastTime;
  336.     if(tb->SMaxPos>0){
  337.         if(!realLpressed)tb->Zaxvat=false;
  338.         int my=tb->y+tb->btnly+div(int(tb->sbly-tb->mkly+2)*tb->SPos,tb->SMaxPos).quot;
  339.         if(!tb->Zaxvat){
  340.             if(MouseInsL(tb->x,tb->y,tb->sblx,tb->btnly)&&Lpressed&&dt>150){
  341.                 tb->LastTime=GetTickCount();
  342.                 //Lpressed=false;
  343.                 int txx=tb->SPos;
  344.                 if(tb->SPos>0)tb->SPos--;
  345.                 if(tb->SPos!=txx)tb->NeedToDraw=true;
  346.             };
  347.             if(MouseInsL(tb->x,tb->sby+tb->sbly,tb->sblx,tb->btnly)&&Lpressed&&dt>150){
  348.                 tb->LastTime=GetTickCount();
  349.                 //Lpressed=false;
  350.                 int txx=tb->SPos;
  351.                 if(tb->SPos<tb->SMaxPos)tb->SPos++;
  352.                 if(tb->SPos!=txx)tb->NeedToDraw=true;
  353.             };
  354.             if(MouseIns(tb->x,tb->y+tb->btnly,tb->x+tb->sblx-1,my)&&Lpressed&&dt>150){
  355.                 tb->LastTime=GetTickCount();
  356.                 //Lpressed=false;
  357.                 int txx=tb->SPos;
  358.                 if(tb->SPos>6)tb->SPos-=6;
  359.                 else tb->SPos=0;
  360.                 if(tb->SPos!=txx)tb->NeedToDraw=true;
  361.             };
  362.             if(MouseIns(tb->x,my+tb->mkly,tb->x+tb->sblx-1,tb->y+tb->sbly+tb->btnly-1)&&Lpressed&&dt>150){
  363.                 tb->LastTime=GetTickCount();
  364.                 //Lpressed=false;
  365.                 int txx=tb->SPos;
  366.                 if(tb->SMaxPos-tb->SPos>6)tb->SPos+=6;
  367.                 else tb->SPos=tb->SMaxPos;
  368.                 if(tb->SPos!=txx)tb->NeedToDraw=true;
  369.             };
  370.             if(MouseInsL(tb->x,my,tb->sblx,tb->mkly)&&Lpressed&&dt>150){
  371.                 tb->LastTime=GetTickCount();
  372.                 //Lpressed=false;
  373.                 tb->Zaxvat=true;
  374.             };
  375.         }else{
  376.             int txx=tb->SPos;
  377.             tb->SPos=div((mouseY-tb->sby-(tb->mkly>>1))*tb->SMaxPos,tb->sbly-tb->mkly).quot;
  378.             if(tb->SPos<0)tb->SPos=0;
  379.             if(tb->SPos>tb->SMaxPos)tb->SPos=tb->SMaxPos;
  380.             if(tb->SPos!=txx)tb->NeedToDraw=true;
  381.         };
  382.     };
  383.     return true;
  384. };
  385. VScrollBar* DialogsSystem::addVScrollBar(SimpleDialog* Parent,
  386.                         int x,int y,int MaxPos,int Pos,
  387.                         SQPicture* btn_up0,
  388.                         SQPicture* btn_up1,
  389.                         SQPicture* btn_up1p,
  390.                         SQPicture* btn_dn0,
  391.                         SQPicture* btn_dn1,
  392.                         SQPicture* btn_dn1p,
  393.                         SQPicture* sbar0,
  394.                         SQPicture* sbar1,
  395.                         SQPicture* marker){
  396.                 
  397.     for(int i=0;i<512&&DSS[i]!=NULL;i++);
  398.     if(i<512){
  399.         VScrollBar* tb=new VScrollBar;
  400.         DSS[i]=tb;
  401.         tb->NeedToDraw=true;
  402.         tb->Parent=Parent;
  403.         tb->x=BaseX+x;
  404.         tb->y=BaseY+y;
  405.         tb->sblx=sbar0->PicPtr[0];
  406.         tb->sbly=sbar0->PicPtr[1];
  407.         tb->mkly=marker->PicPtr[1];
  408.         tb->btnly=btn_dn1->PicPtr[1]-2;
  409.         tb->y1=tb->y+tb->sbly+(tb->btnly<<1)-1;
  410.         tb->x1=tb->x+tb->sblx-1;
  411.         tb->sby=tb->y+tb->btnly;
  412.         tb->SMaxPos=MaxPos;
  413.         tb->SPos=Pos;
  414.         tb->btn_up0=btn_up0;
  415.         tb->btn_up1=btn_up1;
  416.         tb->btn_up1p=btn_up1p;
  417.         tb->btn_dn0=btn_dn0;
  418.         tb->btn_dn1=btn_dn1;
  419.         tb->btn_dn1p=btn_dn1p;
  420.         tb->sbar0=sbar0;
  421.         tb->sbar1=sbar1;
  422.         tb->marker=marker;
  423.         tb->Zaxvat=false;
  424.         tb->OnDraw=&VScrollBar_Draw;
  425.         tb->OnMouseOver=&VScrollBar_MouseOver;
  426.         tb->Enabled=true;
  427.         tb->Active=false;
  428.         return tb;
  429.     };
  430.     return NULL;
  431. };
  432. //-------end of vertical Scroll bar--------//
  433. //------class : Horizontal scroll bar--------//
  434. bool HScrollBar_Draw(SimpleDialog* SD){
  435.     VScrollBar* tb=(VScrollBar*)SD;
  436.     if(tb->SMaxPos>0){
  437.         tb->sbar0->Draw(tb->sby+2,tb->y);
  438.         //left click
  439.         if(MouseInsL(tb->x,tb->y,tb->btnly,tb->sblx)&&realLpressed)
  440.             tb->btn_up1p->DrawTransparent(tb->x,tb->y);
  441.         else tb->btn_up1->DrawTransparent(tb->x,tb->y);
  442.         //right click
  443.         if(MouseInsL(tb->sby+tb->sbly,tb->y,tb->btnly,tb->sblx)&&realLpressed)
  444.             tb->btn_dn1p->DrawTransparent(tb->sby+tb->sbly,tb->y);
  445.         else tb->btn_dn1->DrawTransparent(tb->sby+tb->sbly,tb->y);
  446.         tb->marker->DrawTransparent(tb->x+tb->btnly+div(int(tb->sbly-tb->mkly+2)*tb->SPos,tb->SMaxPos).quot,tb->y+1);
  447.     }else{
  448.         tb->sbar1->Draw(tb->sby+2,tb->y);
  449.         tb->btn_up0->DrawTransparent(tb->x,tb->y);
  450.         tb->btn_dn0->DrawTransparent(tb->sby+tb->sbly,tb->x);
  451.     };
  452.     return true;
  453. };
  454. bool HScrollBar_MouseOver(SimpleDialog* SD){
  455.     VScrollBar* tb=(VScrollBar*)SD;
  456.     int dt=GetTickCount()-tb->LastTime;
  457.     if(tb->SMaxPos>0){
  458.         if(!realLpressed)tb->Zaxvat=false;
  459.         int my=tb->x+tb->btnly+div(int(tb->sbly-tb->mkly+2)*tb->SPos,tb->SMaxPos).quot;
  460.         if(!tb->Zaxvat){
  461.             if(MouseInsL(tb->x,tb->y,tb->btnly,tb->sblx)&&Lpressed&&dt>150){
  462.                 tb->LastTime=GetTickCount();
  463.                 //Lpressed=false;
  464.                 int txx=tb->SPos;
  465.                 if(tb->SPos>0)tb->SPos--;
  466.                 if(tb->SPos!=txx)tb->NeedToDraw=true;
  467.             };
  468.             if(MouseInsL(tb->sby+tb->sbly,tb->y,tb->btnly,tb->sblx)&&Lpressed&&dt>150){
  469.                 tb->LastTime=GetTickCount();
  470.                 //Lpressed=false;
  471.                 int txx=tb->SPos;
  472.                 if(tb->SPos<tb->SMaxPos)tb->SPos++;
  473.                 if(tb->SPos!=txx)tb->NeedToDraw=true;
  474.             };
  475.             if(MouseIns(tb->x+tb->btnly,tb->y,my,tb->y+tb->sblx-1)&&Lpressed&&dt>150){
  476.                 tb->LastTime=GetTickCount();
  477.                 //Lpressed=false;
  478.                 int txx=tb->SPos;
  479.                 if(tb->SPos>6)tb->SPos-=6;
  480.                 else tb->SPos=0;
  481.                 if(tb->SPos!=txx)tb->NeedToDraw=true;
  482.             };
  483.             if(MouseIns(my+tb->mkly,tb->y,tb->x+tb->sbly+tb->btnly-1,tb->y+tb->sblx-1)&&Lpressed&&dt>150){
  484.                 tb->LastTime=GetTickCount();
  485.                 //Lpressed=false;
  486.                 int txx=tb->SPos;
  487.                 if(tb->SMaxPos-tb->SPos>6)tb->SPos+=6;
  488.                 else tb->SPos=tb->SMaxPos;
  489.                 if(tb->SPos!=txx)tb->NeedToDraw=true;
  490.             };
  491.             if(MouseInsL(my,tb->y,tb->mkly,tb->sblx)&&Lpressed&&dt>150){
  492.                 tb->LastTime=GetTickCount();
  493.                 //Lpressed=false;
  494.                 tb->Zaxvat=true;
  495.             };
  496.         }else{
  497.             int txx=tb->SPos;
  498.             tb->SPos=div((mouseX-tb->sby-(tb->mkly>>1))*tb->SMaxPos,tb->sbly-tb->mkly).quot;
  499.             if(tb->SPos<0)tb->SPos=0;
  500.             if(tb->SPos>tb->SMaxPos)tb->SPos=tb->SMaxPos;
  501.             if(tb->SPos!=txx)tb->NeedToDraw=true;
  502.         };
  503.     };
  504.     return true;
  505. };
  506. VScrollBar* DialogsSystem::addHScrollBar(SimpleDialog* Parent,
  507.                         int x,int y,int MaxPos,int Pos,
  508.                         SQPicture* btn_up0,
  509.                         SQPicture* btn_up1,
  510.                         SQPicture* btn_up1p,
  511.                         SQPicture* btn_dn0,
  512.                         SQPicture* btn_dn1,
  513.                         SQPicture* btn_dn1p,
  514.                         SQPicture* sbar0,
  515.                         SQPicture* sbar1,
  516.                         SQPicture* marker){
  517.                 
  518.     for(int i=0;i<512&&DSS[i]!=NULL;i++);
  519.     if(i<512){
  520.         VScrollBar* tb=new VScrollBar;
  521.         DSS[i]=tb;
  522.         tb->NeedToDraw=true;
  523.         tb->Parent=Parent;
  524.         tb->x=BaseX+x;
  525.         tb->y=BaseY+y;
  526.         tb->sblx=sbar0->PicPtr[1];
  527.         tb->sbly=sbar0->PicPtr[0];
  528.         tb->mkly=marker->PicPtr[0];
  529.         tb->btnly=btn_dn1->PicPtr[0]-2;
  530.         tb->x1=tb->x+tb->sbly+(tb->btnly<<1)-1;
  531.         tb->y1=tb->y+tb->sblx-1;
  532.         tb->sby=tb->x+tb->btnly;
  533.         tb->SMaxPos=MaxPos;
  534.         tb->SPos=Pos;
  535.         tb->btn_up0=btn_up0;
  536.         tb->btn_up1=btn_up1;
  537.         tb->btn_up1p=btn_up1p;
  538.         tb->btn_dn0=btn_dn0;
  539.         tb->btn_dn1=btn_dn1;
  540.         tb->btn_dn1p=btn_dn1p;
  541.         tb->sbar0=sbar0;
  542.         tb->sbar1=sbar1;
  543.         tb->marker=marker;
  544.         tb->Zaxvat=false;
  545.         tb->OnDraw=&HScrollBar_Draw;
  546.         tb->OnMouseOver=&HScrollBar_MouseOver;
  547.         tb->Enabled=true;
  548.         tb->Active=false;
  549.         return tb;
  550.     };
  551.     return NULL;
  552. };
  553. //-------end of horizontal Scroll bar--------//
  554. //-------------class : ListBox---------------//
  555. ListBoxItem* ListBox::GetItem(int i){
  556.     ListBoxItem* LB=FirstItem;
  557.     for(int j=0;j<i;j++){
  558.         if(LB)LB=LB->NextItem;
  559.     };
  560.     return LB;
  561. };
  562. void ListBox::AddItem(char* str,int n){
  563.     NeedToDraw=true;
  564.     ListBoxItem* LB=new ListBoxItem;
  565.     if(LastItem){
  566.         LastItem->NextItem=LB;
  567.         LB->NextItem=NULL;
  568.     }else{
  569.         FirstItem=LB;
  570.         LastItem=LB;
  571.         LB->NextItem=NULL;
  572.     };
  573.     LastItem=LB;
  574.     NItems++;
  575.     LB->Message=new char [strlen(str)+1];
  576.     strcpy(LB->Message,str);
  577.     LB->Param1=n;
  578. };
  579. void ListBox::ClearItems(){
  580.     NeedToDraw=true;
  581.     ListBoxItem* LB1,*LB=FirstItem;
  582.     while(LB){
  583.         free(LB->Message);
  584.         LB1=LB->NextItem;
  585.         free(LB);
  586.         LB=LB1;
  587.     };
  588.     NItems=0;
  589.     FirstItem=NULL;
  590.     LastItem=NULL;
  591.     NItems=0;
  592.     CurItem=0;
  593.     FLItem=0;
  594. };
  595. void ListBox::SetFirstPos(int n){
  596.     if(n!=FLItem)NeedToDraw=true;
  597.     FLItem=n;
  598. };
  599. void ListBox::SetCurrentItem(int n){
  600.     if(n!=CurItem)NeedToDraw=true;
  601.     CurItem=n;
  602.     if(CurItem>=NItems)CurItem=NItems-1;
  603.     if(!NItems)CurItem=-1;
  604.     if(CurItem<FLItem)FLItem=CurItem;
  605. };
  606. bool ListBox_OnDraw(SimpleDialog* SD){
  607.     ListBox* LB=(ListBox*)SD;
  608.     if(LB){
  609.         int y=LB->y;
  610.         for(int i=0;i<LB->ny;i++){
  611.             LB->ItemPic->Draw(LB->x,y);
  612.             int Iind=LB->FLItem+i;
  613.             ListBoxItem* str=LB->GetItem(Iind);
  614.             if(str){
  615.                 if(Iind==LB->CurItem)
  616.                     ShowString(LB->x+8,y+8,str->Message,LB->AFont);
  617.                 else ShowString(LB->x+8,y+8,str->Message,LB->PFont);
  618.             };
  619.             y+=LB->oneLy-1;
  620.         };
  621.     };
  622.     return true;
  623. };
  624. bool ListBox_OnMouseOver(SimpleDialog* SD){
  625.     if(!Lpressed)return false;
  626.     ListBox* LB=(ListBox*)SD;
  627.     SD->NeedToDraw=true;
  628.     int ni=div(mouseY-LB->y,LB->oneLy-1).quot;
  629.     if(ni<LB->ny){
  630.         if(LB->FLItem+ni<LB->NItems)
  631.             LB->CurItem=LB->FLItem+ni;
  632.         else LB->CurItem=LB->NItems-1;
  633.     };
  634.     return true;
  635. };
  636. bool ListBox_Refresh(SimpleDialog* SD){
  637.     ListBox* LB=(ListBox*)SD;
  638.     if(LB->VS){
  639.         VScrollBar* VS=LB->VS;
  640.         VS->SetMaxPos(LB->NItems-LB->ny);
  641.         if(VS->GetMaxPos()>0)LB->FLItem=VS->GetPos();
  642.     };
  643.     return true;
  644. };
  645. ListBox* DialogsSystem::addListBox(SimpleDialog* Parent,
  646.                         int x,int y,int Ny,
  647.                         SQPicture* ItemPic,
  648.                         RLCFont* AFont,
  649.                         RLCFont* PFont,
  650.                         VScrollBar* VS){
  651.     for(int i=0;i<512&&DSS[i]!=NULL;i++);
  652.     if(i<512){
  653.         ListBox* LB=new ListBox;
  654.         DSS[i]=LB;
  655.         LB->NeedToDraw=true;
  656.         LB->Parent=Parent;
  657.         LB->AFont=AFont;
  658.         LB->PFont=PFont;
  659.         LB->ItemPic=ItemPic;
  660.         LB->x=x+BaseX;
  661.         LB->y=y+BaseY;
  662.         LB->oneLy=ItemPic->PicPtr[1];
  663.         LB->oneLx=ItemPic->PicPtr[0];
  664.         LB->NItems=0;
  665.         LB->FirstItem=NULL;
  666.         LB->LastItem=NULL;
  667.         LB->y1=LB->y+Ny*int(LB->oneLy);
  668.         LB->x1=LB->x+LB->oneLx;
  669.         LB->OnDraw=&ListBox_OnDraw;
  670.         LB->OnMouseOver=&ListBox_OnMouseOver;
  671.         LB->Refresh=&ListBox_Refresh;
  672.         LB->FLItem=0;
  673.         LB->CurItem=0;
  674.         LB->ny=Ny;
  675.         LB->VS=VS;
  676.         return LB;
  677.     };
  678.     return NULL;
  679. };
  680. //-------------end of List Box---------------//
  681. //-----------class : InputBox----------------//
  682. bool InputBox_OnDraw(SimpleDialog* SD){
  683.     InputBox* IB=(InputBox*)SD;
  684.     if(SD){
  685.         char base[128];
  686.         strcpy(base,IB->Str);
  687.         if(IB->Active)strcat(base,"_");
  688.         IB->Pict->Draw(IB->x,IB->y);
  689.         if(SD->Active)ShowString(IB->x+8,IB->y+4,base,IB->AFont);
  690.         else ShowString(IB->x+8,IB->y+4,base,IB->Font);
  691.     };
  692.     return true;
  693. };
  694. bool InputBox_OnClick(SimpleDialog* SD){
  695.     if(!SD->Active)SD->NeedToDraw=true;
  696.     SD->Active=true;
  697.     return true;
  698. };
  699. bool InputBox_OnKeyDown(SimpleDialog* SD){
  700.     SD->NeedToDraw=true;
  701.     InputBox* IB=(InputBox*)SD;
  702.     if(LastKey==VK_BACK){
  703.         if(strlen(IB->Str)>0)IB->Str[strlen(IB->Str)-1]=0;
  704.         return true;
  705.     }else{
  706.         if(LastKey==' '||(LastKey>='0'&&LastKey<='9')||(LastKey>='A'&&LastKey<='Z')){
  707.             char xx[2];
  708.             xx[1]=0;
  709.             xx[0]=char(LastKey);
  710.             if(strlen(IB->Str)<IB->StrMaxLen)strcat(IB->Str,xx);
  711.             return true;
  712.         };
  713.     };
  714.     return false;
  715. };
  716. InputBox* DialogsSystem::addInputBox(SimpleDialog* Parent,
  717.                                      int x,int y,char* str,
  718.                                      int Len,
  719.                                      SQPicture* Panel,
  720.                                      RLCFont* RFont,
  721.                                      RLCFont* AFont){
  722.     for(int i=0;i<512&&DSS[i]!=NULL;i++);
  723.     if(i<512){
  724.         InputBox* IB=new InputBox;
  725.         DSS[i]=IB;
  726.         IB->NeedToDraw=true;
  727.         IB->Parent=Parent;
  728.         IB->x=x+BaseX;
  729.         IB->y=y+BaseY;
  730.         IB->Pict=Panel;
  731.         IB->Font=RFont;
  732.         IB->AFont=AFont;
  733.         IB->StrMaxLen=Len;
  734.         IB->Str=str;
  735.         IB->x1=IB->x+Panel->PicPtr[0]-1;
  736.         IB->y1=IB->y+Panel->PicPtr[1]-1;
  737.         IB->OnDraw=&InputBox_OnDraw;
  738.         IB->OnClick=&InputBox_OnClick;
  739.         IB->OnKeyDown=&InputBox_OnKeyDown;
  740.         return IB;
  741.     };
  742.     return NULL;
  743. };
  744. //------end of class InputBox----------------//
  745. //----------class : CheckBox-----------------//
  746. bool CheckBox_OnDraw(SimpleDialog* SD){
  747.     CheckBox* CB=(CheckBox*)SD;
  748.     if(CB->State)CB->OnPic->DrawTransparent(CB->x,CB->y);
  749.     else CB->OffPic->DrawTransparent(CB->x,CB->y);
  750.     if(CB->MouseOver)ShowString(CB->x+CB->OnPic->PicPtr[0],CB->y+4,CB->Message,CB->Font);
  751.     else ShowString(CB->x+CB->OnPic->PicPtr[0],CB->y+4,CB->Message,CB->AFont);
  752.     return true;
  753. };
  754. bool CheckBox_OnClick(SimpleDialog* SD){
  755.     SD->NeedToDraw=true;
  756.     CheckBox* CB=(CheckBox*)SD;
  757.     if(CB->GroupIndex){
  758.         DialogsSystem* DSM=CB->DS;
  759.         for(int i=0;i<512;i++){
  760.             CheckBox* SDD=(CheckBox*)DSM->DSS[i];
  761.             if(SDD&&SDD->OnClick==&CheckBox_OnClick&&SDD->GroupIndex==CB->GroupIndex){
  762.                 SDD->State=false;
  763.                 SDD->NeedToDraw=true;
  764.             };
  765.         };
  766.         CB->State=true;
  767.     }else{
  768.         CB->State=!CB->State;
  769.     };
  770.     return false;
  771. };
  772. bool CheckBox_Destroy(SimpleDialog* SD){
  773.     CheckBox* CB=(CheckBox*)SD;
  774.     free(CB->Message);
  775.     return true;
  776. };
  777. bool CheckBox_OnMouseOver(SimpleDialog* SD){
  778.     SD->NeedToDraw=true;
  779.     return false;
  780. };
  781. CheckBox* DialogsSystem::addCheckBox(SimpleDialog* Parent,
  782.                                      int x,int y,char* message,
  783.                                      int group,bool State,
  784.                                      SQPicture* OnPict,
  785.                                      SQPicture* OffPict,
  786.                                      RLCFont* Font,
  787.                                      RLCFont* AFont){
  788.     for(int i=0;i<512&&DSS[i]!=NULL;i++);
  789.     if(i<512){
  790.         CheckBox* CB=new CheckBox;
  791.         DSS[i]=CB;
  792.         CB->MouseOverActive=true;
  793.         CB->NeedToDraw=true;
  794.         CB->Parent=Parent;
  795.         CB->x=x+BaseX;
  796.         CB->y=y+BaseY;
  797.         CB->GroupIndex=group;
  798.         CB->State=State;
  799.         CB->OnPic=OnPict;
  800.         CB->OffPic=OffPict;
  801.         CB->x1=CB->x+OnPict->PicPtr[0]+GetRLen(message,Font)-1+2;
  802.         CB->y1=CB->y+OnPict->PicPtr[1]-1+2;
  803.         CB->DS=this;
  804.         CB->OnClick=&CheckBox_OnClick;
  805.         CB->Destroy=&CheckBox_Destroy;
  806.         CB->OnDraw=&CheckBox_OnDraw;
  807.         CB->Font=Font;
  808.         CB->AFont=AFont;
  809.         CB->Message=new char[strlen(message)+1];
  810.         strcpy(CB->Message,message);
  811.         return CB;
  812.     };
  813.     return NULL;
  814. };
  815. //--------end of CheckBox--------------------//
  816. //-----------colored bar---------------------//
  817. void CBar(int x,int y,int Lx,int Ly,byte c){
  818.     if(Lx<=0||Ly<=0)return;
  819.     int ofst=int(ScreenPtr)+x+y*SCRSizeX;
  820.     int adds=SCRSizeX-Lx;
  821.     int Lx4=Lx>>2;
  822.     int Lx1=Lx&3;
  823.     __asm{
  824.         push    edi
  825.         mov        edi,ofst
  826.         mov        edx,Ly
  827.         cld
  828.         mov        al,c
  829.         mov        ah,al
  830.         shl        eax,16
  831.         mov        al,c
  832.         mov        ah,al
  833.         mov        ebx,Lx1
  834. qwr:    mov        ecx,Lx4
  835.         rep        stosd
  836.         mov        ecx,ebx
  837.         rep        stosb
  838.         add        edi,adds
  839.         dec        edx
  840.         jnz        qwr
  841.         pop        edi
  842.     };
  843. };
  844. bool ColoredBar_OnDraw(SimpleDialog* SD){
  845.     byte c=((ColoredBar*)SD)->color;
  846.     CBar(SD->x,SD->y,SD->x1-SD->x+1,SD->y1-SD->y+1,c);
  847.     return true;
  848. };
  849. ColoredBar* DialogsSystem::addColoredBar(int x,int y,int Lx,int Ly,byte c){
  850.     for(int i=0;i<512&&DSS[i]!=NULL;i++);
  851.     if(i<512){
  852.         ColoredBar* PIC=new ColoredBar;
  853.         DSS[i]=PIC;
  854.         PIC->color=c;
  855.         PIC->x=x+BaseX;
  856.         PIC->y=y+BaseY;
  857.         PIC->x1=PIC->x+Lx;
  858.         PIC->y1=PIC->y+Ly;
  859.         PIC->Parent=NULL;
  860.         PIC->OnDraw=&ColoredBar_OnDraw;
  861.         return PIC;
  862.     };
  863.     return NULL;
  864. };
  865. //---------------Text Viewer-----------------//
  866. //---------Service functions---------
  867.  
  868. void TextViewer::GetNextLine(LineInfo* inf){
  869.     int offs=inf->Offset;
  870.     int x=0;
  871.     word LS=0;
  872.     word LW=0; 
  873.     word NS=0;
  874.     //char tms[128];
  875.     char c;
  876.     int tmsp=0;
  877.     int ofs;
  878.     int wid;
  879.     int spw=GetRLCWidth(Font->RLC,' ');
  880.     int nlsp=0;//Ωεδ-Γε ∩≡εßσδεΓ ∩σ≡σΣ ±δεΓε∞
  881.     while(offs<TextSize){
  882.         //char c=TextPtr[offs];
  883.         //if(c==' '){
  884.             //reading next word
  885.             tmsp=0;//length of string
  886.             nlsp=0;//amount of spaces
  887.             wid=0;
  888.             while(TextPtr[offs+nlsp]==' '&&offs+nlsp<TextSize){
  889.                 nlsp++;
  890.                 wid+=spw;
  891.             };
  892.             do{
  893.                 ofs=offs+nlsp+tmsp;
  894.                 c=0;
  895.                 if(ofs<TextSize){
  896.                     c=TextPtr[ofs];
  897.                     if(c!=' '&&c!=0x0D){
  898.                         //tms[tmsp]=c;
  899.                         tmsp++;
  900.                         wid+=GetRLCWidth(Font->RLC,c);
  901.                     };
  902.                 };
  903.             }while(ofs<TextSize&&c!=' '&&c!=0x0D);
  904.             if(LW+wid<Lx&&c==0x0D){
  905.                 inf->NeedFormat=false;
  906.                 inf->NextOffset=offs+tmsp+nlsp+2;
  907.                 inf->NSpaces=NS;
  908.                 inf->LineWidth=LW;
  909.                 inf->LineSize=offs-inf->Offset+tmsp+nlsp;
  910.                 if(inf->NextOffset>TextSize)inf->NextOffset=-1;
  911.                 return;
  912.             };
  913.             if(LW+wid<Lx){
  914.                 //still current line
  915.                 LW+=wid;
  916.                 offs+=nlsp+tmsp;
  917.                 NS+=nlsp;
  918.             }else{
  919.                 //next line
  920.             /*    if(c!=' '){
  921.                     inf->NeedFormat=false;
  922.                     inf->NextOffset=offs;
  923.                     //if(c==0x0D)inf->NextOffset+=2;
  924.                     inf->NSpaces=NS;
  925.                     inf->LineWidth=LW;
  926.                     inf->LineSize=offs-inf->Offset;
  927.                     if(inf->NextOffset>TextSize)inf->NextOffset=-1;
  928.                     return;
  929.                 }else{*/
  930.                 inf->NeedFormat=true;
  931.                 inf->NextOffset=offs+nlsp;
  932.                 inf->NSpaces=NS;
  933.                 inf->LineWidth=LW;
  934.                 inf->LineSize=offs-inf->Offset;
  935.                 if(inf->NextOffset>TextSize)inf->NextOffset=-1;
  936.                 return;
  937.                 //};
  938.             };
  939.         //};
  940.     };
  941.     inf->NeedFormat=false;
  942.     inf->NextOffset=-1;
  943.     inf->NSpaces=NS;
  944.     inf->LineWidth=LW;
  945.     inf->LineSize=offs-inf->Offset;
  946. };
  947. void TextViewer::CreateLinesList(){
  948.     if(!TextPtr)return;
  949.     NLines=0;
  950.     LineInfo LINF;
  951.     LINF.Offset=0;
  952.     do{
  953.         GetNextLine(&LINF);
  954.         if(LINF.NextOffset!=-1)NLines++;
  955.         LINF.Offset=LINF.NextOffset;
  956.     }while(LINF.Offset!=-1);
  957.     LinePtrs=new char* [NLines];
  958.     LineSize=new word [NLines];
  959.     LineWidth=new word [NLines];
  960.     NeedFormat=new bool [NLines];
  961.     NSpaces=new word [NLines];
  962.     LINF.Offset=0;
  963.     NLines=0;
  964.     do{
  965.         GetNextLine(&LINF);
  966.         if(LINF.NextOffset!=-1){
  967.             LinePtrs[NLines]=TextPtr+LINF.Offset;
  968.             LineSize[NLines]=LINF.LineSize;
  969.             LineWidth[NLines]=LINF.LineWidth;
  970.             NeedFormat[NLines]=LINF.NeedFormat;
  971.             NSpaces[NLines]=LINF.NSpaces;
  972.             NLines++;
  973.         };
  974.         LINF.Offset=LINF.NextOffset;
  975.     }while(LINF.Offset!=-1);
  976. };
  977. bool TextViewer_OnDestroy(SimpleDialog* SD){
  978.     TextViewer* TV=(TextViewer*)SD;
  979.     if(TV->TextPtr){
  980.         free(TV->TextPtr);
  981.         free(TV->LinePtrs);
  982.         free(TV->LineSize);
  983.         free(TV->LineWidth);
  984.         free(TV->NeedFormat);
  985.         free(TV->NSpaces);
  986.         TV->TextPtr=NULL;
  987.     };
  988.     return true;
  989. };
  990. bool TextViewer_OnDraw(SimpleDialog* SD){
  991.     TextViewer* TV=(TextViewer*)SD;
  992.     byte c;
  993.     if(!TV->TextPtr)return false;
  994.     if(TV->Line>TV->NLines)TV->Line=TV->NLines-TV->PageSize+1;
  995.     if(TV->Line<0)TV->Line=0;
  996.     for(int i=0;i<TV->PageSize;i++){
  997.         int lin=TV->Line+i;
  998.         int yy=TV->y+TV->SymSize*i;
  999.         if(lin<TV->NLines){
  1000.             byte* off=(byte*)(TV->LinePtrs[lin]);
  1001.             int x=0;
  1002.             int LS=TV->LineSize[lin];
  1003.             int LW=TV->LineWidth[lin];
  1004.             int NS=TV->NSpaces[lin];
  1005.             int addsp=0;
  1006.             if(NS>0)addsp=div(TV->Lx-LW,NS).quot;
  1007.             if(TV->NeedFormat[lin]){
  1008.                 for(int j=0;j<LS;j++){
  1009.                     c=off[j];
  1010.                     ShowRLCItem(TV->x+x,yy,&TV->Font->RLC,c,0);
  1011.                     x+=GetRLCWidth(TV->Font->RLC,c);
  1012.                     if(c==' ')x+=addsp;
  1013.                 };
  1014.             }else{
  1015.                 for(int j=0;j<LS;j++){
  1016.                     c=off[j];
  1017.                     ShowRLCItem(TV->x+x,yy,&TV->Font->RLC,c,0);
  1018.                     x+=GetRLCWidth(TV->Font->RLC,c);
  1019.                 };
  1020.             };
  1021.         };
  1022.     };
  1023.     return true;
  1024. };
  1025. bool TextView_OnKeyDown(SimpleDialog* SD){
  1026.     TextViewer* TV=(TextViewer*)SD;
  1027.     if(!TV->TextPtr)return false;
  1028.     if(KeyPressed){
  1029.         switch(LastKey){
  1030.         case 38:
  1031.             TV->Line--;
  1032.             KeyPressed=false;
  1033.             return true;
  1034.         case 40:
  1035.             TV->Line++;
  1036.             KeyPressed=false;
  1037.             return true;
  1038.         case 33:
  1039.             TV->Line-=TV->PageSize-1;
  1040.             KeyPressed=false;
  1041.             return true;
  1042.         case 34:
  1043.             TV->Line+=TV->PageSize-1;
  1044.             KeyPressed=false;
  1045.             return true;
  1046.         };
  1047.     };
  1048.     return false;
  1049. };
  1050. TextViewer* DialogsSystem::addTextViewer(SimpleDialog* Parent,int x,int y,int Lx,int Ly,char* TextFile,RLCFont* Font){
  1051.     for(int i=0;i<512&&DSS[i]!=NULL;i++);
  1052.     if(i<512){
  1053.         TextViewer* TV=new TextViewer;
  1054.         DSS[i]=TV;
  1055.         TV->NeedToDraw=true;
  1056.         TV->Parent=Parent;
  1057.         TV->x=x+BaseX;
  1058.         TV->y=y+BaseY;
  1059.         TV->x1=TV->x+Lx-1;
  1060.         TV->y1=TV->y+Ly-1;
  1061.         TV->Lx=Lx;
  1062.         TV->OnDraw=&TextViewer_OnDraw;
  1063.         TV->Destroy=&TextViewer_OnDestroy;
  1064.         TV->Font=Font;
  1065.         TV->Line=0;
  1066.         TV->SymSize=GetRLCHeight(Font->RLC,'W')+6;
  1067.         TV->PageSize=div(Ly,TV->SymSize).quot;
  1068.         ResFile f1=RReset(TextFile);
  1069.         if(IOresult()){
  1070.             TV->TextPtr=NULL;
  1071.             TV->NLines=0;
  1072.             return TV;
  1073.         };
  1074.         TV->TextSize=RFileSize(f1);
  1075.         TV->TextPtr=new char [TV->TextSize+32];
  1076.         RBlockRead(f1,TV->TextPtr,TV->TextSize);
  1077.         RClose(f1);
  1078.         TV->CreateLinesList();
  1079.         TV->OnKeyDown=&TextView_OnKeyDown;
  1080.         TV->Enabled=true;
  1081.         TV->Active=true;
  1082.         return TV;
  1083.     };
  1084.     return NULL;
  1085. }; 
  1086. //-------------------------------------------//
  1087. SimpleDialog::SimpleDialog(){
  1088.     Enabled=false;
  1089.     x=0;
  1090.     y=0;
  1091.     x1=0;
  1092.     y1=0;
  1093.     UserParam=0;
  1094.     OnClick=NULL;
  1095.     OnUserClick=NULL;
  1096.     OnDraw=NULL;
  1097.     OnActivate=NULL;
  1098.     OnKeyDown=NULL;
  1099.     OnLeave=NULL;
  1100.     OnMouseOver=NULL;
  1101.     Destroy=NULL;
  1102.     Refresh=NULL;
  1103.     Parent=NULL;
  1104.     MouseOver=false;
  1105.     MouseOverActive=false;
  1106.     Active=false;
  1107.     Enabled=true;
  1108. };
  1109. //----copy rectangle to screen----//
  1110. void CopyToScreen(int zx,int zy,int zLx,int zLy){
  1111.     int x=zx;
  1112.     int y=zy;
  1113.     int Lx=zLx;
  1114.     int Ly=zLy;
  1115.     //if(zLx<=0||zLy<=0||zx<0||zy<0||zx+zLx>RealLx||zy+zLy>RealLy)return;
  1116.     //if(zLx<=0||zLy<=0||zx<0||zy<0)return;
  1117.     if(x<0){
  1118.         Lx+=x;
  1119.         x=0;
  1120.     };
  1121.     if(y<0){
  1122.         Ly+=y;
  1123.         y=0;
  1124.     };
  1125.     if(x+Lx>RealLx)Lx=RealLx-x;
  1126.     if(y+Ly>RealLy)Ly=RealLy-y;
  1127.     if(Lx<0||Ly<0)
  1128.         return;
  1129.     int scof=int(ScreenPtr)+x+y*SCRSizeX;
  1130.     int reof=int(RealScreenPtr)+x+y*RSCRSizeX;
  1131.     int sadd=SCRSizeX-Lx;
  1132.     int radd=RSCRSizeX-Lx;
  1133.     int Lx4=Lx>>2;
  1134.     int Lx1=Lx&3;
  1135.     __asm{
  1136.         push    esi
  1137.         push    edi
  1138.         mov        edx,Ly
  1139.         or        edx,edx
  1140.         jz        lpp4
  1141.         mov        esi,scof
  1142.         mov        edi,reof
  1143.         cld
  1144. lpp1:    mov        ecx,Lx4
  1145.         jcxz    lpp2
  1146.         rep        movsd
  1147. lpp2:    mov        ecx,Lx1
  1148.         jcxz    lpp3
  1149.         rep        movsb
  1150. lpp3:    add        esi,sadd
  1151.         add        edi,radd
  1152.         dec        edx
  1153.         jnz        lpp1
  1154. lpp4:    pop        edi
  1155.         pop        esi
  1156.     };
  1157. };
  1158. //--------Pictures methods--------//
  1159. void SQPicture::Draw(int x,int y){
  1160.     if(!PicPtr)return;
  1161.     int sofst=int(ScreenPtr)+x+y*SCRSizeX;
  1162.     int pofst=int(PicPtr+2);
  1163.     int lx=int(PicPtr[0]);
  1164.     int ly=int(PicPtr[1]);
  1165.     if(ly<=0||lx<=0||lx>RealLx||ly>RealLy)return;
  1166.     int lx4=lx>>2;
  1167.     int lx1=lx&3;
  1168.     int scradd=SCRSizeX-lx;
  1169.     __asm{
  1170.         push    esi
  1171.         push    edi
  1172.         mov        esi,pofst
  1173.         mov        edi,sofst
  1174.         mov        edx,ly
  1175.         or        edx,edx
  1176.         jz        uu3
  1177.         cld        
  1178. lpp1:    mov        ecx,lx4
  1179.         jcxz    uu1
  1180.         rep        movsd
  1181. uu1:    mov        ecx,lx1
  1182.         jcxz    uu2
  1183.         rep        movsb
  1184. uu2:    add        edi,scradd
  1185.         dec        edx
  1186.         jnz        lpp1
  1187. uu3:    pop        edi
  1188.         pop        esi
  1189.     };
  1190. };
  1191. void SQPicture::DrawTransparent(int x,int y){
  1192.     if(!PicPtr)return;
  1193.     int sofst=int(ScreenPtr)+x+y*SCRSizeX;
  1194.     int pofst=int(PicPtr+2);
  1195.     int lx=int(PicPtr[0]);
  1196.     int ly=int(PicPtr[1]);
  1197.     if(ly<=0||lx<=0||lx>RealLx||ly>RealLy)return;
  1198.     int lx4=lx>>2;
  1199.     int lx1=lx&3;
  1200.     int scradd=SCRSizeX-lx;
  1201.     __asm{
  1202.         push    esi
  1203.         push    edi
  1204.         mov        esi,pofst
  1205.         mov        edi,sofst
  1206.         mov        edx,ly
  1207.         or        edx,edx
  1208.         jz        uu3
  1209.         cld        
  1210. lpp0:    mov        ecx,lx
  1211. lpp1:    lodsb
  1212.         or        al,al
  1213.         jnz        lpp1x
  1214.         //inc        esi
  1215.         inc        edi
  1216.         dec        ecx
  1217.         jnz        lpp1
  1218.         jmp        uu2
  1219. lpp1x:    stosb
  1220.         dec        ecx
  1221.         jnz        lpp1
  1222. uu2:    add        edi,scradd
  1223.         dec        edx
  1224.         jnz        lpp0
  1225. uu3:    pop        edi
  1226.         pop        esi
  1227.     };
  1228. };
  1229. void SQPicture::LoadPicture(char* name){
  1230.     ResFile ff1=RReset(name);
  1231.     if(!IOresult()){
  1232.         int Lx=0;
  1233.         int Ly=0;
  1234.         RBlockRead(ff1,&Lx,2);
  1235.         RBlockRead(ff1,&Ly,2);
  1236.         if(Lx>0&&Ly>0){
  1237.             PicPtr=(word*)(new char[Lx*Ly+4]);
  1238.             RBlockRead(ff1,PicPtr+2,Lx*Ly);
  1239.             PicPtr[0]=Lx;
  1240.             PicPtr[1]=Ly;
  1241.         }else PicPtr=NULL;
  1242.     }else{
  1243.         PicPtr=NULL;
  1244.         
  1245.     };
  1246. };
  1247. SQPicture::~SQPicture(){
  1248.     if(PicPtr)free(PicPtr);
  1249. };
  1250. SQPicture::SQPicture(){
  1251.     PicPtr=NULL;
  1252. };
  1253. //-----end of pictures
  1254. //--------------Handling dialog system----------------//
  1255. void MFix();
  1256. void RedrawGameBackground();
  1257. void DialogsSystem::ProcessDialogs(){
  1258.     if(MUSTDRAW){
  1259.         MUSTDRAW=false;
  1260.         RedrawGameBackground();
  1261.         MarkToDraw();
  1262.     };
  1263.     for(int i=0;i<512;i++){
  1264.         SimpleDialog* SD=DSS[i];
  1265.         if(SD&&SD->Enabled){
  1266.             if(SD->Refresh)
  1267.                 SD->Refresh(SD);
  1268.             if(SD->Active){
  1269.                 if(SD->OnKeyDown){
  1270.                     if(KeyPressed&&SD->OnKeyDown(SD))KeyPressed=false;
  1271.                 };
  1272.             };
  1273.             if(mouseX>=SD->x&&mouseX<=SD->x1&&mouseY>=SD->y&&mouseY<=SD->y1){
  1274.                 if(SD->OnMouseOver)SD->OnMouseOver(SD);
  1275.                 if(SD->MouseOverActive)SD->NeedToDraw=true;
  1276.                 SD->MouseOver=true;
  1277.                 if(Lpressed){
  1278.                     if(SD->OnUserClick){
  1279.                         SD->OnUserClick(SD);
  1280.                         Lpressed=false;
  1281.                     };
  1282.                     if(SD->OnClick){
  1283.                         if(SD->OnClick(SD)){
  1284.                             for(int j=0;j<512;j++){
  1285.                                 SimpleDialog* SD1=DSS[j];
  1286.                                 if(SD1&&SD1!=SD)SD1->Active=false;
  1287.                             };
  1288.                         };
  1289.                         Lpressed=false;
  1290.                     };
  1291.                 };
  1292.             }else{
  1293.                 if(SD->MouseOver&&SD->MouseOverActive)SD->NeedToDraw=true;
  1294.                 SD->MouseOver=false;
  1295.             };
  1296.         };
  1297.         if(SD&&!SD->Enabled){
  1298.             if(SD->OnDraw)SD->OnDraw(SD);
  1299.             SD->NeedToDraw=true;
  1300.         };
  1301.     };
  1302.     for(i=0;i<512;i++){
  1303.         SimpleDialog* SD=DSS[i];
  1304.         if(SD&&SD->OnDraw){
  1305.             if(SD->NeedToDraw||(SD->Parent&&SD->Parent->NeedToDraw)){
  1306.                 //if(SD->Parent&&SD->Parent->NeedToDraw)SD->NeedToDraw=true;
  1307.                 SD->OnDraw(SD);
  1308.             };
  1309.         };
  1310.     };
  1311.     MFix();
  1312. };
  1313. void RedrawOffScreenMouse();
  1314. void OnMouseMoveRedraw();
  1315. void PostRedrawMouse();
  1316. void SERROR();
  1317. void SERROR1();
  1318. void SERROR2();
  1319. extern bool InGame;
  1320. void DialogsSystem::RefreshView(){
  1321.     if(!DDDebug){
  1322.         //if(InGame)SERROR1();
  1323.         RedrawOffScreenMouse();
  1324.         //if(InGame)SERROR1();
  1325.         //FlipPages();
  1326.         for(int i=0;i<512;i++){
  1327.             //if(InGame)SERROR();
  1328.             SimpleDialog* SD=DSS[i];
  1329.             if(SD&&SD->NeedToDraw){
  1330.                 CopyToScreen(SD->x,SD->y,SD->x1-SD->x+1,SD->y1-SD->y+1);
  1331.                 SD->NeedToDraw=false;
  1332.             };
  1333.         };
  1334.         //if(InGame)SERROR2();
  1335.         PostRedrawMouse();
  1336.         //if(InGame)SERROR1();
  1337.     }else{
  1338.         if(DDDebug)RSCRSizeX=SCRSizeX;
  1339.         RedrawOffScreenMouse();
  1340.         PostRedrawMouse();
  1341.         //LockMouse=false;
  1342.         FlipPages();
  1343.     };
  1344. };
  1345. void DialogsSystem::CloseDialogs(){
  1346.     for(int i=0;i<512;i++){
  1347.         SimpleDialog* SD=DSS[i];
  1348.         if(SD){
  1349.             if(SD->Destroy)SD->Destroy(SD);
  1350.             free(SD);
  1351.             DSS[i]=NULL;
  1352.         };
  1353.     };
  1354. };
  1355. void DialogsSystem::MarkToDraw(){
  1356.     for(int i=0;i<512;i++)
  1357.         if(DSS[i])DSS[i]->NeedToDraw=true;
  1358. };
  1359. //----------end of handler of the dialogsystem--------//
  1360. DialogsSystem::~DialogsSystem(){
  1361.     CloseDialogs();
  1362. };