Fix for zoom in/out error (#1221)
* minor fix open/save dialogue on windows On windows 10 the open/save dialogue box has an minor error, and I believe I fixed it. When "Open" is selected from the menu, the title of the dialogue box says "SolveSpace - Save File" and the entered file name is "united". My fix correctly titles the dialoged box, and leaves the address bar blank when a file is being opened because "united" is only needed as a default name when a file being saved. I found that class FileDialogImplWin32 from guiwin.cpp contains two if statements for "isSaveDialog". This is redundant. I removed the first where the title was originally set, but not working. I then set the title in the second if statement and moved the 'if isEmpty'' to this section. * Update guiwin.cpp replaced tabs with spaces * Created ZoomToMouse function in graphicswin.cpp which referances the mouse position directly. Simplified MouseScroll in mouse.cpp to point to this function instead of altering zoom directly. Also pointed zoom commpand from keyboard and menu to ZoomToMouse so that it works avoids different behavior. * clean up some commentspull/1226/head
parent
b429141c28
commit
fc16cdb370
|
@ -712,16 +712,47 @@ double GraphicsWindow::ZoomToFit(const Camera &camera,
|
||||||
return scale;
|
return scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GraphicsWindow::ZoomToMouse(double zoomMultiplyer) {
|
||||||
|
double offsetRight = offset.Dot(projRight);
|
||||||
|
double offsetUp = offset.Dot(projUp);
|
||||||
|
|
||||||
|
double width, height;
|
||||||
|
window->GetContentSize(&width, &height);
|
||||||
|
|
||||||
|
double righti = currentMousePosition.x / scale - offsetRight;
|
||||||
|
double upi = currentMousePosition.y / scale - offsetUp;
|
||||||
|
|
||||||
|
// zoomMultiplyer of 1 gives a default zoom factor of 1.2x: zoomMultiplyer * 1.2
|
||||||
|
// zoom = adjusted zoom negative zoomMultiplyer will zoom out, positive will zoom in
|
||||||
|
//
|
||||||
|
|
||||||
|
scale *= exp(0.1823216 * zoomMultiplyer); // ln(1.2) = 0.1823216
|
||||||
|
|
||||||
|
double rightf = currentMousePosition.x / scale - offsetRight;
|
||||||
|
double upf = currentMousePosition.y / scale - offsetUp;
|
||||||
|
|
||||||
|
offset = offset.Plus(projRight.ScaledBy(rightf - righti));
|
||||||
|
offset = offset.Plus(projUp.ScaledBy(upf - upi));
|
||||||
|
|
||||||
|
if(SS.TW.shown.screen == TextWindow::Screen::EDIT_VIEW) {
|
||||||
|
if(havePainted) {
|
||||||
|
SS.ScheduleShowTW();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
havePainted = false;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void GraphicsWindow::MenuView(Command id) {
|
void GraphicsWindow::MenuView(Command id) {
|
||||||
switch(id) {
|
switch(id) {
|
||||||
case Command::ZOOM_IN:
|
case Command::ZOOM_IN:
|
||||||
SS.GW.scale *= 1.2;
|
SS.GW.ZoomToMouse(1);
|
||||||
SS.ScheduleShowTW();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Command::ZOOM_OUT:
|
case Command::ZOOM_OUT:
|
||||||
SS.GW.scale /= 1.2;
|
SS.GW.ZoomToMouse(-1);
|
||||||
SS.ScheduleShowTW();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Command::ZOOM_TO_FIT:
|
case Command::ZOOM_TO_FIT:
|
||||||
|
|
|
@ -914,7 +914,7 @@ bool GraphicsWindow::MouseEvent(Platform::MouseEvent event) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MouseEvent::Type::SCROLL_VERT:
|
case MouseEvent::Type::SCROLL_VERT:
|
||||||
this->MouseScroll(event.x, event.y, event.shiftDown ? event.scrollDelta / 10 : event.scrollDelta);
|
this->MouseScroll(event.shiftDown ? event.scrollDelta / 10 : event.scrollDelta);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MouseEvent::Type::LEAVE:
|
case MouseEvent::Type::LEAVE:
|
||||||
|
@ -1478,17 +1478,10 @@ void GraphicsWindow::EditControlDone(const std::string &s) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsWindow::MouseScroll(double x, double y, double delta) {
|
void GraphicsWindow::MouseScroll(double zoomMultiplyer) {
|
||||||
double offsetRight = offset.Dot(projRight);
|
|
||||||
double offsetUp = offset.Dot(projUp);
|
|
||||||
|
|
||||||
double righti = x/scale - offsetRight;
|
|
||||||
double upi = y/scale - offsetUp;
|
|
||||||
|
|
||||||
// The default zoom factor is 1.2x for one scroll wheel click (delta==1).
|
|
||||||
// To support smooth scrolling where scroll wheel events come in increments
|
// To support smooth scrolling where scroll wheel events come in increments
|
||||||
// smaller (or larger) than 1 we do:
|
// smaller (or larger) than 1 we do:
|
||||||
// scale *= exp(ln(1.2) * delta);
|
// scale *= exp(ln(1.2) * zoomMultiplyer);
|
||||||
// to ensure that the same total scroll delta always results in the same
|
// to ensure that the same total scroll delta always results in the same
|
||||||
// total zoom irrespective of in how many increments the zoom was applied.
|
// total zoom irrespective of in how many increments the zoom was applied.
|
||||||
// For example if we scroll a total delta of a+b in two events vs. one then
|
// For example if we scroll a total delta of a+b in two events vs. one then
|
||||||
|
@ -1496,21 +1489,7 @@ void GraphicsWindow::MouseScroll(double x, double y, double delta) {
|
||||||
// while
|
// while
|
||||||
// scale * a * b != scale * (a+b)
|
// scale * a * b != scale * (a+b)
|
||||||
// So this constant is ln(1.2) = 0.1823216 to make the default zoom 1.2x
|
// So this constant is ln(1.2) = 0.1823216 to make the default zoom 1.2x
|
||||||
scale *= exp(0.1823216 * delta);
|
ZoomToMouse(zoomMultiplyer);
|
||||||
|
|
||||||
double rightf = x/scale - offsetRight;
|
|
||||||
double upf = y/scale - offsetUp;
|
|
||||||
|
|
||||||
offset = offset.Plus(projRight.ScaledBy(rightf - righti));
|
|
||||||
offset = offset.Plus(projUp.ScaledBy(upf - upi));
|
|
||||||
|
|
||||||
if(SS.TW.shown.screen == TextWindow::Screen::EDIT_VIEW) {
|
|
||||||
if(havePainted) {
|
|
||||||
SS.ScheduleShowTW();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
havePainted = false;
|
|
||||||
Invalidate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsWindow::MouseLeave() {
|
void GraphicsWindow::MouseLeave() {
|
||||||
|
|
3
src/ui.h
3
src/ui.h
|
@ -622,6 +622,7 @@ public:
|
||||||
void HandlePointForZoomToFit(Vector p, Point2d *pmax, Point2d *pmin,
|
void HandlePointForZoomToFit(Vector p, Point2d *pmax, Point2d *pmin,
|
||||||
double *wmin, bool usePerspective,
|
double *wmin, bool usePerspective,
|
||||||
const Camera &camera);
|
const Camera &camera);
|
||||||
|
void ZoomToMouse(double delta);
|
||||||
void LoopOverPoints(const std::vector<Entity *> &entities,
|
void LoopOverPoints(const std::vector<Entity *> &entities,
|
||||||
const std::vector<Constraint *> &constraints,
|
const std::vector<Constraint *> &constraints,
|
||||||
const std::vector<hEntity> &faces,
|
const std::vector<hEntity> &faces,
|
||||||
|
@ -842,7 +843,7 @@ public:
|
||||||
void MouseLeftDoubleClick(double x, double y);
|
void MouseLeftDoubleClick(double x, double y);
|
||||||
void MouseMiddleOrRightDown(double x, double y);
|
void MouseMiddleOrRightDown(double x, double y);
|
||||||
void MouseRightUp(double x, double y);
|
void MouseRightUp(double x, double y);
|
||||||
void MouseScroll(double x, double y, double delta);
|
void MouseScroll(double delta);
|
||||||
void MouseLeave();
|
void MouseLeave();
|
||||||
bool KeyboardEvent(Platform::KeyboardEvent event);
|
bool KeyboardEvent(Platform::KeyboardEvent event);
|
||||||
void EditControlDone(const std::string &s);
|
void EditControlDone(const std::string &s);
|
||||||
|
|
Loading…
Reference in New Issue