public static void SyncActiveDrawPie(MyDrawParam myDrawParam)//直接分配资源的三个资源异步绘制
        {
            int Tick = 0;

            //if(angleEnd==0)

            //Console.WriteLine("被调用");
            while (true)
            {
                if (Tick > myDrawParam.angleIncrease)
                {
                    return;
                    //Console.WriteLine("Finish");
                }
                if (Tick < 270 - myDrawParam.angleBegin)
                {
                    myDrawParam.graphics.FillPie(myDrawParam.mainBrush, myDrawParam.positionRectangle, myDrawParam.angleBegin + Tick, myDrawParam.angleIncrease > Tick + 5 ? 5 : myDrawParam.angleIncrease - Tick);
                }
                else
                {
                    myDrawParam.graphics.FillPie(myDrawParam.backupBrush, myDrawParam.positionRectangle, myDrawParam.angleBegin + Tick, myDrawParam.angleIncrease > Tick + 5 ? 5 : myDrawParam.angleIncrease - Tick);
                }
                Tick += 5;
                Thread.Sleep(myDrawParam.interval);
            }
        }
        public static void AsyncActiveDrawPie(MyDrawParam myDrawParam)//三个资源同步绘制
        {
            Timer timer = new Timer();

            timer.Interval = myDrawParam.interval;
            int Tick = 0;

            timer.Tick += new EventHandler((o, e) => AsyncactivePieEvent(myDrawParam, timer, ref Tick));
            timer.Start();
        }
示例#3
0
        public void drawSingleBox(int index, Resourse demand, Resourse historyHave, Resourse Max, Resourse available, int flag)//按照运行给出的数据动态展示算法运行到的当前进程的变化情况
        {
            //                float angleA = Allocation.A * 360 / (Max.A == 0 ? 1 : Max.A);
            //listBox1.Items.Add("myDrawPie被调用");
            Console.WriteLine(pictureBoxes[index].AccessibilityObject);

            Graphics  g          = this.pictureBoxes[index].CreateGraphics();
            Rectangle rectangle1 = new Rectangle(10, 10, 100, 100);
            Rectangle rectangle2 = new Rectangle(150, 10, 100, 100);
            Rectangle rectangle3 = new Rectangle(290, 10, 100, 100);
            float     angleA     = historyHave.A * 360 / (Max.A == 0 ? 1 : Max.A);
            float     angleB     = historyHave.B * 360 / (Max.B == 0 ? 1 : Max.B);
            float     angleC     = historyHave.C * 360 / (Max.C == 0 ? 1 : Max.C);
            Resourse  after_add  = new Resourse(historyHave.A + demand.A > Max.A ? Max.A : historyHave.A + demand.A, historyHave.B + demand.B > Max.B ? Max.B : historyHave.B + demand.B, historyHave.C + demand.C > Max.C ? Max.C : historyHave.C + demand.C);

            g.FillRectangle(new SolidBrush(Color.White), rectangle1.X, 115, 100, 20);
            g.DrawString(after_add.A.ToString() + "/" + Max.A.ToString(), new Font("等线", 14), new SolidBrush(Color.Black), rectangle1.X + 30, 115);
            g.FillRectangle(new SolidBrush(Color.White), rectangle2.X, 115, 100, 20);
            g.DrawString(after_add.B.ToString() + "/" + Max.B.ToString(), new Font("等线", 14), new SolidBrush(Color.Black), rectangle2.X + 30, 115);
            g.FillRectangle(new SolidBrush(Color.White), rectangle3.X, 115, 100, 20);
            g.DrawString(after_add.C.ToString() + "/" + Max.C.ToString(), new Font("等线", 14), new SolidBrush(Color.Black), rectangle3.X + 30, 115);
            MyDrawParam param1 = new MyDrawParam(g);

            param1.positionRectangle = new Rectangle(10, 10, 100, 100);
            param1.angleBegin        = angleA - 90;
            param1.angleIncrease     = demand.A * 360 / (Max.A == 0 ? 1 : Max.A);
            param1.interval          = DataBus.FormOperatingActiveInterval;
            MyDrawParam param2 = new MyDrawParam(g);

            param2.positionRectangle = new Rectangle(150, 10, 100, 100);
            param2.angleBegin        = angleB - 90;
            param2.angleIncrease     = demand.B * 360 / (Max.B == 0 ? 1 : Max.B);
            param2.interval          = DataBus.FormOperatingActiveInterval;
            MyDrawParam param3 = new MyDrawParam(g);

            param3.positionRectangle = new Rectangle(290, 10, 100, 100);
            param3.angleBegin        = angleC - 90;
            param3.angleIncrease     = demand.C * 360 / (Max.C == 0 ? 1 : Max.C);
            param3.interval          = DataBus.FormOperatingActiveInterval;
            if (flag == 1)
            {
                MyAnimation.SyncPreDrawPie(param1);
                MyAnimation.SyncPreDrawPie(param2);
                MyAnimation.SyncPreDrawPie(param3);
            }
            else
            {
                MyAnimation.SyncActiveDrawPie(param1);
                MyAnimation.SyncActiveDrawPie(param2);
                MyAnimation.SyncActiveDrawPie(param3);
            }
        }
示例#4
0
         private void update_draw(object sender, EventArgs e)//动态的绘制更新
        {
            myOperator.printPro(myOperator.ProcessList, myOperator.available);
            Rectangle rectangle1 = new Rectangle(10, 10, 100, 100);
            Rectangle rectangle2 = new Rectangle(150, 10, 100, 100);
            Rectangle rectangle3 = new Rectangle(290, 10, 100, 100);
            for (int i = 0; i < 5; i++)
            {
                AngleCollection history = historys[i];
                Resourse Max=myOperator.ProcessList[i].Max;
                Resourse Allocation = myOperator.ProcessList[i].Allocation;
                float angleA = Allocation.A * 360 / (Max.A == 0 ? 1 : Max.A);
                float angleB = Allocation.B * 360 / (Max.B == 0 ? 1 : Max.B);
                float angleC = Allocation.C * 360 / (Max.C == 0 ? 1 : Max.C);
                Graphics g=pictureBoxes[i].CreateGraphics();
                MyDrawParam param1 = new MyDrawParam(g);
                param1.positionRectangle = rectangle1;
                param1.angleBegin = -90 + history.A;
                param1.angleIncrease = angleA - history.A;
                param1.interval = DataBus.FormMainActiveInterval;
                MyAnimation.AsyncActiveDrawPie(param1);
                g.FillRectangle(new SolidBrush(Color.White), rectangle1.X, 115, 100, 20);
                g.DrawString(Allocation.A.ToString() + "/" + Max.A.ToString(), new Font("等线", 14), new SolidBrush(Color.Black), rectangle1.X + 30, 115);
                MyDrawParam param2 = new MyDrawParam(g);
                param2.positionRectangle = rectangle2;
                param2.angleBegin = -90 + history.B;
                param2.angleIncrease = angleB - history.B;
                param2.interval = DataBus.FormMainActiveInterval;
                MyAnimation.AsyncActiveDrawPie(param2);
                g.FillRectangle(new SolidBrush(Color.White), rectangle2.X, 115, 100, 20);
                g.DrawString(Allocation.B.ToString() + "/" + Max.B.ToString(), new Font("等线", 14), new SolidBrush(Color.Black), rectangle2.X + 30, 115);
                MyDrawParam param3 = new MyDrawParam(g);
                param3.positionRectangle = rectangle2;
                param3.angleBegin = -90 + history.B;
                param3.angleIncrease = angleB - history.B;
                param3.interval = DataBus.FormMainActiveInterval;
                MyAnimation.AsyncActiveDrawPie(param3);
                //activeDrawPie(g, change_brush, warn_brush, rectangle3, -90+history.C, angleC - history.C,100);
                g.FillRectangle(new SolidBrush(Color.White), rectangle3.X, 115, 100, 20);
                g.DrawString(Allocation.C.ToString() + "/" + Max.C.ToString(), new Font("等线", 14), new SolidBrush(Color.Black), rectangle3.X + 30, 115);
                history.A = angleA;
                history.B = angleB;
                history.C = angleC;


            }
        }
 private static void AsyncactivePieEvent(MyDrawParam myDrawParam, Timer timer, ref int Tick)//同步绘制的时钟事件
 {
     if (Tick > myDrawParam.angleIncrease)
     {
         timer.Stop();
         //Console.WriteLine("Finish");
         return;
     }
     if (Tick < 270 - myDrawParam.angleBegin)//正常绘制
     {
         myDrawParam.graphics.FillPie(myDrawParam.mainBrush, myDrawParam.positionRectangle, myDrawParam.angleBegin + Tick, myDrawParam.angleIncrease > Tick + 5 ? 5 : myDrawParam.angleIncrease - Tick);
     }
     else//超出最大值则换为警示颜色
     {
         myDrawParam.graphics.FillPie(myDrawParam.backupBrush, myDrawParam.positionRectangle, myDrawParam.angleBegin + Tick, myDrawParam.angleIncrease > Tick + 5 ? 5 : myDrawParam.angleIncrease - Tick);
     }
     Tick += 5;
 }
        public static void SyncPreDrawPie(MyDrawParam myDrawParam)//尝试分配资源的三个资源异步绘制
        {
            float Tick = 0;

            //Console.WriteLine("被调用");
            while (true)
            {
                if (Tick == myDrawParam.angleIncrease)                                                         //正好够时作为特殊情况判断
                {
                    if (Tick < 270 - myDrawParam.angleBegin)                                                   //空闲资源不够满足进程
                    {
                        myDrawParam.graphics.DrawImage(Properties.Resources.x, myDrawParam.positionRectangle); //显示叉号
                        myDrawParam.graphics.FillRectangle(new SolidBrush(Color.FromArgb(100, Color.Gray)), 0, 0, 405, 148);
                        //Console.WriteLine("Tick=" + Tick + " angleEnd=" + angleEnd);
                        return;
                        //Console.WriteLine("Finish");
                    }
                    else
                    {
                        myDrawParam.graphics.DrawImage(Properties.Resources.benefits, myDrawParam.positionRectangle);//打勾
                        return;
                    }
                }
                if (Tick < 270 - myDrawParam.angleBegin)//没够,继续画
                {
                    myDrawParam.graphics.FillPie(myDrawParam.mainBrush, myDrawParam.positionRectangle, myDrawParam.angleBegin + Tick, myDrawParam.angleIncrease > Tick + 5 ? 5 : myDrawParam.angleIncrease - Tick);
                }
                else
                {
                    myDrawParam.graphics.DrawImage(Properties.Resources.benefits, myDrawParam.positionRectangle);//打勾
                    return;
                }
                Tick += (myDrawParam.angleIncrease > Tick + 5 ? 5 : myDrawParam.angleIncrease - Tick);//下一帧绘制的角度
                Thread.Sleep(myDrawParam.interval);
            }
        }