Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // The Pimp The Pathetic Image Manipulation Program
  3. // Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org>
  4. // All Rights Reserved
  5. //
  6. // $Id$
  7. //
  8. // This library is free software. It comes without any warranty, to
  9. // the extent permitted by applicable law. You can redistribute it
  10. // and/or modify it under the terms of the Do What The Fuck You Want
  11. // To Public License, Version 2, as published by Sam Hocevar. See
  12. // http://sam.zoy.org/wtfpl/COPYING for more details.
  13. //
  14. using System;
  15. using Gtk;
  16. using Pipi;
  17. namespace ThePimp
  18. {
  19. public class PictureArea : Gtk.DrawingArea
  20. {
  21. private Pipi.Picture _p;
  22. private Pango.Layout _l;
  23. private Adjustment _hadj = null, _vadj = null;
  24. void HAdjust(object sender, EventArgs args)
  25. {
  26. QueueDraw();
  27. }
  28. void VAdjust(object sender, EventArgs args)
  29. {
  30. QueueDraw();
  31. }
  32. protected override bool OnExposeEvent(Gdk.EventExpose e)
  33. {
  34. bool ret = base.OnExposeEvent(e);
  35. //Console.WriteLine("expose {0}x{1}+{2}+{3}", e.Area.Width, e.Area.Height, e.Area.X, e.Area.Y);
  36. GdkWindow.DrawLayout(Style.TextGC(StateType.Normal), 40 - (int)_hadj.Value, 40 - (int)_vadj.Value, _l);
  37. GdkWindow.DrawLayout(Style.TextGC(StateType.Normal), 560 - (int)_hadj.Value, 40 - (int)_vadj.Value, _l);
  38. GdkWindow.DrawLayout(Style.TextGC(StateType.Normal), 40 - (int)_hadj.Value, 560 - (int)_vadj.Value, _l);
  39. GdkWindow.DrawLayout(Style.TextGC(StateType.Normal), 560 - (int)_hadj.Value, 560 - (int)_vadj.Value, _l);
  40. return ret;
  41. }
  42. protected override void OnRealized()
  43. {
  44. _l = new Pango.Layout(PangoContext);
  45. _l.Wrap = Pango.WrapMode.Word;
  46. _l.FontDescription = Pango.FontDescription.FromString("Tahoma 64");
  47. _l.SetMarkup("WHAT THE\nFUCK IS\nTHIS SHIT\nLOL ♥ ♥");
  48. base.OnRealized();
  49. }
  50. protected override void OnSetScrollAdjustments(Adjustment hadj,
  51. Adjustment vadj)
  52. {
  53. _hadj = hadj;
  54. _vadj = vadj;
  55. if(hadj != null)
  56. hadj.ValueChanged += HAdjust;
  57. if(vadj != null)
  58. vadj.ValueChanged += VAdjust;
  59. }
  60. protected override void OnSizeAllocated(Gdk.Rectangle alloc)
  61. {
  62. base.OnSizeAllocated(alloc);
  63. if(_hadj != null)
  64. {
  65. _hadj.SetBounds(0, _p.Width, 1, alloc.Width, alloc.Width);
  66. if(_hadj.Value + alloc.Width > _p.Width)
  67. {
  68. _hadj.Value = _p.Width - alloc.Width;
  69. _hadj.ChangeValue();
  70. }
  71. }
  72. if(_vadj != null)
  73. {
  74. _vadj.SetBounds(0, _p.Height, 1, alloc.Height, alloc.Height);
  75. if(_vadj.Value + alloc.Height > _p.Height)
  76. {
  77. _vadj.Value = _p.Height - alloc.Height;
  78. _vadj.ChangeValue();
  79. }
  80. }
  81. }
  82. protected override void OnDestroyed()
  83. {
  84. if(_hadj != null)
  85. {
  86. _hadj.ValueChanged -= HAdjust;
  87. _hadj = null;
  88. }
  89. if(_vadj != null)
  90. {
  91. _vadj.ValueChanged -= VAdjust;
  92. _vadj = null;
  93. }
  94. }
  95. public PictureArea(Picture p)
  96. {
  97. _p = p;
  98. }
  99. }
  100. public class PictureView : Gtk.ScrolledWindow
  101. {
  102. public PictureView(Picture p)
  103. {
  104. Add(new PictureArea(p));
  105. ShowAll();
  106. }
  107. }
  108. }