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

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

imlib: some more vec2i transition for simplicity.

File size: 3.8 KB
RevLine 
[56]1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
[494]4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
[56]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
[512]13#include "common.h"
14
[481]15#include "devsel.h"
16#include "scroller.h"
17#include "cache.h"
18#include "game.h"
[2]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
[106]24void tile_picker::recenter(image *screen)
[2]25{
[106]26  set_x(get_current(), screen);
[2]27}
28
29int tile_picker::picw()
30{
31  switch (type)
32  {
33    case SPEC_FORETILE :
34    {
[123]35      return cache.foret(foretiles[0])->im->width()/scale;
[2]36    } break;
37    case SPEC_BACKTILE :
38    {
[512]39      return cache.backt(backtiles[0])->im->Size().x/scale;
[2]40    } break;
41    default :
[124]42      return 30/scale;
[2]43  }
44}
45
46int tile_picker::pich()
47{
48  switch (type)
49  {
50    case SPEC_FORETILE :
51    {
[123]52      return cache.foret(foretiles[0])->im->height()/scale;
[2]53    } break;
54    case SPEC_BACKTILE :
55    {
[512]56      return cache.backt(backtiles[0])->im->Size().y/scale;
[2]57    } break;
58    default :
[124]59      return 40/scale;
[2]60  }
61}
62
63int tile_picker::total()
64{
65  switch (type)
66  {
67    case SPEC_FORETILE :
68    { return nforetiles; } break;
69    case SPEC_BACKTILE :
[124]70    { return nbacktiles; } break;
[2]71    case SPEC_CHARACTER :
[124]72    { return total_objects; } break;
[2]73  }
74  return 1;
75}
76
[124]77tile_picker::tile_picker(int X, int Y, int ID, int spec_type,
78             int Scale, int scroll_h, int Wid, ifield *Next)
[2]79     : scroller(X,Y,ID,2,2,1,0,Next)
[124]80{
[2]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
[106]91void tile_picker::scroll_event(int newx, image *screen)
[2]92{
93  int yo=y,ya=pich(),xw=picw(),c=get_current(),xo;
[513]94  image im(vec2i(xw, ya));
[2]95  last_sel=newx;
96
[106]97  screen->bar(x,y,x+l-1,y+h-1,wm->black());
[494]98  for (int i=newx; i<newx+th*wid; i++)
[2]99  {
100    xo=x+((i-newx)%wid)*xw;
101    yo=y+((i-newx)/wid)*ya;
102
103      int blank=0;
104      if (i<t)
[494]105      {
[124]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);
[2]115
[124]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);
[494]129
[124]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    }
[2]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
[120]147void tile_picker::handle_inside_event(event &ev, image *screen, InputManager *inm)
[2]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);
[106]155      scroll_event(last_sel, screen);
[2]156    }
157  }
158}
159
160
161
162
163int tile_picker::get_current()
164{
165  switch (type)
[124]166  {
167    case SPEC_FORETILE :
[494]168    { return cur_fg; } break;
[124]169    case SPEC_BACKTILE :
[494]170    { return cur_bg; } break;
[124]171    case SPEC_CHARACTER :
[494]172    { return cur_char; } break;
[2]173  }
174  return 0;
175}
176
177void tile_picker::set_current(int x)
178{
179  switch (type)
180  {
[124]181    case SPEC_FORETILE :
[494]182    { cur_fg=x; } break;
[124]183    case SPEC_BACKTILE :
[494]184    { cur_bg=x; } break;
[124]185    case SPEC_CHARACTER :
[494]186    { cur_char=x; } break;
[2]187  }
188}
189
190
191
192
193
Note: See TracBrowser for help on using the repository browser.