aboutsummaryrefslogtreecommitdiff
path: root/engines/mortevielle/alert.h
blob: c3a45fe5294318bd884e60a035535f59ef5a36e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/* overlay */ integer do_alert(str255 str_, integer n);


const integer nligne = 7;
const matrix<1,2,1,3,integer> coord
      = {{ {{150, 72, 103}},
         {{143, 107, 183}} }};



static void decod(str255 s, integer& nbc,integer& nbl,integer& col, str255& c, str30& cs)
    {
          integer i,k;
          boolean v;

      val(s[2],nbc,i);
      c= "";
      nbl= 0; i= 5; k= 0;
      v=true; col=0;

      while (s[i]!=']') 
        {
          c=c+s[i];
          if ((s[i]=='|') || (s[i+1]==']')) 
             {
               if (k>col)  col=k;
               k= 0;
               nbl=nbl+1;
             }
           else if (s[i]!=' ')  v=false;
          i=i+1;
          k=k+1;
        }
      if (v)  {
                  c="";
                  col=20;
                }
           else {
                  c=c+']';
                  col=col+6;
                }
      i=i+1;
      cs=copy(s,i,30);
      if (res==2)  col= col*6;
               else col= col*10;
    }



static void posit(integer ji, integer& coldep, integer& esp)
   {
     putxy(coldep + (40+esp) *pred(integer,ji),98);
   }



static void fait_boite(integer lidep,integer nli,integer tx)
   {
         integer x,y,xx,yy;

     if (tx>640)  tx=640;
     x= 320- ((cardinal)tx >> 1);
     y=pred(integer,lidep) << 3;
     xx=x+ tx;
     yy=y + (nli << 3);
     box(15,gd,x,y,xx,yy,255);
     box(0,gd,x,y+2,xx,y+4,255);
     box(0,gd,x,yy-4,xx,yy-2,255);
   }



static void fait_choix(str30 c, integer& coldep, integer& nbcase, array<1,2,varying_string<3> >& s, integer& esp)
   {
         integer i,l,x;
         char ch;

     i=1;
     x=coldep;
     for( l=1; l <= nbcase; l ++)
       {
         s[l]="";
         do {
           i=i+1;
           ch=c[i];
           s[l]=s[l]+ch;
         } while (!(c[i+1]==']'));
         i=i+2;
         while (length(s[l])<3)  s[l]=s[l]+' ';
         putxy(x,98);
         writeg(string(' ')+s[l]+' ',0);
         x= x+esp+40;
       }
   }

              integer do_alert(str255 str_, integer n)
{
       integer coldep,esp,i,l,nbcase,quoi,ix;
       str255 st, chaine;
       matrix<1,2,1,2,integer> limit;
       char c,dumi;
       array<1,2,varying_string<3> > s;
       integer cx,cy,cd,nbcol,nblig;
       boolean touch,newaff,test,test1,test2,test3,dum;
       str30 cas;


  /*debug('** do_alert **');*/
  integer do_alert_result;
  hide_mouse();
  while (keypressed())  input >> kbd >> dumi;
  clic=false;
  decod(str_,nbcase,nblig,nbcol,chaine,cas);
  sauvecr(50,succ(integer,nligne) << 4);

  i=0;
  if (chaine=="") 
    {
      fait_boite(10,5,nbcol);
    }
   else
    {
      fait_boite(8,7,nbcol);
      i=0;
      ywhere=70;
      do {
        cx= 320;
        st= "";
        while (! (set::of('\174','\135', eos).has(chaine[i+1]))) 
          {
            i=i+1;
            st=st+chaine[i];
            if (res==2)  cx=cx-3;
                     else cx=cx-5;
          }
        putxy(cx,ywhere);
        ywhere=ywhere+6;
        writeg(st,4);
        i=i+1;
      } while (!(chaine[i]==']'));
    }
  if (nbcase==1)  esp= nbcol- 40;
              else esp= (cardinal)(nbcol-nbcase*40) >> 1;
  coldep=320-((cardinal)nbcol >> 1)+((cardinal)esp >> 1);
  fait_choix(cas, coldep, nbcase, s, esp);
  limit[1][1]=((cardinal)(coldep) >> 1)*res;
  limit[1][2]=limit[1][1]+40;
  if (nbcase==1) 
     {
       limit[2][1]=limit[2][2];
     }
   else
     {
       limit[2][1]=((cardinal)(320+((cardinal)esp >> 1)) >> 1)*res;
       limit[2][2]=(limit[2][1])+40;
     }
  show_mouse();
  quoi=0;
  dum=false;
  do {
    dumi='\377';
    mov_mouse(dum,dumi);
    cx= x_s;
    cy= y_s;
    test=(cy>95) && (cy<105);
    newaff=false;
    if (test) 
     {
       test1=(cx>limit[1][1]) && (cx<limit[1][2]);
       test2=test1;
       if (nbcase>1)  test2= test1 || ((cx>limit[2][1]) && (cx<limit[2][2]));
       if (test2) 
        {
          newaff=true;
          if (test1)  ix=1;
                   else ix=2;
          if (ix!=quoi)  
           {
             hide_mouse();
             if (quoi!=0) 
              {
                posit(quoi, coldep, esp);
                writeg(string(' ')+s[quoi]+' ',0);
              }
             posit(ix, coldep, esp);
             writeg(string(' ')+s[ix]+' ',1);
             quoi=ix;
             show_mouse();
           }
        }
     }
    if ((quoi!=0) && ! newaff) 
     {
       hide_mouse();
       posit(quoi, coldep, esp);
       writeg(string(' ')+s[quoi]+' ',0);
       quoi=0;
       show_mouse();
     }
     test3=(cy>95) && (cy<105) && (((cx>limit[1][1]) && (cx<limit[1][2]))
                                   || ((cx>limit[2][1]) && (cx<limit[2][2])));
  } while (!clic);
  clic=false;
  hide_mouse();
  if (! test3)  {
                  quoi=n;
                  posit(n, coldep, esp);
                  writeg(string(' ')+s[n]+' ',1);
                }
  charecr(50,succ(integer,nligne) << 4);
  show_mouse();
  do_alert_result=quoi;
  return do_alert_result;
}