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

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

imlib: use vec2i for image::size and unroll all necessary changes
everywhere else in the code.

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