Ejemplo n.º 1
0
 bool DebugStackFrame::setLocal(int which, Atom& val)
 {
     bool worked = false;
     if (trace->framep() && trace->info())
     {
         int firstLocal, pastLastLocal;
         localBounds(&firstLocal, &pastLastLocal);
         int count = pastLastLocal - firstLocal;
         if (count > 0 && which < count)
         {
             MethodInfo* info = trace->info();
             if (which == 0 && info->needRestOrArguments())
             {
                 // They are trying to modify the first local, but that is actually the special
                 // array for "...rest" or for "arguments".  That is too complicated to allow
                 // right now.  We're just going to fail the request.
             }
             else
             {
                 // copy the single arg over
                 info->unboxLocals(&val, 0, trace->types(), trace->framep(), firstLocal+which, 1);
                 worked = true;
             }
         }
     }
     return worked;
 }
    void Pager::mouseReleaseEvent(QMouseEvent * event)
    {
        // Only if left mouse button
        if (event->button() == Qt::LeftButton)
        {
            QPoint pos = event->pos();

            // Within which bounding box?
            QSize box = clampedBoundingBox();
            double lower = (width() - d->marginLeft - d->marginRight - box.width()) / 2.0;
            double upper = (count() - 1) * box.width() - lower;
            double clamp = qBound(lower, d->guiIndex * box.width(), upper);
            QPoint normPos = pos + QPoint((int) clamp + (box.width() - width()) / 2, -d->marginTop);
            int index = normPos.x() / box.width();

            // Valid bounding box?
            if (index >= 0 && index < count())
            {
                // Within bounding box?
                QPoint localPos = normPos - QPoint(index * box.width(), 0);
                QSize localSize;
                if (d->images.at(index).isNull()) {
                    localSize = box;
                } else {
                    localSize = d->images.at(index).size();
                    localSize.scale(box, Qt::KeepAspectRatio);
                }
                QRect localBounds((box.width() - localSize.width()) / 2, box.height() - localSize.height(), localSize.width(), localSize.height());
                if (localBounds.contains(localPos)) {
                    d->focus(index, true);
                }
            }
        }
    }
void OpDumper::dump(const RecordedOp& op, std::ostream& output, int level) {
    for (int i = 0; i < level; i++) {
        output << "  ";
    }

    Rect localBounds(op.unmappedBounds);
    op.localMatrix.mapRect(localBounds);
    output << sOpNameLut[op.opId] << " " << localBounds;

    if (op.localClip
            && (!op.localClip->rect.contains(localBounds) || op.localClip->intersectWithRoot)) {
        output << std::fixed << std::setprecision(0)
             << " clip=" << op.localClip->rect
             << " mode=" << (int)op.localClip->mode;

        if (op.localClip->intersectWithRoot) {
             output << " iwr";
        }
    }
}
Ejemplo n.º 4
0
void BlockFlowPainter::paintSelection(const PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
    ASSERT(paintInfo.phase == PaintPhaseForeground);
    if (!m_layoutBlockFlow.shouldPaintSelectionGaps())
        return;

    LayoutUnit lastTop = 0;
    LayoutUnit lastLeft = m_layoutBlockFlow.logicalLeftSelectionOffset(&m_layoutBlockFlow, lastTop);
    LayoutUnit lastRight = m_layoutBlockFlow.logicalRightSelectionOffset(&m_layoutBlockFlow, lastTop);

    LayoutRect bounds = m_layoutBlockFlow.visualOverflowRect();
    bounds.moveBy(paintOffset);

    // Only create a DrawingRecorder and ClipScope if skipRecording is false. This logic is needed
    // because selectionGaps(...) needs to be called even when we do not record.
    bool skipRecording = LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.context, m_layoutBlockFlow, DisplayItem::SelectionGap, paintOffset);
    Optional<LayoutObjectDrawingRecorder> drawingRecorder;
    Optional<ClipScope> clipScope;
    if (!skipRecording) {
        drawingRecorder.emplace(paintInfo.context, m_layoutBlockFlow, DisplayItem::SelectionGap, FloatRect(bounds), paintOffset);
        clipScope.emplace(paintInfo.context);
    }

    LayoutRect gapRectsBounds = m_layoutBlockFlow.selectionGaps(&m_layoutBlockFlow, paintOffset, LayoutSize(), lastTop, lastLeft, lastRight,
        skipRecording ? nullptr : &paintInfo,
        skipRecording ? nullptr : &(*clipScope));
    // TODO(wkorman): Rework below to process paint invalidation rects during layout rather than paint.
    if (!gapRectsBounds.isEmpty()) {
        PaintLayer* layer = m_layoutBlockFlow.enclosingLayer();
        gapRectsBounds.moveBy(-paintOffset);
        if (!m_layoutBlockFlow.hasLayer()) {
            LayoutRect localBounds(gapRectsBounds);
            m_layoutBlockFlow.flipForWritingMode(localBounds);
            gapRectsBounds = LayoutRect(m_layoutBlockFlow.localToAncestorQuad(FloatRect(localBounds), layer->layoutObject()).enclosingBoundingBox());
            if (layer->layoutObject()->hasOverflowClip())
                gapRectsBounds.move(layer->layoutBox()->scrolledContentOffset());
        }
        layer->addBlockSelectionGapsBounds(gapRectsBounds);
    }
}
Ejemplo n.º 5
0
    /**
     * @return a pointer to an object Atom whose members are
     * the active locals for this frame.
     */
    bool DebugStackFrame::locals(Atom*& ar, int& count)
    {
        bool worked = true;
        if (trace->framep() && trace->info())
        {
            int firstLocal, pastLastLocal;
            localBounds(&firstLocal, &pastLastLocal);
            count = pastLastLocal - firstLocal;
            AvmAssert(count >= 0);
            if ((count > 0) && debugger)
            {
                // frame looks like [this][param0...paramN][local0...localN]
                ar = (Atom*) debugger->core->GetGC()->Calloc(count, sizeof(Atom), GC::kContainsPointers|GC::kZero);
                MethodInfo* info = trace->info();
                info->boxLocals(trace->framep(), firstLocal, trace->types(), ar, 0, count);

                // If NEED_REST or NEED_ARGUMENTS is set, and the jit is being used, then the first
                // local is actually not an atom at all -- it is an ArrayObject*.  So, we need to
                // convert it to an atom.  (If the interpreter is being used instead of the jit, then
                // it is stored as an atom.)
                if (info->needRestOrArguments())
                {
                    int atomType = atomKind(ar[0]);
                    if (atomType == 0) // 0 is not a legal atom type, so ar[0] is not an atom
                    {
                        ScriptObject* obj = (ScriptObject*)ar[0];
                        ar[0] = obj->atom();
                    }
                }
            }
        }
        else
        {
            worked = false;
            count = 0;
        }
        return worked;
    }
Ejemplo n.º 6
0
arma::cube voxelize(std::vector<CylinderFrustum> cylinders, const Transform &transform, const BoundingBox &boundingBox, int maxExtent)
{
    Length xSide = boundingBox.pMax[0] - boundingBox.pMin[0];
    Length ySide = boundingBox.pMax[1] - boundingBox.pMin[1];
    Length zSide = boundingBox.pMax[2] - boundingBox.pMin[2];
    Length maxLen = max(xSide, max(ySide, zSide));
    double xRatio = xSide / maxLen;
    double yRatio = ySide / maxLen;
    double zRatio = zSide / maxLen;

    // x = col, y = row, z = slice
    arma::cube voxels = arma::zeros(maxExtent * yRatio, maxExtent * xRatio, maxExtent * zRatio);

    Length3D offset(boundingBox.pMin);
    for(CylinderFrustum& cylinder : cylinders) {
        cylinder = CylinderFrustum(cylinder.start - offset,
                                   cylinder.end - offset,
                                   cylinder.startRadius,
                                   cylinder.endRadius);
    }

    for(CylinderFrustum& cylinder : cylinders) {
        cylinder = CylinderFrustum(transform(cylinder.start),
                                   transform(cylinder.end),
                                   cylinder.startRadius,
                                   cylinder.endRadius);
    }

    Length step = maxLen / double(maxExtent - 2);
    Length eps = step; // / 2.0;
    for(CylinderFrustum& cylinder : cylinders) {
        BoundingBox localBounds(Point3D(-cylinder.h, -cylinder.startRadius, -cylinder.startRadius),
                         Point3D(cylinder.h, cylinder.startRadius, cylinder.startRadius));

        Vector3D perpendicular = cross(Vector3D(1.0, 0.0, 0.0), cylinder.direction);
        Transform rotation;
        double sinAngle = perpendicular.length();
        if(sinAngle > 0.0) {
            if(sinAngle > 1.0) {
                sinAngle -= 2.2204460492503131e-16; // typical machine precision error
            }
            double cosAngle = sqrt(1.0 - sinAngle*sinAngle);

            rotation = rotate(cosAngle, sinAngle, perpendicular);
        }
        Transform translation = translate(Length3D(cylinder.center));
        BoundingBox bounds = translation(rotation(localBounds));
        bounds.expand(eps);

        int istart = bounds.pMin.x / step;
        int jstart = bounds.pMin.y / step;
        int kstart = bounds.pMin.z / step;

        int iend = bounds.pMax.x / step + 1;
        int jend = bounds.pMax.y / step + 1;
        int kend = bounds.pMax.z / step + 1;

        for(int i = istart; i < iend + 1; i++) {
            for(int j = jstart; j < jend + 1; j++) {
                for(int k = kstart; k < kend + 1; k++) {
                    Point3D p(step * (double(i) + 0.5), step * (double(j) + 0.5), step * (double(k) + 0.5));
                    Length3D diff = p - cylinder.center;
                    Length distance = diff.length();
                    if(distance > cylinder.h + eps && distance > cylinder.startRadius + eps) {
                        continue;
                    }
                    auto yComponent = dot(diff, cylinder.direction * 1.0_um) / 1.0_um;
                    if(fabs(yComponent) <= cylinder.h + eps) {
                        auto y2 = yComponent*yComponent;
                        auto diff2 = dot(diff, diff);
                        auto distanceToAxis = sqrt(diff2 - y2);
                        double endProportion = (yComponent + cylinder.h) / (2.0 * cylinder.h);
                        Length radius = cylinder.startRadius * (1 - endProportion) + endProportion * cylinder.endRadius;
                        if(distanceToAxis <= radius + eps) {
                            if(voxels.in_range(j, i, k)) {
                                voxels(j, i, k) = 1.0;
                            }
                        }
                    }
                }
            }
        }
    }
    return voxels;
}
Ejemplo n.º 7
0
void MLPageView::goToPage (int destPage, bool animate, Component* prevButton, Component* nextButton)
{
	int duration = 500;
	float targetAlpha;
	
	//with this on, animations fail sometimes. with this off, they fail in a different way,always.
	bool proxy = true;
	
	int w = getWidth();
	int h = getHeight();
	Rectangle<int> localBounds(0, 0, w, h);
	
    int pages = mPages.size();
	if(!pages) return;
    if(mCurrPage == destPage) return;

	MLLookAndFeel* myLookAndFeel = (&(getRootViewResources(this).mLookAndFeel));
	int u = myLookAndFeel->getGridUnitSize(); 
	
	// margin between pages prevents invisible components from overlapping
	// those onscreen
	int margin = u;
	int newPage = ml::clamp(destPage, 0, (int)mPages.size() - 1);

	animate = true;
	if ((animate) && (newPage != mCurrPage) && (mCurrPage >= 0))
	{
		// line up all pages from new through current offscreen
		// and make visible all in line up
		
		int start = ml::min(mCurrPage, newPage);
		int end = ml::max(mCurrPage, newPage);
		for(int i=start; i <= end; ++i)
		{
			mPages[i]->setBounds(localBounds.translated((w + margin)*(i - mCurrPage), 0));
			mPages[i]->setVisible(true);
		}
				
		// scroll past all to new page
		for(int i=start; i <= end; ++i)
		{
			if (i == newPage)
			{
				targetAlpha = 1.f;
			}
			else if (i == mCurrPage)
			{
				targetAlpha = 0.f;
			}
			else 
			{
				// allow intermediate pages to show? we don't really do these
				// transitions anyway.  
				targetAlpha = 1.f;
			}
            
            // NOTE: this can cause a problem stopping a running thread in CachedImage::stop if called at just the wrong time-- TODO investigate!
			
			
			mAnimator.animateComponent (mPages[i], localBounds.translated((w + margin)*(i - newPage), 0),
				targetAlpha, duration, proxy, 4.0, 0.25);
		}
		
		// animate buttons 
		if (prevButton)
		{
			targetAlpha = (newPage > 0) ? 1.f : 0.f;
			mAnimator.animateComponent (prevButton, prevButton->getBounds(), 
				targetAlpha, duration, proxy, 1.0, 1.0);
//	//debug() << "prev alpha: " << targetAlpha << "\n";
		}

		// animate buttons 
		if (nextButton)
		{
			int last = mPages.size() - 1;
			targetAlpha = (newPage < last) ? 1.f : 0.f;
			mAnimator.animateComponent (nextButton, nextButton->getBounds(),
				targetAlpha, duration, proxy, 1.0, 1.0);
				
//	//debug() << "next alpha: " << targetAlpha << "\n";
		}
	}
    else
    {
        for(int p=0; p<pages; ++p)
        {
            if(p == newPage)
            {
                mPages[p]->setBounds(localBounds);
                mPages[p]->setVisible(true);
            }
            else
            {
                mPages[p]->setBounds(localBounds.translated((w + margin), 0));
                mPages[p]->setVisible(false);
            }
        }
    }

	mCurrPage = newPage;
}