Author Topic: Button page navigation  (Read 2845 times)

Chewbaca427

  • Guest
Button page navigation
« on: July 17, 2012, 12:02:12 pm »
Is it possible to have a page of buttons that lead to new pages of buttons and have a back button to the first page? if so can you make a simple code please?

nednones

  • Guest
Re: Button page navigation
« Reply #1 on: July 17, 2012, 03:44:18 pm »
It is..

You can either have a Switch Case statement which is embedded in your OnTimer() application whereby each case statement is set by your button callback, e.g. Button 1 sets an integer to 1 and in OnTimer(), the controls, buttons, e.t.c are loaded.

To do this you can either delete or make the views visible or move the views by -(x = 320 pixels) everytime the switch case statement is called. An example of which is shown below:
int Page; //Global declaration

OnButtonCallbackMethod1(declarations)
{
   Page = 1;
}
OnButtonCallbackMethod2(declarations)
{
   Page = 2;
}

AppMain()
{
   Declare Buttons and there callbacks
}

OnTimer()
{
    switch()
    {
         case 1:
                 //Delete or make previous views invisible
                 //Move Page 1 views into place or set visible
             break;
         case 2:
                 //Delete or make previous views invisible
                 //Move Page 2 views into place or set visible
             break;
    }
}

nednones

  • Guest
Re: Button page navigation
« Reply #2 on: July 17, 2012, 03:45:22 pm »
Opps! Should have Page in declared in the switch statement, e.g. switch(Page)

octopus

  • Guest
Re: Button page navigation
« Reply #3 on: July 18, 2012, 03:04:42 am »
I think you'd want to be using containers here especially if your using just momentary buttons. If you want state control it does become more complex but it is all doable.

nednones

  • Guest
Re: Button page navigation
« Reply #4 on: July 18, 2012, 05:04:14 am »
As Octopus stated, keep every page in a single container, e.g. All views/objects, that way when a state has changed in terms of what page you select you can you simply move the container of the screen or make the container invisible.

zacho

  • Jr. Member
  • **
  • Posts: 81
  • Karma: +2/-0
    • View Profile
Re: Button page navigation
« Reply #5 on: July 18, 2012, 08:07:17 am »
Here's how to do this, I am making a program with pages and its really easy once you know how to. First, create your containers and buttons within AppMain() (I use a function for cleanliness). Create a function that handles your swapping menus (I happen to use multiple because it is easier to code but anyway works).

Code: [Select]
int container1;
int container2;
int container3;
//.... etc


int Onbackbutton(int id)
{
         if( id == 1 )
               {
               ContainerSetVisible(page1,0); //"erase" page 1
               ContainerSetVisible(page2,1); //draw page 2 on screen
               }   
}
int Function()
{
         //Create your containers in here
         container1 = ContainerAdd(0,0,0);
         container2 = ContainerAdd(0,0,0);
         container3 = ContainerAdd(0,0,0);


         //Add buttons for your containers
         ButtonAdd( container1, "Images/button", 0,0, Onbackbutton, 1 )
         ButtonAdd( container2, "Images/button", 0,0, Onbackbutton, 2 )


         //Set initial visibility flags
         ContainerSetVisible(container1,1);
         ContainerSetVisible(container2,0);
         //....etc

}



AppMain()
{
        Function();



}

OnTimer()
{


}

Chewbaca427

  • Guest
Re: Button page navigation
« Reply #6 on: July 18, 2012, 04:55:30 pm »
i don't have 2.0 so no containers. can someone just make one page for me with my code.. i learn best by example.

Code: [Select]
#include "DragonFireSDK.h"

int Page=1;
int ButtonTroops=0;
int ButtonFastAttack=0;
int ButtonHeavySupport=0;
int ButtonExit1=0;

int OnButton1(int value)
{
   switch (value)
   {
      case 1:
         if (ButtonTroops)
            ButtonTroops= 0;
         else
            ButtonTroops = 1;
(ButtonTroops);     
  break;
     
   }
   return(1);   
}
int OnButton2(int value)
{
   switch (value)
   {
      case 1:
         if (ButtonFastAttack)
            ButtonFastAttack= 0;
         else
            ButtonFastAttack = 1;
(ButtonFastAttack);
         break;
     
   }
   return(1);   
}
int OnButton3(int value)
{
   switch (value)
   {
      case 1:
         if (ButtonHeavySupport)
            ButtonHeavySupport= 0;
         else
            ButtonHeavySupport = 1;
(ButtonHeavySupport);     
         break;
     
   }
   return(1);   
}

void AppMain()
{
ViewAdd("Images/Background.png",0,0);
ButtonAdd("Images/Button_Troops", 10, 10, OnButton1, 0);
ButtonAdd("Images/Button_FastAttack", 10, 60, OnButton2, 0);
ButtonAdd("Images/Button_HeavySupport", 10, 110, OnButton3, 0);
}
void OnTimer()
{
switch(Page)
    {
         case 1:


             break;
         case 2:

             break;
         case 3:

             break;
         case 4:

             break;
    }
}
void AppExit()
{

}
« Last Edit: July 18, 2012, 05:13:55 pm by Chewbaca427 »

nednones

  • Guest
Re: Button page navigation
« Reply #7 on: July 19, 2012, 01:47:55 am »
You can just create a class with a method to manage all your views per page and then use an overloaded method which sets all views created within that class to be visible or deleted instead of using a container

Chewbaca427

  • Guest
Re: Button page navigation
« Reply #8 on: July 21, 2012, 09:13:36 pm »
ALRIGHT   :D  I got it working but I need to know how to put my main menu stuff as a button or re open it so its on top.. my new code is
Code: [Select]
#include "DragonFireSDK.h"
int Page=1;
int ButtonTroops=0;
int ButtonFastAttack=0;
int ButtonHeavySupport=0;


int OnButton1(int value)
{
   switch (value)
   {
      case 1:
         if (ButtonTroops)
            ButtonTroops= 0;
         else
            ButtonTroops = 1;
(ButtonTroops);
  break;
  case 2:
ViewAdd("Images/TauTroopsBG.png",0,0);
ButtonAdd("Images/Button_Back", 10, 410, OnButton1, 1);
break;
     
   }
   return(1);   
}
int OnButton2(int value)
{
   switch (value)
   {
      case 1:
         if (ButtonFastAttack)
            ButtonFastAttack= 0;
         else
            ButtonFastAttack = 1;
(ButtonFastAttack);
         break;
     
   }
   return(1);   
}
int OnButton3(int value)
{
   switch (value)
   {
      case 1:
         if (ButtonHeavySupport)
            ButtonHeavySupport= 0;
         else
            ButtonHeavySupport = 1;
(ButtonHeavySupport);
         break;
     
   }
   return(1);   
}

void AppMain()
{
ViewAdd("Images/Background.png",0,0);
ButtonAdd("Images/Button_Troops", 10, 10, OnButton1, 2);
ButtonAdd("Images/Button_FastAttack", 10, 60, OnButton2, 2);
ButtonAdd("Images/Button_HeavySupport", 10, 110, OnButton3, 2);
void OnTimer()
{

}
void AppExit()
{

}

zacho

  • Jr. Member
  • **
  • Posts: 81
  • Karma: +2/-0
    • View Profile
Re: Button page navigation
« Reply #9 on: July 21, 2012, 10:50:06 pm »
can you send me your file folder with all the images and I can look at it tomorrow?

Chewbaca427

  • Guest
Re: Button page navigation
« Reply #10 on: July 22, 2012, 12:59:13 pm »
k sent it