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

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

core: rename vec2i to ivec2 and update matrix.h from Lol Engine.

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{
[659]95  int ya = pich(), xw = picw(), c = get_current();
[682]96  image im(ivec2(xw, ya));
[2]97  last_sel=newx;
98
[682]99  screen->Bar(m_pos, m_pos + ivec2(l - 1, h - 1), wm->black());
[494]100  for (int i=newx; i<newx+th*wid; i++)
[2]101  {
[682]102    ivec2 xyo = m_pos + ivec2(((i - newx) % wid) * xw, ((i - newx) / wid) * ya);
[2]103
104      int blank=0;
105      if (i<t)
[494]106      {
[124]107    switch (type)
108    {
109      case SPEC_FORETILE :
110      {
111        if (foretiles[i]<0) blank=1;
112        else
113        {
114          im.clear();
[682]115          the_game->get_fg(i)->im->PutImage(&im,ivec2(0,0));
[2]116
[124]117          if (rev)
118          {
[682]119        screen->Bar(xyo, xyo + ivec2(xw - 1, ya - 1), wm->bright_color());
[659]120        scale_put_trans(&im,screen,xyo.x,xyo.y,xw,ya);
[124]121          }
[659]122          else scale_put(&im,screen,xyo.x,xyo.y,xw,ya);
[124]123        }
124      } break;
125      case SPEC_BACKTILE :
126      {
127        if (backtiles[i]<0) blank=1;
128        else
[659]129          scale_put(the_game->get_bg(i)->im,screen,m_pos.x,m_pos.y,xw,ya);
[494]130
[124]131      } break;
132      case SPEC_CHARACTER :
133      {
[682]134        figures[i]->get_sequence(stopped)->get_figure(0)->forward->PutImage(&im,ivec2(0,0));
[659]135        scale_put(&im,screen,m_pos.x,m_pos.y,xw,ya);
[124]136      } break;
137    }
[2]138      } else blank=1;
139
140      if (i==c)
[682]141        screen->Rectangle(m_pos, m_pos + ivec2(xw - 1, ya - 1),
[655]142                          wm->bright_color());
[2]143
144
145  }
146}
147
148
[643]149void tile_picker::handle_inside_event(Event &ev, image *screen, InputManager *inm)
[2]150{
151  if (ev.type==EV_MOUSE_BUTTON)
152  {
[659]153    int sel=((ev.mouse_move.y-m_pos.y)/pich()*wid)+(ev.mouse_move.x-m_pos.x)/picw()+last_sel;
[2]154    if (sel<t && sel>=0 && sel!=get_current())
155    {
156      set_current(sel);
[106]157      scroll_event(last_sel, screen);
[2]158    }
159  }
160}
161
162
163
164
165int tile_picker::get_current()
166{
167  switch (type)
[124]168  {
169    case SPEC_FORETILE :
[494]170    { return cur_fg; } break;
[124]171    case SPEC_BACKTILE :
[494]172    { return cur_bg; } break;
[124]173    case SPEC_CHARACTER :
[494]174    { return cur_char; } break;
[2]175  }
176  return 0;
177}
178
179void tile_picker::set_current(int x)
180{
181  switch (type)
182  {
[124]183    case SPEC_FORETILE :
[494]184    { cur_fg=x; } break;
[124]185    case SPEC_BACKTILE :
[494]186    { cur_bg=x; } break;
[124]187    case SPEC_CHARACTER :
[494]188    { cur_char=x; } break;
[2]189  }
190}
191
192
193
194
195
Note: See TracBrowser for help on using the repository browser.