//Will render itSelf the Compass sprite public void Render(CompassControl control, IFlatGuiGraphics graphics) { if (control.HidedPanel) { return; } RectangleF absoluteBound = control.GetAbsoluteBounds(); //Draw the DayCircle First SharpDX.Rectangle sourceRect = new SharpDX.Rectangle(0, 0, 150, 75); graphics.DrawCustomTexture(control.DayCircle, ref sourceRect, ref absoluteBound, control.RotationDayCycle, control.sampler); //Draw the main WindRose for direction graphics.DrawCustomTexture(control.CompassTexture, ref sourceRect, ref absoluteBound, control.Rotation, control.sampler); //Draw the Mask Arrow SharpDX.Rectangle sourceRectMaskArrow = new SharpDX.Rectangle(0, 0, 150, 150); RectangleF absoluteBoundMask = new RectangleF(absoluteBound.X, absoluteBound.Y, absoluteBound.Width, 150); graphics.DrawCustomTexture(control.MaskArrow, ref sourceRectMaskArrow, ref absoluteBoundMask, 0.0f, control.sampler); SharpDX.Rectangle sourceRectSoulStoneIcon = new SharpDX.Rectangle(0, 0, 25, 25); RectangleF absoluteBoundSoulStone = new RectangleF(absoluteBound.X + 62.5f, absoluteBound.Y + 72.5f, 25, 25); graphics.DrawCustomTexture(control.SoulStoneIcon, ref sourceRectSoulStoneIcon, ref absoluteBoundSoulStone, 0.0f, control.sampler, 0, new ByteColor((int)(control.SoulStoneFacing * 255f), 0, 0, 255)); }
public void Render(MapControl control, IFlatGuiGraphics graphics) { if (control.MapTexture != null) { RectangleF bound = control.GetAbsoluteBounds(); graphics.DrawCustomTexture(control.MapTexture, ref bound); } if (control.PlayerMarker != null) { var bounds = control.GetAbsoluteBounds(); var scaleX = control.MapTexture.Width / bounds.Width; var scaleY = control.MapTexture.Height / bounds.Height; var point = control.MarkerPosition; point.Offset(control.MapTexture.Width / 2, control.MapTexture.Height / 2); point = new Point((int)(bounds.X + point.X / scaleX), (int)(bounds.Y + point.Y / scaleY)); RectangleF bound = new RectangleF( point.X - control.PlayerMarker.Width / 2, point.Y - control.PlayerMarker.Height / 2, control.PlayerMarker.Width, control.PlayerMarker.Height); graphics.DrawCustomTexture(control.PlayerMarker, ref bound); } }
public void Render(Controls.Desktop.ImageControl control, IFlatGuiGraphics graphics) { RectangleF rect = control.GetAbsoluteBounds(); //rect.X = control.Bounds.Location.X.Offset; //rect.Y = control.Bounds.Location.Y.Offset; //rect.Width = control.Bounds.Size.X.Offset; //rect.Height = control.Bounds.Size.Y.Offset; rect.X = (int)rect.X; rect.Y = (int)rect.Y; if (control.Image != null) { if (control.Stretch) { graphics.DrawCustomTexture(control.Image, ref rect, 0, control.DrawGroupId); } else { graphics.DrawCustomTextureTiled(control.Image, ref rect, 0, control.DrawGroupId); } } }
public void Render(ContainerControl control, IFlatGuiGraphics graphics) { if (control.DisplayBackground && control.Background != null) { var absoluteBounds = control.GetAbsoluteBounds(); graphics.DrawCustomTexture(control.Background, ref absoluteBounds, 0, control.DrawGroupId); } }
public void Render(PaletteButtonControl control, IFlatGuiGraphics graphics) { RectangleF controlBounds = control.GetAbsoluteBounds(); // Determine the style to use for the button int stateIndex = 0; if (control.Enabled) { if (control.Depressed) { stateIndex = 3; } else if (control.MouseHovering || control.HasFocus) { stateIndex = 2; } else { stateIndex = 1; } } // Draw the button's frame ByteColor color = control.Color; graphics.DrawElement(states[stateIndex], ref controlBounds, ref color); RectangleF innerBounds = controlBounds; innerBounds.Inflate(-1f, -1f); if (control.Texture != null) { graphics.DrawCustomTexture(control.Texture, ref innerBounds); } // If there's text assigned to the button, draw it into the button if (!string.IsNullOrEmpty(control.Text)) { graphics.DrawString(states[stateIndex], 0, ref controlBounds, control.Text, true); } }
/// <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.WindowControl control, IFlatGuiGraphics graphics ) { RectangleF controlBounds = control.GetAbsoluteBounds(); if (control.CustomWindowImage == null) { graphics.DrawElement("window", ref controlBounds); } else { graphics.DrawCustomTexture(control.CustomWindowImage, ref controlBounds, 0, control.DrawGroupId); } if (control.Title != null) { graphics.DrawString("window", 0, ref controlBounds, control.Title, false); } }
public void Render(AlphaImageButtonControl control, IFlatGuiGraphics graphics) { RectangleF controlBounds = control.GetAbsoluteBounds(); // Determine the style to use for the button var stateIndex = ButtonState.Disabled; if (control.Enabled) { if (control.Depressed) { stateIndex = ButtonState.Down; } else if (control.MouseHovering || control.HasFocus) { stateIndex = ButtonState.Hover; } else { stateIndex = ButtonState.Default; } } float alpha; SpriteTexture tex; switch (stateIndex) { case ButtonState.Default: alpha = control.AlphaDefault; tex = control.CustomImage; break; case ButtonState.Down: alpha = control.AlphaDown; tex = control.CustomImageDown; break; case ButtonState.Hover: alpha = control.AlphaHover; tex = control.CustomImageHover; break; case ButtonState.Disabled: alpha = control.AlphaDisabled; tex = control.CustomImageDisabled; break; default: alpha = 0f; tex = null; break; } if (alpha == 0f || tex == null) { return; } alpha = MathHelper.Clamp(alpha, 0, 1); graphics.DrawCustomTexture(tex, ref controlBounds, 0, control.DrawGroupId, new ByteColor(255, 255, 255, (int)(255 * alpha))); if (control.CusomImageLabel != null) { var imgRect = controlBounds; imgRect.X += (imgRect.Width - control.CusomImageLabel.Width) / 2; imgRect.Y += (imgRect.Height - control.CusomImageLabel.Height) / 2; imgRect.Width = control.CusomImageLabel.Width; imgRect.Height = control.CusomImageLabel.Height; if (stateIndex == ButtonState.Down) { imgRect.Y += 1; } graphics.DrawCustomTexture(control.CusomImageLabel, ref imgRect, 0, control.DrawGroupId, new ByteColor(255, 255, 255, (int)(255 * alpha))); } }
/// <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; }
public void Render(InventoryCell control, IFlatGuiGraphics graphics) { var controlBounds = control.GetAbsoluteBounds(); #region Backgroung if (control.DrawCellBackground) { if (control.MouseHovering || control.IsCellSelected) { if (control.CustomBackgroundHover != null) { if (control.CustomBackgroundAutosize) { graphics.DrawCustomTexture(control.CustomBackgroundHover, ref controlBounds, 0, control.DrawGroupId); } else { var dx = (controlBounds.Width - control.CustomBackgroundHover.Width) / 2; var dy = (controlBounds.Height - control.CustomBackgroundHover.Height) / 2; var bgBounds = controlBounds; bgBounds.X += dx; bgBounds.Y += dy; bgBounds.Width = control.CustomBackgroundHover.Width; bgBounds.Height = control.CustomBackgroundHover.Height; graphics.DrawCustomTexture(control.CustomBackgroundHover, ref bgBounds, 0, control.DrawGroupId); } } else { graphics.DrawElement("button.highlighted", ref controlBounds); } } else { if (control.CustomBackground != null) { if (control.CustomBackgroundAutosize) { graphics.DrawCustomTexture(control.CustomBackground, ref controlBounds, 0, control.DrawGroupId); } else { var dx = (controlBounds.Width - control.CustomBackground.Width) / 2; var dy = (controlBounds.Height - control.CustomBackground.Height) / 2; var bgBounds = controlBounds; bgBounds.X += dx; bgBounds.Y += dy; bgBounds.Width = control.CustomBackground.Width; bgBounds.Height = control.CustomBackground.Height; graphics.DrawCustomTexture(control.CustomBackground, ref bgBounds, 0, control.DrawGroupId); } } else { graphics.DrawElement("button.normal", ref controlBounds, control.DrawGroupId); } } } #endregion #region Item icon if (control.Slot != null && !control.Slot.IsEmpty) { SpriteTexture tex; int textureArrayIndex; control.IconFactory.Lookup(control.Slot.Item, out tex, out textureArrayIndex); if (tex != null) { const int innerBorder = 3; var texBounds = new RectangleF( controlBounds.X + innerBorder, controlBounds.Y + innerBorder, controlBounds.Width - innerBorder * 2, controlBounds.Height - innerBorder * 2 ); ByteColor?color = control.Color; if (control.IsDisabledCell) { color = new ByteColor(255, 255, 255, 30); } graphics.DrawCustomTexture(tex, ref texBounds, textureArrayIndex, control.DrawIconsGroupId, color); } else { var displayName = control.Slot.Item.Name; graphics.DrawString("button.normal", 0, ref controlBounds, displayName, false, -1, control.DrawGroupId); } } #endregion #region Items count if ((control.Slot != null && control.Slot.ItemsCount > 1) || !string.IsNullOrEmpty(control.CountString)) { var itemsCount = control.CountString ?? control.Slot.ItemsCount.ToString(); var textSize = graphics.MeasureString("slot.items", ref controlBounds, itemsCount); var h = textSize.Height; var w = textSize.Width; var textPosition = new RectangleF(controlBounds.X + controlBounds.Width - textSize.Width - 6, controlBounds.Y + controlBounds.Height - textSize.Height, w, h); graphics.DrawString("slot.items.shadow", 0, ref textPosition, itemsCount, false, -1, control.DrawGroupId); graphics.DrawString("slot.items", 0, ref textPosition, itemsCount, false, -1, control.DrawGroupId); } #endregion }
/// <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.ButtonControl control, IFlatGuiGraphics graphics ) { RectangleF controlBounds = control.GetAbsoluteBounds(); // Determine the style to use for the button int stateIndex = 0; if (control.Enabled) { if (control.Depressed) { stateIndex = 3; } else if (control.MouseHovering || control.HasFocus) { stateIndex = 2; } else { stateIndex = 1; } } if (stateIndex == 0) { if (control.CustomImageDisabled != null) { graphics.DrawCustomTexture(control.CustomImageDisabled, ref controlBounds); } else if (control.CustomImage != null) { graphics.DrawCustomTexture(control.CustomImage, ref controlBounds, 0, control.DrawGroupId, new ByteColor(255, 255, 255, 100)); } } else if (stateIndex == 1 && control.CustomImage != null) { graphics.DrawCustomTexture(control.CustomImage, ref controlBounds); } else if (stateIndex == 2 && control.CustomImageHover != null) { graphics.DrawCustomTexture(control.CustomImageHover, ref controlBounds); } else if (stateIndex == 3 && control.CustomImageDown != null) { graphics.DrawCustomTexture(control.CustomImageDown, ref controlBounds); } else { // Draw the button's frame graphics.DrawElement(states[stateIndex], ref controlBounds); } if (control.CusomImageLabel != null) { var imgRect = controlBounds; imgRect.X += (imgRect.Width - control.CusomImageLabel.Width) / 2; imgRect.Y += (imgRect.Height - control.CusomImageLabel.Height) / 2; imgRect.Width = control.CusomImageLabel.Width; imgRect.Height = control.CusomImageLabel.Height; if (stateIndex == 3) { imgRect.Y += 1; } if (stateIndex == 0) { graphics.DrawCustomTexture(control.CusomImageLabel, ref imgRect, 0, control.DrawGroupId, new ByteColor(255, 255, 255, 100)); } else { graphics.DrawCustomTexture(control.CusomImageLabel, ref imgRect); } } else if (!string.IsNullOrEmpty(control.Text)) { if (control.CustomFont != null) { ByteColor color = control.Color; graphics.DrawString(control.CustomFont, ref controlBounds, control.Text, ref color, false, -1, FlatGuiGraphics.Frame.HorizontalTextAlignment.Center, FlatGuiGraphics.Frame.VerticalTextAlignment.Center); } else { if (control.ColorSet) { ByteColor color = control.Color; graphics.DrawString(states[stateIndex], control.TextFontId, ref controlBounds, control.Text, ref color, false); } else { graphics.DrawString(states[stateIndex], control.TextFontId, ref controlBounds, control.Text, false); } } } }