Beispiel #1
0
            protected NRectangleShape[,] GetLifeMap(NStateObject state)
            {
                NDiagramSessionStateObject diagramState = state as NDiagramSessionStateObject;

                m_Map = new NRectangleShape[boardCellCountWidth, boardCellCountHeight];
                NGroup           cellsGroup = diagramState.Document.ActiveLayer.GetChildByName("cellsGroup", 0) as NGroup;
                NShapeCollection children   = cellsGroup.Shapes;

                if (m_MapShapeIds != null)
                {
                    m_HasReinitialized = false;
                    for (int x = 0; x < boardCellCountWidth; x++)
                    {
                        for (int y = 0; y < boardCellCountHeight; y++)
                        {
                            m_Map[x, y] = children.GetChildFromUniqueId(m_MapShapeIds[x, y]) as NRectangleShape;
                        }
                    }
                    return(m_Map);
                }

                m_MapShapeIds = new Guid[boardCellCountWidth, boardCellCountHeight];
                foreach (NRectangleShape cell in children)
                {
                    string[] tokens = cell.Name.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
                    int      x      = int.Parse(tokens[0]);
                    int      y      = int.Parse(tokens[1]);
                    m_Map[x, y]         = cell;
                    m_MapShapeIds[x, y] = cell.UniqueId;
                }
                ApplyConfigurationCoordinates(m_Map, initialConfigurationCoordinates);
                m_HasReinitialized = true;
                return(m_Map);
            }
            protected void OnMouseEvent(string webControlId, System.Web.HttpContext context, NStateObject state, NCallbackMouseEventArgs args)
            {
                NDiagramSessionStateObject diagramState = state as NDiagramSessionStateObject;

                NNodeList allShapes = diagramState.Document.ActiveLayer.Children(Nevron.Diagram.Filters.NFilters.Shape2D);

                NNodeList affectedNodes  = diagramState.HitTest(args);
                NNodeList affectedShapes = affectedNodes.Filter(Nevron.Diagram.Filters.NFilters.Shape2D);

                int length;

                length = allShapes.Count;
                for (int i = 0; i < length; i++)
                {
                    NShape shape = allShapes[i] as NShape;
                    shape.Style.ShadowStyle = null;
                    if (shape.Tag != null)
                    {
                        shape.Style.FillStyle = new NColorFillStyle((Color)shape.Tag);
                    }
                }

                length = affectedShapes.Count;
                for (int i = 0; i < length; i++)
                {
                    NShape shape = affectedShapes[i] as NShape;
                    shape.Style.ShadowStyle = new NShadowStyle(ShadowType.GaussianBlur, Color.FromArgb(96, Color.Black), new NPointL(3, 3), 1, new NLength(10));
                    NColorFillStyle fs = shape.Style.FillStyle as NColorFillStyle;
                    if (fs != null && fs.Color != Color.White)
                    {
                        shape.Tag             = fs.Color;
                        shape.Style.FillStyle = new NColorFillStyle(Color.YellowGreen);
                    }
                }
            }
            public override void OnAsyncClick(string webControlId, System.Web.HttpContext context, NStateObject state, NCallbackMouseEventArgs args)
            {
                NDiagramSessionStateObject diagramState = state as NDiagramSessionStateObject;
                NNodeList clickedNodes  = diagramState.HitTest(args);
                NNodeList clickedShapes = clickedNodes.Filter(Nevron.Diagram.Filters.NFilters.Shape2D);

                NNodeList shapes = diagramState.Document.ActiveLayer.Children(Nevron.Diagram.Filters.NFilters.Shape2D);
                int       length = shapes.Count;

                for (int i = 0; i < length; i++)
                {
                    NShape s = shapes[i] as NShape;
                    s.Style.FillStyle   = null;
                    s.Style.StrokeStyle = null;
                    s.Style.ShadowStyle = null;
                    s.Tag = null;
                }

                if (clickedShapes.Count == 0)
                {
                    return;
                }

                NShape clickedShape = clickedShapes[0] as NShape;

                clickedShape.Style.FillStyle   = new NColorFillStyle(libraryHighlightFillColor);
                clickedShape.Style.StrokeStyle = new NStrokeStyle(libraryHighlightBorderColor);
                clickedShape.Style.ShadowStyle = new NShadowStyle(ShadowType.GaussianBlur, Color.FromArgb(90, Color.Black), new NPointL(2, 1));
                clickedShape.Tag = "selected";
            }
            protected void UpdateStyles(NStateObject state, NRectangleShape hoverCell)
            {
                bool isCompleted = TestComplete(state);

                NDiagramSessionStateObject diagramState = state as NDiagramSessionStateObject;

                NNodeList allCells = GetAllCells(state);

                for (int i = 0; i < allCells.Count; i++)
                {
                    NRectangleShape cell = allCells[i] as NRectangleShape;
                    if (isCompleted)
                    {
                        cell.Style.FillStyle = completeCellFillStyle;
                    }
                    else
                    {
                        if (hoverCell == null || hoverCell.UniqueId != cell.UniqueId)
                        {
                            cell.Style.FillStyle = emptyCellFillStyle;
                        }
                        else if (TestCanSwap(GetClickedCellCoords(state, cell), GetEmptyCellCoords(state)))
                        {
                            cell.Style.FillStyle = hoverAllowedCellFillStyle;
                        }
                        else
                        {
                            cell.Style.FillStyle = hoverDeniedCellFillStyle;
                        }
                    }
                }

                diagramState.Document.RefreshAllViews();
            }
            protected void ChangeCurrentShapeShadow(string webControlId, System.Web.HttpContext context, NStateObject state, EventArgs args)
            {
                NDiagramSessionStateObject diagramState = state as NDiagramSessionStateObject;

                NNodeList allShapes = diagramState.Document.ActiveLayer.Children(Nevron.Diagram.Filters.NFilters.Shape2D);

                NNodeList affectedNodes  = diagramState.HitTest(args as NCallbackMouseEventArgs);
                NNodeList affectedShapes = affectedNodes.Filter(Nevron.Diagram.Filters.NFilters.Shape2D);

                int    length;
                NShape shape;

                length = allShapes.Count;
                for (int i = 0; i < length; i++)
                {
                    shape = allShapes[i] as NShape;
                    shape.Style.ShadowStyle = null;
                }

                if (affectedShapes.Count == 0)
                {
                    return;
                }

                shape = affectedShapes[affectedShapes.Count - 1] as NShape;
                if (shape.Style.StrokeStyle == null)
                {
                    shape.Style.ShadowStyle = new NShadowStyle(ShadowType.GaussianBlur, Color.FromArgb(96, Color.Black), new NPointL(3, 3), 1, new NLength(10));
                }
            }
            public override void OnAsyncDoubleClick(string webControlId, System.Web.HttpContext context, NStateObject state, NCallbackMouseEventArgs args)
            {
                // init configuration
                InitializeConfigurationFields(GetBoardCellCount(state));

                // reinitialize the configuration and the scene
                InitializeConfigurationFields(GetBoardCellCount(state));
                NDiagramSessionStateObject diagramState = state as NDiagramSessionStateObject;

                InitDocument(diagramState.Document, diagramState.StateId, GetBoardCellCount(state));
                UpdateStyles(state, null);
            }
Beispiel #7
0
            protected void HighliteCell(NStateObject state, NRectangleShape cell)
            {
                NDiagramSessionStateObject diagramState = state as NDiagramSessionStateObject;

                //	obtain/cache life map, create an initial configuration when accessed for the first time
                NRectangleShape[,] map = GetLifeMap(state);

                ClearHighlitsHormatting(map);
                cell.Style.StrokeStyle = highliteCellStrokeStyle;

                diagramState.Document.RefreshAllViews();
            }
Beispiel #8
0
            protected void Clear(NStateObject state)
            {
                NDiagramSessionStateObject diagramState = state as NDiagramSessionStateObject;

                //	obtain/cache life map, create an initial configuration when accessed for the first time
                NRectangleShape[,] map = GetLifeMap(state);

                //	clear all live cells
                ClearBoard(map);

                //	reflect life state to rectangle styles
                UpdateStyles(state);
            }
            protected NNodeList GetAllCells(NStateObject state)
            {
                NDiagramSessionStateObject diagramState = state as NDiagramSessionStateObject;

                NNodeList list       = new NNodeList();
                NGroup    cellsGroup = diagramState.Document.ActiveLayer.GetChildByName("cellsGroup", 0) as NGroup;

                foreach (INNode node in cellsGroup.Shapes)
                {
                    list.Add(node);
                }

                return(list);
            }
Beispiel #10
0
            protected NRectangleShape HitTestCell(NStateObject state, NCallbackMouseEventArgs args)
            {
                NDiagramSessionStateObject diagramState = state as NDiagramSessionStateObject;
                NNodeList nodes  = diagramState.HitTest(args);
                NNodeList shapes = nodes.Filter(Nevron.Diagram.Filters.NFilters.Shape2D);

                foreach (NShape node in shapes)
                {
                    if (!(node.Tag is CellState))
                    {
                        continue;
                    }
                    return(node as NRectangleShape);
                }

                return(null);
            }
            protected NEllipseShape HitTestEllipse(NStateObject state, NCallbackMouseEventArgs args)
            {
                NDiagramSessionStateObject diagramState = state as NDiagramSessionStateObject;
                NNodeList nodes  = diagramState.HitTest(args);
                NNodeList shapes = nodes.Filter(Nevron.Diagram.Filters.NFilters.Shape2D);

                foreach (NShape node in shapes)
                {
                    if (!(node is NEllipseShape))
                    {
                        continue;
                    }
                    if (!node.Name.Contains("Ellipse"))
                    {
                        continue;
                    }
                    return(node as NEllipseShape);
                }

                return(null);
            }
            public override void OnAsyncRefresh(string webControlId, System.Web.HttpContext context, NStateObject state, EventArgs args)
            {
                NDiagramSessionStateObject diagramState = state as NDiagramSessionStateObject;
                NEllipseShape rotatingEllipse           = diagramState.Document.ActiveLayer.GetChildByName("RotatingEllipse", 0) as NEllipseShape;

                if (rotatingEllipse == null)
                {
                    return;
                }
                NEllipseShape rotatingEllipse2 = diagramState.Document.ActiveLayer.GetChildByName("RotatingEllipse2", 0) as NEllipseShape;

                if (rotatingEllipse2 == null)
                {
                    return;
                }

                rotatingEllipse.Rotate(CoordinateSystem.Scene, 7, rotatingEllipse.PinPoint);
                rotatingEllipse2.Rotate(CoordinateSystem.Scene, -4, rotatingEllipse2.PinPoint);

                diagramState.Document.RefreshAllViews();
            }
            public override void OnAsyncMouseMove(string webControlId, System.Web.HttpContext context, NStateObject state, NCallbackMouseEventArgs args)
            {
                //	this method is called when the web control operates in the Nevron Instant Callback mode
                DoSimulateResponseDelay();

                NDiagramSessionStateObject diagramState = state as NDiagramSessionStateObject;
                NEllipseShape rotatingEllipse           = diagramState.Document.ActiveLayer.GetChildByName("RotatingEllipse", 0) as NEllipseShape;

                if (rotatingEllipse == null)
                {
                    return;
                }
                NEllipseShape rotatingEllipse2 = diagramState.Document.ActiveLayer.GetChildByName("RotatingEllipse2", 0) as NEllipseShape;

                if (rotatingEllipse2 == null)
                {
                    return;
                }
                NEllipseShape centerEllipse = diagramState.Document.ActiveLayer.GetChildByName("CenterEllipse", 0) as NEllipseShape;

                if (centerEllipse == null)
                {
                    return;
                }

                rotatingEllipse.Style.StrokeStyle  = null;
                rotatingEllipse2.Style.StrokeStyle = null;
                centerEllipse.Style.StrokeStyle    = null;

                NEllipseShape ellipse = HitTestEllipse(state, args);

                if (ellipse == null)
                {
                    return;
                }

                ellipse.Style.StrokeStyle = new NStrokeStyle(2f, Color.Snow);

                diagramState.Document.RefreshAllViews();
            }
Beispiel #14
0
            protected void UpdateStyles(NStateObject state)
            {
                NDiagramSessionStateObject diagramState = state as NDiagramSessionStateObject;

                //	obtain/cache life map, create an initial configuration when accessed for the first time
                NRectangleShape[,] map = GetLifeMap(state);

                //	reflect life state to rectangle styles
                for (int x = 0; x < boardCellCountWidth; x++)
                {
                    for (int y = 0; y < boardCellCountHeight; y++)
                    {
                        switch ((CellState)map[x, y].Tag)
                        {
                        case CellState.Dead:
                            map[x, y].Style.FillStyle = emptyCellFillStyle;
                            break;

                        case CellState.Alive:
                            map[x, y].Style.FillStyle = fullCellFillStyle;
                            break;

                        case CellState.PinnedDead:
                            map[x, y].Style.FillStyle = emptyPinnedCellFillStyle;
                            break;

                        case CellState.PinnedAlive:
                            map[x, y].Style.FillStyle = fullPinnedCellFillStyle;
                            break;

                        default:
                            System.Diagnostics.Debug.Fail("No intermediate cell states expected");
                            break;
                        }
                    }
                }

                diagramState.Document.RefreshAllViews();
            }
            public override void OnAsyncMouseUp(string webControlId, System.Web.HttpContext context, NStateObject state, NCallbackMouseEventArgs args)
            {
                // init configuration
                InitializeConfigurationFields(GetBoardCellCount(state));

                // decrease board cells count
                int curentBoardCellCount = GetBoardCellCount(state);

                if (curentBoardCellCount <= 2)
                {
                    return;
                }

                curentBoardCellCount--;
                SetBoardCellCount(state, curentBoardCellCount);

                // reinitialize the configuration and the scene
                InitializeConfigurationFields(curentBoardCellCount);
                NDiagramSessionStateObject diagramState = state as NDiagramSessionStateObject;

                InitDocument(diagramState.Document, diagramState.StateId, GetBoardCellCount(state));
                UpdateStyles(state, null);
            }
            protected void ChangeCurrentShapeColor(string webControlId, System.Web.HttpContext context, NStateObject state, EventArgs args, Color c)
            {
                NDiagramSessionStateObject diagramState = state as NDiagramSessionStateObject;

                NNodeList allShapes = diagramState.Document.ActiveLayer.Children(Nevron.Diagram.Filters.NFilters.Shape2D);

                NNodeList affectedNodes  = diagramState.HitTest(args as NCallbackMouseEventArgs);
                NNodeList affectedShapes = affectedNodes.Filter(Nevron.Diagram.Filters.NFilters.Shape2D);

                int    length;
                NShape shape;

                length = allShapes.Count;
                for (int i = 0; i < length; i++)
                {
                    shape = allShapes[i] as NShape;
                    if (shape.Tag != null)
                    {
                        shape.Style.FillStyle = shape.Tag as NAdvancedGradientFillStyle;
                    }
                }

                if (affectedShapes.Count == 0)
                {
                    return;
                }

                shape = affectedShapes[affectedShapes.Count - 1] as NShape;
                NAdvancedGradientFillStyle fs = shape.Style.FillStyle as NAdvancedGradientFillStyle;

                if (fs != null)
                {
                    shape.Tag             = fs;
                    shape.Style.FillStyle = new NColorFillStyle(c);
                }
            }
            public override void OnAsyncRefresh(string webControlId, System.Web.HttpContext context, NStateObject state, EventArgs args)
            {
                //	this method is called when the web control operates in the Nevron Instant Callback mode
                DoSimulateResponseDelay();

                NDiagramSessionStateObject diagramState = state as NDiagramSessionStateObject;
                NEllipseShape rotatingEllipse           = diagramState.Document.ActiveLayer.GetChildByName("RotatingEllipse", 0) as NEllipseShape;

                if (rotatingEllipse == null)
                {
                    return;
                }
                NEllipseShape rotatingEllipse2 = diagramState.Document.ActiveLayer.GetChildByName("RotatingEllipse2", 0) as NEllipseShape;

                if (rotatingEllipse2 == null)
                {
                    return;
                }

                rotatingEllipse.Rotate(CoordinateSystem.Scene, 7, rotatingEllipse.PinPoint);
                rotatingEllipse2.Rotate(CoordinateSystem.Scene, -4, rotatingEllipse2.PinPoint);

                diagramState.Document.RefreshAllViews();
            }
Beispiel #18
0
            protected void IterateOneTurn(NStateObject state)
            {
                NDiagramSessionStateObject diagramState = state as NDiagramSessionStateObject;

                //	obtain/cache life map, create an initial configuration when accessed for the first time
                NRectangleShape[,] map = GetLifeMap(state);
                if (m_HasReinitialized)
                {
                    //	remove the mouse move highlight
                    ClearHighlitsHormatting(map);

                    //	reflect life state to rectangle styles
                    UpdateStyles(state);
                    return;
                }

                //	mark dying cells and cells to be born
                for (int x = 0; x < boardCellCountWidth; x++)
                {
                    for (int y = 0; y < boardCellCountHeight; y++)
                    {
                        int neighboursCount = CountLiveNeighbours(x, y, map);
                        switch ((CellState)map[x, y].Tag)
                        {
                        case CellState.Dead:
                            if (neighboursCount == 3)
                            {
                                map[x, y].Tag = CellState.JustBorn;
                            }
                            break;

                        case CellState.Alive:
                            if (neighboursCount < 2 || neighboursCount > 3)
                            {
                                map[x, y].Tag = CellState.Dying;
                            }
                            break;
                        }
                    }
                }

                //	commit death/birth actions
                for (int x = 0; x < boardCellCountWidth; x++)
                {
                    for (int y = 0; y < boardCellCountHeight; y++)
                    {
                        switch ((CellState)map[x, y].Tag)
                        {
                        case CellState.Dying:
                            map[x, y].Tag = CellState.Dead;
                            break;

                        case CellState.JustBorn:
                            map[x, y].Tag = CellState.Alive;
                            break;
                        }
                    }
                }

                //	remove the mouse move highlight
                ClearHighlitsHormatting(map);

                //	reflect life state to rectangle styles
                UpdateStyles(state);
            }