ColorNode.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // $Id$
  2. using System;
  3. using OpenGl;
  4. using Drawing;
  5. namespace SceneGraph {
  6. /// <summary>
  7. /// Scene graph node that changes the drawing color. Note that you can make
  8. /// stuff (half-)transparent by changing the alpha value of the drawing
  9. /// color.
  10. /// </summary>
  11. /// <remarks>
  12. /// If <see cref="CanSkip"/> is set and the alpha value is 0 then this scene graph node will not call
  13. /// Draw of the child at all.
  14. /// </remarks>
  15. public sealed class ColorNode : Node {
  16. public Color Color;
  17. public Node Child;
  18. public bool CanSkip;
  19. public ColorNode() {
  20. }
  21. /// <summary>
  22. /// Create a new <see cref="ColorNode"/>.
  23. /// </summary>
  24. /// <param name="Child">The child scene graph <see cref="Node"/>.</param>
  25. /// <param name="Color">The color to use.</param>
  26. public ColorNode(Node Child, Color Color) {
  27. this.Child = Child;
  28. this.Color = Color;
  29. }
  30. /// <summary>
  31. /// Create a new <see cref="ColorNode"/>.
  32. /// </summary>
  33. /// <param name="Child">The child scene graph <see cref="Node"/>.</param>
  34. /// <param name="Color">The color to use.</param>
  35. /// <param name="CanSkip">If true we can skip drawing when <see cref="Drawing.Color.Alpha"/> is 0.</param>
  36. public ColorNode(Node Child, Color Color, bool CanSkip) {
  37. this.Child = Child;
  38. this.Color = Color;
  39. this.CanSkip = CanSkip;
  40. }
  41. public void Draw(Gdk.Rectangle cliprect) {
  42. if (Child == null)
  43. return;
  44. // Can we skip drawing at all if Color.Alpha == 0?
  45. if (CanSkip && Color.Alpha == 0f) return;
  46. gl.Color4f(Color.Red, Color.Green, Color.Blue, Color.Alpha);
  47. Child.Draw(cliprect);
  48. gl.Color4f(0, 0, 0, 1f);
  49. }
  50. }
  51. }