Ejemplo n.º 1
0
void ZDCCanvas_X_NonWindow::CopyFrom(ZDCState& ioState, const ZPoint& inDestLocation, ZRef<ZDCCanvas> inSourceCanvas, const ZDCState& inSourceState, const ZRect& inSourceRect)
	{
	ZRef<ZDCCanvas_X> sourceCanvasX = ZRefDynamicCast<ZDCCanvas_X>(inSourceCanvas);
	ZAssertStop(kDebug_X, sourceCanvasX != nil);

	if (!fDrawable || !sourceCanvasX->Internal_GetDrawable())
		return;

	SetupLock theSetupLock(this);

	// We can (currently) only copy from one drawable to another if they're on the same display
	//	ZAssertStop(kDebug_X, fXServer == sourceCanvasX->fXServer);

	ZRect destRect = inSourceRect + (ioState.fOrigin + inDestLocation - inSourceRect.TopLeft());
	ZRect sourceRect = inSourceRect + inSourceState.fOrigin;

	ZDCRgn realClip = this->Internal_CalcClipRgn(ioState);

	fXServer->SetRegion(fGC, realClip.GetRegion());
	++fChangeCount_Clip;

	fXServer->SetFunction(fGC, GXcopy);
	++fChangeCount_Mode;

	fXServer->CopyArea(sourceCanvasX->Internal_GetDrawable(), fDrawable, fGC,
				sourceRect.Left(), sourceRect.Top(),
				sourceRect.Width(), sourceRect.Height(),
				destRect.Left(), destRect.Top());
	}
Ejemplo n.º 2
0
void ZDCCanvas_X_NonWindow::Scroll(ZDCState& ioState, const ZRect& inRect, ZCoord hDelta, ZCoord vDelta)
	{
	if (!fDrawable)
		return;
	SetupLock theSetupLock(this);

	++fChangeCount_Clip;

	ZPoint offset(hDelta, vDelta);

	// destRgn is the pixels we want and are able to draw to.
	ZDCRgn destRgn = ((ioState.fClip + ioState.fClipOrigin) & (inRect + ioState.fOrigin));

	// srcRgn is the set of pixels we're want and are able to copy from.
	ZDCRgn srcRgn = ((destRgn - offset) & (inRect + ioState.fOrigin));

	// drawnRgn is the destination pixels that will be drawn by the CopyBits call, it's the srcRgn
	// shifted back to the destination.
	ZDCRgn drawnRgn = srcRgn + offset;

	// invalidRgn is the destination pixels we wanted to draw but could not because they were
	// outside the visRgn, or were in the excludeRgn
	ZDCRgn invalidRgn = destRgn - drawnRgn;

	// And set the clip (drawnRgn)
	fXServer->SetRegion(fGC, drawnRgn.GetRegion());
	++fChangeCount_Clip;

	fXServer->SetFunction(fGC, GXcopy);
	++fChangeCount_Mode;

	ZRect drawnBounds = drawnRgn.Bounds();

	fXServer->CopyArea(fDrawable, fDrawable, fGC,
				drawnBounds.Left() - offset.h, drawnBounds.Top() - offset.v,
				drawnBounds.Width(), drawnBounds.Height(),
				drawnBounds.Left(), drawnBounds.Top());
	}
Ejemplo n.º 3
0
bool ZUITextEngine::Click(ZPoint inHitPoint, const ZEvent_Mouse& inEvent)
	{
	size_t selectStart, selectLength;
	this->GetSelection(selectStart, selectLength);
	if (selectLength != 0)
		{
		size_t cursorOffset = this->PointToOffset(this->FromHost(inHitPoint));
		if (cursorOffset >= selectStart && cursorOffset < selectStart + selectLength)
			{
			if (fHost->GetHostPane(this)->GetWindow()->WaitForMouse())
				{
				ZTuple theTuple = this->GetTuple(selectStart, selectLength);
				if (ZDragInitiator* theDragInitiator = fHost->GetHostPane(this)->GetWindow()->CreateDragInitiator())
					{
					ZDC theDC = this->GetHostDC();
					ZDCRgn hiliteRgn = theDC.GetClip() & this->GetTextRgn(selectStart, selectLength);
					theDC.SetClip(hiliteRgn);

					ZDCPixmap thePixmap;
					ZPoint hiliteRgnSize = hiliteRgn.Bounds().Size();
					if ((hiliteRgnSize.h * hiliteRgnSize.v) <= 90000)
						{
						ZDC_Off theOffDC(theDC, true);
						this->DrawRange(theOffDC, selectStart, selectLength);
						theOffDC.Sync();
						thePixmap = theOffDC.GetPixmap(theOffDC.GetClip().Bounds());
						}
					ZPoint theOffset = hiliteRgn.Bounds().TopLeft();
					hiliteRgn -= theOffset;
					theDragInitiator->DoDrag(theTuple, fHost->GetHostPane(this)->ToGlobal(inHitPoint), this->FromHost(inHitPoint) - theOffset, theDragInitiator->OutlineRgn(hiliteRgn), thePixmap, hiliteRgn, this);
					return true;
					}
				}
			}
		}
	return false;
	}
Ejemplo n.º 4
0
static bool sCheckPixel(const ZRef<ZDCCanvas>& inCanvas, ZDCState& ioState,
	ZCoord inLocationH, ZCoord inLocationV, const ZRGBColor& inSeedColor, const ZDCRgn& inMaskRgn)
	{
	if (inMaskRgn.Contains(inLocationH, inLocationV))
		{
		// We've already visited this pixel.
		return false;
		}

	if (inCanvas->GetPixel(ioState, inLocationH, inLocationV) != inSeedColor)
		{
		// This pixel is not the seed color.
		return false;
		}

	return true;
	}
Ejemplo n.º 5
0
void ZDCCanvas_X::FrameRegion(ZDCState& ioState, const ZDCRgn& inRgn)
	{
	if (!fDrawable)
		return;
	if (!ioState.fInk)
		return;
	if (ioState.fPenWidth <= 0)
		return;

	SetupLock theSetupLock(this);

	if (ZDCRgn localRgn = this->Internal_CalcClipRgn(ioState) & ((inRgn - inRgn.Inset(ioState.fPenWidth, ioState.fPenWidth)) + ioState.fOrigin))
		{
		SetupInk theSetupInk(this, ioState);
		ZRect localBounds = localRgn.Bounds();

		fXServer->SetRegion(fGC, localRgn.GetRegion());
		++fChangeCount_Clip;

		fXServer->FillRectangle(fDrawable, fGC, localBounds.left, localBounds.top, localBounds.Width(), localBounds.Height());
		}
	}
Ejemplo n.º 6
0
ZDCRgn ZDragInitiator::OutlineRgn(const ZDCRgn& iRgn)
	{
	// Provides a place to do theme-sensitive outlining of regions (2 pixels on MacOS 8.5, 1 pixel just about everywhere else)
	return iRgn - iRgn.Inset(2, 2);
	}
Ejemplo n.º 7
0
void ZDCCanvas_X::DrawPixmap(ZDCState& ioState, const ZPoint& inLocation, const ZDCPixmap& inSourcePixmap, const ZDCPixmap* inMaskPixmap)
	{
	if (!fDrawable)
		return;

	if (!inSourcePixmap)
		return;

	ZRect realSourceBounds = inSourcePixmap.Size();

	ZPoint realLocation = inLocation + ioState.fOrigin;

	if (inMaskPixmap)
		{
		if (!*inMaskPixmap)
			return;

		SetupLock theSetupLock(this);

		ZDCRgn sourceBoundsRgn = ZRect(realSourceBounds.Size());
		ZDCRgn realClip = (this->Internal_CalcClipRgn(ioState) - realLocation) & sourceBoundsRgn;
		if (realClip.IsEmpty())
			return;

		// Take a one bit copy of the mask
		Pixmap monoPixmap = fXServer->CreateBitmapFromDCPixmap(fDrawable, *inMaskPixmap, realSourceBounds, false);
		ZAssert(monoPixmap != None);

		// Paint with zeroes the area of the mask that's not part of the clip, if any
		if (ZDCRgn inverseClip = sourceBoundsRgn - realClip)
			{
			XGCValues values;
			values.graphics_exposures = 0;
			GC monoGC = fXServer->CreateGC(monoPixmap, GCGraphicsExposures, &values);
			fXServer->SetRegion(monoGC, inverseClip.GetRegion());
			fXServer->SetForeground(monoGC, 0);
			fXServer->FillRectangle(monoPixmap, monoGC, 0, 0, realSourceBounds.Width(), realSourceBounds.Height());
			fXServer->FreeGC(monoGC);
			}

		fXServer->SetFunction(fGC, GXcopy);
		++fChangeCount_Mode;
		fXServer->SetClipMask(fGC, monoPixmap);
		fXServer->SetClipOrigin(fGC, realLocation.h, realLocation.v);
		++fChangeCount_Clip;
		fXServer->DrawDCPixmap(fDrawable, fGC, realLocation, inSourcePixmap, realSourceBounds);
		fXServer->SetClipMask(fGC, None);
		fXServer->SetClipOrigin(fGC, 0, 0);
		fXServer->FreePixmap(monoPixmap);
		}
	else
		{
		SetupLock theSetupLock(this);
		SetupClip theSetupClip(this, ioState);
		if (theSetupClip.IsEmpty())
			return;
		fXServer->SetFunction(fGC, GXcopy);
		++fChangeCount_Mode;
		fXServer->DrawDCPixmap(fDrawable, fGC, realLocation, inSourcePixmap, realSourceBounds);
		}
	}