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

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