Layer.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 System.Collections.Generic;
  18. using System.Collections;
  19. namespace SceneGraph
  20. {
  21. /// <summary>
  22. /// A scene graph node which organizes it's childs in layers
  23. /// You can put a child in a layer. The layers are drawn in ascending order
  24. /// ("You can place stuff in foreground and background layers")
  25. /// </summary>
  26. public sealed class Layer : Node
  27. {
  28. private SortedList Layers = new SortedList();
  29. public void Add(float Layer, Node Child)
  30. {
  31. if(Layers[Layer] == null)
  32. Layers[Layer] = new List<Node>();
  33. if(Child == null)
  34. throw new Exception("Somebody has passed Child==null to Layer.Add");
  35. List<Node> Childs = (List<Node>) Layers[Layer];
  36. Childs.Add(Child);
  37. }
  38. public void Remove(float Layer, Node Child)
  39. {
  40. if(Layers[Layer] == null)
  41. throw new Exception("Failed to Remove SceneGraph node - No object was found in layer \""+ Layer.ToString() +"\"");
  42. if(Child == null)
  43. throw new Exception("Somebody has passed Child==null to Layer.Remove");
  44. List<Node> Childs = (List<Node>) Layers[Layer];
  45. Childs.Remove(Child);
  46. }
  47. public void Clear()
  48. {
  49. Layers.Clear();
  50. }
  51. public void Draw(Gdk.Rectangle cliprect)
  52. {
  53. foreach(DictionaryEntry Entry in Layers) {
  54. List<Node> List = (List<Node>) Entry.Value;
  55. foreach(Node Child in List) {
  56. Child.Draw(cliprect);
  57. }
  58. }
  59. }
  60. }
  61. }
  62. /* EOF */