/**
* @brief (Only for Windows) Sets the Console window to full screen
* @param [out] CharAmount how many chars fits in screen (vertically and horizontally)
*/
void SetConsoleWindowFullScreen(SIZES *CharAmount) {
    HANDLE outcon;
    COORD consize;
    SMALL_RECT Rect; /* Rectangle STRUCT for setting Window Size */
#ifndef BASIGMINGW
    HWND consoleHWND;
    RECT r;
#endif /* BASIGMINGW */
    outcon = GetStdHandle(STD_OUTPUT_HANDLE);    /* Get Console Window Handle */
    /* Get console max rows number and max columns number (number of chars fit in window) */
    consize=GetLargestConsoleWindowSize(outcon);
    /* -1 and -2 adjustments to fit in screen perfectly */
    CharAmount->Y = consize.Y-1;
    CharAmount->X = consize.X-2;

    SetConsoleScreenBufferSize(outcon, consize); /* Set Buffer Size */

    Rect.Top = 0;
    Rect.Left = 0;
    /* BufferSize-1 to fit perfectly */
    Rect.Bottom = consize.Y - 1;
    Rect.Right = consize.X - 1;

    SetConsoleWindowInfo(outcon, TRUE, &Rect);   /* Set Window Size */

#ifndef BASIGMINGW
    consoleHWND = GetConsoleWindow(); /* Get Console Window exHandle */

    GetWindowRect(consoleHWND, &r);   /* Get the console's current dimensions (in pixels) */
    /* Move Window to (0;0) position, size: Console Size in pixels */
    MoveWindow(consoleHWND, 0, 0, r.right, r.bottom, TRUE);

    /*    ShowWindow(consoleHWND,SW_MAXIMIZE); */
#endif /* BASIGMINGW */
}
Exemple #2
0
COORD MyGetLargestConsoleWindowSize(HANDLE hConsoleOutput)
{
	// Fails in Wine
	COORD crMax = GetLargestConsoleWindowSize(hConsoleOutput);
	DWORD dwErr = (crMax.X && crMax.Y) ? 0 : GetLastError();
	UNREFERENCED_PARAMETER(dwErr);

	// Wine BUG
	//if (!crMax.X || !crMax.Y)
	if ((crMax.X == 80 && crMax.Y == 24) && IsWine())
	{
		crMax.X = 999;
		crMax.Y = 999;
	}
	#ifdef _DEBUG
	else if (IsWin10())
	{
		CONSOLE_SCREEN_BUFFER_INFO csbi = {};
		GetConsoleScreenBufferInfo(hConsoleOutput, &csbi);

		// Windows 10 Preview had a new bug in GetLargestConsoleWindowSize
		_ASSERTE((crMax.X > (csbi.srWindow.Right-csbi.srWindow.Left+1)) && (crMax.Y > (csbi.srWindow.Bottom-csbi.srWindow.Top+1)));
		//crMax.X = max(crMax.X,555);
		//crMax.Y = max(crMax.Y,555);
	}
	#endif

	return crMax;
}
Exemple #3
0
void SetConsoleSize(HANDLE hConsole, SHORT xSize, SHORT ySize)
{
    CONSOLE_SCREEN_BUFFER_INFO csbi; /* hold current console buffer info */
    BOOL bSuccess;
    SMALL_RECT srWindowRect; /* hold the new console size */
    COORD coordScreen;

    bSuccess = GetConsoleScreenBufferInfo(hConsole, &csbi);
    /* get the largest size we can size the console window to */
    coordScreen = GetLargestConsoleWindowSize(hConsole);
    /* define the new console window size and scroll position */
    srWindowRect.Right = (SHORT) (min(xSize, coordScreen.X) - 1);
    srWindowRect.Bottom = (SHORT) (min(ySize, coordScreen.Y) - 1);
    srWindowRect.Left = srWindowRect.Top = (SHORT) 0;
    /* define the new console buffer size */
    coordScreen.X = xSize;
    coordScreen.Y = ySize;
    /* if the current buffer is larger than what we want, resize the */
    /* console window first, then the buffer */
    if ((DWORD) csbi.dwSize.X * csbi.dwSize.Y > (DWORD) xSize * ySize)
    {
        bSuccess = SetConsoleWindowInfo(hConsole, TRUE, &srWindowRect);
        bSuccess = SetConsoleScreenBufferSize(hConsole, coordScreen);
    }
    /* if the current buffer is smaller than what we want, resize the */
    /* buffer first, then the console window */
    if ((DWORD) csbi.dwSize.X * csbi.dwSize.Y < (DWORD) xSize * ySize)
    {
        bSuccess = SetConsoleScreenBufferSize(hConsole, coordScreen);
        bSuccess = SetConsoleWindowInfo(hConsole, TRUE, &srWindowRect);
    }
    /* if the current buffer *is* the size we want, don't do anything! */
    return;
}
Exemple #4
0
void THardwareInfo::setScreenMode( ushort mode )
{
    COORD newSize = { 80, 25 };
    SMALL_RECT rect = { 0, 0, 79, 24 };

    if( mode & TDisplay::smFont8x8 )
        {
        newSize.Y = 50;
        rect.Bottom = 49;
        }

#if LIB_PLATFORM != LIB_PLATFORM_DPMI32
    COORD maxSize = GetLargestConsoleWindowSize( consoleHandle[cnOutput] );
    if( newSize.Y > maxSize.Y )
    {
        newSize.Y = maxSize.Y;
        rect.Bottom = newSize.Y-1;
    }
#endif

    if( mode & TDisplay::smFont8x8 )
        {
        SetConsoleScreenBufferSize( consoleHandle[cnOutput], newSize );
        SetConsoleWindowInfo( consoleHandle[cnOutput], True, &rect );
        }
    else
        {
        SetConsoleWindowInfo( consoleHandle[cnOutput], True, &rect );
        SetConsoleScreenBufferSize( consoleHandle[cnOutput], newSize );
        }

    GetConsoleScreenBufferInfo( consoleHandle[cnOutput], &sbInfo );
}
Exemple #5
0
void fb_ConsoleGetMaxWindowSize( int *cols, int *rows )
{
    COORD max = GetLargestConsoleWindowSize( __fb_out_handle );
    if( cols != NULL )
        *cols = (max.X==0 ? FB_SCRN_DEFAULT_WIDTH : max.X);
    if( rows != NULL )
        *rows = (max.Y==0 ? FB_SCRN_DEFAULT_HEIGHT : max.Y);
}
int main(){
  string loja, fichClients, fichProdutos, fichTransacoes;

  //tratamento da janela
  HWND hwnd = GetConsoleWindow();
  RECT desktop;
  const HWND hDesktop = GetDesktopWindow();
  GetWindowRect(hDesktop, &desktop);
  MoveWindow(hwnd, desktop.right * 0.2, desktop.bottom * 0.2, desktop.right * 0.6, desktop.bottom * 0.6, TRUE);
  HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
  COORD max_size = GetLargestConsoleWindowSize(screen);
  int console_x = max_size.X*desktop.right*0.6 / desktop.right - 1;
  int console_y = max_size.Y*desktop.bottom*0.6 / desktop.bottom - 1;
  if (console_x < 56)
  {
	  console_x = max_size.X*desktop.right*0.9 / desktop.right + 3;
	  console_y = max_size.Y*desktop.bottom*0.9 / desktop.bottom - 1;
	  MoveWindow(hwnd, desktop.right * 0.025, desktop.bottom * 0.025, desktop.right * 0.95, desktop.bottom * 0.9, TRUE);
  }
  else if (console_y <= 15)
  {
	  console_y = max_size.Y*desktop.bottom*0.9 / desktop.bottom - 1;
	  MoveWindow(hwnd, desktop.right * 0.2, desktop.bottom * 0.1, desktop.right * 0.6, desktop.bottom * 0.8, TRUE);
  }


  // pede a informacoo sobre o nome da loja e os 3 ficheiros com
  // informacao de clientes, produtos e transacoes
  if(! infoInicial(loja, fichClients, fichProdutos, fichTransacoes))
  return(-1);


  //fichClients = "clientes.txt";
  //fichProdutos = "produtos.txt";
  //fichTransacoes = "transacoes.txt";

  // cria uma loja
  VendeMaisMais supermercado(loja, fichClients, fichProdutos, fichTransacoes);
  
  // atualiza vetores
  lerClientesTxt(supermercado);
  lerProdutosTxt(supermercado);
  lerTransacoesTxt(supermercado);
  supermercado.setMaxClientesId();
  unsigned int maxId;
  maxId = supermercado.getMaxClientesId();

  cout << endl << endl << "Informacao da loja '" << loja << " do supermercado Vende++:" << endl;
  cout << supermercado << endl;  // mostra estatisticas da loja

  system("pause");

  opcoesIniciais(supermercado); // menu inicial com as grandes opcoes
				// que implementam as funcioanlidades
				// disponibilizadas

  return 0;
}
Exemple #7
0
static VALUE rb_GetLargestConsoleWindowSize( VALUE self, VALUE hConsoleOutput )
{
   HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) );
   COORD size = GetLargestConsoleWindowSize( handle);
   
   VALUE ret = rb_ary_new();
   rb_ary_push( ret, UINT2NUM( size.X ) );
   rb_ary_push( ret, UINT2NUM( size.Y ) );
   return ret;
}
Exemple #8
0
JNIEXPORT jintArray JNICALL Java_com_yifanlu_Josh_Josh_GETLARGESTCONSOLEWINDOWSIZE
  (JNIEnv *env, jclass jcls, jlong pointer)
{
	HANDLE hConsole = pointerToHandle(pointer);
	COORD size = GetLargestConsoleWindowSize(hConsole);

	jintArray info = env->NewIntArray(2);
	int cInfo[2] = {size.X, size.Y};
	env->SetIntArrayRegion(info, 0, 2, (jint *)cInfo);

	return info;
}
BOOL console::SetConsoleWindowSize(const SHORT x, const SHORT y)
{
	HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);

	if (h == INVALID_HANDLE_VALUE)
		return FALSE;

	// If either dimension is greater than the largest console window we can have,
	// there is no point in attempting the change.
	{
		COORD largestSize = GetLargestConsoleWindowSize(h);
		if (x > largestSize.X)
			return FALSE;//The x dimension is too large
		if (y > largestSize.Y)
			return FALSE;//The y dimension is too large
	}

	CONSOLE_SCREEN_BUFFER_INFO bufferInfo;
	if (!GetConsoleScreenBufferInfo(h, &bufferInfo))
		return FALSE;//Unable to retrieve screen buffer info

	SMALL_RECT& winInfo = bufferInfo.srWindow;
	COORD windowSize = { winInfo.Right - winInfo.Left + 1, winInfo.Bottom - winInfo.Top + 1 };

	if (windowSize.X > x || windowSize.Y > y)
	{
		// window size needs to be adjusted before the buffer size can be reduced.
		SMALL_RECT info =
		{
			0,
			0,
			x < windowSize.X ? x - 1 : windowSize.X - 1,
			y < windowSize.Y ? y - 1 : windowSize.Y - 1
		};

		if (!SetConsoleWindowInfo(h, TRUE, &info))
			return FALSE;//Unable to resize window before resizing buffer
	}

	COORD size = { x, y };
	if (!SetConsoleScreenBufferSize(h, size))
		return FALSE;//Unable to resize screen buffer.

	SMALL_RECT info = { 0, 0, x - 1, y - 1 };
	if (!SetConsoleWindowInfo(h, TRUE, &info))
		return FALSE;//Unable to resize window after resizing buffer.

	return TRUE;
}
Exemple #10
0
int PDC_resize_screen(int nlines, int ncols)
{
    SMALL_RECT rect;
    COORD size, max;

    bool prog_resize = nlines || ncols;

    if (!prog_resize)
    {
        nlines = PDC_get_rows();
        ncols = PDC_get_columns();
    }

    if (nlines < 2 || ncols < 2)
        return ERR;

    max = GetLargestConsoleWindowSize(pdc_con_out);

    rect.Left = rect.Top = 0;
    rect.Right = ncols - 1;

    if (rect.Right > max.X)
        rect.Right = max.X;

    rect.Bottom = nlines - 1;

    if (rect.Bottom > max.Y)
        rect.Bottom = max.Y;

    size.X = rect.Right + 1;
    size.Y = rect.Bottom + 1;

    _fit_console_window(pdc_con_out, &rect);
    SetConsoleScreenBufferSize(pdc_con_out, size);

    if (prog_resize)
    {
        _fit_console_window(pdc_con_out, &rect);
        SetConsoleScreenBufferSize(pdc_con_out, size);
    }
    SetConsoleActiveScreenBuffer(pdc_con_out);

    PDC_flushinp();

    SP->resized = FALSE;
    SP->cursrow = SP->curscol = 0;

    return OK;
}
Exemple #11
0
/* 
	Have to remember where i ripped this code sometime ago.

*/
static void ResizeConsole( HANDLE hConsole, SHORT xSize, SHORT ySize ) {   
	CONSOLE_SCREEN_BUFFER_INFO csbi; // Hold Current Console Buffer Info 
	BOOL bSuccess;   
	SMALL_RECT srWindowRect;         // Hold the New Console Size 
	COORD coordScreen;    
	
	bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
	
	// Get the Largest Size we can size the Console Window to 
	coordScreen = GetLargestConsoleWindowSize( hConsole );
	
	// Define the New Console Window Size and Scroll Position 
	srWindowRect.Right  = (SHORT)(min(xSize, coordScreen.X) - 1);
	srWindowRect.Bottom = (SHORT)(min(ySize, coordScreen.Y) - 1);
	srWindowRect.Left   = srWindowRect.Top = (SHORT)0;
	
	// Define the New Console Buffer Size    
	coordScreen.X = xSize;
	coordScreen.Y = ySize;
	
	// If the Current Buffer is Larger than what we want, Resize the 
	// Console Window First, then the Buffer 
	if( (DWORD)csbi.dwSize.X * csbi.dwSize.Y > (DWORD) xSize * ySize)
	{
		bSuccess = SetConsoleWindowInfo( hConsole, TRUE, &srWindowRect );
		bSuccess = SetConsoleScreenBufferSize( hConsole, coordScreen );
	}
	
	// If the Current Buffer is Smaller than what we want, Resize the 
	// Buffer First, then the Console Window 
	if( (DWORD)csbi.dwSize.X * csbi.dwSize.Y < (DWORD) xSize * ySize )
	{
		bSuccess = SetConsoleScreenBufferSize( hConsole, coordScreen );
		bSuccess = SetConsoleWindowInfo( hConsole, TRUE, &srWindowRect );
	}
	
	// If the Current Buffer *is* the Size we want, Don't do anything! 
	return;
   }
Exemple #12
0
void setup_console_window()
{
    auto hOut = GetStdHandle(STD_OUTPUT_HANDLE);

    // Disable close button in console to avoid shutdown without cleanup.
    EnableMenuItem(GetSystemMenu(GetConsoleWindow(), FALSE), SC_CLOSE , MF_GRAYED);
    DrawMenuBar(GetConsoleWindow());
    //SetConsoleCtrlHandler(HandlerRoutine, true);

    // Configure console size and position.
    auto coord = GetLargestConsoleWindowSize(hOut);
    coord.X /= 2;

    SetConsoleScreenBufferSize(hOut, coord);

    SMALL_RECT DisplayArea = {0, 0, 0, 0};
    DisplayArea.Right = coord.X-1;
    DisplayArea.Bottom = (coord.Y-1)/2;
    SetConsoleWindowInfo(hOut, TRUE, &DisplayArea);

    change_icon(::LoadIcon(GetModuleHandle(0), MAKEINTRESOURCE(101)));

    // Set console title.
    std::wstringstream str;
    str << "CasparCG Server " << caspar::env::version();
#ifdef COMPILE_RELEASE
    str << " Release";
#elif  COMPILE_PROFILE
    str << " Profile";
#elif  COMPILE_DEVELOP
    str << " Develop";
#elif  COMPILE_DEBUG
    str << " Debug";
#endif
    SetConsoleTitle(str.str().c_str());
}
Exemple #13
0
BOOL SetConsoleCXCY(HANDLE hStdout, int cx, int cy)
{
	CONSOLE_SCREEN_BUFFER_INFO	info;
	COORD						coordMax;
 
	coordMax = GetLargestConsoleWindowSize(hStdout);

	if (cy > coordMax.Y)
		cy = coordMax.Y;

	if (cx > coordMax.X)
		cx = coordMax.X;
 
	if (!GetConsoleScreenBufferInfo(hStdout, &info))
		return false;
 
// height
    info.srWindow.Left = 0;         
    info.srWindow.Right = info.dwSize.X - 1;                
    info.srWindow.Top = 0;
    info.srWindow.Bottom = cy - 1;          
 
	if (cy < info.dwSize.Y)
	{
		if (!SetConsoleWindowInfo(hStdout, true, &info.srWindow))
			return false;
 
		info.dwSize.Y = cy;
 
		if (!SetConsoleScreenBufferSize(hStdout, info.dwSize))
			return false;
    }
    else if (cy > info.dwSize.Y)
    {
		info.dwSize.Y = cy;
 
		if (!SetConsoleScreenBufferSize(hStdout, info.dwSize))
			return false;
 
		if (!SetConsoleWindowInfo(hStdout, true, &info.srWindow))
			return false;
    }
 
	if (!GetConsoleScreenBufferInfo(hStdout, &info))
		return false;
 
// width
	info.srWindow.Left = 0;         
	info.srWindow.Right = cx - 1;
	info.srWindow.Top = 0;
	info.srWindow.Bottom = info.dwSize.Y - 1;               
 
	if (cx < info.dwSize.X)
	{
		if (!SetConsoleWindowInfo(hStdout, true, &info.srWindow))
			return false;
 
		info.dwSize.X = cx;
    
		if (!SetConsoleScreenBufferSize(hStdout, info.dwSize))
			return false;
	}
	else if (cx > info.dwSize.X)
	{
		info.dwSize.X = cx;
 
		if (!SetConsoleScreenBufferSize(hStdout, info.dwSize))
			return false;
 
		if (!SetConsoleWindowInfo(hStdout, true, &info.srWindow))
			return false;
	}
 
	return true;
}
Exemple #14
0
/**
 * This function initializes libcaca vout method.
 */
static int Open(vlc_object_t *object)
{
    vout_display_t *vd = (vout_display_t *)object;
    vout_display_sys_t *sys;

    if (vout_display_IsWindowed(vd))
        return VLC_EGENERIC;
#if !defined(__APPLE__) && !defined(_WIN32)
# ifndef X_DISPLAY_MISSING
    if (!vlc_xlib_init(object))
        return VLC_EGENERIC;
# endif
#endif

#if defined(_WIN32)
    CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
    SMALL_RECT rect;
    COORD coord;
    HANDLE hstdout;

    if (!AllocConsole()) {
        msg_Err(vd, "cannot create console");
        return VLC_EGENERIC;
    }

    hstdout =
        CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE,
                                  FILE_SHARE_READ | FILE_SHARE_WRITE,
                                  NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
    if (!hstdout || hstdout == INVALID_HANDLE_VALUE) {
        msg_Err(vd, "cannot create screen buffer");
        FreeConsole();
        return VLC_EGENERIC;
    }

    if (!SetConsoleActiveScreenBuffer(hstdout)) {
        msg_Err(vd, "cannot set active screen buffer");
        FreeConsole();
        return VLC_EGENERIC;
    }

    coord = GetLargestConsoleWindowSize(hstdout);
    msg_Dbg(vd, "SetConsoleWindowInfo: %ix%i", coord.X, coord.Y);

    /* Force size for now */
    coord.X = 100;
    coord.Y = 40;

    if (!SetConsoleScreenBufferSize(hstdout, coord))
        msg_Warn(vd, "SetConsoleScreenBufferSize %i %i",
                  coord.X, coord.Y);

    /* Get the current screen buffer size and window position. */
    if (GetConsoleScreenBufferInfo(hstdout, &csbiInfo)) {
        rect.Top = 0; rect.Left = 0;
        rect.Right = csbiInfo.dwMaximumWindowSize.X - 1;
        rect.Bottom = csbiInfo.dwMaximumWindowSize.Y - 1;
        if (!SetConsoleWindowInfo(hstdout, TRUE, &rect))
            msg_Dbg(vd, "SetConsoleWindowInfo failed: %ix%i",
                     rect.Right, rect.Bottom);
    }
#endif

    /* Allocate structure */
    vd->sys = sys = calloc(1, sizeof(*sys));
    if (!sys)
        goto error;

    sys->cv = cucul_create_canvas(0, 0);
    if (!sys->cv) {
        msg_Err(vd, "cannot initialize libcucul");
        goto error;
    }

    const char *driver = NULL;
#ifdef __APPLE__
    // Make sure we don't try to open a window.
    driver = "ncurses";
#endif

    sys->dp = caca_create_display_with_driver(sys->cv, driver);
    if (!sys->dp) {
        msg_Err(vd, "cannot initialize libcaca");
        goto error;
    }

    if (vd->cfg->display.title)
        caca_set_display_title(sys->dp,
                               vd->cfg->display.title);
    else
        caca_set_display_title(sys->dp,
                               VOUT_TITLE "(Colour AsCii Art)");

    /* Fix format */
    video_format_t fmt = vd->fmt;
    if (fmt.i_chroma != VLC_CODEC_RGB32) {
        fmt.i_chroma = VLC_CODEC_RGB32;
        fmt.i_rmask = 0x00ff0000;
        fmt.i_gmask = 0x0000ff00;
        fmt.i_bmask = 0x000000ff;
    }

    /* TODO */
    vout_display_info_t info = vd->info;

    /* Setup vout_display now that everything is fine */
    vd->fmt = fmt;
    vd->info = info;

    vd->pool    = Pool;
    vd->prepare = Prepare;
    vd->display = PictureDisplay;
    vd->control = Control;
    vd->manage  = Manage;

    /* Fix initial state */
    vout_display_SendEventFullscreen(vd, false);
    Refresh(vd);

    return VLC_SUCCESS;

error:
    if (sys) {
        if (sys->pool)
            picture_pool_Release(sys->pool);
        if (sys->dither)
            cucul_free_dither(sys->dither);
        if (sys->dp)
            caca_free_display(sys->dp);
        if (sys->cv)
            cucul_free_canvas(sys->cv);

        free(sys);
    }
#if defined(_WIN32)
    FreeConsole();
#endif
    return VLC_EGENERIC;
}
Exemple #15
0
/*****************************************************************************
 * Create: allocates libcaca video output thread
 *****************************************************************************
 * This function initializes libcaca vout method.
 *****************************************************************************/
static int Create( vlc_object_t *p_this )
{
    vout_thread_t *p_vout = (vout_thread_t *)p_this;

#if defined( WIN32 ) && !defined( UNDER_CE )
    CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
    SMALL_RECT rect;
    COORD coord;
    HANDLE hstdout;

    if( !AllocConsole() )
    {
        msg_Err( p_vout, "cannot create console" );
        return VLC_EGENERIC;
    }

    hstdout =
        CreateConsoleScreenBuffer( GENERIC_READ | GENERIC_WRITE,
                                   FILE_SHARE_READ | FILE_SHARE_WRITE,
                                   NULL, CONSOLE_TEXTMODE_BUFFER, NULL );
    if( !hstdout || hstdout == INVALID_HANDLE_VALUE )
    {
        msg_Err( p_vout, "cannot create screen buffer" );
        FreeConsole();
        return VLC_EGENERIC;
    }

    if( !SetConsoleActiveScreenBuffer( hstdout) )
    {
        msg_Err( p_vout, "cannot set active screen buffer" );
        FreeConsole();
        return VLC_EGENERIC;
    }

    coord = GetLargestConsoleWindowSize( hstdout );
    msg_Dbg( p_vout, "SetConsoleWindowInfo: %ix%i", coord.X, coord.Y );

    /* Force size for now */
    coord.X = 100;
    coord.Y = 40;

    if( !SetConsoleScreenBufferSize( hstdout, coord ) )
        msg_Warn( p_vout, "SetConsoleScreenBufferSize %i %i",
                  coord.X, coord.Y );

    /* Get the current screen buffer size and window position. */
    if( GetConsoleScreenBufferInfo( hstdout, &csbiInfo ) )
    {
        rect.Top = 0; rect.Left = 0;
        rect.Right = csbiInfo.dwMaximumWindowSize.X - 1;
        rect.Bottom = csbiInfo.dwMaximumWindowSize.Y - 1;
        if( !SetConsoleWindowInfo( hstdout, TRUE, &rect ) )
            msg_Dbg( p_vout, "SetConsoleWindowInfo failed: %ix%i",
                     rect.Right, rect.Bottom );
    }
#endif

    /* Allocate structure */
    p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
    if( p_vout->p_sys == NULL )
    {
        msg_Err( p_vout, "out of memory" );
        return VLC_ENOMEM;
    }

    p_vout->p_sys->p_cv = cucul_create_canvas(0, 0);
    if( !p_vout->p_sys->p_cv )
    {
        msg_Err( p_vout, "cannot initialize libcucul" );
        free( p_vout->p_sys );
        return VLC_EGENERIC;
    }

    p_vout->p_sys->p_dp = caca_create_display( p_vout->p_sys->p_cv );
    if( !p_vout->p_sys->p_dp )
    {
        msg_Err( p_vout, "cannot initialize libcaca" );
        cucul_free_canvas( p_vout->p_sys->p_cv );
        free( p_vout->p_sys );
        return VLC_EGENERIC;
    }

    caca_set_display_title( p_vout->p_sys->p_dp,
                            VOUT_TITLE " - Colour AsCii Art (caca)" );

    p_vout->pf_init = Init;
    p_vout->pf_end = End;
    p_vout->pf_manage = Manage;
    p_vout->pf_render = Render;
    p_vout->pf_display = Display;

    return VLC_SUCCESS;
}
Exemple #16
0
int16_t Console::getLargestWindowWidth(void) const
{
	return GetLargestConsoleWindowSize(m_stdout).X;
}
Exemple #17
0
int16_t Console::getLargestWindowHeight(void) const
{
	return GetLargestConsoleWindowSize(m_stdout).Y;
}
Exemple #18
0
BOOL
consoleSetScreenSize (
    PSCREEN pScreen,
    ROW Rows,
    COLUMN  Cols
    )
/*++

Routine Description:

    Sets the screen size

Arguments:

    pScreen	-   Supplies pointer to screen data.
    Rows	-   Number of rows
    Cols	-   Number of columns

Return Value:

    TRUE if screen size changed successfully
    FALSE otherwise.

--*/
{

    PSCREEN_DATA		ScreenData = (PSCREEN_DATA)pScreen;
    CONSOLE_SCREEN_BUFFER_INFO	ScreenBufferInfo;
    SMALL_RECT			ScreenRect;
    COORD			ScreenSize;
    USHORT			MinRows;
    USHORT			MinCols;
    ULONG			NewBufferSize;
    BOOL			WindowSet   = FALSE;
    BOOL			Status	    = FALSE;

    //
    //	Won't attempt to resize larger than the largest window size
    //
    ScreenSize = GetLargestConsoleWindowSize( ScreenData->ScreenHandle );

    if ( (Rows > (ROW)ScreenSize.Y) || (Cols > (COLUMN)ScreenSize.X) ) {
        return FALSE;
    }

    EnterCriticalSection( &(ScreenData->CriticalSection) );

    //
    //	Obtain the current screen information.
    //
    if ( GetConsoleScreenBufferInfo( ScreenData->ScreenHandle, &ScreenBufferInfo ) ) {

        //
        //  If the desired buffer size is smaller than the current window
        //  size, we have to resize the current window first.
        //
        if ( ( Rows < (ROW)
                   (ScreenBufferInfo.srWindow.Bottom -
                ScreenBufferInfo.srWindow.Top + 1) ) ||
             ( Cols < (COLUMN)
                   (ScreenBufferInfo.srWindow.Right -
                ScreenBufferInfo.srWindow.Left + 1) ) ) {

            //
            //  Set the window to a size that will fit in the current
            //  screen buffer and that is no bigger than the size to
            //  which we want to grow the screen buffer.
            //
            MinRows = (USHORT)min( (int)Rows, (int)(ScreenBufferInfo.dwSize.Y) );
            MinCols = (USHORT)min( (int)Cols, (int)(ScreenBufferInfo.dwSize.X) );

            ScreenRect.Top  = 0;
            ScreenRect.Left = 0;
            ScreenRect.Right    = (SHORT)MinCols - (SHORT)1;
            ScreenRect.Bottom   = (SHORT)MinRows - (SHORT)1;

            WindowSet = (BOOL)SetConsoleWindowInfo( ScreenData->ScreenHandle, TRUE, &ScreenRect );

            if ( !WindowSet ) {
                //
                //  ERROR
                //
                goto Done;
            }
        }

        //
        //  Set the screen buffer size to the desired size.
        //
        ScreenSize.X = (WORD)Cols;
        ScreenSize.Y = (WORD)Rows;

        if ( !SetConsoleScreenBufferSize( ScreenData->ScreenHandle, ScreenSize ) ) {

            //
            //  ERROR
            //
            //
            //  Return the window to its original size. We ignore the return
            //  code because there is nothing we can do about it.
            //
            SetConsoleWindowInfo( ScreenData->ScreenHandle, TRUE, &(ScreenBufferInfo.srWindow) );
            goto Done;
        }

        //
        //  resize the screen buffer. Note that the contents of the screen
        //  buffer are not valid anymore. Someone else will have to update
        //  them.
        //
        NewBufferSize = Rows * Cols;

        if (ScreenData->MaxBufferSize < NewBufferSize ) {
            ScreenData->ScreenBuffer = REALLOC( ScreenData->ScreenBuffer, NewBufferSize * sizeof(CHAR_INFO));
            ScreenData->MaxBufferSize = NewBufferSize;
            ScreenData->LineInfo = REALLOC( ScreenData->LineInfo, Rows * sizeof( LINE_INFO ) );
        }

        //
        //  Set the Window Size. We know that we can grow the window to this size
        //  because we tested the size against the largest window size at the
        //  beginning of the function.
        //
        ScreenRect.Top      = 0;
        ScreenRect.Left     = 0;
        ScreenRect.Right    = (SHORT)Cols - (SHORT)1;
        ScreenRect.Bottom   = (SHORT)Rows - (SHORT)1;

        WindowSet = (BOOL)SetConsoleWindowInfo( ScreenData->ScreenHandle, TRUE, &ScreenRect );

        if ( !WindowSet ) {
            //
            //  We could not resize the window. We will leave the
            //  resized screen buffer.
            //
            //  ERROR
            //
            InitLineInfo( ScreenData );
            goto Done;
        }

        //
        //  Update the screen size
        //
        ScreenData->ScreenInformation.NumberOfRows = Rows;
        ScreenData->ScreenInformation.NumberOfCols = Cols;

        InitLineInfo( ScreenData );

        //
        //  Done
        //
        Status = TRUE;

    } else {

        //
        //  ERROR
        //
        Status = FALSE;
    }

Done:
    //
    //	Invalidate the entire screen buffer
    //
    ScreenData->FirstRow    = ScreenData->ScreenInformation.NumberOfRows;
    ScreenData->LastRow     = 0;

    LeaveCriticalSection( &(ScreenData->CriticalSection) );
    return Status;

}
Exemple #19
0
int __cdecl wmain(int argc, wchar_t *wargv[])
{
	int ret = 0;

	// Global URL cache to not download anything twice
	json_t *url_cache = json_object();
	// Repository ID cache to prioritize the most local repository if more
	// than one repository with the same name is discovered in the network
	json_t *id_cache = json_object();

	json_t *repo_list = NULL;

	const char *start_repo = "http://thcrap.nmlgc.net/repos/nmlgc/";

	json_t *sel_stack = NULL;
	json_t *new_cfg = json_pack("{s[]}", "patches");

	size_t cur_dir_len = GetCurrentDirectory(0, NULL) + 1;
	VLA(char, cur_dir, cur_dir_len);
	json_t *games = NULL;

	const char *run_cfg_fn = NULL;
	const char *run_cfg_fn_js = NULL;
	char *run_cfg_str = NULL;

	json_t *args = json_array_from_wchar_array(argc, wargv);

	wine_flag = GetProcAddress(
		GetModuleHandleA("kernel32.dll"), "wine_get_unix_file_name"
	) != 0;

	strings_mod_init();
	log_init(1);

	// Necessary to correctly process *any* input of non-ASCII characters
	// in the console subsystem
	w32u8_set_fallback_codepage(GetOEMCP());

	GetCurrentDirectory(cur_dir_len, cur_dir);
	PathAddBackslashA(cur_dir);
	str_slash_normalize(cur_dir);

	// Maximize the height of the console window... unless we're running under
	// Wine, where this 1) doesn't work and 2) messes up the console buffer
	if(!wine_flag) {
		CONSOLE_SCREEN_BUFFER_INFO sbi = {0};
		HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
		COORD largest = GetLargestConsoleWindowSize(console);
		HWND console_wnd = GetConsoleWindow();
		RECT console_rect;

		GetWindowRect(console_wnd, &console_rect);
		SetWindowPos(console_wnd, NULL, console_rect.left, 0, 0, 0, SWP_NOSIZE);
		GetConsoleScreenBufferInfo(console, &sbi);
		sbi.srWindow.Bottom = largest.Y - 4;
		SetConsoleWindowInfo(console, TRUE, &sbi.srWindow);
	}

	http_init();

	if(json_array_size(args) > 1) {
		start_repo = json_array_get_string(args, 1);
	}

	log_printf(
		"==========================================\n"
		"Touhou Community Reliant Automatic Patcher - Patch configuration tool\n"
		"==========================================\n"
		"\n"
		"\n"
		"This tool will create a new patch configuration for the\n"
		"Touhou Community Reliant Automatic Patcher.\n"
		"\n"
		"\n"
		"The configuration process has two steps:\n"
		"\n"
		"\t\t1. Selecting patches\n"
		"\t\t2. Download game-independent data\n"
		"\t\t3. Locating game installations\n"
		"\t\t4. Download game-specific data\n"
		"\n"
		"\n"
		"\n"
		"Patch repository discovery will start at\n"
		"\n"
		"\t%s\n"
		"\n"
		"You can specify a different URL as a command-line parameter.\n"
		"Additionally, all patches from previously discovered repositories, stored in\n"
		"subdirectories of the current directory, will be available for selection.\n"
		"\n"
		"\n",
		start_repo
	);
	pause();

	if(RepoDiscoverAtURL(start_repo, id_cache, url_cache)) {
		goto end;
	}
	if(RepoDiscoverFromLocal(id_cache, url_cache)) {
		goto end;
	}
	repo_list = RepoLoad();
	if(!json_object_size(repo_list)) {
		log_printf("No patch repositories available...\n");
		pause();
		goto end;
	}
	sel_stack = SelectPatchStack(repo_list);
	if(json_array_size(sel_stack)) {
		json_t *new_cfg_patches = json_object_get(new_cfg, "patches");
		size_t i;
		json_t *sel;

		log_printf("Downloading game-independent data...\n");
		stack_update(update_filter_global, NULL);

		/// Build the new run configuration
		json_array_foreach(sel_stack, i, sel) {
			json_array_append_new(new_cfg_patches, patch_build(sel));
		}
	}
Exemple #20
0
int main(int argc, char *argv[])
{
    /* gui structures */
    struct gui_state       gstate;
    struct gui_dialog_info dialog;
    struct gui_dialog_item dialog_msg;

    /* temps */
    int c;
    int yn_selected;
    int res;
    int next_index;

    /* status */
    int      running;
    unsigned tick;

    /* global options */
    /*
    int server;
    */

    /* constants */
    const int check[] = {0x6E, 0x69, 0x67, 0x67, 0x61};

#ifdef USING_WINDOWS
    /* windows-only vars */
    HANDLE console_buffer;
    CONSOLE_SCREEN_BUFFER_INFO old_console_info;
    COORD console_size;
    SMALL_RECT console_window;
    LPTSTR error_string = NULL;
    DWORD error;

    /* get console handle */
    console_buffer = GetStdHandle(STD_OUTPUT_HANDLE);

    /* store old console information */
    res = GetConsoleScreenBufferInfo(console_buffer, &old_console_info);
    if (!res) {
        error = GetLastError();
        res = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, res, 0, error_string, 256, NULL);
        if (!res || error_string == NULL) {
            fprintf(stderr, "Setting console size to maximum of (%d, %d) failed, error code %d\n", console_size.X, console_size.Y, (int) error);
        } else {
            fprintf(stderr, "Setting console size to maximum of (%d, %d) failed:\n%s\n", console_size.X, console_size.Y, error_string);
        }
        return -1;
    }

    /* make console fill the screen */
    console_size = GetLargestConsoleWindowSize(console_buffer);
    console_size.X -= 2;
    console_size.Y -= 2;
    res = SetConsoleScreenBufferSize(console_buffer, console_size);
    if (!res) {
        error = GetLastError();
        res = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, res, 0, error_string, 256, NULL);
        if (!res || error_string == NULL) {
            fprintf(stderr, "Setting console size to maximum of (%d, %d) failed, error code %d\n", console_size.X, console_size.Y, (int) error);
        } else {
            fprintf(stderr, "Setting console size to maximum of (%d, %d) failed:\n%s\n", console_size.X, console_size.Y, error_string);
        }
        return -1;
    }
    console_window.Left = 0;
    console_window.Top = 0;
    console_window.Right = console_size.X - 1;
    console_window.Bottom = console_size.Y - 1;
    res = SetConsoleWindowInfo(console_buffer, TRUE, &console_window);
    if (!res) {
        error = GetLastError();
        res = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, res, 0, error_string, 256, NULL);
        if (!res || error_string == NULL) {
            fprintf(stderr, "Setting console size to maximum of (%d, %d) failed, error code %d\n", console_size.X, console_size.Y, (int) error);
        } else {
            fprintf(stderr, "Setting console size to maximum of (%d, %d) failed:\n%s\n", console_size.X, console_size.Y, error_string);
        }
        return -1;
    }
#endif

    /* process args (none supported currently) */
    if (argc > 1) {
        fprintf(stderr, "unrecognised argument(s)\n");
        return -1;
    }

    /* init curses */
    initscr();

    /* give warning dialog if colours are not supported */
    if (has_colors() == FALSE) {

        /* set up message */
        dialog_msg.type = GUI_DIALOG_ITEM_MESSAGE;
        dialog_msg.str = "Your terminal doesn't support colours. This will look REALLY weird. Continue? (y/n)";

        /* set up dialog info */
        dialog.items = &dialog_msg;
        dialog.num_items = 1;
        dialog.title = "No colours!";
        dialog.centered = 1;
        dialog.autosize = 1;

        /* render dialog */
        gui_render_dialog(&dialog, -1);

        /* ask for y/n */
        yn_selected = 0;
        while (!yn_selected) {
            c = wgetch(stdscr);

            /* continue as normal if 'y' hit */
            if (c == 'y' || c == 'Y') {
                yn_selected = 1;

                /* quit program if 'n' hit */
            } else if (c == 'n' || c == 'N') {
                erase();
                refresh();
                endwin();
                return 0;
            }
        }

        /* if colours are supported, init them */
    } else {
        start_color();
        colours_init();
    }

    /* non-blocking read */
    timeout(0);

    /* F-key support */
    keypad(stdscr, TRUE);

    /* no line buffering */
    raw();

    /* detect return key */
    nonl();

    /* non-echoing getch */
    noecho();

    /* fill GUI state with default attributes */
    gui_default_state(&gstate);

    /* main loop */
    running = 1;
    tick = 0;
    next_index = 0;
    while (running) {

        ++tick;

        /* push GUI to screen */
        res = gui_render(&gstate);
        if (res != 0) {
            endwin();
            fprintf(stderr, "tick %d:\ngui_render failed\n", tick);
            return -1;
        }

        /* receive input (ERR received if none) */
        c = wgetch(stdscr);

        /* none received, back to top */
        if (c == ERR) {
            continue;
        }

        /* key combination check algorithm (no effect yet) */
        if (c == check[next_index]) {
            ++next_index;
            if (next_index == 5) {
                next_index = 0;
            }
        } else {
            next_index = 0;
        }

        switch (c) {

        case 'q':
            /* send to quit confirmation, if already there then quit */
            if (gstate.focus != GUI_FOCUS_QUIT_CONFIRM) {
                gstate.focus = GUI_FOCUS_QUIT_CONFIRM;
            } else {
                running = 0;
            }
            break;

        /* curses seems to use \r instead of KEY_ENTER */
        case '\r':
            switch (gstate.focus) {
            case GUI_FOCUS_MAIN_MENU:
                if (gstate.selected_item >= gstate.main_menu_dialog.num_items) {
                    endwin();
                    fprintf(stderr, "Index of selected dialog item (%d) out of range (main menu), max is %d\n", gstate.selected_item, gstate.main_menu_dialog.num_items);
                    return -1;
                }
                gstate.main_menu_dialog.items[gstate.selected_item].callback(&gstate, NULL);
                break;

            case GUI_FOCUS_QUIT_CONFIRM:
                running = 0;

            default:
                break;
            }
            break;

        case KEY_UP:
            switch (gstate.focus) {
            case GUI_FOCUS_MAIN_MENU:
                --gstate.selected_item;
                if (gstate.selected_item < 0) {
                    gstate.selected_item = gstate.main_menu_dialog.num_items - 1;
                }

            default:
                break;
            }
            break;

        case KEY_DOWN:
            switch (gstate.focus) {
            case GUI_FOCUS_MAIN_MENU:
                ++gstate.selected_item;
                if (gstate.selected_item >= gstate.main_menu_dialog.num_items) {
                    gstate.selected_item = 0;
                }

            default:
                break;
            }

        default:
            break;
        }
    }

    /* show end splash, quit curses and stop normally */
    gui_render_endscreen();
    timeout(-1);
    wgetch(stdscr);
    erase();
    refresh();
    endwin();

#ifdef USING_WINDOWS
    /* attempt to restore previous console size + position */
    console_window = old_console_info.srWindow;
    SetConsoleWindowInfo(console_buffer, TRUE, &console_window);
    console_size = old_console_info.dwSize;
    SetConsoleScreenBufferSize(console_buffer, console_size);

    /* clear */
    system("cls");
#endif

    return 0;
}