help with my Menu

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
PsPfReAK
Posts: 61
Joined: Sat Mar 28, 2009 9:02 am
Contact:

help with my Menu

Post by PsPfReAK »

Code: Select all

#include <pspsdk.h>   
#include <pspkernel.h>
#include <psppower.h>
#include <pspctrl.h>
#include <pspdisplay.h>
#include <pspdebug.h> 

#define printf pspDebugScreenPrintf 


PSP_MODULE_INFO&#40;"Sample Menu", 0, 1, 0&#41;;
PSP_MAIN_THREAD_ATTR&#40;PSP_THREAD_ATTR_USER&#41;; 


SceCtrlData currentPad, lastPad;

int option = 1;
int down = 1;
int up = 1;


void Menu_A&#40;&#41;
&#123;
    option = 1;
    down = 1;
    up = 1;
   
    pspDebugScreenClear&#40;&#41;;      
    pspDebugScreenSetTextColor&#40;0xFF0000&#41;;
    printf&#40;"\n Sample Menu\n\n\n"&#41;;
    pspDebugScreenSetTextColor&#40;0xFFFFFF&#41;;
    printf&#40;" Select an option&#58;\n\n"&#41;;
    pspDebugScreenSetTextColor&#40;0x0000FF&#41;;
    printf&#40;" -> Option 1\n"&#41;;
    pspDebugScreenSetTextColor&#40;0xFFFFFF&#41;;
    printf&#40;" -> Option 2\n"&#41;;
    pspDebugScreenSetTextColor&#40;0xFFFFFF&#41;;
    printf&#40;" -> Exit\n\n"&#41;;
    pspDebugScreenSetTextColor&#40;0xFFFFFF&#41;;
	printf&#40;" -> Test selected\n"&#41;;
    pspDebugScreenSetTextColor&#40;0x00FF00&#41;;
    printf&#40;" Press X to select the option."&#41;;
&#125;

void Menu_B&#40;&#41;
&#123;
    option = 2;
    down = 2;
    up = 2;
   
    pspDebugScreenClear&#40;&#41;; 
    pspDebugScreenSetTextColor&#40;0xFF0000&#41;;
    printf&#40;"\n Sample Menu\n\n\n"&#41;;
    pspDebugScreenSetTextColor&#40;0xFFFFFF&#41;;
    printf&#40;" Select an option&#58;\n\n"&#41;;
    printf&#40;" -> Option 1\n"&#41;;
    pspDebugScreenSetTextColor&#40;0x0000FF&#41;;
    printf&#40;" -> Option 2\n"&#41;;
    pspDebugScreenSetTextColor&#40;0xFFFFFF&#41;;
    printf&#40;" -> Exit\n\n"&#41;;
    pspDebugScreenSetTextColor&#40;0xFFFFFF&#41;;
	printf&#40;" -> Test selected\n"&#41;;
    pspDebugScreenSetTextColor&#40;0x00FF00&#41;;
    printf&#40;" Press X to select the option."&#41;;
&#125;

void Menu_C&#40;&#41;
&#123;
    option = 3;
    down = 3;
    up = 3;
   
    pspDebugScreenClear&#40;&#41;; 
    pspDebugScreenSetTextColor&#40;0xFF0000&#41;;
    printf&#40;"\n Sample Menu\n\n\n"&#41;;
    pspDebugScreenSetTextColor&#40;0xFFFFFF&#41;;
    printf&#40;" Select an option&#58;\n\n"&#41;;
    printf&#40;" -> Option 1\n"&#41;;
    pspDebugScreenSetTextColor&#40;0xFFFFFF&#41;;
    printf&#40;" -> Option 2\n"&#41;;
    pspDebugScreenSetTextColor&#40;0x0000FF&#41;;
    printf&#40;" -> Exit\n\n"&#41;;
    pspDebugScreenSetTextColor&#40;0xFFFFFF&#41;;
	printf&#40;" -> Test selected\n"&#41;;
    pspDebugScreenSetTextColor&#40;0x00FF00&#41;;
    printf&#40;" Press X to select the option."&#41;;
&#125;
void Menu_D&#40;&#41;
&#123;
    option = 4;
    down = 4;
    up = 4;
   
    pspDebugScreenClear&#40;&#41;; 
    pspDebugScreenSetTextColor&#40;0xFF0000&#41;;
    printf&#40;"\n Sample Menu\n\n\n"&#41;;
    pspDebugScreenSetTextColor&#40;0xFFFFFF&#41;;
    printf&#40;" Select an option&#58;\n\n"&#41;;
    printf&#40;" -> Option 1\n"&#41;;
    pspDebugScreenSetTextColor&#40;0xFFFFFF&#41;;
    printf&#40;" -> Option 2\n"&#41;;
    pspDebugScreenSetTextColor&#40;0x0000FF&#41;;
    printf&#40;" -> Exit\n\n"&#41;;
	pspDebugScreenSetTextColor&#40;0xFFFFFF&#41;;
    printf&#40;" -> Test selected\n"&#41;;
    pspDebugScreenSetTextColor&#40;0x00FF00&#41;;
    printf&#40;" Press X to select the option."&#41;;
&#125;
void Option_A&#40;&#41;
&#123;
    pspDebugScreenClear&#40;&#41;; 
    pspDebugScreenSetTextColor&#40;0x00FF00&#41;;
    printf&#40;"\n Welcome to option A"&#41;;
    sceKernelDelayThread&#40;2*1000*1000&#41;;
    Menu_A&#40;&#41;;
&#125;

void Option_B&#40;&#41;
&#123;
    pspDebugScreenClear&#40;&#41;; 
    pspDebugScreenSetTextColor&#40;0x00FF00&#41;;
    printf&#40;"\n Welcome to Option B"&#41;;
    sceKernelDelayThread&#40;2*1000*1000&#41;;
    Menu_A&#40;&#41;;
&#125;

void Option_C&#40;&#41;
&#123;
    pspDebugScreenSetTextColor&#40;0x00FF00&#41;;
    printf&#40;"\n\n Bye Bye\n\n Now exiting..."&#41;;
    sceKernelDelayThread&#40;2*1000*1000&#41;;
    sceKernelExitGame&#40;&#41;;
&#125;
void Option_D&#40;&#41;
&#123;
	pspDebugScreenSetTextColor&#40;0x00FF00&#41;;
	pspDebugScreenClear&#40;&#41;; 
    printf&#40;"Test Selected"&#41;;
    sceKernelDelayThread&#40;2*1000*1000&#41;;
    Menu_A&#40;&#41;;
&#125;

int main&#40;&#41;
&#123;
   sceCtrlReadBufferPositive&#40;&lastPad, 1&#41;;

   pspDebugScreenInit&#40;&#41;;
   Menu_A&#40;&#41;;   

   while&#40;1&#41;
   &#123;
   
     sceCtrlReadBufferPositive&#40;&currentPad, 1&#41;;
      
     if&#40; currentPad.Buttons != lastPad.Buttons &#41;
     &#123;
       lastPad = currentPad;

     if&#40;currentPad.Buttons & PSP_CTRL_DOWN&#41;
     &#123;
       switch&#40;down&#41;
       &#123;
           case 1&#58; Menu_B&#40;&#41;;
               break;

           case 2&#58; Menu_C&#40;&#41;;
               break;
      
           case 3&#58; Menu_D&#40;&#41;;
               break;
			
			case 4&#58; Menu_A&#40;&#41;;
				break;
       &#125;
    &#125;

    if&#40;currentPad.Buttons & PSP_CTRL_UP&#41;
    &#123;
       switch&#40;up&#41;
       &#123;
          case 1&#58; Menu_D&#40;&#41;;
             break;

          case 2&#58; Menu_A&#40;&#41;;
             break;

          case 3&#58; Menu_B&#40;&#41;;
             break;
			 
		  case 4&#58; Menu_C&#40;&#41;;
			 break;
       &#125;   
    &#125;
&#125;

    if&#40;currentPad.Buttons & PSP_CTRL_CROSS&#41;
    &#123;
         switch&#40;option&#41;
       &#123;
           case 1&#58; Option_A&#40;&#41;;
             break;

           case 2&#58; Option_B&#40;&#41;;
             break;
       
           case 3&#58; Option_C&#40;&#41;;
             break;
			 
		   case 4&#58; Option_D&#40;&#41;;
			 break;
      &#125;    	  
    &#125;       
  &#125;               
&#125;
well its selecting all four tags like its supposed to but its only highlighting the 1st three and not the last.
how do i correct this?
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Correct the color setting in menu d... it's the same as menu c.
PsPfReAK
Posts: 61
Joined: Sat Mar 28, 2009 9:02 am
Contact:

Post by PsPfReAK »

J.F. wrote:Correct the color setting in menu d... it's the same as menu c.
theyre all the same?
this is my first menu, can you expand what you mean please?
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Notice that each menu sets the background and foreground color before printing the text for the menu. The "hilite" is done by making the text for the menu items not under the cursor one color, and the hilited item a different color. Each menu prints all the items, with the hilite color set for that particular item. Menu a hilites item a, menu b hilites menu b, and so on. Looking at the code above, menu c and d are both hiliting item c instead of c and then d.
Ooblik
Posts: 38
Joined: Thu Apr 10, 2008 1:47 pm

Post by Ooblik »

You need to discover the magic of simple arrays and for-next loops :)
Its not hard to pick up I was doing this kind of stuff in grade 7...

It may not seem like it but it's easier to learn the basics than program like that. XD

Here's a more proper way to do it:
http://www.mediafire.com/download.php?x2zmgwk2j2w
PsPfReAK
Posts: 61
Joined: Sat Mar 28, 2009 9:02 am
Contact:

Post by PsPfReAK »

Ooblik wrote:You need to discover the magic of simple arrays and for-next loops :)
Its not hard to pick up I was doing this kind of stuff in grade 7...

It may not seem like it but it's easier to learn the basics than program like that. XD

Here's a more proper way to do it:
http://www.mediafire.com/download.php?x2zmgwk2j2w
thanks i'll have a look
EDIT: im gonna stick to my menu, its more simple. lol
but thank you for the sample. when i get better at C and understand it more better then i might use it and give you credit.
but thank you for everyone that helped.
Post Reply