00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 #include "colors.hxx"
00021 #include "construo.hxx"
00022 #include "input_context.hxx"
00023 #include "math.hxx"
00024 #include "worldview_component.hxx"
00025 #include "worldview_zoom_tool.hxx"
00026 
00027 WorldViewZoomTool::WorldViewZoomTool ()
00028 {
00029   creating_zoom_rectangle = false;
00030 }
00031 
00032 WorldViewZoomTool::~WorldViewZoomTool ()
00033 {
00034 }
00035 
00036 void
00037 WorldViewZoomTool::activate ()
00038 {
00039   creating_zoom_rectangle = false;
00040 }
00041 
00042 void
00043 WorldViewZoomTool::draw_foreground (ZoomGraphicContext* gc)
00044 {
00045   if (creating_zoom_rectangle)
00046     {
00047       float x = WorldViewComponent::instance()->get_gc()->screen_to_world_x (input_context->get_mouse_x ());
00048       float y = WorldViewComponent::instance()->get_gc()->screen_to_world_y (input_context->get_mouse_y ());               
00049       
00050       gc->draw_rect (Math::min(x, click_pos.x),
00051                      Math::min(y, click_pos.y),
00052                      Math::max(x, click_pos.x),
00053                      Math::max(y, click_pos.y),
00054                      Colors::new_spring);
00055     }
00056 }
00057 
00058 void
00059 WorldViewZoomTool::on_primary_button_press (int screen_x, int screen_y)
00060 {
00061   creating_zoom_rectangle = true;
00062   click_pos.x = WorldViewComponent::instance()->get_gc()->screen_to_world_x (screen_x);
00063   click_pos.y = WorldViewComponent::instance()->get_gc()->screen_to_world_y (screen_y);
00064 }  
00065 
00066 void
00067 WorldViewZoomTool::on_primary_button_release (int screen_x, int screen_y)
00068 {
00069   creating_zoom_rectangle = false;
00070 
00071   float x = WorldViewComponent::instance()->get_gc()->screen_to_world_x (screen_x);
00072   float y = WorldViewComponent::instance()->get_gc()->screen_to_world_y (screen_y);
00073   
00074   WorldViewComponent::instance()->get_gc()->zoom_to((int)Math::min(x, click_pos.x),
00075                                                     (int)Math::min(y, click_pos.y),
00076                                                     (int)Math::max(x, click_pos.x),
00077                                                     (int)Math::max(y, click_pos.y));
00078 }
00079 
00080