}
oldx = x;
oldy = y;
+
+ if (wheel)
+ {
+ view.ScaleAroundPoint(Real(x)/Real(scr.ViewportWidth()),Real(y)/Real(scr.ViewportHeight()), expf(-wheel/20.f));
+ }
}
);
while (scr.PumpEvents())
namespace IPDF
{
-//#define REAL_FLOAT
+#define REAL_SINGLE
//#define REAL_DOUBLE
-#define REAL_HALF
+//#define REAL_HALF
#ifdef REAL_SINGLE
typedef float Real;
}
break;
case SDL_MOUSEMOTION:
+ m_last_mouse_x = evt.motion.x;
+ m_last_mouse_y = evt.motion.y;
if (m_mouse_handler)
{
m_mouse_handler(evt.motion.x, evt.motion.y,evt.motion.state, 0);
break;
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
+ m_last_mouse_x = evt.button.x;
+ m_last_mouse_y = evt.button.y;
if (m_mouse_handler)
{
m_mouse_handler(evt.button.x, evt.button.y, evt.button.state, 0);
}
break;
+ case SDL_MOUSEWHEEL:
+ if (m_mouse_handler)
+ {
+ m_mouse_handler(m_last_mouse_x, m_last_mouse_y, 0, evt.wheel.y);
+ }
+ break;
default:
break;
}
void ResizeViewport(int width, int height);
MouseHandler m_mouse_handler;
+ int m_last_mouse_x;
+ int m_last_mouse_y;
int m_viewport_width;
int m_viewport_height;
void View::Translate(Real x, Real y)
{
+ x *= m_bounds.w;
+ y *= m_bounds.h;
m_bounds.x += x;
m_bounds.y += y;
}
+void View::ScaleAroundPoint(Real x, Real y, Real scaleAmt)
+{
+ // Convert to local coords.
+ x *= m_bounds.w;
+ y *= m_bounds.h;
+ x += m_bounds.x;
+ y += m_bounds.y;
+
+ Debug("Mouse wheel event %f %f %f\n", Float(x), Float(y), Float(scaleAmt));
+
+ Real top = y - m_bounds.y;
+ Real left = x - m_bounds.x;
+
+ top *= scaleAmt;
+ left *= scaleAmt;
+
+ m_bounds.x = x - left;
+ m_bounds.y = y - top;
+ m_bounds.w *= scaleAmt;
+ m_bounds.h *= scaleAmt;
+}
+
void View::Render()
{
static bool debug_output_done = false;
void Render();
void Translate(Real x, Real y);
+ void ScaleAroundPoint(Real x, Real y, Real scaleAmt);
private:
Document & m_document;