/*
          __
         / /_______________  ____  ___
        / __/ ___/ ___/ __ \/ __ \/ _ \
       / /_(__  ) /__/ /_/ / /_/ /  __/
       \__/____/\___/\____/ .___/\___/
                         /_/

    mouse1.c
    drawing mouse buttons on the screen
*/

#include <tscope.h>

// coordinates of the mouse buttons
#define BUTTONS 2
struct {
    int x1, x2;
    int y1, y2;
} knop[BUTTONS];

int main()
{

    // set parameters 
    ts_scrsize(SIZE1);
    ts_bgcolor(RED);
    ts_font(COURIER, 12, BOLD);
    ts_fgcolor(BLUE);
    ts_fill(TRUE);

    // set mouse parameters
    ts_mousepos(0, 0);
    ts_mousecolor(WHITE);

    // compute coordinates of the mouse buttons
    knop[0].x1 = -XMAX / 3 - ax(.1);
    knop[0].x2 = -XMAX / 3 + ax(.1);
    knop[0].y1 = -YMAX / 4 - ay(.1);
    knop[0].y2 = -YMAX / 4 + ay(.1);
    knop[1].x1 = XMAX / 3 - ax(.1);
    knop[1].x2 = XMAX / 3 + ax(.1);
    knop[1].y1 = -YMAX / 4 - ay(.1);
    knop[1].y2 = -YMAX / 4 + ay(.1);

    // draw the buttons
    int i;
    for (i = 0; i < BUTTONS; i++) {
        ts_rect(knop[i].x1, knop[i].y1, knop[i].x2, knop[i].y2);
        int col = ts_fgcolor(RED);
        ts_printf_centre((knop[i].x1 + knop[i].x2) / 2,
                         (knop[i].y1 + knop[i].y2) / 2, "%d", i + 1);
        ts_fgcolor(col);
    }

    // draw mouse cursor, define mouse as response button
    ts_drawmouse();
    ts_defkey(M1);
    ts_defkey(M2);

    // wait for a response,
    // and check wheter the mouse cursor
    // is within one of the button areas
    int resp;
    int x, y, waar = 0;
    do {
        resp = ts_respstatus();
        x = ts_xmouse();
        y = ts_ymouse();
        if (resp)
            for (i = 0; i < BUTTONS; i++)
                if (x > knop[i].x1 && x < knop[i].x2 && y > knop[i].y1
                    && y < knop[i].y2)
                    waar = i + 1;
    } while (!waar);

    // hide the mouse
    ts_hidemouse();

    // print some info on the screen
    ts_printf_centre(0, 2 * YMAX / 3, "screen button %d pressed", waar);
    ts_printf_centre(0, YMAX / 3, "with mouse button %d", resp);

    ts_button(XMAX - 20, -YMAX + 20);
    return 0;
}

END_OF_MAIN();


top
Persoonlijke pagina Universiteit GentTscope
Allegro | Cygwin | Gcc
© See license.html for copyright information