public bool invisibleDragArea(float x, float y, float w, float h, ref bool isDrag, out int dragX, out int dragY) { PMatrix matrix = getMatrix(); matrix.invert(); Vector3 mv = matrix.mult(new Vector3(uiMouseX, uiMouseY)); //bool isActive = (mouseX > x && mouseX < x + w && mouseY > y && mouseY < y + h); bool isActive = (mv.x > x && mv.x <x + w && mv.y> y && mv.y < y + h); if ((isActive || isDrag) && (uiMousePressed || uiMouseReleased)) { dragX = uiMouseDragX; dragY = uiMouseDragY; int margin = 2; if (!isDrag && abs(dragX) <= margin && abs(dragY) <= margin) { isDrag = false; } else { isDrag = true; } } else { dragX = dragY = 0; isDrag = false; } return(isDrag); }
public bool invisibleButton(float x, float y, float w, float h) { PMatrix matrix = getMatrix(); matrix.invert(); Vector3 mv = matrix.mult(new Vector3(uiMouseX, uiMouseY)); //bool isActive = (mouseX > x && mouseX < x + w && mouseY > y && mouseY < y + h); bool isActive = (mv.x > x && mv.x <x + w && mv.y> y && mv.y < y + h); bool isClick = uiClickUp ? uiMouseReleased : uiMousePressed; if (isActive && isClick) { buttonClick(uiStyle.groupName, name, null); } return(isActive && isClick); }
public bool button(string name, float x, float y, float w, float h, int textSize = 0) { pushStyle(); string objName = "button: " + name; var obj = pushMatrix(objName); PMatrix matrix = getMatrix(); matrix.invert(); Vector3 mv = matrix.mult(new Vector3(uiMouseX, uiMouseY)); //bool isActive = (mouseX > x && mouseX < x + w && mouseY > y && mouseY < y + h); bool isActive = (mv.x > x && mv.x <x + w && mv.y> y && mv.y < y + h); PUIStyle.Property prop = isActive ? uiStyle.active : uiStyle.normal; if (prop.frameWeight > 0) { stroke(prop.frameColor); strokeWeight(prop.frameWeight); } else { noStroke(); } fill(prop.bgColor); float fh = prop.frameWeight * 0.2f; rect(x + fh, y + fh, w - fh * 2, h - fh * 2); fill(prop.textColor); uiText(name, x, y, w, h, textSize); popMatrix(objName); popStyle(); bool isClick = uiClickUp ? uiMouseReleased : uiMousePressed; if (isActive && isClick) { buttonClick(uiStyle.groupName, name, obj); } return(isActive && isClick); }