Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Single prim picture viewer with scroll

LaserFur Leonov
Registered User
Join date: 16 Jan 2006
Posts: 18
11-08-2006 01:35
This viewer is different in that you can hold the mouse button down and scroll right and left threw the images.

To set up, just delete the default textures and drop in the ones you want to use.

CODE

//Picture viewer by grumble Loudon and LaserFur Leonov
//Released into the public domain, no rights reserved

//Face 0 is on top (the end of the extrusion)
//Face 1 is south
//Face 2-3 is the other sides
//face 5 is the bottom
integer m_FaceNumber = 1;


//******************************************************************************************
integer g_ImageNumber = 0; // current line number
integer g_ImageTotal; // number of images

string g_ImageName;

integer g_ImageNumberLast = -1; // curently displayed image for changes

integer m_TouchStartImageNumber;

//******************************************************************************************
UpdateDisplay(){

if (g_ImageNumber >= g_ImageTotal) g_ImageNumber = g_ImageTotal - 1;
if (g_ImageNumber < 0 ) g_ImageNumber = 0;

if (g_ImageNumberLast != g_ImageNumber){
g_ImageNumberLast = g_ImageNumber;
g_ImageName = llGetInventoryName(INVENTORY_TEXTURE, g_ImageNumber);
llSetTexture(g_ImageName, m_FaceNumber); //use name since we may not have perms to get key

string txt;
txt = "Now Viewing " + (string)(g_ImageNumber + 1) + " of " + (string)g_ImageTotal + "\n";
txt += g_ImageName + "\n";
txt += "Click for next image\nor click and drag to change image";

llSetText(txt,<1,1,1>,1);
};
} //update display

//********************************************************************************************
default
{
state_entry()
{
g_ImageTotal = llGetInventoryNumber(INVENTORY_TEXTURE);

llSetStatus(STATUS_BLOCK_GRAB, TRUE);

UpdateDisplay();
}
//********************************************************************************************
changed(integer change) { // something changed
if (change & CHANGED_INVENTORY) {
llResetScript();
};
} //Changed
//********************************************************************************************

touch_start(integer total_number)
{
++g_ImageNumber;
if (g_ImageNumber >= g_ImageTotal) g_ImageNumber = 0;

m_TouchStartImageNumber = g_ImageNumber;
UpdateDisplay();
}
touch(integer total_number){ //use touch in order to get grab point
vector GrabDir = llDetectedGrab(0);

rotation primRot = llGetRot();
//Convert the drag to be in line with the prims rotation
GrabDir = GrabDir * (<0,0,0,1> / primRot);

g_ImageNumber = m_TouchStartImageNumber + (integer)(GrabDir.x * 10.0);
UpdateDisplay();
}
//********************************************************************************************
} //default
//********************************************************************************************
Junie Ginsburg
Steampunk Merchant
Join date: 5 Aug 2006
Posts: 35
touch_start
11-08-2006 12:40
This is a pretty cool script. I have one question though.

If you're capturing touch_start() to view the next image and touch() to scroll forward or back, is the next image in the list being displayed even if you then hold down the mouse button and scroll left/back?

I would assume that touch_start() would fire even when you continue to hold the mouse button down, but there is a note on "prim drift" in the wiki that makes me wonder if that's correct. I'm curious how it behaves in your implementation.
Llauren Mandelbrot
Twenty-Four Weeks Old.
Join date: 26 Apr 2006
Posts: 665
Getting Touchy?
11-08-2006 17:53
From: Junie Ginsburg
I would assume that touch_start() would fire even when you continue to hold the mouse button down, but there is a note on "prim drift" in the wiki that makes me wonder if that's correct. I'm curious how it behaves in your implementation.
I would assume that touch_start() would fire once when the prim is first clicked, and that touch() would fire repeatedly until the mouse-button is released.

Why? That`s what they are documented to do. [Also, that`s what experience shows me, too.:)]
_____________________
  1. ninjafoo Ng Says:
    November 4th, 2006 at 7:27 am
    We all love secondlife so much and were afraid that the magic will end, nothing this good can ever last…. can it?

Junie Ginsburg
Steampunk Merchant
Join date: 5 Aug 2006
Posts: 35
touch_start
11-09-2006 13:12
My assumption is the same as yours, Llauren. I'm only asking because that means that if you want to scroll backwards through the images, that you will first be shown the *next* image in the sequence first because of the touch_start event. So I wanted to make sure my assumption was correct. :-)
Llauren Mandelbrot
Twenty-Four Weeks Old.
Join date: 26 Apr 2006
Posts: 665
Misunderstandings Cleard Up...
11-09-2006 13:30
My assumption is the same as yours, Llauren.I`m sorry. I misunderstood.:o The portion I quoted previously made me think that you thought that the touch_start event would continue to fire while the mousebutton was held down -- which is what the unqualified touch event is for. I now know that that is not what you thought.:cool:I'm only asking because that means that if you want to scroll backwards through the images, that you will first be shown the *next* image in the sequence first because of the touch_start event. So I wanted to make sure my assumption was correct. :-)Ah, in that case, I would tend to agree with your interpretation.
_____________________
  1. ninjafoo Ng Says:
    November 4th, 2006 at 7:27 am
    We all love secondlife so much and were afraid that the magic will end, nothing this good can ever last…. can it?

grumble Loudon
A Little bit a lion
Join date: 30 Nov 2005
Posts: 612
11-09-2006 20:52
Is there an issue with the drag scrolling if you rotate the object?

Anyone know some rotation math?

CODE

touch(integer total_number){ //use touch in order to get grab point
vector GrabDir = llDetectedGrab(0);//works even if block grab is on
//To Do! rotate it based on the prim rotation
//
g_ImageNumber = m_TouchStartImageNumber + (integer)(GrabDir.x * 10.0);
LaserFur Leonov
Registered User
Join date: 16 Jan 2006
Posts: 18
11-11-2006 02:07
Grumble... You need to learn math. ;)

I updated the script so that it now rotates the grab vector using the inverse of the rotation