// // The Pimp The Pathetic Image Manipulation Program // Copyright (c) 2004-2008 Sam Hocevar // All Rights Reserved // // $Id$ // // This library is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it // and/or modify it under the terms of the Do What The Fuck You Want // To Public License, Version 2, as published by Sam Hocevar. See // http://sam.zoy.org/wtfpl/COPYING for more details. // using System; using Gtk; using Pipi; namespace ThePimp { public class PictureArea : Gtk.DrawingArea { private Pipi.Picture _p; private Pango.Layout _l; private Adjustment _hadj = null, _vadj = null; void HAdjust(object sender, EventArgs args) { QueueDraw(); } void VAdjust(object sender, EventArgs args) { QueueDraw(); } protected override bool OnExposeEvent(Gdk.EventExpose e) { bool ret = base.OnExposeEvent(e); //Console.WriteLine("expose {0}x{1}+{2}+{3}", e.Area.Width, e.Area.Height, e.Area.X, e.Area.Y); GdkWindow.DrawLayout(Style.TextGC(StateType.Normal), 40 - (int)_hadj.Value, 40 - (int)_vadj.Value, _l); GdkWindow.DrawLayout(Style.TextGC(StateType.Normal), 560 - (int)_hadj.Value, 40 - (int)_vadj.Value, _l); GdkWindow.DrawLayout(Style.TextGC(StateType.Normal), 40 - (int)_hadj.Value, 560 - (int)_vadj.Value, _l); GdkWindow.DrawLayout(Style.TextGC(StateType.Normal), 560 - (int)_hadj.Value, 560 - (int)_vadj.Value, _l); return ret; } protected override void OnRealized() { _l = new Pango.Layout(PangoContext); _l.Wrap = Pango.WrapMode.Word; _l.FontDescription = Pango.FontDescription.FromString("Tahoma 64"); _l.SetMarkup("WHAT THE\nFUCK IS\nTHIS SHIT\nLOL ♥ ♥"); base.OnRealized(); } protected override void OnSetScrollAdjustments(Adjustment hadj, Adjustment vadj) { _hadj = hadj; _vadj = vadj; if(hadj != null) hadj.ValueChanged += HAdjust; if(vadj != null) vadj.ValueChanged += VAdjust; } protected override void OnSizeAllocated(Gdk.Rectangle alloc) { base.OnSizeAllocated(alloc); if(_hadj != null) { _hadj.SetBounds(0, _p.Width, 1, alloc.Width, alloc.Width); if(_hadj.Value + alloc.Width > _p.Width) { _hadj.Value = _p.Width - alloc.Width; _hadj.ChangeValue(); } } if(_vadj != null) { _vadj.SetBounds(0, _p.Height, 1, alloc.Height, alloc.Height); if(_vadj.Value + alloc.Height > _p.Height) { _vadj.Value = _p.Height - alloc.Height; _vadj.ChangeValue(); } } } protected override void OnDestroyed() { if(_hadj != null) { _hadj.ValueChanged -= HAdjust; _hadj = null; } if(_vadj != null) { _vadj.ValueChanged -= VAdjust; _vadj = null; } } public PictureArea(Picture p) { _p = p; } } public class PictureView : Gtk.ScrolledWindow { public PictureView(Picture p) { Add(new PictureArea(p)); ShowAll(); } } }