Revision: 4792
http://sourceforge.net/p/vexi/code/4792
Author: clrg
Date: 2015-05-09 09:29:30 +0000 (Sat, 09 May 2015)
Log Message:
-----------
Fixes for integrated layout
Modified Paths:
--------------
branches/vexi3_integrated_layout/org.vexi-core.main/src/main/jpp/org/vexi/core/Box.jpp
Modified:
branches/vexi3_integrated_layout/org.vexi-core.main/src/main/jpp/org/vexi/core/Box.jpp
===================================================================
---
branches/vexi3_integrated_layout/org.vexi-core.main/src/main/jpp/org/vexi/core/Box.jpp
2015-05-05 00:37:12 UTC (rev 4791)
+++
branches/vexi3_integrated_layout/org.vexi-core.main/src/main/jpp/org/vexi/core/Box.jpp
2015-05-09 09:29:30 UTC (rev 4792)
@@ -187,8 +187,8 @@
private final Box getRoot() { return parent == null ? this :
parent.getRoot(); }
- private final int getXInParent() { return parent==null ? 0 :
((parent.test(PACK) || parent.test(ALIGN_LEFT)) ? x :
x+((parent.width-width)/(parent.test(ALIGN_RIGHT)?1:2))); }
- private final int getYInParent() { return parent==null ? 0 :
((parent.test(PACK) || parent.test(ALIGN_TOP)) ? y :
y+((parent.height-height)/(parent.test(ALIGN_BOTTOM)?1:2))); }
+ private final int getXInParent() { return parent==null ? 0 :
((parent.test(PACK) || parent.alignLeft()) ? x :
x+((parent.width-width)/(parent.alignRight()?1:2))); }
+ private final int getYInParent() { return parent==null ? 0 :
((parent.test(PACK) || parent.alignTop()) ? y :
y+((parent.height-height)/(parent.alignBottom()?1:2))); }
private final int globalToLocalX(int x) { return parent==null ? x :
parent.globalToLocalX(x - getXInParent()); }
private final int globalToLocalY(int y) { return parent==null ? y :
parent.globalToLocalY(y - getYInParent()); }
private final int localToGlobalX(int x) { return parent==null ? x :
parent.localToGlobalX(x + getXInParent()); }
@@ -203,6 +203,10 @@
private final boolean inside(int x, int y) { return test(DISPLAY) && x >=
0 && y >= 0 && x < width && y < height; }
private final boolean hasText() { return text != EMPTY_STRING; }
+ private final boolean alignTop() { return test(ALIGN_TOP); }
+ private final boolean alignLeft() { return test(ALIGN_LEFT); }
+ private final boolean alignRight() { return test(ALIGN_RIGHT); }
+ private final boolean alignBottom() { return test(ALIGN_BOTTOM); }
// TRAPFLAGS helper functions
private final void trap_setclear(int mask, boolean set) { if (set)
set(mask); else clear(mask); }
@@ -268,7 +272,7 @@
private static final int REFLOW = CONSTRAIN | CONSTRAIN_DESCENDENT | PLACE
| PLACE_DESCENDENT;
private static final int PACK = 0x00001000;
- private static final int CLIP = 0x00002000;
+ private static final int GAIN = 0x00002000;
// private static final int HAS_WIDTH_SLACK = 0x00004000;
// private static final int HAS_HEIGHT_SLACK = 0x00008000;
@@ -383,7 +387,7 @@
private Box parent = null;
private Box redirect = this;
- private int flags = DISPLAY | REFLOW | ORIENT | TILE_IMAGE | PACK |
PLACE_CLEAN;
+ private int flags = DISPLAY | REFLOW | ORIENT | TILE_IMAGE | PACK | GAIN |
PLACE_CLEAN;
private int trapflags = 0;
private BasicTree bt = null;
@@ -730,7 +734,8 @@
}
//#end
- } else if (!test(CLIP)) {
+ } else if (test(GAIN)) {
+ // layered layout
for (Box c = getChild(i=0); c != null; c = getChild(++i)) {
if (!c.test(DISPLAY)) {
continue;
@@ -738,31 +743,15 @@
new_contentwidth = constrainToWidth(new_contentwidth, c);
new_contentheight = constrainToHeight(new_contentheight, c);
}
+ } else {
+ // place layout always has a content size of 0
}
- //#repeat width/height WIDTH/HEIGHT
- if (test(CLIP))
- new_contentwidth = max(new_contentwidth, textwidth) + padding.left
+ padding.right;
-/*
- if (test(CLIP)) {
- if (new_contentwidth < maxwidth && new_contentwidth < minwidth) {
- set(HAS_WIDTH_SLACK);
- } else {
- clear(HAS_WIDTH_SLACK);
- }
- } else {
- if (new_contentwidth < maxwidth && (new_contentwidth < minwidth ||
new_contentwidth < textwidth ||
- (texture!=null && new_contentwidth < texture.getWidth())))
{
- set(HAS_WIDTH_SLACK);
- } else {
- clear(HAS_WIDTH_SLACK);
- }
- new_contentwidth = max(new_contentwidth, textwidth);
+ //#repeat HSHRINK/VSHRINK width/height WIDTH/HEIGHT Width/Height
left/top right/bottom
+ if (test(GAIN)) {
+ new_contentwidth = max(new_contentwidth, textwidth + padding.left
+ padding.right);
}
- new_contentwidth = min(maxwidth, max(minwidth, new_contentwidth));
-*/
-
// assign contentwidth and mark for place in parent and placing of
children
if (new_contentwidth != contentwidth) {
if (parent != null) {
@@ -772,7 +761,7 @@
PUT_BOX_FIELD(SC_contentwidth,JSU.N(new_contentwidth),contentwidth=new_contentwidth,CONTENTWIDTH_TRAP)
} else {
// constrain contentwidth to frame width
- if (getSurface()!=null && !test(SHRINK)) {
+ if (getSurface()!=null && !test(HSHRINK)) {
new_contentwidth = min(getSurface().pendingWidth,
new_contentwidth);
}
if (new_contentwidth != contentwidth) {
@@ -805,22 +794,22 @@
set(PLACE_CLEAN);
}
- //#repeat HSHRINK/VSHRINK Width/Height getTargetX/getTargetY x/y tx/ty
width/height left/top right/bottom
- private final int getTargetWidth(final int availableWidth) {
+ //#repeat HSHRINK/VSHRINK Width/Height determineX/determineY x/y
width/height left/top right/bottom
+ private final int determineWidth() {
return test(HSHRINK) ? nominalWidth()
- : max(contentwidth, min(maxwidth, availableWidth - x
+ : max(contentwidth, min(maxwidth, parent.width - x
- max(margin.left, parent.padding.left) -
max(margin.right, parent.padding.right)));
}
- private final int getTargetX(final int availableWidth, final int
targetWidth, final boolean left, final boolean right) {
- if (left) return margin.left;
- if (right) return availableWidth - targetWidth - margin.right;
+ private final int determineX(final int new_width) {
+ if (parent.alignLeft()) return margin.left;
+ if (parent.alignRight()) return parent.width - new_width -
margin.right;
- int tx = (availableWidth - targetWidth) / 2;
+ int new_x = (parent.width - new_width) / 2;
// honour margins
- if (tx < margin.left) return margin.left;
- if (availableWidth - tx - targetWidth < margin.right)
- return availableWidth - margin.bottom;
- return tx;
+ if (new_x < margin.left) return margin.left;
+ if (parent.width - new_x - new_width < margin.right)
+ return parent.width - margin.right;
+ return new_x;
}
//#end
@@ -835,8 +824,8 @@
if (!child.test(DISPLAY)) {
continue;
}
- child.tryResize(child.getTargetWidth(width),
- child.getTargetHeight(height),
+ child.tryResize(child.determineWidth(),
+ child.determineHeight(),
clean);
}
@@ -844,10 +833,6 @@
// pack children into available space
int child_x = 0, child_y = 0;
int child_width, child_height;
- boolean top = test(ALIGN_TOP);
- boolean left = test(ALIGN_LEFT);
- boolean right = test(ALIGN_RIGHT);
- boolean bottom = test(ALIGN_BOTTOM);
if (test(ORIENT) == HORIZONTAL) {
// horizontal stacking
@@ -860,8 +845,8 @@
continue;
}
// height, y
- child_height = child.getTargetHeight(height);
- child_y = getTargetY(height, child_height, top,
bottom);
+ child_height = child.determineHeight();
+ child_y = child.determineY(child_height);
// width, x
child_width = child.nominalWidth();
child_x += max(prior_margin, child.margin.left);
@@ -961,7 +946,7 @@
// if there is 'slack' (child boxes do not consume
parent width) then
// align determines whether we pack boxes to left,
centre, or right
- int offset_x = left ? 0 :
(int)(((float)width-totalsize)/(float)(right?1:2));
+ int offset_x = alignLeft() ? 0 :
(int)(((float)width-totalsize)/(float)(alignRight()?1:2));
// we use total (a float) to keep tabs on final layout
totals
// so we do not get stray pixel sized gaps caused by
rounding
@@ -973,8 +958,8 @@
continue;
}
// height, y
- child_height = child.getTargetHeight(height);
- child_y = child.getTargetY(height, child_height,
top, bottom);
+ child_height = child.determineHeight();
+ child_y = child.determineY(child_height);
// width, x
totalsize += (float)max(prior_margin,
child.margin.left);
@@ -1007,8 +992,8 @@
continue;
}
// width, x
- child_width = child.getTargetWidth(width);
- child_x = child.getTargetX(width, child_width,
left, right);
+ child_width = child.determineWidth();
+ child_x = child.determineX(child_width);
// height, y
child_height = child.nominalHeight();
child_y += max(prior_margin, child.margin.top);
@@ -1108,7 +1093,7 @@
// if there is 'slack' (child boxes do not consume
parent width) then
// align determines whether we pack boxes to left,
centre, or right
- int offset_y = top ? 0 :
(int)(((float)height-totalsize)/(float)(bottom?1:2));
+ int offset_y = alignTop() ? 0 :
(int)(((float)height-totalsize)/(float)(alignBottom()?1:2));
// we use total (a float) to keep tabs on final layout
totals
// so we do not get stray pixel sized gaps caused by
rounding
@@ -1120,8 +1105,8 @@
continue;
}
// width, x
- child_width = child.getTargetWidth(width);
- child_x = child.getTargetX(width, child_width,
left, right);
+ child_width = child.determineWidth();
+ child_x = child.determineX(child_width);
// height, y
totalsize += (float)max(prior_margin,
child.margin.top);
@@ -1193,8 +1178,10 @@
if (hasText()) {
int gap_x = width - textwidth;
int gap_y = height - textheight;
- int text_x = globalx + (test(ALIGN_RIGHT) ? gap_x :
!test(ALIGN_LEFT) ? gap_x/2 : 0);
- int text_y = globaly + (test(ALIGN_BOTTOM) ? gap_y :
!test(ALIGN_TOP) ? gap_y/2 : 0);
+ int text_x = globalx + (alignLeft() ? padding.left
+ : alignRight() ? gap_x-padding.right :
max(max(padding.left, padding.right), gap_x/2));
+ int text_y = globaly + (alignTop() ? padding.top
+ : alignBottom() ? gap_y-padding.bottom :
max(max(padding.top, padding.bottom), gap_y/2));
font.rasterizeGlyphs(text.toString(), buf, textcolor, text_x,
text_y, cx1, cy1, cx2, cy2);
}
@@ -1555,10 +1542,8 @@
return;
}
long textsize = font.textsize(text.toString());
- int iwidth = (int)((textsize >>> 32) & 0xffffffff);
- int iheight = (int)(textsize & 0xffffffffL);
- textwidth = iwidth > Short.MAX_VALUE ? Short.MAX_VALUE : (short)iwidth;
- textheight = iheight > Short.MAX_VALUE ? Short.MAX_VALUE :
(short)iheight;
+ textwidth = (int)((textsize >>> 32) & 0xffffffff);
+ textheight = (int)(textsize & 0xffffffffL);
}
@@ -2235,7 +2220,7 @@
* */
case "layout":
if (redirect == null) return null;
- if (redirect == this) return test(PACK) ? SC_pack : (test(CLIP) ?
SC_place : SC_layer);
+ if (redirect == this) return test(PACK) ? SC_pack : (test(GAIN) ?
SC_layer : SC_place);
return redirect.getAndTriggerTraps(SC_layout);
/* <p><em>Read only</em> reflecting the number of children a box
has.</p>
@@ -2769,6 +2754,7 @@
setFont(fontstream, fontsize);
}
if (hasText()) {
+ textCalculateDimensions();
setConstrain();
dirty();
}
@@ -2787,6 +2773,7 @@
setFont(font.stream, ps);
}
if (hasText()) {
+ textCalculateDimensions();
setConstrain();
dirty();
}
@@ -2983,21 +2970,21 @@
case "layout":
if (tryRedirect(name, value)) return;
if (SC_place.equals(value)) {
- if (!test(PACK) && test(CLIP)) {
+ if (!test(PACK) && !test(GAIN)) {
return;
}
setConstrain();
setPlace();
clear(PACK);
- set(CLIP);
+ clear(GAIN);
} else if (SC_layer.equals(value)) {
- if (!test(PACK) && !test(CLIP)) {
+ if (!test(PACK) && test(GAIN)) {
return;
}
setConstrain();
setPlace();
clear(PACK);
- clear(CLIP);
+ set(GAIN);
} else if (SC_pack.equals(value)) {
if (test(PACK)) {
return;
@@ -3005,7 +2992,7 @@
setConstrain();
setPlace();
set(PACK);
- clear(CLIP);
+ set(GAIN);
} else {
throw new JSExn("Attempt to set Box property 'layout' to
unsupported value '"+JSU.toString(value)+"'");
}
@@ -3461,7 +3448,7 @@
/** change the parent of the box and fire relevant traps */
protected final void removeFromParent() throws JSExn {
if (test(DISPLAY)) {
- if (parent.test(PACK) || !parent.test(CLIP)) {
+ if (parent.test(PACK) || parent.test(GAIN)) {
parent.setConstrain();
}
parent.setPlace();
@@ -3544,7 +3531,7 @@
// requestReflow must happen after parent assignment otherwise
calls
// to setContrainInTree/setPlaceInTree are rendered ineffective
requestReflow();
- if (newparent.test(PACK) || !newparent.test(CLIP)) {
+ if (newparent.test(PACK) || newparent.test(GAIN)) {
newparent.setConstrain();
}
newparent.setPlace();
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Vexi-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vexi-svn