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