예제 #1
0
 protected void RunDrawTest(Action action)
 {
     var deferredAction = new DrawAction(action);
     lock (drawActions)
     {
         drawActions.Add(deferredAction);
     }
     deferredAction.WaitResult();
 }
예제 #2
0
파일: Draw.cs 프로젝트: NerdDev/Hackmobile
 public static DrawAction <T> IsTypeThen <T>(GridType item, DrawAction <T> then, bool not = false)
     where T : IGridSpace
 {
     return((arr, x, y) =>
     {
         if (arr.IsType(x, y, item))
         {
             return then(arr, x, y);
         }
         return true;
     });
 }
예제 #3
0
        private void dgActions_SelectionChanged(object sender, EventArgs e)
        {
            if (dgActions.SelectedCells.Count == 0)
            {
                return;
            }
            int index = dgActions.SelectedCells[0].RowIndex;

            if (actionsList[index] is DrawAction daction)
            {
                activeAction = daction;
                dgObjects.Rows.Clear();
                switch (dgActions.SelectedCells[0].ColumnIndex)
                {
                case 1:
                    foreach (DrawableObject obj in activeAction.ShadowState)
                    {
                        dgObjects.Rows.Add(obj.Name, obj.ObjNumber, obj.zInstance);
                    }
                    break;

                case 2:
                    foreach (DrawableObject obj in activeAction.AfterAction)
                    {
                        dgObjects.Rows.Add(obj.Name, obj.ObjNumber, obj.zInstance);
                    }
                    break;

                case 4:
                case 5:
                    foreach (DrawableObject obj in activeAction.Selection)
                    {
                        dgObjects.Rows.Add(obj.Name, obj.ObjNumber, obj.zInstance);
                    }
                    break;

                default:
                    foreach (DrawableObject obj in activeAction.DrawRef)
                    {
                        dgObjects.Rows.Add(obj.Name, obj.ObjNumber, obj.zInstance);
                    }
                    break;
                }
            }
            else
            {
                activeAction = null;
                dgObjects.Rows.Clear();
            }
            pDrawRef.Refresh();
            pShadow.Refresh();
            pAfterAction.Refresh();
        }
예제 #4
0
 public BoxedAction(DrawAction <T> frontAction, DrawAction <T> middleAction, DrawAction <T> backAction)
 {
     this.FrontAction      = frontAction;
     this.FrontLeftAction  = frontAction;
     this.FrontRightAction = frontAction;
     this.LeftAction       = middleAction;
     this.RightAction      = middleAction;
     this.UnitAction       = middleAction;
     this.BackAction       = backAction;
     this.BackLeftAction   = backAction;
     this.BackRightAction  = backAction;
 }
예제 #5
0
 public BoxedAction(DrawAction <T> frontAction, DrawAction <T> restAction)
 {
     this.FrontAction      = frontAction;
     this.FrontLeftAction  = frontAction;
     this.FrontRightAction = frontAction;
     this.LeftAction       = restAction;
     this.RightAction      = restAction;
     this.UnitAction       = restAction;
     this.BackAction       = restAction;
     this.BackLeftAction   = restAction;
     this.BackRightAction  = restAction;
 }
예제 #6
0
        public void Draw(DrawAction action)
        {
            if (this.undoHover != null)
            {
                ApplyAction(this.undoHover);
            }
            DrawAction undoAction = ApplyAction(action);

            this.UndoQueue.Push(undoAction);
            this.RedoQueue.Clear();
            this.undoHover = null;
        }
예제 #7
0
        /// <summary>
        /// is the main method of this object. See also <see cref="Entity.CompileDraw(OpenGlDevice)"/>.
        /// </summary>
        /// <param name="Device">Device in which it willl be compiled.</param>
        /// <param name="Draw">a event, which holds the drawings.</param>
        public static MeshContainer CreateMeshes(OpenGlDevice Device, DrawAction Draw)
        {
            // sollte nur von compilesnapbuffer aufgerufen werden !!!! und erstellt die triangles
            bool Compiling = Entity.Compiling;

            if (Compiling)
            {
                MeshCreator.Push();
            }
            bool SaveCompiling = Entity.Compiling;

            // Entity.Compiling = true; // Checken braucht es wegen line snap
            if (Selector.StoredSnapItems.Count == 0)
            {
                Selector.StoredSnapItems.Add(null); // braucht es nicht
            }
            MeshListCurrent = new MeshContainer();  // braucht es nicht
            MeshIndices.Clear();                    // braucht es wahrscheinlich  nicht


            RenderKind R = Device.RenderKind;// wieder heraus

            Draw(Device);

            Renew();
            Device.RenderKind = R;
            Entity.Compiling  = SaveCompiling;
            MeshContainer Result = MeshListCurrent;

            //    MeshListCurrent.MySnapItem = new MeshSnapItem(MeshListCurrent);
            Device.RenderKind = RenderKind.SnapBuffer;
            TriangleList TL = new TriangleList();

            for (int i = 0; i < MeshListCurrent.Progs.Count; i++)
            {
                if (MeshListCurrent.Progs[i] is Mesh)
                {
                    Mesh M = MeshListCurrent.Progs[i] as Mesh;
                    M.getTriangles(TL);
                }
            }
            TriangleArrays TA = TL.ToArrays();



            Device.RenderKind = R;
            if (Compiling)
            {
                MeshCreator.Pop();
            }
            return(Result);
        }
예제 #8
0
    public static void DrawPotentialDoors(this Container2D <GenSpace> arr, DrawAction <GenSpace> action)
    {
        DrawAction <GenSpace> check = Draw.CanDrawDoor();

        arr.DrawAll(new DrawAction <GenSpace>((arr2, x, y) =>
        {
            if (check(arr2, x, y))
            {
                action(arr2, x, y);
            }
            return(true);
        }));
    }
예제 #9
0
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            Window.Title          = "T Rex Runner";
            IsMouseVisible        = false;
            MainForm = (Form)Control.FromHandle(Window.Handle);

            score           = 0;
            drawAction      = DrawAction.Crouch;
            runningFrames   = RunningFrames.FirstFrame;
            crouchingFrames = CrouchingFrames.FirstFrame;
        }
예제 #10
0
        public virtual void PerfromDrawAction(SpriteBatch b)
        {
            if (OutOfBounds)
            {
                return;
            }

            DrawAction?.Invoke(b, this);

            foreach (UIElement child in Children)
            {
                child.PerfromDrawAction(b);
            }
        }
예제 #11
0
 public override bool DrawAll(DrawAction <T> call)
 {
     foreach (KeyValuePair <int, Dictionary <int, T> > row in multimap)
     {
         foreach (KeyValuePair <int, T> val in row.Value)
         {
             if (!call(this, val.Key, row.Key))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
예제 #12
0
        private void HandleEndDrawLine(Point currentMousePosition)
        {
            var line = new Line
            {
                X1     = _lineStartPoint.X,
                Y1     = _lineStartPoint.Y,
                X2     = currentMousePosition.X,
                Y2     = currentMousePosition.Y,
                Stroke = Brushes.Green
            };

            MyCanvas.Children.Add(line);
            _drawAction = DrawAction.StartDrawLine;
        }
예제 #13
0
        private DrawAction ApplyAction(DrawAction action)
        {
            Stack <Tile> previousTiles = new Stack <Tile>();

            foreach (Tile tile in action.Tiles)
            {
                Tile previousTile = Draw(tile);
                if (previousTile != null)
                {
                    previousTiles.Push(previousTile);
                }
            }
            DrawAction revertAction = new DrawAction(action.Name, previousTiles);

            return(revertAction);
        }
예제 #14
0
 private void CheckUserInput(KeyboardState CurrentKeyState, KeyboardState OldKeyState)
 {
     if (CurrentKeyState.IsKeyDown(Keys.S) || CurrentKeyState.IsKeyDown(Keys.Down))
     {
         drawAction = DrawAction.Crouch;
     }
     else if (CurrentKeyState.IsKeyDown(Keys.Space) || CurrentKeyState.IsKeyDown(Keys.Up) || CurrentKeyState.IsKeyDown(Keys.W))
     {
         Jumping    = true;
         drawAction = DrawAction.Idle;
     }
     else
     {
         drawAction = DrawAction.Running;
     }
 }
예제 #15
0
파일: Draw.cs 프로젝트: NerdDev/Hackmobile
 /*
  * Walk edges and if alternates more than twice, it's blocking
  */
 public static DrawAction <T> Blocking <T>(DrawAction <T> action)
 {
     return((arr, x, y) =>
     {
         int count = 0;
         bool status = action(arr, x - 1, y - 1); // Bottom left
         DrawAction <T> func = (arr2, x2, y2) =>
         {
             if (action(arr2, x2, y2) != status)
             {
                 status = !status;
                 return ++count > 2;
             }
             return false;
         };
         if (func(arr, x, y - 1))
         {
             return true;                      // Bottom
         }
         if (func(arr, x + 1, y - 1))
         {
             return true;                          // Bottom right
         }
         if (func(arr, x + 1, y))
         {
             return true;                      // Right
         }
         if (func(arr, x + 1, y + 1))
         {
             return true;                          // Top Right
         }
         if (func(arr, x, y + 1))
         {
             return true;                      // Top
         }
         if (func(arr, x - 1, y + 1))
         {
             return true;                          // Top Left
         }
         if (func(arr, x - 1, y))
         {
             return true;                      // Left
         }
         return false;
     });
 }
예제 #16
0
 public override bool DrawAll(DrawAction <T> call)
 {
     for (int y = 0; y < arr.GetLength(0); y++)
     {
         for (int x = 0; x < arr.GetLength(1); x++)
         {
             if (present[y, x])
             {
                 if (!call(this, x, y))
                 {
                     return(false);
                 }
             }
         }
     }
     return(true);
 }
예제 #17
0
 internal void SetDrawAction(DrawAction drawAction)
 {
     switch(drawAction)
     {
         case DrawAction.Intro:
             this.drawAction = this.DrawActionIntro;
             this.Duration = 60 * OneNanoSecond;
             break;
         case DrawAction.Main:
             this.drawAction = this.DrawActionMain;
             Duration = PluginProxy.Duration;
             break;
         case DrawAction.Outro:
             this.drawAction = this.DrawActionOutro;
             this.Duration = 60 * OneNanoSecond;
             break;
     }
 }
예제 #18
0
        //Add an action to the actions collection
        public void AddDrawAction(RecordableAction.ActionTypes actionType, DrawingSheet sheet, List <DrawableObject> changingObjects, List <DrawableObject> selectedObjects, int focusIndex)
        {
            //Erase redo actions
            if (ActionIndex < Actions.Count)
            {
                if (SavedIndex > ActionIndex)
                {
                    SavedIndex = -1;
                }
                Actions.RemoveRange(ActionIndex, Actions.Count - ActionIndex);
            }
            //Create the action object
            var action = new DrawAction(actionType, sheet, changingObjects, selectedObjects, focusIndex);

            sheet.Sketch.PerformAction(action);
            //Add new action
            Actions.Add(action);
            ActionIndex++;
        }
예제 #19
0
        internal void SetDrawAction(DrawAction drawAction)
        {
            switch (drawAction)
            {
            case DrawAction.Intro:
                this.drawAction = this.DrawActionIntro;
                this.Duration   = 60 * OneNanoSecond;
                break;

            case DrawAction.Main:
                this.drawAction = this.DrawActionMain;
                Duration        = PluginProxy.Duration;
                break;

            case DrawAction.Outro:
                this.drawAction = this.DrawActionOutro;
                this.Duration   = 60 * OneNanoSecond;
                break;
            }
        }
예제 #20
0
    public static List <Value2D <GenSpace> > PlaceSomeDoors(this Container2D <GenSpace> arr, IEnumerable <Point> points, Theme theme, System.Random rand, int desiredWallToDoorRatio = -1, Point shift = null)
    {
        if (desiredWallToDoorRatio < 0)
        {
            desiredWallToDoorRatio = LevelGenerator.desiredWallToDoorRatio;
        }
        var     acceptablePoints   = new MultiMap <GenSpace>();
        Counter numPoints          = new Counter();
        DrawAction <GenSpace> call = Draw.Count <GenSpace>(numPoints).And(Draw.CanDrawDoor().IfThen(Draw.AddTo(acceptablePoints)));

        if (shift != null)
        {
            call = call.Shift <GenSpace>(shift.x, shift.y);
        }
        arr.DrawPoints(points, call);
        if (DoorRatioPicker == null)
        {
            DoorRatioPicker = new ProbabilityList <int>();
            DoorRatioPicker.Add(-2, .25);
            DoorRatioPicker.Add(-1, .5);
            DoorRatioPicker.Add(0, 1);
            DoorRatioPicker.Add(1, .5);
            DoorRatioPicker.Add(2, .25);
        }
        int numDoors = numPoints / desiredWallToDoorRatio;

        numDoors += DoorRatioPicker.Get(rand);
        if (numDoors <= 0)
        {
            numDoors = 1;
        }
        List <Value2D <GenSpace> > pickedPts = acceptablePoints.GetRandom(rand, numDoors, 1);

        foreach (Point picked in pickedPts)
        {
            arr.SetTo(picked, GridType.Door, theme);
        }
        return(pickedPts);
    }
예제 #21
0
    protected bool FindNextPathPoints(Container2D <GenSpace> map,
                                      Container2D <GenSpace> runningConnected,
                                      out LayoutObject hit,
                                      DrawAction <GenSpace> pass,
                                      Queue <Value2D <GenSpace> > curQueue,
                                      Container2D <bool> curVisited,
                                      out Value2D <GenSpace> startPoint,
                                      out Value2D <GenSpace> endPoint)
    {
        if (!map.DrawBreadthFirstSearch(
                curQueue, curVisited, false,
                Draw.IsType <GenSpace>(GridType.NULL),
                pass,
                out endPoint))
        {
            hit        = null;
            startPoint = null;
            return(false);
        }
        if (!Container.GetObjAt(endPoint, out hit))
        {
            startPoint = null;
            return(false);
        }
        Container2D <bool>          hitVisited;
        Queue <Value2D <GenSpace> > hitQueue;

        ConstructBFS(hit, out hitQueue, out hitVisited);
        curQueue.Enqueue(hitQueue);
        curVisited.PutAll(hitVisited);
        return(map.DrawBreadthFirstSearch(
                   hitQueue, hitVisited, false,
                   Draw.IsType <GenSpace>(GridType.NULL),
                   pass.And(Draw.ContainedIn(runningConnected)),
                   out startPoint));
    }
예제 #22
0
 public void LoadMe(Prodef domainObject, UnitOfWork currentUnitOfWork)
 {
     Prodef prodef = domainObject;
     if (prodef == null)
     {
         throw new ArgumentOutOfRangeException("domainObject");
     }
     if (this.mGraphDoc != null)
     {
         this.mGraphDoc.Reset();
     }
     else
     {
         this.InitGraphDoc();
     }
     if (this.mProDefDoc == null)
     {
         this.mProDefDoc = new ProDefDoc();
     }
     this.mProDefDoc.Load(prodef, currentUnitOfWork);
     this.mProDefDoc.BuildGraphDoc(this.mGraphDoc, this.img32);
     this.mAction = DrawAction.SingleSelect;
 }
예제 #23
0
 private void HandleStartDrawLine(Point currentMousePosition)
 {
     _lineStartPoint = currentMousePosition;
     _drawAction     = DrawAction.EndDrawLine;
 }
예제 #24
0
 private void StartDrawingCircles(object sender, RoutedEventArgs e)
 {
     _drawAction = DrawAction.DrawCircle;
 }
예제 #25
0
 private void StartDrawingSquares(object sender, RoutedEventArgs e)
 {
     _drawAction = DrawAction.DrawSquare;
 }
예제 #26
0
 private void StartDrawingLines(object sender, RoutedEventArgs e)
 {
     _drawAction = DrawAction.StartDrawLine;
 }
예제 #27
0
 private void Clear(object sender, RoutedEventArgs e)
 {
     MyCanvas.Children.Clear();
     _drawAction = DrawAction.None;
 }
예제 #28
0
 internal void SetDrawAction(DrawAction drawAction)
 {
     frm.SetDrawAction(drawAction);
 }
예제 #29
0
 public override bool DrawAll(DrawAction <GenSpace> call)
 {
     return(Grids.DrawAll(call));
 }
예제 #30
0
 public void DrawOnLayer(string layer, DrawAction drawAction)
 {
     drawActions[layer].Add(drawAction);
 }
예제 #31
0
        private void toolBar1_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
        {
            foreach (ToolBarButton button in this.toolBar1.Buttons)
            {
                if (!button.Equals(e.Button))
                {
                    button.Pushed = false;
                }
            }
            switch (e.Button.Tag.ToString())
            {
                case "select":
                    this.mAction = DrawAction.SingleSelect;
                    return;

                case "delete":
                    this.mGraphDoc.RemoveUnit(this.mGraphDoc.SelectedUnit);
                    return;

                case "arrowline":
                    this.mAction = DrawAction.Draw;
                    this.mDrawType = DrawType.ArrowLine;
                    return;
            }
            this.mImageIndex = int.Parse(e.Button.Tag.ToString());
            this.mAction = DrawAction.Draw;
            this.mDrawType = DrawType.Node;
            this.mNodeType = (NodeType) int.Parse(e.Button.Tag.ToString());
        }
예제 #32
0
 internal void SetAction(DrawAction drawAction)
 {
     this.drawAction = drawAction;
     Create();
 }
예제 #33
0
 internal void SetAction(DrawAction drawAction)
 {
     this.drawAction = drawAction;
     Create();
 }
예제 #34
0
    protected void ConfirmConnection()
    {
        #region DEBUG
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            BigBoss.Debug.printHeader(Logs.LevelGen, "Confirm Connections");
        }
        #endregion
        DrawAction <GenSpace> passTest = Draw.ContainedIn <GenSpace>(Path.PathTypes).Or(Draw.CanDrawDoor());
        var layoutCopy            = Container.GetGrid().Array;
        List <LayoutObject> rooms = new List <LayoutObject>(Layout.Rooms.Cast <LayoutObject>());
        var runningConnected      = Container2D <GenSpace> .CreateArrayFromBounds(layoutCopy);

        // Create initial queue and visited
        var startingRoom = rooms.Take();
        startingRoom.GetConnectedGrid().DrawAll(Draw.AddTo(runningConnected));
        Container2D <bool>          visited;
        Queue <Value2D <GenSpace> > queue;
        ConstructBFS(startingRoom, out queue, out visited);
        visited = visited.Array;
        LayoutObject fail;
        while (!startingRoom.ConnectedTo(rooms, out fail))
        {
            // Find start points
            #region DEBUG
            if (BigBoss.Debug.logging(Logs.LevelGen))
            {
                runningConnected.ToLog(Logs.LevelGen, "Source Setup");
                fail.ToLog(Logs.LevelGen, "Failed to connect to this");
            }
            #endregion
            Value2D <GenSpace> startPoint;
            Value2D <GenSpace> endPoint;
            LayoutObject       hit;
            if (!FindNextPathPoints(layoutCopy, runningConnected, out hit, passTest, queue, visited, out startPoint, out endPoint))
            {
                throw new ArgumentException("Cannot find path to fail room");
            }
            // Connect
            #region DEBUG
            if (BigBoss.Debug.logging(Logs.LevelGen))
            {
                layoutCopy.SetTo(startPoint, GridType.INTERNAL_RESERVED_CUR, Theme);
                layoutCopy.ToLog(Logs.LevelGen, "Largest after putting blocked");
                BigBoss.Debug.w(Logs.LevelGen, "Start Point:" + startPoint);
            }
            #endregion
            var hitConnected = hit.GetConnectedGrid();
            var stack        = layoutCopy.DrawJumpTowardsSearch(
                startPoint.x,
                startPoint.y,
                3,
                5,
                Draw.IsType <GenSpace>(GridType.NULL).And(Draw.Inside <GenSpace>(layoutCopy.Bounding.Expand(5))),
                passTest.And(Draw.ContainedIn(hitConnected)),
                Rand,
                endPoint,
                true);
            var path = new Path(stack);
            if (path.Valid)
            {
                #region DEBUG
                if (BigBoss.Debug.logging(Logs.LevelGen))
                {
                    path.Bake(null).ToLog(Logs.LevelGen, "Connecting Path");
                }
                #endregion
                path.Simplify();
                Point        first = path.FirstEnd;
                Point        second = path.SecondEnd;
                LayoutObject leaf1, leaf2;
                LayoutObject pathObj = path.Bake(Theme);
                Container.ConnectTo(first, pathObj, first, out leaf1, out pathObj);
                Container.ConnectTo(second, pathObj, second, out leaf2, out pathObj);
                if (leaf1[first].Type == GridType.Wall)
                {
                    leaf1.SetTo(first, GridType.Door, Theme);
                }
                if (leaf2[second].Type == GridType.Wall)
                {
                    leaf2.SetTo(second, GridType.Door, Theme);
                }
                foreach (var v in pathObj)
                {
                    layoutCopy[v] = v.val;
                    runningConnected.Put(v);
                    if (!visited[v])
                    {
                        queue.Enqueue(v);
                    }
                    visited[v] = true;
                }
                foreach (var p in path)
                {
                    layoutCopy.DrawAround(p.x, p.y, false, Draw.IsType <GenSpace>(GridType.NULL).IfThen(Draw.SetTo(pathObj, GridType.Floor, Theme).And(Draw.SetTo(GridType.Floor, Theme))));
                    layoutCopy.DrawCorners(p.x, p.y, new DrawAction <GenSpace>((arr, x, y) =>
                    {
                        if (!arr.IsType(x, y, GridType.NULL))
                        {
                            return(false);
                        }
                        return(arr.Cornered(x, y, Draw.IsType <GenSpace>(GridType.Floor)));
                    }).IfThen(Draw.SetTo(pathObj, GridType.Floor, Theme)));
                }
                Container.Objects.Add(pathObj);
                hitConnected.DrawAll(Draw.AddTo(runningConnected));
                #region DEBUG
                if (BigBoss.Debug.logging(Logs.LevelGen))
                {
                    Container.ToLog(Logs.LevelGen, "Final Connection");
                }
                #endregion
            }
            else
            {
                throw new ArgumentException("Cannot create path to hit room");
            }
        }
        #region DEBUG
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            BigBoss.Debug.printFooter(Logs.LevelGen, "Confirm Connections");
        }
        #endregion
    }
 internal void SetDrawAction(DrawAction drawAction)
 {
     frm.SetDrawAction(drawAction);
 }
예제 #36
0
    public List <Bounding> Find()
    {
        List <Bounding> ret = new List <Bounding>();

        if (_width >= _arr.Width || _height >= _arr.Height)
        {
            return(ret);
        }

        if (_width == 1 && _height == 1)
        {
            return(SingleFind());
        }

        // Initialize
        _x              = _scope.XMin;
        _y              = _scope.YMin;
        _lastPassedX    = int.MaxValue;
        _lastTestedX    = _scope.XMin;
        _lastTestedY    = _scope.YMin;
        xShift          = _arr.Bounding.XMin;
        _lastPassedXArr = new bool[_arr.Width];

        if (_tester.StrokeAction == null && _width > 3 && _height > 3)
        { // Just unit
            FindSkip(ret);
        }
        else if (_tester.StrokeAction != null && _tester.UnitAction != null && _width > 5 && _height > 5)
        { // Unit and stroke with optimization
            // Find non-stroke options, then test stroke
            DrawAction <T> stroke = _tester.StrokeAction;
            _tester.StrokeAction = null;
            _width  -= 2;
            _height -= 2;
            FindSkip(ret);
            _width  += 2;
            _height += 2;
            _tester.StrokeAction = stroke;
            List <Bounding> retTmp = new List <Bounding>(ret);
            ret.Clear();
            StrokedAction <T> strokeTest = new StrokedAction <T>()
            {
                StrokeAction = _tester.StrokeAction
            };
            foreach (Bounding b in retTmp)
            {
                b.Expand(1);
                if (_arr.DrawRect(b.XMin, b.XMax, b.YMin, b.YMax, strokeTest))
                {
                    ret.Add(b);
                }
            }
        }
        else
        {
            FindNormal(ret);
        }

        if (_tryFlipped && ret.Count == 0)
        { // Flip and try again
            _tryFlipped = false;
            int tmp = _width;
            _width  = _height;
            _height = tmp;
            return(Find());
        }
        return(ret);
    }