D
D
dlinyj2013-12-04 13:47:32
linux
dlinyj, 2013-12-04 13:47:32

Using mouse in newt (GUI console). Alternatives to ncurses?

I welcome everyone. Was looking for a cheap and easy alternative to ncurses. I thought about writing myself.
Because you want cheap, simple and tasteful. So that opa and molds with buttons fall out. And suddenly I discovered the newt library for myself . Where you can easily do some really cool stuff. Here is an example with checkboxes and radio buttons
0_b42b3_4515f1e7_L.png
The code is generally minimalistic

Code example
#include <newt.h>
#include <stdlib.h>
#include <stdio.h>

void main(void) {
    newtComponent form, checkbox, rb[3], button;
    char cbValue;
    int i;

    newtInit();
    newtCls();

    newtOpenWindow(10, 5, 40, 11, "Checkboxes and Radio buttons");

    checkbox = newtCheckbox(1, 1, "A checkbox", ' ', " *X", &cbValue);

    rb[0] = newtRadiobutton(1, 3, "Choice 1", 1, NULL);
    rb[1] = newtRadiobutton(1, 4, "Choice 2", 0, rb[0]);
    rb[2] = newtRadiobutton(1, 5, "Choice 3", 0, rb[1]);

    button = newtButton(1, 7, "Ok");

    form = newtForm(NULL, NULL, 0);
    newtFormAddComponent(form, checkbox);
    for (i = 0; i < 3; i++)
        newtFormAddComponent(form, rb[i]);
    newtFormAddComponent(form, button);

    newtRunForm(form);
    newtFinished();

    /* We cannot destroy the form until after we've found the current
       radio button */

    for (i = 0; i < 3; i++)
        if (newtRadioGetCurrent(rb[0]) == rb[i])
            printf("radio button picked: %d\n", i);
    newtFormDestroy(form);

    /* But the checkbox's value is stored locally */
    printf("checkbox value: '%c'\n", cbValue);


But, no examples of working with the mouse. Google is silent. In general, the mouse is required not quite for control, it would be nice to at least display the mouse coordinates in the window. Are there any thread ideas? Or is it still worth dumping back into ncurses?
Z.Y. Two useful links with examples of console graphics programming. Just leaving here
www.linuxforu.com/2011/08/spicing-up-console-for-f...
www.linuxforu.com/2011/11/spicing-up-console-for-f...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
elw00d, 2013-12-08
@dlinyj

You can try using the library www.leonerd.org.uk/code/libtermkey/. I use it in my "framework" https://bitbucket.org/igor_kostromin/consoleframework for input processing. How exactly - you can see in the files ConsoleApplication.cs and LibTermKey.cs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question