source: abuse/trunk/src/devsel.cpp @ 494

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

style: remove trailing spaces, fix copyright statements.

File size: 3.8 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
5 *
6 *  This software was released into the Public Domain. As with most public
7 *  domain software, no warranty is made or implied by Crack dot Com or
8 *  Jonathan Clark.
9 */
10
11#include "config.h"
12
13#include "devsel.h"
14#include "scroller.h"
15#include "cache.h"
16#include "game.h"
17
18void scale_put(image *im, image *screen, int x, int y, short new_width, short new_height);
19void scale_put_trans(image *im, image *screen, int x, int y, short new_width, short new_height);
20int cur_bg=0,cur_fg=0,cur_char=0;
21
22void tile_picker::recenter(image *screen)
23{
24  set_x(get_current(), screen);
25}
26
27int tile_picker::picw()
28{
29  switch (type)
30  {
31    case SPEC_FORETILE :
32    {
33      return cache.foret(foretiles[0])->im->width()/scale;
34    } break;
35    case SPEC_BACKTILE :
36    {
37      return cache.backt(backtiles[0])->im->width()/scale;
38    } break;
39    default :
40      return 30/scale;
41  }
42}
43
44int tile_picker::pich()
45{
46  switch (type)
47  {
48    case SPEC_FORETILE :
49    {
50      return cache.foret(foretiles[0])->im->height()/scale;
51    } break;
52    case SPEC_BACKTILE :
53    {
54      return cache.backt(backtiles[0])->im->height()/scale;
55    } break;
56    default :
57      return 40/scale;
58  }
59}
60
61int tile_picker::total()
62{
63  switch (type)
64  {
65    case SPEC_FORETILE :
66    { return nforetiles; } break;
67    case SPEC_BACKTILE :
68    { return nbacktiles; } break;
69    case SPEC_CHARACTER :
70    { return total_objects; } break;
71  }
72  return 1;
73}
74
75tile_picker::tile_picker(int X, int Y, int ID, int spec_type,
76             int Scale, int scroll_h, int Wid, ifield *Next)
77     : scroller(X,Y,ID,2,2,1,0,Next)
78{
79  wid=Wid;
80  type=spec_type;
81  th=scroll_h;
82  scale=Scale;
83  set_size(picw()*wid,pich()*th);
84  sx=get_current();
85  t=total();
86}
87
88
89void tile_picker::scroll_event(int newx, image *screen)
90{
91  int yo=y,ya=pich(),xw=picw(),c=get_current(),xo;
92  image im(xw,ya);
93  last_sel=newx;
94
95  screen->bar(x,y,x+l-1,y+h-1,wm->black());
96  for (int i=newx; i<newx+th*wid; i++)
97  {
98    xo=x+((i-newx)%wid)*xw;
99    yo=y+((i-newx)/wid)*ya;
100
101      int blank=0;
102      if (i<t)
103      {
104    switch (type)
105    {
106      case SPEC_FORETILE :
107      {
108        if (foretiles[i]<0) blank=1;
109        else
110        {
111          im.clear();
112          the_game->get_fg(i)->im->put_image(&im,0,0);
113
114          if (rev)
115          {
116        screen->bar(xo,yo,xo+xw-1,yo+ya-1,wm->bright_color());
117        scale_put_trans(&im,screen,xo,yo,xw,ya);
118          }
119          else scale_put(&im,screen,xo,yo,xw,ya);
120        }
121      } break;
122      case SPEC_BACKTILE :
123      {
124        if (backtiles[i]<0) blank=1;
125        else
126          scale_put(the_game->get_bg(i)->im,screen,xo,yo,xw,ya);
127
128      } break;
129      case SPEC_CHARACTER :
130      {
131        figures[i]->get_sequence(stopped)->get_figure(0)->forward->put_image(&im,0,0);
132        scale_put(&im,screen,xo,yo,xw,ya);
133      } break;
134    }
135      } else blank=1;
136
137      if (i==c)
138        screen->rectangle(xo,yo,xo+xw-1,yo+ya-1,wm->bright_color());
139
140
141  }
142}
143
144
145void tile_picker::handle_inside_event(event &ev, image *screen, InputManager *inm)
146{
147  if (ev.type==EV_MOUSE_BUTTON)
148  {
149    int sel=((ev.mouse_move.y-y)/pich()*wid)+(ev.mouse_move.x-x)/picw()+last_sel;
150    if (sel<t && sel>=0 && sel!=get_current())
151    {
152      set_current(sel);
153      scroll_event(last_sel, screen);
154    }
155  }
156}
157
158
159
160
161int tile_picker::get_current()
162{
163  switch (type)
164  {
165    case SPEC_FORETILE :
166    { return cur_fg; } break;
167    case SPEC_BACKTILE :
168    { return cur_bg; } break;
169    case SPEC_CHARACTER :
170    { return cur_char; } break;
171  }
172  return 0;
173}
174
175void tile_picker::set_current(int x)
176{
177  switch (type)
178  {
179    case SPEC_FORETILE :
180    { cur_fg=x; } break;
181    case SPEC_BACKTILE :
182    { cur_bg=x; } break;
183    case SPEC_CHARACTER :
184    { cur_char=x; } break;
185  }
186}
187
188
189
190
191
Note: See TracBrowser for help on using the repository browser.