#8 ncurses mouse API support

closed-fixed
None
5
2007-05-14
2002-04-16
Anonymous
No

E:\curses>cl -c -I pcur mtest.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler
Version 12.00.8168 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights
reserved.

mtest.c
mtest.c(25) : error C2065: 'MEVENT' : undeclared
identifier
mtest.c(25) : error C2146: syntax error : missing ';'
before identifier 'event'
mtest.c(25) : error C2065: 'event' : undeclared
identifier
mtest.c(52) : warning C4087: 'getmouse' : declared
with 'void' parameter list
mtest.c(54) : error C2224: left of '.bstate' must
have struct/union type
mtest.c(55) : error C2224: left of '.x' must have
struct/union type
mtest.c(55) : error C2224: left of '.y' must have
struct/union type
mtest.c(55) : warning C4047: 'function' : 'int '
differs in levels of indirectio
n from 'int *'
mtest.c(55) : warning C4024: 'report_choice' :
different types for formal and ac
tual parameter 1
mtest.c(55) : error C2198: 'report_choice' : too few
actual parameters

E:\curses>

Discussion

  • Stephen Gennard

    Stephen Gennard - 2002-04-16

    Logged In: YES
    user_id=47239

    /* File Path: basics/mouse_menu.c */
    #include <curses.h>

    #define WIDTH 30
    #define HEIGHT 10

    int startx = 0;
    int starty = 0;

    char *choices[] = { "Choice 1",
    "Choice 2",
    "Choice 3",
    "Choice 4",
    "Exit",
    };

    int n_choices = sizeof(choices) / sizeof(char *);

    void print_menu(WINDOW *menu_win, int highlight);
    void report_choice(int mouse_x, int mouse_y, int
    *p_choice);

    int main()
    { int c, choice = 0;
    WINDOW *menu_win;
    MEVENT event;

    /* Initialize curses */
    initscr();
    clear();
    noecho();
    cbreak(); //Line buffering disabled. pass on
    everything

    /* Try to put the window in the middle of screen */
    startx = (80 - WIDTH) / 2;
    starty = (24 - HEIGHT) / 2;

    attron(A_REVERSE);
    mvprintw(23, 1, "Click on Exit to quit");
    refresh();
    attroff(A_REVERSE);

    /* Print the menu for the first time */
    menu_win = newwin(HEIGHT, WIDTH, starty, startx);
    print_menu(menu_win, 1);
    /* Get all the mouse events */
    mousemask(ALL_MOUSE_EVENTS, NULL);

    while(1)
    { c = wgetch(menu_win);
    switch(c)
    { case KEY_MOUSE:
    if(getmouse(&event) == OK)
    { /* When the user clicks left mouse button
    */
    if(event.bstate & BUTTON1_PRESSED)
    { report_choice(event.x + 1, event.y +
    1, &choice);
    if(choice == -1) //Exit chosen
    goto end;
    mvprintw(22, 1, "Choice made is : %d
    String Chosen is \"%10s\"", choice, choices[choice - 1]);
    refresh();
    }
    }
    print_menu(menu_win, choice);
    break;
    }
    }
    end:
    endwin();
    return 0;
    }

    void print_menu(WINDOW *menu_win, int highlight)
    {
    int x, y, i;

    x = 2;
    y = 2;
    box(menu_win, 0, 0);
    for(i = 0; i < n_choices; ++i)
    { if(highlight == i + 1)
    { wattron(menu_win, A_REVERSE);
    mvwprintw(menu_win, y, x, "%s", choices[i]);
    wattroff(menu_win, A_REVERSE);
    }
    else
    mvwprintw(menu_win, y, x, "%s", choices[i]);
    ++y;
    }
    wrefresh(menu_win);
    }

    /* Report the choice according to mouse position */
    void report_choice(int mouse_x, int mouse_y, int *p_choice)
    { int i,j, choice;

    i = startx + 2;
    j = starty + 3;

    for(choice = 0; choice < n_choices; ++choice)
    if(mouse_y == j + choice && mouse_x >= i &&
    mouse_x <= i + strlen(choices[choice]))
    { if(choice == n_choices - 1)
    *p_choice = -1;
    else
    *p_choice = choice + 1;
    break;
    }
    }

     
  • Mark Hessling

    Mark Hessling - 2002-04-18

    Logged In: YES
    user_id=86185

    The code you have provided (I guess) was built with
    ncurses. PDCurses does not have the same interface to the
    mouse as ncurses does. This is unfortunate, but as I
    believe mouse support was built into PDCurses (09/1996)
    BEFORE ncurses implemented mouse support, the
    incompatibilities are due to ncurses, not PDCurses.

    An example of equivalent mouse usage between PDCurses and
    ncurses can be found in mouse.c in THE:
    http://prdownloads.sourceforge.net/hessling-
    editor/thesrc31.zip

     
  • Mark Hessling

    Mark Hessling - 2002-04-18
    • assigned_to: nobody --> rexx
    • status: open --> closed
     
  • William McBrine

    William McBrine - 2005-12-09
    • status: closed --> closed-invalid
     
  • William McBrine

    William McBrine - 2007-05-14
    • summary: No mouse support --> ncurses mouse API support
    • status: closed-invalid --> closed-fixed
     
  • William McBrine

    William McBrine - 2007-05-14

    Logged In: YES
    user_id=27933
    Originator: NO

    PDCurses 3.0+ includes an ncurses-compatible mouse interface. To use it, you must either #define NCURSES_MOUSE_VERSION yourself before including curses.h, or change instances of getmouse() in your code to nc_getmouse().

    The original report (titled "No mouse support") is still invalid, but "Fixed" seems a more appropriate label now. Title changed accordingly.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks