PAID : Load images from folder and let user scroll through them

Posted By: jaknine

PAID : Load images from folder and let user scroll through them - 04/30/09 23:18

I need a few functions made in C-Script (no Lite C) for A7 that will do the following:
  • A function that looks inside a folder and makes a list of all images in it based on a wildcard, and puts all entries into an array.
  • Change the BMAP image on a panel based on this array of images.
On my main menu screen I have a panel that has two buttons underneath it, one left arrow and one right arrow.

I want a function for the left arrow that will cycle backwards through the list of images in the folder and show each image in turn on the panel. I also want a function for the right arrow that cycles forwards through the list and shows the image on the panel. There should also be a string variable that's updated with the current image shown, so that I can access that variable in the rest of my program.

I already have the buttons set up to call on functions and the main image panel is already present on my menu screen, I just need the functions written as noted.

If you can do it pretty quickly please send me a private message with your price and time frame. Again, this project is using C-Script so I need it done in that and not Lite-C.

Thanks!
Posted By: Xarthor

Re: PAID : Load images from folder and let user scroll through them - 05/01/09 08:20

Hopefully no one has taken on this job.
I was interested in it and wrote a script in a few minutes which does the job.
However you did not specify if the folder where the images are is static or not and if the image format (wildcard) is static or not.
So here is a code which uses a specific folder and a specific image format:
Code:
// ============================================================================
// VARIABLES

var nro_images = 0;
var cur_image = 0;


// ============================================================================
// STRINGS & TEXT

string current_image = "#100";

text image_file
{
	strings = 100;
}


// ============================================================================
// PANEL

panel image_pan
{
	pos_x = 100;
	pos_y = 100;
}


// ============================================================================
// FUNCTIONS

// sets the current_image string and updates the panel
function update_image()
{
	str_cpy(current_image,"images\\");
	str_cat(current_image,image_file.string[cur_image]);
 	
	image_pan.bmap = bmap_create(current_image);
	image_pan.size_x = bmap_width(image_pan.bmap);
	image_pan.size_y = bmap_height(image_pan.bmap);
}

// shows the next image
function cycle_imagesUp()
{
	cur_image = cycle(cur_image+1,0,nro_images);
	
	update_image();
}

// shows the previous image
function cycle_imagesDown()
{
	cur_image = cycle(cur_image-1,0,nro_images);
	
	update_image();
}


// loads the images with a specific format from a specific folder
function load_images()
{
	nro_images = txt_for_dir(image_file,"images\\*.jpg");
	
	update_image();
}


// ============================================================================
// END OF FILE
// ============================================================================


Posted By: jaknine

Re: PAID : Load images from folder and let user scroll through them - 05/02/09 00:16

Awesome, thanks very much Xarthor. That looks like exactly what I needed. I really appreciate it!
Posted By: nfs42

Re: PAID : Load images from folder and let user scroll through them - 05/02/09 15:49

nice contribution, added to 3DGS codebase
Posted By: Xarthor

Re: PAID : Load images from folder and let user scroll through them - 05/02/09 16:57

Thanks you two, hope everything works ok. Otherwise PM me.

@nfs42:
Cool, thanks for adding it. But: The version is A7 C-Script, not lite-C.
As requested is the snippet written in C-Script, but it can easily be converted to lite-C
Posted By: nfs42

Re: PAID : Load images from folder and let user scroll through them - 05/02/09 17:44

changed to A7 c-script
© 2024 lite-C Forums