source: abuse/trunk/src/director.cpp @ 659

Last change on this file since 659 was 645, checked in by Sam Hocevar, 11 years ago

imlib: clean up EventHandler? and JCMouse.

File size: 4.5 KB
RevLine 
[56]1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
[494]4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
[56]5 *
6 *  This software was released into the Public Domain. As with most public
[555]7 *  domain software, no warranty is made or implied by Crack dot Com, by
8 *  Jonathan Clark, or by Sam Hocevar.
[56]9 */
10
[555]11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
[56]14
[512]15#include "common.h"
16
[481]17#include "director.h"
18#include "game.h"
19#include "lisp.h"
20#include "fonts.h"
[2]21
22director scene_director;
23
[124]24void director::scroll_text(char *Text)
25{ text=Text;
[2]26  text_y=the_game->first_view->cy2-the_game->first_view->cy1+1;
27}
28
29director::director()
30{
31  tleft=ttop=tright=tbottom=pan_xv=pan_yv=0;
32  text_step=-2;
33  frame_speed=100;
34  scroll_speed=60;
35  pan_speed=60;
36  scene_abort=0;
37}
38
39extern unsigned char *white_light;
40
41
42
[39]43int text_draw(int y, int x1, int y1, int x2, int y2, char const *buf, JCFont *font, uint8_t *cmap, char color)
[2]44{
[518]45  int cx1, cy1, cx2, cy2, word_size, word_len;
[643]46  main_screen->GetClip(cx1, cy1, cx2, cy2);
47  main_screen->InClip(x1,y1,x2+1,y2+1);
[2]48  int h=font->height()+2,w=font->width(),x=x1,dist;
49  y+=y1;
[39]50  char const *word_start;
[2]51
52  while (buf && *buf)
53  {
[124]54    do
55    {
[2]56      if (*buf=='\\' && buf[1]=='n')
57      {
[124]58    x=x1;
59    y+=h*2;
60    buf+=2;
[2]61      }
[124]62
[2]63      // skip space
64      if (*buf==' ' || *buf=='\r' || *buf=='\n' || *buf=='\t')
[124]65      {
66    x+=w;
67    while (*buf==' ' || *buf=='\r' || *buf=='\n' || *buf=='\t')   // skip space until next word
[2]68          buf++;
69      }
70
71      word_start=buf;
[494]72      for (word_len=0,word_start=buf,word_size=0; *buf && *buf!=' ' && *buf!='\r' && *buf!='\n' &&
73       *buf!='\t' && (*buf!='\\' || buf[1]!='n'); buf++,word_size+=w,word_len++);
[124]74
[2]75      if (word_size<x2-x1) // make sure the word can fit on the screen
76      {
[124]77    if (word_size+x>x2)    // does word not fit on line?
78    {
79      y+=h;                // go to next line
80      x=x1;
81    }
[2]82      }
83
84
85      if (y+h<y1)         // word on screen yet?
[124]86    x+=word_size;
[2]87
88    } while (*buf && y+h<y1);     // if not on screen yet, fetch next word
89
90    dist=31;
91    if (y-y1<dist)
[162]92    {
[2]93      if (y-y1<1) dist=0;
94      else dist=y-y1;
[162]95    }
[2]96
97    if (y2-y<dist)
[162]98    {
[2]99      if (y2-y<1) dist=0;
[124]100      else dist=y2-y;
[162]101    }
[2]102
103    int c=cmap[dist];
[124]104    if (y>y2) { buf=NULL; }
[2]105    else
106    {
107      while (word_len--)
108      {
[643]109    font->put_char(main_screen,x+1,y+1,*word_start,0);
110    font->put_char(main_screen,x,y,*word_start,c);
[124]111    word_start++;
112    x+=w;
[2]113      }
114    }
115
116  }
[643]117  main_screen->SetClip(cx1,cy1,cx2,cy2);
[124]118  return (y<=y1);
[2]119}
120
121void director::wait(void *arg)
122{
123  if (scene_abort) return ;
124  pan_time=frame_time=text_time=NULL;
125  int done=0;
[492]126  LSymbol *pan_symbol = LSymbol::FindOrCreate("pan"),
127             *text_symbol = LSymbol::FindOrCreate("text");
[124]128
[106]129  JCFont *font=wm->font();
[2]130
131  do
132  {
133    the_game->draw_map(the_game->first_view);
134    time_marker cur_time;
135
136    if (pan_steps)
137    {
138      if (pan_time)
139      {
[124]140    if ((int)(cur_time.diff_time(pan_time)*1000)>pan_speed)
141    {
142      the_game->pan(pan_xv,pan_yv);
143      pan_steps--;
144      delete pan_time;
145      if (pan_steps)
146          pan_time=new time_marker;
147      else pan_time=NULL;
148    }
[2]149      } else pan_time=new time_marker;
150    } else if (arg==pan_symbol) done=1;
151
152    if (text)
153    {
154      if (text_draw(text_y,
[124]155            the_game->first_view->cx1+tleft,
156            the_game->first_view->cy1+ttop,
157            the_game->first_view->cx2-tright,
158            the_game->first_view->cy2-tbottom,text,font,
159            white_light+32*256,
160            wm->bright_color()
[494]161
[124]162            ))
[2]163        text=NULL;
164      if (text_time)
165      {
[124]166    if ((int)(cur_time.diff_time(text_time)*1000)>scroll_speed)
[494]167    {
[124]168      text_y+=text_step;
169      delete text_time;
170      if (text)
[494]171        text_time=new time_marker;
[124]172      else
173        text_time=NULL;
174    }
[494]175      } else text_time=new time_marker;
[2]176    } else if (arg==text_symbol) done=1;
[494]177
178    wm->flush_screen();
[645]179    while (wm->IsPending())
[494]180    {
[643]181      Event ev;
[106]182      wm->get_event(ev);
[2]183      if (ev.type==EV_KEY)
184      {
[124]185    switch (ev.key)
186    {
187      case JK_UP :
188      case JK_LEFT :
189      {
190        if (scroll_speed>=20)
191        scroll_speed-=20;
192          else text_step--;
193      }
194      break;
195      case JK_RIGHT :
196      case JK_DOWN :
197      {
198        if (text_step<-2)
199        text_step++;
200        else if (scroll_speed<200) scroll_speed+=20;
201        break;
202        case JK_ESC : set_abort(1); done=1; break;
203        case JK_ENTER : done=1; break;
204      }
205    }
[494]206      }
207    }
[2]208  } while (!done);
209  if (pan_time) delete pan_time;
210  if (frame_time) delete frame_time;
211  if (text_time) delete text_time;
212}
213
Note: See TracBrowser for help on using the repository browser.