Exemplo n.º 1
0
		///<summary>
		///Gets the outer points of this Poly and resets+modifies OR creates rectReturn boundary
		///</summary>
		public bool GetBounds(ref IRect rectReturn) {
			bool bGood=false;
			if (rectReturn==null) rectReturn=new IRect();
			int xMax=int.MinValue;
			int yMax=int.MinValue;
			rectReturn.Y=int.MaxValue;
			rectReturn.X=int.MaxValue;
			try {
				if (iUsed>0) {
					for (int iNow=0; iNow<iUsed; iNow++) {
						if (parr[iNow].X>xMax) xMax=parr[iNow].X;
						if (parr[iNow].Y>yMax) yMax=parr[iNow].Y;
						if (parr[iNow].X<rectReturn.X) rectReturn.X=parr[iNow].X;
						if (parr[iNow].Y<rectReturn.Y) rectReturn.Y=parr[iNow].Y;
					}
					bGood=true;
					rectReturn.Width=(xMax-rectReturn.X)+1;
					rectReturn.Height=(yMax-rectReturn.Y)+1;
				}
			}
			catch (Exception e) {
				RReporting.ShowExn(e,"Poly GetBounds(out IRect)");
			}
			return bGood;
		}//end GetBounds(IRect)
Exemplo n.º 2
0
		public bool RenderAll(GBuffer gbDest, IRect rectDest) {//, DPoint pOrigin, double rScale, double rSetSeed) {
			bool bGood=false;
			try {
				//int xDest=rectDest.Left;
				//int yDest=rectDest.Top;
				pOrigin.Set((double)xCenterAtPixel,(double)yCenterAtPixel);
				//double rScale=rPixelsPerUnit;//rPixelsPerUnit is formerly rScale
				
				int xEnder=rectDest.X+rectDest.Width;
				int yEnder=rectDest.Y+rectDest.Height;
				double rUnitsPerPixel=1.0/rPixelsPerUnit;
				double xSrcStart=-(pOrigin.X*rUnitsPerPixel);
				double xSrc;
				double rSpeed;
				double ySrc=-(pOrigin.Y*rUnitsPerPixel);
				for (int yDest=rectDest.Y; yDest<yEnder; yDest++) {
					xSrc=xSrcStart;
					for (int xDest=rectDest.X; xDest<xEnder; xDest++) {
						//rSpeed=;
						//this.SetPixelHSVA(xDest,yDest,RMath.SafeAngle360(RMath.THETAOFXY_RAD(xSrc,ySrc))/360.0f,1.0,1.0,1.0);
						double rFractalness=(double)(ResultMandelbrot(xSrc,ySrc,(double)rSeed)%256)/255.0; //RMath.SafeAngle360(ResultMandelbrot(xSrc,ySrc,(double)rSeed))/360.0;
						gbDest.SetPixelHsva(xDest,yDest,rFractalness,1.0,rFractalness,1.0);
						xSrc+=rUnitsPerPixel;
					}
					ySrc+=rUnitsPerPixel;
				}
				bGood=true;
			}
			catch (Exception exn) {	
				bGood=false;
				RReporting.ShowExn(exn,"Fractal RenderAll");
			}
			if (bGood) iFramesRendered++;
			return bGood;
		}//end RenderAll
Exemplo n.º 3
0
		public IRect Copy() {
			IRect rectReturn=new IRect(this.X,this.Y,this.Width,this.Height);
			//rectReturn.X=this.X;
			//rectReturn.Y=this.Y;
			//rectReturn.Width=this.Width;
			//rectReturn.Height=this.Height;
			return rectReturn;
		}
Exemplo n.º 4
0
		public void CopyTo(ref IRect rectNow) {
			if (rectNow==null) rectNow=new IRect(Left,Top,Right-Left,Bottom-Top);
			else {
				rectNow.X=Left;
				rectNow.Y=Top;
				rectNow.Width=Right-Left;
				rectNow.Height=Bottom-Top;
			}
		}
Exemplo n.º 5
0
        public bool TypeHTML(ref RImage riDest, ref IPoint ipAt, IRect irectReturn, string sText, bool bVisible)
        {
            int  iNextTag;
            int  iLength;
            bool bGood = true;

            try {
                //TODO: finish TypeHTML
            }
            catch (Exception exn) {
                RReporting.ShowExn(exn, "", "TypeHTML(...,\"" + sText + "\",...)");
                bGood = false;
            }
            return(bGood);
        }
Exemplo n.º 6
0
		public void From(IRect rectFrom, bool bToInclusiveZone) {
			try {
				Left=rectFrom.X;
				Top=rectFrom.Y;
				Right=rectFrom.X+rectFrom.Width; //i.e. Width 1 makes exclusive rect of 1 width but inclusive rect of 2 width (fixed below)
				Bottom=rectFrom.Y+rectFrom.Height;
				if (bToInclusiveZone) {
					if (rectFrom.Height>0) Bottom-=1;
					else RReporting.ShowErr("Source rect height was "+rectFrom.Height.ToString()+" while setting IZone");
					if (rectFrom.Width>0) Right-=1;
					else RReporting.ShowErr("Source rect width was "+rectFrom.Width.ToString()+" while setting IZone");
				}
			}
			catch (Exception e) {
				RReporting.ShowExn(e,"IZone From(IRect)");
			}
		}
Exemplo n.º 7
0
        public bool NeedsToBreakBeforeWordBreaker(string sText, int iCursor, int xPixel, IRect rectDest, int iGlyphType)
        {
            bool bReturn = false;

            try {
                if (rectDest != null)
                {
                    if (sText != null && iCursor >= 0 && iCursor < sText.Length)
                    {
                        int zone_Right = rectDest.X + rectDest.Width;
                        while (!RString.IsWordBreaker(sText[iCursor]))                           //while (!RString.IsSpacing(sText[iCursor])) {
                        {
                            xPixel += WidthOf(sText[iCursor], iGlyphType);
                            if (xPixel >= zone_Right)
                            {
                                bReturn = true;
                                break;
                            }
                            iCursor++;
                        }
                    }
                }
                else
                {
                    RReporting.ShowErr("Cannot check line breaking using null rect.", "", "NeedsToBreakBeforeWordBreaker");
                }
            }
            catch (Exception exn) {
                RReporting.ShowExn(exn, "checking for line break", String.Format("NeedsToBreakBeforeWordBreaker {{{0}{1}{2}rectDest:{3}}}",
                                                                                 RReporting.DebugStyle("sText", sText, false, true),
                                                                                 RReporting.DebugStyle("iCursor", iCursor, true),
                                                                                 RReporting.DebugStyle("xPixel", xPixel, true),
                                                                                 IRect.ToString(rectDest)));
            }
            return(bReturn);
        }
Exemplo n.º 8
0
		public IZone(IRect rectFrom) {
			From(rectFrom);
		}
Exemplo n.º 9
0
		}//end GetBounds(IRect)
		public IRect GetBounds() {
			IRect rectNow=new IRect();
			GetBounds(ref rectNow);
			return rectNow;
		}
Exemplo n.º 10
0
		public static string ToString(IRect rectX) {
			return rectX!=null?rectX.ToString():"null";
		}
Exemplo n.º 11
0
// 		public bool Render(GBuffer gbDest, IRect rectDest) {
// 			bool bGood=true;
// 			IRect rectShrinking=gbDest.ToRect();
// 			//int iBlobSizeNow=8;
// 			int iBlobSizeNow=1;
// 			int iShrinkBy=gbDest.Height/8;
// 			while (iBlobSizeNow>0) {
// 				if (!Render(gbDest,rectDest,rectShrinking,iBlobSizeNow)) bGood=false;
// 				if (iBlobSizeNow==1) iBlobSizeNow=0;
// 				else {
// 					iBlobSizeNow/=2;
// 					//rectShrinking.Shrink(iShrinkBy);//commented for debug only
// 				}
// 			}
// 			return bGood;
// 		}
		public bool Render(GBuffer gbDest, IRect rectDest) {//, DPoint pPixelOrigin, double rPixelsPerUnit, double rSeed) {
			bool bGood=true;
			try {
				ResetPasses();//fixes iDetailRadius etc
				//int xDest=rectDest.Left;
				//int yDest=rectDest.Top;
				int xEnder=rectDest.X+rectDest.Width;
				int yEnder=rectDest.Y+rectDest.Height;
				
				//double rInverseScale=1.0/rPixelsPerUnit;
				FRACTALREAL rUnitsPerPixel=fr1/rPixelsPerUnit;
				xSrcStart=-((FRACTALREAL)xCenterAtPixel*rUnitsPerPixel);//rInverseScale
				ySrc=-((FRACTALREAL)yCenterAtPixel*rUnitsPerPixel);//rInverseScale
				int iHalfW=gbFractal.Width/2;
				int iHalfH=gbFractal.Height/2;
				//int iBlobIncrement=gbFractal.Height/8;
				//if (iBlobIncrement<1) iBlobIncrement=1;
				FRACTALREAL rFractalness=fr0;
// 			int xBlobPrev=-1;
// 			int yBlobPrev=-1;
// 			int xBlob;
// 			int yBlob;
// 			bool bBlobStartX=false;
// 			bool bBlobStartY=false;
				xDest=rectDest.X;
				yDest=rectDest.Y;
				//int zone_Right=rectCropFractal.Right;
				//int zone_Bottom=rectCropFractal.Bottom;
				//int iBlobSize=(int)RMath.Dist((double)iHalfW,(double)iHalfH,(double)xDest,(double)yDest)/iBlobIncrement;
				//int iBlobSize=(int)(  (1.0-(RMath.Dist((double)iHalfW,(double)iHalfH,(double)xDest,(double)yDest)/(double)iHalfW)) * (double)iBlobIncrement  );
				//iBlobSize=8;//debug only
				for (yDest=rectDest.Y; yDest<yEnder; yDest++) {
					xSrc=xSrcStart;
					//yBlob=yDest/iBlobSize;
					//bBlobStartY=yBlobPrev!=yBlob;
					//yBlobPrev=yBlob;
					for (xDest=rectDest.X; xDest<xEnder; xDest++) {
						///NOTE: Hsv is NOT H<360 it is H<1.0
						//iBlobSize=(int)(  (1.0-(RMath.Dist((double)iHalfW,(double)iHalfH,(double)xDest,(double)yDest)/(double)iHalfW)) * (double)iBlobIncrement  );
						//iBlobSize=8;//debug only
						//if (iBlobSize<1) iBlobSize=1;
						//xBlob=xDest/iBlobSize;
						//bBlobStartX=xBlobPrev!=xBlob;//&&yBlobPrev!=yBlob;
						//xBlobPrev=xBlob;
						//this.SetPixelHsva(xDest,yDest,RMath.SafeAngle360(RMath.THETAOFXY_RAD(xSrc,ySrc))/360.0f,1.0,1.0,1.0);
						//double rFractalness=RMath.SafeAngle360(
						//	(double)FractalResultMandelbrot(xSrc,ySrc,rSeed) 
						//	);
						//int iFractalResult=FractalResultMandelbrot((float)xSrc,(float)ySrc);//TODO: use rSeed
						//byte byFractalResult=(byte)(iFractalResult%255);
						//double rFractalness=(double)byFractalResult/255.0;
						//float rFractalness=(float)(Fractal.FractalResultMandelbrot((float)xSrc,(float)ySrc)%255)/255.0f;
						//double rFractalness=(double)(FractalResultMandelbrot((double)xSrc,(double)ySrc)%255)/255.0;
						//if (iBlobSize==1||(bBlobStartX||bBlobStartY))
						//if (bBlobStartX||bBlobStartY)
						//rFractalness=fr_1;
						//if (xDest>rectCropFractal.X&&xDest<zone_Right&&yDest<zone_Bottom&&yDest>=rectCropFractal.Y) {
							//if (xDest%iBlobSize==0&&yDest%iBlobSize==0)
							//double rFractalness=(double)(ResultMandelbrot(xSrc,ySrc,(double)rSeed)%256)/255.0;
							rFractalness=(FRACTALREAL)(ResultMandelbrot((FRACTALREAL)xSrc,(FRACTALREAL)ySrc,rSeed)%256)/fr255;
						//}
						//if (rFractalness!=fr_1) {//bBlobStartX||bBlobStartY) {
							//if (iBlobSize>1) {
							//	try {
							//		if (xDest>=0&&yDest>=0&&xDest+iBlobSize<=gbFractal.Width&&yDest+iBlobSize<=gbFractal.Height) {
							//			GBuffer.SetBrushHsva(rFractalness,1.0,rFractalness,1.0);
							//			if (!gbFractal.DrawRectFilledSafe(xDest,yDest,iBlobSize,iBlobSize)) {
							//				RReporting.Warning("Skipped fractal blob.","{location:"+IPoint.Description(xDest,yDest)+"; size:"+IPoint.Description(iBlobSize,iBlobSize)+"}");
							//			}
							//		}
							//	}
							//	catch {RReporting.Warning("Failed to render fractal blob.","{location:"+IPoint.Description(xDest,yDest)+"}");}
							//}
							//else {
								gbFractal.SetPixelHsva(xDest,yDest,rFractalness,1.0,rFractalness,1.0);
							//}
						//}
						xSrc+=rUnitsPerPixel;
					}
					ySrc+=rUnitsPerPixel;
				}
				//GBuffer.SetBrushRgb(255,0,0);
				//gbFractal.DrawRectFilledSafe(0,0,64,64);
				//gbFractal.DrawRectFilledSafe(gbFractal.Width-64,gbFractal.Height-64,64,64);
				//if (!gbDest.DrawSmallerWithoutCropElseCancel(rectDest.X,rectDest.Y,gbFractal)) bGood=false;
				if (!gbDest.Draw(rectDest,gbFractal,rectSrcDefault)) bGood=false;
				//if (!GBuffer.Render(gbDest,rectDest,gbFractal,rectCropFractal,GBuffer.DrawModeCopyAlpha)) bGood=false;
				if (bGood) iFramesRendered++;
			}
			catch (Exception exn) {	
				RReporting.ShowExn(exn,"Fractal Render");
			}
			return bGood;
		}//end Render
Exemplo n.º 12
0
 public bool Render(ref RImage riDest, IRect rectDest, string sText, int iGlyphType)
 {
     return(Render(ref riDest, rectDest, sText, iGlyphType, LineBreakingOnlyWhenEndOfTextLine));
 }
Exemplo n.º 13
0
        public bool ReadLine(out string sLine, string sText, ref int iMoveMe, IRect rectDest, int iGlyphType)
        {
            bool HasALine   = false;
            bool bBreakable = false;
            int  iSkipper   = 0;
            int  iStartLine = iMoveMe;

            try {
                int iStart     = iMoveMe;
                int xPixel     = rectDest.X;
                int zone_Right = rectDest.Right;
                if (iMoveMe + 1 < sText.Length)
                {
                    HasALine = true;
                }
                while (iMoveMe + 1 < sText.Length)
                {
                    //string sTemp=SafeSubstring(sText,iMoveMe,Environment.NewLine.Length);
                    if (RString.CompareAt(sText, Environment.NewLine, iMoveMe))
                    {
                        bBreakable = true;
                        iSkipper   = Environment.NewLine.Length;
                        break;
                    }
                    else if (RString.CompareAt(sText, '\n', iMoveMe))
                    {
                        bBreakable = true;
                        iSkipper   = 1;
                        break;
                    }
                    else if (RString.CompareAt(sText, '\r', iMoveMe))
                    {
                        bBreakable = true;
                        iSkipper   = 1;
                        break;
                    }
                    else if (xPixel + WidthOf(sText[iMoveMe], iGlyphType) >= zone_Right)
                    {
                        int  iLastBreaker    = iMoveMe;
                        bool bVisibleBreaker = false;
                        bool bTest           = RString.PreviousWordBreakerExceptNewLine(sText, ref iLastBreaker, out bVisibleBreaker);
                        if (iLastBreaker > iStartLine)
                        {
                            if (bVisibleBreaker)
                            {
                                iSkipper = 0;                 //says not to skip any characters
                                iMoveMe  = iLastBreaker + 1;  //includes it in the substring
                            }
                            else                              //else invisible, so skip it
                            {
                                iSkipper = 1;                 //says to skip it after substring is taken
                                iMoveMe  = iLastBreaker;      //excludes it from the substring
                            }
                        }
                        else                          //else no breaker
                        {
                            iSkipper = 0;
                        }
                        //NOTE: debug non-compliance: bBreakable and break allow non-html-style forced breakage if no breaker before wrap (when "else" case above occurs)
                        bBreakable = true;                      //says to not skip to end of sText
                        break;
                    }
                    //else if (NeedsToBreakBeforeWordBreaker(sText, iMoveMe+1, xPixel, rectDest, iGlyphType) && RString.IsWordBreakerExceptNewLine(sText,iMoveMe)) {
                    //	bBreakable=true;
                    //	iSkipper=1;
                    //	bTypeableNewLine=true;
                    //	break;
                    //}
                    else
                    {
                        xPixel += WidthOf(sText[iMoveMe], iGlyphType);
                        iMoveMe++;
                    }
                }
                if (!bBreakable)
                {
                    iMoveMe = sText.Length;
                }
                sLine = RString.SafeSubstring(sText, iStart, iMoveMe - iStart);
                if (bBreakable)
                {
                    iMoveMe += iSkipper;
                }
            }
            catch (Exception exn) {
                sLine = "";
                RReporting.ShowExn(exn, "RFont ReadLine");
            }
            return(HasALine);
        }
Exemplo n.º 14
0
        }                                                                                                     //end RenderLine

        public bool Render(ref RImage riDest, IRect rectDest, string sText, int iGlyphType, int LineBreaking) //formerly typefast
        //TODO: really, this should return a rect (e.g. html-style stretching of container)
        {
            bool bGood = true;
            //IPoint ipDestNow;
            //IPoint ipDestLine;
            bool bSpacing;

            try {
                //ipDestNow=new IPoint();
                //ipDestNow.X=rectDest.X;
                //ipDestNow.Y=rectDest.Y;
                //ipDestLine.Set(ipDestNow);
                int    zone_Bottom = rectDest.Bottom;
                string sLine;
                int    iCursor     = 0;
                int    yDest       = rectDest.Y;
                int    iLineHeight = GlyphHeight(iGlyphType);
                int    iLine       = 0;
                //RImage.rpaintFore.SetRgb(0,0,0);
                //riDest.DrawRectCropped(rectDest);
                //string sDebugReadLineFile="0.debug-Typing.txt";//debug only
                //bool bDebug=!File.Exists(sDebugReadLineFile);
                CalculateSpacing(iGlyphType);
                if (LineBreaking == LineBreakingOnlyWhenEndOfTextLine)
                {
                    while (RenderLine(ref riDest, rectDest.X, yDest, sText, iGlyphType, ref iCursor, false))
                    {
                        yDest += iLineHeight;
                        if (yDest + iLineHeight >= zone_Bottom)
                        {
                            break;                                                        //+iLineHeight skips croppable chars
                        }
                        iLine++;
                    }
                }
                else if (LineBreaking == LineBreakingFast)
                {
                    while (RenderLine(ref riDest, rectDest.X, yDest, sText, iGlyphType, ref iCursor, true))
                    {
                        yDest += iLineHeight;
                        if (yDest + iLineHeight >= zone_Bottom)
                        {
                            break;                                                        //+iLineHeight skips croppable chars
                        }
                        iLine++;
                    }
                }
                else                  //assume LineBreakingSlowAccurate
                {
                    while (ReadLine(out sLine, sText, ref iCursor, rectDest, iGlyphType))
                    {
                        if (yDest < zone_Bottom)
                        {
                            TypeOnOneLine(ref riDest, rectDest.X, yDest, sLine, iGlyphType);
                        }
                        else
                        {
                            break;
                        }
                        yDest += iLineHeight;                      //+iLineHeight skips croppable chars
                        iLine++;
                    }
                }
            }
            catch (Exception exn) {
                RReporting.ShowExn(exn, "", "Render(...,\"" + RString.ElipsisIfOver(sText, 10) + "\")");
                bGood = false;
            }
            return(bGood);
        }
Exemplo n.º 15
0
		public void From(IRect rectFrom) {
			From(rectFrom,false);
		}
Exemplo n.º 16
0
 public bool TypeHTML(ref RImage riDest, ref IPoint ipAt, IRect irectReturn, string sText)
 {
     return(TypeHTML(ref riDest, ref ipAt, irectReturn, sText, true));
 }
Exemplo n.º 17
0
		public bool RenderIncrement(GBuffer gbDest, IRect rectDest) {
			bool bGood=true;
			try {
				gbFractal.SetPixelArgb(400,300, 255,255,0,0);//debug only
				if (!FinishedRenderingAll()) {
					iTickStartPrev=iTickStart;
					iTickStart=PlatformNow.TickCount;
					if (iTickStartPrev!=-1) {//&&iTickStart!=-1) {
						iTicksPerFrame=iTickStart-iTickStartPrev;
						//if (iTicksPerFrame>iMaxUsableTicksPerFrame_ElseIgnoreFrameRate) {
							//TODO: fix this: //FRACTALREAL rPerformanceScaler=(FRACTALREAL)iMaxUsableTicksPerFrame_ElseIgnoreFrameRate/(FRACTALREAL)iTicksPerFrame;
							//TODO: fix this: iMaxPPF=(int)((FRACTALREAL)iMaxPPF*rPerformanceScaler);
							if (iMaxPPF<1) iMaxPPF=1;
						//}
					}
					int iPixelRel=0;
					while (iPixelRel<iMaxPPF&&iPixelsRendered<gbFractal.iPixelsTotal) {
						//xSrc+=rPassUnitsPerChunk;
						if (xDest>=gbFractal.Width) {
							xDest=0;
							yDest+=iPassPixelsPerChunk;
							xSrc=xSrcStart;
							//ySrc+=rPassUnitsPerChunk;
						}
						xSrc=XPixelToUnitLocation(xDest);
						ySrc=YPixelToUnitLocation(yDest);
						
						if (yDest<gbFractal.Height) {
							//gbFractal.SetPixelRgb(xDest,yDest, 255,0,0);//debug only
	
							//float rFractalness=(float)(ResultMandelbrot((float)xSrc,(float)ySrc)%255)/255.0f;
							//TODO: finish this--use rSeed
							//double rFractalness=(double)(ResultMandelbrot((double)xSrc,(double)ySrc)%255)/255.0;
							
							//if (RMath.Dist(RMath.IRound(gbFractal.Width/2),RMath.IRound(gbFractal.Height/2),xDest,yDest)<iDetailRadius) {
							if (iPass==1||RMath.Dist((double)(gbFractal.Width/2.0),(double)(gbFractal.Height/2.0),(double)xDest,(double)yDest)<(double)iDetailRadius) {
								FRACTALREAL rFractalness=(FRACTALREAL)(ResultMandelbrot((FRACTALREAL)xSrc,(FRACTALREAL)ySrc)%255)/fr255;
								if (iPassPixelsPerChunk>1) {
									GBuffer.SetBrushHsva(rFractalness,1.0,rFractalness,1.0);
									gbFractal.DrawRectCroppedFilled(xDest,yDest,iPassPixelsPerChunk,iPassPixelsPerChunk);
								}
								else gbFractal.SetPixelHsva(xDest,yDest,rFractalness,1.0,rFractalness,1.0);
								//xSrc+=rPassUnitsPerChunk;
							}
							
							iPixelsRendered++;
							iPixelRel++;
						}//end if yDest<gbFractal.Height
						else break;//finished rendering frame
						xDest+=iPassPixelsPerChunk;
					}//end while iPixelRel<iMaxPPF
					
					//TODO: finish this
					if (FinishedRenderingFrame()) {
						iPass++;//must be incremented BEFORE ResetLocations (before OnSetPass)
						ResetLocations();//DOES OnStartPass
						iFramesRendered++;
					}
				}//end if !FinishedRenderingAll
				//gbFractal.SetPixelArgb(400,300, 255,0,255,0);//debug only
				if (!gbDest.Draw(rectDest,gbFractal)) {
					bGood=false;
					RReporting.Warning("Couldn't draw Fractal buffer to destination.","{gbFractal:"+GBuffer.VariableMessage(gbFractal)+"; gbDest:"+GBuffer.VariableMessage(gbDest)+"; rectDest:"+rectDest.Description()+"}");
				}
			}
			catch (Exception exn) {
				bGood=false;
				RReporting.ShowExn(exn,"Fractal RenderIncrement","rendering fractal increment");
			}
			return bGood;
		}//end RenderIncrement