SpriteViewWidget.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 OpenGl;
  17. using Sprites;
  18. using Gtk;
  19. /// <summary>Simple class that draws one sprite and can embed itself in a window</summary>
  20. public class SpriteViewWidget : GLWidgetBase
  21. {
  22. private Sprite sprite;
  23. /// <summary>Returns SpriteViewWidget inserted in a window</summary>
  24. public static Window CreateWindow(Sprite sprite)
  25. {
  26. Gtk.Window window = new Window(WindowType.Popup);
  27. SpriteViewWidget widget = new SpriteViewWidget(sprite);
  28. window.SetSizeRequest( (int)sprite.Width, (int)sprite.Height);
  29. window.Add(widget);
  30. window.ShowAll();
  31. return window;
  32. }
  33. public SpriteViewWidget(Sprite sprite)
  34. {
  35. this.sprite = sprite;
  36. SetSizeRequest( (int)sprite.Width, (int)sprite.Height);
  37. }
  38. /// <summary>Redraw Widget</summary>
  39. protected override void DrawGl()
  40. {
  41. gl.Clear(gl.COLOR_BUFFER_BIT);
  42. if( sprite != null ){
  43. sprite.Draw(sprite.Offset);
  44. }
  45. }
  46. }
  47. /* EOF */