public override void OnDraw() { T totalExtra = BorderWidth.Add(TextPadding); RectDouble <T> Bounds = new RectDouble <T>(totalExtra.Negative(), totalExtra.Negative(), m_ButtonText.Width.Add(totalExtra), m_ButtonText.Height.Add(totalExtra)); RoundedRect <T> rectBorder = new RoundedRect <T>(Bounds, m_BorderRadius); GetRenderer().Render(rectBorder, new RGBA_Bytes(0, 0, 0)); RectDouble <T> insideBounds = Bounds; insideBounds.Inflate(BorderWidth.Negative()); RoundedRect <T> rectInside = new RoundedRect <T>(insideBounds, M.New <T>(Math.Max(m_BorderRadius.Subtract(BorderWidth).ToDouble(), 0))); RGBA_Bytes insideColor = new RGBA_Bytes(1.0, 1.0, 1.0); if (MouseOverButton) { if (MouseDownOnButton) { insideColor = new RGBA_Bytes(255, 110, 110); } else { insideColor = new RGBA_Bytes(225, 225, 255); } } GetRenderer().Render(rectInside, insideColor); #if false double x1, y1, x2, y2; m_ButtonText.GetTextBounds(out x1, out y1, out x2, out y2); RoundedRect rectText = new RoundedRect(x1, y1, x2, y2, 0); conv_stroke rectOutline = new conv_stroke(rectText); GetRenderer().Render(rectOutline, new RGBA_Bytes(1.0, 0, 0)); #endif #if false RoundedRect rectText2 = new RoundedRect(m_ButtonText.Bounds, 0); conv_stroke rectOutline2 = new conv_stroke(rectText2); GetRenderer().Render(rectOutline, new RGBA_Bytes(0, 0, 1.0)); #endif base.OnDraw(); }
public ButtonWidget(T x, T y, string lable, T textHeight, T textPadding, T borderWidth, T borderRadius) { m_X = x; m_Y = y; SetTransform(MatrixFactory <T> .NewTranslation(x, y)); m_ButtonText = new TextWidget <T>(lable, M.Zero <T>(), M.Zero <T>(), textHeight); AddChild(m_ButtonText); TextPadding = textPadding; BorderWidth = borderWidth; BorderRadius = borderRadius; T totalExtra = BorderWidth.Add(TextPadding); m_Bounds.Left = totalExtra.Negative(); m_Bounds.Bottom = totalExtra.Negative(); m_Bounds.Right = m_ButtonText.Width.Add(totalExtra); m_Bounds.Top = m_ButtonText.Height.Add(totalExtra); }