コード例 #1
0
ファイル: PokerWindow.cs プロジェクト: vladNV/poker-master
        public void Draw(string[] args)
        {
            // fix draw
            if (player1cards.InvokeRequired && player2cards.InvokeRequired &&
                tableCard.InvokeRequired && player1.InvokeRequired &&
                p1act.InvokeRequired && p2act.InvokeRequired &&
                p1chips.InvokeRequired && p2chips.InvokeRequired &&
                bank.InvokeRequired)
            {
                DrawCallback d = new DrawCallback(Draw);
                Invoke(d, new object[] { args });
            }
            else
            {
                string[] param1 = args[1].Split('|');
                string[] param2 = args[2].Split('|');
                string[] table  = args[3].Split('|');
                //player1cards.Text = param1[1];
                //player2cards.Text = param2[1];
                //tableCard.Text = table[1];

                p1chips.Text = param1[2];
                p2chips.Text = param2[2];
                bank.Text    = table[2];

                // действия
                animation(param1[3], param2[3]);
            }
        }
コード例 #2
0
        public void DrawField(string fieldName, Object context, object target, DrawCallback drawCallback)
        {
            var field     = target.GetField(fieldName);
            var attribute = field.GetCustomAttribute <EditorSerializeAttribute>();

            if (attribute.PreviousName != null)
            {
                EditorFieldsDatabase.RenameField(context, attribute.PreviousName, field.Name);
            }

            var editorField = EditorFieldsDatabase.GetEditorField(context, field.Name);

            if (editorField == null)
            {
                return;
            }

            var value = field.GetValue(target);

            Deserialize(editorField, target, field, ref value);

            EditorGUI.BeginChangeCheck();

            value = drawCallback(attribute, context, target, value);

            if (EditorGUI.EndChangeCheck())
            {
                Serialize(attribute, editorField, value, field.FieldType);
            }
        }
コード例 #3
0
        /// <summary>
        /// Update + Draw
        /// </summary>
        /// <param name="isRunningSlow"></param>
        /// <returns></returns>

        public Argb32[] RenderOneFrame(bool isRunningSlow)
        {
            if (this.State == States.Pause)
            {
                return(screen.Pixels);
            }

            var updateExecutedCount = isRunningSlow ? 2 : 1;

            for (int i = 0; i < updateExecutedCount; i++)
            {
                Update();
            }

            DrawCallback?.Invoke(updateExecutedCount);

            this.Frame += updateExecutedCount;

            return(screen.Pixels);
        }
コード例 #4
0
        public byte[] Draw(DrawCallback callback, GraphicsFormat format)
        {
            using (Graphics g = Graphics.FromImage(bitmap))
            {
                callback(g);
            }

            switch (format)
            {
            case GraphicsFormat.Grayscale:
                return(ConvertToGrayscale());

            case GraphicsFormat.BlackAndWhiteDithered:
                return(ConvertToBlackAndWhiteDithered());

            case GraphicsFormat.RGB565:
                return(ConvertToRGB565());

            default:
                return(ConvertToRGB565Rotated180());
            }
        }
コード例 #5
0
ファイル: Graph2D.cs プロジェクト: xiaguoli/IoTGateway
        private void AddSegment(IVector X, IVector Y, ICollection <IElement> X2, ICollection <IElement> Y2,
                                ScriptNode Node, DrawCallback PlotCallback, params object[] Parameters)
        {
            IVector X2V = (IVector)X.Encapsulate(X2, Node);
            IVector Y2V = (IVector)Y.Encapsulate(Y2, Node);

            if (this.axisTypeX == null)
            {
                this.axisTypeX = X2V.GetType();
                this.axisTypeY = Y2V.GetType();
            }
            else
            {
                if (X2V.GetType() != this.axisTypeX || Y2V.GetType() != this.axisTypeY)
                {
                    throw new ScriptException("Incompatible types of series.");
                }
            }

            this.x.AddLast(X2V);
            this.y.AddLast(Y2V);
            this.callbacks.AddLast(PlotCallback);
            this.parameters.AddLast(Parameters);
        }
コード例 #6
0
        public static void StepVerticalScroll(ref int offset, ref Vector2 position, int drawLen, int maxLen, DrawCallback drawer,
                                              GUIStyle style, params GUILayoutOption[] options)
        {
            GUILayout.BeginVertical();
            position = GUILayout.BeginScrollView(position, options);
            int  len    = 0;
            int  logEnd = offset;
            Rect r0     = default(Rect);

            for (int i = offset; len < drawLen && i < maxLen; i++)
            {
                if (drawer(i, len))
                {
                    if (len == 0)
                    {
                        r0 = GUILayoutUtility.GetLastRect();
                    }
                    len++;
                }
                logEnd = i + 1;
            }
            Rect r1 = len > 0 ? GUILayoutUtility.GetLastRect() : r0;

            GUILayout.EndScrollView();
            Rect r2 = GUILayoutUtility.GetLastRect();

            if (r0.height > 1 && len > 0)
            {
                if ((position.y < r0.height || len < drawLen) && offset > 0)
                {
                    offset--;
                    position.y += r0.height;
                }
                else if (logEnd < maxLen && r1.yMin < r2.height + position.y && r1.yMax > position.y)
                {
                    offset++;
                    position.y -= r1.height;
                }
            }
            GUILayout.EndVertical();
        }
コード例 #7
0
        /// <summary>
        /// Base class for two-dimensional graphs.
        /// </summary>
        /// <param name="X">X-axis</param>
        /// <param name="Y">Y-axis</param>
        /// <param name="PlotCallback">Callback method that performs the plotting.</param>
        /// <param name="ShowZeroX">If the y-axis (x=0) should always be shown.</param>
        /// <param name="ShowZeroY">If the x-axis (y=0) should always be shown.</param>
        /// <param name="Node">Node creating the graph.</param>
        /// <param name="Parameters">Graph-specific parameters.</param>
        public Graph2D(IVector X, IVector Y, DrawCallback PlotCallback, bool ShowZeroX, bool ShowZeroY,
                       ScriptNode Node, params object[] Parameters)
            : base()
        {
            if (X is Interval XI)
            {
                X = new DoubleVector(XI.GetArray());
            }

            if (Y is Interval YI)
            {
                Y = new DoubleVector(YI.GetArray());
            }

            int      i, c = X.Dimension;
            bool     HasNull = false;
            IElement ex, ey;

            if (c != Y.Dimension)
            {
                throw new ScriptException("X and Y series must be equally large.");
            }

            for (i = 0; i < c; i++)
            {
                ex = X.GetElement(i);
                ey = Y.GetElement(i);

                if (ex.AssociatedObjectValue is null || ey.AssociatedObjectValue is null)
                {
                    HasNull = true;
                    break;
                }
            }

            this.showZeroX = ShowZeroX;
            this.showZeroY = ShowZeroY;

            this.minX = Min.CalcMin(X, null);
            this.maxX = Max.CalcMax(X, null);

            if (this.showZeroX && this.minX is AbelianGroup Gx)
            {
                List <IElement> Elements = new List <IElement> {
                    this.minX, Gx.Zero
                };
                this.minX = Min.CalcMin(X.Encapsulate(Elements, null) as IVector, null);

                Elements = new List <IElement> {
                    this.maxX, Gx.Zero
                };
                this.maxX = Max.CalcMax(X.Encapsulate(Elements, null) as IVector, null);
            }

            this.minY = Min.CalcMin(Y, null);
            this.maxY = Max.CalcMax(Y, null);

            if (this.showZeroY && this.minY is AbelianGroup Gy)
            {
                List <IElement> Elements = new List <IElement> {
                    this.minY, Gy.Zero
                };
                this.minY = Min.CalcMin(Y.Encapsulate(Elements, null) as IVector, null);

                Elements = new List <IElement> {
                    this.maxY, Gy.Zero
                };
                this.maxY = Max.CalcMax(Y.Encapsulate(Elements, null) as IVector, null);
            }

            if (HasNull)
            {
                LinkedList <IElement> X2 = new LinkedList <IElement>();
                LinkedList <IElement> Y2 = new LinkedList <IElement>();

                this.axisTypeX = null;
                this.axisTypeY = null;

                for (i = 0; i < c; i++)
                {
                    ex = X.GetElement(i);
                    ey = Y.GetElement(i);

                    if (ex.AssociatedObjectValue is null || ey.AssociatedObjectValue is null)
                    {
                        if (X2.First != null)
                        {
                            this.AddSegment(X, Y, X2, Y2, Node, PlotCallback, Parameters);
                            X2 = new LinkedList <IElement>();
                            Y2 = new LinkedList <IElement>();
                        }
                    }
                    else
                    {
                        X2.AddLast(ex);
                        Y2.AddLast(ey);
                    }
                }
コード例 #8
0
 public void DrawField(string fieldName, Object context, DrawCallback drawCallback) =>
 DrawField(fieldName, context, context, drawCallback);
コード例 #9
0
ファイル: Graph2D.cs プロジェクト: xiaguoli/IoTGateway
        /// <summary>
        /// Base class for two-dimensional graphs.
        /// </summary>
        /// <param name="X">X-axis</param>
        /// <param name="Y">Y-axis</param>
        /// <param name="PlotCallback">Callback method that performs the plotting.</param>
        /// <param name="ShowZeroX">If the y-axis (x=0) should always be shown.</param>
        /// <param name="ShowZeroY">If the x-axis (y=0) should always be shown.</param>
        /// <param name="Node">Node creating the graph.</param>
        /// <param name="Parameters">Graph-specific parameters.</param>
        public Graph2D(IVector X, IVector Y, DrawCallback PlotCallback, bool ShowZeroX, bool ShowZeroY,
                       ScriptNode Node, params object[] Parameters)
            : base()
        {
            int      i, c = X.Dimension;
            bool     HasNull = false;
            IElement ex, ey;

            if (c != Y.Dimension)
            {
                throw new ScriptException("X and Y series must be equally large.");
            }

            if (X is Interval XI)
            {
                X = new DoubleVector(XI.GetArray());
            }

            if (Y is Interval YI)
            {
                Y = new DoubleVector(YI.GetArray());
            }

            for (i = 0; i < c; i++)
            {
                ex = X.GetElement(i);
                ey = Y.GetElement(i);

                if (ex.AssociatedObjectValue == null || ey.AssociatedObjectValue == null)
                {
                    HasNull = true;
                    break;
                }
            }

            this.showZeroX = ShowZeroX;
            this.showZeroY = ShowZeroY;

            this.minX = Min.CalcMin(X, null);
            this.maxX = Max.CalcMax(X, null);

            this.minY = Min.CalcMin(Y, null);
            this.maxY = Max.CalcMax(Y, null);

            if (HasNull)
            {
                LinkedList <IElement> X2 = new LinkedList <IElement>();
                LinkedList <IElement> Y2 = new LinkedList <IElement>();

                this.axisTypeX = null;
                this.axisTypeY = null;

                for (i = 0; i < c; i++)
                {
                    ex = X.GetElement(i);
                    ey = Y.GetElement(i);

                    if (ex.AssociatedObjectValue == null || ey.AssociatedObjectValue == null)
                    {
                        if (X2.First != null)
                        {
                            this.AddSegment(X, Y, X2, Y2, Node, PlotCallback, Parameters);
                            X2 = new LinkedList <IElement>();
                            Y2 = new LinkedList <IElement>();
                        }
                    }
                    else
                    {
                        X2.AddLast(ex);
                        Y2.AddLast(ey);
                    }
                }

                if (X2.First != null)
                {
                    this.AddSegment(X, Y, X2, Y2, Node, PlotCallback, Parameters);
                }
            }
            else
            {
                this.axisTypeX = X.GetType();
                this.axisTypeY = Y.GetType();

                if (c > 0)
                {
                    this.x.AddLast(X);
                    this.y.AddLast(Y);
                    this.callbacks.AddLast(PlotCallback);
                    this.parameters.AddLast(Parameters);
                }
            }

            IElement Zero = null;

            if (ShowZeroX && c > 0 && this.minX.AssociatedSet is IAbelianGroup AG)
            {
                Zero = AG.AdditiveIdentity;

                this.minX = Min.CalcMin(new ObjectVector(this.minX, Zero), null);
                this.maxX = Max.CalcMax(new ObjectVector(this.maxX, Zero), null);
            }

            if (ShowZeroY && c > 0 && this.minY.AssociatedSet is IAbelianGroup AG2)
            {
                Zero = AG2.AdditiveIdentity;

                this.minY = Min.CalcMin(new ObjectVector(this.minY, Zero), null);
                this.maxY = Max.CalcMax(new ObjectVector(this.maxY, Zero), null);
            }
        }
コード例 #10
0
ファイル: Graph2D.cs プロジェクト: xiaguoli/IoTGateway
        /// <summary>
        /// Creates a bitmap of the graph.
        /// </summary>
        /// <param name="Settings">Graph settings.</param>
        /// <param name="States">State object(s) that contain graph-specific information about its inner states.
        /// These can be used in calls back to the graph object to make actions on the generated graph.</param>
        /// <returns>Bitmap</returns>
        public override SKImage CreateBitmap(GraphSettings Settings, out object[] States)
        {
            using (SKSurface Surface = SKSurface.Create(Settings.Width, Settings.Height, SKImageInfo.PlatformColorType, SKAlphaType.Premul))
            {
                SKCanvas Canvas = Surface.Canvas;

                States = new object[0];

                Canvas.Clear(Settings.BackgroundColor);

                int x1, y1, x2, y2, x3, y3, w, h;

                x1 = Settings.MarginLeft;
                x2 = Settings.Width - Settings.MarginRight;
                y1 = Settings.MarginTop;
                y2 = Settings.Height - Settings.MarginBottom;

                IVector YLabels = GetLabels(ref this.minY, ref this.maxY, this.y, Settings.ApproxNrLabelsY, out LabelType YLabelType);
                SKPaint Font    = new SKPaint()
                {
                    FilterQuality = SKFilterQuality.High,
                    HintingLevel  = SKPaintHinting.Full,
                    SubpixelText  = true,
                    IsAntialias   = true,
                    Style         = SKPaintStyle.Fill,
                    Color         = Settings.AxisColor,
                    Typeface      = SKTypeface.FromFamilyName(Settings.FontName, SKTypefaceStyle.Normal),
                    TextSize      = (float)Settings.LabelFontSize
                };
                float  Size;
                double MaxSize = 0;

                if (this.showYAxis)
                {
                    foreach (IElement Label in YLabels.ChildElements)
                    {
                        Size = Font.MeasureText(LabelString(Label, YLabelType));
                        if (Size > MaxSize)
                        {
                            MaxSize = Size;
                        }
                    }
                }

                x3 = (int)Math.Ceiling(x1 + MaxSize) + Settings.MarginLabel;

                IVector XLabels = GetLabels(ref this.minX, ref this.maxX, this.x, Settings.ApproxNrLabelsX, out LabelType XLabelType);
                MaxSize = 0;

                if (this.showXAxis)
                {
                    foreach (IElement Label in XLabels.ChildElements)
                    {
                        Size = Font.MeasureText(LabelString(Label, XLabelType));
                        if (Size > MaxSize)
                        {
                            MaxSize = Size;
                        }
                    }
                }

                y3 = (int)Math.Floor(y2 - MaxSize) - Settings.MarginLabel;
                w  = x2 - x3;
                h  = y3 - y1;

                SKPaint AxisBrush = new SKPaint()
                {
                    FilterQuality = SKFilterQuality.High,
                    IsAntialias   = true,
                    Style         = SKPaintStyle.Fill,
                    Color         = Settings.AxisColor
                };
                SKPaint GridBrush = new SKPaint()
                {
                    FilterQuality = SKFilterQuality.High,
                    IsAntialias   = true,
                    Style         = SKPaintStyle.Fill,
                    Color         = Settings.GridColor
                };
                SKPaint AxisPen = new SKPaint()
                {
                    FilterQuality = SKFilterQuality.High,
                    IsAntialias   = true,
                    Style         = SKPaintStyle.Stroke,
                    Color         = Settings.AxisColor,
                    StrokeWidth   = Settings.AxisWidth
                };
                SKPaint GridPen = new SKPaint()
                {
                    FilterQuality = SKFilterQuality.High,
                    IsAntialias   = true,
                    Style         = SKPaintStyle.Stroke,
                    Color         = Settings.GridColor,
                    StrokeWidth   = Settings.GridWidth
                };

                double OrigoX;
                double OrigoY;

                if (this.minX.AssociatedSet is IAbelianGroup AgX)
                {
                    OrigoX = Scale(new ObjectVector(AgX.AdditiveIdentity), this.minX, this.maxX, x3, w)[0];
                }
                else
                {
                    OrigoX = 0;
                }

                if (this.minY.AssociatedSet is IAbelianGroup AgY)
                {
                    OrigoY = Scale(new ObjectVector(AgY.AdditiveIdentity), this.minY, this.maxY, y3, -h)[0];
                }
                else
                {
                    OrigoY = 0;
                }

                DrawingArea DrawingArea = new DrawingArea(this.minX, this.maxX, this.minY, this.maxY, x3, y3, w, -h, (float)OrigoX, (float)OrigoY);
                double[]    LabelYY     = DrawingArea.ScaleY(YLabels);
                int         i           = 0;
                float       f;
                string      s;

                foreach (IElement Label in YLabels.ChildElements)
                {
                    Size = Font.MeasureText(s = LabelString(Label, YLabelType));
                    f    = (float)LabelYY[i++];

                    if (this.showGrid)
                    {
                        if (Label is DoubleNumber && ((DoubleNumber)Label).Value == 0)
                        {
                            Canvas.DrawLine(x3, f, x2, f, AxisPen);
                        }
                        else
                        {
                            Canvas.DrawLine(x3, f, x2, f, GridPen);
                        }
                    }

                    if (this.showYAxis)
                    {
                        f += (float)Settings.LabelFontSize * 0.5f;
                        Canvas.DrawText(s, x3 - Size - Settings.MarginLabel, f, Font);
                    }
                }

                double[] LabelXX = DrawingArea.ScaleX(XLabels);
                i = 0;

                foreach (IElement Label in XLabels.ChildElements)
                {
                    Size = Font.MeasureText(s = LabelString(Label, XLabelType));
                    f    = (float)LabelXX[i++];

                    if (this.showGrid)
                    {
                        if (Label is DoubleNumber && ((DoubleNumber)Label).Value == 0)
                        {
                            Canvas.DrawLine(f, y1, f, y3, AxisPen);
                        }
                        else
                        {
                            Canvas.DrawLine(f, y1, f, y3, GridPen);
                        }
                    }

                    if (this.showXAxis)
                    {
                        f -= Size * 0.5f;
                        if (f < x3)
                        {
                            f = x3;
                        }
                        else if (f + Size > x3 + w)
                        {
                            f = x3 + w - Size;
                        }

                        Canvas.DrawText(s, f, y3 + Settings.MarginLabel + (float)Settings.LabelFontSize, Font);
                    }
                }

                IEnumerator <IVector>      ex          = this.x.GetEnumerator();
                IEnumerator <IVector>      ey          = this.y.GetEnumerator();
                IEnumerator <object[]>     eParameters = this.parameters.GetEnumerator();
                IEnumerator <DrawCallback> eCallbacks  = this.callbacks.GetEnumerator();
                SKPoint[]    Points;
                SKPoint[]    PrevPoints     = null;
                object[]     PrevParameters = null;
                DrawCallback PrevCallback   = null;

                while (ex.MoveNext() && ey.MoveNext() && eParameters.MoveNext() && eCallbacks.MoveNext())
                {
                    Points = DrawingArea.Scale(ex.Current, ey.Current);

                    if (PrevCallback != null && eCallbacks.Current.Target.GetType() == PrevCallback.Target.GetType())
                    {
                        eCallbacks.Current(Canvas, Points, eParameters.Current, PrevPoints, PrevParameters, DrawingArea);
                    }
                    else
                    {
                        eCallbacks.Current(Canvas, Points, eParameters.Current, null, null, DrawingArea);
                    }

                    PrevPoints     = Points;
                    PrevParameters = eParameters.Current;
                    PrevCallback   = eCallbacks.Current;
                }

                SKImage Result = Surface.Snapshot();

                Font.Dispose();
                AxisBrush.Dispose();
                GridBrush.Dispose();
                GridPen.Dispose();
                AxisPen.Dispose();

                States = new object[] { DrawingArea };

                return(Result);
            }
        }
コード例 #11
0
 public void UnRegisterDrawCallBack(DrawCallback callback)
 {
     callbacks.Add(callback);
 }