コード例 #1
0
        private void DrawPoint(int x, int y, double value, bool isData)
        {
            var brush = value == 0 ? Brushes.White : (isData ? Draw.GetBrush(value) : Draw.GetBrush(Draw.GetColor((byte)(255 * value), Colors.Green)));
            var pen   = Draw.GetPen(Colors.Black);

            CtlPresenter.DrawRectangle(brush, pen, Rects.Get(x * PointSize, y * PointSize, PointSize, PointSize));
        }
コード例 #2
0
        private static void EnableDoubleTapToast(Element element)
        {
            if (element is VisualElement visualElement)
            {
                if (element is View view)
                {
                    var tapGestureRecognizer = new TapGestureRecognizer
                    {
                        NumberOfTapsRequired = 2
                    };
                    tapGestureRecognizer.Tapped += (s, e) =>
                    {
                        Rects.Clear();
                        RectsStack.Clear();
                        ExtractRect = true;
                        ExtractCompleteRect(view);

                        foreach (var item in RectsStack)
                        {
                            Rects.AppendLine(item.ToString());
                        }

                        UserDialogs.Instance.Toast($"{Rects.ToString()}", TimeSpan.FromSeconds(10));
                    };
                    view.GestureRecognizers.Add(tapGestureRecognizer);
                }
            }
        }
コード例 #3
0
        public void DrawBase(ErrorMatrix matrix)
        {
            CtlBase.Clear();

            int  size       = 9;
            long axisOffset = 12;

            for (int y = 0; y < matrix.Output.Length; ++y)
            {
                for (int x = 0; x < matrix.Input.Length; ++x)
                {
                    CtlBase.DrawRectangle(null, PenSilver, Rects.Get(axisOffset + x * size, axisOffset + y * size, size, size));
                }
            }

            for (int x = 0; x < matrix.Output.Length; ++x)
            {
                var text = ClassesFmtText[matrix.Classes[x]];
                CtlBase.DrawText(text, Points.Get(axisOffset + x * size + (size - text.Width) / 2, 1 + axisOffset + matrix.Input.Length * size));
            }

            for (int y = 0; y < matrix.Input.Length; ++y)
            {
                var text = ClassesFmtText[matrix.Classes[y]];
                CtlBase.DrawText(text, Points.Get(1 + axisOffset + matrix.Output.Length * size + (size - text.Width) / 2, axisOffset + y * size));
            }

            CtlBase.DrawText(FmtOutput, Points.Get(axisOffset + (matrix.Output.Length * size - FmtOutput.Width) / 2, axisOffset - FmtOutput.Height - 1));
            CtlBase.DrawText(FmtInput, Points.Get(-axisOffset - (matrix.Input.Length * size - FmtInput.Width) / 1, axisOffset - FmtInput.Height - 1), -90);

            CtlBase.Update();
        }
コード例 #4
0
 public void ParseRects(List <List <string> > data)
 {
     Rects.Clear();
     foreach (var rect in data)
     {
         Rects.Add(new DrawRects(rect));
     }
 }
コード例 #5
0
        private Rects CreateRandomRects()
        {
            Rects r = new Rects();

            r.rect = new Rectangle(
                rnd.Next(10, 250), rnd.Next(10, 250),
                rnd.Next(10, 40), rnd.Next(10, 40));
            r.color = Color.FromArgb(
                rnd.Next(128, 256), rnd.Next(128, 256), rnd.Next(128, 256), rnd.Next(128, 256));

            return(r);
        }
コード例 #6
0
        private int DrawSurfaceTest(bool applyColor)
        {
            Surface      surf   = new Surface("jellybean.png");
            List <Rects> rects  = new List <Rects>();
            int          frames = 0;

            surf.Color = Color.White;

            for (int i = 1; i < 10; i++)
            {
                Rects r = CreateRandomRects();

                rects.Add(r);
            }

            for (frames = 0; frames < totalFrames; frames++)
            {
                if (Display.CurrentWindow.IsClosed)
                {
                    return(frames);
                }

                rects.Add(CreateRandomRects());

                Display.BeginFrame();
                Display.Clear();

                if (applyColor)
                {
                    for (int i = 0; i < rects.Count; i++)
                    {
                        surf.Color = rects[i].color;
                        surf.Draw(rects[i].rect.Location);
                    }
                }
                else
                {
                    for (int i = 0; i < rects.Count; i++)
                    {
                        surf.Draw(rects[i].rect.Location);
                    }
                }

                font.DrawText(string.Format("{0} frames per second.", Math.Round(Display.FramesPerSecond, 2)));

                Display.EndFrame();
                Core.KeepAlive();
            }

            return(frames);
        }
コード例 #7
0
        protected void AddRect(BiomeRect n)
        {
            var newRects = new List <BiomeRect>(20)
            {
                n
            };
            var victims = new List <BiomeRect>(20);

            foreach (var rect in Rects)
            {
                if (!n.Intersects(rect))
                {
                    continue;
                }

                victims.Add(rect);

                var clampn = rect.Intersect(n);

                if (clampn.BottomLeft.X > rect.BottomLeft.X)
                {
                    var colour = rect.Colour;
                    newRects.Add(new BiomeRect(rect.BottomLeft, new BiomeVector(clampn.BottomLeft.X, rect.TopRight.Y), colour));
                }

                if (clampn.TopRight.X < rect.TopRight.X)
                {
                    var colour = rect.Colour;
                    newRects.Add(new BiomeRect(new BiomeVector(clampn.TopRight.X, rect.BottomLeft.Y), rect.TopRight, colour));
                }

                if (clampn.BottomLeft.Y > rect.BottomLeft.Y)
                {
                    var colour = rect.Colour;
                    newRects.Add(new BiomeRect(new BiomeVector(clampn.BottomLeft.X, rect.BottomLeft.Y), new BiomeVector(clampn.TopRight.X, clampn.BottomLeft.Y), colour));
                }

                if (clampn.TopRight.Y < rect.TopRight.Y)
                {
                    var colour = rect.Colour;
                    newRects.Add(new BiomeRect(new BiomeVector(clampn.BottomLeft.X, clampn.TopRight.Y), new BiomeVector(clampn.TopRight.X, rect.TopRight.Y), colour));
                }
            }

            foreach (var victim in victims)
            {
                Rects.Remove(victim);
            }

            Rects.AddRange(newRects);
        }
コード例 #8
0
        protected void Optimize()
        {
            var victims  = new List <BiomeRect>(10);
            var newrects = new List <BiomeRect>(5);

            foreach (var rect in Rects)
            {
                // does this rect adjoin a similar height rect on its right hand side?

                if (victims.Contains(rect))
                {
                    continue;
                }

                foreach (var other in Rects)
                {
                    if (rect.Equals(other))
                    {
                        continue;
                    }

                    if (victims.Contains(other))
                    {
                        continue;
                    }

                    if ((rect.Colour == other.Colour) &&
                        (rect.Height == other.Height) &&
                        (rect.TopRight.X == other.BottomLeft.X) &&
                        (rect.BottomLeft.Y == other.BottomLeft.Y))
                    {
                        var colour = rect.Colour;
                        colour = rect.Colour;
                        newrects.Add(new BiomeRect(rect.BottomLeft, other.TopRight, colour));
                        victims.Add(rect);
                        break;
                    }
                }
            }

            foreach (var victim in victims)
            {
                Rects.Remove(victim);
            }

            Rects.AddRange(newrects);
        }
コード例 #9
0
        public ViewModel()
        {
            _nodes = new ObservableCollection <Node>();
            _rects = new ObservableCollection <Rect>();
            GenerateNode(2, 6);
            Rect inlet = new Rect();

            inlet.X          = Nodes[0].X - RowPitch + 5;
            inlet.Y          = Nodes[0].Y;
            inlet.RectHeight = 170;
            Rects.Add(inlet);
            Rect outlet = new Rect();

            outlet.X          = Nodes[1].X + RowPitch + 5;
            outlet.Y          = Nodes[0].Y - TubePitch / 2;
            outlet.RectHeight = inlet.RectHeight;
            Rects.Add(outlet);
        }
コード例 #10
0
ファイル: KinectForm.cs プロジェクト: SysMa/hitbricks
        public void timer_Tick(object sender, EventArgs e)
        {
            if (!IsGameOver())
            {
                if (!timer_time.Enabled)
                {
                    timer_time.Start();
                }

                BulletsRun();
                RunBall();
                Hit();

                // this.splitContainer1.Panel1.Refresh();
                // this.splitContainer1.Panel1.Invalidate();
                txtScore.Text = score.ToString();
                // this.Invalidate();

                if (IsSuccess())
                {
                    foreach (Brick_Type brick in Rects)
                    {
                        brick.pictureBox.Dispose();
                    }
                    Rects.Clear();
                    newBricks();
                }
            }
            else
            {
                timer_time.Stop();
                timer.Stop();
                bgmPlayer.Stop();
                foreach (Brick_Type brick in Rects)
                {
                    brick.pictureBox.Dispose();
                }
                Rects.Clear();
                this.oversign.Visible = true;
            }
        }
コード例 #11
0
        private int FilledRectTest()
        {
            List <Rects> rects  = new List <Rects>();
            int          frames = 0;

            for (int i = 1; i < 10; i++)
            {
                Rects r = CreateRandomRects();

                rects.Add(r);
            }

            for (frames = 0; frames < totalFrames; frames++)
            {
                if (Display.CurrentWindow.IsClosed)
                {
                    return(frames);
                }

                rects.Add(CreateRandomRects());

                Display.BeginFrame();
                Display.Clear();

                for (int i = 0; i < rects.Count; i++)
                {
                    Display.FillRect(rects[i].rect, rects[i].color);
                }

                font.DrawText(string.Format("{0} frames per second.", Math.Round(Display.FramesPerSecond, 2)));

                Display.EndFrame();
                Core.KeepAlive();

                ;
            }

            return(frames);
        }
コード例 #12
0
        public Args(Engine engine, string args)
        {
            this.engine = engine;
            var items  = args.Split(new[] { ' ' });
            var others = new List <string>();

            foreach (var item in items)
            {
                if (engine.Markers.ContainsKey(item))
                {
                    Markers.Add(engine.Markers[item]);
                }
                else if (engine.Rects.ContainsKey(item))
                {
                    Rects.Add(engine.Rects[item]);
                }
                else if (engine.Strings.ContainsKey(item))
                {
                    Strings.Add(engine.Strings[item]);
                }
                else if (engine.Floats.ContainsKey(item))
                {
                    Floats.Add(engine.Floats[item]);
                }
                else if (float.TryParse(item, out float f))
                {
                    Floats.Add(f);
                }
                else
                {
                    others.Add(item);
                }
            }
            if (others.Count > 0)
            {
                Text = string.Join(" ", others);
            }
        }
コード例 #13
0
ファイル: KinectForm.cs プロジェクト: SysMa/hitbricks
        private void button2_Click(object sender, EventArgs e)
        {
            this.oversign.Visible = false;

            this.stage = 1;
            foreach (Brick_Type brick in Rects)
            {
                brick.pictureBox.Dispose();
            }
            Rects.Clear();
            newBricks();

            for (int i = 0; i < balls.Count; i++)
            {
                balls[i].pic.Dispose();
            }
            balls.Clear();
            Ball ball = new Ball(this.splitContainer1.Panel1.Width / 2, begin + _height - 3 * 18);

            this.splitContainer1.Panel1.Controls.Add(ball.pic);
            ball.pic.BringToFront();
            balls.Add(ball);

            render.type = Render.BarWidth.NORMAL;

            score         = 0;
            txtScore.Text = "0";

            this.isGameOver = false;

            this.remainLife = 3;
            for (int i = 0; i < maxLife; i++)
            {
                lifePics[i].Visible = true;
            }

            timer.Start();
        }
コード例 #14
0
        private void DrawData(DynamicStatistics.PlotPoints data, Color color, PointFunc func, bool isRect)
        {
            if (data == null || data.FirstOrDefault() == null)
            {
                return;
            }

            var pen = Tools.Draw.GetPen(color);

            var firstData = data[0];
            var lastData  = data.Last();

            var ticks = lastData.Item2 - firstData.Item2;

            Point prevPoint = new Point(-1000, -1000);
            var   prevData  = firstData;

            foreach (var d in data)
            {
                var point = func(data, d, ticks);
                if ((point.X - prevPoint.X) > 10 || Math.Abs(point.Y - prevPoint.Y) > 10 || d == lastData) // opt
                {
                    CtlPresenter.DrawLine(pen, func(data, prevData, ticks), point);

                    if (isRect)
                    {
                        CtlPresenter.DrawRectangle(pen.Brush, pen, Rects.Get(point.X - 6 / 2, point.Y - 6 / 2, 6, 6));
                    }
                    else
                    {
                        CtlPresenter.DrawEllipse(pen.Brush, pen, Points.Get(point.X, point.Y), 7 / 2, 7 / 2);
                    }

                    prevData  = d;
                    prevPoint = point;
                }
            }
        }
コード例 #15
0
        public void draw_stage_one()
        {
            int    half_blank          = (this.splitContainer1.Panel1.Width - _width) / 2;
            Random rd                  = new Random();
            int    bricksNumberPerLine = 10;

            for (int i = 66, j = 0; i < _height - 18 * 3; i += 18, j += 20, bricksNumberPerLine--)
            {
                int bricksNumberCurrentLine = bricksNumberPerLine;
                for (int x = j; x < _width; x += 40)
                {
                    if (bricksNumberCurrentLine-- > 0)
                    {
                        Rectangle  Rect       = new Rectangle(half_blank + x, i, 40, 18);
                        Brick_Type temp_brick = new Brick_Type();
                        temp_brick.rectangle  = Rect;
                        temp_brick.type       = rd.Next() % 3;
                        temp_brick.pictureBox = new PictureBox();
                        Rects.Add(temp_brick);
                    }
                }
            }
        }
コード例 #16
0
        public void draw_stage_two()
        {
            int    half_blank = (this.splitContainer1.Panel1.Width - _width) / 2;
            Random rd         = new Random();

            for (int i = 66; i < _height - 18 * 3; i += 18)   //_width: 400 、  _height: 300 、 每个砖块的高度18
            {
                for (int j = 0; j < _width; j += 40)
                {
                    int x = j / 40;
                    int y = (i - 66) / 18;
                    if (x + y == 9 || x == y || y == 5 || y == 0 || y == 9 || x == 0 || x == 9)
                    {
                        Rectangle  Rect       = new Rectangle(half_blank + j, i, 40, 18);
                        Brick_Type temp_brick = new Brick_Type();
                        temp_brick.rectangle  = Rect;
                        temp_brick.type       = rd.Next() % 3;
                        temp_brick.pictureBox = new PictureBox();
                        Rects.Add(temp_brick);
                    }
                }
            }
        }
コード例 #17
0
        public Image GetImage(double width = 0, double height = 0)
        {
            double w = width == 0 ? SystemParameters.PrimaryScreenWidth : width;
            double h = height == 0 ? SystemParameters.PrimaryScreenHeight : height;

            RenderTargetBitmap bitmap = new RenderTargetBitmap((int)w, (int)h, Render.Dpi, Render.Dpi, PixelFormats.Pbgra32);

            Measure(RenderSize);
            Arrange(Rects.Get(RenderSize));

            foreach (var visual in Visuals)
            {
                bitmap.Render(visual);
            }
            bitmap.Freeze();

            var image = new Image
            {
                Source = bitmap
            };

            return(image);
        }
コード例 #18
0
        private void DrawLabel(DynamicStatistics.PlotPoints data, Color color)
        {
            var text = new FormattedText(TimeSpan.FromTicks(data.Last().Item2 - data[0].Item2).ToString(@"hh\:mm\:ss") + " / " + Converter.DoubleToText(data.Last().Item1, "N6", false) + " %", Culture.Current, FlowDirection.LeftToRight, Font, 10, Tools.Draw.GetBrush(color), Render.PixelsPerDip);

            CtlPresenter.DrawRectangle(Tools.Draw.GetBrush(Tools.Draw.GetColor(150, Colors.White)), null, Rects.Get((ActualWidth - AxisOffset - text.Width) / 2 - 5, ActualHeight - AxisOffset - 20, text.Width + 10, text.Height));
            CtlPresenter.DrawText(text, Points.Get((ActualWidth - AxisOffset - text.Width) / 2, ActualHeight - AxisOffset - 20));
        }
コード例 #19
0
        public void Render(long startTicks, long endTicks, DataManager manager, bool isOdd, bool isHeadOfGroup)
        {
            CtlPresenter.Clear();

            using (var dc = CtlPresenter.G())
            {
                var width  = CtlPresenter.ActualWidth;
                var height = CtlPresenter.ActualHeight;

                if (Values.Count == 0)
                {
                    //todo: add grid
                    return;
                }

                CtlGroup.Visibility = isHeadOfGroup ? Visibility.Visible : Visibility.Collapsed;

                double rangeMin = RangeMinimum;
                double rangeMax = RangeMaximum;

                /* auto range
                 * if (manager.IsAutoRangeMinMax)
                 * {
                 *  var min = Values.Min(v => v.CtlValue.Value);
                 *  var max = Values.Max(v => v.CtlValue.Value);
                 *
                 *  rangeMax = max + min;
                 *  rangeMin = 0;
                 * }
                 */

                // Min-Max range
                if (manager.IsAutoRangeMinMax)
                {
                    var min = Values.Min(v => v.CtlValue.Value);
                    var max = Values.Max(v => v.CtlValue.Value);

                    rangeMax = max;
                    rangeMin = min;
                }

                if (rangeMin == rangeMax)
                {
                    var pen = GetPenFromValue(rangeMin);

                    CtlMinRange.Text = Converter.DoubleToText(rangeMin, "F3", true);
                    CtlMinRange.VerticalAlignment = VerticalAlignment.Center;
                    CtlMinRange.Background        = pen.Brush;
                    CtlMaxRange.Visibility        = Visibility.Collapsed;
                }
                else
                {
                    var penMin = GetPenFromValue(rangeMin);
                    var penMax = GetPenFromValue(rangeMax);

                    CtlMinRange.Text       = Converter.DoubleToText(rangeMin, "F3", true);
                    CtlMinRange.Background = penMin.Brush;
                    CtlMaxRange.Text       = Converter.DoubleToText(rangeMax, "F3", true);
                    CtlMaxRange.Background = penMax.Brush;
                }

                double optimalValue = CriticalMinumim + (CriticalMaximum - CriticalMinumim) / 2;

                if (manager.IsShowOptimalLine && CriticalMinumim > 0)
                {
                    if (rangeMax < optimalValue)
                    {
                        rangeMax = optimalValue;
                    }

                    if (rangeMin > optimalValue)
                    {
                        rangeMin = optimalValue;
                    }
                }

                var prevValue = Values[0];

                double val     = prevValue.CtlValue.Value;
                var    prevPen = GetPenFromValue(val);
                double prevX   = GetX(startTicks, endTicks, prevValue.CtlDate.SelectedDate.Value);

                foreach (var value in Values)
                {
                    if (prevValue != null)
                    {
                        var v       = value.CtlValue.Value;
                        var currPen = GetPenFromValue(v);
                        if (currPen != prevPen)
                        {
                            var end         = value == Values[Values.Count - 1] ? value.CtlDate.SelectedDate.Value : value.CtlDate.SelectedDate.Value.AddDays(-1);
                            var dayOfChange = GetDayOfChange2(prevValue, value, end, prevPen);

                            val = GetValueForDate(prevValue, value, dayOfChange.Ticks);
                            var pen = GetPenFromValue(val);

                            bool lastDay = value == Values[Values.Count - 1] && dayOfChange == end;
                            if (pen != prevPen || lastDay)
                            {
                                double x = (lastDay && pen == prevPen) ? width : GetX(startTicks, endTicks, dayOfChange);
                                CtlPresenter.DrawRectangle(prevPen.Brush, prevPen, Rects.Get(prevX, 0, x - prevX, height), dc);

                                prevX   = x;
                                prevPen = pen;
                            }
                        }
                    }

                    prevValue = value;
                }

                CtlPresenter.DrawRectangle(prevPen.Brush, prevPen, Rects.Get(prevX, 0, width - prevX, height), dc);

                // grid

                var endDate   = new DateTime(endTicks);
                var startDate = new DateTime(startTicks);

                for (DateTime day = startDate; day <= endDate; day = day.AddMonths(1))
                {
                    double x = GetX(startTicks, endTicks, day);
                    CtlPresenter.DrawLine(day.Month == 1 ? penGridYear : (isOdd ? penGrid : penGridAlt), Points.Get(x, 0), Points.Get(x, height), dc);
                }

                double xt = GetX(startTicks, endTicks, DateTime.Today);
                CtlPresenter.DrawLine(penToday, Points.Get(xt, 0), Points.Get(xt, height), dc);

                // optimal line
                if (manager.IsShowOptimalLine && CriticalMinumim > 0)
                {
                    double y = GetY(optimalValue, rangeMin, rangeMax);
                    CtlPresenter.DrawLine(penOptimalValue, Points.Get(0, y), Points.Get(width, y), dc);
                }

                // graph
                prevValue = null;
                foreach (var value in Values)
                {
                    var point = GetValuePoint(value, startTicks, endTicks, rangeMin, rangeMax);
                    if (prevValue != null)
                    {
                        var prevPoint = GetValuePoint(prevValue, startTicks, endTicks, rangeMin, rangeMax);
                        CtlPresenter.DrawLine(penLine, prevPoint, point, dc);
                    }

                    // Critical border circle

                    var pointPen = penLine;

                    double pointRadius = 5 * Tools.Render.PixelSize;

                    if (CriticalMinumim != CriticalMaximum)
                    {
                        if (CriticalMinumim > RangeMinimum && value.CtlValue.Value == CriticalMinumim)
                        {
                            CtlPresenter.DrawEllipse(penCriticalBorder.Brush, penCriticalBorder, point, pointRadius, pointRadius, dc);
                            pointPen = penLow;
                        }
                        else if (CriticalMaximum < RangeMaximum && value.CtlValue.Value == CriticalMaximum)
                        {
                            CtlPresenter.DrawEllipse(penCriticalBorder.Brush, penCriticalBorder, point, pointRadius, pointRadius, dc);
                            pointPen = penHigh;
                        }
                    }

                    // Value point

                    CtlPresenter.DrawEllipse(pointPen.Brush, pointPen, point, pointRadius / 2, pointRadius / 2, dc);

                    prevValue = value;
                }
                //

                // values
                var brush     = Tools.Draw.GetBrush(Colors.White);
                var prevRects = new List <Rect>();
                for (int i = Values.Count - 1; i >= 0; --i)
                {
                    var value = Values[i];
                    var point = GetValuePoint(value, startTicks, endTicks, rangeMin, rangeMax);
                    var fmt   = new FormattedText(Converter.DoubleToText(value.CtlValue.Value, "F3"), Culture.Current, FlowDirection.LeftToRight, Font, 9, Brushes.Black, Tools.Render.PixelsPerDip);
                    var x     = point.X + Tools.Render.PixelSize;
                    var y     = point.Y >= height / 2 ? point.Y - Tools.Render.PixelSize - fmt.Height : point.Y + Tools.Render.PixelSize;
                    var rect  = Rects.Get(x, y, fmt.Width + 2 * Tools.Render.PixelSize, fmt.Height - 2 * Tools.Render.PixelSize);

                    if (!prevRects.Any(prevRect => Rects.Intersects(rect, prevRect)))
                    {
                        CtlPresenter.DrawRectangle(brush, null, rect, dc);
                        CtlPresenter.DrawText(fmt, Points.Get(x + Tools.Render.PixelSize, y - Tools.Render.PixelSize), 0, dc);
                        prevRects.Add(rect);
                    }
                }
            }

            IsRenderNeeded = false;
        }
コード例 #20
0
        public void Draw(ErrorMatrix matrix)
        {
            if (!IsLoaded)
            {
                return;
            }

            if (IsClassesChanged(matrix.Classes))
            {
                InitClassesFmtText(matrix.Classes);
                DrawBase(matrix);
            }

            Classes = matrix.Classes;
            CtlPresenter.Clear();

            int  size       = 9;
            long goodMax    = 1;
            long badMax     = 1;
            long axisOffset = 12;
            long bound      = 30;

            for (int y = 0; y < matrix.Output.Length; ++y)
            {
                for (int x = 0; x < matrix.Input.Length; ++x)
                {
                    if (x == y)
                    {
                        goodMax = Math.Max(goodMax, matrix.Matrix[x, y]);
                    }
                    else
                    {
                        badMax = Math.Max(badMax, matrix.Matrix[x, y]);
                    }
                }
            }

            for (int y = 0; y < matrix.Output.Length; ++y)
            {
                for (int x = 0; x < matrix.Input.Length; ++x)
                {
                    if (matrix.Matrix[y, x] > 0)
                    {
                        var value = (double)matrix.Matrix[y, x] / (double)(x == y ? goodMax : badMax);
                        var color = Tools.Draw.GetColorDradient(Colors.LightGray, x == y ? Colors.Green : Colors.Red, 255, value);
                        var brush = Tools.Draw.GetBrush(color);
                        CtlPresenter.DrawRectangle(brush, PenSilver, Rects.Get(axisOffset + x * size, axisOffset + y * size, size, size));
                    }
                }
            }

            long outputMax = Math.Max(matrix.Output.Max(), 1);

            for (int x = 0; x < matrix.Output.Length; ++x)
            {
                var color = Tools.Draw.GetColorDradient(Colors.White, matrix.Output[x] > matrix.Input[x] ? Colors.Red : matrix.Output[x] < matrix.Input[x] ? Colors.Blue : Colors.Green, 100, (double)matrix.Output[x] / (double)outputMax);
                var brush = Tools.Draw.GetBrush(color);
                CtlPresenter.DrawRectangle(brush, PenSilver, Rects.Get(axisOffset + x * size, 10 + axisOffset + matrix.Input.Length * size, size, (int)(bound * (double)matrix.Output[x] / (double)outputMax)));
            }

            long inputMax = Math.Max(matrix.Input.Max(), 1);

            for (int y = 0; y < matrix.Input.Length; ++y)
            {
                var color = Tools.Draw.GetColorDradient(Colors.White, Colors.Green, 100, (double)matrix.Input[y] / (double)inputMax);
                var brush = Tools.Draw.GetBrush(color);
                CtlPresenter.DrawRectangle(brush, PenSilver, Rects.Get(11 + axisOffset + matrix.Output.Length * size, axisOffset + y * size, (int)(bound * (double)matrix.Input[y] / (double)inputMax), size));
            }

            CtlPresenter.Update();
        }
コード例 #21
0
 //Add a rectangle to the list
 public void AddRect(Rect rect)
 {
     Rects.Add(rect);
 }
コード例 #22
0
 //Make enumerable instead
 #region Implementation of IEnumerable
 public IEnumerator <Rect> GetEnumerator()
 {
     return(Rects.GetEnumerator());
 }
コード例 #23
0
 public AddRectCommand(Rects rects, Rect rect)
 {
     this.rects = rects;
     this.rect  = rect;
 }
コード例 #24
0
        public Path RenderPath(PathPaintingRenderInfo renderInfo)
        {
            //var p = typeof(PathPaintingRenderInfo).GetField("gs", BindingFlags.NonPublic | BindingFlags.Instance);
            //var gs = (GraphicsState)(p.GetValue(renderInfo));
            //Debug.WriteLine(gs.StrokeColor?.RGB.ToString() ?? "empty");
            // detect gs.StrokeColor != null

            if (renderInfo.Operation != 0)
            {
                Tuple <int, Vector> cur = null;
                Vector from             = null;
                Vector to = null;
                while (movements.Count > 0 && (cur = movements.Dequeue()) != null)
                {
                    if (cur.Item1 == 1)
                    {
                        from = cur.Item2.Cross(renderInfo.Ctm);
                    }
                    else
                    {
                        if (from == null)
                        {
                            continue;
                        }

                        to = cur.Item2.Cross(renderInfo.Ctm);

                        if (from[0] == to[0] && from[1] < to[1] ||
                            from[1] == to[1] && from[0] < to[0])
                        {
                            Lines.Add(new LineSegment(new Vector(FixAxis(from[0]), FixAxis(from[1]), 1)
                                                      , new Vector(FixAxis(to[0]), FixAxis(to[1]), 1)));
                        }
                        else if (from[0] == to[0] && from[1] > to[1] ||
                                 from[1] == to[1] && from[0] > to[0])
                        {
                            Lines.Add(new LineSegment(new Vector(FixAxis(to[0]), FixAxis(to[1]), 1)
                                                      , new Vector(FixAxis(from[0]), FixAxis(from[1]), 1)));
                        }
                        else
                        {
                            //throw new Exception("oblique line");
                        }

                        //Debug.WriteLine("x:{0},y:{1}", Lines[Lines.Count - 1].GetStartPoint()[0], Lines[Lines.Count - 1].GetStartPoint()[1]);
                        from = null;
                        to   = null;
                    }
                }

                if (rData != null)
                {
                    var    r   = rData;
                    Vector vxy = new Vector(r[0], r[1], 1).Cross(renderInfo.Ctm);
                    Vector vwh = new Vector(r[2], r[3], 1).Cross(renderInfo.Ctm);
                    var    x   = vxy[0];
                    var    y   = vxy[1];
                    if (vwh[0] < 0)
                    {
                        x = vxy[0] + vwh[0];
                    }
                    if (vwh[1] < 0)
                    {
                        y = vxy[1] - vwh[1];
                    }
                    vxy = new Vector(x, y, 1);
                    vwh = new Vector(Math.Abs(r[2]), Math.Abs(r[3]), 1).Cross(renderInfo.Ctm);
                    if (TreatSmallRectAsLine && vwh[0] < Variance)
                    {
                        //Lines.Add(new LineSegment(new Vector(FixAxis(x), FixAxis(y - vwh[1]), 1)
                        //       , new Vector(FixAxis(x), FixAxis(y), 1)));
                        Lines.Add(new LineSegment(new Vector(FixAxis(x), FixAxis(y), 1)
                                                  , new Vector(FixAxis(x), FixAxis(y + vwh[1]), 1)));
                    }
                    else if (TreatSmallRectAsLine && vwh[1] < Variance)
                    {
                        Lines.Add(new LineSegment(new Vector(FixAxis(x), FixAxis(y), 1)
                                                  , new Vector(FixAxis(x + vwh[0]), FixAxis(y), 1)));
                    }
                    else
                    {
                        Rects.Add(new Rect(vxy[0], vxy[1], vwh[0], vwh[1]));
                    }
                    rData = null;
                }
            }

            return(null);
        }
コード例 #25
0
 public static void FullRedraw()
 {
     Clear();
     FrameBuffer.Instance.Clear();
     Rects.Add(new Rect(0, 0, FrameBuffer.Instance.Width, FrameBuffer.Instance.Height));
 }
コード例 #26
0
 public void RectInvalidated(Rect rc)
 {
     Rects.Add(rc);
 }
コード例 #27
0
        protected override Size MeasureOverride(Size availableSize)
        {
            arrageRects.Clear();

            var requiredSize = new Size(Padding.Left + Padding.Right, Padding.Top + Padding.Bottom);
            var clientSize   = new Size(
                availableSize.Width - Padding.Left - Padding.Right,
                availableSize.Height - Padding.Top - Padding.Bottom);

            if (Children.Count < 1)
            {
                return(requiredSize);
            }

            if (Orientation == Orientation.Horizontal)
            {
                availableRects.MergeItem(new Rect(Padding.Left, Padding.Top,
                                                  clientSize.Width + HorizontalSpacing, double.PositiveInfinity));
            }
            else
            {
                availableRects.MergeItem(new Rect(Padding.Left, Padding.Top,
                                                  double.PositiveInfinity, clientSize.Height + VerticalSpacing));
            }

            foreach (var child in Children)
            {
                child.Measure(clientSize);
                var childSize = child.DesiredSize;

                childSize.Width  += HorizontalSpacing;
                childSize.Height += VerticalSpacing;

                var(index, rect) = Rects.FindEnoughArea(availableRects, childSize);
                Debug.Assert(index != -1);
                var(target, clipRight, clipBottom) = rect.Clip(childSize);

                availableRects.RemoveAt(index);

                availableRects.CutThenMergeOthers(target,
                                                  clipRight.GetValueOrDefault(),
                                                  clipBottom.GetValueOrDefault());

                target.Width  -= HorizontalSpacing;
                target.Height -= VerticalSpacing;
                arrageRects.Add(target);

                if (Orientation == Orientation.Horizontal)
                {
                    availableRects.Sort(CompareRectTop);
                }
                else
                {
                    availableRects.Sort(CompareRectLeft);
                }
            }

            availableRects.Clear();

            var bounds = arrageRects.GetOutBounds();

            requiredSize.Width  += bounds.Width;
            requiredSize.Height += bounds.Height;
            return(requiredSize);
        }
コード例 #28
0
        //碰撞检测
        public void Hit()
        {
            // 这部分和下面一部分最好不要合并。
            // 意外是:子弹和小球同时击中。
            bool bullet_hit = false;

            for (int i = 0; i < Rects.Count;)
            {
                if (bullets.Count == 0)
                {
                    break;
                }
                for (int k = 0; k < bullets.Count;)
                {
                    if (bullets[k].rect.IntersectsWith(Rects[i].rectangle))
                    {
                        Rects[i].pictureBox.Visible = false;
                        Rects[i].pictureBox.Dispose();
                        Rects.Remove(Rects[i]);
                        bullet_hit = true;

                        bullets[k].pic.Visible = false;
                        bullets[k].pic.Dispose();
                        bullets.Remove(bullets[k]);

                        Mp3 mp3 = new Mp3();
                        mp3.FileName = @"..\..\Resources\hitBricks.wav";
                        mp3.play();
                        break;
                    }
                    else
                    {
                        k++;
                    }
                }
                if (bullet_hit)
                {
                    bullet_hit = false;
                }
                else
                {
                    i++;
                }
            }

            for (int j = 0; j < balls.Count; j++)
            {
                //砖块与小球碰撞
                for (int i = 0; i < Rects.Count; i++)
                {
                    if (balls[j].speedY < 0)
                    {
                        balls[j].speedY = -3;
                    }
                    // 下面4个变量用来记录相交与否
                    // 如果某一条边和小球的矩形相交,则为true
                    // 否则为false
                    bool[] flags = new bool[4];
                    bool   hit   = false;

                    // 相交与否
                    flags[0] = Rects[i].rectangle.Contains(
                        new Point(balls[j].rect.X, balls[j].rect.Y));
                    flags[1] = Rects[i].rectangle.Contains(
                        new Point(balls[j].rect.X + 2 * ball_R, balls[j].rect.Y));
                    flags[2] = Rects[i].rectangle.Contains(
                        new Point(balls[j].rect.X, balls[j].rect.Y + ball_R * 2));
                    flags[3] = Rects[i].rectangle.Contains(
                        new Point(balls[j].rect.X + ball_R * 2, balls[j].rect.Y + ball_R * 2));

                    if (flags[0] && flags[1])
                    {
                        if (!isHeavy)
                        {
                            balls[j].speedY = -balls[j].speedY;
                        }
                        hit = true;
                    }
                    else if (flags[0] && !flags[1] && !flags[2])
                    {
                        hit = true;
                        if (!isHeavy)
                        {
                            if (balls[j].speedX > 0 && balls[j].speedY > 0)
                            {
                                balls[j].speedY = -balls[j].speedY;
                            }
                            else if (balls[j].speedX < 0)
                            {
                                balls[j].speedX = -balls[j].speedX;
                            }
                            else if (balls[j].speedX > 0 && balls[j].speedY < 0)
                            {
                                // impossible
                                return;
                            }
                        }
                    }
                    else if (flags[0] && flags[2])
                    {
                        hit = true;
                        if (!isHeavy)
                        {
                            balls[j].speedX = -balls[j].speedX;
                        }
                    }
                    else if (flags[2] && !flags[0] && !flags[3])
                    {
                        hit = true;
                        if (!isHeavy)
                        {
                            if (balls[j].speedX > 0 && balls[j].speedY < 0)
                            {
                                balls[j].speedY = -balls[j].speedY;
                            }
                            else if (balls[j].speedX < 0)
                            {
                                balls[j].speedX = -balls[j].speedX;
                            }
                            else if (balls[j].speedX > 0 && balls[j].speedY > 0)
                            {
                                // impossible
                                return;
                            }
                        }
                    }
                    else if (flags[2] && flags[3])
                    {
                        hit = true;
                        if (!isHeavy)
                        {
                            balls[j].speedY = -balls[j].speedY;
                        }
                    }
                    else if (flags[3] && !flags[1] && !flags[2])
                    {
                        hit = true;
                        if (!isHeavy)
                        {
                            if (balls[j].speedX < 0 && balls[j].speedY < 0)
                            {
                                balls[j].speedY = -balls[j].speedY;
                            }
                            else if (balls[j].speedX > 0)
                            {
                                balls[j].speedX = -balls[j].speedX;
                            }
                            else if (balls[j].speedX < 0 && balls[j].speedY > 0)
                            {
                                // impossible
                                return;
                            }
                        }
                    }
                    else if (flags[1] && flags[3])
                    {
                        hit = true;
                        if (!isHeavy)
                        {
                            balls[j].speedX = -balls[j].speedX;
                        }
                    }
                    else if (flags[1] && !flags[0] && !flags[3])
                    {
                        hit = true;
                        if (!isHeavy)
                        {
                            if (balls[j].speedX < 0 && balls[j].speedY > 0)
                            {
                                balls[j].speedY = -balls[j].speedY;
                            }
                            else if (balls[j].speedX > 0)
                            {
                                balls[j].speedX = -balls[j].speedX;
                            }
                            else if (balls[j].speedX < 0 && balls[j].speedY < 0)
                            {
                                // impossible
                                return;
                            }
                        }
                    }

                    if (hit)
                    {
                        //得分
                        score        += (Rects[i].type + 1) * 10;
                        txtScore.Text = score.ToString();

                        if (i % 5 == 0)
                        {
                            Bonus bonus = new Bonus();
                            bonus.xPos = Rects[i].rectangle.X;
                            bonus.yPos = Rects[i].rectangle.Y;
                            bonus.rect = new Rectangle(bonus.xPos, bonus.yPos,
                                                       2 * ball_R, 2 * ball_R);

                            bonus.pic           = new PictureBox();
                            bonus.pic.BackColor = Color.Transparent;
                            bonus.pic.Location  = new Point(bonus.xPos, bonus.yPos);
                            bonus.pic.Size      = new Size(2 * ball_R, 2 * ball_R);
                            this.splitContainer1.Panel1.Controls.Add(bonus.pic);
                            bonus.pic.BringToFront();

                            switch (random.Next(0, (int)(Bonus_Type.COUNT)))
                            {
                            case (int)Bonus_Type.INCREASE:
                                bonus.type      = Bonus_Type.INCREASE;
                                bonus.pic.Image = global::HitBrick_WinForm.Properties.Resources.increaseLength;
                                break;

                            case (int)Bonus_Type.DECREASE:
                                bonus.type      = Bonus_Type.DECREASE;
                                bonus.pic.Image = global::HitBrick_WinForm.Properties.Resources.decreaseLength;
                                break;

                            case (int)Bonus_Type.ADD_LIFE:
                                bonus.type      = Bonus_Type.ADD_LIFE;
                                bonus.pic.Image = global::HitBrick_WinForm.Properties.Resources.life_small;
                                break;

                            case (int)Bonus_Type.BOMB:
                                bonus.type      = Bonus_Type.BOMB;
                                bonus.pic.Image = global::HitBrick_WinForm.Properties.Resources.bomb;
                                break;

                            case (int)Bonus_Type.THREE_BALLS:
                                bonus.type      = Bonus_Type.THREE_BALLS;
                                bonus.pic.Image = global::HitBrick_WinForm.Properties.Resources.ball;
                                break;

                            case (int)Bonus_Type.HEAVY_BALL:
                                bonus.type      = Bonus_Type.HEAVY_BALL;
                                bonus.pic.Image = global::HitBrick_WinForm.Properties.Resources.heavyBall;
                                break;

                            case (int)Bonus_Type.BULLET:
                            default:
                                bonus.type      = Bonus_Type.BULLET;
                                bonus.pic.Image = global::HitBrick_WinForm.Properties.Resources.lighting;
                                break;
                            }

                            bonuses.Add(bonus);
                        }

                        //删除砖块
                        Rects[i].pictureBox.Visible = false;
                        Rects[i].pictureBox.Dispose();
                        Rects.Remove(Rects[i]);
                        Mp3 mp3 = new Mp3();
                        mp3.FileName = @"..\..\Resources\hitBricks.wav";
                        mp3.play();
                        break;
                    }
                }
            }

            //获得奖励
            for (int i = 0; i < bonuses.Count;)
            {
                Bonus bonus = bonuses[i];
                if (bonus.pic.RectangleToScreen(bonus.pic.DisplayRectangle)
                    .IntersectsWith(render.manImage.RectangleToScreen(render.manImage.DisplayRectangle)))
                {
                    //奖励效果
                    switch (bonus.type)
                    {
                    case Bonus_Type.INCREASE:
                        render.type = Render.BarWidth.DOUBLE;
                        break;

                    case Bonus_Type.DECREASE:
                        render.type = Render.BarWidth.HALF;
                        break;

                    case Bonus_Type.ADD_LIFE:
                        if (remainLife < 3)
                        {
                            lifePics[remainLife].Visible = true;
                            remainLife++;
                        }
                        break;

                    case Bonus_Type.BOMB:
                        for (int num_bonus = 0; num_bonus < bonus_bricks && num_bonus < Rects.Count; num_bonus++)
                        {
                            int pick = random.Next(0, Rects.Count - 1);
                            // delete the brick
                            Rects[pick].pictureBox.Visible = false;
                            Rects[pick].pictureBox.Dispose();
                            Rects.Remove(Rects[pick]);
                        }
                        break;

                    case Bonus_Type.THREE_BALLS:
                    {
                        Ball ball1 = new Ball(10, 50);
                        this.splitContainer1.Panel1.Controls.Add(ball1.pic);
                        ball1.pic.BringToFront();
                        balls.Add(ball1);
                        Ball ball2 = new Ball(this.splitContainer1.Panel1.Width - 30, 50);
                        this.splitContainer1.Panel1.Controls.Add(ball2.pic);
                        ball2.pic.BringToFront();
                        balls.Add(ball2);
                    }
                    break;

                    case Bonus_Type.HEAVY_BALL:
                    {
                        isHeavy = true;
                        for (int j = 0; j < balls.Count; j++)
                        {
                            balls[j].pic.Image = global::HitBrick_WinForm.Properties.Resources.heavyBall;
                        }
                    }
                    break;

                    case Bonus_Type.BULLET:
                    default:
                    {
                        //render.setBegin(0);
                        numberOfBullets = 10;
                        break;
                    }
                    }

                    bonus.pic.Dispose();
                    bonuses.Remove(bonus);
                }
                //奖励消失
                else if (bonus.yPos > this.Height)
                {
                    bonus.pic.Dispose();
                    bonuses.Remove(bonus);
                }
                else
                {
                    bonus.yPos         = bonus.yPos + bonus_speed;
                    bonus.pic.Location = new Point(bonus.xPos, bonus.yPos);
                    bonus.rect         = new Rectangle(bonus.xPos, bonus.yPos, 2 * ball_R, 2 * ball_R);
                    i++;
                }
            }

            Point center = render.GetBarLocation();

            for (int i = 0; i < balls.Count; i++)
            {
                //小球与挡板碰撞
                if (balls[i].pic.RectangleToScreen(balls[i].pic.DisplayRectangle).IntersectsWith(
                        render.barImage.RectangleToScreen(render.GetBarRect()))
                    &&
                    balls[i].pic.RectangleToScreen(balls[i].pic.DisplayRectangle).IntersectsWith(
                        render.manImage.RectangleToScreen(render.manImage.DisplayRectangle)))
                {
                    int    dis_x = center.X - lastCenter.X;
                    int    dis_y = center.Y - lastCenter.Y;
                    double angle = render.Angle;

                    if (angle < 0)
                    {
                        angle = angle + Math.PI;
                    }

                    if (angle > Math.PI / 2)
                    {
                        angle = Math.PI - angle;
                    }

                    // so now the v is this
                    // along the board: x*cosα-y*sinα
                    // and x*sinα+y*cosα
                    // rules: along the board, no changes, the other, direction and speedup.
                    if ((dis_x > 0 && balls[i].speedX > 0 && balls[i].speedX > dis_x) ||
                        (dis_x < 0 && balls[i].speedX <0 && dis_x> balls[i].speedX))
                    {
                        balls[i].speedX = dis_x * 1;
                        balls[i].speedX = dis_y * 1;
                    }
                    else
                    {
                        balls[i].speedX = (int)((balls[i].speedX * Math.Cos(2 * angle)
                                                 - balls[i].speedY * Math.Sin(2 * angle)) + dis_x * speedup_x);
                        balls[i].speedY = (int)((balls[i].speedX * Math.Sin(2 * angle)
                                                 + balls[i].speedY * Math.Cos(2 * angle)) + dis_y * speedup_y);

                        if (balls[i].speedY == 0)
                        {
                            balls[i].speedY = 5;
                        }
                    }
                }
            }

            lastCenter = center;
        }
コード例 #29
0
 public void Reset()
 {
     Rects.Clear();
 }
コード例 #30
0
        public void Render(DateTime start, DateTime end)
        {
            CtlPresenter.Clear();

            byte alpha = 100;

            var winterColor = Draw.GetBrush(Draw.GetColor(alpha, Colors.White));
            var springColor = Draw.GetBrush(Draw.GetColor(alpha, Colors.Blue));
            var summerColor = Draw.GetBrush(Draw.GetColor(alpha, Colors.Green));
            var autumColor  = Draw.GetBrush(Draw.GetColor(alpha, Colors.Yellow));

            var year0Color = Draw.GetBrush(Draw.GetColor(255, Colors.WhiteSmoke));
            var year1Color = Draw.GetBrush(Draw.GetColor(255, Colors.DarkGray));

            var dictMonth = new Dictionary <int, Brush>()
            {
                { 1, winterColor },
                { 2, winterColor },
                { 3, springColor },
                { 4, springColor },
                { 5, springColor },
                { 6, summerColor },
                { 7, summerColor },
                { 8, summerColor },
                { 9, autumColor },
                { 10, autumColor },
                { 11, autumColor },
                { 12, winterColor }
            };

            var dictYear = new Dictionary <int, Brush>()
            {
                { 0, year0Color },
                { 1, year1Color }
            };

            var width  = CtlPresenter.ActualWidth;
            var height = CtlPresenter.ActualHeight;

            const double yearHeight = 5;

            // grid
            for (DateTime day = start; day <= end; day = day.AddMonths(1))
            {
                double x  = GetX(start.Ticks, end.Ticks, day.Ticks);
                double x2 = GetX(start.Ticks, end.Ticks, day.AddMonths(1).Ticks);

                CtlPresenter.DrawRectangle(dictMonth[day.Month], penGrid, Rects.Get(x, 0, x2 - x, height - yearHeight));

                if (day.Month == 1)
                {
                    CtlPresenter.DrawLine(penGridYear, Points.Get(x, 0), Points.Get(x, height - yearHeight));
                }

                var fmt = new FormattedText(day.Date.ToString("MMM") + "\r\n" + (day.Date.Year - 2000), Culture.Current, FlowDirection.LeftToRight, Font, 9, Brushes.Black, Tools.Render.PixelsPerDip);
                CtlPresenter.DrawText(fmt, Points.Get(x + (x2 - x - fmt.Width) / 2, (height - fmt.Height) / 2 - 3));

                CtlPresenter.DrawRectangle(dictYear[day.Year % 2], null, Rects.Get(x, height - yearHeight, x2 - x, yearHeight));
            }
            CtlPresenter.DrawLine(penGrid, Points.Get(0, 0), Points.Get(width, 0));
            //
        }