Exemple #1
0
        public override void CursorPressed(Vector2 cursorPos)
        {
            if (!scrollHandle.IsVisible)             // don't care about clicks if text not scrollable
            {
                return;
            }

            Vector2 co = CursorOffset(scrollHandle, cursorPos);

            if (co.SquaredLength <= 81f)
            {
                dragging   = true;
                dragOffset = co.y;
            }
            else if (IsCursorOver(scrollTrack, cursorPos))
            {
                float newTop        = scrollHandle.Top + co.y;
                float lowerBoundary = scrollTrack.Height - scrollHandle.Height;
                scrollHandle.Top = (UIMathHelper.clamp <int>((int)newTop, 0, (int)lowerBoundary));

                // update text area contents based on new scroll percentage
                scrollPercentage = UIMathHelper.clamp <float>(newTop / lowerBoundary, 0f, 1f);
                filterLines();
            }
        }
Exemple #2
0
        protected float getSnappedValue(float percentage)
        {
            percentage = UIMathHelper.clamp <float>(percentage, 0f, 1f);
            uint whichMarker = (uint)(percentage * (mMaxValue - mMinValue) / mInterval + 0.5f);

            return(whichMarker * mInterval + mMinValue);
        }
Exemple #3
0
        public override void CursorMoved(Mogre.Vector2 cursorPos)
        {
            Mogre.OverlayManager om = Mogre.OverlayManager.Singleton;

            if (isExpanded)
            {
                if (isDragging)
                {
                    Mogre.Vector2 co            = Widget.CursorOffset(scrollHandleElement, cursorPos);
                    float         newTop        = scrollHandleElement.Top + co.y - dragOffset;
                    float         lowerBoundary = scrollTrackElement.Height - scrollHandleElement.Height;
                    scrollHandleElement.Top = (UIMathHelper.clamp <int>((int)newTop, 0, (int)lowerBoundary));

                    float scrollPercentage = UIMathHelper.clamp <float>(newTop / lowerBoundary, 0f, 1f);
                    int   newIndex         = (int)(scrollPercentage * (Items.Count - itemElements.Count) + 0.5f);
                    if (newIndex != displayIndex)
                    {
                        setDisplayIndex((uint)newIndex);
                    }
                    return;
                }

                float l = itemElements[0]._getDerivedLeft() * om.ViewportWidth + 5f;
                float t = itemElements[0]._getDerivedTop() * om.ViewportHeight + 5f;
                float r = l + itemElements[itemElements.Count - 1].Width - 10f;
                float b = itemElements[itemElements.Count - 1]._getDerivedTop() * om.ViewportHeight + itemElements[itemElements.Count - 1].Height - 5f;

                if (cursorPos.x >= l && cursorPos.x <= r && cursorPos.y >= t && cursorPos.y <= b)
                {
                    int newIndex = (int)(displayIndex + (cursorPos.y - t) / (b - t) * itemElements.Count);
                    if (highlightIndex != newIndex)
                    {
                        highlightIndex = newIndex;
                        setDisplayIndex((uint)displayIndex);
                    }
                }
            }
            else
            {
                if (IsCursorOver(smallBoxElement, cursorPos, 4f))
                {
                    smallBoxElement.MaterialName       = ("SdkTrays/MiniTextBox/Over");
                    smallBoxElement.BorderMaterialName = ("SdkTrays/MiniTextBox/Over");
                    isCursorOver = true;
                }
                else
                {
                    if (isCursorOver)
                    {
                        smallBoxElement.MaterialName       = ("SdkTrays/MiniTextBox");
                        smallBoxElement.BorderMaterialName = ("SdkTrays/MiniTextBox");
                        isCursorOver = false;
                    }
                }
            }
        }
Exemple #4
0
        public override void CursorMoved(Mogre.Vector2 cursorPos)
        {
            if (mDragging)
            {
                Mogre.Vector2 co            = Widget.CursorOffset(mHandle, cursorPos);
                float         newLeft       = mHandle.Left + co.x - mDragOffset;
                float         rightBoundary = mTrack.Width - mHandle.Width;

                mHandle.Left = (UIMathHelper.clamp <int>((int)newLeft, 0, (int)rightBoundary));
                setValue(getSnappedValue(newLeft / rightBoundary));
            }
        }
Exemple #5
0
        public override void CursorMoved(Mogre.Vector2 cursorPos)
        {
            if (dragging)
            {
                Vector2 co            = Widget.CursorOffset(scrollHandle, cursorPos);
                float   newTop        = scrollHandle.Top + co.y - dragOffset;
                float   lowerBoundary = scrollTrack.Height - scrollHandle.Height;
                scrollHandle.Top = (UIMathHelper.clamp <int>((int)newTop, 0, (int)lowerBoundary));

                // update text area contents based on new scroll percentage
                scrollPercentage = UIMathHelper.clamp <float>(newTop / lowerBoundary, 0f, 1f);
                filterLines();
            }
        }
Exemple #6
0
        //ORIGINAL LINE: void setValue(Ogre::Real value, bool notifyListener = true)
        public void setValue(float @value, bool notifyListener)
        {
            if (mInterval == 0)
            {
                return;
            }

            mValue = UIMathHelper.clamp <float>(@value, mMinValue, mMaxValue);

            setValueCaption((mValue).ToString());

            if (listener != null && notifyListener)
            {
                listener.sliderMoved(this);
            }

            if (!mDragging)
            {
                mHandle.Left = ((int)((mValue - mMinValue) / (mMaxValue - mMinValue) * (mTrack.Width - mHandle.Width)));
            }
        }
Exemple #7
0
        public override void CursorPressed(Mogre.Vector2 cursorPos)
        {
            if (!mHandle.IsVisible)
            {
                return;
            }

            Mogre.Vector2 co = Widget.CursorOffset(mHandle, cursorPos);

            if (co.SquaredLength <= 81f)
            {
                mDragging   = true;
                mDragOffset = co.x;
            }
            else if (Widget.IsCursorOver(mTrack, cursorPos))
            {
                float newLeft       = mHandle.Left + co.x;
                float rightBoundary = mTrack.Width - mHandle.Width;

                mHandle.Left = (UIMathHelper.clamp <int>((int)newLeft, 0, (int)rightBoundary));
                setValue(getSnappedValue(newLeft / rightBoundary));
            }
        }
 /// <summary>
 /// Sets the progress as a percentage.
 /// </summary>
 /// <param name="progress"></param>
 public void setProgress(float progress)
 {
     this.progress     = UIMathHelper.clamp <float>(progress, 0f, 1f);
     fillElement.Width = (System.Math.Max((int)fillElement.Height, (int)(this.progress * (meterElement.Width - 2 * fillElement.Left))));
 }
Exemple #9
0
        public override void CursorPressed(Mogre.Vector2 cursorPos)
        {
            Mogre.OverlayManager om = Mogre.OverlayManager.Singleton;

            if (isExpanded)
            {
                if (scrollHandleElement.IsVisible)                 // check for scrolling
                {
                    Mogre.Vector2 co = Widget.CursorOffset(scrollHandleElement, cursorPos);

                    if (co.SquaredLength <= 81f)
                    {
                        isDragging = true;
                        dragOffset = co.y;
                        return;
                    }
                    else if (Widget.IsCursorOver(scrollTrackElement, cursorPos))
                    {
                        float newTop        = scrollHandleElement.Top + co.y;
                        float lowerBoundary = scrollTrackElement.Height - scrollHandleElement.Height;
                        scrollHandleElement.Top = (UIMathHelper.clamp <int>((int)newTop, 0, (int)lowerBoundary));

                        float scrollPercentage = UIMathHelper.clamp <float>(newTop / lowerBoundary, 0f, 1f);
                        setDisplayIndex((uint)(scrollPercentage * (Items.Count - itemElements.Count) + 0.5f));
                        return;
                    }
                }

                if (!IsCursorOver(expandedBoxElement, cursorPos, 3f))
                {
                    retract();
                }
                else
                {
                    float l = itemElements[0]._getDerivedLeft() * om.ViewportWidth + 5f;
                    float t = itemElements[0]._getDerivedTop() * om.ViewportHeight + 5f;
                    float r = l + itemElements[itemElements.Count - 1].Width - 10f;
                    float b = itemElements[itemElements.Count - 1]._getDerivedTop() * om.ViewportHeight + itemElements[itemElements.Count - 1].Height - 5;

                    if (cursorPos.x >= l && cursorPos.x <= r && cursorPos.y >= t && cursorPos.y <= b)
                    {
                        if (highlightIndex != selectionIndex)
                        {
                            SelectItem((uint)highlightIndex);
                        }
                        retract();
                    }
                }
            }
            else
            {
                if (Items.Count < 2)                 // don't waste time showing a menu if there's no choice
                {
                    return;
                }

                if (IsCursorOver(smallBoxElement, cursorPos, 4f))
                {
                    expandedBoxElement.Show();
                    smallBoxElement.Hide();

                    // calculate how much vertical space we need
                    float idealHeight = itemsShown * (smallBoxElement.Height - 8f) + 20f;
                    expandedBoxElement.Height = (idealHeight);
                    scrollTrackElement.Height = (expandedBoxElement.Height - 20f);

                    expandedBoxElement.Left = (smallBoxElement.Left - 4f);

                    // if the expanded menu goes down off the screen, make it go up instead
                    if (smallBoxElement._getDerivedTop() * om.ViewportHeight + idealHeight > om.ViewportHeight)
                    {
                        expandedBoxElement.Top = (smallBoxElement.Top + smallBoxElement.Height - idealHeight + 3f);
                        // if we're in thick style, hide the caption because it will interfere with the expanded menu
                        if (textAreaElement.HorizontalAlignment == GuiHorizontalAlignment.GHA_CENTER)
                        {
                            textAreaElement.Hide();
                        }
                    }
                    else
                    {
                        expandedBoxElement.Top = (smallBoxElement.Top + 3f);
                    }

                    isExpanded     = true;
                    highlightIndex = selectionIndex;
                    setDisplayIndex((uint)highlightIndex);

                    if (itemsShown < Items.Count)                     // update scrollbar position
                    {
                        scrollHandleElement.Show();
                        float lowerBoundary = scrollTrackElement.Height - scrollHandleElement.Height;
                        scrollHandleElement.Top = ((int)(displayIndex * lowerBoundary / (Items.Count - itemElements.Count)));
                    }
                    else
                    {
                        scrollHandleElement.Hide();
                    }
                }
            }
        }
Exemple #10
0
 /// <summary>
 /// Sets how far scrolled down the text is as a percentage.
 /// </summary>
 /// <param name="percentage"></param>
 public void setScrollPercentage(float percentage)
 {
     scrollPercentage = UIMathHelper.clamp <float>(percentage, 0f, 1f);            //Mogre.Math.Clamp<float>(percentage, 0, 1);
     scrollHandle.Top = ((int)(percentage * (scrollTrack.Height - scrollHandle.Height)));
     filterLines();
 }