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

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

imlib: refactor a few image methods so that they use vec2i.

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