source: abuse/branches/lol/src/director.cpp @ 732

Last change on this file since 732 was 732, checked in by Sam Hocevar, 8 years ago

build: SDL2 compilation fixes.

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