Layer.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // $Id$
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Collections;
  5. namespace SceneGraph
  6. {
  7. /// <summary>
  8. /// A scene graph node which organizes it's childs in layers
  9. /// You can put a child in a layer. The layers are drawn in ascending order
  10. /// ("You can place stuff in foreground and background layers")
  11. /// </summary>
  12. public sealed class Layer : Node
  13. {
  14. private SortedList Layers = new SortedList();
  15. public void Add(float Layer, Node Child)
  16. {
  17. if(Layers[Layer] == null)
  18. Layers[Layer] = new List<Node>();
  19. List<Node> Childs = (List<Node>) Layers[Layer];
  20. Childs.Add(Child);
  21. }
  22. public void Remove(float Layer, Node Child)
  23. {
  24. if(Layers[Layer] == null)
  25. throw new Exception("Specified Layer is empty");
  26. List<Node> Childs = (List<Node>) Layers[Layer];
  27. Childs.Remove(Child);
  28. }
  29. public void Clear()
  30. {
  31. Layers.Clear();
  32. }
  33. public void Draw(Gdk.Rectangle cliprect)
  34. {
  35. foreach(DictionaryEntry Entry in Layers) {
  36. List<Node> List = (List<Node>) Entry.Value;
  37. foreach(Node Child in List) {
  38. Child.Draw(cliprect);
  39. }
  40. }
  41. }
  42. }
  43. }