private NTableShape CreateBoardShape(NDrawingDocument document, NClickomaniaGame game) { NTableShape shape = new NTableShape(); shape.Name = "Table"; shape.InitTable(TableColumns, TableRows); shape.BeginUpdate(); int i, j, index; int colorCount = GradientSchemes.Length; Random random = new Random(); for (i = 0; i < TableRows; i++) { for (j = 0; j < TableColumns; j++) { shape[j, i].Text = CellText; index = random.Next(colorCount); game.CellCount[index]++; shape[j, i].StyleSheetName = GradientSchemes[index].ToString(); } } game.BoardShape = shape; document.ActiveLayer.AddChild(shape); shape.EndUpdate(); return(shape); }
void INMouseEventCallback.OnMouseEvent(NAspNetThinWebControl control, NBrowserMouseEventArgs e) { NThinDiagramControl diagramControl = (NThinDiagramControl)control; NNodeList nodes = diagramControl.HitTest(new NPointF(e.X, e.Y)); NNodeList shapes = nodes.Filter(CellFilter); if (shapes.Count == 0) { return; } NClickomaniaGame game = (NClickomaniaGame)diagramControl.Document.Tag; NTableCell cell = (NTableCell)shapes[0]; if (cell.ParentNode.ParentNode != game.BoardShape) { return; } if (String.IsNullOrEmpty(cell.StyleSheetName)) { return; } if (game.OnCellClicked(cell) == false) { return; } // The user has clicked on a cell that is part of a region diagramControl.ServerSettings.EnableAutoUpdate = true; diagramControl.Update(); }
void INAutoUpdateCallback.OnAutoUpdate(NAspNetThinWebControl control) { NThinDiagramControl diagramControl = (NThinDiagramControl)control; NClickomaniaGame game = (NClickomaniaGame)diagramControl.Document.Tag; game.ClearHighlightedCells(); diagramControl.ServerSettings.EnableAutoUpdate = false; diagramControl.Update(); }
private NTableShape CreateInfoShape(NDrawingDocument document, NClickomaniaGame game) { NTableShape shape = new NTableShape(); shape.Name = "Info"; int i; int count = GradientSchemes.Length; shape.InitTable(2, count + 2); shape.BeginUpdate(); shape.ShowGrid = false; NTableCell headerCell = shape[0, 0]; headerCell.ColumnSpan = 2; headerCell.Padding = new Nevron.Diagram.NMargins(2, 2, 2, 0); headerCell.Borders = TableCellBorder.Bottom; headerCell.Text = "Cells:"; for (i = 0; i < count; i++) { NTableCell colorCell = shape[0, i + 1]; colorCell.Text = CellText; colorCell.StyleSheetName = GradientSchemes[i].ToString(); colorCell.Margins = new Nevron.Diagram.NMargins(4, 4, 4, 4); colorCell.Borders = TableCellBorder.All; NTableCell countCell = shape[1, i + 1]; countCell.Text = game.CellCount[i].ToString(); } NTableCell scoreCell = shape[0, i + 1]; scoreCell.ColumnSpan = 2; scoreCell.Padding = new Nevron.Diagram.NMargins(2, 2, 2, 0); scoreCell.Borders = TableCellBorder.Top; scoreCell.Text = String.Format("Score:{0}{1}", Environment.NewLine, game.Score); game.InfoShape = shape; document.ActiveLayer.AddChild(shape); shape.EndUpdate(); return(shape); }
private void InitDocument(NDrawingDocument document) { // Set up visual formatting document.BackgroundStyle.FrameStyle.Visible = false; document.Style.TextStyle.FontStyle = new NFontStyle(document.Style.TextStyle.FontStyle.Name, 14); // Create the stylesheets int i = 0; int count = GradientSchemes.Length; for (i = 0; i < count; i++) { AdvancedGradientScheme scheme = GradientSchemes[i]; NStyleSheet styleSheet = new NStyleSheet(scheme.ToString()); NAdvancedGradientFillStyle fill = new NAdvancedGradientFillStyle(scheme, 4); if (scheme.Equals(AdvancedGradientScheme.Green)) { // Make the green color dark ((NAdvancedGradientPoint)fill.Points[0]).Color = Color.FromArgb(0, 128, 0); } NStyle.SetFillStyle(styleSheet, fill); document.StyleSheets.AddChild(styleSheet); NAdvancedGradientFillStyle highlightedFill = (NAdvancedGradientFillStyle)fill.Clone(); ((NAdvancedGradientPoint)highlightedFill.Points[0]).Color = ControlPaint.LightLight(((NAdvancedGradientPoint)fill.Points[0]).Color); NStyleSheet highlightedStyleSheet = new NStyleSheet(styleSheet.Name + HighlightedSuffix); NStyle.SetFillStyle(highlightedStyleSheet, highlightedFill); document.StyleSheets.AddChild(highlightedStyleSheet); } // Create the board and info shapes NClickomaniaGame game = new NClickomaniaGame(); CreateBoardShape(document, game); CreateInfoShape(document, game); game.BoardShape.Location = new NPointF(game.InfoShape.Bounds.Right + game.InfoShape.Width / 2, game.BoardShape.Location.Y); // Resize the document to fit all shapes document.SizeToContent(); game.InfoShape.Location = new NPointF(game.InfoShape.Location.X, game.BoardShape.Location.Y); document.Tag = game; }