Beispiel #1
0
        /**********************************************************************
         *********************************************************************/
        private static void CalculateNeededVariables()
        {
            /*important: the coordinate system starts in the upper left corner*/
            strokeWidth = 5;
            centerX     = info.Width / 2;
            centerY     = info.Height / 2;
            x1          = strokeWidth / 2;
            y1          = strokeWidth / 2;
            x2          = info.Width - strokeWidth / 2;
            y2          = info.Height - strokeWidth / 2;

            //other needed stuff
            textSize          = 0.05f;
            step              = 0.2f;
            backgWindowLength = xText(0.28f) + Deadlock.GetVectorC().Length *xText(0.05f);
            float xLengthLeftInCell = x2 - backgWindowLength * 3;

            spaceBetweenBackgWindows = xLengthLeftInCell / 4.0f;

            //TODO: should not be smaller than 0
            //Debug.WriteLine(string.Format($" spaceBetweenBackgWindows: {spaceBetweenBackgWindows}"));

            xStartBackgWindow1 = spaceBetweenBackgWindows;
            xStartBackgWindow2 = xStartBackgWindow1 + backgWindowLength + spaceBetweenBackgWindows;
            xStartBackgWindow3 = xStartBackgWindow2 + backgWindowLength + spaceBetweenBackgWindows;

            //Debug.WriteLine("t: " + Deadlock.GetTotalProcesses());
            backgWindowHeight = Deadlock.GetTotalProcesses() * yPercent(step);
            float yLengthLeftInCell = y2 - backgWindowHeight;

            yStartBackgWindow = yLengthLeftInCell / 2.0f;
            //Debug.WriteLine(string.Format($" centerX: {centerX}, centerY {centerY}, x1: {x1}, x2: {x2}, y1: {y1}, y2: {y2}"));
        }
Beispiel #2
0
        //custom contructor unfortunately not possible...
        public DeadlockViewCell()
        {
            this.skiaview = new SKCanvasView();
            this.skiaview.BackgroundColor = App._viewBackground;
            this.skiaview.PaintSurface   += PaintSurface;
            this.View = this.skiaview;

            this.cellNumber       = Deadlock.GetCellNumber();
            this.vectorE          = Deadlock.GetVectorE();
            this.vectorB          = Deadlock.GetVectorB();
            this.vectorC          = Deadlock.GetVectorC();
            this.vectorCProcesses = Deadlock.GetVectorCProcesses();
            this.vectorBProcesses = Deadlock.GetVectorBProcesses();
            this.totalProcesses   = Deadlock.GetTotalProcesses();

            //NOTE: Lists and Arrays in C# do not stay the same
            //and are recreated a lot since they're not by reference.
            //somehow bool, int etc stay the same for this viewcellobject
            //once they're assinged
            this.P0done = Deadlock.P0done;
            this.P1done = Deadlock.P1done;
            this.P2done = Deadlock.P2done;
            this.P3done = Deadlock.P3done;
            this.P4done = Deadlock.P4done;

            touchable = true;

            if (cellNumber != -1)
            {
                this.history = Deadlock.GetHistory(cellNumber, 0);
                this.vectorA = Deadlock.GetHistory(cellNumber, 1);
                //.WriteLine("history of cell " + cellNumber + ": " + history);
                //Deadlock.deadLockViewCellCansvasList.Add(this.skiaview);
                //Deadlock.deadLockViewCellTouchableList.Add(this.touchable);
            }
            else
            {
                this.vectorA = Deadlock.GetVectorA();
            }
        }
Beispiel #3
0
        /* TOUCH SENISITIVIY
         **********************************************************************
         *********************************************************************/
        private void OnTouch(object sender, SKTouchEventArgs e)
        {
            switch (e.ActionType)
            {
            case SKTouchAction.Pressed:
                //Debug.WriteLine(this.Id);

                if (rect_CP0.Contains(e.Location))
                {
                    Deadlock.CPx_Clicked(ref this.skiaview, ref this.touchable,
                                         0, this.vectorA);
                }
                else if (rect_CP1.Contains(e.Location))
                {
                    Deadlock.CPx_Clicked(ref this.skiaview, ref this.touchable,
                                         1, this.vectorA);
                }
                else if (rect_CP2.Contains(e.Location))
                {
                    Deadlock.CPx_Clicked(ref this.skiaview, ref this.touchable,
                                         2, this.vectorA);
                }
                else if (rect_CP3.Contains(e.Location))
                {
                    Deadlock.CPx_Clicked(ref this.skiaview, ref this.touchable,
                                         3, this.vectorA);
                }
                else if (rect_CP4.Contains(e.Location))
                {
                    Deadlock.CPx_Clicked(ref this.skiaview, ref this.touchable,
                                         4, this.vectorA);
                }
                break;
            }

            e.Handled = true;
        }
Beispiel #4
0
        private void DrawCalculation()
        {
            float starty    = 0.21f;
            float y1Backg   = 0.10f;
            float stepBackg = 0.20f;

            // vectors to display
            String oldVA = "";

            if (cellNumber == 0)
            {
                oldVA = Deadlock.GetVectorA();
            }
            else
            {
                oldVA = Deadlock.GetHistory(cellNumber - 1, 1);
            }
            String currVB = vectorBProcesses[Int16.Parse(history)];
            String currVC = vectorCProcesses[Int16.Parse(history)];
            String currVA = vectorA;

            //Fromat text
            String resultTextVAold = "Aold   = ( ";
            String resultTextVB    = "B(P" + history + ") = ( ";
            String resultTextVC    = "C(P" + history + ") = ( ";
            String resultTextVAnew = "Anew = ( ";
            String space           = "  ";

            for (int j = 0; j < currVB.Length; j++)
            {
                if (j == currVB.Length - 1)
                {
                    space = " )";
                }
                resultTextVB    = resultTextVB + currVB[j] + space;
                resultTextVC    = resultTextVC + currVC[j] + space;
                resultTextVAnew = resultTextVAnew + currVA[j] + space;
                resultTextVAold = resultTextVAold + oldVA[j] + space;
            }

            //Draw green background
            SKRect sk_rBackground0 = new SKRect(
                xStartBackgWindow1,
                yPercent(y1Backg),
                xStartBackgWindow1 + backgWindowLength,
                yPercent(y1Backg) + yPercent(stepBackg));         //left , top, right, bottom

            canvas.DrawRect(sk_rBackground0, sk_BackgroundWhite); //left, top, right, bottom, color
            canvas.DrawRect(sk_rBackground0, sk_BackgroundGreen); //left, top, right, bottom, color

            // Aold
            SKPoint textPosition0 = new SKPoint(
                xStartBackgWindow1 + xText(0.02f),
                yPercent(starty));

            canvas.DrawText(resultTextVAold, textPosition0, sk_blackText);

            //Draw yellow background
            SKRect sk_rBackground = new SKRect(
                xStartBackgWindow1,
                yPercent(y1Backg) + yPercent(stepBackg),
                xStartBackgWindow1 + backgWindowLength,
                yPercent(y1Backg) + yPercent(stepBackg * 2));     //left , top, right, bottom

            canvas.DrawRect(sk_rBackground, sk_BackgroundWhite);  //left, top, right, bottom, color
            canvas.DrawRect(sk_rBackground, sk_BackgroundYellow); //left, top, right, bottom, color
            // C(x)

            SKPoint textPosition2 = new SKPoint(
                xStartBackgWindow1 + xText(0.02f),
                yPercent(starty) + yPercent(step));

            canvas.DrawText(resultTextVC, textPosition2, sk_blackText);

            //Draw red background
            SKRect sk_rBackground2 = new SKRect(
                xStartBackgWindow1,
                yPercent(y1Backg) + yPercent(stepBackg * 2),
                xStartBackgWindow1 + backgWindowLength,
                yPercent(y1Backg) + yPercent(stepBackg * 3));     //left , top, right, bottom

            canvas.DrawRect(sk_rBackground2, sk_BackgroundWhite); //left, top, right, bottom, color
            canvas.DrawRect(sk_rBackground2, sk_BackgroundRed);   //left, top, right, bottom, color
            // B(x)
            SKPoint textPosition3 = new SKPoint(
                xStartBackgWindow1 + xText(0.02f),
                yPercent(starty) + yPercent(step * 2));

            canvas.DrawText(resultTextVB, textPosition3, sk_blackText);

            //Draw green background
            SKRect sk_rBackground4 = new SKRect(
                xStartBackgWindow1,
                yPercent(y1Backg) + yPercent(stepBackg * 3),
                xStartBackgWindow1 + backgWindowLength,
                yPercent(y1Backg) + yPercent(stepBackg * 4));     //left , top, right, bottom

            canvas.DrawRect(sk_rBackground4, sk_BackgroundWhite); //left, top, right, bottom, color
            canvas.DrawRect(sk_rBackground4, sk_BackgroundGreen); //left, top, right, bottom, color
            // Anew
            SKPoint textPosition4 = new SKPoint(
                xStartBackgWindow1 + xText(0.02f),
                yPercent(starty) + yPercent(step * 3));

            canvas.DrawText(resultTextVAnew, textPosition4, sk_blackText);
        }