text based interfaces...

This is a discussion on text based interfaces... within the C++ Programming forums, part of the General Programming Boards category; the source for that prog is too long, I'll make a smaller program and post it afterwards I made a ...

  1. #16
    Rez
    Rez is offline
    Registered User
    Join Date
    Nov 2002
    Posts
    82
    the source for that prog is too long, I'll make a smaller program and post it afterwards I made a DOSGUI API.

  2. #17
    Registered User xconspirisist's Avatar
    Join Date
    Nov 2003
    Posts
    44
    Can someone tell me how to do what res did - sameple code or smth ?

  3. #18
    Rez
    Rez is offline
    Registered User
    Join Date
    Nov 2002
    Posts
    82
    Do you really want the code? My API code is kinda long.

  4. #19
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,607
    Originally posted by xconspirisist
    Can someone tell me how to do what res did - sameple code or smth ?
    http://msdn.microsoft.com/library/de..._reference.asp

    gg

  5. #20
    Registered User xconspirisist's Avatar
    Join Date
    Nov 2003
    Posts
    44
    As mentioned before, codeplug - I am using UNIX. That link is of no use what so ever.

    I wrote one myself in the end. well, its a hacked example. How clean is this ? :

    Code:
    #include <curses.h>
    #include <stdlib.h>
    
    #define ENTER 10
    #define ESCAPE 27
    
    void init_curses()
    {
            initscr();
            start_color();
            init_pair(1,COLOR_RED,COLOR_WHITE);
            init_pair(2,COLOR_BLUE,COLOR_WHITE);
            init_pair(3,COLOR_RED,COLOR_WHITE);
            curs_set(0);
            noecho();
            keypad(stdscr,TRUE);
    }
    
    WINDOW **draw_menu(int start_col)
    {
            int i;
            WINDOW **items;
            items=(WINDOW **)malloc(5*sizeof(WINDOW *));
    
            items[0]=newwin(6,19,1,start_col);
            wbkgd(items[0],COLOR_PAIR(0));
            box(items[0],ACS_VLINE,ACS_HLINE);
            items[1]=subwin(items[0],1,17,2,start_col+1);
            items[2]=subwin(items[0],1,17,3,start_col+1);
    		items[3]=subwin(items[0],1,17,4,start_col+1);
    		items[4]=subwin(items[0],1,17,5,start_col+1);
    	
            for (i=1;i<5;i++)
    			
                    wprintw(items[i],"Item%d",i);
    
    		
            wbkgd(items[1],COLOR_PAIR(1));
            wrefresh(items[0]);
            return items;
    }
    void delete_menu(WINDOW **items,int count)
    {
            int i;
            for (i=0;i<count;i++)
                    delwin(items[i]);
            free(items);
    }
    int scroll_menu(WINDOW **items,int count,int menu_start_col)
    {
            int key;
            int selected=0;
            while (1) {
                    key=getch();
                    if (key==KEY_DOWN || key==KEY_UP) {
                            wbkgd(items[selected+1],COLOR_PAIR(0));
                            wnoutrefresh(items[selected+1]);
                            if (key==KEY_DOWN) {
                                    selected=(selected+1) % count;
                            } else {
                                    selected=(selected+count-1) % count;
                            }
                            wbkgd(items[selected+1],COLOR_PAIR(1));
                            wnoutrefresh(items[selected+1]);
                            doupdate();
    
                    } else if (key==ESCAPE) {
                            return -1;
                    } else if (key==ENTER) {
                            return selected;
                    }
            }
    }
    int main()
    {
        int key;
    	int selected_item;
    
        init_curses();
        
      //  bkgd(COLOR_PAIR(1));
    
        move(0,0);
        printw("welcome to meh menu");
    
        refresh();
    
            WINDOW **menu_items;
       
                menu_items=draw_menu(4);
                selected_item=scroll_menu(menu_items,4,0);
                delete_menu(menu_items,9);
    	
    
    			
    	
                touchwin(stdscr);
                refresh();
    
        endwin();
        return 0;
    }
    Last edited by xconspirisist; 12-07-2003 at 01:28 PM.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Text based game..
    By MipZhaP in forum C++ Programming
    Replies: 8
    Last Post: 02-28-2005, 07:35 AM
  2. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 03:49 PM
  3. Looping Text based battle
    By pujuman in forum C++ Programming
    Replies: 7
    Last Post: 12-18-2004, 04:24 AM
  4. making a text based game
    By MisterSako in forum C++ Programming
    Replies: 1
    Last Post: 12-05-2004, 12:20 PM
  5. Text Based Game
    By drdroid in forum C++ Programming
    Replies: 2
    Last Post: 02-18-2002, 05:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21