void Awake() { if (type == null) { int val = (int)(UnityEngine.Random.value * 100); if (val % 10 == 0) { type = new CellType(CellType.Type.Sand | CellType.Type.Stone); } else { type = new CellType(CellType.Type.Sand); } } painter = Instantiate(painterPrefab); painter.Init(type); painter.transform.SetParent(transform, false); cellCollider = Instantiate(colliderPrefab, transform, false); Vector3 colliderLocalScale = cellCollider.transform.localScale; Vector3 colliderGlobalScale = cellCollider.transform.lossyScale; cellCollider.transform.localScale = new Vector3(colliderLocalScale.x / colliderGlobalScale.x, colliderLocalScale.y / colliderGlobalScale.y, colliderLocalScale.z / colliderGlobalScale.z); cellCollider2D = Instantiate(collider2DPrefab, transform, false); Vector3 collider2DLocalScale = cellCollider2D.transform.localScale; Vector3 collider2DGlobalScale = cellCollider2D.transform.lossyScale; cellCollider2D.transform.localScale = new Vector3(collider2DLocalScale.x / collider2DGlobalScale.x, collider2DLocalScale.y / collider2DGlobalScale.y, collider2DLocalScale.z / collider2DGlobalScale.z); }
private void ExportAsAnimatedGifWorker(string outputFilePath, ProgressBox box, int numFramesPreamble, int numFrames) { Cells cells = _genAlg.CaSettings.GetInitialCells(_genAlg.GaSettings.InitialStateDistribution); CellularAutomataRules rules = ctrlCellularAutomata.Rules; NeighborhoodFunction function = _genAlg.CaSettings.NeighborhoodFunction; CellPainter painter = _genAlg.CaSettings.CellStructure.Painter; for (int i = 0; i < numFramesPreamble; i++) { cells = cells.ApplyRules(rules, function); box.Invoke( new Action( () => box.Increment() ) ); } using (FileStream fs = new FileStream(outputFilePath, FileMode.Create)) using (GifEncoder encoder = new GifEncoder(fs, cells.Columns * 2, cells.Rows * 2)) { Bitmap bmp = new Bitmap(cells.Columns * 2, cells.Rows * 2); Point offset = new Point(0, 0); for (int i = 0; i < numFrames; i++) { painter.PaintBitmap(bmp, cells, offset, ctrlCellularAutomata.Colors); encoder.AddFrame(Image.FromHbitmap(bmp.GetHbitmap()), 0, 0, new TimeSpan(0)); cells = cells.ApplyRules(rules, function); box.Increment(); } } box.Finish(); }
internal void OnSearch(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { BeginUpdate(); //-------------------------------------------------------test1 CommonTools.TreeList.TextFormatting newFormat = new CommonTools.TreeList.TextFormatting(); //CommonTools.TreeList.TextFormatting newFormat = new CommonTools.TreeList.TextFormatting(GetFormatting(Nodes[1], Columns[0])); newFormat.BackColor = System.Drawing.Color.Red; CellPainter.PaintCell(CreateGraphics(), GetPlusMinusRectangle(Nodes[1], Columns[1], CommonTools.NodeCollection.GetVisibleNodeIndex(Nodes[1])), Nodes[1], Columns[1], newFormat, GetData(Nodes[1], Columns[1])); //-------------------------------------------------------test4 //-------------------------------------------------------test5 EndUpdate(); itrHelp.FindModule(((TextBox)sender).Text); } }
/// <summary>Draw a single cell to the context.</summary> /// <param name="cr">The context to draw in.</param> /// <param name="columnIndex">The column index.</param> /// <param name="rowIndex">The row index.</param> private void DrawCell(Context cr, int columnIndex, int rowIndex) { try { var text = DataProvider.GetCellContents(columnIndex, rowIndex); var cellBounds = CalculateBounds(columnIndex, rowIndex); if (cellBounds != null) { if (text == null) { text = string.Empty; } cr.Rectangle(cellBounds.ToClippedRectangle(Width - 20, Height)); cr.Clip(); cr.LineWidth = lineWidth; cr.Rectangle(cellBounds.ToRectangle()); if (!CellPainter.PaintCell(columnIndex, rowIndex)) { //cr.SetSourceColor(CellPainter.GetForegroundColour(columnIndex, rowIndex)); //cr.Stroke(); } else { // Draw the filled in cell. #if NETCOREAPP this.StyleContext.State = CellPainter.GetCellState(columnIndex, rowIndex); this.StyleContext.RenderBackground(cr, cellBounds.Left, cellBounds.Top, cellBounds.Width - 5, cellBounds.Height - 5); var c = this.StyleContext.GetColor(this.StyleContext.State); cr.SetSourceColor(new Cairo.Color(c.Red, c.Green, c.Blue, c.Alpha)); #else cr.SetSourceColor(CellPainter.GetBackgroundColour(columnIndex, rowIndex)); cr.Fill(); cr.SetSourceColor(CellPainter.GetForegroundColour(columnIndex, rowIndex)); #endif // Draw cell outline. if (ShowLines) { cr.Rectangle(cellBounds.ToRectangle()); cr.Stroke(); } //Set text font options for cell. var layout = this.CreatePangoLayout(text); layout.FontDescription = new Pango.FontDescription(); if (CellPainter.TextItalics(columnIndex, rowIndex)) { layout.FontDescription.Style = Pango.Style.Italic; } if (CellPainter.TextBold(columnIndex, rowIndex)) { layout.FontDescription.Weight = Pango.Weight.Bold; } layout.GetPixelExtents(out Pango.Rectangle inkRectangle, out Pango.Rectangle logicalRectangle); // Vertically center the text. double y = cellBounds.Top + (cellBounds.Height - logicalRectangle.Height) / 2; // Horizontal alignment is determined by the cell painter. double x; if (CellPainter.TextLeftJustify(columnIndex, rowIndex)) { x = cellBounds.Left + ColumnPadding; } else { x = cellBounds.Right - ColumnPadding - inkRectangle.Width; } cr.MoveTo(x, y); Pango.CairoHelper.ShowLayout(cr, layout); } cr.ResetClip(); #if NETCOREAPP this.StyleContext.State = StateFlags.Normal; #endif } } catch (Exception ex) { MainView.MasterView.ShowError(ex); } }
/// <summary>Draw a single cell to the context.</summary> /// <param name="cr">The context to draw in.</param> /// <param name="columnIndex">The column index.</param> /// <param name="rowIndex">The row index.</param> private void DrawCell(IDrawContext cr, int columnIndex, int rowIndex) { try { var text = DataProvider.GetCellContents(columnIndex, rowIndex); var cellBounds = CalculateBounds(columnIndex, rowIndex); if (cellBounds != null) { if (text == null) { text = string.Empty; } cr.Rectangle(cellBounds.Clip(Width - 20, Height).ToRectangle()); cr.Clip(); cr.SetLineWidth(lineWidth); cr.Rectangle(cellBounds.ToRectangle()); if (CellPainter.PaintCell(columnIndex, rowIndex)) { // Draw the filled in cell. cr.State = CellPainter.GetCellState(columnIndex, rowIndex); cr.DrawFilledRectangle(cellBounds.Left, cellBounds.Top, cellBounds.Width - 5, cellBounds.Height - 5); // Draw cell outline. if (ShowLines) { cr.Rectangle(cellBounds.ToRectangle()); cr.Stroke(); } // Measure text for cell. var r = cr.GetPixelExtents(text, CellPainter.TextBold(columnIndex, rowIndex), CellPainter.TextItalics(columnIndex, rowIndex)); // Vertically center the text. double y = cellBounds.Top + (cellBounds.Height - r.Height) / 2; // Horizontal alignment is determined by the cell painter. double x; if (CellPainter.TextLeftJustify(columnIndex, rowIndex)) { x = cellBounds.Left + ColumnPadding; } else { x = cellBounds.Right - ColumnPadding - r.Width; } cr.MoveTo(x, y); cr.DrawText(text, CellPainter.TextBold(columnIndex, rowIndex), CellPainter.TextItalics(columnIndex, rowIndex)); } cr.ResetClip(); cr.State = States.Normal; } } catch (Exception ex) { MainView.MasterView.ShowError(ex); } }