// Uses: window
if ((changeMask & (CHANGED_GEOMETRY | CHANGED_SIZE_APP)) != 0) {
logger.fine("Update texture for view " + this);
if (geometryNode != null) {
DrawingSurface surface = getWindow().getSurface();
if (surface != null) {
sgChangeGeometryTextureSet(geometryNode, getWindow().getTexture(), surface);
windowNeedsValidate = true;
}
}
}
// Now reattach geometry if view should be visible
// Note: MTGame can currently only setOrtho on a visible rc
// Uses: visible, ortho
if (isActuallyVisible()) {
if (ortho) {
logger.fine("View is ortho for view " + this);
entity.getComponent(RenderComponent.class).setOrtho(true);
entity.getComponent(CollisionComponent.class).setCollidable(false);
if (type == Type.PRIMARY || type == Type.UNKNOWN) {
// Attach top level ortho views directly to world
ClientContextJME.getWorldManager().addEntity(entity);
attachState = AttachState.ATTACHED_TO_WORLD;
logger.fine("Attached entity " + entity + " to world manager.");
} else {
parentEntity = getParentEntity();
if (parentEntity == null) {
// Has no Parent; attach directly to world
ClientContextJME.getWorldManager().addEntity(entity);
attachState = AttachState.ATTACHED_TO_WORLD;
logger.fine("Attached parentless entity " + entity + " to world manager.");
} else {
RenderComponent rc = (RenderComponent) entity.getComponent(RenderComponent.class);
// TODO: these two statements appear to be obsolete.
RenderComponent rcParent =
(RenderComponent) parentEntity.getComponent(RenderComponent.class);
Node attachNode = rcParent.getSceneRoot();
// Note: we need to attach non-primaries to the parent geometry node in
// ortho mode, rather than the view node. This way it picks up the parent's
// offset translation, which contains locationOrtho
// TODO: do this cleaner. Convert attach node to a view and get the
// geometry node for this view.
attachNode = (Node) attachNode.getChild(0);
sgChangeAttachPointSetAddEntity(rc, attachNode, parentEntity, entity);
attachState = AttachState.ATTACHED_TO_ENTITY;
logger.fine("Attach ortho entity " + entity + " to geometry node of parent entity " + parentEntity);
}
}
} else {
logger.fine("View is not ortho for view " + this);
parentEntity = getParentEntity();
if (parentEntity == null) {
logger.warning("getParentEntity() returns null; must be non-null");
} else {
logger.fine("Attach entity " + entity + " to parent entity " + parentEntity);
RenderComponent rc = (RenderComponent) entity.getComponent(RenderComponent.class);
RenderComponent rcParent =
(RenderComponent) parentEntity.getComponent(RenderComponent.class);
Node attachNode = rcParent.getSceneRoot();
// SPECIAL NOTE: Here is where special surgery is done on header windows so
// that they are parented to the *geometry node* of their parent view instead of
// the view node, as windows normally are. This way it picks up the offset
// translation in the geometry node and stays in sync with the rest of the frame.
// See also: SPECIAL NOTE in Frame2DCell.attachViewToEntity.
if (window instanceof WindowSwingHeader) {
WindowSwingHeader wsh = (WindowSwingHeader) window;
if (wsh.getView().getType() == View2D.Type.SECONDARY) {
// TODO: do this cleaner. Convert attach node to a view and get the
// geometry node for this view.
attachNode = (Node) attachNode.getChild(0);
}
}
sgChangeAttachPointSetAddEntity(rc, attachNode, parentEntity, entity);
attachState = AttachState.ATTACHED_TO_ENTITY;
entity.getComponent(RenderComponent.class).setOrtho(false);
entity.getComponent(CollisionComponent.class).setCollidable(true);
}
}
}
if ((changeMask & CHANGED_VISIBLE) != 0) {
// Update visibility of children
logger.fine("Update children visibility for view " + this);
for (View2DEntity child : children) {
child.updateVisibility(inCleanup);
}
}
} // End Topology Changes
// Determine what frame changes need to be performed. But these aren't executed now;
// they are executed later by view.updateFrame, which must be invoked outside the window lock.
// issue 151: prepare for reattachment of frame on resize.
if ((changeMask & (CHANGED_DECORATED | CHANGED_TITLE | CHANGED_TYPE | CHANGED_SIZE_APP |
CHANGED_PIXEL_SCALE | CHANGED_USER_RESIZABLE | CHANGED_VISIBLE)) != 0) {
logger.fine("Update frame for view " + this);
logger.fine("decorated " + decorated);
if ((changeMask & (CHANGED_DECORATED | CHANGED_VISIBLE)) != 0) {
// Some popups initiall are decorated and then are set to undecorated before
// the popup becomes visible. So to avoid wasting time, wait until the window
// becomes visible before attaching its frame.
if (decorated && isActuallyVisible()) {
if (!hasFrame()) {
logger.fine("Attach frame");
frameChanges.add(FrameChange.ATTACH_FRAME);
}
} else {
if (hasFrame()) {
logger.fine("Detach frame");
frameChanges.add(FrameChange.DETACH_FRAME);
}
}
}
if ((changeMask & CHANGED_TITLE) != 0) {
if (decorated && hasFrame()) {
frameChanges.add(FrameChange.UPDATE_TITLE);
}
}
if ((changeMask & (CHANGED_TYPE | CHANGED_SIZE_APP)) != 0) {
if (decorated) {
frameChanges.add(FrameChange.REATTACH_FRAME);
}
}
if ((changeMask & (CHANGED_USER_RESIZABLE | CHANGED_VISIBLE)) != 0) {
if (decorated) {
frameChanges.add(FrameChange.UPDATE_USER_RESIZABLE);
}
}
}
if ((changeMask & (CHANGED_STACK | CHANGED_ORTHO)) != 0) {
logger.fine("Update geometry ortho Z order for view " + this);
if (ortho) {
if (window != null) {
int zOrder = window.getZOrder();
logger.fine("Z order = " + zOrder);
if (zOrder >= 0) {
sgChangeGeometryOrthoZOrderSet(geometryNode, zOrder);
}
}
}
}
if ((changeMask & CHANGED_ORTHO) != 0) {
// MTGame: can currently only setOrtho on a visible rc
if (isActuallyVisible()) {
entity.getComponent(RenderComponent.class).setOrtho(ortho);
entity.getComponent(CollisionComponent.class).setCollidable(!ortho);
}
sgChangeViewNodeOrthoSet(viewNode, ortho);
}
// React to size related changes (must be done before handling transform changes)
if ((changeMask & (CHANGED_DECORATED | CHANGED_SIZE_APP | CHANGED_PIXEL_SCALE |
CHANGED_ORTHO)) != 0) {
float width = getDisplayerLocalWidth();
float height = getDisplayerLocalHeight();
sgChangeGeometrySizeSet(geometryNode, width, height);
/**
* Subtle: Changing the size of the quad will stomp the texture coordinates.
* We must force them to be restored.
*/
changeMask |= CHANGED_TEX_COORDS;
}
// React to texture coordinate changes
// Uses: window, texture
if ((changeMask & (CHANGED_TEX_COORDS|CHANGED_GEOMETRY|CHANGED_SIZE_APP)) != 0) {
// TODO: for now, texcoords only depend on app size. Eventually this should
// be the effective aperture rectangle width and height
float width = (float) sizeApp.width;
float height = (float) sizeApp.height;
if (getWindow() != null && getWindow().getTexture() != null) {
Image image = getWindow().getTexture().getImage();
float widthRatio = width / image.getWidth();
float heightRatio = height / image.getHeight();
sgChangeGeometryTexCoordsSet(geometryNode, widthRatio, heightRatio);
windowNeedsValidate = true;
}
}
// React to transform related changes
// Uses: type, parent, pixelscale, size, offset, ortho, locationOrtho, stack
if ((changeMask & (CHANGED_TYPE | CHANGED_PARENT | CHANGED_PIXEL_SCALE | CHANGED_SIZE_APP |
CHANGED_OFFSET | CHANGED_ORTHO | CHANGED_LOCATION_ORTHO | CHANGED_STACK)) != 0) {
CellTransform transform = null;
switch (type) {
case UNKNOWN:
case PRIMARY:
transform = new CellTransform(null, null);
if (ortho) {
Vector3f orthoLocTranslation = new Vector3f();
orthoLocTranslation.x = locationOrtho.x;
orthoLocTranslation.y = locationOrtho.y;
transform.setTranslation(orthoLocTranslation);
} else {
// Note: primaries now also honor the offset.
// Uses: type, parent, pixelScale, size, offset, ortho
transform = calcOffsetStackTransform();
}
break;
case SECONDARY:
case POPUP:
// Uses: type, parent, pixelScale, size, offset, ortho
transform = calcOffsetStackTransform();
}
sgChangeGeometryTransformOffsetStackSet(geometryNode, transform);
}
// Update the view node's user transform, if necessary
// Uses: type, deltaTranslationToApply
if ((changeMask & (CHANGED_TYPE | CHANGED_USER_TRANSFORM | CHANGED_ORTHO)) != 0) {
// Select the current user transform based on the ortho mode
CellTransform currentUserTransform;
if (ortho) {
currentUserTransform = userTransformOrtho;
} else {
currentUserTransform = userTransformCell;
}
if (!userTransformCellReplaced) {
// Apply any pending user transform deltas (by post-multiplying them
// into the current user transform
logger.fine("currentUserTransform (before) = " + currentUserTransform);
userTransformApplyDeltas(currentUserTransform);
}
logger.fine("currentUserTransform (latest) = " + currentUserTransform);
// Now put the update user transformation into effect
switch (type) {
case UNKNOWN:
case PRIMARY:
updatePrimaryTransform(currentUserTransform);
break;
case SECONDARY:
sgChangeTransformUserSet(viewNode, currentUserTransform);
// Note: moving a secondary in the cell doesn't change the position
// of the secondary in ortho, and vice versa.
if (!ortho && !userTransformCellChangedLocalOnly) {
window.changedUserTransformCell(userTransformCell, this);
}
break;
case POPUP:
// Always set to identity
sgChangeTransformUserSet(viewNode, new CellTransform(null, null));
}
userTransformCellReplaced = false;
userTransformCellChangedLocalOnly = false;
}
// Changing the 3D size of the app can change the offset of children, such as headers.
if ((changeMask & (CHANGED_SIZE_APP | CHANGED_PIXEL_SCALE)) != 0) {
for (View2DEntity childView : children) {
childView.changeOffsetSelfAndChildren();
}
}
sgProcessChanges();
/* For Debug
System.err.println("************* After View2DEntity.processChanges, viewNode = ");
GraphicsUtils.printNode(viewNode);
*/
/* For debug of ortho entities which should be visible
WorldManager wm = ClientContextJME.getWorldManager();
for (int i=0; i < wm.numEntities(); i++) {
Entity e = wm.getEntity(i);
if (e.toString().equals("<Plug the name of the window in here")) {
System.err.println("e = " + e);
RenderComponent rc = (RenderComponent) e.getComponent(RenderComponent.class);
}
}
*/
// In certain situations, especially after we change the texture, WindowSwings
// need to be repainted into that texture.
if (windowNeedsValidate) {
if (window instanceof WindowSwing) {
((WindowSwing)window).validate();
}
}
// Inform the window's surface of the view visibility.
if (window != null) {
DrawingSurface surface = window.getSurface();
if (surface != null) {
surface.setViewIsVisible(this, isActuallyVisible());
}
}
// Make sure that all descendent views are up-to-date
logger.fine("Update children for view " + this);