LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-16-2007, 03:51 PM   #1
spoody_goon
Member
 
Registered: Sep 2003
Location: Michigan USA
Distribution: Mandrake, DamnSmallLinux, VectorLinux
Posts: 416

Rep: Reputation: 30
Post Gtk# Image Pixbuf freeze


Using monodevelop v 0.12 gtk-sharp 2.0.
The program is a simple Yahtzee game it freezes when changing the dice images. The big catch to the code below is it works if I use the checkboxes to stop the images from changing for the first roll. After that it will work fine.

Code:
protected System.Timers.Timer  mTimer = new System.Timers.Timer();
		
// load the dice images into an array
DiceArray[0] = Gdk.Pixbuf.LoadFromResource("dice1.png");
DiceArray[1] = Gdk.Pixbuf.LoadFromResource("dice2.png");
DiceArray[2] = Gdk.Pixbuf.LoadFromResource("dice3.png");
DiceArray[3] = Gdk.Pixbuf.LoadFromResource("dice4.png");
DiceArray[4] = Gdk.Pixbuf.LoadFromResource("dice5.png");
DiceArray[5] = Gdk.Pixbuf.LoadFromResource("dice6.png");
when the roll button is pushed it starts the gtk.timer

Code:
this.mTimer.Enabled = true;
this.mTimer.AutoReset = true;
this.mTimer.Interval = 1;
this.mTimer.Elapsed += new System.Timers.ElapsedEventHandler(this.mTimer_Tick);
this.mTimer.Start();
then the image widget is assinged an image from the pixbuf array via a random number

Code:
Random random = new Random();
if((lblHold1.State.ToString() != "Active")&& (mTimer.Interval < 34))
    Dice1.Pixbuf  = DiceArray[random.Next(0, 5)];
							
if((lblHold2.State.ToString() != "Active")&& (mTimer.Interval < 29))
    Dice2.Pixbuf = DiceArray[random.Next(0, 5)];
						
if((lblHold3.State.ToString() != "Active")&& (mTimer.Interval < 32))
    Dice3.Pixbuf = DiceArray[random.Next(0, 5)];
						
if((lblHold4.State.ToString() != "Active")&& (mTimer.Interval < 25))
   Dice4.Pixbuf = DiceArray[random.Next(0, 5)];
						
if((lblHold5.State.ToString() != "Active")&& (mTimer.Interval < 22))
   Dice5.Pixbuf = DiceArray[random.Next(0, 5)];
						
mTimer.Interval = mTimer.Interval + 1;
if(mTimer.Interval > 35)
{
   // destroy the timer at the end of the roll cycle
   mTimer.Dispose();
}
 
  


Reply

Tags
gtk, mono, monodevelop


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting an image to resize to fit window in a GTK app drosen Linux - Newbie 1 02-01-2007 01:02 PM
How to zoom in or out a image in GTK programming knsr433 Programming 0 09-07-2006 05:52 AM
Perl - Error installing Gtk::Gdk::Pixbuf for dvd::rip revof11 Linux - Software 3 05-11-2006 03:42 PM
random image with gtk chirita Programming 1 08-29-2003 08:32 PM
Gtk-Perl: Problems getting pixbuf module to install wackman Linux From Scratch 1 06-08-2003 11:44 AM


All times are GMT -5. The time now is 07:05 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration