1 // $Id: worldview_zoom_tool.cxx,v 1.6 2003/07/24 10:10:02 grumbel Exp $
3 // Construo - A wire-frame construction gamee
4 // Copyright (C) 2002 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 "construo.hxx"
22 #include "input_context.hxx"
24 #include "worldview_component.hxx"
25 #include "worldview_zoom_tool.hxx"
27 WorldViewZoomTool::WorldViewZoomTool ()
29 creating_zoom_rectangle
= false;
32 WorldViewZoomTool::~WorldViewZoomTool ()
37 WorldViewZoomTool::activate ()
39 creating_zoom_rectangle
= false;
43 WorldViewZoomTool::draw_foreground (ZoomGraphicContext
* gc
)
45 if (creating_zoom_rectangle
)
47 float x
= WorldViewComponent::instance()->get_gc()->screen_to_world_x (input_context
->get_mouse_x ());
48 float y
= WorldViewComponent::instance()->get_gc()->screen_to_world_y (input_context
->get_mouse_y ());
50 gc
->draw_rect (Math::min(x
, click_pos
.x
),
51 Math::min(y
, click_pos
.y
),
52 Math::max(x
, click_pos
.x
),
53 Math::max(y
, click_pos
.y
),
59 WorldViewZoomTool::on_primary_button_press (int screen_x
, int screen_y
)
61 creating_zoom_rectangle
= true;
62 click_pos
.x
= WorldViewComponent::instance()->get_gc()->screen_to_world_x (screen_x
);
63 click_pos
.y
= WorldViewComponent::instance()->get_gc()->screen_to_world_y (screen_y
);
67 WorldViewZoomTool::on_primary_button_release (int screen_x
, int screen_y
)
69 creating_zoom_rectangle
= false;
71 float x
= WorldViewComponent::instance()->get_gc()->screen_to_world_x (screen_x
);
72 float y
= WorldViewComponent::instance()->get_gc()->screen_to_world_y (screen_y
);
74 WorldViewComponent::instance()->get_gc()->zoom_to((int)Math::min(x
, click_pos
.x
),
75 (int)Math::min(y
, click_pos
.y
),
76 (int)Math::max(x
, click_pos
.x
),
77 (int)Math::max(y
, click_pos
.y
));
81 WorldViewZoomTool::on_secondary_button_press (int x
, int y
)
83 WorldViewComponent::instance()->get_gc()->zoom_out(x
, y
);
87 WorldViewZoomTool::on_secondary_button_release (int x
, int y
)