Пример #1
0
void quit3(struct winampVisModule *this_mod)
{
	if (current_window_size==0)
	{
		width=640;
		height=480;
	}
	if (current_window_size==1)
	{
		width=800;
		height=600;
	}
	if (current_window_size==2)
	{
		width=1024;
		height=768;
	}
	if (current_window_size==3)
	{
		width=1280;
		height=1024;
	}
	if (current_window_size==4)
	{
		width=1600;
		height=1200;
	}

	//config_write(this_mod);																			// write configuration
	change_resolution(this_mod);
}
Пример #2
0
int main(int argc, char **argv)
{
    struct usb_device *usb_dev;
    struct usb_dev_handle *usb_handle;
    int retval = 1;
    int i;
    int usb_strlen[2];
    unsigned char res = 0;
    char usb_str[2][USBSTRLEN];

    usb_dev = device_init();
    if (usb_dev == NULL) {
        fprintf(stderr, "Device not found\n");
        exit(1);
    }

    usb_handle = usb_open(usb_dev);
    if (usb_handle == NULL) {
        fprintf(stderr,
             "Not able to claim the USB device\n");
        goto exit;
    }
    
   /* usb_strlen[0] = usb_get_string_simple(usb_handle, 1, usb_str[0], USBSTRLEN);
    usb_strlen[1] = usb_get_string_simple(usb_handle, 2, usb_str[1], USBSTRLEN);
    if (usb_strlen[0] < 0 ||
        usb_strlen[0] < 0)
        {
        fprintf(stderr,
             "Not able to get dev string\n");
        goto exit;
    }
    printf("Found: %s %s\n", usb_str[0], usb_str[1]);
*/
    if (argc == 1) {
        fprintf(stderr,
                "specify at least 1 arg\n");
        goto exit;
    }

    for (i = 1; i < argc; ++i) {
        if (strcasecmp(argv[i], "a") == 0)
            res = 1;
        if (strcasecmp(argv[i], "b") == 0)
            res = 2;
        if (strcasecmp(argv[i], "c") == 0)
            res = 3;
        if (strcasecmp(argv[i], "d") == 0)
            res = 4;
    }
    change_resolution(usb_handle, res);
    retval = 0;

exit:
    usb_close(usb_handle);
    return retval;
}
Пример #3
0
int main(int argc, char** argv) {
    int c;
    while ((c = getopt(argc, argv, "v:")) != -1) {
        switch (c) {
        case 'v':
            verbose = atoi(optarg);
            break;
        default:
            usage(argv[0]);
        }
    }

    if (optind != argc-1)
        usage(argv[0]);

    char* display = argv[optind];

    trueorabort(display[0] == ':', "Invalid display: '%s'", display);

    char* endptr;
    int displaynum = (int)strtol(display+1, &endptr, 10);
    trueorabort(display+1 != endptr && (*endptr == '\0' || *endptr == '.'),
                "Invalid display number: '%s'", display);

    init_display(display);
    socket_server_init(PORT_BASE + displaynum);

    unsigned char buffer[BUFFERSIZE];
    int length;

    while (1) {
        set_connected(dpy, False);
        socket_server_accept(VERSION);
        write_init();
        set_connected(dpy, True);
        while (1) {
            length = socket_client_read_frame((char*)buffer, sizeof(buffer));
            if (length < 0) {
                socket_client_close(1);
                break;
            }

            if (length < 1) {
                error("Invalid packet from client (size <1).");
                socket_client_close(0);
                break;
            }

            switch (buffer[0]) {
            case 'S':  /* Screen */
                if (!check_size(length, sizeof(struct screen), "screen"))
                    break;
                write_image((struct screen*)buffer);
                break;
            case 'P':  /* Cursor */
                if (!check_size(length, sizeof(struct cursor), "cursor"))
                    break;
                write_cursor();
                break;
            case 'R':  /* Resolution */
                if (!check_size(length, sizeof(struct resolution),
                                "resolution"))
                    break;
                change_resolution((struct resolution*)buffer);
                break;
            case 'K': {  /* Key */
                if (!check_size(length, sizeof(struct key), "key"))
                    break;
                struct key* k = (struct key*)buffer;
                log(2, "Key: kc=%04x\n", k->keycode);
                XTestFakeKeyEvent(dpy, k->keycode, k->down, CurrentTime);
                if (k->down) {
                    kb_add(KEYBOARD, k->keycode);
                } else {
                    kb_remove(KEYBOARD, k->keycode);
                }
                break;
            }
            case 'C': {  /* Click */
                if (!check_size(length, sizeof(struct mouseclick),
                                "mouseclick"))
                    break;
                struct mouseclick* mc = (struct mouseclick*)buffer;
                XTestFakeButtonEvent(dpy, mc->button, mc->down, CurrentTime);
                if (mc->down) {
                    kb_add(MOUSE, mc->button);
                } else {
                    kb_remove(MOUSE, mc->button);
                }
                break;
            }
            case 'M': {  /* Mouse move */
                if (!check_size(length, sizeof(struct mousemove), "mousemove"))
                    break;
                struct mousemove* mm = (struct mousemove*)buffer;
                XTestFakeMotionEvent(dpy, 0, mm->x, mm->y, CurrentTime);
                break;
            }
            case 'Q':  /* "Quit": release all keys */
                kb_release_all();
                break;
            default:
                error("Invalid packet from client (%d).", buffer[0]);
                socket_client_close(0);
            }
        }
        socket_client_close(0);
        kb_release_all();
        close_mmap(&cache[0]);
        close_mmap(&cache[1]);
    }

    return 0;
}
Пример #4
0
static WORD do_optnmenu(WORD item)
{
    WORD done, rebld, curr;
    WORD newres, newmode;

    done = FALSE;
    rebld = FALSE;

    curr = win_isel(G.g_screen, G.g_croot, 0);

    switch(item)
    {
    case IDSKITEM:
        rebld = ins_devices();
        if (rebld)
        {
            app_blddesk();
            do_wredraw(0, G.g_xdesk, G.g_ydesk, G.g_wdesk, G.g_hdesk);
        }
        break;
    case IAPPITEM:
        curr = 0;
        while( (curr = win_isel(G.g_screen, G.g_croot, curr)) )
        {
            WORD change;

            change = ins_app(curr);
            if (change < 0) /* user cancelled */
                break;
            if (change > 0) /* install or remove */
                rebld++;
        }
        if (rebld)
            desk_all(FALSE);
        break;
    case IICNITEM:
        rebld = ins_icon(curr);
        if (rebld > 0)
        {
            app_blddesk();
            do_wredraw(0, G.g_xdesk, G.g_ydesk, G.g_wdesk, G.g_hdesk);
        }
#if CONF_WITH_WINDOW_ICONS
        else if (rebld < 0)
        {
            win_bdall();
            win_shwall();
        }
#endif
        break;
    case RICNITEM:
        if (curr)
            rebld = rmv_icon(curr);
        if (rebld)
        {
            app_blddesk();
            do_wredraw(0, G.g_xdesk, G.g_ydesk, G.g_wdesk, G.g_hdesk);
        }
        break;
    case PREFITEM:
        if (inf_pref())
            desk_all(FALSE);
        break;
    case SAVEITEM:
        desk_wait(TRUE);
        cnx_put();
        app_save(TRUE);
        desk_wait(FALSE);
        break;
    case RESITEM:
        rebld = change_resolution(&newres,&newmode);
        if (rebld == 1)
        {
            if (FALSE)
                {
                    /* Dummy case for conditional compilation */
                }
#if CONF_WITH_VIDEL
            else if (newres == FALCON_REZ)
                shel_write(5,newmode,1,NULL,NULL);
#endif
#if CONF_WITH_ATARI_VIDEO
            else shel_write(5,newres+2,0,NULL,NULL);
#endif
            done = TRUE;
        }
        break;
    }

    return done;
}
Пример #5
0
struct Game* options_menu(WINDOW* screen, struct Game* game, struct Ball* ball, struct Paddle* paddle, int max_x, int max_y)
{
    clear();
    refresh();

    move_ball_xy(ball, ball->x, max_y / 2);

    char* opts_menu_l[8] = {"Difficulty", "Sound", "Paddle Sensitivity",\
        "Screen Size", "Left Control", "Right Control",\
        "Play to", "Save & Return"};

    struct Menu* opts_menu = new_menu(max_x / 8, 8, 8, opts_menu_l, BLUE_ON_BLACK, GREEN_ON_BLACK);

    WINDOW* info_win = newwin(3, max_x, max_y - 3, 0);

    Timer* timer = sgl_timer_new();

    char* tmp_str = malloc(sizeof(char) * MAX_STRING_LENGTH);

    int key;

    while (key != 'q'){
        switch (key = getch()){
            case KEY_DOWN:
                move_selected(opts_menu, DOWN);
                wclear(info_win);
                break;

            case KEY_UP:
                wclear(info_win);
                move_selected(opts_menu, UP);
                break;

            case KEY_LEFT:
                switch (opts_menu->selected){
                    case 0: //Difficulty
                        if (game->difficulty == 0) game->difficulty = 2;
                        else game->difficulty--;
                        break;
                    case 1: //Sound
                        if (game->sound) game->sound = 0;
                        else game->sound = 1;
                        break;
                    case 2: //Paddle sensitivity
                        if (game->sensitivity == 1) game->sensitivity = 4;//DEHARDCODE THE 4
                        else game->sensitivity--;
                        break;
                    case 4: //Left control selection...
                        game->p1_aictrl = (game->p1_aictrl ? 0 : 1); break;
                    case 5: //Right control selection
                        game->p2_aictrl = (game->p2_aictrl ? 0 : 1); break;
                    case 6: //Change maximum score...
                        game->max_score--;
                        if (game->max_score < 1) game->max_score = MAX_SCORE;
                        break;
                }
                break;

            case KEY_RIGHT:
            case KEY_ENTER:
                switch (opts_menu->selected){
                    case 0: //Difficulty
                        if (game->difficulty == 2) game->difficulty = 0;
                        else game->difficulty++;
                        break;
                    case 1: //Sound
                        if (game->sound) game->sound = 0;
                        else game->sound = 1;
                        break;
                    case 2: //Paddle sensitivity
                        if (game->sensitivity == 4) game->sensitivity = 1;
                        else game->sensitivity++;
                        break;
                    case 3: //Change Resolution
                        change_resolution(screen, game);
                        break;
                    case 4: //Left control selection...
                        if (game->p1_aictrl) game->p1_aictrl = 0;
                        else game->p1_aictrl = 1;
                        break;
                    case 5: //Right control selection
                        if (game->p2_aictrl) game->p2_aictrl = 0;
                        else game->p2_aictrl = 1;
                        break;
                    case 6: //Change maximum score...
                        game->max_score++;
                        if (game->max_score > MAX_SCORE) game->max_score = 1;
                        break;
                    case 7: //Quit
                        return game;
                        break;
                }
                break;
        }

        //Move and bound ball
        if (sgl_timer_elapsed_milliseconds(timer) > 20){
            sgl_timer_reset(timer);
            update_background(ball, paddle, max_x, max_y - 4);
            draw_background(screen, ball, paddle);
            box(info_win, 0, 0);
        }

        draw_strings(screen, 1, max_x / 2 - strlen(options_title[0]), options_title, 6);
        draw_menu(opts_menu);

        /************************************************************
         * NOTE: The spaces in strings below are there for a purpose!
         * They erase double digits. eg. "1 " erases "10"
         */
        snprintf(tmp_str, MAX_STRING_LENGTH, "%d ", game->difficulty + 1);//+1 so we don't get a difficulty of '0'
        mvwaddstr(screen, opts_menu->y, opts_menu->x + opts_menu->width + 1, tmp_str);//print difficulty

        mvwaddstr(screen, opts_menu->y + 1, opts_menu->x + opts_menu->width + 1, game->sound ? "On " : "Off");//print sound

        snprintf(tmp_str, MAX_STRING_LENGTH, "%d ", game->sensitivity);
        mvwaddstr(screen, opts_menu->y + 2, opts_menu->x + opts_menu->width + 1, tmp_str);//print sensitivity

        snprintf(tmp_str, MAX_STRING_LENGTH, "%dx%d", game->width, game->height); //Print the resolution
        mvwaddstr(screen, opts_menu->y + 3, opts_menu->x + opts_menu->width + 1, tmp_str);

        mvwaddstr(screen, opts_menu->y + 4, opts_menu->x + opts_menu->width + 1, game->p1_aictrl ? "Computer" : "Human   ");

        mvwaddstr(screen, opts_menu->y + 5, opts_menu->x + opts_menu->width + 1, game->p2_aictrl ? "Computer" : "Human   ");

        snprintf(tmp_str, MAX_STRING_LENGTH, "%d ", game->max_score);
        mvwaddstr(screen, opts_menu->y + 6, opts_menu->x + opts_menu->width + 1, tmp_str);

        //Write a helpful hint in the info_win
        switch (opts_menu->selected){
            case 0:
                mvwaddstr(info_win, 1, 1, "Change the difficulty, higher numbers are more difficult"); break;
            case 1:
                mvwaddstr(info_win, 1, 1, "Toggle sound on or off"); break;
            case 2:
                mvwaddstr(info_win, 1, 1, "Adjust paddle sensitivity, higher numbers are less sensitive"); break;
            case 3:
                mvwaddstr(info_win, 1, 1, "Change the playing screen size"); break;
            case 4:
                mvwaddstr(info_win, 1, 1, "Toggle control between Computer and Human for the left paddle"); break;
            case 5:
                mvwaddstr(info_win, 1, 1, "Toggle control between Computer and Human for the right paddle"); break;
            case 6:
                mvwaddstr(info_win, 1, 1, "Change the maximum score needed to win"); break;
            case 7:
                mvwaddstr(info_win, 1, 1, "Save changes and go back to main menu"); break;
        }

        wrefresh(opts_menu->win);
        wrefresh(info_win);
    }

    clear();
    refresh();
    return game;
}