00001
00002
00023 #include "panoinc_WX.h"
00024 #include "panoinc.h"
00025 #include "PreviewCropTool.h"
00026 #include <config.h>
00027 #include "base_wx/platform.h"
00028 #include "hugin/config_defaults.h"
00029 #include "CommandHistory.h"
00030 #include "wxPanoCommand.h"
00031
00032 #include <wx/platform.h>
00033 #ifdef __WXMAC__
00034 #include <OpenGL/gl.h>
00035 #else
00036 #include <GL/gl.h>
00037 #endif
00038
00039 PreviewCropTool::PreviewCropTool(PreviewToolHelper *helper)
00040 : PreviewTool(helper)
00041 {
00042
00043 }
00044
00045 void PreviewCropTool::Activate()
00046 {
00047 helper->NotifyMe(PreviewToolHelper::MOUSE_MOVE, this);
00048 helper->NotifyMe(PreviewToolHelper::MOUSE_PRESS, this);
00049 helper->NotifyMe(PreviewToolHelper::REALLY_DRAW_OVER_IMAGES, this);
00050 mouse_down = false;
00051 moving_left = false;
00052 moving_right = false;
00053 moving_top = false;
00054 moving_bottom = false;
00055 helper->SetStatusMessage(_("Drag the inside of the cropping rectangle to adjust the crop."));
00056 }
00057
00058 void PreviewCropTool::ReallyAfterDrawImagesEvent()
00059 {
00060
00061
00062
00063
00064
00065
00066
00067
00068 HuginBase::PanoramaOptions *opts = helper->GetVisualizationStatePtr()->getViewState()->GetOptions();
00069 vigra::Rect2D roi = opts->getROI();
00070 double width = (double) roi.width(),
00071 height = (double) roi.height(),
00072 margin = (width > height ? height : width) / 4.0;
00073 top = (double) roi.top() + margin;
00074 bottom = (double) roi.bottom() - margin;
00075 left = (double) roi.left() + margin;
00076 right = (double) roi.right() - margin;
00077
00078
00079 if (!mouse_down)
00080 {
00081 glEnable(GL_BLEND);
00082 helper->GetVisualizationStatePtr()->getViewState()->GetTextureManager()->DisableTexture();
00083 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00084 glColor4f(1.0, 1.0, 1.0, 0.38197);
00085 glBegin(GL_QUADS);
00086 if (moving_left)
00087 {
00088 glVertex2d(roi.left(), top); glVertex2d(left, top);
00089 glVertex2d(left, bottom); glVertex2d(roi.left(), bottom);
00090 }
00091 if (moving_right)
00092 {
00093 glVertex2d(right, top); glVertex2d(roi.right(), top);
00094 glVertex2d(roi.right(), bottom); glVertex2d(right, bottom);
00095 }
00096 if (moving_top)
00097 {
00098 glVertex2d(right, top); glVertex2d(right, roi.top());
00099 glVertex2d(left, roi.top()); glVertex2d(left, top);
00100 }
00101 if (moving_bottom)
00102 {
00103 glVertex2d(right, bottom); glVertex2d(right, roi.bottom());
00104 glVertex2d(left, roi.bottom()); glVertex2d(left, bottom);
00105 }
00106 glEnd();
00107 glEnable(GL_TEXTURE_2D);
00108 glDisable(GL_BLEND);
00109 } else {
00110
00111
00112 opts->setROI(new_roi);
00113 helper->GetViewStatePtr()->SetOptions(opts);
00114 }
00115 }
00116
00117 void PreviewCropTool::MouseMoveEvent(double x, double y, wxMouseEvent & e)
00118 {
00119
00120
00121
00122
00123
00124
00125
00126
00127
00129
00130
00131
00132
00133
00134 if (mouse_down)
00135 {
00136 vigra::Rect2D roi = start_drag_options.getROI();
00137 if (moving_left)
00138 {
00139 if (roi.left()<roi.right())
00140 {
00141
00142 unsigned int left_d = (int) (start_drag_x - x);
00143 roi.setUpperLeft(vigra::Point2D(roi.left() - left_d, roi.top()));
00144 }
00145 }
00146 if (moving_top)
00147 {
00148 if (roi.top()<roi.bottom())
00149 {
00150
00151 unsigned int top_d = (int) (start_drag_y - y);
00152 roi.setUpperLeft(vigra::Point2D(roi.left(), roi.top() - top_d));
00153 }
00154 }
00155 if (moving_right)
00156 {
00157 if (roi.left()<roi.right())
00158 {
00159
00160 unsigned int right_d = (int) (start_drag_x - x);
00161 roi.setLowerRight(vigra::Point2D(roi.right() - right_d,
00162 roi.bottom()));
00163 }
00164 }
00165 if (moving_bottom)
00166 {
00167
00168 if (roi.top()<roi.bottom())
00169 {
00170 unsigned int bottom_d = (int) (start_drag_y - y);
00171 roi.setLowerRight(vigra::Point2D(roi.right(),
00172 roi.bottom() - bottom_d));
00173 }
00174 }
00175
00176 if((roi.top()<roi.bottom())&&(roi.left()<roi.right()))
00177 {
00178 opts.setROI(roi);
00179 new_roi = roi;
00180 helper->GetVisualizationStatePtr()->getViewState()->SetOptions(&opts);
00181 helper->GetVisualizationStatePtr()->Redraw();
00182 }
00183 } else {
00184 start_drag_x = x;
00185 start_drag_y = y;
00186
00187
00188
00189
00190
00191 int changes = 0;
00192 if ((x < left) != moving_left)
00193 {
00194 moving_left = !moving_left;
00195 changes++;
00196 }
00197 if ((x > right) != moving_right)
00198 {
00199 moving_right = !moving_right;
00200 changes++;
00201 }
00202 if ((y < top) != moving_top)
00203 {
00204 moving_top = !moving_top;
00205 changes++;
00206 }
00207 if ((y > bottom) != moving_bottom)
00208 {
00209 moving_bottom = !moving_bottom;
00210 changes++;
00211 }
00212 if (!(moving_left || moving_right || moving_top || moving_bottom))
00213 {
00214
00215 moving_left = true; moving_right = true;
00216 moving_top = true; moving_bottom = true;
00217 changes++;
00218 }
00219
00220 if (changes == 5) changes = 0;
00221
00222 if (changes)
00223 {
00224
00225
00226 helper->GetVisualizationStatePtr()->ForceRequireRedraw();
00227 helper->GetVisualizationStatePtr()->Redraw();
00228 }
00229 }
00230 }
00231
00232
00233 void PreviewCropTool::MouseButtonEvent(wxMouseEvent &e)
00234 {
00235 if (e.GetButton() == wxMOUSE_BTN_LEFT)
00236 {
00237 if (e.ButtonDown())
00238 {
00239 start_drag_options = *helper->GetVisualizationStatePtr()->getViewState()->GetOptions();
00240 opts = start_drag_options;
00241 new_roi = opts.getROI();
00242 mouse_down = true;
00243 moving_left = false;
00244 moving_right = false;
00245 moving_top = false;
00246 moving_bottom = false;
00247 if (start_drag_x < left) moving_left = true;
00248 if (start_drag_x > right) moving_right = true;
00249 if (start_drag_y < top) moving_top = true;
00250 if (start_drag_y > bottom) moving_bottom = true;
00251
00252 if (!(moving_left || moving_right || moving_top || moving_bottom))
00253 {
00254 moving_left = true;
00255 moving_right = true;
00256 moving_top = true;
00257 moving_bottom = true;
00258 }
00259 } else {
00260 if (mouse_down)
00261 {
00262 mouse_down = false;
00263 moving_left = false;
00264 moving_right = false;
00265 moving_top = false;
00266 moving_bottom = false;
00267
00268 GlobalCmdHist::getInstance().addCommand(
00269 new PT::SetPanoOptionsCmd(*(helper->GetPanoramaPtr()),
00270 opts));
00271 }
00272 }
00273 }
00274 }
00275