Esempio n. 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 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();
            }
            private void ExplodePieSegment(NStateObject state, EventArgs e, int offset)
            {
                //	this method is called when the web control operates in the Nevron Instant Callback mode
                NCallbackMouseEventArgs  args       = e as NCallbackMouseEventArgs;
                NChartSessionStateObject chartState = state as NChartSessionStateObject;
                NHitTestResult           result     = chartState.HitTest(args);
                NRootPanel rootPanel = chartState.Document.RootPanel;

                if (result.ChartElement == ChartElement.DataPoint)
                {
                    NPieSeries pieSeries = result.Series as NPieSeries;
                    pieSeries.Detachments.Clear();
                    for (int i = 0; i < pieSeries.Values.Count; i++)
                    {
                        if (i == result.DataPointIndex)
                        {
                            pieSeries.Detachments.Add(offset);
                        }
                        else
                        {
                            pieSeries.Detachments.Add(0);
                        }
                    }
                }
            }
            private void ColorPieSegment(NStateObject state, EventArgs e, Color c)
            {
                NCallbackMouseEventArgs  args       = e as NCallbackMouseEventArgs;
                NChartSessionStateObject chartState = state as NChartSessionStateObject;
                NHitTestResult           result     = chartState.HitTest(args);
                NRootPanel rootPanel = chartState.Document.RootPanel;

                if (result.ChartElement == ChartElement.DataPoint)
                {
                    NPieSeries pieSeries = result.Series as NPieSeries;
                    for (int i = 0; i < pieSeries.Values.Count; i++)
                    {
                        if (i == result.DataPointIndex)
                        {
                            pieSeries.FillStyles[i]   = new NColorFillStyle(c);
                            pieSeries.BorderStyles[i] = new NStrokeStyle(1, Color.White);
                        }
                        else
                        {
                            int   colorIndex = i % NExampleUC.arrCustomColors2.Length;
                            Color color      = NExampleUC.arrCustomColors2[colorIndex];

                            pieSeries.FillStyles[i]   = new NColorFillStyle(color);
                            pieSeries.BorderStyles[i] = new NStrokeStyle(1, color);
                        }
                    }
                }
            }
            protected void MoveCell(NStateObject state, NRectangleShape cell, Point clickedCoords)
            {
                Point emptyCellPixelCoords = GetEmptyCellPixelCoords(state);

                //	move the empty cell
                SetEmptyCellPixelCoords(state, new Point((int)cell.Bounds.X, (int)cell.Bounds.Y));
                SetEmptyCellCoords(state, clickedCoords);

                //	move the clicked cell
                cell.Bounds = new NRectangleF(emptyCellPixelCoords.X, emptyCellPixelCoords.Y, cell.Bounds.Width, cell.Bounds.Height);
            }
Esempio n. 6
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();
            }
Esempio n. 7
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);
            }
Esempio n. 9
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 bool TestComplete(NStateObject state)
            {
                Hashtable grid = GetGrid(state);

                NNodeList allCells = GetAllCells(state);

                for (int i = 0; i < allCells.Count; i++)
                {
                    NRectangleShape cell           = allCells[i] as NRectangleShape;
                    Point           coords         = (Point)grid[new Point((int)cell.Bounds.X, (int)cell.Bounds.Y)];
                    int             expectedNumber = coords.X + coords.Y * GetBoardCellCount(state) + 1;
                    if (expectedNumber != (int)cell.Tag)
                    {
                        return(false);
                    }
                }
                return(true);
            }
            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);
            }
Esempio n. 12
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();
            }
            private void ExplodePieSegment(NStateObject state, EventArgs e, int offset)
            {
                NCallbackMouseEventArgs  args       = e as NCallbackMouseEventArgs;
                NChartSessionStateObject chartState = state as NChartSessionStateObject;
                NHitTestResult           result     = chartState.HitTest(args);

                if (result.ChartElement == ChartElement.DataPoint)
                {
                    NPieSeries pieSeries = result.Series as NPieSeries;
                    pieSeries.Detachments.Clear();
                    for (int i = 0; i < pieSeries.Values.Count; i++)
                    {
                        if (i == result.DataPointIndex)
                        {
                            pieSeries.Detachments.Add(offset);
                        }
                        else
                        {
                            pieSeries.Detachments.Add(0);
                        }
                    }
                }
            }
            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";
            }
            public override void OnAsyncCustomCommand(string webControlId, System.Web.HttpContext context, NStateObject state, NCallbackCustomCommandArgs args)
            {
                //	this method is called when the web control operates in the Nevron Instant Callback mode
                switch (args.Command.Name)
                {
                case "restartApplication":
                    try
                    {
                        System.Web.HttpRuntime.UnloadAppDomain();
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine("OnAsyncCustomCommand, restartApplication: " + ex.Message);
                    }
                    break;

                case "enforceResponseDelay":
                    try
                    {
                        SimulateResponseDelay = true;
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine("OnAsyncCustomCommand, changeResponseDelay: " + ex.Message);
                    }
                    break;
                }
            }
            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();
            }
Esempio n. 17
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);
            }
            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();
            }
 public override void OnAsyncCustomCommand(string webControlId, System.Web.HttpContext context, NStateObject state, NCallbackCustomCommandArgs args)
 {
     switch (args.Command.Name)
     {
     case "setDataWindowWidth":
         NPointF ptViewPoint = new NPointF(float.Parse(args.Command.Arguments["x"] as string), 0f);
         DataWindowWidth = double.Parse(args.Command.Arguments["width"] as string);
         UpdateDataWindow(webControlId, context, state, ptViewPoint);
         break;
     }
 }
            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 OnAsyncRefresh(string webControlId, System.Web.HttpContext context, NStateObject state, EventArgs args)
            {
                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);
            }
 public override void OnAsyncDoubleClick(string webControlId, System.Web.HttpContext context, NStateObject state, NCallbackMouseEventArgs args)
 {
     DoSimulateResponseDelay();
     ChangeCurrentShapeColor(webControlId, context, state, args, Color.Red);
 }
 public override void OnAsyncMouseMove(string webControlId, System.Web.HttpContext context, NStateObject state, NCallbackMouseEventArgs args)
 {
     DoSimulateResponseDelay();
     ChangeCurrentShapeShadow(webControlId, context, state, args);
 }
Esempio n. 24
0
            public override void OnAsyncDoubleClick(string webControlId, System.Web.HttpContext context, NStateObject state, NCallbackMouseEventArgs args)
            {
                // init configuration
                InitializeConfigurationFields();

                //	clear the board
                Clear(state);
            }
            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);
                }
            }
Esempio n. 26
0
            public override void OnAsyncMouseUp(string webControlId, System.Web.HttpContext context, NStateObject state, NCallbackMouseEventArgs args)
            {
                // init configuration
                InitializeConfigurationFields();

                //	toggle the underlying cell
                NRectangleShape cell = HitTestCell(state, args);

                if (cell == null)
                {
                    return;
                }

                if ((CellState)cell.Tag == CellState.PinnedAlive)
                {
                    cell.Tag = CellState.Alive;
                }
                else if ((CellState)cell.Tag == CellState.PinnedDead)
                {
                    cell.Tag = CellState.Dead;
                }
                else
                {
                    return;
                }

                UpdateStyles(state);
            }
            public override void OnAsyncClick(string webControlId, System.Web.HttpContext context, NStateObject state, NCallbackMouseEventArgs args)
            {
                NPointF ptViewPoint = new NPointF((float)args.Point.X, 0);

                UpdateDataWindow(webControlId, context, state, ptViewPoint);
            }
Esempio n. 28
0
            public override void OnAsyncMouseMove(string webControlId, System.Web.HttpContext context, NStateObject state, NCallbackMouseEventArgs args)
            {
                // init configuration
                InitializeConfigurationFields();

                //	highlight underlying cell
                NRectangleShape cell = HitTestCell(state, args);

                if (cell == null)
                {
                    return;
                }

                HighliteCell(state, cell);
            }
            void UpdateDataWindow(string webControlId, System.Web.HttpContext context, NStateObject state, NPointF ptViewPoint)
            {
                NChartSessionStateObject chartState = state as NChartSessionStateObject;
                NRootPanel      rootPanel           = chartState.Document.RootPanel;
                NCartesianChart chart         = rootPanel.Charts[0] as NCartesianChart;
                NVector2DD      vecScalePoint = new NVector2DD();
                NAxis           xAxis         = chart.Axis(StandardAxis.PrimaryX);
                NAxis           yAxis         = chart.Axis(StandardAxis.PrimaryY);

                using (NChartRasterView view = new NChartRasterView(chartState.Document, chartState.Size, NResolution.ScreenResolution))
                {
                    view.RecalcLayout();

                    NViewToScale2DTransformation viewToScale = new NViewToScale2DTransformation(
                        view.Context,
                        chart,
                        (int)StandardAxis.PrimaryX,
                        (int)StandardAxis.PrimaryY
                        );

                    if (viewToScale.Transform(ptViewPoint, ref vecScalePoint))
                    {
                        double rangeMin = vecScalePoint.X - DataWindowWidth / 2;
                        rangeMin = xAxis.Scale.ViewRange.GetValueInRange(rangeMin);

                        double rangeMax = rangeMin + DataWindowWidth;
                        rangeMax = xAxis.Scale.ViewRange.GetValueInRange(rangeMax);

                        rangeMin = rangeMax - DataWindowWidth;

                        NRangeSelection selection = chart.RangeSelections[0] as NRangeSelection;
                        selection.HorizontalAxisRange = new NRange1DD(rangeMin, rangeMax);
                        selection.VerticalAxisRange   = new NRange1DD(-waveDataWave1Factor, waveDataWave1Factor);
                    }
                }
            }
Esempio n. 30
0
            public override void OnAsyncRefresh(string webControlId, System.Web.HttpContext context, NStateObject state, EventArgs args)
            {
                // init configuration
                InitializeConfigurationFields();

                IterateOneTurn(state);
            }