void PageComponent::base_pointerDown( float inX, float inY ){ inX -= mX; inY -= mY; for( int i=0; i<mComponents.size(); i++ ) { PageComponent *c = *( mComponents.getElement( i ) ); if( c->isVisible() && c->isActive() ) { c->base_pointerDown( inX, inY ); } } pointerDown( inX, inY ); }
int UIList::Do(int id, int x, int y, int w, int h, UIListAdapter *adapter) { int clicked = 0; // Pointer and focus handling // UIList only cares about the first pointer for simplicity. // Probably not much need to scroll one of these while dragging something // else. // TODO: Abstract this stuff out into EmulatePointerEvents for (int i = 0; i < 1; i++) { // Check for hover bool isInside = false; if (UIRegionHit(i, x, y, w, h, 0)) { isInside = true; uistate.hotitem[i] = id; if (uistate.activeitem[i] == 0 && uistate.mousedown[i]) { // Mousedown uistate.activeitem[i] = id; pointerDown(i, uistate.mousex[i], uistate.mousey[i]); } } if (uistate.activeitem[i] == id) { // NOTE: won't work with multiple pointers if (uistate.mousex[i] != lastX || uistate.mousey[i] != lastY) { pointerMove(i, uistate.mousex[i], uistate.mousey[i], isInside); } } // If button is hot and active, but mouse button is not // down, the user must have clicked a list item (unless after the last item). if (uistate.mousedown[i] == 0 && uistate.activeitem[i] == id && selected != -1) { if (uistate.hotitem[i] == id) { clicked = 1; } pointerUp(i, uistate.mousex[i], uistate.mousey[i], isInside); } } int itemHeight = adapter->itemHeight(0); int numItems = adapter->getCount(); // Cap total inertia if (inertiaY > 20) inertiaY = 20; if (inertiaY < -20) inertiaY = -20; float mouseY = uistate.mousey[0]; if (!uistate.mousedown[0]) { // Let it slide if the pointer is not down scrollY += inertiaY; } else if (scrolling /* && mouseY > y && mouseY < y + h*/ ) { // Pointer is down so stick to it scrollY = startScrollY - (uistate.mousey[0] - startDragY); } // Inertia gradually trails off inertiaY *= 0.92f; if (scrolling && fabsf(inertiaY) < 0.001f) scrolling = false; // Cap top and bottom softly. float maxScrollY = numItems * itemHeight - h; if (maxScrollY < 0.0f) maxScrollY = 0.0f; if (scrollY > maxScrollY) { scrollY -= 0.4f * (scrollY - maxScrollY); } else if (scrollY < 0.0f) { scrollY += 0.4f * -scrollY; } lastX = uistate.mousex[0]; lastY = uistate.mousey[0]; uistate.lastwidget = id; // Drawing and item hittesting // render items for (int i = 0; i < numItems; i++) { int item_y = y + i * itemHeight - scrollY; if (item_y >= y - itemHeight && item_y <= y + h) { for (int k = 0; k < 1; k++) { // MAX_POINTERS if we add back multitouch if (uistate.mousedown[k] && uistate.mouseframesdown[k] >= holdFramesClick && adapter->itemEnabled(i) && !scrolling && selected == -1 && UIRegionHit(k, x, item_y, w, itemHeight, 0)) { selected = i; } else if (scrolling) { selected = -1; } } adapter->drawItem(i, x, item_y, w, itemHeight, i == selected); } } // Prevent scroll-clicks from registering if (selected == -1) clicked = 0; // Otherwise, no clicky. return clicked; }