public void PutBefore(MHRoot p, MHRoot pRef) { int nPos = CurrentApp().FindOnStack(p); if (nPos == -1) { return; // If it's not there do nothing } MHVisible pVis = (MHVisible)p; // Can now safely cast it. int nRef = CurrentApp().FindOnStack(pRef); if (nRef == -1) { return; // If the reference visible isn't there do nothing. } CurrentApp().DisplayStack.RemoveAt(nPos); if (nRef >= nPos) { nRef--; // The position of the reference may have shifted } CurrentApp().DisplayStack.InsertAt(pVis, nRef + 1); // Redraw the area occupied by the moved item. We might be able to reduce // the area to be redrawn by looking at the way it is affected by other items // in the stack. We could also see whether it's currently active. Redraw(pVis.GetVisibleArea()); // Request a redraw }
protected void DrawRegion(Region toDraw, int nStackPos) { if (IsRegionEmpty(toDraw)) { return; } while (nStackPos >= 0) { MHVisible pItem = CurrentApp().DisplayStack.GetAt(nStackPos); // Work out how much of the area we want to draw is included in this visible. // The visible area will be empty if the item is transparent or not active. Region drawArea = pItem.GetVisibleArea().Clone(); drawArea.Intersect(toDraw); if (!IsRegionEmpty(drawArea)) { // It contributes something. // Remove the opaque area of this item from the region we have left. // If this item is (semi-)transparent this will not remove anything. Region newDraw = toDraw.Clone(); newDraw.Exclude(pItem.GetOpaqueArea()); DrawRegion(newDraw, nStackPos - 1); // Do the items further down if any. // Now we've drawn anything below this we can draw this item on top. pItem.Display(this); return; } nStackPos--; } // We've drawn all the visibles and there's still some undrawn area. // Fill it with black. m_Context.DrawBackground(toDraw); }
// Display stack and draw functions. public void AddToDisplayStack(MHVisible pVis) { if (CurrentApp().FindOnStack(pVis) != -1) { return; // Return if it's already there. } CurrentApp().DisplayStack.Append(pVis); Redraw(pVis.GetVisibleArea()); // Request a redraw }
public void RemoveFromDisplayStack(MHVisible pVis) { int nPos = CurrentApp().FindOnStack(pVis); if (nPos == -1) { return; } CurrentApp().DisplayStack.RemoveAt(nPos); Redraw(pVis.GetVisibleArea()); // Request a redraw }
public void SendToBack(MHRoot p) { int nPos = CurrentApp().FindOnStack(p); if (nPos == -1) { return; // If it's not there do nothing } MHVisible pVis = (MHVisible)p; // Can now safely cast it. CurrentApp().DisplayStack.RemoveAt(nPos); // Remove it from its present posn CurrentApp().DisplayStack.InsertAt(pVis, 0); // Put it on the bottom. Redraw(pVis.GetVisibleArea()); // Request a redraw }
// Functions to alter the Z-order. public void BringToFront(MHRoot p) { int nPos = CurrentApp().FindOnStack(p); if (nPos == -1) { return; // If it's not there do nothing } MHVisible pVis = (MHVisible)p; // Can now safely cast it. CurrentApp().DisplayStack.RemoveAt(nPos); // Remove it from its present posn CurrentApp().DisplayStack.Append((MHVisible)pVis); // Push it on the top. Redraw(pVis.GetVisibleArea()); // Request a redraw }
public void PutBehind(MHRoot p, MHRoot pRef) { int nPos = CurrentApp().FindOnStack(p); if (nPos == -1) { return; // If it's not there do nothing } int nRef = CurrentApp().FindOnStack(pRef); if (nRef == -1) { return; // If the reference visible isn't there do nothing. } MHVisible pVis = (MHVisible)p; // Can now safely cast it. CurrentApp().DisplayStack.RemoveAt(nPos); if (nRef >= nPos) { nRef--; // The position of the reference may have shifted } CurrentApp().DisplayStack.InsertAt((MHVisible)pVis, nRef); // Shift the reference and anything above up. Redraw(pVis.GetVisibleArea()); // Request a redraw }