public EPoint GetPoint(EPoint inputPoint, CoordinateHook coordinateHook = CoordinateHook.Hook) { EPoint outputPoint = new EPoint(); try { switch (coordinateHook) { case CoordinateHook.Hook: outputPoint = Base.SensorToLocal(inputPoint); break; case CoordinateHook.NotHook: outputPoint = Base.LocalToSensor(inputPoint); break; } } catch (EException exc) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, exc.Message, true, true); } catch (Exception ex) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, ex.Message, true, true); } return(outputPoint); }
public MemberBitmapBase() { //m_clrKey = Color.FromArgb(255,255,255); m_pntRegPoint = new EPoint(0, 0); //m_sizeAnimateWithin = new EPoint(0,0); m_sizeTotal = new EPoint(0, 0); }
private void btnFindPattern_Click(object sender, EventArgs e) { eFindPattern.SetROIEnd(); int maxInstances = Convert.ToInt32(nudFindCount.Value); float minScore = Convert.ToSingle(nudFindScore.Value); EFindContrastMode contrastMode = (EFindContrastMode)Enum.Parse(typeof(EFindContrastMode), cboFindMode.Text, true); float angleTolerance = Convert.ToSingle(nudAngleTolerance.Value); float scaleTolerance = Convert.ToSingle(nudScaleTolerance.Value); eFindPattern.FindPattern(maxInstances, minScore, contrastMode, angleTolerance, scaleTolerance); eFindPattern.GetPattern(); EPoint world = eCalibration.Base.SensorToWorld(new EPoint(eFindPattern.Results_CenterX, eFindPattern.Results_CenterY)); eFindPattern.PatternTable.Rows.Add( eFindPattern.PatternTable.Rows.Count + 1, eFindPattern.Results_Score, world.X, world.Y, eFindPattern.Results_Angle, eFindPattern.Results_Scale); eFindPattern.ShowResult(); eFixture.SetOrigin(eFindPattern.Results_CenterX, eFindPattern.Results_CenterY, eFindPattern.Results_Angle); }
private void treeView1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { m_bStartedDragging = false; this.mouseDownLoc = new EPoint(e.X, e.Y); XmlNode xmlNode = null; try { TreeNode node = treeView1.GetNodeAt(e.X, e.Y); if (node != null) { xmlNode = (XmlNode)node.Tag; } } catch { return; } if (xmlNode == null) { return; } this.xmlNodeMouseDownOn = xmlNode; if (XmlNodeMouseDown != null) { XmlNodeMouseDown(this, xmlNode); } }
public override System.Collections.ArrayList GeneratePoints(EPoint ptStart) { //Calculate curve's control and end anchor points: //Control point is the start point + offset to control EPoint ptControl = ptStart + this._ptControl; //End point is control point + offset to anchor: EPoint ptAnchor = ptControl + this._ptAnchor; //now calculate two bezier handles for the curve (Flash uses quadratic beziers, GDI+ uses cubic). //The two handles are 2/3rds from each endpoint to the control point. EPointF diff = (ptControl - ptStart).ToEPointF(); EPointF ctrl1 = EPointF.FromLengthAndAngle(diff.Length * 2 / 3, diff.Angle) + ptStart.ToEPointF(); //EPointF ctrl1 = ptStart.ToEPointF() + diff/2f; //EPointF ctrl1 = new EPointF(ptStart.X + (1f * (ptControl.X - ptStart.X) / 2f), ptStart.Y + (1f * (ptControl.Y - ptStart.Y) / 2f)); diff = (ptControl - ptAnchor).ToEPointF(); EPointF ctrl2 = EPointF.FromLengthAndAngle(diff.Length * 2 / 3, diff.Angle) + ptAnchor.ToEPointF(); //diff = (ptAnchor-ptControl).ToEPointF(); //EPointF ctrl2 = ptControl.ToEPointF() + diff/2f; //ctrl2 = new EPointF(ptControl.X + (1f * (ptAnchor.X - ptControl.X) / 2f), ptControl.Y + (1f * (ptAnchor.Y - ptControl.Y) / 2f)); System.Collections.ArrayList pts = new System.Collections.ArrayList(); pts.Add(ptStart.ToEPointF()); pts.Add(ctrl1); pts.Add(ctrl2); pts.Add(ptAnchor.ToEPointF()); return(pts); }
public void SetPosColor(EPoint pos, Color clr) { Graphics g = Graphics.FromImage(this.m_bmp); ERectangle rct = new ERectangle(pos.X, pos.Y, 1, 1) * this.SquareSide; g.FillRectangle(new SolidBrush(clr), rct.ToRectangle()); }
public override System.Collections.ArrayList GeneratePoints(EPoint ptStart) { //Calculate curve's control and end anchor points: //Control point is the start point + offset to control EPoint ptControl = ptStart + this._ptControl; //End point is control point + offset to anchor: EPoint ptAnchor = ptControl + this._ptAnchor; //now calculate two bezier handles for the curve (Flash uses quadratic beziers, GDI+ uses cubic). //The two handles are 2/3rds from each endpoint to the control point. EPointF diff = (ptControl-ptStart).ToEPointF(); EPointF ctrl1 = EPointF.FromLengthAndAngle(diff.Length*2/3, diff.Angle) + ptStart.ToEPointF(); //EPointF ctrl1 = ptStart.ToEPointF() + diff/2f; //EPointF ctrl1 = new EPointF(ptStart.X + (1f * (ptControl.X - ptStart.X) / 2f), ptStart.Y + (1f * (ptControl.Y - ptStart.Y) / 2f)); diff = (ptControl-ptAnchor).ToEPointF(); EPointF ctrl2 = EPointF.FromLengthAndAngle(diff.Length*2/3, diff.Angle) + ptAnchor.ToEPointF(); //diff = (ptAnchor-ptControl).ToEPointF(); //EPointF ctrl2 = ptControl.ToEPointF() + diff/2f; //ctrl2 = new EPointF(ptControl.X + (1f * (ptAnchor.X - ptControl.X) / 2f), ptControl.Y + (1f * (ptAnchor.Y - ptControl.Y) / 2f)); System.Collections.ArrayList pts = new System.Collections.ArrayList(); pts.Add(ptStart.ToEPointF()); pts.Add(ctrl1); pts.Add(ctrl2); pts.Add(ptAnchor.ToEPointF()); return pts; }
public void RefreshLayout() { EPoint pntHeaderBottomRight = new EPoint(); for (int x = 0; x < this.slColumnStyles.Count; x++) { VersatileDataGridColumnStyle columnStyle = GetColumnStyle(x); EPoint pntLeftRight = this.GetColumnLeftRight(columnStyle.ColumnName); //rct.Height = this.panelHeaders.Height; //panelSubHeaders Control ctrl = this.Controls[x * 2]; //panelSubHeaders ctrl.Width = pntLeftRight.Y - pntLeftRight.X; ctrl.Left = pntLeftRight.X; // this.listView1.Columns[x].Width = pntLeftRight.Y-pntLeftRight.X; Control splitter = this.Controls[x * 2 + 1]; //panelSubHeaders splitter.Left = pntLeftRight.Y; //splitter.Height = rct.Height; pntHeaderBottomRight.X = pntLeftRight.Y; //pntHeaderBottomRight.Y = rct.Bottom; } // this.listView1.Width = pntHeaderBottomRight.X; this.Width = pntHeaderBottomRight.X; //panelSubHeaders.Width = pntHeaderBottomRight.X; //panelSubHeaders.Height = pntHeaderBottomRight.Y; }
public void GetLineWordResults(CornerLine cornerLine, ref ezLine line) { try { float result_CenterX = 0; float result_CenterY = 0; float result_Angle = 0; FindCorner[cornerLine].FindLine(ref result_CenterX, ref result_CenterY, ref result_Angle); EPoint localSensor = eFixture.GetPoint(new EPoint(result_CenterX, result_CenterY), CoordinateHook.NotHook); EPoint world = eCalibration.Fixture.GetPoint(new EPoint(localSensor.X, localSensor.Y), CoordinateHook.Hook); line = new ezLine(world.X, world.Y, result_Angle + eFixture.Angle); } catch (EException exc) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, exc.Message, true, true); } catch (Exception ex) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, ex.Message, true, true); } }
private void m_astar_SearchStarted(object sender, EPoint coordinate) { this.ClearGrid(); this.SetPosColor(this.m_astar.StartPos, this.StartColor); this.SetPosColor(this.m_astar.GoalPos, this.GoalColor); this.m_sp.Member.Bitmap = this.m_bmp; }
public void ShowPath() { m_shootingBall = (Ball)m_aComingBalls[0]; EPointF loc = m_shootingBall.Loc; double dAngle = -Math.PI * Angle / 180; float fSpeed = 1000; EPointF pntVel = EPointF.FromLengthAndAngle(fSpeed, (float)dAngle); EPoint pntGridStick = null; EPointF pntBounce; int nMaxTests = 40; //if more bounces than this is calculated, then something has gone wrong as it's outside the system // EH.Put("Start at "+loc.ToString()); while (nMaxTests-- > 0) { if (m_playArea.m_pathCalc.GetFirstStickOrBounce(ref loc, ref pntVel, out pntGridStick, out pntBounce, true) == false) { // EH.Put("Test num:"+nMaxTests.ToString() + " loc"+loc.ToString()); // EH.Put("Bounce:" + loc.ToString()+" vel:"+pntVel.ToString()); // loc = pntBounce.Copy(); } else { // if (m_spTarget!=null) // m_spTarget.Loc = m_playArea.Grid.GetGfxLocFromGridLoc(pntGridStick); break; } } }
public Rectangle GetBoundingRect(int rowIndex, int colIndex) { Rectangle rct = new Rectangle(0, 0, 0, 0); DataView dv = this.GetDataView(); DataColumn col = dv.Table.Columns[colIndex]; EPoint pntRange = this.columnHeaders1.GetColumnLeftRight(col.ColumnName); rct.X = pntRange.X; rct.Width = pntRange.Y - pntRange.X; int nTotalHeight = 0; for (int y = 0; y <= rowIndex; y++) { VersatileDataGridRowStyle rowStyle = this.GetRowStyle(y); if (y == rowIndex) { rct.Y = nTotalHeight; rct.Height = rowStyle.Height; } nTotalHeight += rowStyle.Height; } return(rct); }
public MemberBitmapBase() { //m_clrKey = Color.FromArgb(255,255,255); m_pntRegPoint = new EPoint(0,0); //m_sizeAnimateWithin = new EPoint(0,0); m_sizeTotal = new EPoint(0,0); }
public TestCircle() { m_pntVel = new EPointF(0, 0); m_pntThrust = new EPoint(0, 0); aKeysPressedX = new ArrayList(); aKeysPressedY = new ArrayList(); Bitmap bmp = new Bitmap(40, 40, PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(bmp); g.FillEllipse(new SolidBrush(Color.Red), 0, 0, 40, 40); g.Dispose(); MemberSpriteBitmap mb = new MemberSpriteBitmap(bmp); mb.CenterRegPoint(); Member = mb; m_aLines = new ArrayList(); for (int i = 0; i < 1; i++) { TestLine line = new TestLine(m_endogine); line.SetLine(new EPointF((i) * 150, 0), new EPointF((i + 1) * 150, 150)); m_aLines.Add(line); } LocZ = 10; Loc = new EPointF(171, 171); m_endogine.KeyEvent += new KeyEventHandler(m_endogine_KeyEvent); }
public bool ShowCornerResult(PictureBox display) { bool reSuccess = false; try { float scalingRatio = ScalingRatio(eFindCorner[CornerLine.Line_1].InputImage, display); eFindCorner[CornerLine.Line_1].Base.SetZoom(scalingRatio, scalingRatio); eFindCorner[CornerLine.Line_1].Base.SetPan(0, 0); eFindCorner[CornerLine.Line_2].Base.SetZoom(scalingRatio, scalingRatio); eFindCorner[CornerLine.Line_2].Base.SetPan(0, 0); Bitmap bmp = new Bitmap(InputImage.Width, InputImage.Height); eFindCorner[CornerLine.Line_1].Base.Draw(Graphics.FromImage(bmp), EDrawingMode.SampledPoints); eFindCorner[CornerLine.Line_1].Base.Draw(Graphics.FromImage(bmp), EDrawingMode.Actual); eFindCorner[CornerLine.Line_2].Base.Draw(Graphics.FromImage(bmp), EDrawingMode.SampledPoints); eFindCorner[CornerLine.Line_2].Base.Draw(Graphics.FromImage(bmp), EDrawingMode.Actual); ezPoint ezPoint = new ezPoint(); GetCornerResults(ref ezPoint); EPoint ePoint = new EPoint((float)ezPoint.x, (float)ezPoint.y); ELineGauge line_1 = new ELineGauge(); ELineGauge line_2 = new ELineGauge(); //line_1.Attach(eFixture.Base); //line_2.Attach(eFixture.Base); line_1.SetCenterXY(ePoint.X, ePoint.Y); line_2.SetCenterXY(ePoint.X, ePoint.Y); line_1.Angle = eFindCorner[CornerLine.Line_1].Position_Angle + eFixture.Angle; line_2.Angle = eFindCorner[CornerLine.Line_2].Position_Angle + eFixture.Angle; line_1.SetZoom(scalingRatio, scalingRatio); line_2.SetZoom(scalingRatio, scalingRatio); line_1.SetPan(0, 0); line_2.SetPan(0, 0); line_1.Draw(Graphics.FromImage(bmp), new ERGBColor(255, 0, 0), EDrawingMode.Actual); line_2.Draw(Graphics.FromImage(bmp), new ERGBColor(255, 0, 0), EDrawingMode.Actual); if (display.InvokeRequired) { display.Invoke(new Action(() => { display.Image = bmp; })); } else { display.Image = bmp; } reSuccess = true; } catch (EException exc) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, exc.Message, true, true); } catch (Exception ex) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, ex.Message, true, true); } return(reSuccess); }
public void GetCornerWordResults(ref ezPoint corner) { try { //ezLine line_1 = new ezLine(0, 0, 0); //ezLine line_2 = new ezLine(0, 0, 0); //GetLineWordResults(CornerLine.Line_1, ref line_1); //GetLineWordResults(CornerLine.Line_2, ref line_2); //line[CornerLine.Line_1] = line_1; //line[CornerLine.Line_2] = line_2; //corner = new ezPoint(line_1, line_2); ezPoint pixelCorner = new ezPoint(); GetCornerResults(ref pixelCorner); EPoint wordPoint = eCalibration.Fixture.GetPoint(new EPoint((float)pixelCorner.x, (float)pixelCorner.y), CoordinateHook.Hook); corner = new ezPoint(); corner.x = wordPoint.X; corner.y = wordPoint.Y; } catch (EException exc) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, exc.Message, true, true); } catch (Exception ex) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, ex.Message, true, true); } }
public void GetCornerResults(ref ezPoint corner) { try { float result_CenterX_1 = 0; float result_CenterY_1 = 0; float result_Angle_1 = 0; float result_CenterX_2 = 0; float result_CenterY_2 = 0; float result_Angle_2 = 0; FindCorner[CornerLine.Line_1].FindLine(ref result_CenterX_1, ref result_CenterY_1, ref result_Angle_1); FindCorner[CornerLine.Line_2].FindLine(ref result_CenterX_2, ref result_CenterY_2, ref result_Angle_2); EPoint localSensor_1 = eFixture.GetPoint(new EPoint(result_CenterX_1, result_CenterY_1), CoordinateHook.NotHook); EPoint localSensor_2 = eFixture.GetPoint(new EPoint(result_CenterX_2, result_CenterY_2), CoordinateHook.NotHook); ezLine line_1 = new ezLine(localSensor_1.X, localSensor_1.Y, result_Angle_1 + eFixture.Angle); ezLine line_2 = new ezLine(localSensor_2.X, localSensor_2.Y, result_Angle_2 + eFixture.Angle); line[CornerLine.Line_1] = line_1; line[CornerLine.Line_2] = line_2; corner = new ezPoint(line_1, line_2); } catch (EException exc) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, exc.Message, true, true); } catch (Exception ex) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, ex.Message, true, true); } }
private bool GetSample(EImageBW8 inputImage, ref DataTable result) { bool reSuccess = false; try { result.Clear(); EPoint point = new EPoint(); for (int i = 0; i < Base.NumSamples; i++) { Base.MeasureSample(inputImage, i); if (Base.GetSample(point, i)) { float centerX = Base.GetMeasuredPoint().X; float centerY = Base.GetMeasuredPoint().Y; int amplitude = Base.GetMeasuredPeak().Amplitude; int area = Base.GetMeasuredPeak().Area; result.Rows.Add(i + 1, centerX, centerY, amplitude, area); } } reSuccess = true; } catch (EException exc) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, exc.Message, true, true); } catch (Exception ex) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, ex.Message, true, true); } return(reSuccess); }
private void m_astar_ChangedAcceptableGoals(object sender, EPoint coordinate) { foreach (EPoint pnt in this.m_astar.AcceptableGoals) { this.SetPosColor(pnt, Color.FromArgb(0, 200, 200)); } this.m_sp.Member.Bitmap = this.m_bmp; }
public Ball GetBallOnLoc(EPoint a_pnt) { if (a_pnt.X < 0 || a_pnt.Y < 0 || a_pnt.X >= GridSize.Width || a_pnt.Y >= GridSize.Height) { return((Ball)null); } return((Ball)m_aGrid[a_pnt.X, a_pnt.Y]); }
private void m_resizeCorner_MouseEvent(Sprite sender, System.Windows.Forms.MouseEventArgs e, MouseEventType t) { if (t == Sprite.MouseEventType.StillDown) { EPoint pntDiff = new EPoint(e.X - m_resizeCorner.MouseLastLoc.X, e.Y - m_resizeCorner.MouseLastLoc.Y); Rect = new ERectangleF(Rect.Location, Rect.Size + pntDiff.ToEPointF()); //SizeF(Rect.Size.Width+pntDiff.X,Rect.Size.Height+pntDiff.Y)); } }
public override System.Collections.ArrayList GeneratePoints(EPoint ptStart) { System.Collections.ArrayList pts = new System.Collections.ArrayList(); EPoint ptEnd = ptStart + this._ptTarget; pts.Add(ptStart); pts.Add(ptEnd); return pts; }
private void m_astar_SearchFinished(object sender, EPoint coordinate) { for (int i = 1; i < this.m_astar.Solution.Count - 1; i++) { this.SetPosColor((EPoint)this.m_astar.Solution[i], Color.Yellow); } this.m_sp.Member.Bitmap = this.m_bmp; }
public override void AddToPath(System.Drawing.Drawing2D.GraphicsPath path, EPoint ptStart, float scale) { System.Collections.ArrayList pts = this.GeneratePoints(ptStart); path.AddBezier( ((EPointF)pts[0]).X*scale, ((EPointF)pts[0]).Y*scale, ((EPointF)pts[1]).X*scale, ((EPointF)pts[1]).Y*scale, ((EPointF)pts[2]).X*scale, ((EPointF)pts[2]).Y*scale, ((EPointF)pts[3]).X*scale, ((EPointF)pts[3]).Y*scale); }
public override void AddToPath(System.Drawing.Drawing2D.GraphicsPath path, EPoint ptStart, float scale) { System.Collections.ArrayList pts = this.GeneratePoints(ptStart); path.AddBezier( ((EPointF)pts[0]).X * scale, ((EPointF)pts[0]).Y * scale, ((EPointF)pts[1]).X * scale, ((EPointF)pts[1]).Y * scale, ((EPointF)pts[2]).X * scale, ((EPointF)pts[2]).Y * scale, ((EPointF)pts[3]).X * scale, ((EPointF)pts[3]).Y * scale); }
public static Bitmap Convolve(Bitmap bmpSrc, float[,] kernel) { Bitmap bmpDst = new Bitmap(bmpSrc.Width, bmpSrc.Height, bmpSrc.PixelFormat); System.Drawing.Imaging.BitmapData bmpDstData = bmpDst.LockBits( new Rectangle(0, 0, bmpDst.Width, bmpDst.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmpDst.PixelFormat); System.Drawing.Imaging.BitmapData bmpSrcData = bmpSrc.LockBits( new Rectangle(0, 0, bmpSrc.Width, bmpSrc.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmpSrc.PixelFormat); EPoint pntKernelSize = new EPoint(kernel.GetLength(0), kernel.GetLength(1)); //TODO: find out depth properly int nBpp = 3; if (bmpSrc.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb) { nBpp = 4; } unsafe { for (int y = pntKernelSize.Y / 2; y < bmpSrc.Height - pntKernelSize.Y / 2; y++) { byte *ptrSrc = (byte *)bmpSrcData.Scan0; byte *ptrDst = (byte *)bmpDstData.Scan0; ptrDst += bmpDstData.Stride * y; for (int x = pntKernelSize.X / 2; x < bmpSrc.Width - pntKernelSize.X / 2; x++) { for (int bit = 0; bit < nBpp; bit++) { float fVal = 0; for (int yKernel = 0; yKernel < pntKernelSize.Y; yKernel++) { for (int xKernel = 0; xKernel < pntKernelSize.X; xKernel++) { fVal += kernel[xKernel, yKernel] * (float)*(ptrSrc + bit + (x + xKernel - pntKernelSize.X / 2) * nBpp + (y + yKernel - pntKernelSize.Y / 2) * bmpSrcData.Stride); } } *ptrDst = (byte)fVal; ptrDst++; } } } } bmpSrc.UnlockBits(bmpSrcData); bmpDst.UnlockBits(bmpDstData); return(bmpDst); }
public override System.Collections.ArrayList GeneratePoints(EPoint ptStart) { System.Collections.ArrayList pts = new System.Collections.ArrayList(); EPoint ptEnd = ptStart + this._ptTarget; pts.Add(ptStart); pts.Add(ptEnd); return(pts); }
public ArrayList CalcColorChain(EPoint a_pntLoc) { m_aCurrentChainInfo = new ChainInfo(); Ball ball = GetBallOnLoc(a_pntLoc); RecursiveCalcColorChain(ball); return(m_aCurrentChainInfo.Balls); // return duplicate(currentChain) }
public static Canvas Convolve(Canvas canvas, float[,] kernel) { //Bitmap bmp = ((Canvas)canvas).ToBitmap(); Canvas canvasDst = canvas.CreateSimilar(); //Bitmap bmpDst = new Bitmap(canvas.Width, canvas.Height, bmp.PixelFormat); //Canvas canvasDst = Canvas.Create(bmpDst); canvasDst.Locked = true; canvas.Locked = true; EPoint pntKernelSize = new EPoint(kernel.GetLength(0), kernel.GetLength(1)); int nBpp = canvas.BitsPerPixel / 8; //TODO: what to do with palettes in D3D..? //if (nBpp == 1) // bmpDst.Palette = bmp.Palette; EPoint canvasSize = new EPoint(canvas.Width, canvas.Height); float[] vals = new float[nBpp]; for (int y = pntKernelSize.Y / 2; y < canvasSize.Y - pntKernelSize.Y / 2; y++) { for (int x = pntKernelSize.X / 2; x < canvasSize.X - pntKernelSize.X / 2; x++) { for (int channel = 0; channel < nBpp; channel++) vals[channel] = 0; for (int yKernel = 0; yKernel < pntKernelSize.Y; yKernel++) { for (int xKernel = 0; xKernel < pntKernelSize.X; xKernel++) { int clr = canvas.GetPixelInt( x + xKernel - pntKernelSize.X / 2, y + yKernel - pntKernelSize.Y / 2); for (int channel = 0; channel < nBpp; channel++) { vals[channel] += kernel[xKernel, yKernel] * (float)(clr & 0xff); clr >>= 8; } } } if (nBpp == 1) canvasDst.SetPixelInt(x, y, vals[0] > 255 ? 255 : (int)vals[0]); else if (nBpp == 3) canvasDst.SetPixel(x, y, Color.FromArgb( vals[2] > 255 ? 255 : (int)vals[2], vals[1] > 255 ? 255 : (int)vals[1], vals[0] > 255 ? 255 : (int)vals[0])); } } canvas.Locked = false; canvasDst.Locked = false; return canvasDst; }
private void m_astar_SearchedCoordinate(object sender, EPoint coordinate) { this.SetPosColor(coordinate, Color.Blue); if (this.UpdateWhileSearching) { this.m_sp.Member.Bitmap = this.m_bmp; this.m_astar.Paused = true; m_nNumFramesLeftToWaitAfterUpdate = 1; } }
public VersatileDataGrid() { InitializeComponent(); this.slColumnStyles = new SortedList(); this.aRowStyles = new ArrayList(); this.aRowStyles.Add(new VersatileDataGridRowStyle()); this.pntCachedBottomRightLoc = new EPoint(); this.columnHeaders1.Height = this.panelHeaders.Height; }
public static Bitmap CreateFilledBitmap(EPoint pntSize, System.Drawing.Color clr) { PixelFormat pf = PixelFormat.Format24bppRgb; if (clr.A != 255) pf = PixelFormat.Format32bppArgb; System.Drawing.Bitmap bmp = new Bitmap(pntSize.X, pntSize.Y, pf); Graphics g = Graphics.FromImage(bmp); g.FillRectangle(new SolidBrush(clr), 0,0,pntSize.X, pntSize.Y); g.Dispose(); return bmp; }
private EPoint ParseRegPoint(string sRegPoint, EPoint size) { if (sRegPoint == "center") { return(size / 2); } else { return(new EPoint(sRegPoint)); } }
/// <summary> /// Stretching sprite /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <param name="t"></param> private void spSquare_MouseEvent(Sprite sender, System.Windows.Forms.MouseEventArgs e, Endogine.Sprite.MouseEventType t) { if (t == Endogine.Sprite.MouseEventType.StillDown) { EPoint pntWhichSquare = (EPoint)sender.Tag; EPointF pntDiff = new EPointF(e.X, e.Y) - sender.MouseLastLoc.ToEPointF(); EPointF pntRestrictTo = new EPointF(); if (pntWhichSquare.Y == 1) { pntRestrictTo.X = 1; } else if (pntWhichSquare.X == 1) { pntRestrictTo.Y = 1; } else { pntRestrictTo = new EPointF(1, 1); } EPointF pntMove = pntDiff * pntRestrictTo; ERectangleF rct = this.m_sp.Rect.Copy(); if (pntWhichSquare.X == 0 || pntWhichSquare.Y == 0) { if (pntWhichSquare.X == 0 && pntWhichSquare.Y == 2) { rct.X += pntMove.X; rct.Width -= pntMove.X; rct.Height += pntMove.Y; } else if (pntWhichSquare.X == 2 && pntWhichSquare.Y == 0) { rct.Y += pntMove.Y; rct.Height -= pntMove.Y; rct.Width += pntMove.X; } else { rct.Location += pntMove; rct.Size -= pntMove; } } else { rct.Size += pntMove; } this.m_sp.Rect = rct; this.Update(); } }
private void sp_MouseEvent(Sprite sender, System.Windows.Forms.MouseEventArgs e, Endogine.Sprite.MouseEventType t) { if (t == Endogine.Sprite.MouseEventType.Down) { } else if (t == Endogine.Sprite.MouseEventType.StillDown) { EPoint pntAxis = (EPoint)sender.Tag; EPointF pntDiff = new EPointF(e.X, e.Y) - sender.MouseLastLoc.ToEPointF(); this.m_sp.Move(pntDiff * pntAxis); } }
public Curve GetAsCurve() { if (this is Curve) { return((Curve)this); } EPoint pt = ((Line)this).Offset; EPoint ptNew = pt / 2; return(new Curve(ptNew.Copy(), ptNew)); }
public override void CalcRenderRegion(ERectangleF rctDrawTarget, float rotation, EPoint regPoint, EPoint sourceRectSize) { if (this._effect == null) this._matrix = this.CreateMatrix(rctDrawTarget, rotation, regPoint, sourceRectSize); else { //Have to calculate differently when using shaders (haven't looked into why exactly yet) System.Drawing.Rectangle rctView = this._device.ScissorRectangle; this._matrix = Matrix.Scaling(rctDrawTarget.Width / rctView.Width * 2, rctDrawTarget.Height / rctView.Height * 2, 1); //Matrix.Identity; ////EPointF pntRelativeRegPoint = this._sp.RegPoint.ToEPointF() / this._sp.SourceRect.Size.ToEPointF(); ////EPointF pntRegOff = regPoint.ToEPointF() / new EPointF(sourceRectSize.X, sourceRectSize.Y) * new EPointF(rctDrawTarget.Width, rctDrawTarget.Height); ////m2.Multiply(Matrix.Translation(-pntRegOff.X, pntRegOff.Y, 0)); ////m2.Multiply(Matrix.RotationZ(-rotation)); ////m2.Multiply(Matrix.Translation(pntRegOff.X, -pntRegOff.Y, 0)); this._matrix.Multiply(Matrix.Translation(rctDrawTarget.X / rctView.Width * 2 - 1f, 1f - rctDrawTarget.Y / rctView.Height * 2, 0)); } }
public static System.Xml.XmlDocument CreateDocFromRectsAndOffsets(ERectangle[] rects, EPoint[] offsets, string[] optionalNames) { Node infoNode = new Node(); infoNode = infoNode.CreateChild("Files"); for (int i = 0; i<rects.Length; i++) { Node frameNode = infoNode.CreateChild("Bitmap"); if (optionalNames!=null) frameNode.Value = optionalNames[i]; else frameNode.Value = i.ToString(); Node subNode = frameNode.CreateChild("Rect"); subNode.Value = rects[i].ToString(); subNode = frameNode.CreateChild("Offset"); subNode.Value = offsets[i].ToString(); } return infoNode.RootNode.CreateXmlDocument(); }
public override void SubDraw() { ERectangleF rctDraw = m_sp.CalcRectInDrawTarget(); // Matrix QuadMatrix = Matrix.Scaling(rctDraw.Width, rctDraw.Height, 1); EPointF pntRegOff = m_sp.RegPoint.ToEPointF()/new EPointF(m_sp.SourceRect.Width, m_sp.SourceRect.Height) * new EPointF(rctDraw.Width, rctDraw.Height); // QuadMatrix.Multiply(Matrix.Translation(-pntRegOff.X, pntRegOff.Y,0)); // QuadMatrix.Multiply(Matrix.RotationZ(-m_sp.Rotation)); // QuadMatrix.Multiply(Matrix.Translation(pntRegOff.X, -pntRegOff.Y,0)); EPoint renderControlSize = new EPoint(800,600); EPointF pntLoc = new EPointF(rctDraw.X-renderControlSize.X/2, rctDraw.Y-renderControlSize.Y/2); //QuadMatrix.Multiply(Matrix.Translation(pntLoc.X, -pntLoc.Y, 0f)); int tx = ((MemberSpriteBitmapRenderStrategyA)this.m_sp.Member.RenderStrategy).TextureId; Gl.glBindTexture(Gl.GL_TEXTURE_2D, tx); //Gl.glRotatef(m_sp.Rotation, 0, 0, 1); Gl.glBegin(Gl.GL_QUADS); if (false) { Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-1, -1, 1); Gl.glTexCoord2f(1, 0); Gl.glVertex3f(1, -1, 1); Gl.glTexCoord2f(1, 1); Gl.glVertex3f(1, 1, 1); Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-1, 1, 1); } rctDraw = rctDraw*0.01f; rctDraw.Offset(-1f,-1f); // rctDraw.Y = 1f-rctDraw.Y; Gl.glTexCoord2f(0, 0); Gl.glVertex3f(rctDraw.Left, rctDraw.Top, 1); Gl.glTexCoord2f(1, 0); Gl.glVertex3f(rctDraw.Right, rctDraw.Top, 1); Gl.glTexCoord2f(1, 1); Gl.glVertex3f(rctDraw.Right, rctDraw.Bottom, 1); Gl.glTexCoord2f(0, 1); Gl.glVertex3f(rctDraw.Left, rctDraw.Bottom, 1); Gl.glEnd(); }
public void RecalcColumnLeftRights() { this.htCachedColumnLeftRights = new Hashtable(); int nTotalWidth = 0; for (int x = 0; x < this.slColumnStyles.Count; x++) { VersatileDataGridColumnStyle columnStyle = GetColumnStyle(x); EPoint pntRange = new EPoint(nTotalWidth, nTotalWidth+columnStyle.Width); //EH.Put(col.ColumnName + " " + pntRange.ToString()); this.htCachedColumnLeftRights.Add(columnStyle.ColumnName, pntRange); nTotalWidth+=columnStyle.Width+this.SplitterWidth; } }
public virtual EPoint GetNewLoc(EPoint ptStart) { return ptStart; }
public Matrix CreateMatrix(ERectangleF rctDrawTarget, float rotation, EPoint regPoint, EPoint sourceRectSize) { System.Drawing.Rectangle rctView = this._device.ScissorRectangle; //this._device.Viewport Matrix m = Matrix.Scaling(rctDrawTarget.Width, rctDrawTarget.Height, 1); EPointF pntRegOff = regPoint.ToEPointF() / new EPointF(sourceRectSize.X, sourceRectSize.Y) * new EPointF(rctDrawTarget.Width, rctDrawTarget.Height); m.Multiply(Matrix.Translation(-pntRegOff.X, pntRegOff.Y, 0)); m.Multiply(Matrix.RotationZ(-rotation)); m.Multiply(Matrix.Translation(pntRegOff.X, -pntRegOff.Y, 0)); EPointF pntLoc = new EPointF(rctDrawTarget.X - rctView.Width / 2, rctDrawTarget.Y - rctView.Height / 2); m.Multiply(Matrix.Translation(pntLoc.X, -pntLoc.Y, 0f)); m.M43 = 9000f; return m; }
public static void Assemble(string definition, string savePathWithPrefix, EPoint firstTryTextureSize) { Hashtable passNumberToTexture = GenerateFileLists(definition, null); bool usingPasses = passNumberToTexture.Count > 1 ? true : false; //usingPasses = generate several bitmaps, based on different sequences foreach (DictionaryEntry dePass in passNumberToTexture) { int passNum = (int)dePass.Key; Hashtable textureNamesToFramesets = (Hashtable)dePass.Value; foreach (DictionaryEntry deTexture in textureNamesToFramesets) { string textureName = (string)deTexture.Key; Hashtable framesets = (Hashtable)deTexture.Value; XmlDocument doc = new XmlDocument(); XmlNode xmlNode = doc.CreateElement("Animations"); doc.AppendChild(xmlNode); XmlNode xmlFramesetNode; XmlAttribute xmlAttr; ArrayList allFiles = new ArrayList(); foreach (DictionaryEntry deAnim in framesets) { string framesetName = (string)deAnim.Key; string[] filenames = (string[])deAnim.Value; if (filenames.Length > 0) { //frameset can have same name as others (other characters etc) //so it must be uniquely identifiable - add xmlFramesetNode = xmlNode.OwnerDocument.CreateElement(framesetName); xmlNode.AppendChild(xmlFramesetNode); string sAnimFrames = "0"; // Create animation frame list: <Animations> tag //if (usingPasses) //{ int startFrame = allFiles.Count; sAnimFrames = startFrame.ToString(); //} sAnimFrames += " 0-" + (filenames.Length - 1).ToString(); //for (int i=0; i<filenames.Length;i++) // sAnimFrames+=i.ToString()+","; //sAnimFrames = sAnimFrames.Remove(sAnimFrames.Length-1,1); xmlAttr = xmlNode.OwnerDocument.CreateAttribute("value"); xmlFramesetNode.Attributes.Append(xmlAttr); xmlAttr.InnerText = sAnimFrames; } foreach (string filename in filenames) allFiles.Add(filename); } string[] all = new string[allFiles.Count]; for (int i = 0; i < allFiles.Count; i++) all[i] = (string)allFiles[i]; string saveFilename = textureName; if (usingPasses) saveFilename += "_" + passNum.ToString().PadLeft(2, '0'); saveFilename = savePathWithPrefix + saveFilename; //TODO: find texture size to start trying with. //TODO: doesn't really matter in which texture the individual frames are... (in some cases at least) EPoint trySize = firstTryTextureSize.Copy(); for (int tryNum = 0; tryNum < 3; tryNum++) { try { Endogine.BitmapHelpers.TexturePacking.TreePack( new System.Drawing.Size(trySize.X, trySize.Y), all, saveFilename); } catch { if (trySize.X <= trySize.Y) trySize.X *= 2; else trySize.Y *= 2; } } //load the auto-created resource fork and add the animations to it: string xmlFilename = saveFilename + ".xml"; XmlDocument resDoc = new XmlDocument(); resDoc.Load(xmlFilename); if (resDoc["root"]["Animations"] == null) Endogine.Serialization.XmlHelper.CreateAndAddElement(resDoc["root"], "Animations"); resDoc["root"]["Animations"].InnerXml = doc["Animations"].InnerXml; //Endogine.Serialization.XmlHelper.Merge(resDoc["root"]["Animations"], doc["Animations"]); resDoc.Save(xmlFilename); } } }
public Move(EPoint ptTarget) { this._ptTarget = ptTarget; }
public static unsafe Bitmap TrimWhitespace(Bitmap bmp, out EPoint topLeftCorner) { //TODO: name should be TrimAlpha int nThreshold = 0; Canvas canvas = Canvas.Create(bmp); canvas.Locked = true; ERectangle rctBounds = ERectangle.FromLTRB(0, 0, canvas.Width, canvas.Height); for (int side = 0; side < 2; side++) { int yDir = 1; int yUse = 0; if (side == 1) { yDir = -1; yUse = canvas.Height - 2; } bool bFound = false; for (int y = 0; y < canvas.Height; y++) { for (int x = 0; x < canvas.Width; x++) { if (canvas.GetPixel(x, yUse).A > nThreshold) { if (side == 0) rctBounds.Top = yUse; else rctBounds.Bottom = yUse; bFound = true; break; } } if (bFound) break; yUse += yDir; } } for (int side = 0; side < 2; side++) { int xDir = 1; int xUse = 0; if (side == 1) { xDir = -1; xUse = canvas.Width - 1; } bool bFound = false; for (int x = 0; x < canvas.Width; x++) { xUse += xDir; for (int y = 0; y < canvas.Height; y++) { if (canvas.GetPixel(xUse, y).A > nThreshold) { if (side == 0) rctBounds.Left = xUse; else rctBounds.Right = xUse; bFound = true; break; } } if (bFound) break; } } canvas.Locked = false; if (rctBounds.Width==0 || rctBounds.Height==0) { topLeftCorner = new EPoint(); return null; } Bitmap trimmedBmp = new Bitmap(rctBounds.Width, rctBounds.Height); Graphics g = Graphics.FromImage(trimmedBmp); g.DrawImage(bmp, new Rectangle(0,0,rctBounds.Width,rctBounds.Height), rctBounds.X,rctBounds.Y,rctBounds.Width,rctBounds.Height, GraphicsUnit.Pixel); topLeftCorner = new EPoint(rctBounds.X, rctBounds.Y); return trimmedBmp; }
public static Bitmap RenderToBitmap(int nTwipSize, ArrayList commandList, ArrayList fillStyles, ArrayList lineStyles, out EPoint ptOffset) { EPoint pntCurrentLoc = new EPoint(); ArrayList pathInfos = new ArrayList(); PathInfo pathInfoCurrent = new PathInfo(); pathInfos.Add(pathInfoCurrent); bool hasDrawnSinceLastStyleChange = false; EPointF ptScale = new EPointF(1,1)/nTwipSize; string sDebug = ""; foreach (ShapeCommand.Base cmd in commandList) { if (cmd.MovesTurtle) { if (cmd.Draws) { ((ShapeCommand.Draw)cmd).AddToPath(pathInfoCurrent.Path, pntCurrentLoc, ptScale.X); if (Shape.Debug) { ArrayList pts = ((ShapeCommand.Draw)cmd).GeneratePoints(pntCurrentLoc); if (cmd is ShapeCommand.Curve) sDebug+="Curve"; else sDebug+="Line"; sDebug+="\r\n"; foreach (EPointF pt in pts) sDebug+=pt.ToString()+"\r\n"; } hasDrawnSinceLastStyleChange = true; } else { pathInfoCurrent.Path.CloseAllFigures(); pathInfoCurrent.Path.StartFigure(); } pntCurrentLoc = cmd.GetNewLoc(pntCurrentLoc); } else { if (hasDrawnSinceLastStyleChange) { pathInfoCurrent = new PathInfo(); pathInfos.Add(pathInfoCurrent); } if (cmd is ShapeCommand.FillStyle) { ShapeCommand.FillStyle fs = (ShapeCommand.FillStyle)cmd; Brush brush = null; if (fs.StyleId > 0) brush = ((Style.FillStyle)fillStyles[fs.StyleId-1]).GetBrush(); if (fs.Side == 0) pathInfoCurrent.Brush0 = brush; else pathInfoCurrent.Brush1 = brush; } else if (cmd is ShapeCommand.LineStyle) { ShapeCommand.LineStyle ls = (ShapeCommand.LineStyle)cmd; Pen pen = null; if (ls.StyleId > 0) pen = ((Style.LineStyle)lineStyles[ls.StyleId-1]).GetPen(); pathInfoCurrent.Pen = pen; if (pen!=null) pen.Width*= ptScale.X; } hasDrawnSinceLastStyleChange = false; } } Matrix transform = new Matrix(); transform.Scale(ptScale.X,ptScale.Y); ERectangle bounds = ERectangle.FromLTRB(99999,99999,-99999,-99999); foreach (PathInfo pathInfo in pathInfos) { //pathInfo.Path.Transform(transform); bounds.Expand(pathInfo.GetBounds().ToERectangle()); } ptOffset = bounds.TopLeft; if (bounds.Width == 0 || bounds.Height == 0) return null; //this.Bounds = bounds; if (Shape.Debug) Endogine.Files.FileReadWrite.Write("__s.txt", sDebug); transform = new Matrix(); transform.Translate(-bounds.X, -bounds.Y); foreach (PathInfo pathInfo in pathInfos) pathInfo.Path.Transform(transform); Bitmap bmp = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppArgb); Endogine.BitmapHelpers.Canvas canvas = Endogine.BitmapHelpers.Canvas.Create(bmp); canvas.Locked = true; canvas.Fill(Color.FromArgb(0, 255, 255, 255)); canvas.Dispose(); Graphics g = Graphics.FromImage(bmp); g.SmoothingMode = SmoothingMode.HighQuality; foreach (PathInfo pathInfo in pathInfos) { if (pathInfo.Pen!=null) g.DrawPath(pathInfo.Pen, pathInfo.Path); if (pathInfo.Brush0!=null) g.FillPath(pathInfo.Brush0, pathInfo.Path); if (pathInfo.Brush1!=null) //TODO: can GDI+ handle Flash's two different fills (0 and 1)? g.FillPath(pathInfo.Brush1, pathInfo.Path); } return bmp; }
private void CustomSplitter_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { this.isDragging = false; EPoint pntDiff = new EPoint(e.X, e.Y) - this.mouseLastLoc; //mouseDownLoc; this.mouseLastLoc = new EPoint(e.X, e.Y); this.Left+= (this.mouseLastLoc-this.mouseDownLoc).X; if (SplitterMoved!=null) SplitterMoved(this, pntDiff.X); }
private void CustomSplitter_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if (this.isDragging) { EPoint pntDiff = new EPoint(e.X, e.Y) - this.mouseLastLoc; this.mouseLastLoc = new EPoint(e.X, e.Y); //TODO:why doesn't it work? this.Left+= pntDiff.X; if (SplitterMoving!=null) SplitterMoving(this, pntDiff.X); } }
private void CustomSplitter_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { this.isDragging = true; this.mouseDownLoc = new EPoint(e.X, e.Y); this.mouseLastLoc = new EPoint(e.X, e.Y); }
public Line(EPoint ptTarget) { this._ptTarget = ptTarget; }
public static Bitmap Convolve(Bitmap bmpSrc, float[,] kernel) { Bitmap bmpDst = new Bitmap(bmpSrc.Width, bmpSrc.Height, bmpSrc.PixelFormat); System.Drawing.Imaging.BitmapData bmpDstData = bmpDst.LockBits( new Rectangle(0, 0, bmpDst.Width, bmpDst.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmpDst.PixelFormat); System.Drawing.Imaging.BitmapData bmpSrcData = bmpSrc.LockBits( new Rectangle(0, 0, bmpSrc.Width, bmpSrc.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmpSrc.PixelFormat); EPoint pntKernelSize = new EPoint(kernel.GetLength(0), kernel.GetLength(1)); //TODO: find out depth properly int nBpp = 3; if (bmpSrc.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb) nBpp = 4; unsafe { for (int y = pntKernelSize.Y / 2; y < bmpSrc.Height - pntKernelSize.Y / 2; y++) { byte* ptrSrc = (byte*)bmpSrcData.Scan0; byte* ptrDst = (byte*)bmpDstData.Scan0; ptrDst += bmpDstData.Stride * y; for (int x = pntKernelSize.X / 2; x < bmpSrc.Width - pntKernelSize.X / 2; x++) { for (int bit = 0; bit < nBpp; bit++) { float fVal = 0; for (int yKernel = 0; yKernel < pntKernelSize.Y; yKernel++) { for (int xKernel = 0; xKernel < pntKernelSize.X; xKernel++) { fVal += kernel[xKernel, yKernel] * (float)*(ptrSrc + bit + (x + xKernel - pntKernelSize.X / 2) * nBpp + (y + yKernel - pntKernelSize.Y / 2) * bmpSrcData.Stride); } } *ptrDst = (byte)fVal; ptrDst++; } } } } bmpSrc.UnlockBits(bmpSrcData); bmpDst.UnlockBits(bmpDstData); return bmpDst; }
public ArrayList BeginSearch(EPoint start, EPoint goal) { this.StartPos = start; this.GoalPos = goal; return this.BeginSearch(); }
public void RefreshLayout() { EPoint pntHeaderBottomRight = new EPoint(); for (int x = 0; x < this.slColumnStyles.Count; x++) { VersatileDataGridColumnStyle columnStyle = GetColumnStyle(x); EPoint pntLeftRight = this.GetColumnLeftRight(columnStyle.ColumnName); //rct.Height = this.panelHeaders.Height; //panelSubHeaders Control ctrl = this.Controls[x*2]; //panelSubHeaders ctrl.Width = pntLeftRight.Y-pntLeftRight.X; ctrl.Left = pntLeftRight.X; // this.listView1.Columns[x].Width = pntLeftRight.Y-pntLeftRight.X; Control splitter = this.Controls[x*2+1]; //panelSubHeaders splitter.Left = pntLeftRight.Y; //splitter.Height = rct.Height; pntHeaderBottomRight.X = pntLeftRight.Y; //pntHeaderBottomRight.Y = rct.Bottom; } // this.listView1.Width = pntHeaderBottomRight.X; this.Width = pntHeaderBottomRight.X; //panelSubHeaders.Width = pntHeaderBottomRight.X; //panelSubHeaders.Height = pntHeaderBottomRight.Y; }
private static void translateEntries(List<MapEntry> entries, DataManager manager, ContentManager content) { Dictionary<string, EPoint> points = new Dictionary<string, EPoint>(); Dictionary<string, Texture2D> textures = new Dictionary<string, Texture2D>(); Dictionary<string, ETile> tiles = new Dictionary<string, ETile>(); Dictionary<string, Grid> grids = new Dictionary<string, Grid>(); Dictionary<string, ECell> cells = new Dictionary<string, ECell>(); Dictionary<string, double> numbers = new Dictionary<string, double>(); Dictionary<string, bool> booleans = new Dictionary<string, bool>(); Dictionary<string, string> strings = new Dictionary<string, string>(); foreach (MapEntry entry in entries) { if (entry.TypeName == "Texture") { Texture2D texture = content.Load<Texture2D>(entry[0]); textures.Add(entry.EntryName, texture); } else if (entry.TypeName == "Point") { EPoint point = new EPoint( int.Parse(entry[0]), int.Parse(entry[1]), int.Parse(entry[2])); points.Add(entry.EntryName, point); } else if (entry.TypeName == "Tile") { ETile tile = new ETile(); tile.Texture = textures[entry[0]]; tile.Solid = bool.Parse(entry[1]); tiles.Add(entry.EntryName, tile); } else if (entry.TypeName == "Grid") { EPoint gridSize = points[entry[0]]; EPoint gridOrigin = points[entry[1]]; EPoint gridTileOffset = points[entry[2]]; EPoint gridTileSize = points[entry[3]]; EPoint playerStart = points[entry[4]]; Grid grid = new Grid( gridSize.X, gridSize.Y, gridSize.Z, null, gridTileOffset.X, gridTileOffset.Y, gridTileSize.X, gridTileSize.Y, gridTileOffset.Z, gridOrigin.X, gridOrigin.Y); grid.ShadowEast = content.Load<Texture2D>("Block Shadow\\Shadow East"); grid.ShadowEast = content.Load<Texture2D>("Block Shadow\\Shadow North East"); grid.ShadowEast = content.Load<Texture2D>("Block Shadow\\Shadow North West"); grid.ShadowEast = content.Load<Texture2D>("Block Shadow\\Shadow North"); grid.ShadowEast = content.Load<Texture2D>("Block Shadow\\Shadow West"); grid.ShadowEast = content.Load<Texture2D>("Block Shadow\\Shadow South East"); grid.ShadowEast = content.Load<Texture2D>("Block Shadow\\Shadow South West"); grid.ShadowEast = content.Load<Texture2D>("Block Shadow\\Shadow South"); grid.ShadowEast = content.Load<Texture2D>("Block Shadow\\Shadow East"); grids.Add(entry.EntryName, grid); } else if (entry.TypeName == "Cell") { ECell cell = new ECell(); cell.Point = new EPoint(int.Parse(entry[0]), int.Parse(entry[1]), int.Parse(entry[2])); cell.Grid = grids[entry[3]]; cell.Tile = tiles[entry[4]]; cell.Grid.setTile( cell.Point.X, cell.Point.Y, cell.Point.Z, cell.Tile.Texture, cell.Tile.Solid); if (!string.IsNullOrEmpty(entry.EntryName)) cells.Add(entry.EntryName, cell); } else if (entry.TypeName == "Number") { numbers.Add(entry.EntryName, double.Parse(entry[0])); } else if (entry.TypeName == "Boolean") { booleans.Add(entry.EntryName, bool.Parse(entry[0])); } else if (entry.TypeName == "String") { strings.Add(entry.EntryName, entry[0]); } } foreach (string key in grids.Keys) { manager.AddItem(key, grids[key]); } foreach (string key in textures.Keys) { manager.AddItem(key, textures[key]); } }
public static ArrayList ReadShapeCommands(BinaryFlashReader reader, ArrayList fillStyles, ArrayList lineStyles, bool useAlpha, bool extended, bool morph, bool hasX) { reader.JumpToNextByteStart(); ArrayList commands = new ArrayList(); Byte val = reader.ReadByte(); int numFillBits = val >> 4; //this.NumFillBits int numLineBits = val & 15; //this.NumLineBits while (true) { //Debugging // ArrayList types = new ArrayList(); // foreach (ShapeCommand.Base cmd in commands) // { // string name = cmd.GetType().ToString(); // types.Add(name.Remove(0,name.LastIndexOf(".")+1) + ":"+cmd.ToString()); // } bool bIsEdge = reader.ReadBoolean(); if (!bIsEdge) { int nFlags = (int)reader.ReadBits(5); if (nFlags == 0) break; bool bStateNewStyles = (nFlags & 16) > 0; bool bStateLineStyle = (nFlags & 8) > 0; bool bStateFillStyle1 = (nFlags & 4) > 0; bool bStateFillStyle0 = (nFlags & 2) > 0; bool bStateMoveTo = (nFlags & 1) > 0; if (bStateMoveTo) { int nMoveBits = (int)reader.ReadBits(5); EPoint pntMove = new EPoint( (int)reader.ReadBits(nMoveBits,true), (int)reader.ReadBits(nMoveBits,true)); commands.Add(new ShapeCommand.Move(pntMove)); } if (bStateFillStyle0) commands.Add(new ShapeCommand.FillStyle((int)reader.ReadBits(numFillBits), 0)); if (bStateFillStyle1) commands.Add(new ShapeCommand.FillStyle((int)reader.ReadBits(numFillBits), 1)); if (bStateLineStyle) commands.Add(new ShapeCommand.LineStyle((int)reader.ReadBits(numLineBits))); if (bStateNewStyles) { fillStyles.AddRange(reader.ReadFillStyleArray(useAlpha, extended, morph)); lineStyles.AddRange(reader.ReadLineStyleArray(useAlpha, extended, morph, hasX)); numFillBits = (int)reader.ReadBits(4); numLineBits = (int)reader.ReadBits(4); } } else { bool bIsStraight = reader.ReadBoolean(); if (bIsStraight) { int nNumBits = (int)reader.ReadBits(4)+2; bool bGeneralLineFlag = reader.ReadBoolean(); //0 = horizontal/vertical, 1 = general (ie both X and Y) EPoint pntMove = new EPoint(); if (bGeneralLineFlag) { pntMove.X = (int)reader.ReadBits(nNumBits,true); pntMove.Y = (int)reader.ReadBits(nNumBits,true); } else { //error in MMs documentation: either X or Y in here, not both! bool bVertical = reader.ReadBoolean(); int nVal = (int)reader.ReadBits(nNumBits, true); if (bVertical) pntMove.Y = nVal; else pntMove.X = nVal; } commands.Add(new ShapeCommand.Line(pntMove)); } else { //it's a curve int nNumBits = (int)reader.ReadBits(4)+2; long[] vals = reader.ReadBitArray(4, nNumBits, true); commands.Add(new ShapeCommand.Curve(new EPoint(vals[0], vals[1]), new EPoint(vals[2], vals[3]))); } } } return commands; }
public override EPoint GetNewLoc(EPoint ptStart) { return this._ptTarget; }
public override void AddToPath(System.Drawing.Drawing2D.GraphicsPath path, EPoint ptStart, float scale) { EPoint ptEnd = ptStart + this._ptTarget; path.AddLine(ptStart.X*scale, ptStart.Y*scale, ptEnd.X*scale, ptEnd.Y*scale); }
public Pattern(BinaryPSDReader r) { long startPos = r.BaseStream.Position; uint length = r.ReadUInt32(); uint version = r.ReadUInt32(); this.ColorMode = (ColorModes)r.ReadUInt32(); this.Loc = new EPoint(r.ReadUInt16(), r.ReadUInt16()); //TODO: signed?? this.Name = r.ReadPSDUnicodeString(); this.Id = r.ReadPascalString(); //? if (this.ColorMode == ColorModes.Indexed) { this.PaletteForXml = ""; for (int i = 0; i < 256; i++) { string s = ""; for (int j = 0; j < 3; j++) s += r.ReadByte().ToString("X"); this.PaletteForXml += s; } } byte[] imageData = r.ReadBytes((int)(length - (int)r.BaseStream.Position - startPos)); //TODO: what is the format? //System.IO.MemoryStream stream = new System.IO.MemoryStream(imageData); //System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(stream); //this.ImageData = Endogine.Serialization.ReadableBinary.CreateHexEditorString(imageData); //TODO: length isn't correct! By 6 bytes always?? if (r.BytesToEnd < 20) r.BaseStream.Position = r.BaseStream.Length; }
protected void ResizeSliders() { if (this._sliders.Count == 0) return; if (this.Horizontal) { //TODO: change each textbox size and move both labels and textboxes //get space left for textboxes: int totalLabelWidth = 0; //Graphics g = Graphics.FromImage for (int i = 0; i < this._sliders.Count; i++) totalLabelWidth += this._labels[i].Width; totalLabelWidth += this._spacing.X * (this._labels.Count - 1); int sliderWidth = (this.Width - totalLabelWidth) / this._sliders.Count; EPoint pnt = new EPoint(0, 0); for (int i = 0; i < this._sliders.Count; i++) { this._labels[i].Location = pnt.ToPoint(); pnt.X = this._labels[i].Right; this._sliders[i].Location = pnt.ToPoint(); this._sliders[i].Width = sliderWidth; pnt.X = this._sliders[i].Right; pnt += this._spacing; } } else { for (int i = 0; i < this._sliders.Count; i++) this._sliders[i].Width = this.Width - this._sliders[i].Left; } }