コード例 #1
0
 void SetDrawable(MyButtonRenderer myButtonRenderer)
 {
     if (myButtonRenderer.IsGradient)
     {
         Color StartColor = ColorInterpolator.InterpolateBetween(myButtonRenderer.EndColor,
                                                                 myButtonRenderer.StartColor,
                                                                 myButtonRenderer.NumOfGradientStart);
         Color EndColor = ColorInterpolator.InterpolateBetween(myButtonRenderer.StartColor,
                                                               myButtonRenderer.EndColor,
                                                               myButtonRenderer.NumOfGradientEnd);
         var gradient = new CAGradientLayer();
         gradient.Colors = new CGColor[]
         {
             StartColor.ToCGColor(),
                 EndColor.ToCGColor()
         };
         gradient.StartPoint = new CGPoint(0, 0.5);
         gradient.EndPoint   = new CGPoint(1, 0.5);
         Control.Layer.InsertSublayer(gradient, 0);
     }
     else
     {
         Control.BackgroundColor = myButtonRenderer.StaticColor.ToUIColor();
     }
 }
コード例 #2
0
        public override void Draw(CGRect rect)
        {
            MyLabelRenderer myLabelRenderer = (MyLabelRenderer)Element;

            if (myLabelRenderer.IsGradient)
            {
                var gradientView = new UIView(Control.Frame);
                Control.BackgroundColor = UIColor.Clear;
                Color color = ColorInterpolator.InterpolateBetween(myLabelRenderer.StartColor,
                                                                   myLabelRenderer.EndColor,
                                                                   myLabelRenderer.NumToGradient);

                var gradientLayer = new CAGradientLayer
                {
                    Frame  = gradientView.Layer.Bounds,
                    Colors = new CGColor[] { myLabelRenderer.StartColor.ToCGColor(), color.ToCGColor() }
                };

                gradientView.Layer.AddSublayer(gradientLayer);
                gradientView.AddSubview(Control);

                var gradientLabel = new UILabel(Control.Frame);
                gradientLabel.AddSubview(gradientView);
                SetNativeControl(gradientLabel);

                gradientLayer.StartPoint = new CGPoint(0, 0.5);
                gradientLayer.EndPoint   = new CGPoint(1.0, 0.5);
            }
            else
            {
                Control.BackgroundColor = myLabelRenderer.StaticColor.ToUIColor();
            }
            base.Draw(rect);
        }
コード例 #3
0
 public virtual System.Drawing.Bitmap GetAsBmp(float[] value)
 {
     System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(1, value.Length);
     for (int i = 0; i < size; i++)
     {
         bmp.SetPixel(0, i, ColorInterpolator.InterpolateBetween(System.Drawing.Color.Black, System.Drawing.Color.Lime, value[i]));
     }
     return(bmp);
 }
コード例 #4
0
ファイル: CVZ_TPC.cs プロジェクト: kourouklides/mmcm-net
        public System.Drawing.Bitmap GetFrequencyVisualization()
        {
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(width, height);

            //Build the bmp
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    System.Drawing.Color color = ColorInterpolator.InterpolateBetween(Color.Blue, Color.Yellow, Color.Red, neurons[x, y].GetSpikingFrequency());
                    bmp.SetPixel(x, y, color);
                }
            }
            //Console.WriteLine("Visualization computed in " + (time2 - time1).ToString());
            return(bmp);
        }
コード例 #5
0
        void SetDrawable(MyLabelRenderer myLabelRenderer)
        {
            GradientDrawable gradientDrawable = new GradientDrawable();

            if (myLabelRenderer.IsGradient)
            {
                Color color = ColorInterpolator.InterpolateBetween(myLabelRenderer.StartColor,
                                                                   myLabelRenderer.EndColor,
                                                                   myLabelRenderer.NumToGradient);
                gradientDrawable = new GradientDrawable(
                    GradientDrawable.Orientation.LeftRight,
                    new int[] { myLabelRenderer.StartColor.ToAndroid(), color.ToAndroid() }
                    );
            }
            else
            {
                gradientDrawable.SetColor(myLabelRenderer.StaticColor.ToAndroid());
            }
            switch (myLabelRenderer.TypeBorder)
            {
            case TypeBorder.All:
                gradientDrawable.SetCornerRadii(new float[] { 80, 80, 80, 80,
                                                              80, 80, 80, 80 });
                break;

            case TypeBorder.Left:
                gradientDrawable.SetCornerRadii(new float[] { 80, 80, 0, 0,
                                                              0, 0, 80, 80 });
                break;

            case TypeBorder.Right:
                gradientDrawable.SetCornerRadii(new float[] { 0, 0, 80, 80,
                                                              80, 80, 0, 0 });
                break;

            case TypeBorder.Down:
                gradientDrawable.SetCornerRadii(new float[] { 0, 0, 0, 0,
                                                              80, 80, 80, 80 });
                break;

            case TypeBorder.Up:
                gradientDrawable.SetCornerRadii(new float[] { 80, 80, 80, 80,
                                                              0, 0, 0, 0 });
                break;
            }
            Control.SetBackground(gradientDrawable);
        }
コード例 #6
0
        private void RenderBlip()
        {
            int x_off = 38;
            int y_off = 17;

            int blipMaxArea = 90;

            int blipUp   = 45;
            int blipDown = 57;

            if (blipTime * blipSpeed > blipMaxArea)
            {
                blipTime = 0;
            }

            var bs = (int)Math.Floor(blipTime * blipSpeed);

            Gorgon.CurrentRenderTarget.BlendingMode = BlendingModes.Modulated;
            for (int i = bs; i < (bs + blipWidth); i++)
            {
                float sweepPct = (float)i / (bs + blipWidth);

                float alpha =
                    Math.Min(Math.Max((1 - (Math.Abs((blipMaxArea / 2f) - i) / (blipMaxArea / 2f))) * (300f * sweepPct), 0f), 255f);
                _backgroundSprite.Color = Color.FromArgb((int)alpha,
                                                         ColorInterpolator.InterpolateBetween(Color.Orange,
                                                                                              Color.LawnGreen, healthPct));

                float blipHeightUp   = Math.Max(((blipUp - Math.Abs(blipUp - i)) / (float)blipUp) - 0.80f, 0f);
                float blipHeightDown = Math.Max(((blipDown - Math.Abs(blipDown - i)) / (float)blipDown) - 0.93f, 0f);

                if (i <= blipMaxArea)
                {
                    _backgroundSprite.Draw(new Rectangle(healthMeterInner.X + x_off + i,
                                                         healthMeterInner.Y + y_off -
                                                         (int)
                                                         ((blipHeightUp * 65) *
                                                          ((healthPct > 0f) ? Math.Max(healthPct, 0.30f) : 0)) +
                                                         (int)
                                                         ((blipHeightDown * 65) *
                                                          ((healthPct > 0f) ? Math.Max(healthPct, 0.45f) : 0)),
                                                         3, 3));
                }
            }
            Gorgon.CurrentRenderTarget.BlendingMode = BlendingModes.None;
        }
コード例 #7
0
        public static IEnumerable <Color> GetColorsBetween(Color start, Color end, int count, bool include_start = false, bool include_end = false)
        {
            //if (count <= 0 | count > 100) { throw new NotSupportedException(); }

            if (include_start)
            {
                yield return(start);
            }

            for (int i = 0; i < count; i++)
            {
                double lambda = (1.0 / (count + 1)) * (i + 1);

                yield return(ColorInterpolator.InterpolateBetween(start, end, lambda));
            }

            if (include_end)
            {
                yield return(end);
            }
        }
コード例 #8
0
        public override void Update(float frameTime)
        {
            const int x_inner   = 4;
            const int y_inner   = 25;
            const int dec_inner = 7;

            panelBG.Position            = Position;
            healthMeterBg.Position      = new Vector2D(Position.X + x_inner, Position.Y + y_inner);
            healthMeterOverlay.Position = new Vector2D(Position.X + x_inner, Position.Y + y_inner);
            healthMeterGrid.Position    = new Vector2D(Position.X + x_inner, Position.Y + y_inner);

            ClientArea = Rectangle.Round(panelBG.AABB);

            healthMeterInner = new Rectangle(Position.X + x_inner + dec_inner, Position.Y + y_inner + dec_inner,
                                             (int)(healthMeterOverlay.Width - (2 * dec_inner)),
                                             (int)(healthMeterOverlay.Height - (2 * dec_inner)));
            healthPc.Position = new Point(healthMeterInner.X + 5,
                                          (int)
                                          (healthMeterInner.Y + (healthMeterInner.Height / 2f) -
                                           (healthPc.ClientArea.Height / 2f)) - 2);
            healthPc.Update(frameTime);

            Entity entity = _playerManager.ControlledEntity;

            if (entity != null && entity.HasComponent(ComponentFamily.Damageable))
            {
                var   comp    = (HealthComponent)entity.GetComponent(ComponentFamily.Damageable);
                float _health = comp.GetHealth();

                healthPct = comp.GetHealth() / comp.GetMaxHealth();
                if (float.IsNaN(healthPct))
                {
                    healthPct = 1;                         //This can happen when the components are not ready yet.
                }
                interpCol          = ColorInterpolator.InterpolateBetween(ColCritical, ColHealthy, healthPct);
                healthPc.Text.Text = Math.Round((healthPct * 100)).ToString() + "%";
            }

            blipTime += frameTime;
        }
コード例 #9
0
        protected override void OnBindingContextChanged()
        {
            if ((BindingContext != null) && (message == null))
            {
                message = (MessageElementModel)BindingContext;
                if (message != null)
                {
                    // Add Urgency element ?
                    if (message.Content.Urgency != UrgencyType.Std)
                    {
                        if (messageContentUrgency == null)
                        {
                            messageContentUrgency = new MessageContentUrgency();
                            messageContentUrgency.BindingContext = message;
                            ContentGrid.Children.Add(messageContentUrgency, 0, 0);
                            Grid.SetColumnSpan(messageContentUrgency, 2);
                        }
                    }

                    // Add forward header
                    if (message.IsForwarded)
                    {
                        if (messageContentForward == null)
                        {
                            messageContentForward = new MessageContentForward();
                            messageContentForward.BindingContext = message;
                            ContentGrid.Children.Add(messageContentForward, 0, 0);
                            Grid.SetColumnSpan(messageContentForward, 2);
                        }
                    }

                    // Add Reply element ?
                    if (message.Reply != null)
                    {
                        if (messageContentReply == null)
                        {
                            messageContentReply = new MessageContentReply();
                            messageContentReply.BindingContext = message;
                            ContentGrid.Children.Add(messageContentReply, 0, 1);
                            Grid.SetColumnSpan(messageContentReply, 2);
                        }
                    }

                    // Add Body element ?
                    if (!String.IsNullOrEmpty(message.Content?.Body))
                    {
                        if (message.Content.Body.StartsWith("/img", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (messageContentBodyWithImg == null)
                            {
                                messageContentBodyWithImg = new MessageContentBodyWithImg();
                                messageContentBodyWithImg.BindingContext = message;
                                ContentGrid.Children.Add(messageContentBodyWithImg, 0, 2);
                            }
                        }
                        else if (message.Content.Body.StartsWith("/code", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (messageContentBodyWithCode == null)
                            {
                                messageContentBodyWithCode = new MessageContentBodyWithCode();
                                messageContentBodyWithCode.BindingContext = message;
                                ContentGrid.Children.Add(messageContentBodyWithCode, 0, 2);
                            }
                        }
                        else if (messageContentBody == null)
                        {
                            messageContentBody = new MessageContentBody();
                            messageContentBody.BindingContext = message;
                            ContentGrid.Children.Add(messageContentBody, 0, 2);
                        }

                        BtnPosition = 2;
                    }
                    else if (message.Content.Type == "deletedMessage")
                    {
                        // We don't need action button in this case
                        needActionButton = false;

                        // Create MessageContentDeleted
                        messageContentDeleted = new MessageContentDeleted();
                        messageContentDeleted.BindingContext = message;
                        ContentGrid.Children.Add(messageContentDeleted, 0, 2);
                        Grid.SetColumnSpan(messageContentDeleted, 2);
                    }

                    // Add Attachment element ?
                    if (message.Content.Attachment != null)
                    {
                        if (messageContentAttachment == null)
                        {
                            messageContentAttachment = new MessageContentAttachment();
                            messageContentAttachment.BindingContext = message;
                            ContentGrid.Children.Add(messageContentAttachment, 0, 3);

                            if (BtnPosition == -1)
                            {
                                BtnPosition = 3;
                            }
                            else
                            {
                                Grid.SetColumnSpan(messageContentAttachment, 2);
                            }
                        }
                    }

                    // Are we managing a msg of the current user ?
                    if (message.Peer.Id == Helper.SdkWrapper.GetCurrentContactId())
                    {
                        color           = Helper.GetResourceDictionaryById <Color>("ColorConversationStreamMessageCurrentUserFont");
                        backgroundColor = Helper.GetResourceDictionaryById <Color>("ColorConversationStreamMessageCurrentUserBackGround");
                    }
                    else
                    {
                        color           = Helper.GetResourceDictionaryById <Color>("ColorConversationStreamMessageOtherUserFont");
                        backgroundColor = Helper.GetResourceDictionaryById <Color>("ColorConversationStreamMessageOtherUserBackGround");
                    }
                    interpolateColor = ColorInterpolator.InterpolateBetween(color, backgroundColor, 0.5);


                    Frame.BackgroundColor = backgroundColor;

                    // Add Btn Action in the correct place
                    if (needActionButton && (BtnPosition != -1))
                    {
                        CreateBtnAction();

                        BtnAction.ImageSourceId              = null;
                        BtnAction.BackgroundColor            = backgroundColor;
                        BtnAction.BackgroundColorOnMouseOver = interpolateColor;

                        ContentGrid.Children.Add(BtnAction, 1, BtnPosition);
                    }
                }
            }
        }
コード例 #10
0
        protected override void OnElementChanged(ElementChangedEventArgs <Button> e)
        {
            base.OnElementChanged(e);

            if ((Control != null) && (e.OldElement == null))
            {
                MyButtonRenderer myButtonRenderer = (MyButtonRenderer)Element;
                GradientDrawable gradientDrawable = new GradientDrawable();
                if (myButtonRenderer.IsGradient)
                {
                    Color StartColor = ColorInterpolator.InterpolateBetween(myButtonRenderer.EndColor,
                                                                            myButtonRenderer.StartColor,
                                                                            myButtonRenderer.NumOfGradientStart);
                    Color EndColor = ColorInterpolator.InterpolateBetween(myButtonRenderer.StartColor,
                                                                          myButtonRenderer.EndColor,
                                                                          myButtonRenderer.NumOfGradientEnd);
                    if (!myButtonRenderer.IsEnabled)
                    {
                        StartColor = System.Drawing.Color.FromArgb(70, StartColor);
                        EndColor   = System.Drawing.Color.FromArgb(70, EndColor);
                    }
                    gradientDrawable = new GradientDrawable(
                        GradientDrawable.Orientation.LeftRight,
                        new int[] { StartColor.ToAndroid(),
                                    EndColor.ToAndroid() }
                        );
                }
                else
                {
                    Color staticColor = myButtonRenderer.StaticColor;
                    if (!myButtonRenderer.IsEnabled)
                    {
                        staticColor = System.Drawing.Color.FromArgb(70, myButtonRenderer.StaticColor);
                    }
                    gradientDrawable.SetColor(staticColor.ToAndroid());
                }
                switch (myButtonRenderer.TypeBorder)
                {
                case TypeBorder.All:
                    gradientDrawable.SetCornerRadii(new float[] { 80, 80, 80, 80,
                                                                  80, 80, 80, 80 });
                    break;

                case TypeBorder.Left:
                    gradientDrawable.SetCornerRadii(new float[] { 80, 80, 0, 0,
                                                                  0, 0, 80, 80 });
                    break;

                case TypeBorder.Right:
                    gradientDrawable.SetCornerRadii(new float[] { 0, 0, 80, 80,
                                                                  80, 80, 0, 0 });
                    break;

                case TypeBorder.Down:
                    gradientDrawable.SetCornerRadii(new float[] { 0, 0, 0, 0,
                                                                  80, 80, 80, 80 });
                    break;

                case TypeBorder.Up:
                    gradientDrawable.SetCornerRadii(new float[] { 80, 80, 80, 80,
                                                                  0, 0, 0, 0 });
                    break;
                }
                Control.StateListAnimator = new StateListAnimator();
                Control.SetBackground(gradientDrawable);
            }
        }