Thread: SDL Game Menu

  1. #1
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719

    SDL Game Menu

    So I'm using SDL to make a game. I am starting with the game menu first. For example, it will have "New Game", "Load Game", "Exit", etc. I want to use the mouse to pick the choice, I don't want to use the arrow keys or anything like that. So would I just have to keep track of where the mouse is, and if it equals the area of the text, then it will execute whatever action, correct? Would I have to make sometype of boundary around the text to detect a mouse event?

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Yes. Basically compare where the mouse is on the screen in respect to your text or bitmaps. I used this cool little effect in allegro which is similar to SDL where the bitmap would change on a rollover. I will see if I can dig up that code.
    Woop?

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Yes. If you know you'll need more menus such as in game and options menus then it might be best to create a GUI managment system. make each button a class which stores it's co-ordinates. When a mouse event happens such as a move or click send it to the GUI system which intereates through all it's items and determins which one the mouse co-ordinates are inside.

  4. #4
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Very nice Idea Quantum!
    Woop?

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You can either return a value from the menu indicating the selection choice and respond based on the value; function pointers; class message systems; or any method of your choice to get the job done.

    As long as it works and leads the user to the correct area of your application.....who cares how it works, just that it does.

    Technically in Windows every control or item is a window in itself and thus has all the functionality of a Window or it can have. Meaning that each can have it's own WinProc, etc, etc. You don't have to get this complicated.

    Might I suggest a framework like this:

    Code:
    struct MenuItemStruc
    {
      std::string lpszText;
      float x,y;
      float left,top,right,bottom;
      float width,height;
      DWORD dwID;
    };
    
      
    class CMenu;
    
    class CMenuItem
    {
      MenuItemStruc m_MenuItemProps;
    
      //Possible pointers to previous and next menus
      //Enables menu items to lead to pop-ups and/or can
      //implement a PREV/NEXT setup
      CMenu *m_pNextMenu;
      CMenu *m_pPrevMenu;
      
      //Selection ID of menu item
      //Returned when this menu item has been selected
    
      bool m_bHasFrame;  //If frame is visible this is true
      
      public:
        ...
        ...
        bool Create(float x,float y,std::string lpszText,bool bHasFrame=false);
    
        void SetText(std::string lpszText);
        ...
    };
    
    class CMenu
    {
      std::vector<CMenuItem *> m_vMenuItems;
      
      ....
       ....
      public:
       ...
       ...
       bool AddItem(CMenuItem *pItem);
       bool AddItem(MenuItemStruc item);
       ...
       ...
    };
    That should get you started.
    Last edited by VirtualAce; 05-29-2006 at 03:00 AM.

  6. #6
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Hmm...Seems tougher than I thought. I might just go with what prog said for now, since this is my first game. Than i'll make the choice of making a GUI after this first game, and use that for all my games. What would be the best method for checking if the mouse is on text? Should I use a simple "if statement" or something more complex?

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Do a simple bounding box check
    Code:
    if ((MouseX>=TextX && MouseX<=TextX+TextWidth) && (MouseY>=TextY && MouseY<=TextY+TextHeight))

  8. #8
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Ok, thats what I thought. Thanks!!!!!!!!!!!!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2009, 10:25 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. PC Game project requires c++ programmers
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 02-22-2006, 12:23 AM
  4. Game programming with SDL
    By cozman in forum Game Programming
    Replies: 9
    Last Post: 08-23-2001, 09:18 AM