ColorNode.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // SuperTux Editor
  2. // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. using System;
  17. using OpenGl;
  18. using Drawing;
  19. namespace SceneGraph {
  20. /// <summary>
  21. /// Scene graph node that changes the drawing color. Note that you can make
  22. /// stuff (half-)transparent by changing the alpha value of the drawing
  23. /// color.
  24. /// </summary>
  25. /// <remarks>
  26. /// If <see cref="CanSkip"/> is set and the alpha value is 0 then this scene graph node will not call
  27. /// Draw of the child at all.
  28. /// </remarks>
  29. public sealed class ColorNode : Node {
  30. public Color Color;
  31. public Node Child;
  32. public bool CanSkip;
  33. public ColorNode() {
  34. }
  35. /// <summary>
  36. /// Create a new <see cref="ColorNode"/>.
  37. /// </summary>
  38. /// <param name="Child">The child scene graph <see cref="Node"/>.</param>
  39. /// <param name="Color">The color to use.</param>
  40. public ColorNode(Node Child, Color Color) {
  41. this.Child = Child;
  42. this.Color = Color;
  43. }
  44. /// <summary>
  45. /// Create a new <see cref="ColorNode"/>.
  46. /// </summary>
  47. /// <param name="Child">The child scene graph <see cref="Node"/>.</param>
  48. /// <param name="Color">The color to use.</param>
  49. /// <param name="CanSkip">If true we can skip drawing when <see cref="Drawing.Color.Alpha"/> is 0.</param>
  50. public ColorNode(Node Child, Color Color, bool CanSkip) {
  51. this.Child = Child;
  52. this.Color = Color;
  53. this.CanSkip = CanSkip;
  54. }
  55. public void Draw(Gdk.Rectangle cliprect) {
  56. if (Child == null)
  57. return;
  58. // Can we skip drawing at all if Color.Alpha == 0?
  59. if (CanSkip && Color.Alpha == 0f) return;
  60. gl.Color4f(Color.Red, Color.Green, Color.Blue, Color.Alpha);
  61. Child.Draw(cliprect);
  62. gl.Color4f(0, 0, 0, 1f);
  63. }
  64. }
  65. }
  66. /* EOF */