Skip to content

Commit

Permalink
View: Fixed to apply clip to paintBack/paintFront in addition to chil…
Browse files Browse the repository at this point in the history
…dren
  • Loading branch information
reportmill committed Nov 15, 2024
1 parent 062f7dd commit c3324f3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 81 deletions.
30 changes: 3 additions & 27 deletions src/snap/view/ParentView.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,7 @@ public <E extends View> E[] getChildrenForClass(Class<E> aClass)
/**
* Returns the child at given point.
*/
public View getChildAt(Point aPnt) { return _children.getViewAt(aPnt.x, aPnt.y); }

/**
* Returns the child at given point.
*/
public View getChildAt(double aX, double aY) { return _children.getViewAt(aX, aY); }
public View getChildAtXY(double aX, double aY) { return _children.getViewAtXY(aX, aY); }

/**
* Returns the number of managed children.
Expand Down Expand Up @@ -378,7 +373,7 @@ public boolean intersectsShape(Shape aShape)
return hit;

// If any child is hit, return true
View hview = getViewList().getViewAt(aShape, null, null);
View hview = getViewList().getViewIntersectingShape(aShape, null, null);
if (hview != null)
return true;
return false;
Expand All @@ -390,25 +385,15 @@ public boolean intersectsShape(Shape aShape)
protected void paintAll(Painter aPntr)
{
super.paintAll(aPntr);
if (_effect == null) {
paintChildren(aPntr);
paintAbove(aPntr);
}
_needsRepaintDeep = false;
}

/**
* Paint children.
*/
@Override
protected void paintChildren(Painter aPntr)
{
// If view clip set, save painter state and set
Shape viewClip = getClip();
if (viewClip != null) {
aPntr.save();
aPntr.clip(viewClip);
}

// Get painter clip
Shape pntrClip = aPntr.getClip();

Expand All @@ -434,17 +419,8 @@ protected void paintChildren(Painter aPntr)
child.paintAll(aPntr);
aPntr.restore();
}

// If ClipToBounds, Restore original clip
if (viewClip != null)
aPntr.restore();
}

/**
* Paints above children.
*/
protected void paintAbove(Painter aPntr) { }

/**
* Returns whether any children need repaint.
*/
Expand Down
27 changes: 27 additions & 0 deletions src/snap/view/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -2060,6 +2060,13 @@ public Insets getInsetsAll()
*/
protected void paintAll(Painter aPntr)
{
// If view clip set, save painter state and set
Shape viewClip = getClip();
if (viewClip != null) {
aPntr.save();
aPntr.clip(viewClip);
}

// Set opacity
double opacity = getOpacityAll(), opacityOld = 0;
if (opacity != 1) {
Expand Down Expand Up @@ -2087,6 +2094,16 @@ else if (_effect != null)
if (opacity != 1)
aPntr.setOpacity(opacityOld);

// Paint children and above children
if (_effect == null) {
paintChildren(aPntr);
paintAbove(aPntr);
}

// If ClipToBounds, Restore original clip
if (viewClip != null)
aPntr.restore();

// Clear RepaintRect
_repaintRect = null;
}
Expand Down Expand Up @@ -2124,6 +2141,16 @@ protected void paintFront(Painter aPntr)
paintRealClassName(aPntr);
}

/**
* Paint children.
*/
protected void paintChildren(Painter aPntr) { }

/**
* Paints above children.
*/
protected void paintAbove(Painter aPntr) { }

/**
* Returns the tool tip text.
*/
Expand Down
74 changes: 20 additions & 54 deletions src/snap/view/ViewList.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,22 @@
public class ViewList {

// The views array
private View[] _views = EMPTY_VIEWS;
private View[] _views = EMPTY_VIEWS_ARRAY;

// The array of managed views (usually just the same as above)
protected View[] _managed = EMPTY_VIEWS;
protected View[] _managed = EMPTY_VIEWS_ARRAY;

// Shared empty view array
private static View[] EMPTY_VIEWS = new View[0];

private static View[] EMPTY_VIEWS_ARRAY = new View[0];

/**
* Constructor.
*/
public ViewList()
{
super();
}

/**
* Returns the number of views in this list.
*/
Expand Down Expand Up @@ -70,72 +78,30 @@ protected View remove(int anIndex)
protected int remove(View aView)
{
int index = indexOf(aView);
if (index>=0)
if (index >= 0)
remove(index);
return index;
}

/**
* Removes all children from this node (in reverse order).
*/
protected void removeAll()
{
for (int i=size()-1; i>=0; i--) remove(i);
}

/**
* Sets views to given list.
*/
protected void setAll(View ... theViews)
{
removeAll();
for (View c : theViews) add(c);
}

/**
* Returns the child with given name.
*/
public View getView(String aName)
{
for (View view : _views) {
if (aName.equals(view.getName()))
return view;
//if (view instanceof ParentView && view.getOwner()==getOwner()) {
// View n = ((ParentView)view).getChild(aName); if (n!=null) return n; }
}
return null;
}

/**
* Returns the index of the given child in this node's children list.
*/
public int indexOf(View aView)
{
for (int i=0,iMax=size();i<iMax;i++)
if (aView==get(i))
return i;
return -1;
}
public int indexOf(View aView) { return ArrayUtils.indexOfId(_views, aView); }

/**
* Returns the last view of this list.
*/
public View getFirst() { return size()>0 ? get(0) : null; }
public View getFirst() { return size() > 0 ? get(0) : null; }

/**
* Returns the last view of this list.
*/
public View getLast() { return size()>0 ? get(size()-1) : null; }

/**
* Returns the view at given point.
*/
public View getViewAt(Point aPnt) { return getViewAt(aPnt.x, aPnt.y); }
public View getLast() { return size() > 0 ? get(size()-1) : null; }

/**
* Returns the view at given point.
* Returns the view at given point X/Y.
*/
public View getViewAt(double aX, double aY)
public View getViewAtXY(double aX, double aY)
{
// Get children
View[] children = getAll();
Expand All @@ -157,7 +123,7 @@ public View getViewAt(double aX, double aY)
/**
* Returns the first view of given class (optional) hit by given shape, excluding given view (optional).
*/
public <T extends View> T getViewAt(Shape aShape, Class <T> aClass, View aView)
public <T extends View> T getViewIntersectingShape(Shape aShape, Class <T> aClass, View aView)
{
// Get Children
View[] children = getAll();
Expand Down Expand Up @@ -215,7 +181,7 @@ public <T extends View> T getHitView(View aView, Class <T> aClass, double anInse
if (anInset != 0)
bounds.inset(anInset);
Shape boundsInParent = aView.localToParent(bounds);
return getViewAt(boundsInParent, aClass, aView);
return getViewIntersectingShape(boundsInParent, aClass, aView);
}

/**
Expand Down

0 comments on commit c3324f3

Please sign in to comment.