private bool MouseOnButton(RenderWindow win) { Vector2i mousePos = win.InternalGetMousePosition(); return(spriteRect.Contains(mousePos.X, mousePos.Y)); }
public static void GetPoints_ContainsAllPointsInRect() { var rect = new IntRect(1, 1, 3, 3); var points = rect.GetPoints(); Assert.AreEqual(9, points.Count); for (int i = 0; i < points.Count; ++i) Assert.That(rect.Contains(points[i])); }
private int RenderBlock(int leftPos, int rightPos, Color?selectedTextColor, Color bgColor, IntRect rectContent, IFastGridCellBlock block, FastGridCellAddress cellAddr, bool leftAlign, bool isHoverCell) { bool renderBlock = true; if (block.MouseHoverBehaviour == MouseHoverBehaviours.HideWhenMouseOut && !isHoverCell) { renderBlock = false; } int width = 0, top = 0, height = 0; switch (block.BlockType) { case FastGridBlockType.Text: var font = GetFont(block.IsBold, block.IsItalic); int textHeight = font.GetTextHeight(block.TextData); width = font.GetTextWidth(block.TextData, _columnSizes.MaxSize); height = textHeight; top = rectContent.Top + (int)Math.Round(rectContent.Height / 2.0 - textHeight / 2.0); break; case FastGridBlockType.Image: top = rectContent.Top + (int)Math.Round(rectContent.Height / 2.0 - block.ImageHeight / 2.0); height = block.ImageHeight; width = block.ImageWidth; break; } if (renderBlock && block.CommandParameter != null) { var activeRect = new IntRect(new IntPoint(leftAlign ? leftPos : rightPos - width, top), new IntSize(width, height)).GrowSymmetrical(1, 1); var region = new ActiveRegion { CommandParameter = block.CommandParameter, Rect = activeRect, Tooltip = block.ToolTip, }; CurrentCellActiveRegions.Add(region); if (_mouseCursorPoint.HasValue && activeRect.Contains(_mouseCursorPoint.Value)) { _drawBuffer.FillRectangle(activeRect, ActiveRegionHoverFillColor); CurrentHoverRegion = region; } bool renderRectangle = true; if (block.MouseHoverBehaviour == MouseHoverBehaviours.HideButtonWhenMouseOut && !isHoverCell) { renderRectangle = false; } if (renderRectangle) { _drawBuffer.DrawRectangle(activeRect, ActiveRegionFrameColor); } } switch (block.BlockType) { case FastGridBlockType.Text: if (renderBlock) { var textOrigin = new IntPoint(leftAlign ? leftPos : rightPos - width, top); var font = GetFont(block.IsBold, block.IsItalic); var fontcolor = selectedTextColor ?? block.FontColor ?? ((cellAddr.IsColumnHeader) ? (cellAddr.IsColumnFilter) ? HeaderFilterFontColor : HeaderFontColor : CellFontColor); _drawBuffer.DrawString(textOrigin.X, textOrigin.Y, rectContent, fontcolor, UseClearType ? bgColor : (Color?)null, font, block.TextData); } break; case FastGridBlockType.Image: if (renderBlock) { var imgOrigin = new IntPoint(leftAlign ? leftPos : rightPos - block.ImageWidth, top); var image = GetImage(block.ImageSource); _drawBuffer.Blit(new Point(imgOrigin.X, imgOrigin.Y), image.Bitmap, new Rect(0, 0, block.ImageWidth, block.ImageHeight), image.KeyColor, image.BlendMode); } break; } return(width); }