Skip to content

Commit

Permalink
added mouse wheel support to map
Browse files Browse the repository at this point in the history
  • Loading branch information
camillol committed Oct 20, 2011
1 parent 9874feb commit ff69b0a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
22 changes: 21 additions & 1 deletion MapView.pde
Expand Up @@ -18,7 +18,7 @@ class MapView extends View {

void drawContent()
{
imageMode(CORNER); // modestmaps needs this
imageMode(CORNER); // modestmaps needs this - I sent a patch, but who knows when it'll be committed
mmap.draw();
smooth();
noStroke();
Expand All @@ -29,6 +29,26 @@ class MapView extends View {
image(airplaneImage,p.x,p.y);
}

boolean contentMouseWheel(float lx, float ly, int delta)
{
float sc = 1.0;
if (delta < 0) {
sc = 1.05;
}
else if (delta > 0) {
sc = 1.0/1.05;
}
float mx = lx - w/2;
float my = ly - h/2;
mmap.tx -= mx/mmap.sc;
mmap.ty -= my/mmap.sc;
mmap.sc *= sc;
mmap.tx += mx/mmap.sc;
mmap.ty += my/mmap.sc;

return true;
}

boolean mouseDragged(float px, float py)
{
mmap.mouseDragged();
Expand Down
18 changes: 18 additions & 0 deletions View.pde
Expand Up @@ -49,6 +49,11 @@ class View {
{
return true;
}

boolean contentMouseWheel(float lx, float ly, int delta)
{
return false;
}

boolean ptInRect(float px, float py, float rx, float ry, float rw, float rh)
{
Expand Down Expand Up @@ -93,5 +98,18 @@ class View {
}
return contentClicked(lx, ly);
}

boolean mouseWheel(float px, float py, int delta)
{
if (!ptInRect(px, py, x, y, w, h)) return false;
float lx = px - x;
float ly = py - y;
// check our subviews first
for (int i = subviews.size()-1; i >= 0; i--) {
View v = (View)subviews.get(i);
if (v.mouseWheel(lx, ly, delta)) return true;
}
return contentMouseWheel(lx, ly, delta);
}
}

7 changes: 7 additions & 0 deletions cs424p3.pde
Expand Up @@ -61,6 +61,13 @@ void setup()
rootView.subviews.add(settingsView);

settingsAnimator = new Animator(settingsView.y);

// I want to add true multitouch support, but let's have this as a stopgap for now
addMouseWheelListener(new java.awt.event.MouseWheelListener() {
public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {
rootView.mouseWheel(mouseX, mouseY, evt.getWheelRotation());
}
});
}

void draw()
Expand Down

0 comments on commit ff69b0a

Please sign in to comment.