/// <summary>
        /// Adds a font to the resource manager
        /// </summary>
        public int AddFont(string faceName, uint height, FontWeight weight)
        {
            // See if this font exists
            for (int i = 0; i < _fontCache.Count; i++)
            {
                FontNode fn = _fontCache[i];
                if ((string.Compare(fn.FaceName, faceName, StringComparison.OrdinalIgnoreCase) == 0) &&
                    fn.Height == height &&
                    fn.Weight == weight)
                {
                    // Found it
                    return(i);
                }
            }

            // Doesn't exist, add a new one and try to create it
            var newNode = new FontNode {
                FaceName = faceName, Height = height, Weight = weight
            };

            _fontCache.Add(newNode);

            int fontIndex = _fontCache.Count - 1;

            // If a device is available, try to create immediately
            if (Engine != null)
            {
                CreateFont(fontIndex);
            }

            return(fontIndex);
        }
Example #2
0
        /// <summary>Update the rectangles for the list box control</summary>
        protected override void UpdateRectangles()
        {
            // Get bounding box
            base.UpdateRectangles();

            // Calculate the size of the selection rectangle
            selectionRect        = boundingBox;
            selectionRect.Width -= scrollWidth;
            selectionRect.Inflate(-border, -border);
            textRect = selectionRect;
            textRect.Inflate(-margin, 0);

            // Update the scroll bars rects too
            scrollbarControl.SetLocation(boundingBox.Right - scrollWidth, boundingBox.Top);
            scrollbarControl.SetSize(scrollWidth, height);
            FontNode fNode = parentDialog.DialogManager.GetFontNode((int)elementList[0].FontIndex);

            if ((fNode != null) && (fNode.Height > 0))
            {
                scrollbarControl.PageSize = (int)(textRect.Height / fNode.Height);

                // The selected item may have been scrolled off the page.
                // Ensure that it is in page again.
                scrollbarControl.ShowItem(selectedIndex);
            }
        }
        /// <summary>
        /// Creates a font
        /// </summary>
        public void CreateFont(int font)
        {
            // Get the font node here
            FontNode fn = GetFontNode(font);

            if (fn.Font != null)
            {
                fn.Font.Dispose(); // Get rid of this
            }
            // Create the new font
            fn.Font = new Font(Engine.Device, (int)fn.Height, 0, fn.Weight, 1, false, CharacterSet.Default,
                               // ReSharper disable BitwiseOperatorOnEnumWihtoutFlags
                               Precision.Default, FontQuality.Default, PitchAndFamily.Default | PitchAndFamily.DontCare, fn.FaceName);
            // ReSharper restore BitwiseOperatorOnEnumWihtoutFlags
        }
Example #4
0
        /// <summary>Update the rectangles for the dropdown list control</summary>
        protected override void UpdateRectangles()
        {
            // Get bounding box
            base.UpdateRectangles();

            // Update the bounding box for the items
            buttonRect = new Rectangle(boundingBox.Right - boundingBox.Height, boundingBox.Top,
                                       boundingBox.Height, boundingBox.Height);

            textRect      = boundingBox;
            textRect.Size = new Size(textRect.Width - buttonRect.Width, textRect.Height);

            dropDownRect = textRect;
            dropDownRect.Offset(0, (int)(0.9f * textRect.Height));
            dropDownRect.Size = new Size(dropDownRect.Width - scrollWidth, dropDownRect.Height + dropHeight);

            // Scale it down slightly
            Point loc  = dropDownRect.Location;
            Size  size = dropDownRect.Size;

            loc.X       += (int)(0.1f * dropDownRect.Width);
            loc.Y       += (int)(0.1f * dropDownRect.Height);
            size.Width  -= (2 * (int)(0.1f * dropDownRect.Width));
            size.Height -= (2 * (int)(0.1f * dropDownRect.Height));

            dropDownTextRect = new Rectangle(loc, size);

            // Update the scroll bars rects too
            scrollbarControl.SetLocation(dropDownRect.Right, dropDownRect.Top + 2);
            scrollbarControl.SetSize(scrollWidth, dropDownRect.Height - 2);
            FontNode fNode = parentDialog.DialogManager.GetFontNode(
                (int)(elementList[2]).FontIndex);

            if ((fNode != null) && (fNode.Height > 0))
            {
                scrollbarControl.PageSize = (int)(dropDownTextRect.Height / fNode.Height);

                // The selected item may have been scrolled off the page.
                // Ensure that it is in page again.
                scrollbarControl.ShowItem(selectedIndex);
            }
        }
Example #5
0
        /// <summary>Called when the control should be rendered</summary>
        public override void Render(Device device, float elapsedTime)
        {
            var state = ControlState.Normal;

            if (!isComboOpen)
            {
                state = ControlState.Hidden;
            }

            // Dropdown box
            Element e = elementList[DropdownLayer];

            // If we have not initialized the scroll bar page size,
            // do that now.
            if (!isScrollBarInit)
            {
                FontNode fNode = parentDialog.DialogManager.GetFontNode((int)e.FontIndex);
                if ((fNode != null) && (fNode.Height > 0))
                {
                    scrollbarControl.PageSize = (int)(dropDownTextRect.Height / fNode.Height);
                }
                else
                {
                    scrollbarControl.PageSize = dropDownTextRect.Height;
                }

                isScrollBarInit = true;
            }

            if (isComboOpen)
            {
                using (new ProfilerEvent(() => "Render GUI control: " + scrollbarControl))
                    scrollbarControl.Render(device, elapsedTime);
            }

            // Blend current color
            e.TextureColor.Blend(state, elapsedTime);
            e.FontColor.Blend(state, elapsedTime);
            parentDialog.DrawSprite(e, dropDownRect);

            // Selection outline
            Element selectionElement = elementList[SelectionLayer];

            selectionElement.TextureColor.Current = e.TextureColor.Current;
            selectionElement.FontColor.Current    = selectionElement.FontColor.States[(int)ControlState.Normal];

            FontNode font            = parentDialog.DialogManager.GetFontNode((int)e.FontIndex);
            int      currentY        = dropDownTextRect.Top;
            int      remainingHeight = dropDownTextRect.Height;

            for (int i = scrollbarControl.TrackPosition; i < itemList.Count; i++)
            {
                ListItem cbi = itemList[i];

                // Make sure there's room left in the dropdown
                remainingHeight -= (int)font.Height;
                if (remainingHeight < 0)
                {
                    // Not visible, store that item
                    cbi.IsItemVisible = false;
                    itemList[i]       = cbi; // Store this back in list
                    continue;
                }

                cbi.ItemRect = new Rectangle(dropDownTextRect.Left, currentY,
                                             dropDownTextRect.Width, (int)font.Height);
                cbi.IsItemVisible = true;
                currentY         += (int)font.Height;
                itemList[i]       = cbi; // Store this back in list

                if (isComboOpen)
                {
                    if (focusedIndex == i)
                    {
                        var rect = new Rectangle(
                            dropDownRect.Left, cbi.ItemRect.Top - 2, dropDownRect.Width,
                            cbi.ItemRect.Height + 4);
                        parentDialog.DrawSprite(selectionElement, rect);
                        parentDialog.DrawText(cbi.ItemText, selectionElement, cbi.ItemRect);
                    }
                    else
                    {
                        parentDialog.DrawText(cbi.ItemText, e, cbi.ItemRect);
                    }
                }
            }

            int offsetX = 0;
            int offsetY = 0;

            state = ControlState.Normal;
            if (IsVisible == false)
            {
                state = ControlState.Hidden;
            }
            else if (IsEnabled == false)
            {
                state = ControlState.Disabled;
            }
            else if (isPressed)
            {
                state   = ControlState.Pressed;
                offsetX = 1;
                offsetY = 2;
            }
            else if (isMouseOver)
            {
                state   = ControlState.MouseOver;
                offsetX = -1;
                offsetY = -2;
            }
            else if (hasFocus)
            {
                state = ControlState.Focus;
            }

            float blendRate = (state == ControlState.Pressed) ? 0.0f : 0.8f;

            // Button
            e = elementList[ComboButtonLayer];

            // Blend current color
            e.TextureColor.Blend(state, elapsedTime, blendRate);

            Rectangle windowRect = buttonRect;

            windowRect.Offset(offsetX, offsetY);
            // Draw sprite
            parentDialog.DrawSprite(e, windowRect);

            if (isComboOpen)
            {
                state = ControlState.Pressed;
            }

            // Main text box
            e = elementList[MainLayer];

            // Blend current color
            e.TextureColor.Blend(state, elapsedTime, blendRate);
            e.FontColor.Blend(state, elapsedTime, blendRate);

            // Draw sprite
            parentDialog.DrawSprite(e, textRect);

            if (selectedIndex >= 0 && selectedIndex < itemList.Count)
            {
                try
                {
                    ListItem cbi = itemList[selectedIndex];
                    parentDialog.DrawText(cbi.ItemText, e, new Rectangle(
                                              new Point(textRect.Left + 5, textRect.Top),
                                              new Size(textRect.Width - 10, textRect.Height)));
                }
                catch (ArgumentOutOfRangeException)
                {} // Ignore
            }
        }