Changeset 632


Ignore:
Timestamp:
Mar 16, 2006, 5:59:57 PM (14 years ago)
Author:
Sam Hocevar
Message:
  • Fix resizing of the Win32 console. It now adapts to the requested size.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca/driver_win32.c

    r612 r632  
    2525
    2626#include <stdlib.h>
     27#include <stdio.h>
    2728
    2829#include "caca.h"
     
    7778struct driver_private
    7879{
    79     HANDLE hin, hout;
    80     HANDLE front, back;
     80    HANDLE hin, hout, screen;
    8181    CHAR_INFO *buffer;
    8282    CONSOLE_CURSOR_INFO cci;
     
    8686{
    8787    CONSOLE_SCREEN_BUFFER_INFO csbi;
     88    SMALL_RECT rect;
    8889    COORD size;
    8990
     
    106107    SetConsoleMode(kk->drv.p->hout, ENABLE_MOUSE_INPUT);
    107108
    108     kk->drv.p->front =
     109    kk->drv.p->screen =
    109110        CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE,
    110111                                  0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
    111     if(!kk->drv.p->front || kk->drv.p->front == INVALID_HANDLE_VALUE)
     112    if(!kk->drv.p->screen || kk->drv.p->screen == INVALID_HANDLE_VALUE)
    112113        return -1;
    113114
    114     kk->drv.p->back =
    115         CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE,
    116                                   0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
    117     if(!kk->drv.p->back || kk->drv.p->back == INVALID_HANDLE_VALUE)
     115    /* Set the new console size */
     116    size.X = kk->qq->width;
     117    size.Y = kk->qq->height;
     118    SetConsoleScreenBufferSize(kk->drv.p->screen, size);
     119
     120    rect.Left = rect.Top = 0;
     121    rect.Right = kk->qq->width - 1;
     122    rect.Bottom = kk->qq->height - 1;
     123    SetConsoleWindowInfo(kk->drv.p->screen, TRUE, &rect);
     124
     125    /* Report our new size to libcucul */
     126    if(!GetConsoleScreenBufferInfo(kk->drv.p->screen, &csbi))
    118127        return -1;
    119128
    120     if(!GetConsoleScreenBufferInfo(kk->drv.p->hout, &csbi))
    121         return -1;
    122 
    123     /* Sample code to get the biggest possible window */
    124     //size = GetLargestConsoleWindowSize(kk->drv.p->hout);
    125129    _cucul_set_size(kk->qq, csbi.srWindow.Right - csbi.srWindow.Left + 1,
    126130                            csbi.srWindow.Bottom - csbi.srWindow.Top + 1);
    127     size.X = kk->qq->width;
    128     size.Y = kk->qq->height;
    129     SetConsoleScreenBufferSize(kk->drv.p->front, size);
    130     SetConsoleScreenBufferSize(kk->drv.p->back, size);
    131 
    132     SetConsoleMode(kk->drv.p->front, 0);
    133     SetConsoleMode(kk->drv.p->back, 0);
    134 
    135     GetConsoleCursorInfo(kk->drv.p->front, &kk->drv.p->cci);
     131
     132    SetConsoleMode(kk->drv.p->screen, 0);
     133
     134    GetConsoleCursorInfo(kk->drv.p->screen, &kk->drv.p->cci);
    136135    kk->drv.p->cci.dwSize = 0;
    137136    kk->drv.p->cci.bVisible = FALSE;
    138     SetConsoleCursorInfo(kk->drv.p->front, &kk->drv.p->cci);
    139     SetConsoleCursorInfo(kk->drv.p->back, &kk->drv.p->cci);
    140 
    141     SetConsoleActiveScreenBuffer(kk->drv.p->front);
     137    SetConsoleCursorInfo(kk->drv.p->screen, &kk->drv.p->cci);
     138
     139    SetConsoleActiveScreenBuffer(kk->drv.p->screen);
    142140
    143141    kk->drv.p->buffer = malloc(kk->qq->width * kk->qq->height
     
    152150{
    153151    SetConsoleActiveScreenBuffer(kk->drv.p->hout);
    154     CloseHandle(kk->drv.p->back);
    155     CloseHandle(kk->drv.p->front);
     152    CloseHandle(kk->drv.p->screen);
    156153
    157154    SetConsoleTextAttribute(kk->drv.p->hout, FOREGROUND_INTENSITY
     
    196193    unsigned int i;
    197194
    198     /* Render everything to our back buffer */
     195    /* Render everything to our screen buffer */
    199196    for(i = 0; i < kk->qq->width * kk->qq->height; i++)
    200197    {
     
    218215    }
    219216
    220     /* Blit the back buffer to the front buffer */
     217    /* Blit the screen buffer */
    221218    size.X = kk->qq->width;
    222219    size.Y = kk->qq->height;
     
    226223    rect.Bottom = kk->qq->height - 1;
    227224#if 0
    228     WriteConsoleOutput(kk->drv.p->front, kk->drv.p->buffer, size, pos, &rect);
     225    WriteConsoleOutput(kk->drv.p->screen, kk->drv.p->buffer, size, pos, &rect);
    229226#else
    230     WriteConsoleOutputW(kk->drv.p->front, kk->drv.p->buffer, size, pos, &rect);
     227    WriteConsoleOutputW(kk->drv.p->screen, kk->drv.p->buffer, size, pos, &rect);
    231228#endif
    232229}
Note: See TracChangeset for help on using the changeset viewer.