1
// $Id: surface_selector.cxx,v 1.7 2003/02/19 09:50:36 grumbel Exp $
3
// Pingus - A free Lemmings clone
4
// Copyright (C) 2000 Ingo Ruhnke <grumbel@gmx.de>
6
// This program is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU General Public License
8
// as published by the Free Software Foundation; either version 2
9
// of the License, or (at your option) any later version.
11
// This program is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
// GNU General Public License for more details.
16
// You should have received a copy of the GNU General Public License
17
// along with this program; if not, write to the Free Software
18
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
#include <ClanLib/Core/System/system.h>
22
#include <ClanLib/Display/Display/display.h>
23
#include <ClanLib/Display/Input/mouse.h>
24
#include "../gui/display.hxx"
25
#include "../pingus_resource.hxx"
26
#include "surface_selector.hxx"
28
SurfaceSelector::SurfaceSelector (std::vector<surface_obj>* s)
29
: font(PingusResource::load_font("Fonts/courier_small", "fonts")),
32
width(CL_Display::get_width() - (CL_Display::get_width() % 50)),
33
height((sur_list->size() / (CL_Display::get_width() / 50)) * 50),
34
c_obj(std::vector<surface_obj>::iterator())
38
SurfaceSelector::~SurfaceSelector ()
43
std::vector<surface_obj>::iterator
44
SurfaceSelector::get_current_obj ()
49
for(std::vector<surface_obj>::iterator i = sur_list->begin();
53
if (CL_Mouse::get_x() > x && CL_Mouse::get_x() <= x + 50
54
&& CL_Mouse::get_y() > y && CL_Mouse::get_y() <= y + 50)
60
if (x + 50 > CL_Display::get_width())
67
return std::vector<surface_obj>::iterator();
71
SurfaceSelector::draw ()
73
// FIXME: This could heavily optimized if ClanLib would have a put_target(x,y,w,h)
74
std::vector<surface_obj>::iterator tmp_obj = get_current_obj();
78
if (tmp_obj != std::vector<surface_obj>::iterator())
79
tmp_obj->display_time = CL_System::get_time();
81
if (c_obj != std::vector<surface_obj>::iterator())
82
c_obj->display_time = 0;
90
CL_System::keep_alive();
92
CL_Display::clear_display();
95
for(std::vector<surface_obj>::iterator i = sur_list->begin(); i != sur_list->end(); ++i)
97
if (i->thumbnail.get_width() <= 50 && i->thumbnail.get_height() <= 50)
99
i->thumbnail.put_screen(x + 25 - (i->thumbnail.get_width() / 2),
100
y + 25 - (i->thumbnail.get_height() / 2));
104
i->thumbnail.put_screen(x, y);
109
Display::draw_rect(x, y, x + 50, y + 50, 1.0, 1.0, 1.0, 1.0);
113
if (x + 50 > CL_Display::get_width())
120
//Display::draw_rect(CL_Display::get_width() - 16, y/10,
121
//CL_Display::get_width(), y+1/10,
122
//1.0, 1.0, 1.0, 1.0);
124
// Draw the current object in the bottom/left corner when the
125
// surface is selected for more then 1sec
126
if (c_obj != std::vector<surface_obj>::iterator()
127
&& (c_obj->display_time + 350 < CL_System::get_time ()
128
|| c_obj->large_sur))
130
if (!c_obj->large_sur)
132
std::cout << "Loading: " << c_obj->name << " " << c_obj->datafile << std::endl;
133
c_obj->large_sur = PingusResource::load_surface (c_obj->name, c_obj->datafile);
136
CL_Display::fill_rect(0, CL_Display::get_height() - c_obj->large_sur.get_height(),
137
c_obj->large_sur.get_width(), CL_Display::get_height(),
138
0.5f, 0.5f, 0.5f, 0.8f);
139
c_obj->large_sur.put_screen(0, CL_Display::get_height() - c_obj->large_sur.get_height());
141
Display::flip_display();
145
SurfaceSelector::scroll ()
147
const int range = 100;
149
if (CL_Mouse::get_y() > CL_Display::get_height() - range)
151
y_of += range - (CL_Display::get_height() - CL_Mouse::get_y());
153
else if (CL_Mouse::get_y() < range)
155
y_of -= range - CL_Mouse::get_y();
158
if (y_of < 0) y_of = 0;
160
if (y_of > height) y_of = height;
164
SurfaceSelector::select ()
167
std::vector<surface_obj>::iterator iter;
169
while (!CL_Mouse::left_pressed())
175
CL_System::keep_alive();
178
iter = get_current_obj();
180
if (iter != std::vector<surface_obj>::iterator())
183
std::cout << "str: " << str << std::endl;
188
surface_obj::surface_obj ()
192
surface_obj::surface_obj (const surface_obj& old) : thumbnail(old.thumbnail),
193
large_sur(old.large_sur),
195
datafile(old.datafile),
196
display_time(old.display_time)
200
surface_obj& surface_obj::operator= (const surface_obj& old)
204
thumbnail = old.thumbnail;
205
large_sur = old.large_sur;
207
datafile = old.datafile;
208
display_time = old.display_time;