Пример #1
0
static bool gfx_ctx_set_video_mode(void *data,
      unsigned width, unsigned height,
      bool fullscreen)
{
   DWORD style;
   RECT rect   = {0};

   HMONITOR hm_to_use = NULL;
   MONITORINFOEX current_mon;

   monitor_info(&current_mon, &hm_to_use);
   RECT mon_rect = current_mon.rcMonitor;

   g_resize_width  = width;
   g_resize_height = height;

   bool windowed_full = g_settings.video.windowed_fullscreen;
   if (fullscreen)
   {
      if (windowed_full)
      {
         style = WS_EX_TOPMOST | WS_POPUP;
         g_resize_width  = width  = mon_rect.right - mon_rect.left;
         g_resize_height = height = mon_rect.bottom - mon_rect.top;
      }
      else
      {
         style = WS_POPUP | WS_VISIBLE;

         if (!set_fullscreen(width, height, current_mon.szDevice))
            goto error;

         // display settings might have changed, get new coordinates
         GetMonitorInfo(hm_to_use, (MONITORINFO*)&current_mon);
         mon_rect = current_mon.rcMonitor;
         g_restore_desktop = true;
      }
   }
   else
   {
      style = WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
      rect.right  = width;
      rect.bottom = height;
      AdjustWindowRect(&rect, style, FALSE);
      width  = rect.right - rect.left;
      height = rect.bottom - rect.top;
   }

   g_hwnd = CreateWindowEx(0, "RetroArch", "RetroArch", style,
         fullscreen ? mon_rect.left : g_pos_x,
         fullscreen ? mon_rect.top  : g_pos_y,
         width, height,
         NULL, NULL, NULL, NULL);

   if (!g_hwnd)
      goto error;

   if (!fullscreen || windowed_full)
   {
      ShowWindow(g_hwnd, SW_RESTORE);
      UpdateWindow(g_hwnd);
      SetForegroundWindow(g_hwnd);
      SetFocus(g_hwnd);
   }

   show_cursor(!fullscreen);

   // Wait until GL context is created (or failed to do so ...)
   MSG msg;
   while (!g_inited && !g_quit && GetMessage(&msg, g_hwnd, 0, 0))
   {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
   }

   if (g_quit)
      goto error;

   p_swap_interval = (BOOL (APIENTRY *)(int))wglGetProcAddress("wglSwapIntervalEXT");

   gfx_ctx_swap_interval(data, g_interval);

   driver.display_type  = RARCH_DISPLAY_WIN32;
   driver.video_display = 0;
   driver.video_window  = (uintptr_t)g_hwnd;

   return true;

error:
   gfx_ctx_destroy(data);
   return false;
}
Пример #2
0
static void gfx_ctx_show_mouse(void *data, bool state)
{
   (void)data;
   show_cursor(state);
}
Пример #3
0
int main(int argc, char *argv[])
{
	puts("conlib测试程序:");
	T(conlib_init(),"初始化控制台库");
	 
	T(gotoxy(5,5),"现在光标在这里了");
	T(hide_cursor(),"光标不见了"); 
	T(show_cursor(50),"显示一半光标"); 
	T(show_cursor(100),"显示完整光标"); 
	T(settitle("conlib test program"),"设置标题");
	T(set_text_color(ConRed),"设置文字颜色");
	T(set_background_color(ConWhite),"设置背景颜色");
	
	clrscr();
	
	const ConKey* ck;
	const ConMouse* cm;
	const ConControlKeyState *cks; 

	char spaceLine[80] = {[0 ... 78] = ' ',[79] = '\0'};

	

	puts("按键测试:");
	hide_cursor();
#define Tand(v,t)	if(v & t)printf(#t "  ");
#define Teq(v,t)	if(v == t)printf(#t "  ");
	while(1)
	{
		gotoxy(12,0);
		printf("clock: %d\t", (int)clock()); 
		
		ck = getkey();
		cm = getmouse();
		cks = NULL; 
		gotoxy(0,1);
		printf("key value: %p", ck);
		gotoxy(0,2);
		printf("mouse value: %p", cm);
		
		gotoxy(0,3);
		if(ck != NULL)
		{
			cks = ck->ctrl_key_state;
			printf("key code: %d is %s", ck->key, ck->state? "按下": "释放");			
		}
			
		gotoxy(0,4);
		if(cm != NULL)
		{
			cks = cm->ctrl_key_state;
			printf("mouse position: %2d, %2d\n", cm->x, cm->y);
			printf(spaceLine);
			printf(spaceLine);
			printf(spaceLine);
			printf(spaceLine);
			gotoxy(0,5);
			if(cm->event != ConMOUSE_WHEELED && cm->event != ConMOUSE_HWHEELED)
			{
				Tand(cm->button,ConMOUSE_1ST_BUTTON);
				Tand(cm->button,ConMOUSE_2ND_BUTTON);
				Tand(cm->button,ConMOUSE_3RD_BUTTON);
				Tand(cm->button,ConMOUSE_4TH_BUTTON);
				Tand(cm->button,ConMOUSE_RIGHT_BUTTON);
				printf(" 被 按下了\n");
			}else
				printf("鼠标向 [%s] 滚\n", cm->button > 0? "前":"后");
			Teq(cm->event,ConMOUSE_CLICK);
			Teq(cm->event,ConMOUSE_DBCLICK);
			Teq(cm->event,ConMOUSE_MOVED);
			Teq(cm->event,ConMOUSE_WHEELED);
			Teq(cm->event,ConMOUSE_HWHEELED);
			printf(" 被 触发了\n");
		}

		gotoxy(0,10);
#define S(c)	(c? "ON": "OFF")

		if(cks != NULL)
			printf("NUM[%3s]  SCROLL[%3s]  CAPS[%3s]\n"
					"LCTRL[%3s]  LALT[%3s]  RALT[%3s]  RCTRL[%3s]\n"
					"SHIFT[%3s]  ENHANCED[%3s]"
					, S(cks->numlock), S(cks->scrolllock), S(cks->capslock)
					, S(cks->left_ctrl), S(cks->left_alt), S(cks->right_alt), S(cks->right_ctrl)
					, S(cks->shift), S(cks->enhanced));
		console_test();
	}	
	
return EXIT_SUCCESS;
}
Пример #4
0
static void gfx_ctx_show_mouse(bool state)
{
   show_cursor(state);
}
Пример #5
0
/*
 * Main driver for the game.
 */
int
main(int argc, char **argv) {
    // define usage
    const char *usage = "Usage: sudoku n00b|l33t [#]\n";

    // ensure that number of arguments is as expected
    if (argc != 2 && argc != 3) {
        fprintf(stderr, usage);
        return 1;
    }

    // ensure that level is valid
    if (!strcmp(argv[1], "debug"))
        g.level = "debug";
    else if (!strcmp(argv[1], "n00b"))
        g.level = "n00b";
    else if (!strcmp(argv[1], "l33t"))
        g.level = "l33t";
    else {
        fprintf(stderr, usage);
        return 2;
    }

    // n00b and l33t levels have 1024 boards; debug level has 9
    int max = (!strcmp(g.level, "debug")) ? 9 : 1024;

    // ensure that #, if provided, is in [1, max]
    if (argc == 3) {
        // ensure n is integral
        char c;
        if (!sscanf(argv[2], " %d %c", &g.number, &c) == 1) {
            fprintf(stderr, usage);
            return 3;
        }

        // ensure n is in [1, max]
        if (g.number < 1 || g.number > max) {
            fprintf(stderr, "That board # does not exist!\n");
            return 4;
        }

        // seed PRNG with # so that we get same sequence of boards
        srand(g.number);
    }
    else {
        // seed PRNG with current time so that we get any sequence of boards
        srand(time(NULL));

        // choose a random n in [1, max]
        g.number = rand() % max + 1;
    }

    // start up ncurses
    if (!startup()) {
        fprintf(stderr, "Error starting up ncurses!\n");
        return 6;
    }

    // register handler for SIGWINCH (SIGnal WINdow CHanged)
    signal(SIGWINCH, (void (*)(int)) handle_signal);

    // start the first game
    if (!restart_game()) {
        shutdown();
        fprintf(stderr, "Could not load board from disk!\n");
        return 7;
    }
    redraw_all();

    // let the user play!
    int ch;
    do {
        // refresh the screen
        refresh();

        // get user's input
        ch = getch();

        // capitalize input to simplify cases
        ch = toupper(ch);

        // process user's input
        switch (ch) {

            // left arrow key
            case KEY_LEFT:
            case 'H':
                if (--g.x < 0)
                    g.x += DIM;
                hide_banner();
                show_cursor();
                break;
            // right arrow key
            case KEY_RIGHT:
            case 'L': 
                if (++g.x >= DIM)
                    g.x -= DIM;
                hide_banner();
                show_cursor();
                break;
            // up arrow key
            case KEY_UP:
            case 'K':
                if (--g.y < 0)
                    g.y += DIM;
                hide_banner();
                show_cursor();
                break;
            // down arrow key
            case KEY_DOWN:
            case 'J':
                if (++g.y >= DIM)
                    g.y -= DIM;
                hide_banner();
                show_cursor();
                break;

            // enable user to enter numbers
            case '1': case '2': 
            case '3': case '4': 
            case '5': case '6': 
            case '7': case '8': 
            case '9':
                if (g.given[g.y][g.x] == false && validate(ch) == true) {
                    enter_number(ch);
                    draw_numbers();
                    show_cursor();
                    won();
                }
                break; 

            // delete a number
            case KEY_BACKSPACE:
            case KEY_DC:
            case '.':
            case '0':
                if (g.given[g.y][g.x] == false) {
                    g.board[g.y][g.x] = 0; 
                    draw_numbers();
                    hide_banner();
                    show_cursor();
                }
                break;
            // start a new game
            case 'N': 
                g.number = rand() % max + 1;
                if (!restart_game()) {
                    shutdown();
                    fprintf(stderr, "Could not load board from disk!\n");
                    return 7;
                }
                break;

            // restart current game
            case 'R': 
                if (!restart_game()) {
                    shutdown();
                    fprintf(stderr, "Could not load board from disk!\n");
                    return 7;
                }
                break;

            // let user manually redraw screen with ctrl-L
            case CTRL('l'):
                redraw_all();
                break;
        }   // end switch statement

        // log input (and board's state) if any was received this iteration
        if (ch != ERR)
            log_move(ch);

    } while (ch != 'Q');

    // shut down ncurses
    shutdown();

    // tidy up the screen (using ANSI escape sequences)
    printf("\033[2J");
    printf("\033[%d;%dH", 0, 0);

    // kthxbai
    printf("\nkthxbai!\n\n");
    return 0;
}
Пример #6
0
void TextRenderer::render( const MapVisibility& m ) {
	show_cursor( false );
	for( size_t r = 0; r < m.rows; ++r ) for( size_t c = 0; c < m.cols; ++c )
		if( m[r][c].is_dirty() )	put_glyph( glyph_map( m[r][c] ), c, r );
	show_cursor( true );
}
Пример #7
0
bool
check_valid(int n)
{

    int newx=0, newy=0;
    for (int i=0; i<9; i++)
    {
      
      if  ((g.board[i][g.x])==movenumber)


      {
	     show_banner("You have made an invalid move!");
	     g.badMoves[i][g.x]=99;
	     show_cursor();

	     return false;
	}
      if  ((g.board[g.y][i])==movenumber)


      {
	     show_banner("You have made an invalid move!");
	     g.badMoves[i][g.x]=99;
	     show_cursor();

	     return false;
	}

    }
        
	if (g.y%3==2) ///find origin of little box
	          
	    newy=g.y-2;
	           
	else if (g.y%3==1)
	
	    newy=g.y-1;
	    
	if (g.x%3==2)
	
	    newx=g.x-2;
	    
	else if (g.x%3==1)
	
	    newx=g.x-1;
        
	for (int j=0; j<3; j++)
	{
	    for (int k=0; k<3; k++)
	    {
	        if (((tempBoard[newy+j][newx+k])==movenumber)&& ((g.board[k][g.x])!=movenumber))
		 { 
			
	      		 show_banner("You have made an invalid move!");
			 g.badMoves[newy+j][newx+k]=99;
			 show_cursor();
			 return false;
		  }
	    }
	} 

return true;
}
Пример #8
0
void term::show ()
{
  if (!_visible)
    {
      int sx;
      int sy;
      int ex;
      int ey;
      int char_height = _fn->get_height ();
      pattern* background;

      char_coord_to_screen_coord (_nb_columns-1, _nb_rows-1, sx, sy, ex, ey);

      color_to_pattern (normal_background, background);

      video::screen.frame_rect
        (_x,
         _y,
         ex + outer_border + frame_border + inner_border,
         ey + outer_border + frame_border + inner_border,
         outer_border,
         &pattern::white);

      video::screen.frame_rect
        (_x + outer_border,
         _y + outer_border,
         ex + frame_border + inner_border,
         ey + frame_border + inner_border,
         frame_border,
         &pattern::gray50);

      video::screen.fill_rect
        (_x + outer_border + frame_border,
         _y + char_height + outer_border + frame_border + 2*inner_border,
         ex + inner_border,
         _y + char_height + outer_border + 2*frame_border + 2*inner_border,
         &pattern::gray50);

      video::screen.fill_rect
        (_x + outer_border + frame_border,
         _y + outer_border + frame_border,
         ex + inner_border,
         _y + char_height + outer_border + frame_border + 2*inner_border,
         &pattern::black);

      _fn->draw_string
        (&video::screen,
         _fn->draw_string
           (&video::screen,
            _x + outer_border + frame_border + inner_border,
            _y + outer_border + frame_border + inner_border,
            L"\x25b6 ", // rightward triangle and space
            &pattern::blue,
            &pattern::black),
         _y + outer_border + frame_border + inner_border,
         _title,
         &pattern::blue,
         &pattern::black);

      video::screen.fill_rect
        (_x + outer_border + frame_border,
         _y + char_height + outer_border + 2*frame_border + 2*inner_border,
         ex + inner_border,
         ey + inner_border,
         background);

      show_cursor ();

      _visible = TRUE;
    }
}
Пример #9
0
int
main(int argc, char *argv[])
{
    // define usage
    const char *usage = "Usage: sudoku n00b|l33t [#]\n";

    // ensure that number of arguments is as expected
    if (argc != 2 && argc != 3)
    {
        fprintf(stderr, usage);
        return 1;
    }

    // ensure that level is valid
    if (strcmp(argv[1], "debug") == 0)
        g.level = "debug";
    else if (strcmp(argv[1], "n00b") == 0)
        g.level = "n00b";
    else if (strcmp(argv[1], "l33t") == 0)
        g.level = "l33t";
    else
    {
        fprintf(stderr, usage);
        return 2;
    }

    // n00b and l33t levels have 1024 boards; debug level has 9
    int max = (strcmp(g.level, "debug") == 0) ? 9 : 1024;

    // ensure that #, if provided, is in [1, max]
    if (argc == 3)
    {
        // ensure n is integral
        char c;
        if (sscanf(argv[2], " %d %c", &g.number, &c) != 1)
        {
            fprintf(stderr, usage);
            return 3;
        }

        // ensure n is in [1, max]
        if (g.number < 1 || g.number > max)
        {
            fprintf(stderr, "That board # does not exist!\n");
            return 4;
        }

        // seed PRNG with # so that we get same sequence of boards
        srand(g.number);
    }
    else
    {
        // seed PRNG with current time so that we get any sequence of boards
        srand(time(NULL));

        // choose a random n in [1, max]
        g.number = rand() % max + 1;
    }

    // start up ncurses
    if (!startup())
    {
        fprintf(stderr, "Error starting up ncurses!\n");
        return 5;
    }

    // register handler for SIGWINCH (SIGnal WINdow CHanged)
    signal(SIGWINCH, (void (*)(int)) handle_signal);

    // start the first game
    if (!restart_game())
    {
        shutdown();
        fprintf(stderr, "Could not load board from disk!\n");
        return 6;
    }
    redraw_all();
  

    // let the user play!
    int ch;
    
    int last[3] = {10};
    do
    {
        // refresh the screen
        refresh();

        // get user's input
        ch = getch();

        // capitalize input to simplify cases
        ch = toupper(ch);
         

        // process user's input
        switch (ch)
        {
            // start a new game
            case 'N': 
                g.number = rand() % max + 1;
                if (!restart_game())
                {
                    shutdown();
                    fprintf(stderr, "Could not load board from disk!\n");
                    return 6;
                }
                break;

            // restart current game
            case 'R': 
                if (!restart_game())
                {
                    shutdown();
                    fprintf(stderr, "Could not load board from disk!\n");
                    return 6;
                }
                break;

            // let user manually redraw screen with ctrl-L
            case CTRL('l'):
                redraw_all();
                break;
                
            
            
            case 'U': case CTRL('Z'):
                if (last[0] != 10 && !game_won())
                {
                    g.board[last[0]][last[1]] = last[2]; 
                    draw_numbers();
                    if (check_cols(1) || check_rows(1) || check_squares(1))
                    hide_banner();
                    show_cursor();
                    warn();
                }
               
                break; 
                
                // move cursor 
                
            case KEY_UP: 
                if (g.y > 0)
                {
                    g.y -= 1;
                    show_cursor();
                }
                else
                {
                    g.y = 8;
                    show_cursor();
                }          
                break; 
            
            case KEY_DOWN: 
                if (g.y < 8)
                {
                    g.y += 1;
                    show_cursor();
                }          
                else
                {
                    g.y = 0;
                    show_cursor();
                }    
                break; 
                
            case KEY_LEFT: 
                if (g.x > 0)
                {
                    g.x -= 1;
                    show_cursor();
                }          
                else
                {
                    g.x = 8;
                    show_cursor(); 
                }
                break; 
              
             case KEY_RIGHT: 
                if (g.x < 8)
                {
                    g.x += 1;
                    show_cursor();
                }    
                else
                {
                    g.x = 0;
                    show_cursor(); 
                }      
                break; 
                
             //input number and check if game is won
             case '1' ... '9':                
                if (g.init_board[g.y][g.x] == 0)
                {                    
                    last[0] = g.y;
                    last[1] = g.x;
                    last[2] = g.board[g.y][g.x];
                    g.board[g.y][g.x] = ch - 48; 
                    draw_numbers(); 
                    if (check_cols(1) || check_rows(1) || check_squares(1))
                    hide_banner(); 
                    show_cursor();
                }
                game_won();
                warn();                                
                
                break; 
                
             //return to blank space
             case '0': case '.': case KEY_BACKSPACE: case KEY_DC:
                if (g.init_board[g.y][g.x] == 0)
                {
                    last[0] = g.y;
                    last[1] = g.x;
                    last[2] = g.board[g.y][g.x];
                    g.board[g.y][g.x] = 0; 
                    draw_numbers();
                    if (check_cols(1) || check_rows(1) || check_squares(1))
                    hide_banner(); 
                    show_cursor();                   
                }               
                warn(); 
                break;          
        }

        // log input (and board's state) if any was received this iteration
        if (ch != ERR)
            log_move(ch);
    }
    while (ch != 'Q');

    // shut down ncurses
    shutdown();

    // tidy up the screen (using ANSI escape sequences)
    printf("\033[2J");
    printf("\033[%d;%dH", 0, 0);

    // that's all folks
    printf("\nkthxbai!\n\n");
    return 0;
}
Пример #10
0
void select_file(char result[13])
{
    static int page = 0; // Remember selections while the program runs
    static int index = 0;
    int maxindex = 0;
    
    bool rerender = true;
    
    for(;;)
    {
        if (get_keys(BUTTON1) && index >= 0)
        {
            // File selected, get the name and return
            if (get_name(result, page, index))
                return;
            else
                rerender = true; // Couldn't find file, maybe fs has changed?
        }
        
        if (get_keys(BUTTON2))
        {
            // Refresh
            //f_flush(&fatfs);
            rerender = true;
        }
        
        if (get_keys(BUTTON4))
        {
            show_msgbox("About PAWN_APP",
                        "Pawn scripting language for DSO Quad\n"
                        "(C) 2012 Petteri Aimonen <*****@*****.**>\n"
                        "\n"
                        "Built " __DATE__ " at " __TIME__ "\n"
                        "Git id " COMMITID "\n"
                        "GCC version " __VERSION__
            );
            rerender = true;
        }
        
        if (peek_keys(SCROLL1_LEFT | SCROLL1_RIGHT | SCROLL2_LEFT | SCROLL2_RIGHT))
        {
            // Clear old cursor
            show_cursor(index, 0);
            
            // Update index
            if (get_keys(SCROLL1_LEFT)) index -= 4;
            if (get_keys(SCROLL1_RIGHT)) index += 4;
            if (get_keys(SCROLL2_LEFT)) index -= 1;
            if (get_keys(SCROLL2_RIGHT)) index += 1;
            
            if (index < 0)
            {
                if (page > 0)
                {
                    page--;
                    render_screen(page, &maxindex);
                    index += 12;
                }
                else
                {
                    index = 0;
                }
            }
            
            if (index >= maxindex)
            {
                if (maxindex > ICONS_ON_SCREEN)
                {
                    page++;
                    index -= 12;
                    rerender = true;
                }
                else
                {
                    index = maxindex - 1;
                }
            }
            
            // Draw new cursor
            show_cursor(index, RGB(128, 128, 255));
        }
        
        if (rerender)
        {
            render_screen(page, &maxindex);
            show_cursor(index, RGB(128, 128, 255));
            rerender = false;
            
            if (index >= maxindex)
                index = maxindex - 1;
        }
    }
}
Пример #11
0
void c_start(unsigned int magic, struct mb_info *mbinfo)
{
	struct mod_info *mods = mbinfo->mods;
	smram_state_t old_smramc;
	struct info_section * info;
	int i;
	
	void (*realmode)() = (void (*)()) 0x4000;
	
	show_cursor();
	outputf("NetWatch loader");
	
	if (magic != MULTIBOOT_LOADER_MAGIC)
		panic("Bootloader was not multiboot compliant; cannot continue.");
	
	for (i = 0; i < mbinfo->mod_cnt; i++)
	{
		outputf("Module found:");
		outputf("  Start: %08x", (unsigned long) mods[i].mod_start);
		outputf("  Size: %08x", (unsigned long)mods[i].mod_end - (unsigned long)mods[i].mod_start);
		outputf("  Name: %s", mods[i].mod_string);
	}

	if (mbinfo->mod_cnt != 1)
		panic("Expected exactly one module; cannot continue.");
	outputf("Current SMRAMC state is: %02x", (unsigned char)smram_save_state());
	outputf("Current SMI state is: %08x", inl(0x830));	// XXX ICH2 specific
	
	smi_disable();
	
	/* Open the SMRAM aperture and load our ELF. */
	old_smramc = smram_save_state();

	if (smram_aseg_set_state(SMRAM_ASEG_OPEN) != 0)
		panic("Opening SMRAM failed; cannot load ELF.");

	load_elf(mods[0].mod_start, (unsigned long)mods[0].mod_end - (unsigned long)mods[0].mod_start);

	info = (struct info_section *)0x10000;
	if (info->signature != INFO_SIGNATURE)
	{
		smram_restore_state(old_smramc);		/* Restore so that video ram is touchable again. */
		panic("Info section signature mismatch.");
	}

	info->firstrun();
	smram_restore_state(old_smramc);
	
	outputf("New SMRAMC state is: %02x", (unsigned char)smram_save_state());

	puts("Waiting for a bit before returning to real mode...");
	for (i=0; i<0x500000; i++)
	{
		if ((i % 0x100000) == 0)
			puts(".");
		inb(0x80);
	}
	puts("\n");

	outputf("Now returning to real mode.");
	memcpy((void *)0x4000, _binary_realmode_bin_start, (int)&_binary_realmode_bin_size);
	realmode();	// goodbye!
}
Пример #12
0
int
main(int argc, char *argv[])
{
	int ch, i;
	XEvent e;
	XGenericEventCookie *cookie;

	struct mod_lookup {
		char *name;
		int mask;
	} mods[] = {
		{"shift", ShiftMask}, {"lock", LockMask},
		{"control", ControlMask}, {"mod1", Mod1Mask},
		{"mod2", Mod2Mask}, {"mod3", Mod3Mask},
		{"mod4", Mod4Mask}, {"mod5", Mod5Mask}
	};

	while ((ch = getopt(argc, argv, "di:")) != -1)
		switch (ch) {
		case 'd':
			debug = 1;
			break;
		case 'i':
			for (i = 0;
			    i < sizeof(mods) / sizeof(struct mod_lookup); i++)
				if (strcasecmp(optarg, mods[i].name) == 0)
					ignored |= mods[i].mask;

			break;
		default:
			usage();
		}

	argc -= optind;
	argv += optind;

	if (!(dpy = XOpenDisplay(NULL)))
		errx(1, "can't open display %s", XDisplayName(NULL));

#ifdef __OpenBSD__
	if (pledge("stdio", NULL) == -1)
		err(1, "pledge");
#endif

	XSetErrorHandler(swallow_error);

	if (snoop_xinput(DefaultRootWindow(dpy)) == 0) {
		if (debug)
			warn("no XInput devices found, using legacy "
			    "snooping");

		legacy = 1;
		snoop_legacy(DefaultRootWindow(dpy));
	}

	for (;;) {
		cookie = &e.xcookie;
		XNextEvent(dpy, &e);

		int etype = e.type;
		if (e.type == motion_type)
			etype = MotionNotify;
		else if (e.type == key_press_type ||
		    e.type == key_release_type)
			etype = KeyRelease;
		else if (e.type == button_press_type ||
		    e.type == button_release_type)
			etype = ButtonRelease;

		switch (etype) {
		case KeyRelease:
			if (ignored && (e.xkey.state & ignored)) {
				if (debug)
					printf("ignoring keystroke %d\n",
					    e.xkey.keycode);
				break;
			}

			hide_cursor();
			break;

		case ButtonRelease:
		case MotionNotify:
			show_cursor();
			break;

		case CreateNotify:
			if (legacy) {
				if (debug)
					printf("created new window, "
					    "snooping on it\n");

				/* not sure why snooping directly on the window
				 * doesn't work, so snoop on all windows from
				 * its parent (probably root) */
				snoop_legacy(e.xcreatewindow.parent);
			}
			break;

		case GenericEvent:
			/* xi2 raw event */
			XGetEventData(dpy, cookie);
			XIDeviceEvent *xie = (XIDeviceEvent *)cookie->data;

			switch (xie->evtype) {
			case XI_RawMotion:
			case XI_RawButtonPress:
				show_cursor();
				break;

			case XI_RawButtonRelease:
				break;

			default:
				if (debug)
					printf("unknown XI event type %d\n",
					    xie->evtype);
			}

			XFreeEventData(dpy, cookie);
			break;

		default:
			if (debug)
				printf("unknown event type %d\n", e.type);
		}
	}
}
Пример #13
0
Файл: main.c Проект: purchae/xtc
int main(int argc, char* argv[]) {

	int screen_height, screen_width;
#ifdef HAVE_DEFINE_KEY
	char key_string[10];
#endif
	char *termtype;

	config_load();
	initscr();
	if ((in_color = has_colors())) start_color();
	hide_cursor();
	raw();        /* immediate char return */
	noecho ();    /* no immediate echo */
	keypad(stdscr,TRUE);
	termtype = getenv("TERM");
	if (termtype && !strncmp(termtype,"xterm",5)) {
		/* A quick and dirty hack to get certain keys working properly in xterm */
		/* For kvt, you might need to set your terminal emulation to "Original Xterm II" */
#ifdef HAVE_DEFINE_KEY
		sprintf(key_string,"%cOH",033); define_key(key_string,KEY_HOME);
		sprintf(key_string,"%cOF",033); define_key(key_string,KEY_END);
		sprintf(key_string,"%cOj",033); define_key(key_string,'*');
		sprintf(key_string,"%cOm",033); define_key(key_string,'-');
		sprintf(key_string,"%cOM",033); define_key(key_string,KEY_ENTER);
		sprintf(key_string,"%c*k",033); define_key(key_string,'+');
#endif
	}
	
	set_special_chars(config.misc.use_ext_chars);

	getmaxyx(stdscr,screen_height,screen_width);
	if (screen_height >= 40) minifl_height = 8;
	else minifl_height = 4;
	
	
	main_window_draw();
	refresh();
	file_window_init();
	info_window_init();
	status_line_init();
	dir_window_init();

#ifdef HAVE_RESIZETERM
	(void) signal(SIGWINCH, resize_screen); /* arrange interrupts to resize */
#endif


	if (argc >= 2) dir_window_set_path(argv[1]);
	else dir_window_set_initial_path();

	
	dir_window_activate();	
	main_loop();
	
	show_cursor();
	remove_color();
	erase();
	refresh();
	noraw();
	endwin();
	return 0;
}
Пример #14
0
void cursor_inactive(WINDOW* wnd) {
    wnd->cursor_char = CURSOR_INACTIVE;
    show_cursor(wnd);
}
Пример #15
0
int
main(int argc, char *argv[])
{
    // define usage
    const char *usage = "Usage: sudoku n00b|l33t [#]\n";

    // ensure that number of arguments is as expected
    if (argc != 2 && argc != 3)
    {
        fprintf(stderr, usage);
        return 1;
    }

    // ensure that level is valid
    if (strcmp(argv[1], "debug") == 0)
        g.level = "debug";
    else if (strcmp(argv[1], "n00b") == 0)
        g.level = "n00b";
    else if (strcmp(argv[1], "l33t") == 0)
        g.level = "l33t";
    else
    {
        fprintf(stderr, usage);
        return 2;
    }

    // n00b and l33t levels have 1024 boards; debug level has 9
    int max = (strcmp(g.level, "debug") == 0) ? 9 : 1024;

    // ensure that #, if provided, is in [1, max]
    if (argc == 3)
    {
        // ensure n is integral
        char c;
        if (sscanf(argv[2], " %d %c", &g.number, &c) != 1)
        {
            fprintf(stderr, usage);
            return 3;
        }

        // ensure n is in [1, max]
        if (g.number < 1 || g.number > max)
        {
            fprintf(stderr, "That board # does not exist!\n");
            return 4;
        }

        // seed PRNG with # so that we get same sequence of boards
        srand(g.number);
    }
    else
    {
        // seed PRNG with current time so that we get any sequence of boards
        srand(time(NULL));

        // choose a random n in [1, max]
        g.number = rand() % max + 1;
    }

//////////////

    for (int m=0; m<9; m++)
    {
	for (int n=0; n<9; n++)
	    {
	    	g.badMoves[m][n]=0;
	    }
    }

    // start up ncurses
    if (!startup())
    {
        fprintf(stderr, "Error starting up ncurses!\n");
        return 5;
    }

    // register handler for SIGWINCH (SIGnal WINdow CHanged)
    signal(SIGWINCH, (void (*)(int)) handle_signal);

    // start the first game
    if (!restart_game())
    {
        shutdown();
        fprintf(stderr, "Could not load board from disk!\n");
        return 6;
    }
    redraw_all();

    // let the user play!
    int ch;
    do
    {
        // refresh the screen
        refresh();

        // get user's input
        ch = getch();
	//check won

        // capitalize input to simplify cases
        ch = toupper(ch);

        // process user's input
        switch (ch)
        {
            // start a new game
            case 'N': 
                g.number = rand() % max + 1;
                if (!restart_game())
                {
                    shutdown();
                    fprintf(stderr, "Could not load board from disk!\n");
                    return 6;
                }
                break;

            // restart current game
            case 'R': 
                if (!restart_game())
                {
                    shutdown();
                    fprintf(stderr, "Could not load board from disk!\n");
                    return 6;
                }
                break;

            // let user manually redraw screen with ctrl-L
            case CTRL('l'):
                redraw_all();
                break;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////


            //getting input as a char and logging as the ascii value

            case '9':
            movenumber=9;
            if (tempBoard[g.y][g.x]!=0)///
	     break;///
            if (check_valid(movenumber))
	     {
	        g.board[g.y][g.x]=9;
               draw_numbers();
               show_cursor();////

	        //printf ("%c" g.board[3][3]);
	        //printf ("%c" tempBoard[3][3]);
             }
             break;
                
            case '8':
 	     movenumber=8;
            if (tempBoard[g.y][g.x]!=0)///
	     break;///
	     if (check_valid(movenumber))
	     {
	     g.board[g.y][g.x]=8;
            draw_numbers();
            show_cursor();////
            }
	     break;
            
            case '7':
            movenumber=7;
            if (tempBoard[g.y][g.x]!=0)///
	     break;///
	     if (check_valid(movenumber))
	     {
            g.board[g.y][g.x]=7;
            draw_numbers();
            show_cursor();////
            }
            break;
            
            
            case '6':
 	     movenumber=6;
            if (tempBoard[g.y][g.x]!=0)///
	     break;///
check_valid(movenumber);
	     g.board[g.y][g.x]=6;
            draw_numbers();
            show_cursor();////
            
            break;
            
            case '5':
            movenumber=5;
            if (tempBoard[g.y][g.x]!=0)///
	     break;///
check_valid(movenumber);
	     g.board[g.y][g.x]=5;
            draw_numbers();
            show_cursor();////
            
            break;
            
            case '4':
	     movenumber=4;
            if (tempBoard[g.y][g.x]!=0)///
	     break;///
check_valid(movenumber);
	     g.board[g.y][g.x]=4;
            draw_numbers();
            show_cursor();////
            
            break;
            
            
            case '3':
 	     movenumber=3;
            if (tempBoard[g.y][g.x]!=0)///
	     break;///
check_valid(movenumber);
	     g.board[g.y][g.x]=3;
            draw_numbers();
            show_cursor();////
            
            break;
            
            
            case '2':
 	     movenumber=2;
            if (tempBoard[g.y][g.x]!=0)///
	     break;///
check_valid(movenumber);
	     g.board[g.y][g.x]=2;
            draw_numbers();
            show_cursor();////
            
            break;
            
            case '1':
 	     movenumber=1;
            if (tempBoard[g.y][g.x]!=0)///
	     break;///
check_valid(movenumber);
	     g.board[g.y][g.x]=1;
            draw_numbers();
            show_cursor();////
        
            break;
           
             
             case '0':
                        
             break;

		case KEY_UP:
			
              // move cursor to new place
		if (g.y<1)
		{
		g.y = 8;
		}
		else
   		g.y = g.y-1;
		
		
   		show_cursor();
		break;
		
		case KEY_DOWN:
			
              // move cursor to new place
		if (g.y>7)
		{
		g.y = 0;
		}
		else
   		g.y = g.y+1;
		
		
   		show_cursor();
		break;

		case KEY_RIGHT:
			
              // move cursor to new place
		if (g.x>7)
		{
		g.x = 0;
		}
		else
   		
		g.x = g.x+1;
		
		
   		show_cursor();
		break;

		case KEY_LEFT:
			
              // move cursor to new place
		if (g.x<1)
		{
		g.x = 8;
		}
		else
   		
		g.x = g.x-1;
		
		
   		show_cursor();
		break;

        }

        // log input (and board's state) if any was received this iteration
        if (ch != ERR)
            log_move(ch);


		if (!badBanner())
		{
		hide_banner();
		show_cursor();
		}


		////call badBanner

    }          ///////////////////////////////goes with do way above////////


    while (ch != 'Q');

    // shut down ncurses
    shutdown();

    // tidy up the screen (using ANSI escape sequences)
    printf("\033[2J");
    printf("\033[%d;%dH", 0, 0);

    // that's all folks
    printf("\nkthxbai!\n\n");
    return 0;
}
Пример #16
0
static void process_event(const SDL_Event &event)
{
	switch (event.type) {
	case SDL_MOUSEMOTION:
		if (get_game_state() == _game_in_progress)
		{
			mouse_moved(event.motion.xrel, event.motion.yrel);
		}
		break;
	case SDL_MOUSEWHEEL:
		if (get_game_state() == _game_in_progress)
		{
			bool up = (event.wheel.y > 0);
#if SDL_VERSION_ATLEAST(2,0,4)
			if (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED)
				up = !up;
#endif
			mouse_scroll(up);
		}
		break;
	case SDL_MOUSEBUTTONDOWN:
		if (get_game_state() == _game_in_progress) 
		{
			if (!get_keyboard_controller_status())
			{
				hide_cursor();
				validate_world_window();
				set_keyboard_controller_status(true);
			}
			else
			{
				SDL_Event e2;
				memset(&e2, 0, sizeof(SDL_Event));
				e2.type = SDL_KEYDOWN;
				e2.key.keysym.sym = SDLK_UNKNOWN;
				e2.key.keysym.scancode = (SDL_Scancode)(AO_SCANCODE_BASE_MOUSE_BUTTON + event.button.button - 1);
				process_game_key(e2);
			}
		}
		else
			process_screen_click(event);
		break;
	
	case SDL_JOYBUTTONDOWN:
		if (get_game_state() == _game_in_progress)
		{
			SDL_Event e2;
			memset(&e2, 0, sizeof(SDL_Event));
			e2.type = SDL_KEYDOWN;
			e2.key.keysym.sym = SDLK_UNKNOWN;
			e2.key.keysym.scancode = (SDL_Scancode)(AO_SCANCODE_BASE_JOYSTICK_BUTTON + event.button.button);
			process_game_key(e2);
			
		}
		break;
		
	case SDL_KEYDOWN:
		process_game_key(event);
		break;

	case SDL_TEXTINPUT:
		if (Console::instance()->input_active()) {
		    Console::instance()->textEvent(event);
		}
		break;
		
	case SDL_QUIT:
		set_game_state(_quit_game);
		break;

	case SDL_WINDOWEVENT:
		switch (event.window.event) {
			case SDL_WINDOWEVENT_FOCUS_LOST:
				if (get_game_state() == _game_in_progress && get_keyboard_controller_status() && !Movie::instance()->IsRecording()) {
					darken_world_window();
					set_keyboard_controller_status(false);
					show_cursor();
				}
				break;
			case SDL_WINDOWEVENT_EXPOSED:
#if !defined(__APPLE__) && !defined(__MACH__) // double buffering :)
#ifdef HAVE_OPENGL
				if (MainScreenIsOpenGL())
					MainScreenSwap();
				else
#endif
					update_game_window();
#endif
				break;
		}
		break;
	}
	
}
Пример #17
0
int term::write (unicode_char* buf, int count)
{
  unicode_char c;
  int start;
  int end;
  int i;

  video::screen.hide_mouse ();

  show ();

  start = 0;
  end = 0;

  while (end < count)
    {
      i = start;
      end = count;

      if (_param_num == -2) // not inside an escape sequence
        {
          while (i < end)
            {
              c = buf[i++];
              if (c==0x08 || c==0x0a || c==0x0d || c==0x1b) // special char?
                {
                  i--; // only process characters before the special character
                  break;
                }
            }
        }

      if (i > start)
        end = i; // stop drawing characters at the first special one
      else
        {
          while (i < end)
            {
              int op = -999; // noop
              int arg = 0;
              int pn = _param_num;

              c = buf[i++];

              switch (pn)
                {
                case -2:
                  if (c == 0x08) // backspace character?
                    {
                      op = -1; // move cursor horizontally
                      arg = -1; // one column left
                    }
                  else if (c == 0x0a) // linefeed character?
                    {
                      hide_cursor ();
                      _cursor_column = 0;
                      if (_cursor_row == _nb_rows-1) // on last row?
                        scroll_up ();
                      else
                        {
                          op = 0; // move cursor vertically
                          arg = 1; // one row down
                        }
                    }
                  else if (c == 0x0d) // carriage return character?
                    {
                      op = _cursor_row+1; // move cursor on same row
                      arg = 1; // to leftmost column
                    }
                  else if (c == 0x1b) // ESC character?
                    _param_num = -1;
                  else
                    end = i-1; // special character processing is done
                  break;

                case -1:
                  if (c == '[')
                    {
                      _param_num = 0;
                      _param[0] = 0;
                    }
                  else
                    _param_num = -2;
                  break;

                default:
                  if (c >= '0' && c <= '9')
                    {
                      int x = c - '0';
                      int p = _param[pn];
                      if (p < 1000)
                        _param[pn] = p*10 + x;
                    }
                  else if (c == ';')
                    {
                      pn++;
                      if (pn < max_nb_params)
                        {
                          _param_num = pn;
                          _param[pn] = 0;
                        }
                    }
                  else
                    {
                      _param_num = -2;

                      if (c == 'A')
                        {
                          op = 0; // move cursor vertically
                          arg = -_param[0];
                          if (arg >= 0) arg = -1;
                        }
                      else if (c == 'B')
                        {
                          op = 0; // move cursor vertically
                          arg = _param[0];
                          if (arg <= 0) arg = 1;
                        }
                      else if (c == 'C')
                        {
                          op = -1; // move cursor horizontally
                          arg = _param[0];
                          if (arg <= 0) arg = 1;
                        }
                      else if (c == 'D')
                        {
                          op = -1; // move cursor horizontally
                          arg = -_param[0];
                          if (arg >= 0) arg = -1;
                        }
                      else if (c == 'H' || c == 'f')
                        {
                          op = _param[0]; // move cursor, op = row
                          arg = _param[1]; // arg = column
                          if (op <= 0) op = 1;
                          if (pn < 1 || arg <= 0) arg = 1;
                        }
                      else if (c == 'J')
                        {
                          op = -2; // clear characters
                          arg = _param[0];
                          if (arg <= 0) arg = 0;
                        }
                      else if (c == 'K')
                        {
                          op = -3; // clear characters
                          arg = _param[0];
                          if (arg <= 0) arg = 0;
                        }
                      else if (c == 'm')
                        {
                          int j;
                          op = -4; // set attributes
                          for (j=0; j<=pn; j++)
                            {
                              int x = _param[j];
                              if (x <= 0)
                                {
                                  _bold = FALSE;
                                  _underline = FALSE;
                                  _reverse = FALSE;
                                  _fg = normal_foreground;
                                  _bg = normal_background;
                                }
                              else if (x == 1)
                                _bold = TRUE;
                              else if (x == 4)
                                _underline = TRUE;
                              else if (x == 7)
                                _reverse = TRUE;
                              else if (x >= 30 && x <= 37)
                                _fg = x-30;
                              else if (x >= 40 && x <= 47)
                                _bg = x-40;
                            }
                        }
                    }
                }

              // execute appropriate operation as indicated by "op" and "arg"

              if (op != -999) // not noop?
                {
                  if (op >= -1) // move cursor?
                    {
                      hide_cursor ();

                      if (op <= 0)
                        {
                          if (op == 0)
                            _cursor_row += arg;
                          else
                            _cursor_column += arg;
                        }
                      else
                        {
                          _cursor_row = op-1;
                          _cursor_column = arg-1;
                        }

                      if (_cursor_row < 0)
                        _cursor_row = 0;
                      else if (_cursor_row >= _nb_rows)
                        _cursor_row = _nb_rows-1;

                      if (_cursor_column < 0)
                        _cursor_column = 0;
                      else if (_cursor_column >= _nb_columns)
                        _cursor_column = _nb_columns-1;
                    }
                  else if (op >= -3) // clear characters
                    {
                      if (arg <= 2)
                        {
                          int sx;
                          int sy;
                          int ex;
                          int ey;
                          int csx;
                          int csy;
                          int cex;
                          int cey;
                          pattern* background;

                          color_to_pattern (normal_background, background);

                          char_coord_to_screen_coord
                            (0, 0, sx, sy, cex, cey);

                          char_coord_to_screen_coord
                            (_nb_columns-1, _nb_rows-1, csx, csy, ex, ey);

                          char_coord_to_screen_coord
                            (_cursor_column, _cursor_row, csx, csy, cex, cey);

                          if (arg != 1)
                            hide_cursor ();

                          if (op == -2 && arg != 0)
                            video::screen.fill_rect
                              (sx, sy, ex, csy, background);

                          video::screen.fill_rect
                            ((arg == 0) ? csx : sx,
                             csy,
                             (arg == 1) ? csx : ex,
                             cey,
                             background);

                          if (op == -2 && arg != 1)
                            video::screen.fill_rect
                              (sx, cey, ex, ey, background);
                        }
                    }
                  else if (op == -4) // set attributes
                    {
                      // note: attributes are handled when characters
                      // are displayed
                    }
                }
            }

          start = end;

          // All escape sequence and special character processing is
          // done.
        }

      while (start < end)
        {
          int sx;
          int sy;
          int ex;
          int ey;
          int fg;
          int bg;
          pattern* foreground;
          pattern* background;
          int n = end - start;

          if (n > _nb_columns - _cursor_column) // one line at a time
            n = _nb_columns - _cursor_column;

          if (_reverse)
            {
              fg = _bg;
              bg = _fg;
            }
          else
            {
              fg = _fg;
              bg = _bg;
            }

          char_coord_to_screen_coord
            (_cursor_column, _cursor_row, sx, sy, ex, ey);

          color_to_pattern (fg, foreground);
          color_to_pattern (bg, background);

          hide_cursor ();

          _fn->draw_text
            (&video::screen, sx, sy, buf+start, n, foreground, background);

          start += n;

          _cursor_column += n;

          if (_cursor_column >= _nb_columns)
            {
              _cursor_column = 0;
              _cursor_row++;
              if (_cursor_row >= _nb_rows)
                {
                  scroll_up ();
                  _cursor_row = _nb_rows-1;
                }
            }
        }

      end = start;
    }

  if (!_cursor_visible)
    show_cursor ();

  video::screen.show_mouse ();

  return end;
}