Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Image function question

Author
Message
sneaky smith12
18
Years of Service
User Offline
Joined: 30th Apr 2006
Location: Like id tell you, oh wait i just did
Posted: 8th Oct 2009 02:39
Well I am trying to make a rollover button, which I did just fine.

I was wondering if there is a way into make it into a function like:
switchImage(image number)

My current code is



Any help would be great!

If at first you dont succeed, LOWER YOUR STANDARDS.
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 9th Oct 2009 14:08
Is there a reason that you're deleting the image every time?

An image can stay loaded throughout the program and is only "shown" when calling paste image.

Meaning:


Cheers!
Sven B

sneaky smith12
18
Years of Service
User Offline
Joined: 30th Apr 2006
Location: Like id tell you, oh wait i just did
Posted: 9th Oct 2009 22:51
Quote: "Is there a reason that you're deleting the image every time?

An image can stay loaded throughout the program and is only "shown" when calling paste image."


Because I didn't realize the image stayed loaded

Thanks for the advice

Also, is there any more efficient way to do a rollover?

If at first you dont succeed, LOWER YOUR STANDARDS.
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 10th Oct 2009 12:20 Edited at: 10th Oct 2009 12:23
Well, the code I posted is the way we usually do it.
You could say there's one more efficient way, and that's using a function. This way you can easily place multiple rollover images without too much code.



Quote: "Also, is there any more efficient way to do a rollover?"


It's nice to see someone learning a programming language the good way .

Sven B

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 10th Oct 2009 12:53 Edited at: 10th Oct 2009 12:54
Quote: "Also, is there any more efficient way to do a rollover?"


The easiest way is to have one large image for all the normal button looks (the way the screen would look without anything selected). Only show the button changes when the mouse is over the menu selection rather than flipping between two images for each selection all the time.



Attachments

Login to view attachments
sneaky smith12
18
Years of Service
User Offline
Joined: 30th Apr 2006
Location: Like id tell you, oh wait i just did
Posted: 10th Oct 2009 21:13 Edited at: 10th Oct 2009 22:55
Quote: "It's nice to see someone learning a programming language the good way ."


Of course. Appreciate the help; however, for my purposes I think Grueslayer's method would be more applicable.

Quote: "The easiest way is to have one large image for all the normal button looks (the way the screen would look without anything selected). Only show the button changes when the mouse is over the menu selection rather than flipping between two images for each selection all the time."


So then in order to have another menu you would just change the title image I take it?

Would it be more versatile (and perhaps quicker) to place the code in a function?

perhaps:


functionally it does the same process, but it would seem more expandable from the function?

EDIT:

Well, toying around with it I figured out how to add a clicked state; however, now how would I make it so that it doesn't allow you to hold the mouse down and clicks other things at the point clicked (see example)



Media attached.

If at first you dont succeed, LOWER YOUR STANDARDS.

Attachments

Login to view attachments
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 11th Oct 2009 19:59
Quote: "So then in order to have another menu you would just change the title image I take it?"


Yup.

Quote: "Would it be more versatile (and perhaps quicker) to place the code in a function?"


Of course.

Quote: "Well, toying around with it I figured out how to add a clicked state; however, now how would I make it so that it doesn't allow you to hold the mouse down and clicks other things at the point clicked (see example)"


What I do is have a small REPEAT/UNTIL loop to wait for the user to let go of the mouse buttons then another check to see if the mouse is still in the right area to actually register the click.

I added it to your code but it messes up your error checking since there needs to be a SYNC after the clicked button is shown. I also recommend that the image numbers be staggered so there is no need to repeat code (make two FOR/NEXT loops). I also added a MenuSelect() function to put anything you need for each menu option. Right now hitting Menu 1 will stay in the first menu and hitting Menu 3 will go to the next menu.



sneaky smith12
18
Years of Service
User Offline
Joined: 30th Apr 2006
Location: Like id tell you, oh wait i just did
Posted: 12th Oct 2009 01:41 Edited at: 12th Oct 2009 01:43
Quote: "What I do is have a small REPEAT/UNTIL loop to wait for the user to let go of the mouse buttons then another check to see if the mouse is still in the right area to actually register the click."


Great! Didn't think about that.

The functionality was all there for a menu I could need, so instead of this update on the code for functionality it's for readability. I added a freeImage function to allow image numbers be handles instead, which makes them much for meaningful, and therefore better.

Perhaps when we finish this code it would be worthy of using that code base there? I can't really find a thread in these forums this helpful.



If at first you dont succeed, LOWER YOUR STANDARDS.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 12th Oct 2009 02:51
Quote: "The functionality was all there for a menu I could need, so instead of this update on the code for functionality it's for readability. I added a freeImage function to allow image numbers be handles instead, which makes them much for meaningful, and therefore better."


I would do the function a bit different. Any check for the first free image should use the IMAGE EXIST() command. That way if you use specific image numbers you don't remember it'll make sure it won't use an already used image number. The nextfreeimage variable shouldn't be global so it checks starting at image number 1 till it finds the first free image number.



Quote: "Perhaps when we finish this code it would be worthy of using that code base there? I can't really find a thread in these forums this helpful."


Yeah you can put it in the code base if you want... and thanks.

sneaky smith12
18
Years of Service
User Offline
Joined: 30th Apr 2006
Location: Like id tell you, oh wait i just did
Posted: 12th Oct 2009 03:21
Quote: "Any check for the first free image should use the IMAGE EXIST() command."


I didn't have my file handy, but yeah I did it with the Image Exist... I just used a for next loop with an if statement. yours looks better though.

I've never really used repeat...until loops. They look pretty handy thus far. It will take getting use to of course, but I'll look into them.

Before I go ahead and add it... any rather important oversight made here?

If at first you dont succeed, LOWER YOUR STANDARDS.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 12th Oct 2009 18:42
Quote: "I didn't have my file handy, but yeah I did it with the Image Exist... I just used a for next loop with an if statement. yours looks better though."


Thanks

Quote: "I've never really used repeat...until loops. They look pretty handy thus far. It will take getting use to of course, but I'll look into them."


Yeah their real nice when you want the code within the REPEAT/UNTIL loop to run at least once before the condition check.

Quote: "Before I go ahead and add it... any rather important oversight made here?"


I can't think of any other than removing all the error checking code.

sneaky smith12
18
Years of Service
User Offline
Joined: 30th Apr 2006
Location: Like id tell you, oh wait i just did
Posted: 12th Oct 2009 19:40
Quote: "I can't think of any other than removing all the error checking code."


Ok, thanks again.

The following code is what I'll put in the codebase (of course giving you credit as well):


If at first you dont succeed, LOWER YOUR STANDARDS.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 13th Oct 2009 06:34
Np.



This line needs to be removed since the FreeImage() function needs to start at zero. Looks good.

Login to post a reply

Server time is: 2024-11-24 01:55:51
Your offset time is: 2024-11-24 01:55:51