Author Topic: Scrolling  (Read 19487 times)

xabaras

  • Guest
Re: Scrolling
« Reply #15 on: August 09, 2012, 12:53:29 am »
hi jj,
thank you, containers are very very useful... i've tried on the iphone only the first version of the scroller, not the last one... i'll test it soon and i'm sure it will perfectly work.
Meanwhile i'm trying to put dynamic contents into a scroll-list... it's a "simple" loop of inner elements (not top and bottom) and dynamic calculation of sizes and scroll lengths... it should work in some way...


Otherwise, the current buttons won't allow the scroller's touch component to be activated while the button is being pressed, and buttons take up a lot of space, so this is obviously a big issue.

Yes this could be an issue... but perhaps a solution could be something like this



where you have a simple image on the main part of the button, where you can easily touch to scroll, and the real button is only on the right part... you touch it and something happens...

What about adding the fading scrollbar on the right of the scrollable content?

Anyway, thank you and really good job!

AnswerSoft

  • Guest
Re: Scrolling
« Reply #16 on: August 09, 2012, 10:24:02 am »
jj,

I want to second the "thank you" here. I've been plowing through the original code trying to get my text to scroll. For some reason all the buttons would scroll while leaving the text stationary. I think this new code should work fine, as I can just add text into the container. Thanks again. I actually wound up postponing the demo last Tuesday.

Thanks again,
Mike

xabaras

  • Guest
Re: Scrolling
« Reply #17 on: August 10, 2012, 02:19:02 pm »
Another question... i have a situation like this one...



In one of the pages of my app i have a main background-image (with a transparent area inside), some buttons on it, an input field and so on... unfortunately everything not inside a container...
Now, i'm trying to put your scroller "below" the page, in order to see it only in the transparent window.... it works, obviously... but only if i put my main background in a container too... Is there a way to avoid this? or can containers stay below only other containers?

jjsanchezramirez

  • Guest
Re: Scrolling
« Reply #18 on: August 10, 2012, 03:48:47 pm »
Hey, I didn't completely understood what you meant, but I think this can be solved by putting different things on different containers. Having containers on top of other containers doesn't really matter because touch components are independent of z-order.

In this example, I added another container named GUI elements. The GUI container is above the container with the scroller. Bellow the scroller container is the background image.

Code: [Select]
/* Copyright 2012 Juan José Sánchez Ramírez

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

   Author Juan José Sánchez Ramírez
   Version 1.0
*/

#include "DragonFireSDK.h"
#include "SimpleScroller.h"

SimpleScroller simpleScroller;
SimpleScroller sliderSimpleScroller;

int nContainer;
int nSliderContainer;
int nGUIContainer;

int nFont;

// This function will be called when a button is pressed
int OnButton(int id)
{
return id;
}

// This function marks the beginning of program execution
void AppMain()
{
nContainer = ContainerAdd(0, 0, 0);
nSliderContainer = ContainerAdd(nContainer, 50, 165);
nGUIContainer = ContainerAdd(0, 0, 0);

nFont = FontAdd("Arial", "Regular", 20, 0x000000);

ViewAdd(0, "Images/Background.png", 0, 0);

// Initiate scroller 320x720, ID 0, horizontal scroll false
simpleScroller.Init(nContainer, 0, 0, 320, 720, 0);
simpleScroller.SetHorizontalScroll(false);

// Populate container
ButtonAdd(nContainer, "Images/RoundedButton", 8, 80, OnButton, 0);
TextAdd(nContainer, 24, 91, "Button", nFont);

ButtonAdd(nContainer, "Images/RoundedButton", 8, 595, OnButton, 1);
TextAdd(nContainer, 24, 606, "Another button", nFont);

ViewAdd(nContainer, "Images/Slider.png", 50, 165);

// Initiate scroller 25x26, ID 1, vertical scroll false
sliderSimpleScroller.Init(nSliderContainer, 0, 0, 25, 26, 1);
sliderSimpleScroller.SetVerticalScroll(false);
sliderSimpleScroller.SetMinX(50);
sliderSimpleScroller.SetMaxX(246);

// Populate slider container
ViewAdd(nSliderContainer, "Images/Handle.png", 0, 0);

// GUI elements
ViewAdd(nGUIContainer, "Images/TopBar.png", 0, 0);
ViewAdd(nGUIContainer, "Images/Navigator.png", 0, 20);
ViewAdd(nGUIContainer, "Images/Toolbar.png", 0, 436);
}

// This function is called whenever the app terminates
void AppExit()
{

}

// This function is called 30 times per second
void OnTimer()
{
if (nTouchId == 0)
simpleScroller.Update();

if (nTouchId == 1)
sliderSimpleScroller.Update();
}

By the way, I've gone over the menu in my head and wrote some ideas.

First of all, when you touch a menu item (a button), if your coordinates remain the same, it's a click. Otherwise, you're scrolling. If you did click the button, and every button will share the same OnButton function, this should call a function, OnMenu, while passing the menu item ID number. A simple switch statement in the OnMenu function will make it easy to have different commands for each item in the menu.

Also, I think the menu should be a class composed of a scroller and buttons. It will also need two string vectors, one for labels, and one for icons. Finally, it will need a variable to hold the current number of items.

If I make a scrollbar, it's going to be a very simple, rectangular scrollbar.

I imagine using the menu like this.

Code: [Select]
int nContainer;
nContainer = ContainerAdd(0, 0, 0);

Menu menu;
menu.Init(nContainer, OnMenu);
menu.AddMenuItem("Item 0");
menu.AddMenuIcon(0, "Images/Icon.png");

I've also written a pseudoscript to add elasticity (recoil) and friction (momentum) to the scroller. Unlike the initial framework, these won't be mutually exclusive, since they work very differently.

In my head, it works. The problem is I won't be having much free time this week.

jjsanchezramirez

  • Guest
Re: Scrolling
« Reply #19 on: August 11, 2012, 08:14:38 pm »
It was extenuating, but I finally managed to add recoil to the scroller. This means the containers can now behave like springs. Basically, when you're scrolling out of boundaries you still move a little bit, and when you let go the container bounces back into position.

You'll probably notice I added various functions and variables, and many nested if statements. These are self-explanatory in most cases. I also added a function to set all four boundaries or ranges at once. This function is useful in the case of small components like sliders.

Code: [Select]
/* Copyright 2012 Juan José Sánchez Ramírez

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

   Author Juan José Sánchez Ramírez
   Version 1.0
*/

#ifndef DYNAMIC_SCROLLER
#define DYNAMIC_SCROLLER

int nOldX;
int nOldY;
int nNewX;
int nNewY;

int nTouchId;
int nTouchEvent;

// This function will be called when a scroller is activated
int OnTouch(int id, int event, int x, int y)
{
// Get the ID of the container
nTouchId = id;

// Get the event of the container
nTouchEvent = event;

// Record initial coordinates when pressed down
if (event == 1)
{
nOldX = x;
nOldY = y;
nNewX = x;
nNewY = y;
}

// Record new coordinates when moving
if (event == 2)
{
nNewX = x;
nNewY = y;
}

// Erase coordinates when released
if (event == 3)
{
nOldX = 0;
nOldY = 0;
nNewX = 0;
nNewY = 0;
}

return id;
}

// This function approximates a container to it's target position.
void SlideContainer(int container, int targetX, int targetY, int speed=5)
{
/* To approximate the container, we're going to do the following:

   1. We get the container's x and y positions on the screen.
   2. If the value is less than the target value, we substract the
      value from the target value. If the value is more than the
  target value, we substract the target value from the value.
   3. We divide the difference by the speed.
   4. If the result equals 0, we make it equal to 1.
   5. If the value is less than the target value, we add the result
      to the value. If the value is more than the target value, we
  substract the result from the value.
   6. Finally, we set the container's position to our x and y values.
*/

int x = ContainerGetx(container);
int y = ContainerGety(container);

if (x < targetX)
{
int n = (targetX - x) / speed;
if (n == 0) n = 1;
x += n;
}
else if (x > targetX)
{
int n = (x - targetX) / speed;
if (n == 0) n = 1;
x -= n;
}

if (y < targetY)
{
int n = (targetY - y) / speed;
if (n == 0) n = 1;
y += n;
}
else if (y > targetY)
{
int n = (y - targetY) / speed;
if (n == 0) n = 1;
y -= n;
}

ContainerSetxy(container, x, y);
}

// This class creates a simple scroller for containers
class DynamicScroller
{
/* A scroller lets a container slide upon a portion of the screen.
   It's designed to move containers that are too big for the screen,
   both vertically and horizontally, but it can be modified to move
   smaller objects too, such as sliders. This can be achieved by
   modifying minimum and maximum ranges, using the SetMinX, SetMinY,
   SetMaxX, and SetMaxY functions.

   The scroller uses the following components:

   1. A container which contains all of the elements in the scroller.
   2. A touch component which must be at least the size of the
      entire container, which records the drag and drop actions.
   3. An ID number that allows to differentiate among scrollers,
      since all scrollers use the same OnTouch function.
*/

private:

int m_nContainer;
int m_nTouch;

int m_nX;
int m_nY;

int m_nMinX;
int m_nMinY;

int m_nMaxX;
int m_nMaxY;

bool m_bHorizontalScroll;
bool m_bVerticalScroll;

bool m_bRecoil;
bool m_bFriction;

public:

// Constructor
DynamicScroller()
{

}

// This function initiates the scroller and all of its components
void Init(int& container, int x, int y, int touchWidth, int touchHeight, int id)
{
m_nContainer = container;
m_nTouch = TouchAdd(container, x, y, touchWidth, touchHeight, OnTouch, id);

m_nX = ContainerGetx(container);
m_nY = ContainerGety(container);

m_nMinX = x-touchWidth+320;
m_nMinY = y-touchHeight+480;

m_nMaxX = 0;
m_nMaxY = 0;

m_bHorizontalScroll = true;
m_bVerticalScroll = true;

m_bRecoil = true;
m_bFriction = true;
}

// This function updates the scroller
void Update()
{
/* To update the scroller we're going to:

   1. Check if the x coordinate has changed. If it has, and
      if horizontal scrolling is allowed, move the container.
  If the container is out of bounds, move the container
  within bounds.

   2. Repeat for the y coordinate.

   3. If nothing has changed, then make the scroller x and y
      coordinates equal to the container's coordinates. This
  is necessary to start scrolling again.
*/

if (nOldX != nNewX && m_bHorizontalScroll)
{
ContainerSetx(m_nContainer, m_nX+nNewX-nOldX);

if (ContainerGetx(m_nContainer) < m_nMinX)
{
if (m_bRecoil)// && m_nMinX-nNewX > 0)
ContainerSetx(m_nContainer, m_nMinX-(m_nMinX-(m_nX+nNewX-nOldX))/5);
else
ContainerSetx(m_nContainer, m_nMinX);
}

if (ContainerGetx(m_nContainer) > m_nMaxX)
{
if (m_bRecoil)// && m_nMaxX-nNewX < 0)
ContainerSetx(m_nContainer, m_nMaxX-(m_nMaxX-(m_nX+nNewX-nOldX))/5);
else
ContainerSetx(m_nContainer, m_nMaxX);
}
}
else if (nOldY != nNewY && m_bVerticalScroll)
{
ContainerSety(m_nContainer, m_nY+nNewY-nOldY);

if (ContainerGety(m_nContainer) < m_nMinY)
{
if (m_bRecoil)
ContainerSety(m_nContainer, m_nMinY-(m_nMinY-(m_nY+nNewY-nOldY))/5);
else
ContainerSety(m_nContainer, m_nMinY);
}

if (ContainerGety(m_nContainer) > m_nMaxY)
{
if (m_bRecoil)
ContainerSety(m_nContainer, m_nMaxY-(m_nMaxY-(m_nY+nNewY-nOldY))/5);
else
ContainerSety(m_nContainer, m_nMaxY);
}
}
else
{
m_nX = ContainerGetx(m_nContainer);
m_nY = ContainerGety(m_nContainer);

if (m_nX < m_nMinX)
SlideContainer(m_nContainer, m_nMinX, m_nY);
if (m_nY < m_nMinY)
SlideContainer(m_nContainer, m_nX, m_nMinY);
if (m_nX > m_nMaxX)
SlideContainer(m_nContainer, m_nMaxX, m_nY);
if (m_nY > m_nMaxY)
SlideContainer(m_nContainer, m_nX, m_nMaxY);
}
}

// This function sets the minimum x range
void SetMinX(int x)
{
m_nMinX = x;
}

// This function sets the minimum y range
void SetMinY(int y)
{
m_nMinY = y;
}

// This function sets the maximum x range
void SetMaxX(int x)
{
m_nMaxX = x;
}

// This function sets the maximum y range
void SetMaxY(int y)
{
m_nMaxY = y;
}

// This function sets the minimum and maximum x and y ranges
void SetBoundaries(int minX, int minY, int maxX, int maxY)
{
SetMinX(minX);
SetMinY(minY);
SetMaxX(maxX);
SetMaxY(maxY);
}

// This function sets the horizontal scroll
void SetHorizontalScroll(bool flag)
{
m_bHorizontalScroll = flag;
}

// This function sets the vertical scroll
void SetVerticalScroll(bool flag)
{
m_bVerticalScroll = flag;
}
};

#endif

Now, there is a small change in how you use this scroller. Basically, when the scroller is moving, you don't want the other scrollers to be moving as well. However, when the scroller stops moving, you want all the other scrollers to move back into position at the same time. As of this moment, I can't think of a better way to do this.

Code: [Select]
if (nTouchEvent == 2)
{
if (nTouchId == 0)
dynamicScroller.Update();
else if (nTouchId == 1)
sliderDynamicScroller.Update();
}
else
{
dynamicScroller.Update();
sliderDynamicScroller.Update();
}

Seriously, if someone has a solution to this, I'd be glad to listen.

xabaras

  • Guest
Re: Scrolling
« Reply #20 on: August 13, 2012, 04:56:23 am »
Recoil works very good on the device...  ;)

stuckerj

  • Guest
Re: Scrolling
« Reply #21 on: August 15, 2012, 01:11:13 am »
Hi jj,

I found a bug in your DynamicScroller code.  When I put two containers side-by-size on the same screen, and give them both a DynamicScroller, the SlideContainer logic in the Update cycle immediately moves the right one on top of the left one.  Will try to track down and fix that...  I suspect it's related to the hard-coded screen size values used for m_nMinX etc.

The SimpleScroller logic works just fine with two containers side-by-side.

Thanks,

Jeff

jjsanchezramirez

  • Guest
Re: Scrolling
« Reply #22 on: August 15, 2012, 05:11:33 pm »
@stuckerj

I definitely think it's related to the screen values. It's not so much a bug. The scroller is, after all, meant to be used mainly for whole screens. That's why you can change the boundaries of the scroller with the SetBoundaries function. Try changing those, and see if you can fix it. Otherwise, hand me your code in a .zip file and I'll see if I can fix it myself.

I'll probably make a newer version of the code somewhere in the near future, which has a better way to set boundaries, and which enables screen rotation.

jjsanchezramirez

  • Guest
Re: Scrolling
« Reply #23 on: August 15, 2012, 07:27:49 pm »
@stuckerj

I didn't make any changes to the scroller code. I simply modified the values in the main app, and got two scrollers working side by side. To be perfect honest, the code didn't work at first. I modified the values of the touch width, and the x boundaries, and got it working.

This was a very interesting request, and something I hadn't even thought about.



Code: [Select]
/* Copyright 2012 Juan José Sánchez Ramírez

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

   Author Juan José Sánchez Ramírez
   Version 1.0
*/

#ifndef DYNAMIC_SCROLLER
#define DYNAMIC_SCROLLER

int nOldX;
int nOldY;
int nNewX;
int nNewY;

int nTouchId;
int nTouchEvent;

// This function will be called when a scroller is activated
int OnTouch(int id, int event, int x, int y)
{
// Get the ID of the container
nTouchId = id;

// Get the event of the container
nTouchEvent = event;

// Record initial coordinates when pressed down
if (event == 1)
{
nOldX = x;
nOldY = y;
nNewX = x;
nNewY = y;
}

// Record new coordinates when moving
if (event == 2)
{
nNewX = x;
nNewY = y;
}

// Erase coordinates when released
if (event == 3)
{
nOldX = 0;
nOldY = 0;
nNewX = 0;
nNewY = 0;
}

return id;
}

// This function approximates a container to it's target position.
void SlideContainer(int container, int targetX, int targetY, int speed)
{
/* To approximate the container, we're going to do the following:

   1. We get the container's x and y positions on the screen.
   2. If the value is less than the target value, we substract the
      value from the target value. If the value is more than the
  target value, we substract the target value from the value.
   3. We divide the difference by the speed.
   4. If the result equals 0, we make it equal to 1.
   5. If the value is less than the target value, we add the result
      to the value. If the value is more than the target value, we
  substract the result from the value.
   6. Finally, we set the container's position to our x and y values.
*/

int x = ContainerGetx(container);
int y = ContainerGety(container);

if (x < targetX)
{
int n = (targetX - x) / speed;
if (n == 0) n = 1;
x += n;
}
else if (x > targetX)
{
int n = (x - targetX) / speed;
if (n == 0) n = 1;
x -= n;
}

if (y < targetY)
{
int n = (targetY - y) / speed;
if (n == 0) n = 1;
y += n;
}
else if (y > targetY)
{
int n = (y - targetY) / speed;
if (n == 0) n = 1;
y -= n;
}

ContainerSetxy(container, x, y);
}

// This class creates a simple scroller for containers
class DynamicScroller
{
/* A scroller lets a container slide upon a portion of the screen.
   It's designed to move containers that are too big for the screen,
   both vertically and horizontally, but it can be modified to move
   smaller objects too, such as sliders. This can be achieved by
   modifying minimum and maximum ranges, using the SetMinX, SetMinY,
   SetMaxX, and SetMaxY functions, or alternatively, using the
   SetBoundaries function, which modifies all of these values at once.

   The scroller uses the following components:

   1. A container which contains all of the elements in the scroller.
   2. A touch component which must be at least the size of the
      entire container, which records the drag and drop actions.
   3. An ID number that allows to differentiate among scrollers,
      since all scrollers use the same OnTouch function.
   
   The recoil component uses the following variables:

   1. Elasticity, defined here as the property of an object to return
      to its original state after a stress. In this particular context,
  elasticity can be thought of as how fast the container returns to
  its position.
 
  Note: The lower the value, the higher the elasticity!

   2. Compliance, defined here as the inverse of elasticity. In this
      particular context, compliance can be thought of as the resistance
  of a container to move out of position.

  Note: The higher the value, the higher the compliance!
*/

private:

int m_nContainer;
int m_nTouch;

int m_nX;
int m_nY;

int m_nMinX;
int m_nMinY;

int m_nMaxX;
int m_nMaxY;

int m_nCompliance;
int m_nElasticity;

bool m_bHorizontalScroll;
bool m_bVerticalScroll;

bool m_bRecoil;

public:

// Constructor
DynamicScroller()
{

}

// This function initiates the scroller and all of its components
void Init(int& container, int x, int y, int touchWidth, int touchHeight, int id)
{
m_nContainer = container;
m_nTouch = TouchAdd(container, x, y, touchWidth, touchHeight, OnTouch, id);

m_nX = ContainerGetx(container);
m_nY = ContainerGety(container);

m_nMinX = x-touchWidth+320;
m_nMinY = y-touchHeight+480;

m_nMaxX = 0;
m_nMaxY = 0;

m_nCompliance = 10;
m_nElasticity = 2;

m_bHorizontalScroll = true;
m_bVerticalScroll = true;

m_bRecoil = true;
}

// This function updates the scroller
void Update()
{
/* To update the scroller we're going to:

   1. Check if the x coordinate has changed. If it has, and
      if horizontal scrolling is allowed, move the container.
  If the container is out of bounds, and recoil is allowed,
  move the container using compliance. If the container is
  out of bounds, and recoil is not allowed, move the
  container within bounds.

   2. Repeat for the y coordinate.

   3. If nothing has changed, then make the scroller x and y
      coordinates equal to the container's coordinates. This
  is necessary to start scrolling again. If the container
  is out of bounds, slide the container within bounds using
  elasticty.
*/

if (nOldX != nNewX && m_bHorizontalScroll)
{
ContainerSetx(m_nContainer, m_nX+nNewX-nOldX);

if (ContainerGetx(m_nContainer) < m_nMinX)
{
if (m_bRecoil)
ContainerSetx(m_nContainer, m_nMinX-(m_nMinX-(m_nX+nNewX-nOldX))/m_nCompliance);
else
ContainerSetx(m_nContainer, m_nMinX);
}

if (ContainerGetx(m_nContainer) > m_nMaxX)
{
if (m_bRecoil)
ContainerSetx(m_nContainer, m_nMaxX-(m_nMaxX-(m_nX+nNewX-nOldX))/m_nCompliance);
else
ContainerSetx(m_nContainer, m_nMaxX);
}
}
else if (nOldY != nNewY && m_bVerticalScroll)
{
ContainerSety(m_nContainer, m_nY+nNewY-nOldY);

if (ContainerGety(m_nContainer) < m_nMinY)
{
if (m_bRecoil)
ContainerSety(m_nContainer, m_nMinY-(m_nMinY-(m_nY+nNewY-nOldY))/m_nCompliance);
else
ContainerSety(m_nContainer, m_nMinY);
}

if (ContainerGety(m_nContainer) > m_nMaxY)
{
if (m_bRecoil)
ContainerSety(m_nContainer, m_nMaxY-(m_nMaxY-(m_nY+nNewY-nOldY))/m_nCompliance);
else
ContainerSety(m_nContainer, m_nMaxY);
}
}
else
{
m_nX = ContainerGetx(m_nContainer);
m_nY = ContainerGety(m_nContainer);

if (m_nX < m_nMinX)
SlideContainer(m_nContainer, m_nMinX, m_nY, m_nElasticity);
if (m_nY < m_nMinY)
SlideContainer(m_nContainer, m_nX, m_nMinY, m_nElasticity);
if (m_nX > m_nMaxX)
SlideContainer(m_nContainer, m_nMaxX, m_nY, m_nElasticity);
if (m_nY > m_nMaxY)
SlideContainer(m_nContainer, m_nX, m_nMaxY, m_nElasticity);
}
}

// This function sets the minimum x range
void SetMinX(int x)
{
m_nMinX = x;
}

// This function sets the minimum y range
void SetMinY(int y)
{
m_nMinY = y;
}

// This function sets the maximum x range
void SetMaxX(int x)
{
m_nMaxX = x;
}

// This function sets the maximum y range
void SetMaxY(int y)
{
m_nMaxY = y;
}

// This function sets the minimum and maximum x and y ranges
void SetBoundaries(int minX, int minY, int maxX, int maxY)
{
SetMinX(minX);
SetMinY(minY);
SetMaxX(maxX);
SetMaxY(maxY);
}

// This function sets the horizontal scroll
void SetHorizontalScroll(bool flag)
{
m_bHorizontalScroll = flag;
}

// This function sets the vertical scroll
void SetVerticalScroll(bool flag)
{
m_bVerticalScroll = flag;
}

// This function sets the recoil
void SetRecoil(bool flag)
{
m_bRecoil = flag;
}
};

#endif

Code: [Select]
/* Copyright 2012 Juan José Sánchez Ramírez

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

   Author Juan José Sánchez Ramírez
   Version 1.0
*/

#include "DragonFireSDK.h"
#include "DynamicScroller.h"

DynamicScroller leftDynamicScroller;
DynamicScroller rightDynamicScroller;

int nLeftContainer;
int nRightContainer;

// This function marks the beginning of program execution
void AppMain()
{
nLeftContainer = ContainerAdd(0, 0, 0);
nRightContainer = ContainerAdd(0, 160, 0);

// Initiate scroller 320x720, ID 0, horizontal scroll false
leftDynamicScroller.Init(nLeftContainer, 0, 0, 160, 480, 0);
leftDynamicScroller.SetHorizontalScroll(false);
leftDynamicScroller.SetMinX(0);
leftDynamicScroller.SetMaxX(160);

// Populate left container
ViewAdd(nLeftContainer, "Images/Background1.png", 0, 0);

// Initiate scroller 320x720, ID 0, horizontal scroll false
rightDynamicScroller.Init(nRightContainer, 0, 0, 160, 480, 1);
rightDynamicScroller.SetHorizontalScroll(false);
rightDynamicScroller.SetMinX(160);
rightDynamicScroller.SetMaxX(320);

// Populate right container
ViewAdd(nRightContainer, "Images/Background2.png", 0, 0);
}

// This function is called whenever the app terminates
void AppExit()
{

}

// This function is called 30 times per second
void OnTimer()
{
if (nTouchEvent == 2)
{
if (nTouchId == 0)
leftDynamicScroller.Update();
else if (nTouchId == 1)
rightDynamicScroller.Update();
}
else
{
leftDynamicScroller.Update();
rightDynamicScroller.Update();
}
}

As usual, I leave the a ZIP file for anyone that's interested.

http://www.mediafire.com/?su353d84072daj8

By the way, I'm still working on the list menu. I've got the button almost working.

stuckerj

  • Guest
Re: Scrolling
« Reply #24 on: August 15, 2012, 08:24:42 pm »
Thanks, setting the min and max properly makes it work.  Good job on the scroller.

Nico91

  • Guest
Re: Scrolling
« Reply #25 on: September 21, 2012, 10:37:44 am »
the problem is that you can't include an .h file on the build center. But this recoil is perfect! im waiting the friction!! thank you very much :)

jjsanchezramirez

  • Guest
Re: Scrolling
« Reply #26 on: September 21, 2012, 12:06:25 pm »
Sure you can! I'm pretty certain it says so somewhere in the help file. I've been swamped with work, but I plan to add friction soon. I'm finally getting an iPad, so I can now actually test the code.

Nico91

  • Guest
Re: Scrolling
« Reply #27 on: September 22, 2012, 07:43:24 am »
I made a code for friction, can you add on my code your code for recoil in a simple way?
The code you've shown for the recoil is very complicated to understand, there are too many features .. you can simplify it?
« Last Edit: January 10, 2013, 06:49:45 am by Nico91 »

jjsanchezramirez

  • Guest
Re: Scrolling
« Reply #28 on: September 22, 2012, 12:58:20 pm »
It's really good code. I can definitely simplify it and add it to the other one.

jjsanchezramirez

  • Guest
Re: Scrolling
« Reply #29 on: September 22, 2012, 09:03:16 pm »
I just reviewed the code, and it's excellent. Sure, it's a bit confabulated, but the core idea behind it works incredibly well. You might want to consider using comments next time. :/
It was incredibly hard to read.