[Gtk-sharp-list] Gtk.Image

mono baumm monobaum at gmx.ch
Tue May 31 09:40:59 EDT 2011


Hello

I'm trying to create a screensaver kind of thing which shows in a given area a list of multimedia Files like Movies, Flash, Images etc.

I've done this sucessfully with WinFoms but had to change to something Linux Native because of performance issues.

Ok. The Problem i'm facing is the same for Flash and for Images and therefore i will only talk about the images.

Whats Happening:
I start the MainWindow, which holds two ImagePlayers ( gtk.Windows with a method to set the picture).
The Image is set to Player1 and the Player is shown with ShowAll() and i'm starting a timer which changes the Player every few secounds.
When the Timer elapses i set the Image to Player2, ShowwAll() Player two and Hide Player1 by moving it to nirvane(-1000, -1000).
The Fist Image shown in such a player shows fine. The images after wont get redrawn and the window remains Grey. 

Since i don't know anything about Gtk i assume i just handle it wrong and so i hope you can help me to a better understanding.
I can't explain my self too well so i hope my Code speaks for itsself.

public partial class MainWindow : Gtk.Window
{
	System.Timers.Timer changeMediaTimer;
	
	IPlayer f1;
	IPlayer f2;
	
	MediaPlayData mpd1;
	MediaPlayData mpd2;
	
	bool IsLoading = false;
	
	public MainWindow () : base(Gtk.WindowType.Toplevel)
	{
		Build ();
		
		this.Move( -1000, -1000);
		
		changeMediaTimer = new System.Timers.Timer();
		changeMediaTimer.Interval = 3000;
		changeMediaTimer.Elapsed += new System.Timers.ElapsedEventHandler( changeMediaTimer_Elapsed );
						
		f1 = new ImagePlayer( new Rectangle (800, 130, 810, 475), 1);
		f2 = new ImagePlayer( new Rectangle (800, 130, 810, 475), 2);
		
		mpd1 = new MediaPlayData();
		mpd1.url = "18617.jpg";
		
		mpd2 = new MediaPlayData();
		mpd2.url = "18618.jpg";
		
		f1.SetMedia( mpd1 );
		f1.ShowPlayer();
		
		changeMediaTimer.Start();
	}
	
	private void changeMediaTimer_Elapsed (object sender, EventArgs e)
	{
		if ( IsLoading ) return;
		IsLoading = true;
		
		if ( !f1.IsBusy )
		{
			f1.SetMedia( mpd1 );
			f1.ShowPlayer();
			f2.HidePlayer();
		}
		else
		{
			f2.SetMedia( mpd2 );
			f2.ShowPlayer();		
			f1.HidePlayer();	
		}
		
		IsLoading = false;
	}
		
	protected void OnDeleteEvent (object sender, DeleteEventArgs a)
	{
		Application.Quit ();
		a.RetVal = true;
	}
}

#
#
# Above is the Logic. And know comes the Player
#
#

public partial class ImagePlayer : PlayerBase, IPlayer
{
	Gtk.Image img;
		
	private ImagePlayer () : base()
	{
		this.Build ();
	}
		
	public ImagePlayer ( System.Drawing.Rectangle rect, int i ) : base( rect )
	{
		playerType = MediaPlayData.eType.Image;
			
		img = new Gtk.Image();			
		this.Add( img );			
	}
		      
	 public void SetMedia( MediaPlayData mpd )
       	 {
			string s = String.Format("/opt/aaa/Data/Medias/{0}", mpd.url);			
			
			img.Pixbuf = new Gdk.Pixbuf( s );			
       	 }
		
	public void ShowPlayer( )
       	 {	
			this.Move(bounds.X, bounds.Y);
			this.Visible = true;
			
			ShowAll();
       	 }
       
 	public void HidePlayer( )
       	 {			
			this.Move( nirvana.X, nirvana.X );	
			this.Visible = false;			
       	 } 
       	 public void Stop( )
       	 {
			
        	}
}
-- 
NEU: FreePhone - kostenlos mobil telefonieren!			
Jetzt informieren: http://www.gmx.net/de/go/freephone


More information about the Gtk-sharp-list mailing list