Beispiel #1
0
        // Construct

        public SimpleProgressBar()
        {
            _maximum        = 100;
            _textBrush      = new SolidBrush(Color.Black);
            _borderPen      = new Pen(Color.DarkGray, 1);
            _style          = ProgressBarStyle.Continuous;
            _foreColorBrush = new SolidBrush(Color.LightGreen);
            _backColorBrush = new SolidBrush(Color.WhiteSmoke);
            _textBrush      = new SolidBrush(Color.Black);

            Step         = 10;
            Font         = new Font("Segoi UI", 10);
            Padding      = new Padding(2);
            Size         = new Size(100, 23);
            SizeChanged += (s, e) => { Invalidate(); };

            DoubleBuffered = true;

            // Marquee stuff
            MarqueeWidth          = 50;
            MarqueeSpeed          = 5;
            MarqueeTimer          = new System.Timers.Timer(100);
            MarqueeTimer.Elapsed += (s, e) =>
            {
                switch (MarqueeAnimation)
                {
                case MarqueeAnimation.Bouncy:
                    switch (_marqueeDirection)
                    {
                    case MarqueeDirection.Right:
                        if (_marqueePosition + MarqueeSpeed + MarqueeWidth
                            > Width)
                        {
                            _marqueeDirection = MarqueeDirection.Left;
                            _marqueePosition -= MarqueeSpeed;
                        }
                        else
                        {
                            _marqueePosition += MarqueeSpeed;
                        }
                        break;

                    case MarqueeDirection.Left:
                        if (_marqueePosition - MarqueeSpeed < Padding.Left)
                        {
                            _marqueeDirection = MarqueeDirection.Right;
                            _marqueePosition += MarqueeSpeed;
                        }
                        else
                        {
                            _marqueePosition -= MarqueeSpeed;
                        }
                        break;
                    }
                    break;

                case MarqueeAnimation.Slide:
                    if (_marqueePosition > Width)
                    {
                        _marqueePosition = -MarqueeWidth;
                    }
                    else
                    {
                        _marqueePosition += MarqueeSpeed;
                    }
                    break;
                }

                Invalidate();
            };
        }
Beispiel #2
0
        public override bool OnAttributeChange(string property)
        {
            if (base.OnAttributeChange(property))
            {
                return(true);
            }

            if (property == "loop")
            {
                Loop = int.Parse(this["loop"]);

                if (Loop == 0)
                {
                    Loop = 1;
                }
                else if (Loop < 0)
                {
                    Loop = -1;
                }
            }
            else if (property == "scrollamount")
            {
                ScrollAmount = int.Parse(this["scrollamount"]);
            }
            else if (property == "scrolldelay")
            {
                ScrollDelay = int.Parse(this["scrolldelay"]);

                if (ScrollDelay < 50)
                {
                    // No super fast scrolling - it's too distracting. Use animate for effects like that.

                    ScrollDelay = 50;
                }
            }
            else if (property == "behaviour")
            {
                ApplyBehaviour(this["behaviour"]);
            }
            else if (property == "behavior")
            {
                ApplyBehaviour(this["behavior"]);
            }
            else if (property == "direction")
            {
                // Grab the direction:
                string direction = this["direction"];

                switch (direction)
                {
                case "left":
                    Direction = MarqueeDirection.Left;
                    break;

                case "right":
                    Direction = MarqueeDirection.Right;
                    break;

                case "up":
                    Direction = MarqueeDirection.Up;
                    break;

                case "down":
                    Direction = MarqueeDirection.Down;
                    break;
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }
Beispiel #3
0
        private void OnTick()
        {
            // Grab the computed style:
            ComputedStyle style = Style.Computed;

            float amount = ScrollAmount;

            // Is it odd? If so, it travels in the inverted direction.
            if (((int)Direction & 1) == 1)
            {
                // Invert the direction:
                amount = -ScrollAmount;
            }

            float scrollLeft = style.ScrollLeft;
            float scrollTop  = style.ScrollTop;

            if ((int)Direction <= 2)
            {
                // Vertical scroll:
                scrollTop += amount;

                // Grab the content height:
                float contentHeight = style.ContentHeight;

                // Grab the parent height:
                float height = style.InnerHeight;

                switch (Behaviour)
                {
                case MarqueeBehaviour.Scroll:

                    if (scrollTop < -height)
                    {
                        // Wrap:
                        scrollTop = contentHeight;

                        Wrapped();
                    }
                    else if (scrollTop > contentHeight)
                    {
                        // Wrap:
                        scrollTop = -height;

                        Wrapped();
                    }

                    break;

                case MarqueeBehaviour.Alternate:

                    float minimum = -(height - contentHeight);

                    if (minimum >= 0)
                    {
                        // No space to bounce anyway.
                        return;
                    }

                    if (scrollTop > 0f)
                    {
                        // Reset:
                        scrollTop = 0f;

                        // Flip the direction.
                        if (Direction == MarqueeDirection.Up)
                        {
                            Direction = MarqueeDirection.Down;
                        }
                        else
                        {
                            Direction = MarqueeDirection.Up;
                        }

                        Bounced();
                    }
                    else if (scrollTop < minimum)
                    {
                        scrollTop = minimum;

                        // Flip the direction.
                        if (Direction == MarqueeDirection.Up)
                        {
                            Direction = MarqueeDirection.Down;
                        }
                        else
                        {
                            Direction = MarqueeDirection.Up;
                        }

                        Bounced();
                    }

                    break;
                }
            }
            else
            {
                // Horizontal scroll:
                scrollLeft += amount;

                // Grab the content width:
                float contentWidth = style.ContentWidth;

                // Grab the parent width:
                float width = style.InnerWidth;

                switch (Behaviour)
                {
                case MarqueeBehaviour.Scroll:

                    if (scrollLeft < -width)
                    {
                        // Wrap:
                        scrollLeft = contentWidth;

                        Wrapped();
                    }
                    else if (scrollLeft > contentWidth)
                    {
                        // Wrap:
                        scrollLeft = -width;

                        Wrapped();
                    }

                    break;

                case MarqueeBehaviour.Alternate:

                    float minimum = -(width - contentWidth);

                    if (minimum >= 0f)
                    {
                        // No space to bounce anyway.
                        return;
                    }

                    if (scrollLeft > 0f)
                    {
                        // Reset:
                        scrollLeft = 0f;

                        // Flip the direction.
                        if (Direction == MarqueeDirection.Left)
                        {
                            Direction = MarqueeDirection.Right;
                        }
                        else
                        {
                            Direction = MarqueeDirection.Left;
                        }

                        Bounced();
                    }
                    else if (scrollLeft < minimum)
                    {
                        scrollLeft = minimum;

                        // Flip the direction.
                        if (Direction == MarqueeDirection.Left)
                        {
                            Direction = MarqueeDirection.Right;
                        }
                        else
                        {
                            Direction = MarqueeDirection.Left;
                        }

                        Bounced();
                    }

                    break;
                }
            }

            // Scroll now:
            scrollTo(scrollLeft, scrollTop);

            // Request a redraw:
            style.RequestLayout();
        }
		private void OnTick(){
			
			// Grab the computed style:
			ComputedStyle style=Element.style.Computed;
			
			int amount=ScrollAmount;
			
			// Is it odd? If so, it travels in the inverted direction.
			if(((int)Direction&1)==1){
				
				// Invert the direction:
				amount=-ScrollAmount;
				
			}
			
			if((int)Direction<=2){
				
				// Vertical scroll:
				style.ScrollTop+=amount;
			
				// Grab the content height:
				int contentHeight=style.ContentHeight;
				
				// Grab the parent height:
				int height=style.InnerHeight;
				
				switch(Behaviour){
					
					case MarqueeBehaviour.Scroll:
						
						if(style.ScrollTop<-height){
							
							// Wrap:
							style.ScrollTop=contentHeight;
							
							Wrapped();
							
						}else if(style.ScrollTop>contentHeight){
							
							// Wrap:
							style.ScrollTop=-height;
							
							Wrapped();
							
						}
						
					break;
					
					case MarqueeBehaviour.Alternate:
						
						int minimum=-(height-contentHeight);
						
						if(minimum>=0){
							
							// No space to bounce anyway.
							return;
							
						}
						
						if(style.ScrollTop>0){
							
							// Reset:
							style.ScrollTop=0;
							
							// Flip the direction.
							if(Direction==MarqueeDirection.Up){
								
								Direction=MarqueeDirection.Down;
								
							}else{
								
								Direction=MarqueeDirection.Up;
								
							}
							
							Bounced();
							
						}else if(style.ScrollTop<minimum){
							
							style.ScrollTop=minimum;
							
							// Flip the direction.
							if(Direction==MarqueeDirection.Up){
								
								Direction=MarqueeDirection.Down;
								
							}else{
								
								Direction=MarqueeDirection.Up;
								
							}
							
							Bounced();
							
						}
						
					break;
					
				}
				
			}else{
				
				// Horizontal scroll:
				style.ScrollLeft+=amount;
				
				// Grab the content width:
				int contentWidth=style.ContentWidth;
				
				// Grab the parent width:
				int width=style.InnerWidth;
				
				switch(Behaviour){
					
					case MarqueeBehaviour.Scroll:
						
						if(style.ScrollLeft<-width){
							
							// Wrap:
							style.ScrollLeft=contentWidth;
							
							Wrapped();
							
						}else if(style.ScrollLeft>contentWidth){
							
							// Wrap:
							style.ScrollLeft=-width;
							
							Wrapped();
							
						}
						
					break;
					
					case MarqueeBehaviour.Alternate:
						
						int minimum=-(width-contentWidth);
						
						if(minimum>=0){
							
							// No space to bounce anyway.
							return;
							
						}
						
						if(style.ScrollLeft>0){
							
							// Reset:
							style.ScrollLeft=0;
							
							// Flip the direction.
							if(Direction==MarqueeDirection.Left){
								
								Direction=MarqueeDirection.Right;
								
							}else{
								
								Direction=MarqueeDirection.Left;
								
							}
							
							Bounced();
							
						}else if(style.ScrollLeft<minimum){
							
							style.ScrollLeft=minimum;
							
							// Flip the direction.
							if(Direction==MarqueeDirection.Left){
								
								Direction=MarqueeDirection.Right;
								
							}else{
								
								Direction=MarqueeDirection.Left;
								
							}
							
							Bounced();
							
						}
						
					break;
					
				}
				
			}
			
			// The below block of code comes from inside the scrollTo function:
			
			// Recompute the size:
			style.SetSize();
			
			// And request a redraw:
			style.RequestLayout();
			
			if(Element.VScrollbar){
				Element.VerticalScrollbar.ElementScrolled();
			}else if(Element.HScrollbar){
				Element.HorizontalScrollbar.ElementScrolled();
			}
			
		}
		public override bool OnAttributeChange(string property){
			
			if(base.OnAttributeChange(property)){
				return true;
			}
			
			if(property=="loop"){
				
				Loop=int.Parse(Element["loop"]);
				
				if(Loop==0){
					Loop=1;
				}else if(Loop<0){
					Loop=-1;
				}
				
			}else if(property=="scrollamount"){
				
				ScrollAmount=int.Parse(Element["scrollamount"]);
				
			}else if(property=="scrolldelay"){
				
				ScrollDelay=int.Parse(Element["scrolldelay"]);
				
				if(ScrollDelay<50){
					
					// No super fast scrolling - it's too distracting. Use animate for effects like that.
					
					ScrollDelay=50;
					
				}
				
			}else if(property=="behaviour"){
				
				ApplyBehaviour(Element["behaviour"]);
				
			}else if(property=="behavior"){
				
				ApplyBehaviour(Element["behavior"]);
				
			}else if(property=="direction"){
				
				// Grab the direction:
				string direction=Element["direction"];
				
				switch(direction){
					
					case "left":
						Direction=MarqueeDirection.Left;
					break;
					
					case "right":
						Direction=MarqueeDirection.Right;
					break;
					
					case "up":
						Direction=MarqueeDirection.Up;
					break;
					
					case "down":
						Direction=MarqueeDirection.Down;
					break;
					
				}
				
			}else{
				
				return false;
				
			}
			
			return true;
			
		}
Beispiel #6
0
        private void OnTick()
        {
            // Grab the computed style:
            ComputedStyle style = Element.style.Computed;

            int amount = ScrollAmount;

            // Is it odd? If so, it travels in the inverted direction.
            if (((int)Direction & 1) == 1)
            {
                // Invert the direction:
                amount = -ScrollAmount;
            }

            if ((int)Direction <= 2)
            {
                // Vertical scroll:
                style.ScrollTop += amount;

                // Grab the content height:
                int contentHeight = style.ContentHeight;

                // Grab the parent height:
                int height = style.InnerHeight;

                switch (Behaviour)
                {
                case MarqueeBehaviour.Scroll:

                    if (style.ScrollTop < -height)
                    {
                        // Wrap:
                        style.ScrollTop = contentHeight;

                        Wrapped();
                    }
                    else if (style.ScrollTop > contentHeight)
                    {
                        // Wrap:
                        style.ScrollTop = -height;

                        Wrapped();
                    }

                    break;

                case MarqueeBehaviour.Alternate:

                    int minimum = -(height - contentHeight);

                    if (minimum >= 0)
                    {
                        // No space to bounce anyway.
                        return;
                    }

                    if (style.ScrollTop > 0)
                    {
                        // Reset:
                        style.ScrollTop = 0;

                        // Flip the direction.
                        if (Direction == MarqueeDirection.Up)
                        {
                            Direction = MarqueeDirection.Down;
                        }
                        else
                        {
                            Direction = MarqueeDirection.Up;
                        }

                        Bounced();
                    }
                    else if (style.ScrollTop < minimum)
                    {
                        style.ScrollTop = minimum;

                        // Flip the direction.
                        if (Direction == MarqueeDirection.Up)
                        {
                            Direction = MarqueeDirection.Down;
                        }
                        else
                        {
                            Direction = MarqueeDirection.Up;
                        }

                        Bounced();
                    }

                    break;
                }
            }
            else
            {
                // Horizontal scroll:
                style.ScrollLeft += amount;

                // Grab the content width:
                int contentWidth = style.ContentWidth;

                // Grab the parent width:
                int width = style.InnerWidth;

                switch (Behaviour)
                {
                case MarqueeBehaviour.Scroll:

                    if (style.ScrollLeft < -width)
                    {
                        // Wrap:
                        style.ScrollLeft = contentWidth;

                        Wrapped();
                    }
                    else if (style.ScrollLeft > contentWidth)
                    {
                        // Wrap:
                        style.ScrollLeft = -width;

                        Wrapped();
                    }

                    break;

                case MarqueeBehaviour.Alternate:

                    int minimum = -(width - contentWidth);

                    if (minimum >= 0)
                    {
                        // No space to bounce anyway.
                        return;
                    }

                    if (style.ScrollLeft > 0)
                    {
                        // Reset:
                        style.ScrollLeft = 0;

                        // Flip the direction.
                        if (Direction == MarqueeDirection.Left)
                        {
                            Direction = MarqueeDirection.Right;
                        }
                        else
                        {
                            Direction = MarqueeDirection.Left;
                        }

                        Bounced();
                    }
                    else if (style.ScrollLeft < minimum)
                    {
                        style.ScrollLeft = minimum;

                        // Flip the direction.
                        if (Direction == MarqueeDirection.Left)
                        {
                            Direction = MarqueeDirection.Right;
                        }
                        else
                        {
                            Direction = MarqueeDirection.Left;
                        }

                        Bounced();
                    }

                    break;
                }
            }

            // The below block of code comes from inside the scrollTo function:

            // Recompute the size:
            style.SetSize();

            // And request a redraw:
            style.RequestLayout();

            if (Element.VScrollbar)
            {
                Element.VerticalScrollbar.ElementScrolled();
            }
            else if (Element.HScrollbar)
            {
                Element.HorizontalScrollbar.ElementScrolled();
            }
        }