private void DrawScrub()
        {
            AppearanceInfo dimensions = CurrentAppearanceInfo();
            Rect           group      = new Rect(x + dimensions.leftSideWidth, y + dimensions.topSideHeight, dimensions.centerWidth, dimensions.centerHeight);

            GUI.BeginGroup(group);
            float xPos = 0, yPos = 0, drawWidth = dimensions.centerWidth, drawHeight = dimensions.centerHeight;
            float progressToPixelDistance = progress;

            if (horizontal)
            {
                drawWidth *= scrubPercentSize; progressToPixelDistance *= (dimensions.centerWidth - drawWidth); xPos += progressToPixelDistance;
            }
            else
            {
                drawHeight *= scrubPercentSize; progressToPixelDistance *= (dimensions.centerHeight - drawHeight); yPos += progressToPixelDistance;
            }
            scrubButton.parentInfo.group = group;
            scrubButton.x      = Mathf.RoundToInt(xPos);
            scrubButton.y      = Mathf.RoundToInt(yPos);
            scrubButton.width  = Mathf.RoundToInt(drawWidth);
            scrubButton.height = Mathf.RoundToInt(drawHeight);
            //scrubButton.text = progress.ToString();
            scrubButton.Draw();
            GUI.EndGroup();
        }
        private void ScrubButton_dragged(OxBase obj, Vector2 delta)
        {
            AppearanceInfo dimensions = CurrentAppearanceInfo();
            float          scrubPosition = scrubButton.x, scrubSize = scrubButton.width, barSize = dimensions.centerWidth, changeInProgress = delta.x;

            if (!horizontal)
            {
                scrubPosition = scrubButton.y; scrubSize = scrubButton.height; barSize = dimensions.centerHeight; changeInProgress = delta.y;
            }

            float amountChanged = progress;

            if (scrubPosition + changeInProgress < 0)
            {
                progress = 0;
            }
            else if (scrubPosition + changeInProgress > barSize - scrubSize)
            {
                progress = 1;
            }
            else
            {
                progress = OxHelpers.TruncateTo((scrubPosition + changeInProgress) / (barSize - scrubSize), 3);
            }

            amountChanged = progress - amountChanged;
            if (amountChanged != 0)
            {
                FireScrollValueChangedEvent(amountChanged);
            }
        }
Exemple #3
0
        internal virtual void TextPaint()
        {
            AppearanceInfo dimensions = CurrentAppearanceInfo();
            float          xPos = x, yPos = y, drawWidth = dimensions.leftSideWidth, drawHeight = dimensions.topSideHeight;

            GUIStyle textStyle = new GUIStyle();

            if (manualSizeAllText)
            {
                textStyle.fontSize = allTextSize;
            }
            else if (autoSizeAllText)
            {
                textStyle.fontSize = OxHelpers.CalculateFontSize(OxHelpers.InchesToPixel(new Vector2(0, 0.2f)).y);
            }
            else if (autoSizeText)
            {
                textStyle.fontSize = OxHelpers.CalculateFontSize(dimensions.centerHeight);
            }
            else
            {
                textStyle.fontSize = textSize;
            }
            textStyle.normal.textColor = textColor;
            textStyle.alignment        = ((TextAnchor)textAlignment);
            textStyle.clipping         = TextClipping.Clip;
            xPos = x; yPos = y; drawWidth = dimensions.leftSideWidth; drawHeight = dimensions.topSideHeight;
            if (textPosition == OxHelpers.Alignment.Top || textPosition == OxHelpers.Alignment.Center || textPosition == OxHelpers.Alignment.Bottom)
            {
                xPos     += dimensions.leftSideWidth;
                drawWidth = dimensions.centerWidth;
            }
            else if (textPosition == OxHelpers.Alignment.Top_Right || textPosition == OxHelpers.Alignment.Right || textPosition == OxHelpers.Alignment.Bottom_Right)
            {
                xPos     += dimensions.leftSideWidth + dimensions.centerWidth;
                drawWidth = dimensions.rightSideWidth;
            }
            if (textPosition == OxHelpers.Alignment.Left || textPosition == OxHelpers.Alignment.Center || textPosition == OxHelpers.Alignment.Right)
            {
                yPos      += dimensions.topSideHeight;
                drawHeight = dimensions.centerHeight;
            }
            else if (textPosition == OxHelpers.Alignment.Bottom_Left || textPosition == OxHelpers.Alignment.Bottom || textPosition == OxHelpers.Alignment.Bottom_Right)
            {
                yPos      += dimensions.topSideHeight + dimensions.centerHeight;
                drawHeight = dimensions.bottomSideHeight;
            }

            string shownText = text;

            if (shownText.Length <= 0 && value != null)
            {
                shownText = value.ToString();
            }
            GUI.Label(new Rect(xPos, yPos, drawWidth, drawHeight), shownText, textStyle);
        }
Exemple #4
0
        protected virtual void DrawContainedItems()
        {
            AppearanceInfo dimensions = CurrentAppearanceInfo();
            Rect           group      = new Rect(x + dimensions.leftSideWidth, y + dimensions.topSideHeight, dimensions.centerWidth, dimensions.centerHeight);

            GUI.BeginGroup(group);
            foreach (OxBase item in items)
            {
                item.parentInfo.group = group;
                item.Draw();
            }
            GUI.EndGroup();
        }
Exemple #5
0
        internal AppearanceInfo CurrentAppearanceInfo()
        {
            AppearanceInfo appearanceInfo = new AppearanceInfo();

            appearanceInfo.state            = GetTexturableState();
            appearanceInfo.centerWidth      = width * centerPercentSize.x;
            appearanceInfo.centerHeight     = height * centerPercentSize.y;
            appearanceInfo.rightSideWidth   = (width - appearanceInfo.centerWidth) * origInfo[((int)appearanceInfo.state)].percentRight;
            appearanceInfo.leftSideWidth    = (width - appearanceInfo.centerWidth) * (1 - origInfo[((int)appearanceInfo.state)].percentRight);
            appearanceInfo.topSideHeight    = (height - appearanceInfo.centerHeight) * origInfo[((int)appearanceInfo.state)].percentTop;
            appearanceInfo.bottomSideHeight = (height - appearanceInfo.centerHeight) * (1 - origInfo[((int)appearanceInfo.state)].percentTop);
            return(appearanceInfo);
        }
Exemple #6
0
        internal override void TextPaint()
        {
            AppearanceInfo dimensions = CurrentAppearanceInfo();
            GUIStyle       textStyle  = new GUIStyle();

            textStyle.font = font;
            if (manualSizeAllText)
            {
                textStyle.fontSize = allTextSize;
            }
            else if (autoSizeAllText)
            {
                textStyle.fontSize = OxHelpers.CalculateFontSize(OxHelpers.InchesToPixel(new Vector2(0, 0.2f)).y);
            }
            else if (autoSizeText)
            {
                textStyle.fontSize = OxHelpers.CalculateFontSize(dimensions.centerHeight);
            }
            else
            {
                textStyle.fontSize = textSize;
            }
            textStyle.normal.textColor = textColor;
            textStyle.wordWrap         = wordWrap;
            textStyle.alignment        = ((TextAnchor)textAlignment);
            textStyle.clipping         = clipping;
            textStyle.contentOffset    = contentOffset;
            textStyle.fontStyle        = fontStyle;
            textStyle.richText         = richText;

            //string shownText = text;
            if (text.Length <= 0 && value != null)
            {
                text = value.ToString();
            }
            string prevText = text;

            if (multiline)
            {
                text = GUI.TextArea(new Rect(x + dimensions.leftSideWidth, y + dimensions.topSideHeight, dimensions.centerWidth, dimensions.centerHeight), text, textStyle);
            }
            else
            {
                text = GUI.TextField(new Rect(x + dimensions.leftSideWidth, y + dimensions.topSideHeight, dimensions.centerWidth, dimensions.centerHeight), text, textStyle);
            }
            if (!prevText.Equals(text))
            {
                FireTextChangedEvent(prevText);
            }
        }
Exemple #7
0
        private void PaintCheckAndBox()
        {
            AppearanceInfo dimensions = CurrentAppearanceInfo();
            bool           horizontal = dimensions.centerWidth >= dimensions.centerHeight;
            float          size       = dimensions.centerHeight;

            if (!horizontal)
            {
                size = dimensions.centerWidth;
            }

            float xPos = x + dimensions.leftSideWidth, yPos = y + dimensions.topSideHeight, drawWidth = size, drawHeight = size;

            if (horizontal && switchSide)
            {
                xPos += dimensions.centerWidth - drawWidth;
            }
            if (!horizontal && switchSide)
            {
                yPos += dimensions.centerHeight - drawHeight;
            }

            checkbox.x      = Mathf.RoundToInt(xPos);
            checkbox.y      = Mathf.RoundToInt(yPos);
            checkbox.width  = Mathf.RoundToInt(drawWidth);
            checkbox.height = Mathf.RoundToInt(drawHeight);
            checkbox.TexturePaint();

            if (checkboxChecked)
            {
                dimensions = checkbox.CurrentAppearanceInfo();
                xPos       = checkbox.x + dimensions.leftSideWidth;
                yPos       = checkbox.y + dimensions.topSideHeight;
                drawWidth  = dimensions.centerWidth;
                drawHeight = dimensions.centerHeight;

                check.x      = Mathf.RoundToInt(xPos);
                check.y      = Mathf.RoundToInt(yPos);
                check.width  = Mathf.RoundToInt(drawWidth);
                check.height = Mathf.RoundToInt(drawHeight);
                check.TexturePaint();
            }
        }
Exemple #8
0
        public virtual void AddItems(params OxBase[] addedItems)
        {
            AppearanceInfo dimensions = CurrentAppearanceInfo();
            Rect           group      = new Rect(x + dimensions.leftSideWidth, y + dimensions.topSideHeight, dimensions.centerWidth, dimensions.centerHeight);

            foreach (OxBase item in addedItems)
            {
                if (item != null)
                {
                    item.x          = item.absoluteX;
                    item.y          = item.absoluteY;
                    item.parentInfo = new ParentInfo(this, group);
                    item.absoluteX  = item.x;
                    item.absoluteY  = item.y;
                    item.clicked   += Item_clicked;
                    items.Add(item);
                }
            }
        }
Exemple #9
0
        private void DrawContainerButtons()
        {
            AppearanceInfo dimensions = CurrentAppearanceInfo();
            Rect           group      = new Rect(position, size);

            GUI.BeginGroup(group);
            for (int row = 0; row < 3; row++)
            {
                for (int col = 0; col < 3; col++)
                {
                    if (containerButtons[((row * 3) + col)].elementFunction != OxHelpers.ElementType.None)
                    {
                        float xPos = 0, yPos = 0, drawWidth = dimensions.leftSideWidth, drawHeight = dimensions.topSideHeight;
                        if (col > 0)
                        {
                            xPos += dimensions.leftSideWidth; drawWidth = dimensions.centerWidth;
                        }
                        if (col > 1)
                        {
                            xPos += dimensions.centerWidth; drawWidth = dimensions.rightSideWidth;
                        }
                        if (row > 0)
                        {
                            yPos += dimensions.topSideHeight; drawHeight = dimensions.centerHeight;
                        }
                        if (row > 1)
                        {
                            yPos += dimensions.centerHeight; drawHeight = dimensions.bottomSideHeight;
                        }

                        containerButtons[((row * 3) + col)].parentInfo.group = group;
                        containerButtons[((row * 3) + col)].x      = Mathf.RoundToInt(xPos);
                        containerButtons[((row * 3) + col)].y      = Mathf.RoundToInt(yPos);
                        containerButtons[((row * 3) + col)].width  = Mathf.RoundToInt(drawWidth);
                        containerButtons[((row * 3) + col)].height = Mathf.RoundToInt(drawHeight);

                        containerButtons[((row * 3) + col)].Draw();
                    }
                }
            }
            GUI.EndGroup();
        }
Exemple #10
0
        internal override void TextPaint()
        {
            AppearanceInfo dimensions = CurrentAppearanceInfo();
            string         shownText  = text;

            if (shownText.Length <= 0 && value != null)
            {
                shownText = value.ToString();
            }
            label.text = shownText;
            bool  horizontal   = dimensions.centerWidth >= dimensions.centerHeight;
            float checkboxSize = dimensions.centerHeight;

            if (!horizontal)
            {
                checkboxSize = dimensions.centerWidth;
            }

            float xPos = x + dimensions.leftSideWidth, yPos = y + dimensions.topSideHeight, drawWidth = dimensions.centerWidth - checkboxSize, drawHeight = dimensions.centerHeight;

            if (horizontal && !switchSide)
            {
                xPos += checkboxSize;
            }
            if (!horizontal)
            {
                drawWidth  = dimensions.centerWidth;
                drawHeight = dimensions.centerHeight - checkboxSize;
                if (!switchSide)
                {
                    yPos += checkboxSize;
                }
            }

            label.x      = Mathf.RoundToInt(xPos);
            label.y      = Mathf.RoundToInt(yPos);
            label.width  = Mathf.RoundToInt(drawWidth);
            label.height = Mathf.RoundToInt(drawHeight);
            label.Paint();
        }
Exemple #11
0
        internal virtual void TexturePaint()
        {
            AppearanceInfo dimensions     = CurrentAppearanceInfo();
            Texture2D      currentTexture = null;

            UpdateNonPixeliness(((int)dimensions.state));

            float xPos = x, yPos = y, drawWidth = dimensions.leftSideWidth, drawHeight = dimensions.topSideHeight;

            for (int row = 0; row < 3; row++)
            {
                for (int col = 0; col < 3; col++)
                {
                    xPos = x; yPos = y; drawWidth = dimensions.leftSideWidth; drawHeight = dimensions.topSideHeight;
                    if (col > 0)
                    {
                        xPos += dimensions.leftSideWidth; drawWidth = dimensions.centerWidth;
                    }
                    if (col > 1)
                    {
                        xPos += dimensions.centerWidth; drawWidth = dimensions.rightSideWidth;
                    }
                    if (row > 0)
                    {
                        yPos += dimensions.topSideHeight; drawHeight = dimensions.centerHeight;
                    }
                    if (row > 1)
                    {
                        yPos += dimensions.centerHeight; drawHeight = dimensions.bottomSideHeight;
                    }

                    currentTexture = appearances[((int)dimensions.state), ((row * 3) + col)];
                    if (currentTexture != null)
                    {
                        GUI.DrawTexture(new Rect(xPos, yPos, drawWidth, drawHeight), currentTexture);
                    }
                }
            }
        }
Exemple #12
0
        protected override void DrawContainedItems()
        {
            AppearanceInfo dimensions = CurrentAppearanceInfo();
            Rect           group      = new Rect(x + dimensions.leftSideWidth, y + dimensions.topSideHeight, dimensions.centerWidth, dimensions.centerHeight);

            GUI.BeginGroup(group);
            float xPos = 0, yPos = 0, menuItemWidth = dimensions.centerWidth, menuItemHeight = dimensions.centerHeight;

            #region Add Scrollbar
            if (itemsCount > itemsShown && !hideScrollbar)
            {
                #region Scrollbar
                float scrollbarXPos = 0, scrollbarYPos = 0, scrollbarWidth = dimensions.centerWidth * scrollbarPercentSpaceTaken, scrollbarHeight = dimensions.centerHeight;
                scrollbar.horizontal = horizontal;
                if (horizontal)
                {
                    scrollbarWidth  = dimensions.centerWidth;
                    scrollbarHeight = dimensions.centerHeight * scrollbarPercentSpaceTaken;
                    if (!switchScrollbarSide)
                    {
                        scrollbarYPos += dimensions.centerHeight - scrollbarHeight;
                    }
                }
                else
                {
                    if (switchScrollbarSide)
                    {
                        scrollbarXPos += dimensions.centerWidth - scrollbarWidth;
                    }
                }
                scrollbar.parentInfo.group = group;
                scrollbar.x      = Mathf.RoundToInt(scrollbarXPos);
                scrollbar.y      = Mathf.RoundToInt(scrollbarYPos);
                scrollbar.width  = Mathf.RoundToInt(scrollbarWidth);
                scrollbar.height = Mathf.RoundToInt(scrollbarHeight);

                scrollbar.Draw();
                #endregion
                #region Fit Menu Items with Scrollbar
                if (horizontal)
                {
                    if (switchScrollbarSide)
                    {
                        yPos += scrollbarHeight;
                    }
                    menuItemHeight -= scrollbarHeight;
                }
                else
                {
                    if (!switchScrollbarSide)
                    {
                        xPos += scrollbarWidth;
                    }
                    menuItemWidth -= scrollbarWidth;
                }
                #endregion
            }
            #endregion

            int actualItemsShown = itemsShown;
            if (itemsCount < itemsShown && fitItemsWhenLess)
            {
                actualItemsShown = itemsCount;
            }

            if (horizontal)
            {
                menuItemWidth = ((menuItemWidth - (cushion * (actualItemsShown - 1))) / actualItemsShown);
            }
            else
            {
                menuItemHeight = ((menuItemHeight - (cushion * (actualItemsShown - 1))) / actualItemsShown);
            }

            //float menuItemMainSize = menuItemHeight;
            //if (horizontal) menuItemMainSize = menuItemWidth;
            //float fullListSize = (menuItemMainSize * (itemsCount - itemsShown)) + (cushion * ((itemsCount - itemsShown) - 1));

            float scrollPixelProgress = (items.Count - actualItemsShown) * scrollbar.progress;
            //float scrollPixelProgress = fullListSize * scrollbar.progress;

            int index      = Mathf.RoundToInt(scrollPixelProgress);
            int firstIndex = index;
            for (int i = 0; i < actualItemsShown; i++)
            {
                if (i + index < items.Count)
                {
                    items[i + index].parentInfo.group = group;

                    float specificIndex = scrollPixelProgress - (firstIndex + i);
                    if (horizontal)
                    {
                        items[i + index].x = Mathf.RoundToInt(xPos - (menuItemWidth * specificIndex) - (cushion * specificIndex));
                        items[i + index].y = Mathf.RoundToInt(yPos);
                    }
                    else
                    {
                        items[i + index].x = Mathf.RoundToInt(xPos);
                        items[i + index].y = Mathf.RoundToInt(yPos - (menuItemHeight * specificIndex) - (cushion * specificIndex));
                    }
                    items[i + index].width  = Mathf.RoundToInt(menuItemWidth);
                    items[i + index].height = Mathf.RoundToInt(menuItemHeight);
                    items[i + index].Draw();
                }
            }
            GUI.EndGroup();

            if (amountDragged != 0)
            {
                float menuItemMainSize = menuItemHeight;
                if (horizontal)
                {
                    menuItemMainSize = menuItemWidth;
                }
                float fullListSize = (menuItemMainSize * (itemsCount - itemsShown)) + (cushion * ((itemsCount - itemsShown) - 1));

                float scrollAddition = (amountDragged / fullListSize);
                //float scrollAddition = (amountDragged * ((menuItemMainSize * (itemsCount - itemsShown)) / fullListSize));
                //float scrollAddition = amountDragged / (menuItemMainSize * (itemsCount - itemsShown));

                if ((scrollAddition > 0 && (scrollProgress + scrollAddition) < 1) || (scrollAddition < 0 && (scrollProgress + scrollAddition) > 0))
                {
                    scrollProgress += scrollAddition;
                }
                else if (scrollAddition > 0)
                {
                    scrollProgress = 1; amountDragged = 0;
                }
                else if (scrollAddition < 0)
                {
                    scrollProgress = 0; amountDragged = 0;
                }

                if (amountDragged > 0)
                {
                    if (amountDragged - drift > 0)
                    {
                        amountDragged -= drift;
                    }
                    else
                    {
                        amountDragged = 0;
                    }
                }
                else
                {
                    if (amountDragged + drift < 0)
                    {
                        amountDragged += drift;
                    }
                    else
                    {
                        amountDragged = 0;
                    }
                }
            }
        }