MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / isVisible

Method isVisible

CodenameOne/src/com/codename1/ui/Graphics.java:433–488  ·  view source on GitHub ↗
(int x, int y, int w, int h)

Source from the content-addressed store, hash-verified

431 ///
432 /// true if the rectangle intersects the current clip
433 public boolean isVisible(int x, int y, int w, int h) {
434 if (w <= 0 || h <= 0) {
435 return false;
436 }
437 int cx = getClipX();
438 int cy = getClipY();
439 int cw = getClipWidth();
440 int ch = getClipHeight();
441 if (cw <= 0 || ch <= 0) {
442 return false;
443 }
444 // If a non-trivial transform is in effect, map the rectangle's corners
445 // through it and test the resulting bounding box. Only the matrix is
446 // applied -- the integer translate cancels against getClipX/getClipY,
447 // which already subtract it back out.
448 if (isTransformSupported()) {
449 Transform t = getTransform();
450 if (t != null && !t.isIdentity()) {
451 try {
452 float[] pts = new float[]{
453 x, y,
454 x + w, y,
455 x + w, y + h,
456 x, y + h
457 };
458 t.transformPoints(2, pts, 0, pts, 0, 4);
459 float minX = pts[0];
460 float maxX = pts[0];
461 float minY = pts[1];
462 float maxY = pts[1];
463 for (int i = 2; i < pts.length; i += 2) {
464 float px = pts[i];
465 float py = pts[i + 1];
466 if (px < minX) {
467 minX = px;
468 }
469 if (px > maxX) {
470 maxX = px;
471 }
472 if (py < minY) {
473 minY = py;
474 }
475 if (py > maxY) {
476 maxY = py;
477 }
478 }
479 return minX < cx + cw && minY < cy + ch && maxX > cx && maxY > cy;
480 } catch (RuntimeException err) {
481 // Some ports throw when the transform isn't backed natively;
482 // fall back to the untransformed rectangle test below.
483 Log.e(err);
484 }
485 }
486 }
487 return x < cx + cw && y < cy + ch && x + w > cx && y + h > cy;
488 }
489
490 /// Clips the given rectangle by intersecting with the current clipping region, this

Callers

nothing calls this directly

Calls 9

getClipXMethod · 0.95
getClipYMethod · 0.95
getClipWidthMethod · 0.95
getClipHeightMethod · 0.95
isTransformSupportedMethod · 0.95
getTransformMethod · 0.95
isIdentityMethod · 0.95
transformPointsMethod · 0.95
eMethod · 0.95

Tested by

no test coverage detected