Ejemplo n.º 1
0
	bool ConvexHull::PointInsideHull(const Vec2f &point)
	{
		int sgn = 0;

		for(unsigned int i = 0, numVertices = m_vertices.size(); i < numVertices; i++)
		{
			int wrappedIndex = Wrap(i + 1, numVertices);
			Vec2f currentVertex(GetWorldVertex(i));
			Vec2f side(GetWorldVertex(wrappedIndex) - currentVertex);
			Vec2f toPoint(point - currentVertex);

			float cpd = side.Cross(toPoint);

			int cpdi = static_cast<int>(cpd / abs(cpd));

			if(sgn == 0)
				sgn = cpdi;
			else if(cpdi != sgn)
				return false;
		}

		return true;
	}
Ejemplo n.º 2
0
bool IPLData::isConvertibleTo(IPLDataType dataType)
{
    switch (dataType)
    {
    case IPLData::IMAGE_BW:
    case IPLData::IMAGE_GRAYSCALE:
    case IPLData::IMAGE_COLOR:
        return toImage() != NULL;
    case IPLData::IMAGE_COMPLEX:
        return toComplexImage() != NULL;
    case IPLData::POINT:
        return toPoint() != NULL;
    case IPLData::MATRIX:
        return toMatrix() != NULL;
    case IPLData::IMAGE_ORIENTED:
    case IPLData::SHAPES:
    case IPLData::UNDEFINED:
    default:
        throw std::logic_error("Unknown method for data type");
        break;
    }
    return false;
}
Ejemplo n.º 3
0
void Editor::doScroll(int x, int y)
{
  SCROLLINFO si;
  memset(&si, 0, sizeof si);
  si.cbSize = sizeof si;
  si.fMask = SIF_RANGE | SIF_PAGE;
  GetScrollInfo(hWnd, SB_HORZ, &si);
  if (x < si.nMin) x = si.nMin;
  if (x > si.nMax - si.nPage + 1) x = si.nMax - si.nPage + 1;
  GetScrollInfo(hWnd, SB_VERT, &si);
  if (y < si.nMin) y = si.nMin;
  if (y > si.nMax - si.nPage + 1) y = si.nMax - si.nPage + 1;
  si.fMask = SIF_POS;
  if (x != scrollPos.x)
  {
    si.nPos = x;
    SetScrollInfo(hWnd, SB_HORZ, &si, TRUE);
  }
  if (y != scrollPos.y)
  {
    si.nPos = y;
    SetScrollInfo(hWnd, SB_VERT, &si, TRUE);
  }
  if (x != scrollPos.x || y != scrollPos.y)
  {
    int deltaX = scrollPos.x - x;
    int deltaY = scrollPos.y - y;
    scrollPos.x = x;
    scrollPos.y = y;
    ScrollWindowEx(hWnd, chSize.cx * deltaX, chSize.cy * deltaY, NULL, NULL, NULL, NULL, SW_INVALIDATE);
    if (GetFocus() == hWnd)
    {
      POINT pt = toPoint(caret);
      SetCaretPos((pt.x - scrollPos.x) * chSize.cx + LeftMargin(), (pt.y - scrollPos.y) * chSize.cy);
    }
  }
}
Ejemplo n.º 4
0
void MarkPatch(const Mat &src, Mat &dst, int patch_radius, std::vector<NymphPoint> &centers)
{
    src.copyTo(dst);
    Mat flags(src.rows, src.cols, CV_8UC1, Scalar::all(0));
    for (auto& pt : centers)
    {
        flags.at<uchar>(pt.row, pt.col) = 1;
    }
    int patch_size = patch_radius * 2 + 1;
    int dirmap[4][2] = {
        {1, 0}, {-1, 0}, {0, 1}, {0, -1}
    };
    int linemap[3][2] = {   // {from, to}
        {-1, -1}, {-1, 1}, {1, 1}
    };
    for (auto& pt : centers)
    {
        for (int i = 0; i < 4; ++i)
        {
            int tmp_row = pt.row + dirmap[i][0] * patch_size, tmp_col = pt.col + dirmap[i][1] * patch_size;
            if (tmp_row < 0 || tmp_row >= flags.rows
                    || tmp_col < 0 || tmp_col >= flags.cols
                    || flags.at<uchar>(tmp_row, tmp_col) == 0)
            {
                Point fromPoint(
                            pt.col + linemap[dirmap[i][1] + 1][0] * patch_radius,
                            pt.row + linemap[dirmap[i][0] + 1][0] * patch_radius
                        );
                Point toPoint(
                            pt.col + linemap[dirmap[i][1] + 1][1] * patch_radius,
                            pt.row + linemap[dirmap[i][0] + 1][1] * patch_radius
                        );
                line(dst, fromPoint, toPoint, Scalar(0, 0, 255), 2);
            }
        }
    }
}
Ejemplo n.º 5
0
void Matrix4_Test::matrix4mul()
{
	int boneId = 3;
	const Cluster* cluster = adapter->clusters();
	Matrix4 mat = cluster[boneId].world2local();

	Point p(1,2,3);
	Vector v(1,2,3);

	#if 0
	// matrix point mul
	Point p1 = mat * p;
	Point p2 = mat.rot * p + trans;
	QVERIFY(p1 == p2);

	// matrix vector mul
	Vector v1 = mat * v;
	Vector v2 = rot * v;
	QVERIFY(v1 == v2);

	// matrix inv mul
	p1 = mat.inverse() * p;
	p2 = rot.inverse() * (p + (-1 * trans));
	QVERIFY(p1 == p2);

	v1 = mat.inverse() * v;
	v2 = rot.inverse() * v;
	QVERIFY(v1 == v2);

	// check Cal3d matrices
	Point cp1 = rot * p;
	CalVector cp2 = toCalVector(p);
	cp2 *= adapter->bone(boneId)->getTransformMatrix();
	QVERIFY(cp1 == toPoint(cp2));
	#endif
}
Ejemplo n.º 6
0
void PaintLayerPainter::paintFragmentWithPhase(PaintPhase phase, const PaintLayerFragment& fragment, GraphicsContext* context, const ClipRect& clipRect, const PaintLayerPaintingInfo& paintingInfo, LayoutObject* paintingRootForLayoutObject, PaintLayerFlags paintFlags, ClipState clipState)
{
    ASSERT(m_paintLayer.isSelfPaintingLayer());

    Optional<LayerClipRecorder> clipRecorder;
    if (clipState != HasClipped && paintingInfo.clipToDirtyRect && needsToClip(paintingInfo, clipRect)) {
        DisplayItem::Type clipType = DisplayItem::paintPhaseToClipLayerFragmentType(phase);
        LayerClipRecorder::BorderRadiusClippingRule clippingRule;
        switch (phase) {
        case PaintPhaseBlockBackground: // Background painting will handle clipping to self.
        case PaintPhaseSelfOutline:
        case PaintPhaseMask: // Mask painting will handle clipping to self.
            clippingRule = LayerClipRecorder::DoNotIncludeSelfForBorderRadius;
            break;
        default:
            clippingRule = LayerClipRecorder::IncludeSelfForBorderRadius;
            break;
        }

        clipRecorder.emplace(*context, *m_paintLayer.layoutObject(), clipType, clipRect, &paintingInfo, fragment.paginationOffset, paintFlags, clippingRule);
    }

    PaintInfo paintInfo(context, pixelSnappedIntRect(clipRect.rect()), phase, paintingInfo.globalPaintFlags(), paintFlags, paintingRootForLayoutObject, paintingInfo.rootLayer->layoutObject());
    Optional<ScrollRecorder> scrollRecorder;
    LayoutPoint paintOffset = toPoint(fragment.layerBounds.location() - m_paintLayer.layoutBoxLocation());
    if (!paintingInfo.scrollOffsetAccumulation.isZero()) {
        // As a descendant of the root layer, m_paintLayer's painting is not controlled by the ScrollRecorders
        // created by BlockPainter of the ancestor layers up to the root layer, so we need to issue ScrollRecorder
        // for this layer seperately, with the scroll offset accumulated from the root layer to the parent of this
        // layer, to get the same result as ScrollRecorder in BlockPainter.
        paintOffset += paintingInfo.scrollOffsetAccumulation;
        paintInfo.rect.move(paintingInfo.scrollOffsetAccumulation);
        scrollRecorder.emplace(*paintInfo.context, *m_paintLayer.layoutObject(), paintInfo.phase, paintingInfo.scrollOffsetAccumulation);
    }
    m_paintLayer.layoutObject()->paint(paintInfo, paintOffset);
}
Ejemplo n.º 7
0
void CCxImageCtrl::OnMouseMove(UINT nFlags, CPoint point) 
{
	CPoint	imagePoint(point);
	
	ClientToImage(imagePoint);

	CRect clientRect;
	GetClientRect(&clientRect);
	
	if(m_hImage.IsInside(imagePoint.x,imagePoint.y) || (GetState()==CCxImageCtrl::IS_TextMove && m_bCaptureWasSet))
	{
		switch(GetState()) 
		{
		case CCxImageCtrl::IS_Move:
			if(m_bCaptureWasSet)
			{
				SCROLLINFO si	=	{0};
				
				if(m_dwWidth>clientRect.Width())
				{
					GetScrollInfo(SB_HORZ,&si);
					m_nHScrollPos = m_RefScroll.cx - point.x + m_RefPoint.x;

					if(m_nHScrollPos<si.nMin)
						m_nHScrollPos = si.nMin;
					if(m_nHScrollPos>si.nMax)
						m_nHScrollPos = si.nMax;
					
					SetScrollPos(SB_HORZ,m_RefScroll.cx - point.x + m_RefPoint.x); 
					Invalidate(FALSE);
				}
				
				if(m_dwHeight>clientRect.Height())
				{
					GetScrollInfo(SB_VERT,&si);
					m_nVScrollPos = m_RefScroll.cy - point.y + m_RefPoint.y;
					
					if(m_nVScrollPos<si.nMin)
						m_nVScrollPos = si.nMin;
					if(m_nVScrollPos>si.nMax)
						m_nVScrollPos = si.nMax;
					
					SetScrollPos(SB_VERT,m_RefScroll.cy - point.y + m_RefPoint.y); 
					Invalidate(FALSE);
				}
			}
			break;
		case CCxImageCtrl::IS_Crop:
			if(m_bCaptureWasSet)
			{
				m_CropActivePoint = point;

				ClientToImage(m_CropActivePoint);
				ImageToClient(m_CropActivePoint);
				
				Invalidate(FALSE);
			}
			break;
		case CCxImageCtrl::IS_TextMove:
			if (m_pTextComment != NULL)
			{
				if (!m_bCaptureWasSet)
				{
					if (!m_pTextComment->GetRectangle().PtInRect(imagePoint))
					{
						SetState(IS_Text);
						SetCursor(AfxGetApp()->LoadCursor(IDC_TEXTCURSOR));
					}
				}
				else
				{
					m_RefPoint = imagePoint;
					m_RefPoint.Offset(m_RefOffset);

					m_hImage.Copy(m_hImageBuffer);
					m_pTextComment->SetPosition(m_RefPoint, GetDC());

					m_pTextComment->DrawText(m_hImage, CPaintDC(GetDesktopWindow()));
					Invalidate(false);
				}
			}
			break;
		case CCxImageCtrl::IS_Text:
			if (m_pTextComment != NULL)
			{
				if (m_pTextComment->GetRectangle().PtInRect(imagePoint))
				{
					SetState(IS_TextMove);
					SetCursor(AfxGetApp()->LoadCursor(IDC_HANDCATCHCURSOR2));
					
					Invalidate(false);
				}
			}
			break;
		case CCxImageCtrl::IS_Pen:
			{
				// Draw Line 
				if(m_bCaptureWasSet)
				{
					CPoint	fromPoint(m_RefPoint), toPoint(point);
					
					ClientToImage(fromPoint);
					ClientToImage(toPoint);
					
					m_hImage.DrawLine(fromPoint.x, toPoint.x, m_hImage.GetHeight()-fromPoint.y,m_hImage.GetHeight()-toPoint.y,GetPenColor());
					
					//and remember new position [4/7/2004]
					m_RefScroll = CSize(m_nHScrollPos,m_nVScrollPos);
					m_RefPoint = point;

					Invalidate(FALSE);
				}
			}
			break;
		}
	}
	
	
	CWnd::OnMouseMove(nFlags, point);
}
Ejemplo n.º 8
0
void Foam::CV2D::newPoints()
{
    const scalar relaxation = relaxationModel_->relaxation();

    Info<< "Relaxation = " << relaxation << endl;

    Field<point2D> dualVertices(number_of_faces());

    label dualVerti = 0;

    // Find the dual point of each tetrahedron and assign it an index.
    for
    (
        Triangulation::Finite_faces_iterator fit = finite_faces_begin();
        fit != finite_faces_end();
        ++fit
    )
    {
        fit->faceIndex() = -1;

        if
        (
            fit->vertex(0)->internalOrBoundaryPoint()
         || fit->vertex(1)->internalOrBoundaryPoint()
         || fit->vertex(2)->internalOrBoundaryPoint()
        )
        {
            fit->faceIndex() = dualVerti;

            dualVertices[dualVerti] = toPoint2D(circumcenter(fit));

            dualVerti++;
        }
    }

    dualVertices.setSize(dualVerti);

    Field<vector2D> displacementAccumulator
    (
        startOfSurfacePointPairs_,
        vector2D::zero
    );

    // Calculate target size and alignment for vertices
    scalarField sizes
    (
        number_of_vertices(),
        meshControls().minCellSize()
    );

    Field<vector2D> alignments
    (
        number_of_vertices(),
        vector2D(1, 0)
    );

    for
    (
        Triangulation::Finite_vertices_iterator vit = finite_vertices_begin();
        vit != finite_vertices_end();
        ++vit
    )
    {
        if (vit->internalOrBoundaryPoint())
        {
            point2D vert = toPoint2D(vit->point());

            // alignment and size determination
            pointIndexHit pHit;
            label hitSurface = -1;

            qSurf_.findSurfaceNearest
            (
                toPoint3D(vert),
                meshControls().span2(),
                pHit,
                hitSurface
            );

            if (pHit.hit())
            {
                vectorField norm(1);
                allGeometry_[hitSurface].getNormal
                (
                    List<pointIndexHit>(1, pHit),
                    norm
                );

                alignments[vit->index()] = toPoint2D(norm[0]);

                sizes[vit->index()] =
                    cellSizeControl_.cellSize
                    (
                        toPoint3D(vit->point())
                    );
            }
        }
    }

    // Info<< "Calculated alignments" << endl;

    scalar cosAlignmentAcceptanceAngle = 0.68;

    // Upper and lower edge length ratios for weight
    scalar u = 1.0;
    scalar l = 0.7;

    PackedBoolList pointToBeRetained(startOfSurfacePointPairs_, true);

    std::list<Point> pointsToInsert;

    for
    (
        Triangulation::Finite_edges_iterator eit = finite_edges_begin();
        eit != finite_edges_end();
        eit++
    )
    {
        Vertex_handle vA = eit->first->vertex(cw(eit->second));
        Vertex_handle vB = eit->first->vertex(ccw(eit->second));

        if (!vA->internalOrBoundaryPoint() || !vB->internalOrBoundaryPoint())
        {
            continue;
        }

        const point2D& dualV1 = dualVertices[eit->first->faceIndex()];
        const point2D& dualV2 =
            dualVertices[eit->first->neighbor(eit->second)->faceIndex()];

        scalar dualEdgeLength = mag(dualV1 - dualV2);

        point2D dVA = toPoint2D(vA->point());
        point2D dVB = toPoint2D(vB->point());

        Field<vector2D> alignmentDirsA(2);

        alignmentDirsA[0] = alignments[vA->index()];
        alignmentDirsA[1] = vector2D
        (
           -alignmentDirsA[0].y(),
            alignmentDirsA[0].x()
        );

        Field<vector2D> alignmentDirsB(2);

        alignmentDirsB[0] = alignments[vB->index()];
        alignmentDirsB[1] = vector2D
        (
           -alignmentDirsB[0].y(),
            alignmentDirsB[0].x()
        );

        Field<vector2D> alignmentDirs(alignmentDirsA);

        forAll(alignmentDirsA, aA)
        {
            const vector2D& a(alignmentDirsA[aA]);

            scalar maxDotProduct = 0.0;

            forAll(alignmentDirsB, aB)
            {
                const vector2D& b(alignmentDirsB[aB]);

                scalar dotProduct = a & b;

                if (mag(dotProduct) > maxDotProduct)
                {
                    maxDotProduct = mag(dotProduct);

                    alignmentDirs[aA] = a + sign(dotProduct)*b;

                    alignmentDirs[aA] /= mag(alignmentDirs[aA]);
                }
            }
        }

        vector2D rAB = dVA - dVB;

        scalar rABMag = mag(rAB);

        forAll(alignmentDirs, aD)
        {
            vector2D& alignmentDir = alignmentDirs[aD];

            if ((rAB & alignmentDir) < 0)
            {
                // swap the direction of the alignment so that has the
                // same sense as rAB
                alignmentDir *= -1;
            }

            scalar alignmentDotProd = ((rAB/rABMag) & alignmentDir);

            if (alignmentDotProd > cosAlignmentAcceptanceAngle)
            {
                scalar targetFaceSize =
                    0.5*(sizes[vA->index()] + sizes[vB->index()]);

                // Test for changing aspect ratio on second alignment (first
                // alignment is neartest surface normal)
                // if (aD == 1)
                // {
                //     targetFaceSize *= 2.0;
                // }

                alignmentDir *= 0.5*targetFaceSize;

                vector2D delta = alignmentDir - 0.5*rAB;

                if (dualEdgeLength < 0.7*targetFaceSize)
                {
                    delta *= 0;
                }
                else if (dualEdgeLength < targetFaceSize)
                {
                    delta *=
                        (
                            dualEdgeLength
                           /(targetFaceSize*(u - l))
                          - 1/((u/l) - 1)
                        );
                }

                if
                (
                    vA->internalPoint()
                 && vB->internalPoint()
                 && rABMag > 1.75*targetFaceSize
                 && dualEdgeLength > 0.05*targetFaceSize
                 && alignmentDotProd > 0.93
                )
                {
                    // Point insertion
                    pointsToInsert.push_back(toPoint(0.5*(dVA + dVB)));
                }
                else if
                (
                    (vA->internalPoint() || vB->internalPoint())
                 && rABMag < 0.65*targetFaceSize
                )
                {
                    // Point removal

                    // Only insert a point at the midpoint of the short edge
                    // if neither attached point has already been identified
                    // to be removed.
                    if
                    (
                        pointToBeRetained[vA->index()] == true
                     && pointToBeRetained[vB->index()] == true
                    )
                    {
                        pointsToInsert.push_back(toPoint(0.5*(dVA + dVB)));
                    }

                    if (vA->internalPoint())
                    {
                        pointToBeRetained[vA->index()] = false;
                    }

                    if (vB->internalPoint())
                    {
                        pointToBeRetained[vB->index()] = false;
                    }
                }
                else
                {
                    if (vA->internalPoint())
                    {
                        displacementAccumulator[vA->index()] += delta;
                    }

                    if (vB->internalPoint())
                    {
                        displacementAccumulator[vB->index()] += -delta;
                    }
                }
            }
        }
    }
Ejemplo n.º 9
0
void MenuPowers::loadPower(FileParser &infile) {
	// @ATTR power.id|integer|A power id from powers/powers.txt for this slot.
	if (infile.key == "id") {
		int id = popFirstInt(infile.val);
		if (id > 0) {
			skip_section = false;
			power_cell.back().id = static_cast<short>(id);
		}
		else {
			infile.error("MenuPowers: Power index out of bounds 1-%d, skipping power.", INT_MAX);
		}
		return;
	}

	if (power_cell.back().id <= 0) {
		skip_section = true;
		power_cell.pop_back();
		slots.pop_back();
		upgradeButtons.pop_back();
		logError("MenuPowers: There is a power without a valid id as the first attribute. IDs must be the first attribute in the power menu definition.");
	}

	if (skip_section)
		return;

	// @ATTR power.tab|integer|Tab index to place this power on, starting from 0.
	if (infile.key == "tab") power_cell.back().tab = static_cast<short>(toInt(infile.val));
	// @ATTR power.position|x (integer), y (integer)|Position of this power icon; relative to MenuPowers "pos".
	else if (infile.key == "position") power_cell.back().pos = toPoint(infile.val);

	// @ATTR power.requires_physoff|integer|Power requires Physical and Offense stat of this value.
	else if (infile.key == "requires_physoff") power_cell.back().requires_physoff = static_cast<short>(toInt(infile.val));
	// @ATTR power.requires_physdef|integer|Power requires Physical and Defense stat of this value.
	else if (infile.key == "requires_physdef") power_cell.back().requires_physdef = static_cast<short>(toInt(infile.val));
	// @ATTR power.requires_mentoff|integer|Power requires Mental and Offense stat of this value.
	else if (infile.key == "requires_mentoff") power_cell.back().requires_mentoff = static_cast<short>(toInt(infile.val));
	// @ATTR power.requires_mentdef|integer|Power requires Mental and Defense stat of this value.
	else if (infile.key == "requires_mentdef") power_cell.back().requires_mentdef = static_cast<short>(toInt(infile.val));

	// @ATTR power.requires_defense|integer|Power requires Defense stat of this value.
	else if (infile.key == "requires_defense") power_cell.back().requires_defense = static_cast<short>(toInt(infile.val));
	// @ATTR power.requires_offense|integer|Power requires Offense stat of this value.
	else if (infile.key == "requires_offense") power_cell.back().requires_offense = static_cast<short>(toInt(infile.val));
	// @ATTR power.requires_physical|integer|Power requires Physical stat of this value.
	else if (infile.key == "requires_physical") power_cell.back().requires_physical = static_cast<short>(toInt(infile.val));
	// @ATTR power.requires_mental|integer|Power requires Mental stat of this value.
	else if (infile.key == "requires_mental") power_cell.back().requires_mental = static_cast<short>(toInt(infile.val));

	// @ATTR power.requires_point|boolean|Power requires a power point to unlock.
	else if (infile.key == "requires_point") power_cell.back().requires_point = toBool(infile.val);
	// @ATTR power.requires_level|integer|Power requires at least this level for the hero.
	else if (infile.key == "requires_level") power_cell.back().requires_level = static_cast<short>(toInt(infile.val));
	// @ATTR power.requires_power|integer|Power requires another power id.
	else if (infile.key == "requires_power") power_cell.back().requires_power.push_back(static_cast<short>(toInt(infile.val)));

	// @ATTR power.visible_requires_status|string|Hide the power if we don't have this campaign status.
	else if (infile.key == "visible_requires_status") power_cell.back().visible_requires_status.push_back(infile.val);
	// @ATTR power.visible_requires_not_status|string|Hide the power if we have this campaign status.
	else if (infile.key == "visible_requires_not_status") power_cell.back().visible_requires_not.push_back(infile.val);

	// @ATTR power.upgrades|id (integer), ...|A list of upgrade power ids that this power slot can upgrade to. Each of these powers should have a matching upgrade section.
	else if (infile.key == "upgrades") {
		upgradeButtons.back() = new WidgetButton("images/menus/buttons/button_plus.png");
		std::string repeat_val = infile.nextValue();
		while (repeat_val != "") {
			power_cell.back().upgrades.push_back(static_cast<short>(toInt(repeat_val)));
			repeat_val = infile.nextValue();
		}

		if (!power_cell.back().upgrades.empty())
			power_cell.back().upgrade_level = 1;
	}

	else infile.error("MenuPowers: '%s' is not a valid key.", infile.key.c_str());
}
Ejemplo n.º 10
0
void DynamicGoo::paint(QPainter &p){
    //Check rutine



    //Real paint stuff
    //check if is dragged
    if (isDragging()){
        p.setBrush(Qt::transparent);
        p.setPen(QPen(color,3));
        p.drawEllipse(toPoint(body->GetPosition()), getRadius()+10,getRadius()+10);
        //p.drawRect(boundingRect());
    }
    //check if is selected and draggable
    else if (selected && isDragable()){
        if (!hasJoint())
            p.setPen(QPen(color,3,Qt::DashLine));
        else
            p.setPen(QPen(color,3,Qt::DotLine));
        p.setBrush(Qt::transparent);
        p.drawEllipse(toPoint(body->GetPosition()), getRadius()+10,getRadius()+10);

    }
    //paint goo
    p.setPen(secondaryColor);

    QColor center=secondaryColor;
    center.setRgb((center.red()+50 > 255 ? 255 : center.red()+50),(center.green()+50 > 255 ? 255 : center.green()+50),(center.blue()+50 > 255 ? 255 : center.blue()+50));

    if (sleeping){
        p.setBrush(center);
        p.drawEllipse(getPPosition(),getRadius(),getRadius());

    }
    else {
        b2Vec2 speed=body->GetLinearVelocity();
        float angle=qAtan2(speed.x,speed.y);
        float module=(isFalling() ? speed.Length()/8 : (!hasJoint() ? speed.Length()/15 : 0));
        p.save();
        p.translate(getPPosition());
        if (!isDragging()) p.rotate((hasJoint() ? 0 :-angle*180.0/3.141628));
        else p.rotate(this->angle);
        p.setBrush(secondaryColor);

        p.drawEllipse(QPoint(0,0),qRound(getRadius()-module),qRound(getRadius()+module));
            rx=3;//+=(rand()%5-2);
            ry=-2;//+=(rand()%5-2);

        counter++;

        QRadialGradient rg(rx,ry,getRadius()+5);
        rg.setColorAt(0,center);
        rg.setColorAt(1,Qt::transparent);

        p.setBrush(rg);
        p.drawEllipse(QPoint(0,0),qRound(getRadius()-module),qRound(getRadius()+module));

        if ((counter>=delay && !hasJoint()) || isDragging() || isFalling()){
            if (!isDragging() && !isFalling()) {
                bool nE=!(rand()%5);
                if (eye) nE=rand()%3;

                if (eye!=nE && nE){
                    eyeSizeL=qrand()%3+5;
                    eyeSizeR=eyeSizeL+qrand()%4-1;
                }
                eye=nE;
                counter=0;
            }
            else if (!eye) {
                eyeSizeL=qrand()%3+5;
                eyeSizeR=eyeSizeL+qrand()%4-1;
                eye=true;
                this->angle=qrand()%360;
            }
        }

        if (eye && !hasJoint()&& !onGround) {
            p.setPen(secondaryColor);
            QRadialGradient rG2(-9,13,eyeSizeL);
            QRadialGradient rG3(9,13,eyeSizeR);

            rG2.setColorAt(0,Qt::white);
            rG2.setColorAt(1,Qt::lightGray);

            p.setBrush(rG2);
            p.drawEllipse(QPoint(-9,12),eyeSizeL,eyeSizeL);

            rG3.setColorAt(0,Qt::white);
            rG3.setColorAt(1,Qt::lightGray);

            p.setBrush(rG3);
            p.drawEllipse(QPoint(9,12),eyeSizeR,eyeSizeR);

            p.setBrush(Qt::black);
            p.setPen(Qt::transparent);
            p.drawEllipse(QPoint(-9,14),2,2);
            p.drawEllipse(QPoint(9,13),2,2);
        }

        p.restore();

    }
}
Ejemplo n.º 11
0
uint32 Editor::onMessage(uint32 message, uint32 wParam, uint32 lParam)
{
  switch (message)
  {
  case WM_DESTROY:
    delete target;
    target = NULL;
    break;
  case WM_SETCURSOR:
    if (LOWORD(lParam) == HTCLIENT)
    {
      POINT pt;
      GetCursorPos(&pt);
      ScreenToClient(hWnd, &pt);
      if (pt.x < LeftMargin())
        SetCursor(cursors[cArrow]);
      else if (selStart != caret)
      {
        pt.x = (pt.x - LeftMargin()) / chSize.cx + scrollPos.x;
        pt.y = pt.y / chSize.cy + scrollPos.y;
        if (pt.y < 0 || pt.y >= lines.length() || pt.x < 0 || pt.x >= lines[pt.y].text.length())
          SetCursor(cursors[cBeam]);
        else
        {
          int offset = fromPoint(pt);
          int sela = (selStart < caret ? selStart : caret);
          int selb = (selStart < caret ? caret : selStart);
          if (offset >= sela && offset < selb)
            SetCursor(cursors[cArrow]);
          else
            SetCursor(cursors[cBeam]);
        }
      }
      else
        SetCursor(cursors[cBeam]);
    }
    else
      SetCursor(cursors[cArrow]);
    return TRUE;
  case WM_ERASEBKGND:
    return TRUE;
  case WM_PAINT:
    paint();
    return 0;
  case WM_SIZE:
    if (hBitmap)
    {
      int wd = LOWORD(lParam);
      int ht = HIWORD(lParam);
      if (wd < 10) wd = 10;
      if (ht < 10) ht = 10;
      hBitmap = CreateCompatibleBitmap(hDC, wd, ht);
      SelectObject(hDC, hBitmap);
    }
    updateExtent();
    return 0;
  case WM_SETFOCUS:
    placeCaret();
    invalidate();
    getParent()->notify(EN_FOCUSED, (uint32) this, 0);
    return 0;
  case WM_KILLFOCUS:
    DestroyCaret();
    updateCaret();
    invalidate();
    return 0;
  case WM_LBUTTONDBLCLK:
    {
      POINT pt = paramToPoint(lParam);
      fixPoint(pt);
      int ptStart = wordEnd(lines[pt.y].text.c_str(), pt.x, -1);
      int ptEnd = wordEnd(lines[pt.y].text.c_str(), pt.x, 1);
      int offset = fromPoint(pt);
      selStart = offset - (pt.x - ptStart);
      caret = offset + (ptEnd - pt.x);
      updateCaret();
    }
    return 0;
  case WM_LBUTTONDOWN:
    if (int(GET_X_LPARAM(lParam)) < int(settings->bpOffset - scrollPos.x * chSize.cx))
    {
      POINT pt = paramToPoint(lParam);
      toggleBreakpoint(pt.y);
    }
    else
    {
      POINT pt = paramToPoint(lParam);
      int offset = fromPoint(pt);
      int sela = (selStart < caret ? selStart : caret);
      int selb = (selStart > caret ? selStart : caret);
      if (offset >= sela && offset < selb)
      {
        dragop = 1;
        uint32 fx = DoDragDropEx(CF_UNICODETEXT, CreateGlobalText(getSelection()),
            DROPEFFECT_MOVE | DROPEFFECT_COPY, hWnd);
        if (fx == DROPEFFECT_NONE)
          dragop = 0;
        //else if (fx != DROPEFFECT_COPY && dragop != 2)
        //  replace(sela, selb, "");
      }
      else
        SetCapture(hWnd);
      if (dragop == 0)
      {
        caret = offset;
        if (!(wParam & MK_SHIFT))
          selStart = caret;
      }
      dragop = 0;
      if (GetFocus() != hWnd)
        SetFocus(hWnd);
      updateCaret();
    }
    return 0;
  case WM_RBUTTONDOWN:
    if (int(GET_X_LPARAM(lParam)) >= int(settings->bpOffset - scrollPos.x * chSize.cx))
    {
      POINT pt = paramToPoint(lParam);
      int offset = fromPoint(pt);
      int sela = (selStart < caret ? selStart : caret);
      int selb = (selStart > caret ? selStart : caret);
      if (offset < sela || offset >= selb)
        caret = selStart = offset;
      if (GetFocus() != hWnd)
        SetFocus(hWnd);
      updateCaret();
    }
    return 0;
  case WM_MOUSEMOVE:
    if (GetCapture() == hWnd && (wParam & MK_LBUTTON))
    {
      POINT pt = paramToPoint(lParam);
      caret = fromPoint(pt);
      updateCaret();
    }
    return 0;
  case WM_LBUTTONUP:
    ReleaseCapture();
    return 0;
  case WM_CHAR:
    if (iswprint(wParam) && (GetAsyncKeyState(VK_CONTROL) & 0x8000) == 0)
    {
      if (caret == selStart && !insertMode && caret < getTextLength())
        replace(caret, caret + 1, WideString((wchar_t) wParam));
      else
        replace(selStart, caret, WideString((wchar_t) wParam));
    }
    return 0;
  case WM_VSCROLL:
    {
      SCROLLINFO si;
      memset(&si, 0, sizeof si);
      si.cbSize = sizeof si;
      si.fMask = SIF_ALL;
      GetScrollInfo(hWnd, SB_VERT, &si);
      switch (LOWORD(wParam))
      {
      case SB_TOP:
        si.nPos = si.nMin;
        break;
      case SB_BOTTOM:
        si.nPos = si.nMax;
        break;
      case SB_LINEUP:
        si.nPos--;
        break;
      case SB_LINEDOWN:
        si.nPos++;
        break;
      case SB_PAGEUP:
        si.nPos -= si.nPage;
        break;
      case SB_PAGEDOWN:
        si.nPos += si.nPage;
        break;
      case SB_THUMBTRACK:
        si.nPos = si.nTrackPos;
        break;
      }
      doScroll(scrollPos.x, si.nPos);
    }
    return 0;
  case WM_HSCROLL:
    {
      SCROLLINFO si;
      memset(&si, 0, sizeof si);
      si.cbSize = sizeof si;
      si.fMask = SIF_ALL;
      GetScrollInfo(hWnd, SB_HORZ, &si);
      switch (LOWORD(wParam))
      {
      case SB_LEFT:
        si.nPos = si.nMin;
        break;
      case SB_RIGHT:
        si.nPos = si.nMax;
        break;
      case SB_LINELEFT:
        si.nPos--;
        break;
      case SB_LINERIGHT:
        si.nPos++;
        break;
      case SB_PAGELEFT:
        si.nPos -= si.nPage;
        break;
      case SB_PAGERIGHT:
        si.nPos += si.nPage;
        break;
      case SB_THUMBTRACK:
        si.nPos = si.nTrackPos;
        break;
      }
      doScroll(si.nPos, scrollPos.y);
    }
    return 0;
  case WM_MOUSEWHEEL:
    {
      int step;
      SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &step, 0);
      if (step < 0)
        step = 3;
      scrollAccum.y += GET_WHEEL_DELTA_WPARAM(wParam) * step;
      doScroll(scrollPos.x, scrollPos.y - scrollAccum.y / WHEEL_DELTA);
      scrollAccum.y %= WHEEL_DELTA;
    }
    return 0;
  case WM_MOUSEHWHEEL:
    {
      scrollAccum.x += GET_WHEEL_DELTA_WPARAM(wParam) * 4;
      doScroll(scrollPos.x + scrollAccum.x / WHEEL_DELTA, scrollPos.y);
      scrollAccum.x %= WHEEL_DELTA;
    }
    return 0;
  case WM_DRAGOVER:
    {
      if (running || settings->mode)
        return TRUE;
      POINT pt = paramToPoint(lParam);
      dropPos = fromPoint(pt);

      RECT rc;
      GetClientRect(hWnd, &rc);
      int xto = scrollPos.x;
      if (pt.x < 10)
        xto--;
      else if (pt.x > rc.right - 10)
        xto++;
      int yto = scrollPos.y;
      if (pt.y < 10)
        yto--;
      else if (pt.y > rc.bottom - 10)
        yto++;
      doScroll(xto, yto);

      int sela = (selStart < caret ? selStart : caret);
      int selb = (selStart > caret ? selStart : caret);
      if (dropPos > sela && dropPos < selb)
        return TRUE;
      else
      {
        fixPoint(pt);
        CreateCaret(hWnd, NULL, 2, chSize.cy);
        SetCaretPos((pt.x - scrollPos.x) * chSize.cx + LeftMargin(), (pt.y - scrollPos.y) * chSize.cy);
        ShowCaret(hWnd);
      }
    }
    return 0;
  case WM_DRAGLEAVE:
    dropPos = 0;
    updateCaret();
    return 0;
  case WM_DRAGDROP:
    if (running || settings->mode)
      return DROPEFFECT_NONE;
    if (dragop)
    {
      dragop = 2;
      int sela = (selStart < caret ? selStart : caret);
      int selb = (selStart > caret ? selStart : caret);
      if (dropPos < sela || dropPos > selb)
      {
        WideString text = getSelection();
        if (lParam != DROPEFFECT_COPY)
        {
          replace(sela, selb, L"");
          if (dropPos > selb)
            dropPos -= (selb - sela);
          caret = replace(dropPos, dropPos, text, NULL, true);
        }
        else
          caret = replace(dropPos, dropPos, text);
        selStart = dropPos;
      }
    }
    else
    {
      caret = replace(dropPos, dropPos, GetGlobalTextWide((HGLOBAL) wParam));
      selStart = dropPos;
      return DROPEFFECT_COPY;
    }
    return lParam;
  case WM_SYSKEYDOWN:
  case WM_KEYDOWN:
    onKey(wParam);
    return 0;
  case WM_COMMAND:
    switch (LOWORD(wParam))
    {
    case ID_EDIT_UNDO:
      {
        bool glue = true;
        bool first = true;
        while (glue && historyPos > 0)
        {
          HistoryItem& h = history[--historyPos];
          replace(h.begin, h.end, h.text, &h);
          glue = h.glue;
          h.glue = !first;
          first = false;
        }
      }
      break;
    case ID_EDIT_REDO:
      {
        bool glue = true;
        bool first = true;
        while (glue && historyPos < history.length())
        {
          HistoryItem& h = history[historyPos++];
          replace(h.begin, h.end, h.text, &h);
          glue = h.glue;
          h.glue = !first;
          first = false;
        }
      }
      break;
    case ID_EDIT_SELECTALL:
      selStart = 0;
      caret = getTextLength();
      updateCaret();
      break;
    case ID_EDIT_COPY:
      if (caret != selStart)
        SetClipboard(CF_UNICODETEXT, CreateGlobalText(getSelection()));
      else
      {
        POINT pt = toPoint(caret);
        pt.x = 0;
        int start = fromPoint(pt);
        if (pt.y < lines.length() - 1)
          pt.y++;
        else
          pt.x = lines[pt.y].text.length();
        int end = fromPoint(pt);
        if (pCopyLine)
          pCopyLine->Release();
        pCopyLine = SetClipboard(CF_UNICODETEXT, CreateGlobalText(substring(start, end)));
        if (pCopyLine)
          pCopyLine->AddRef();
      }
      break;
    case ID_EDIT_CUT:
      if (caret != selStart)
      {
        SetClipboard(CF_UNICODETEXT, CreateGlobalText(getSelection()));
        replace(selStart, caret, L"");
      }
      else
      {
        POINT pt = toPoint(caret);
        POINT save = pt;
        pt.x = 0;
        int start = fromPoint(pt);
        if (pt.y < lines.length() - 1)
          pt.y++;
        else
          pt.x = lines[pt.y].text.length();
        int end = fromPoint(pt);
        if (pCopyLine)
          pCopyLine->Release();
        pCopyLine = SetClipboard(CF_UNICODETEXT, CreateGlobalText(substring(start, end)));
        if (pCopyLine)
          pCopyLine->AddRef();
        replace(start, end, L"");
        caret = selStart = fromPoint(save);
        updateCaret();
      }
      break;
    case ID_EDIT_PASTE:
      {
        ClipboardReader reader(CF_UNICODETEXT);
        if (reader.getData())
        {
          if (OleIsCurrentClipboard(pCopyLine) == S_OK)
          {
            POINT pt = toPoint(caret);
            pt.x = 0;
            caret = selStart = fromPoint(pt);
          }
          selStart = caret = replace(selStart, caret, GetGlobalTextWide(reader.getData()));
          updateCaret();
        }
      }
      break;
    case ID_DEBUG_BREAKPOINT:
      {
        POINT pt = toPoint(caret);
        toggleBreakpoint(pt.y);
      }
      break;
    default:
      return M_UNHANDLED;
    }
    return 0;
  }
  return M_UNHANDLED;
}
Ejemplo n.º 12
0
wxSize JSONItem::toSize() const
{
    wxPoint pt = toPoint();
    return wxSize(pt.x, pt.y);
}
Ejemplo n.º 13
0
MenuInventory::MenuInventory(StatBlock *_stats) {
	stats = _stats;
	MAX_EQUIPPED = 4;
	MAX_CARRIED = 64;
	visible = false;

	setBackground("images/menus/inventory.png");

	currency = 0;

	carried_cols = 4; // default to 4 if menus/inventory.txt::carried_cols not set
	carried_rows = 4; // default to 4 if menus/inventory.txt::carried_rows not set

	drag_prev_src = -1;
	changed_equipment = true;
	log_msg = "";
	show_book = "";

	closeButton = new WidgetButton("images/menus/buttons/button_x.png");

	// Load config settings
	FileParser infile;
	// @CLASS MenuInventory|Description of menus/inventory.txt
	if (infile.open("menus/inventory.txt")) {
		while(infile.next()) {
			if (parseMenuKey(infile.key, infile.val))
				continue;

			// @ATTR close|x (integer), y (integer)|Position of the close button.
			if(infile.key == "close") {
				Point pos = toPoint(infile.val);
				closeButton->setBasePos(pos.x, pos.y);
			}
			// @ATTR equipment_slot|x (integer), y (integer), size (integer), slot_type (string)|Position and item type of an equipment slot.
			else if(infile.key == "equipment_slot") {
				Rect area;
				Point pos;

				pos.x = area.x = popFirstInt(infile.val);
				pos.y = area.y = popFirstInt(infile.val);
				area.w = area.h = popFirstInt(infile.val);
				equipped_area.push_back(area);
				equipped_pos.push_back(pos);
				slot_type.push_back(popFirstString(infile.val));
			}
			// @ATTR slot_name|string|The displayed name of the last defined equipment slot.
			else if(infile.key == "slot_name") slot_desc.push_back(infile.val);
			// @ATTR carried_area|x (integer), y (integer)|Position of the first normal inventory slot.
			else if(infile.key == "carried_area") {
				Point pos;
				carried_pos.x = carried_area.x = popFirstInt(infile.val);
				carried_pos.y = carried_area.y = popFirstInt(infile.val);
			}
			// @ATTR carried_cols|integer|The number of columns for the normal inventory.
			else if (infile.key == "carried_cols") carried_cols = std::max(1, toInt(infile.val));
			// @ATTR carried_rows|integer|The number of rows for the normal inventory.
			else if (infile.key == "carried_rows") carried_rows = std::max(1, toInt(infile.val));
			// @ATTR label_title|label|Position of the "Inventory" label.
			else if (infile.key == "label_title") title =  eatLabelInfo(infile.val);
			// @ATTR currency|label|Position of the label that displays the total currency being carried.
			else if (infile.key == "currency") currency_lbl =  eatLabelInfo(infile.val);
			// @ATTR help|x (integer), y (integer), w (integer), h (integer)|A mouse-over area that displays some help text for inventory shortcuts.
			else if (infile.key == "help") help_pos = toRect(infile.val);

			else infile.error("MenuInventory: '%s' is not a valid key.", infile.key.c_str());
		}
		infile.close();
	}

	MAX_EQUIPPED = equipped_area.size();
	MAX_CARRIED = carried_cols * carried_rows;

	carried_area.w = carried_cols*ICON_SIZE;
	carried_area.h = carried_rows*ICON_SIZE;

	color_normal = font->getColor("menu_normal");
	color_high = font->getColor("menu_bonus");

	inventory[EQUIPMENT].init(MAX_EQUIPPED, equipped_area, slot_type);
	inventory[CARRIED].init(MAX_CARRIED, carried_area, ICON_SIZE, carried_cols);

	for (int i = 0; i < MAX_EQUIPPED; i++) {
		tablist.add(inventory[EQUIPMENT].slots[i]);
	}
	for (int i = 0; i < MAX_CARRIED; i++) {
		tablist.add(inventory[CARRIED].slots[i]);
	}

	align();
}
Ejemplo n.º 14
0
void Editor::updateFocus()
{
  focus.clear();
  //if (caret != selStart)
  //  return;
  POINT pt = toPoint(caret);

  int ctx = lines[pt.y].ctx;
  int ctxType = lines[pt.y].ctxType;
  wchar_t const* text = lines[pt.y].text.c_str();
  int pos = 0;
  while (pos < pt.x && text[pos])
  {
    if (ctx)
    {
      if (text[pos] == ']')
      {
        pos++;
        int count = 0;
        while (text[pos] == '=' && count < ctxType)
          pos++, count++;
        if (text[pos] == ']' && count == ctxType)
        {
          pos++;
          ctx = 0;
          ctxType = 0;
        }
      }
      else
        pos++;
    }
    else
    {
      if (text[pos] == '[')
      {
        pos++;
        while (text[pos] == '=')
          pos++, ctxType++;
        if (text[pos] == '[')
        {
          pos++;
          ctx = ctxString;
        }
        else
          ctxType = 0;
      }
      else if (text[pos] == '-' && text[pos + 1] == '-')
      {
        pos += 2;
        if (text[pos] == '[')
        {
          pos++;
          while (text[pos] == '=')
            pos++, ctxType++;
          if (text[pos] == '[')
          {
            pos++;
            ctx = ctxComment;
          }
          else
            return;
        }
        else
          return;
      }
      else if (text[pos] == '"' || text[pos] == '\'')
      {
        wchar_t end = text[pos++];
        while (text[pos] && text[pos] != end)
        {
          if (text[pos] == '\\') pos++;
          if (text[pos]) pos++;
        }
        if (text[pos])
          pos++;
      }
      else
        pos++;
    }
  }
  if (pos > pt.x || ctx) return;
  if (text[pt.x] == '[')
  {
    int pos = pt.x + 1;
    while (text[pos] == '=')
      pos++;
    if (text[pos] == '[')
      return;
  }

  int start = pt.x;
  int type = 0;
  WideString kw;
  if (isBracket(lines[pt.y].text[pt.x]))
    type = 1;
  else
  {
    int end = start;
    while (start > 0 && iswalpha(lines[pt.y].text[start - 1]))
      start--;
    while (iswalpha(lines[pt.y].text[end]))
      end++;
    kw = lines[pt.y].text.substring(start, end);
    if (keywords.has(kw))
      type = -1;
  }
  if (type == 0 && pt.x > 0 && isBracket(lines[pt.y].text[pt.x - 1]))
  {
    start = pt.x - 1;
    type = 1;
  }
  pt.x = start;
  if (type == 1)
  {
    int stack = 1;
    wchar_t fwd = lines[pt.y].text[start];
    wchar_t rev = isBracket(fwd);
    bool forward = (fwd == '(' || fwd == '[' || fwd == '{');
    while (stack > 0)
    {
      WideString brk = (forward ? nextKey(pt, true) : prevKey(pt, true));
      if (brk.length() == 0 || pt.y < 0 || pt.y >= lines.length())
        break;
      if (brk[0] == fwd)
        stack++;
      else if (brk[0] == rev)
        stack--;
    }
    if (stack == 0)
    {
      focus.push(FocusWord(fromPoint(pt), 1));
      pt = toPoint(caret); pt.x = start;
      focus.push(FocusWord(fromPoint(pt), 1));
    }
  }
  else if (type == -1 && kwInGraph.has(kw))
  {
    Array<WideString> stk;
    stk.push(kw);
    POINT save = pt;
    while (stk.length() && pt.y < lines.length())
    {
      WideString next = nextKey(pt, false);
      if (next.length() == 0) break;
      if (inKwGraph(stk.top(), next))
      {
        if (stk.length() == 1)
          focus.push(FocusWord(fromPoint(pt), next.length()));
        stk.top() = next;
      }
      else if (kwBegin.has(next))
        stk.push(next);
      if (kwEnd.has(stk.top()))
        stk.pop();
    }
    pt = save;
    stk.clear();
    stk.push(kw);
    while (stk.length() && pt.y >= 0)
    {
      WideString prev = prevKey(pt, false);
      if (prev.length() == 0) break;
      if (inKwGraph(prev, stk.top()))
      {
        if (stk.length() == 1)
          focus.push(FocusWord(fromPoint(pt), prev.length()));
        stk.top() = prev;
      }
      else if (kwEnd.has(prev))
        stk.push(prev);
      if (kwBegin.has(stk.top()) && (stk.top() != L"do" || stk.length() > 1))
        stk.pop();
    }
    if (focus.length())
    {
      pt = toPoint(caret); pt.x = start;
      focus.push(FocusWord(fromPoint(pt), kw.length()));
    }
  }
  focus.sort();
}
Ejemplo n.º 15
0
MenuInventory::MenuInventory(StatBlock *_stats)
	: stats(_stats)
	, MAX_EQUIPPED(4)
	, MAX_CARRIED(64)
	, carried_cols(4)
	, carried_rows(4)
	, tap_to_activate_ticks(0)
	, currency(0)
	, drag_prev_src(-1)
	, changed_equipment(true)
	, inv_ctrl(INV_CTRL_NONE)
	, show_book("")
{
	visible = false;

	setBackground("images/menus/inventory.png");

	closeButton = new WidgetButton("images/menus/buttons/button_x.png");

	// Load config settings
	FileParser infile;
	// @CLASS MenuInventory|Description of menus/inventory.txt
	if (infile.open("menus/inventory.txt")) {
		while(infile.next()) {
			if (parseMenuKey(infile.key, infile.val))
				continue;

			// @ATTR close|point|Position of the close button.
			if(infile.key == "close") {
				Point pos = toPoint(infile.val);
				closeButton->setBasePos(pos.x, pos.y);
			}
			// @ATTR equipment_slot|repeatable(int, int, string) : X, Y, Slot Type|Position and item type of an equipment slot.
			else if(infile.key == "equipment_slot") {
				Rect area;
				Point pos;

				pos.x = area.x = popFirstInt(infile.val);
				pos.y = area.y = popFirstInt(infile.val);
				area.w = area.h = ICON_SIZE;
				equipped_area.push_back(area);
				equipped_pos.push_back(pos);
				slot_type.push_back(popFirstString(infile.val));
			}
			// @ATTR carried_area|point|Position of the first normal inventory slot.
			else if(infile.key == "carried_area") {
				Point pos;
				carried_pos.x = carried_area.x = popFirstInt(infile.val);
				carried_pos.y = carried_area.y = popFirstInt(infile.val);
			}
			// @ATTR carried_cols|int|The number of columns for the normal inventory.
			else if (infile.key == "carried_cols") carried_cols = std::max(1, toInt(infile.val));
			// @ATTR carried_rows|int|The number of rows for the normal inventory.
			else if (infile.key == "carried_rows") carried_rows = std::max(1, toInt(infile.val));
			// @ATTR label_title|label|Position of the "Inventory" label.
			else if (infile.key == "label_title") title =  eatLabelInfo(infile.val);
			// @ATTR currency|label|Position of the label that displays the total currency being carried.
			else if (infile.key == "currency") currency_lbl =  eatLabelInfo(infile.val);
			// @ATTR help|rectangle|A mouse-over area that displays some help text for inventory shortcuts.
			else if (infile.key == "help") help_pos = toRect(infile.val);

			else infile.error("MenuInventory: '%s' is not a valid key.", infile.key.c_str());
		}
		infile.close();
	}

	MAX_EQUIPPED = static_cast<int>(equipped_area.size());
	MAX_CARRIED = carried_cols * carried_rows;

	carried_area.w = carried_cols*ICON_SIZE;
	carried_area.h = carried_rows*ICON_SIZE;

	color_normal = font->getColor("menu_normal");
	color_high = font->getColor("menu_bonus");

	inventory[EQUIPMENT].initFromList(MAX_EQUIPPED, equipped_area, slot_type);
	inventory[CARRIED].initGrid(MAX_CARRIED, carried_area, carried_cols);

	for (int i = 0; i < MAX_EQUIPPED; i++) {
		tablist.add(inventory[EQUIPMENT].slots[i]);
	}
	for (int i = 0; i < MAX_CARRIED; i++) {
		tablist.add(inventory[CARRIED].slots[i]);
	}

	align();
}
Ejemplo n.º 16
0
bool BuildingCollsionImpl::openSceneFile(const char* pSource, unsigned int fileSize)
{
	//清除旧数据
	clear();

	const char* point = pSource;

	unsigned int dwVersion = 0;
	memcpy(&dwVersion, point, sizeof(unsigned int)); point += sizeof(unsigned int);

	int nPointsCounts = 0;
	memcpy(&nPointsCounts, point, sizeof(int));	point += sizeof(int);
	
	iTriangleSet iAllTriangle;
	iPointMap iAllPointMap;
	m_pointBuf.reserve(5000);

	//int totalCounts = 0;
	if(nPointsCounts <= 0) return true;		//skip
	for(int i=0; i<nPointsCounts; i++)
	{
		point += sizeof(int)*2;		//skip x,y

		int triCounts;
		memcpy(&triCounts, point, sizeof(int));	point += sizeof(int);
		for(int j=0; j<triCounts; j++)
		{
			fTriangle f_triangle;
			memcpy(&f_triangle, point, sizeof(fTriangle));	point += sizeof(fTriangle);

			iPoint3 i_triangle;
			toPoint(i_triangle,
				_insertPoint(iAllPointMap, m_pointBuf, f_triangle.v1),
				_insertPoint(iAllPointMap, m_pointBuf, f_triangle.v2),
				_insertPoint(iAllPointMap, m_pointBuf, f_triangle.v3));

			std::pair< iTriangleSet::iterator, bool > ret = 
				iAllTriangle.insert(i_triangle);
		}
	}
#if 0
	FILE* fpDebug = fopen("d:\\out.txt", "w");
	for(int i=0; i<(int)m_pointBuf.size(); i++)
	{
		fprintf(fpDebug, "%d\t%f\t%f\t%f\n", i, m_pointBuf[i].x, m_pointBuf[i].y, m_pointBuf[i].z);
	}
	fclose(fpDebug); fpDebug=0;
#endif
	//create index buf
	m_indexBuf = new unsigned int[iAllTriangle.size()*3];
	iTriangleSet::iterator it, end=iAllTriangle.end();
	int i=0;
	for(it=iAllTriangle.begin(); it!=end; it++)
	{
		m_indexBuf[i++]=it->first;
		m_indexBuf[i++]=it->second.first;
		m_indexBuf[i++]=it->second.second;
	}

	m_meshInterface.SetNbTriangles((uword)iAllTriangle.size());
	m_meshInterface.SetNbVertices((uword)m_pointBuf.size());
	m_meshInterface.SetPointers((const IndexedTriangle*)m_indexBuf, &(m_pointBuf[0]));

	Opcode::OPCODECREATE Create;
	Create.mIMesh			= &m_meshInterface;
	Create.mSettings.mLimit	= 1;
	Create.mSettings.mRules	= Opcode::SPLIT_SPLATTER_POINTS|Opcode::SPLIT_GEOM_CENTER;
	Create.mNoLeaf			= true;
	Create.mQuantized		= true;
	Create.mKeepOriginal	= false;
	Create.mCanRemap		= false;


	m_modelScene = new Opcode::Model;
	bool ret = m_modelScene->Build(Create);

	return true;
}
Ejemplo n.º 17
0
// Updates the contents of the root layer texture that fall inside the updateRect
// and re-composits all sublayers.
void LayerRendererChromium::drawLayers(const IntRect& updateRect, const IntRect& visibleRect,
                                       const IntRect& contentRect, const IntPoint& scrollPosition)
{
    ASSERT(m_hardwareCompositing);

    if (!m_rootLayer)
        return;

    makeContextCurrent();

    GLC(glBindTexture(GL_TEXTURE_2D, m_rootLayerTextureId));

    // If the size of the visible area has changed then allocate a new texture
    // to store the contents of the root layer and adjust the projection matrix
    // and viewport.
    int visibleRectWidth = visibleRect.width();
    int visibleRectHeight = visibleRect.height();
    if (visibleRectWidth != m_rootLayerTextureWidth || visibleRectHeight != m_rootLayerTextureHeight) {
        m_rootLayerTextureWidth = visibleRect.width();
        m_rootLayerTextureHeight = visibleRect.height();

        m_projectionMatrix = orthoMatrix(0, visibleRectWidth, visibleRectHeight, 0, -1000, 1000);
        GLC(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_rootLayerTextureWidth, m_rootLayerTextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0));
    }

    // The GL viewport covers the entire visible area, including the scrollbars.
    GLC(glViewport(0, 0, visibleRectWidth, visibleRectHeight));

    // Bind the common vertex attributes used for drawing all the layers.
    LayerChromium::prepareForDraw(layerSharedValues());

    // FIXME: These calls can be made once, when the compositor context is initialized.
    GLC(glDisable(GL_DEPTH_TEST));
    GLC(glDisable(GL_CULL_FACE));
    GLC(glDepthFunc(GL_LEQUAL));
    GLC(glClearStencil(0));

    if (m_scrollPosition == IntPoint(-1, -1))
        m_scrollPosition = scrollPosition;

    IntPoint scrollDelta = toPoint(scrollPosition - m_scrollPosition);
    // Scroll only when the updateRect contains pixels for the newly uncovered region to avoid flashing.
    if ((scrollDelta.x() && updateRect.width() >= abs(scrollDelta.x()) && updateRect.height() >= contentRect.height())
        || (scrollDelta.y() && updateRect.height() >= abs(scrollDelta.y()) && updateRect.width() >= contentRect.width())) {
        // Scrolling works as follows: We render a quad with the current root layer contents
        // translated by the amount the page has scrolled since the last update and then read the
        // pixels of the content area (visible area excluding the scroll bars) back into the
        // root layer texture. The newly exposed area is subesquently filled as usual with
        // the contents of the updateRect.
        TransformationMatrix scrolledLayerMatrix;
#if PLATFORM(SKIA)
        float scaleFactor = 1.0f;
#elif PLATFORM(CG)
        // Because the contents of the OpenGL texture are inverted
        // vertically compared to the Skia backend, we need to move
        // the backing store in the opposite direction.
        float scaleFactor = -1.0f;
#else
#error "Need to implement for your platform."
#endif

        scrolledLayerMatrix.translate3d(0.5 * visibleRect.width() - scrollDelta.x(),
            0.5 * visibleRect.height() + scaleFactor * scrollDelta.y(), 0);
        scrolledLayerMatrix.scale3d(1, -1, 1);

        useShader(m_scrollShaderProgram);
        GLC(glUniform1i(m_scrollShaderSamplerLocation, 0));
        LayerChromium::drawTexturedQuad(m_projectionMatrix, scrolledLayerMatrix,
                                        visibleRect.width(), visibleRect.height(), 1,
                                        m_scrollShaderMatrixLocation, -1);

        GLC(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, contentRect.width(), contentRect.height()));
        m_scrollPosition = scrollPosition;
    } else if (abs(scrollDelta.y()) > contentRect.height() || abs(scrollDelta.x()) > contentRect.width()) {
        // Scrolling larger than the contentRect size does not preserve any of the pixels, so there is
        // no need to copy framebuffer pixels back into the texture.
        m_scrollPosition = scrollPosition;
    }

    // FIXME: The following check should go away when the compositor renders independently from its own thread.
    // Ignore a 1x1 update rect at (0, 0) as that's used a way to kick off a redraw for the compositor.
    if (!(!updateRect.x() && !updateRect.y() && updateRect.width() == 1 && updateRect.height() == 1)) {
        // Update the root layer texture.
        ASSERT((updateRect.x() + updateRect.width() <= m_rootLayerTextureWidth)
               && (updateRect.y() + updateRect.height() <= m_rootLayerTextureHeight));

#if PLATFORM(SKIA)
        // Get the contents of the updated rect.
        const SkBitmap bitmap = m_rootLayerCanvas->getDevice()->accessBitmap(false);
        int rootLayerWidth = bitmap.width();
        int rootLayerHeight = bitmap.height();
        ASSERT(rootLayerWidth == updateRect.width() && rootLayerHeight == updateRect.height());
        void* pixels = bitmap.getPixels();

        // Copy the contents of the updated rect to the root layer texture.
        GLC(glTexSubImage2D(GL_TEXTURE_2D, 0, updateRect.x(), updateRect.y(), updateRect.width(), updateRect.height(), GL_RGBA, GL_UNSIGNED_BYTE, pixels));
#elif PLATFORM(CG)
        // Get the contents of the updated rect.
        ASSERT(static_cast<int>(CGBitmapContextGetWidth(m_rootLayerCGContext.get())) == updateRect.width() && static_cast<int>(CGBitmapContextGetHeight(m_rootLayerCGContext.get())) == updateRect.height());
        void* pixels = m_rootLayerBackingStore.data();

        // Copy the contents of the updated rect to the root layer texture.
        // The origin is at the lower left in Core Graphics' coordinate system. We need to correct for this here.
        GLC(glTexSubImage2D(GL_TEXTURE_2D, 0,
                            updateRect.x(), m_rootLayerTextureHeight - updateRect.y() - updateRect.height(),
                            updateRect.width(), updateRect.height(),
                            GL_RGBA, GL_UNSIGNED_BYTE, pixels));
#else
#error "Need to implement for your platform."
#endif
    }

    glClearColor(0, 0, 1, 1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Render the root layer using a quad that takes up the entire visible area of the window.
    // We reuse the shader program used by ContentLayerChromium.
    const ContentLayerChromium::SharedValues* contentLayerValues = contentLayerSharedValues();
    useShader(contentLayerValues->contentShaderProgram());
    GLC(glUniform1i(contentLayerValues->shaderSamplerLocation(), 0));
    TransformationMatrix layerMatrix;
    layerMatrix.translate3d(visibleRect.width() * 0.5f, visibleRect.height() * 0.5f, 0);
    LayerChromium::drawTexturedQuad(m_projectionMatrix, layerMatrix,
                                    visibleRect.width(), visibleRect.height(), 1,
                                    contentLayerValues->shaderMatrixLocation(), contentLayerValues->shaderAlphaLocation());

    // If culling is enabled then we will cull the backface.
    GLC(glCullFace(GL_BACK));
    // The orthographic projection is setup such that Y starts at zero and
    // increases going down the page so we need to adjust the winding order of
    // front facing triangles.
    GLC(glFrontFace(GL_CW));

    // The shader used to render layers returns pre-multiplied alpha colors
    // so we need to send the blending mode appropriately.
    GLC(glEnable(GL_BLEND));
    GLC(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));

    // Translate all the composited layers by the scroll position.
    TransformationMatrix matrix;
    matrix.translate3d(-m_scrollPosition.x(), -m_scrollPosition.y(), 0);

    // Traverse the layer tree and update the layer transforms.
    float opacity = 1;
    const Vector<RefPtr<LayerChromium> >& sublayers = m_rootLayer->getSublayers();
    size_t i;
    for (i = 0; i < sublayers.size(); i++)
        updateLayersRecursive(sublayers[i].get(), matrix, opacity);

    m_rootVisibleRect = visibleRect;

    // Enable scissoring to avoid rendering composited layers over the scrollbars.
    GLC(glEnable(GL_SCISSOR_TEST));
    FloatRect scissorRect(contentRect);
    // The scissorRect should not include the scroll offset.
    scissorRect.move(-m_scrollPosition.x(), -m_scrollPosition.y());
    scissorToRect(scissorRect);

    // Clear the stencil buffer to 0.
    GLC(glClear(GL_STENCIL_BUFFER_BIT));
    // Disable writes to the stencil buffer.
    GLC(glStencilMask(0));

    // Traverse the layer tree one more time to draw the layers.
    for (i = 0; i < sublayers.size(); i++)
        drawLayersRecursive(sublayers[i].get(), scissorRect);

    GLC(glDisable(GL_SCISSOR_TEST));

    m_gles2Context->swapBuffers();

    m_needsDisplay = false;
}
Ejemplo n.º 18
0
MenuDevConsole::MenuDevConsole()
	: Menu()
	, input_scrollback_pos(0)
{

	button_close = new WidgetButton("images/menus/buttons/button_x.png");
	tablist.add(button_close);

	input_box = new WidgetInput("images/menus/input_console.png");
	tablist.add(input_box);

	button_confirm = new WidgetButton();
	button_confirm->label = msg->get("Execute");
	tablist.add(button_confirm);

	// Load config settings
	FileParser infile;
	// @CLASS MenuDevConsole|Description of menus/devconsole.txt
	if(infile.open("menus/devconsole.txt")) {
		while(infile.next()) {
			if (parseMenuKey(infile.key, infile.val))
				continue;

			// @ATTR close|x (integer), y (integer)|Position of the close button.
			if(infile.key == "close") {
				Point pos = toPoint(infile.val);
				button_close->setBasePos(pos.x, pos.y);
			}
			// @ATTR label_title|label|Position of the "Developer Console" label.
			else if(infile.key == "label_title") title = eatLabelInfo(infile.val);
			// @ATTR confirm|x (integer), y (integer)|Position of the "Execute" button.
			else if(infile.key == "confirm") {
				Point pos = toPoint(infile.val);
				button_confirm->setBasePos(pos.x, pos.y);
			}
			// @ATTR input|x (integer), y (integer)|Position of the command entry widget.
			else if(infile.key == "input") {
				Point pos = toPoint(infile.val);
				input_box->setBasePos(pos.x, pos.y);
			}
			// @ATTR history|x (integer), y (integer), w (integer), h (integer)|Position and dimensions of the command history.
			else if(infile.key == "history") history_area = toRect(infile.val);

			else infile.error("MenuDevConsole: '%s' is not a valid key.", infile.key.c_str());
		}
		infile.close();
	}

	log_history = new WidgetLog(history_area.w, history_area.h);
	log_history->setBasePos(history_area.x, history_area.y);
	tablist.add(log_history->getWidget());

	setBackground("images/menus/dev_console.png");

	color_echo = font->getColor("widget_disabled");
	color_error = font->getColor("menu_penalty");
	color_hint = font->getColor("menu_bonus");

	align();
	input_box->inFocus = true;
}
Ejemplo n.º 19
0
void CCxImageCtrl::OnLButtonUp(UINT nFlags, CPoint point) 
{
	CPoint	imagePoint(point);
	
	ClientToImage(imagePoint);
	
	if(m_bCaptureWasSet&&m_hImage.IsInside(imagePoint.x,imagePoint.y))
	{
		CPoint lefttop(m_RefPoint), rightbottom(point);
		ClientToImage(lefttop);
		ClientToImage(rightbottom);

		switch(GetState()) 
		{
		case CCxImageCtrl::IS_Move:
			SetCursor(AfxGetApp()->LoadCursor(IDC_HANDCATCHCURSOR1));
			break;
		case CCxImageCtrl::IS_Crop:

			SaveImageToUndo();

			m_hImage.Crop(CRect(lefttop,rightbottom));

			//  [Tue 7/6/2004]
			//m_bCurrentImageWasSave = false;
			m_bIsSaved = false;

			Refresh();

			break;
		case CCxImageCtrl::IS_TextMove:
		case CCxImageCtrl::IS_Text:
			
			m_bIsSaved = false;

			break;
		case CCxImageCtrl::IS_Pen:
			CPoint	fromPoint(m_RefPoint), toPoint(point);
			
			ClientToImage(fromPoint);
			ClientToImage(toPoint);
			
			m_hImage.DrawLine(fromPoint.x, toPoint.x, m_hImage.GetHeight()-fromPoint.y,m_hImage.GetHeight()-toPoint.y,GetPenColor());

			//  [Tue 7/6/2004]
			//m_bCurrentImageWasSave = false;
			m_bIsSaved = false;

			break;		
		}
	}

	if(m_bCaptureWasSet)
	{
		ReleaseCapture();
		Invalidate(FALSE);
		m_bCaptureWasSet = FALSE;
	}
	
	
	CWnd::OnLButtonUp(nFlags, point);
}
Ejemplo n.º 20
0
MenuVendor::MenuVendor(StatBlock *_stats)
	: Menu()
	, stats(_stats)
	, closeButton(new WidgetButton("images/menus/buttons/button_x.png"))
	, tabControl(new WidgetTabControl())
	, slots_cols(1)
	, slots_rows(1)
	, activetab(VENDOR_BUY)
	, color_normal(font->getColor("menu_normal"))
	, npc(NULL)
	, buyback_stock() {
	setBackground("images/menus/vendor.png");

	tabControl->setTabTitle(VENDOR_BUY, msg->get("Inventory"));
	tabControl->setTabTitle(VENDOR_SELL, msg->get("Buyback"));

	// Load config settings
	FileParser infile;
	// @CLASS MenuVendor|Description of menus/vendor.txt
	if(infile.open("menus/vendor.txt")) {
		while(infile.next()) {
			if (parseMenuKey(infile.key, infile.val))
				continue;

			// @ATTR close|x (integer), y (integer)|Position of the close button.
			if(infile.key == "close") {
				Point pos = toPoint(infile.val);
				closeButton->setBasePos(pos.x, pos.y);
			}
			// @ATTR slots_area|x (integer), y (integer)|Position of the top-left slot.
			else if(infile.key == "slots_area") {
				slots_area.x = popFirstInt(infile.val);
				slots_area.y = popFirstInt(infile.val);
			}
			// @ATTR vendor_cols|integer|The number of columns in the grid of slots.
			else if (infile.key == "vendor_cols") {
				slots_cols = std::max(1, toInt(infile.val));
			}
			// @ATTR vendor_rows|integer|The number of rows in the grid of slots.
			else if (infile.key == "vendor_rows") {
				slots_rows = std::max(1, toInt(infile.val));
			}
			// @ATTR label_title|label|The position of the text that displays the NPC's name.
			else if (infile.key == "label_title") {
				title =  eatLabelInfo(infile.val);
			}
			else {
				infile.error("MenuVendor: '%s' is not a valid key.", infile.key.c_str());
			}
		}
		infile.close();
	}

	VENDOR_SLOTS = slots_cols * slots_rows;
	slots_area.w = slots_cols*ICON_SIZE;
	slots_area.h = slots_rows*ICON_SIZE;

	stock[VENDOR_BUY].init(VENDOR_SLOTS, slots_area, ICON_SIZE, slots_cols);
	stock[VENDOR_SELL].init(VENDOR_SLOTS, slots_area, ICON_SIZE, slots_cols);
	buyback_stock.init(NPC_VENDOR_MAX_STOCK);

	for (unsigned i = 0; i < VENDOR_SLOTS; i++) {
		tablist.add(stock[VENDOR_BUY].slots[i]);
	}
	for (unsigned i = 0; i < VENDOR_SLOTS; i++) {
		tablist.add(stock[VENDOR_SELL].slots[i]);
	}

	align();
}
Ejemplo n.º 21
0
wxSize JSONElement::toSize() const
{
    wxPoint pt = toPoint();
    return wxSize(pt.x, pt.y);
}
Ejemplo n.º 22
0
LayoutState::LayoutState(std::unique_ptr<LayoutState> next, RenderBox* renderer, const LayoutSize& offset, LayoutUnit pageLogicalHeight, bool pageLogicalHeightChanged, ColumnInfo* columnInfo)
    : m_columnInfo(columnInfo)
    , m_lineGrid(0)
    , m_next(std::move(next))
#if ENABLE(CSS_SHAPES)
    , m_shapeInsideInfo(0)
#endif
#ifndef NDEBUG
    , m_renderer(renderer)
#endif
{
    ASSERT(m_next);

    bool fixed = renderer->isOutOfFlowPositioned() && renderer->style().position() == FixedPosition;
    if (fixed) {
        // FIXME: This doesn't work correctly with transforms.
        FloatPoint fixedOffset = renderer->view().localToAbsolute(FloatPoint(), IsFixed);
        m_paintOffset = LayoutSize(fixedOffset.x(), fixedOffset.y()) + offset;
    } else
        m_paintOffset = m_next->m_paintOffset + offset;

    if (renderer->isOutOfFlowPositioned() && !fixed) {
        if (RenderElement* container = renderer->container()) {
            if (container->isInFlowPositioned() && container->isRenderInline())
                m_paintOffset += toRenderInline(container)->offsetForInFlowPositionedInline(renderer);
        }
    }

    m_layoutOffset = m_paintOffset;

    if (renderer->isInFlowPositioned() && renderer->hasLayer())
        m_paintOffset += renderer->layer()->offsetForInFlowPosition();

    m_clipped = !fixed && m_next->m_clipped;
    if (m_clipped)
        m_clipRect = m_next->m_clipRect;

    if (renderer->hasOverflowClip()) {
        LayoutRect clipRect(toPoint(m_paintOffset) + renderer->view().layoutDelta(), renderer->cachedSizeForOverflowClip());
        if (m_clipped)
            m_clipRect.intersect(clipRect);
        else {
            m_clipRect = clipRect;
            m_clipped = true;
        }

        m_paintOffset -= renderer->scrolledContentOffset();
    }

    // If we establish a new page height, then cache the offset to the top of the first page.
    // We can compare this later on to figure out what part of the page we're actually on,
    if (pageLogicalHeight || m_columnInfo || renderer->isRenderFlowThread()) {
        m_pageLogicalHeight = pageLogicalHeight;
        bool isFlipped = renderer->style().isFlippedBlocksWritingMode();
        m_pageOffset = LayoutSize(m_layoutOffset.width() + (!isFlipped ? renderer->borderLeft() + renderer->paddingLeft() : renderer->borderRight() + renderer->paddingRight()),
                               m_layoutOffset.height() + (!isFlipped ? renderer->borderTop() + renderer->paddingTop() : renderer->borderBottom() + renderer->paddingBottom()));
        m_pageLogicalHeightChanged = pageLogicalHeightChanged;
    } else {
        // If we don't establish a new page height, then propagate the old page height and offset down.
        m_pageLogicalHeight = m_next->m_pageLogicalHeight;
        m_pageLogicalHeightChanged = m_next->m_pageLogicalHeightChanged;
        m_pageOffset = m_next->m_pageOffset;
        
        // Disable pagination for objects we don't support. For now this includes overflow:scroll/auto, inline blocks and
        // writing mode roots.
        if (renderer->isUnsplittableForPagination())
            m_pageLogicalHeight = 0;
    }
    
    // Propagate line grid information.
    propagateLineGridInfo(renderer);

    if (!m_columnInfo)
        m_columnInfo = m_next->m_columnInfo;

#if ENABLE(CSS_SHAPES)
    if (renderer->isRenderBlock()) {
        const RenderBlock* renderBlock = toRenderBlock(renderer);
        m_shapeInsideInfo = renderBlock->shapeInsideInfo();
        if (!m_shapeInsideInfo && m_next->m_shapeInsideInfo && renderBlock->allowsShapeInsideInfoSharing())
            m_shapeInsideInfo = m_next->m_shapeInsideInfo;
    }
#endif

    m_layoutDelta = m_next->m_layoutDelta;
#if !ASSERT_DISABLED && ENABLE(SATURATED_LAYOUT_ARITHMETIC)
    m_layoutDeltaXSaturated = m_next->m_layoutDeltaXSaturated;
    m_layoutDeltaYSaturated = m_next->m_layoutDeltaYSaturated;
#endif
    
    m_isPaginated = m_pageLogicalHeight || m_columnInfo || renderer->isRenderFlowThread();

    if (lineGrid() && renderer->hasColumns() && renderer->style().hasInlineColumnAxis())
        computeLineGridPaginationOrigin(renderer);

    // If we have a new grid to track, then add it to our set.
    if (renderer->style().lineGrid() != RenderStyle::initialLineGrid() && renderer->isRenderBlockFlow())
        establishLineGrid(toRenderBlockFlow(renderer));

    // FIXME: <http://bugs.webkit.org/show_bug.cgi?id=13443> Apply control clip if present.
}
Ejemplo n.º 23
0
LayoutState::LayoutState(LayoutState* prev, RenderBox* renderer, const IntSize& offset, int pageLogicalHeight, bool pageLogicalHeightChanged, ColumnInfo* columnInfo)
    : m_columnInfo(columnInfo)
    , m_next(prev)
#ifndef NDEBUG
    , m_renderer(renderer)
#endif
{
    ASSERT(m_next);

    bool fixed = renderer->isPositioned() && renderer->style()->position() == FixedPosition;
    if (fixed) {
        // FIXME: This doesn't work correctly with transforms.
        FloatPoint fixedOffset = renderer->view()->localToAbsolute(FloatPoint(), true);
        m_paintOffset = IntSize(fixedOffset.x(), fixedOffset.y()) + offset;
    } else
        m_paintOffset = prev->m_paintOffset + offset;

    if (renderer->isPositioned() && !fixed) {
        if (RenderObject* container = renderer->container()) {
            if (container->isRelPositioned() && container->isRenderInline())
                m_paintOffset += toRenderInline(container)->relativePositionedInlineOffset(renderer);
        }
    }

    m_layoutOffset = m_paintOffset;

    if (renderer->isRelPositioned() && renderer->hasLayer())
        m_paintOffset += renderer->layer()->relativePositionOffset();

    m_clipped = !fixed && prev->m_clipped;
    if (m_clipped)
        m_clipRect = prev->m_clipRect;

    if (renderer->hasOverflowClip()) {
        RenderLayer* layer = renderer->layer();
        IntRect clipRect(toPoint(m_paintOffset) + renderer->view()->layoutDelta(), layer->size());
        if (m_clipped)
            m_clipRect.intersect(clipRect);
        else {
            m_clipRect = clipRect;
            m_clipped = true;
        }

        m_paintOffset -= layer->scrolledContentOffset();
    }

    // If we establish a new page height, then cache the offset to the top of the first page.
    // We can compare this later on to figure out what part of the page we're actually on,
    if (pageLogicalHeight || m_columnInfo) {
        m_pageLogicalHeight = pageLogicalHeight;
        m_pageOffset = IntSize(m_layoutOffset.width() + renderer->borderLeft() + renderer->paddingLeft(),
                               m_layoutOffset.height() + renderer->borderTop() + renderer->paddingTop());
        m_pageLogicalHeightChanged = pageLogicalHeightChanged;
    } else {
        // If we don't establish a new page height, then propagate the old page height and offset down.
        m_pageLogicalHeight = m_next->m_pageLogicalHeight;
        m_pageLogicalHeightChanged = m_next->m_pageLogicalHeightChanged;
        m_pageOffset = m_next->m_pageOffset;
        
        // Disable pagination for objects we don't support.  For now this includes overflow:scroll/auto and inline blocks.
        if (renderer->isReplaced() || renderer->scrollsOverflow())
            m_pageLogicalHeight = 0;
    }
    
    if (!m_columnInfo)
        m_columnInfo = m_next->m_columnInfo;

    m_layoutDelta = m_next->m_layoutDelta;
    
    // FIXME: <http://bugs.webkit.org/show_bug.cgi?id=13443> Apply control clip if present.
}
Ejemplo n.º 24
0
int Editor::replace(int ibegin, int iend, WideString cstr, HistoryItem* mod, bool glue)
{
  if (running || settings->mode)
    return iend;
  wchar_t const* str = cstr.c_str();
  if (ibegin > iend)
  {
    int tmp = ibegin;
    ibegin = iend;
    iend = tmp;
  }
  POINT begin = toPoint(ibegin);
  POINT end = toPoint(iend);
  POINT oldEnd = end;

  if (mod)
  {
    mod->begin = ibegin;
    mod->end = ibegin + getlength(str);
    mod->text = substring(ibegin, iend);
  }
  else
  {
    HistoryItem h;
    h.begin = ibegin;
    h.end = ibegin + getlength(str);
    h.text = substring(ibegin, iend);
    h.glue = glue;

    bool push = true;
    if (historyPos < history.length())
      history.resize(historyPos);
    else if (historyPos > 0 && h.text.empty() && h.end == h.begin + 1 && !h.glue)
    {
      HistoryItem& p = history[historyPos - 1];
      if (p.text.empty() && h.begin == p.end)
      {
        push = false;
        p.end = h.end;
      }
    }
    if (push)
    {
      if (history.length() >= 256)
      {
        for (int i = 1; i < history.length(); i++)
          history[i - 1] = history[i];
        history[history.length() - 1] = h;
        if (origHistory >= 0)
          origHistory--;
      }
      else
        history.push(h);
    }
    historyPos = history.length();
    if (historyPos < origHistory)
      origHistory = -1;
  }

  if (begin.y == end.y)
  {
    Line ln = lines[begin.y];
    lines.insert(begin.y + 1, ln);
    end.y = begin.y + 1;
  }
  lines[begin.y].text.resize(begin.x);
  int curLine = begin.y;
  int curPos = 0;
  while (str[curPos])
  {
    if (str[curPos] == '\r' || str[curPos] == '\n')
    {
      if (curLine == begin.y)
        lines[curLine].text.append(str, curPos);
      else if (curLine < end.y)
        lines[curLine].text = WideString(str, curPos);
      else
      {
        Line& ln = lines.insert(curLine);
        ln.text = WideString(str, curPos);
        end.y++;
      }
      untabify(lines[curLine].text);
      if ((str[curPos + 1] == '\r' || str[curPos + 1] == '\n') && str[curPos] != str[curPos + 1])
        curPos++;
      str = str + curPos + 1;
      curPos = 0;
      curLine++;
    }
    else
      curPos++;
  }
  if (curLine < end.y)
  {
    if (curLine == begin.y)
      lines[curLine].text += str;
    else
      lines[curLine].text = str;
    untabify(lines[curLine].text);
    int ex = lines[curLine].text.length();
    lines[curLine].text += lines[end.y].text.substring(end.x);
    if (lines[end.y].breakpoint > 0)
      lines[curLine].breakpoint = 1;
    lines.remove(curLine + 1, end.y - curLine);
    end.y = curLine;
    end.x = ex;
  }
  else
  {
    lines[end.y].text.replace(0, end.x, str);
    end.x = wcslen(str);
    untabify(lines[end.y].text);
  }

  caret = selStart = fromPoint(end);
  updateCtx(begin.y, end.y);
  updateExtent();
  updateCaret();

  getParent()->notify(EN_MODIFIED, (uint32) this, 0);

  return caret;
}
Ejemplo n.º 25
0
MenuTalker::MenuTalker(MenuManager *_menu)
    : Menu()
    , menu(_menu)
    , portrait(NULL)
    , dialog_node(0)
    , event_cursor(0)
    , font_who("font_regular")
    , font_dialog("font_regular")
    , color_normal(font->getColor("menu_normal"))
    , npc(NULL)
    , advanceButton(new WidgetButton("images/menus/buttons/right.png"))
    , closeButton(new WidgetButton("images/menus/buttons/button_x.png")) {

    setBackground("images/menus/dialog_box.png");

    // Load config settings
    FileParser infile;
    // @CLASS MenuTalker|Description of menus/talker.txt
    if(infile.open("menus/talker.txt")) {
        while(infile.next()) {
            if (parseMenuKey(infile.key, infile.val))
                continue;

            // @ATTR close|x (integer), y (integer)|Position of the close button.
            if(infile.key == "close") {
                Point pos = toPoint(infile.val);
                closeButton->setBasePos(pos.x, pos.y);
            }
            // @ATTR advance|x (integer), y (integer)|Position of the button to advance dialog.
            else if(infile.key == "advance") {
                Point pos = toPoint(infile.val);
                advanceButton->setBasePos(pos.x, pos.y);
            }
            // @ATTR dialogbox|x (integer), y (integer), w (integer), h (integer)|Position and dimensions of the text box graphics.
            else if (infile.key == "dialogbox") dialog_pos = toRect(infile.val);
            // @ATTR dialogtext|x (integer), y (integer), w (integer), h (integer)|Rectangle where the dialog text is placed.
            else if (infile.key == "dialogtext") text_pos = toRect(infile.val);
            // @ATTR text_offset|x (integer), y (integer)|Margins for the left/right and top/bottom of the dialog text.
            else if (infile.key == "text_offset") text_offset = toPoint(infile.val);
            // @ATTR portrait_he|x (integer), y (integer), w (integer), h (integer)|Position and dimensions of the NPC portrait graphics.
            else if (infile.key == "portrait_he") portrait_he = toRect(infile.val);
            // @ATTR portrait_you|x (integer), y (integer), w (integer), h (integer)|Position and dimensions of the player's portrait graphics.
            else if (infile.key == "portrait_you") portrait_you = toRect(infile.val);
            // @ATTR font_who|string|Font style to use for the name of the currently talking person.
            else if (infile.key == "font_who") font_who = infile.val;
            // @ATTR font_dialog|string|Font style to use for the dialog text.
            else if (infile.key == "font_dialog") font_dialog = infile.val;

            else infile.error("MenuTalker: '%s' is not a valid key.", infile.key.c_str());
        }
        infile.close();
    }

    label_name = new WidgetLabel();
    label_name->setBasePos(text_pos.x + text_offset.x, text_pos.y + text_offset.y);

    textbox = new WidgetScrollBox(text_pos.w, text_pos.h-(text_offset.y*2));
    textbox->setBasePos(text_pos.x, text_pos.y + text_offset.y);

    tablist.add(advanceButton);
    tablist.add(closeButton);
    tablist.add(textbox);

    align();
}
QPointF FixedRatioTransform::dataToScene(QPointF dataPoint) const
{
	return m_origin + toPoint(dataToScene(toSize(dataPoint)));
}
Ejemplo n.º 27
0
GameStateLoad::GameStateLoad() : GameState()
	, background(NULL)
	, selection(NULL)
	, portrait_border(NULL)
	, portrait(NULL)
	, loading_requested(false)
	, loading(false)
	, loaded(false)
	, delete_items(true)
	, selected_slot(-1)
	, visible_slots(0)
	, scroll_offset(0)
	, has_scroll_bar(false)
	, game_slot_max(4)
	, text_trim_boundary(0) {

	if (items == NULL)
		items = new ItemManager();

	label_loading = new WidgetLabel();

	// Confirmation box to confirm deleting
	confirm = new MenuConfirm(msg->get("Delete Save"), msg->get("Delete this save?"));
	button_exit = new WidgetButton();
	button_exit->label = msg->get("Exit to Title");

	button_new = new WidgetButton();
	button_new->label = msg->get("New Game");
	button_new->enabled = true;

	button_load = new WidgetButton();
	button_load->label = msg->get("Choose a Slot");
	button_load->enabled = false;

	button_delete = new WidgetButton();
	button_delete->label = msg->get("Delete Save");
	button_delete->enabled = false;

	scrollbar = new WidgetScrollBar();

	// Set up tab list
	tablist = TabList(HORIZONTAL);
	tablist.add(button_exit);
	tablist.add(button_new);

	// Read positions from config file
	FileParser infile;

	// @CLASS GameStateLoad|Description of menus/gameload.txt
	if (infile.open("menus/gameload.txt")) {
		while (infile.next()) {
			// @ATTR button_new|int, int, alignment : X, Y, Alignment|Position of the "New Game" button.
			if (infile.key == "button_new") {
				int x = popFirstInt(infile.val);
				int y = popFirstInt(infile.val);
				ALIGNMENT a = parse_alignment(popFirstString(infile.val));
				button_new->setBasePos(x, y, a);
			}
			// @ATTR button_load|int, int, alignment : X, Y, Alignment|Position of the "Load Game" button.
			else if (infile.key == "button_load") {
				int x = popFirstInt(infile.val);
				int y = popFirstInt(infile.val);
				ALIGNMENT a = parse_alignment(popFirstString(infile.val));
				button_load->setBasePos(x, y, a);
			}
			// @ATTR button_delete|int, int, alignment : X, Y, Alignment|Position of the "Delete Save" button.
			else if (infile.key == "button_delete") {
				int x = popFirstInt(infile.val);
				int y = popFirstInt(infile.val);
				ALIGNMENT a = parse_alignment(popFirstString(infile.val));
				button_delete->setBasePos(x, y, a);
			}
			// @ATTR button_exit|int, int, alignment : X, Y, Alignment|Position of the "Exit to Title" button.
			else if (infile.key == "button_exit") {
				int x = popFirstInt(infile.val);
				int y = popFirstInt(infile.val);
				ALIGNMENT a = parse_alignment(popFirstString(infile.val));
				button_exit->setBasePos(x, y, a);
			}
			// @ATTR portrait|rectangle|Position and dimensions of the portrait image.
			else if (infile.key == "portrait") {
				portrait_dest = toRect(infile.val);
			}
			// @ATTR gameslot|rectangle|Position and dimensions of the first game slot.
			else if (infile.key == "gameslot") {
				gameslot_pos = toRect(infile.val);
			}
			// @ATTR name|label|The label for the hero's name. Position is relative to game slot position.
			else if (infile.key == "name") {
				name_pos = eatLabelInfo(infile.val);
			}
			// @ATTR level|label|The label for the hero's level. Position is relative to game slot position.
			else if (infile.key == "level") {
				level_pos = eatLabelInfo(infile.val);
			}
			// @ATTR class|label|The label for the hero's class. Position is relative to game slot position.
			else if (infile.key == "class") {
				class_pos = eatLabelInfo(infile.val);
			}
			// @ATTR map|label|The label for the hero's current location. Position is relative to game slot position.
			else if (infile.key == "map") {
				map_pos = eatLabelInfo(infile.val);
			}
			// @ATTR slot_number|label|The label for the save slot index. Position is relative to game slot position.
			else if (infile.key == "slot_number") {
				slot_number_pos = eatLabelInfo(infile.val);
			}
			// @ATTR loading_label|label|The label for the "Entering game world..."/"Loading saved game..." text.
			else if (infile.key == "loading_label") {
				loading_pos = eatLabelInfo(infile.val);
			}
			// @ATTR sprite|point|Position for the avatar preview image in each slot
			else if (infile.key == "sprite") {
				sprites_pos = toPoint(infile.val);
			}
			// @ATTR visible_slots|int|The maximum numbers of visible save slots.
			else if (infile.key == "visible_slots") {
				game_slot_max = toInt(infile.val);

				// can't have less than 1 game slot visible
				game_slot_max = std::max(game_slot_max, 1);
			}
			// @ATTR text_trim_boundary|int|The position of the right-side boundary where text will be shortened with an ellipsis. Position is relative to game slot position.
			else if (infile.key == "text_trim_boundary") {
				text_trim_boundary = toInt(infile.val);
			}
			else {
				infile.error("GameStateLoad: '%s' is not a valid key.", infile.key.c_str());
			}
		}
		infile.close();
	}

	// prevent text from overflowing on the right edge of game slots
	if (text_trim_boundary == 0 || text_trim_boundary > gameslot_pos.w)
		text_trim_boundary = gameslot_pos.w;

	button_new->refresh();
	button_load->refresh();
	button_delete->refresh();

	loadGraphics();
	readGameSlots();

	color_normal = font->getColor("menu_normal");

	refreshWidgets();
	updateButtons();

	// if we specified a slot to load at launch, load it now
	if (!LOAD_SLOT.empty()) {
		size_t load_slot_id = toInt(LOAD_SLOT) - 1;
		LOAD_SLOT.clear();

		if (load_slot_id < game_slots.size()) {
			setSelectedSlot(static_cast<int>(load_slot_id));
			loading_requested = true;
		}
	}

	render_device->setBackgroundColor(Color(0,0,0,0));
}
QPointF FixedRatioTransform::sceneToData(QPointF scenePoint) const
{
	return toPoint(sceneToData(toSize(scenePoint - m_origin)));
}
Ejemplo n.º 29
0
MenuStash::MenuStash(StatBlock *_stats)
	: Menu()
	, stats(_stats)
	, closeButton(new WidgetButton("images/menus/buttons/button_x.png"))
	, color_normal(font->getColor("menu_normal"))
	, stock()
	, updated(false)

{

	setBackground("images/menus/stash.png");

	slots_cols = 8; // default if menus/stash.txt::stash_cols not set
	slots_rows = 8; // default if menus/stash.txt::slots_rows not set

	// Load config settings
	FileParser infile;
	// @CLASS MenuStash|Description of menus/stash.txt
	if (infile.open("menus/stash.txt")) {
		while(infile.next()) {
			if (parseMenuKey(infile.key, infile.val))
				continue;

			// @ATTR close|x (integer), y (integer)|Position of the close button.
			if (infile.key == "close") {
				Point pos = toPoint(infile.val);
				closeButton->setBasePos(pos.x, pos.y);
			}
			// @ATTR slots_area|x (integer), y (integer)|Position of the top-left slot.
			else if (infile.key == "slots_area") {
				slots_area.x = popFirstInt(infile.val);
				slots_area.y = popFirstInt(infile.val);
			}
			// @ATTR stash_cols|integer|The number of columns for the grid of slots.
			else if (infile.key == "stash_cols") {
				slots_cols = std::max(1, toInt(infile.val));
			}
			// @ATTR stash_rows|integer|The number of rows for the grid of slots.
			else if (infile.key == "stash_rows") {
				slots_rows = std::max(1, toInt(infile.val));
			}
			// @ATTR label_title|label|Position of the "Stash" label.
			else if (infile.key == "label_title") {
				title =  eatLabelInfo(infile.val);
			}
			// @ATTR currency|label|Position of the label displaying the amount of currency stored in the stash.
			else if (infile.key == "currency") {
				currency =  eatLabelInfo(infile.val);
			}
			else {
				infile.error("MenuStash: '%s' is not a valid key.", infile.key.c_str());
			}
		}
		infile.close();
	}

	STASH_SLOTS = slots_cols * slots_rows;
	slots_area.w = slots_cols*ICON_SIZE;
	slots_area.h = slots_rows*ICON_SIZE;

	stock.init( STASH_SLOTS, slots_area, ICON_SIZE, slots_cols);
	for (int i = 0; i < STASH_SLOTS; i++) {
		tablist.add(stock.slots[i]);
	}

	align();
}
Ejemplo n.º 30
0
void MenuPowers::loadPower(FileParser &infile) {
	// @ATTR power.id|int|A power id from powers/powers.txt for this slot.
	if (infile.key == "id") {
		int id = popFirstInt(infile.val);
		if (id > 0) {
			skip_section = false;
			power_cell.back().id = id;
		}
		else {
			infile.error("MenuPowers: Power index out of bounds 1-%d, skipping power.", INT_MAX);
		}
		return;
	}

	if (power_cell.back().id <= 0) {
		skip_section = true;
		power_cell.pop_back();
		slots.pop_back();
		upgradeButtons.pop_back();
		logError("MenuPowers: There is a power without a valid id as the first attribute. IDs must be the first attribute in the power menu definition.");
	}

	if (skip_section)
		return;

	// @ATTR power.tab|int|Tab index to place this power on, starting from 0.
	if (infile.key == "tab") power_cell.back().tab = toInt(infile.val);
	// @ATTR power.position|point|Position of this power icon; relative to MenuPowers "pos".
	else if (infile.key == "position") power_cell.back().pos = toPoint(infile.val);

	// @ATTR power.requires_primary|predefined_string, int : Primary stat name, Required value|Power requires this primary stat to be at least the specificed value.
	else if (infile.key == "requires_primary") {
		std::string prim_stat = popFirstString(infile.val);
		size_t prim_stat_index = getPrimaryStatIndex(prim_stat);

		if (prim_stat_index != PRIMARY_STATS.size()) {
			power_cell.back().requires_primary[prim_stat_index] = toInt(infile.val);
		}
		else {
			infile.error("MenuPowers: '%s' is not a valid primary stat.", prim_stat.c_str());
		}
	}
	// @ATTR power.requires_point|bool|Power requires a power point to unlock.
	else if (infile.key == "requires_point") power_cell.back().requires_point = toBool(infile.val);
	// @ATTR power.requires_level|int|Power requires at least this level for the hero.
	else if (infile.key == "requires_level") power_cell.back().requires_level = toInt(infile.val);
	// @ATTR power.requires_power|power_id|Power requires another power id.
	else if (infile.key == "requires_power") power_cell.back().requires_power.push_back(toInt(infile.val));

	// @ATTR power.visible_requires_status|repeatable(string)|Hide the power if we don't have this campaign status.
	else if (infile.key == "visible_requires_status") power_cell.back().visible_requires_status.push_back(infile.val);
	// @ATTR power.visible_requires_not_status|repeatable(string)|Hide the power if we have this campaign status.
	else if (infile.key == "visible_requires_not_status") power_cell.back().visible_requires_not.push_back(infile.val);

	// @ATTR power.upgrades|list(power_id)|A list of upgrade power ids that this power slot can upgrade to. Each of these powers should have a matching upgrade section.
	else if (infile.key == "upgrades") {
		if (power_cell.back().upgrades.empty()) {
			upgradeButtons.back() = new WidgetButton("images/menus/buttons/button_plus.png");
		}

		std::string repeat_val = popFirstString(infile.val);
		while (repeat_val != "") {
			power_cell.back().upgrades.push_back(toInt(repeat_val));
			repeat_val = popFirstString(infile.val);
		}

		if (!power_cell.back().upgrades.empty())
			power_cell.back().upgrade_level = 1;
	}

	else infile.error("MenuPowers: '%s' is not a valid key.", infile.key.c_str());
}