/// <summary> /// Renders the specified control using the provided graphics interface /// </summary> /// <param name="control">Control that will be rendered</param> /// <param name="graphics"> /// Graphics interface that will be used to draw the control /// </param> public void Render( Controls.Desktop.InputControl control, IFlatGuiGraphics graphics ) { RectangleF controlBounds = control.GetAbsoluteBounds(); // Draw the control's frame and background graphics.DrawElement(Style, controlBounds); using (graphics.SetClipRegion(controlBounds)) { string text = control.Text ?? string.Empty; // Amount by which the text will be moved within the input box in // order to keep the caret in view even when the text is wider than // the input box. float left = 0; // Only scroll the text within the input box when it has the input // focus and the caret is being shown. if (control.HasFocus) { // Find out where the cursor is from the left end of the text RectangleF stringSize = graphics.MeasureString( Style, controlBounds, text.Substring(0, control.CaretPosition) ); // TODO: Renderer should query the size of the control's frame // Otherwise text will be visible over the frame, which might look bad // if a skin uses a frame wider than 2 pixels or in a different color // than the text. while (stringSize.Width + left > controlBounds.Width) { left -= controlBounds.Width / 10.0f; } } // Draw the text into the input box controlBounds.X += left; graphics.DrawString(Style, controlBounds, control.Text); // If the input box is in focus, also draw the caret so the user knows // where characters will be inserted into the text. if (control.HasFocus) { if (control.MillisecondsSinceLastCaretMovement % 500 < 250) { graphics.DrawCaret( "input.normal", controlBounds, control.Text, control.CaretPosition ); } } } // Let the control know that we can provide it with additional informations // about how its text is being rendered control.OpeningLocator = this; this.graphics = graphics; }
/// <summary> /// Renders the specified control using the provided graphics interface /// </summary> /// <param name="control">Control that will be rendered</param> /// <param name="graphics"> /// Graphics interface that will be used to draw the control /// </param> public void Render(Controls.Desktop.ListControl control, IFlatGuiGraphics graphics) { this.graphics = graphics; RectangleF controlBounds = control.GetAbsoluteBounds(); graphics.DrawElement(Style, ref controlBounds); // Cache the number of items in the list (as a float, this comes in handy later) // and the height of a single item when rendered float totalItems = control.Items.Count; float rowHeight = GetRowHeight(controlBounds); // Number of items (+fraction) fitting into the list's height float itemsInView = controlBounds.Height / rowHeight; // Number of items by which the slider can move up and down float scrollableArea = Math.Max(totalItems - itemsInView, 0.0f); // Index (+fraction) of the item at the top of the list given // the slider's current position float scrollPosition = control.Slider.ThumbPosition * scrollableArea; // Determine the first and the last item we need to draw // (no need to draw the whole of the list when only a small subset // will end up in the clipping area) int firstItem = (int)scrollPosition; int lastItem = (int)Math.Ceiling(scrollPosition + itemsInView); lastItem = Math.Min(lastItem, control.Items.Count); // Set up a rectangle we can use to track the bounds of the item // currently being rendered RectangleF itemBounds = controlBounds; itemBounds.Y -= (scrollPosition - firstItem) * rowHeight; itemBounds.Height = rowHeight; //Force a scissor zone for drawing ! => Will flush the previously accumulated information using (graphics.SetClipRegion(ref controlBounds)) { for (int item = firstItem; item < lastItem; ++item) { if (control.SelectedItems.Contains(item)) { graphics.DrawElement("list.selection", ref itemBounds); } graphics.DrawString(Style, 0, ref itemBounds, control.Items[item].ToString(), false); //graphics.DrawElement("button.normal", itemBounds); itemBounds.Y += rowHeight; } } control.ListRowLocator = this; }
/// <summary> /// Renders the specified control using the provided graphics interface /// </summary> /// <param name="control">Control that will be rendered</param> /// <param name="graphics"> /// Graphics interface that will be used to draw the control /// </param> public void Render(GuiListControl control, IFlatGuiGraphics graphics) { _graphics = graphics; var controlBounds = control.GetAbsoluteBounds(); graphics.DrawElement(_style, controlBounds); // Cache the number of items in the list (as a float, this comes in handy later) // and the height of a single item when rendered float totalItems = control.Items.Count; var rowHeight = GetRowHeight(controlBounds); // Number of items (+fraction) fitting into the list's height var itemsInView = controlBounds.Height / rowHeight; // Number of items by which the slider can move up and down var scrollableArea = Math.Max(totalItems - itemsInView, 0.0f); // Index (+fraction) of the item at the top of the list given // the slider's current position var scrollPosition = control.Slider.ThumbPosition * scrollableArea; // Determine the first and the last item we need to draw // (no need to draw the whole of the list when only a small subset // will end up in the clipping area) var firstItem = (int)scrollPosition; var lastItem = (int)Math.Ceiling(scrollPosition + itemsInView); lastItem = Math.Min(lastItem, control.Items.Count); // Set up a rectangle we can use to track the bounds of the item // currently being rendered var itemBounds = controlBounds; itemBounds.Y -= (scrollPosition - firstItem) * rowHeight; itemBounds.Height = rowHeight; using (graphics.SetClipRegion(controlBounds)) { for (var item = firstItem; item < lastItem; ++item) { if (control.SelectedItems.Contains(item)) { graphics.DrawElement("list.selection", itemBounds); } graphics.DrawString(_style, itemBounds, control.Items[item]); itemBounds.Y += rowHeight; } } control.ListRowLocator = this; }
/// <summary> /// Renders the specified control using the provided graphics interface /// </summary> /// <param name="control">Control that will be rendered</param> /// <param name="graphics"> /// Graphics interface that will be used to draw the control /// </param> public void Render(Controls.Desktop.InputControl control, IFlatGuiGraphics graphics) { RectangleF controlBounds = control.GetAbsoluteBounds(); // Draw the control's frame and background if (control.CustomBackground == null) { graphics.DrawElement(Style, ref controlBounds); } else { graphics.DrawCustomTexture(control.CustomBackground, ref controlBounds); } if (control.CustomHintImage != null && string.IsNullOrEmpty(control.Text) && !control.HasFocus) { var bounds = controlBounds; bounds.Width = control.CustomHintImage.Width; bounds.Height = control.CustomHintImage.Height; if (!control.CustomHintImageOffset.HasValue) { var dx = (controlBounds.Height - bounds.Height) / 2; bounds.X += dx; bounds.Y += dx; } else { bounds.X += control.CustomHintImageOffset.Value.X; bounds.Y += control.CustomHintImageOffset.Value.Y; } graphics.DrawCustomTexture(control.CustomHintImage, ref bounds); } //Clip the region using (graphics.SetClipRegion(ref controlBounds)) { string text = control.Text ?? string.Empty; // Amount by which the text will be moved within the input box in // order to keep the caret in view even when the text is wider than // the input box. float left = 0; // Only scroll the text within the input box when it has the input // focus and the caret is being shown. if (control.HasFocus) { float offSetSize = 0; // Find out where the cursor is from the left end of the text RectangleF stringSize; if (control.CustomFont == null) { stringSize = graphics.MeasureString(Style, ref controlBounds, text.Substring(0, control.CaretPosition)); } else { stringSize = graphics.MeasureString(control.CustomFont, ref controlBounds, text.Substring(0, control.CaretPosition)); offSetSize = control.CustomFont.Size; } // exTODO: Renderer should query the size of the control's frame // Otherwise text will be visible over the frame, which might look bad // if a skin uses a frame wider than 2 pixels or in a different color // than the text. while ((stringSize.Width + offSetSize) + left > controlBounds.Width) { left -= controlBounds.Width / 10.0f; } } // Draw the text into the input box controlBounds.X += left; string textToDraw = control.Text; if (control.IsPassword) { textToDraw = new string('*', textToDraw.Length); } int withCarret = -1; // If the input box is in focus, also draw the caret so the user knows // where characters will be inserted into the text. if (control.HasFocus) { if (control.MillisecondsSinceLastCaretMovement % 500 < 250) { withCarret = control.CaretPosition; } } if (control.ColorSet) { ByteColor color = control.Color; if (control.CustomFont != null) { if (!control.TextOffset.HasValue) { var dx = (controlBounds.Height - control.CustomFont.HeightInPoints) / 2; var dy = (controlBounds.Height - control.CustomFont.CharHeight) / 2; controlBounds.X += dx; controlBounds.Y += dy; } else { controlBounds.X += control.TextOffset.Value.X; controlBounds.Y += control.TextOffset.Value.Y; } graphics.DrawString(control.CustomFont, ref controlBounds, textToDraw, ref color, false, withCarret); } else { graphics.DrawString(Style, 0, ref controlBounds, textToDraw, ref color, false, withCarret); } } else { if (control.CustomFont != null) { ByteColor color = control.Color; if (!control.TextOffset.HasValue) { var dx = (controlBounds.Height - control.CustomFont.HeightInPoints) / 2; var dy = (controlBounds.Height - control.CustomFont.CharHeight) / 2; controlBounds.X += dx; controlBounds.Y += dy; } else { controlBounds.X += control.TextOffset.Value.X; controlBounds.Y += control.TextOffset.Value.Y; } graphics.DrawString(control.CustomFont, ref controlBounds, textToDraw, ref color, false, withCarret); } else { graphics.DrawString(Style, 0, ref controlBounds, textToDraw, false, withCarret); } } } // Let the control know that we can provide it with additional informations // about how its text is being rendered control.OpeningLocator = this; this.graphics = graphics; }
/// <summary> /// Renders the specified control using the provided graphics interface /// </summary> /// <param name="control">Control that will be rendered</param> /// <param name="graphics"> /// Graphics interface that will be used to draw the control /// </param> public void Render(Controls.Desktop.InputKeyCatchControl control, IFlatGuiGraphics graphics) { RectangleF controlBounds = control.GetAbsoluteBounds(); // Draw the control's frame and background if (control.CustomBackground == null) { if (control.HasFocus) { graphics.DrawElement(Style, ref controlBounds, ref control.HasFocusBackColor); } else { graphics.DrawElement(Style, ref controlBounds); } } else { graphics.DrawCustomTexture(control.CustomBackground, ref controlBounds); } if (control.CustomHintImage != null && string.IsNullOrEmpty(control.Text) && !control.HasFocus) { var bounds = controlBounds; bounds.Width = control.CustomHintImage.Width; bounds.Height = control.CustomHintImage.Height; var dx = (controlBounds.Height - bounds.Height) / 2; bounds.X += dx; bounds.Y += dx; graphics.DrawCustomTexture(control.CustomHintImage, ref bounds); } using (graphics.SetClipRegion(ref controlBounds)) { string text = control.Text ?? string.Empty; // Amount by which the text will be moved within the input box in // order to keep the caret in view even when the text is wider than // the input box. float left = 0; // Only scroll the text within the input box when it has the input // focus and the caret is being shown. if (control.HasFocus) { // Find out where the cursor is from the left end of the text RectangleF stringSize = graphics.MeasureString(Style, ref controlBounds, text); // exTODO: Renderer should query the size of the control's frame // Otherwise text will be visible over the frame, which might look bad // if a skin uses a frame wider than 2 pixels or in a different color // than the text. while (stringSize.Width + left > controlBounds.Width) { left -= controlBounds.Width / 10.0f; } } // Draw the text into the input box controlBounds.X += left; string textToDraw = control.Text; // If the input box is in focus, also draw the caret so the user knows // where characters will be inserted into the text. if (control.ColorSet) { ByteColor color = control.Color; if (control.CustomFont != null) { var move = (controlBounds.Height - control.CustomFont.CharHeight) / 2; controlBounds.X += move; controlBounds.Y += move; #if DEBUG if (move <= 2) { logger.Warn("Input component height ({0}) too small for the font size ({1})!", controlBounds.Height, control.CustomFont.CharHeight); } #endif graphics.DrawString(control.CustomFont, ref controlBounds, textToDraw, ref color, false); } else { graphics.DrawString(Style, 0, ref controlBounds, textToDraw, ref color, false); } } else { if (control.CustomFont != null) { ByteColor color = control.Color; var move = (controlBounds.Height - control.CustomFont.CharHeight) / 2; controlBounds.X += move; controlBounds.Y += move; graphics.DrawString(control.CustomFont, ref controlBounds, textToDraw, ref color, false); } else { graphics.DrawString(Style, 0, ref controlBounds, textToDraw, false); } } } // Let the control know that we can provide it with additional informations // about how its text is being rendered this.graphics = graphics; }