source: libcaca/trunk/caca/driver_conio.c @ 1233

Last change on this file since 1233 was 1218, checked in by Sam Hocevar, 14 years ago
  • Support for fullwidth glyphs in the libcaca output drivers.
  • Property svn:keywords set to Id
File size: 4.0 KB
RevLine 
[35]1/*
[672]2 *  libcaca       Colour ASCII-Art library
[527]3 *  Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
[268]4 *                All Rights Reserved
[35]5 *
[769]6 *  $Id: driver_conio.c 1218 2006-10-22 16:35:25Z sam $
7 *
[268]8 *  This library is free software; you can redistribute it and/or
[522]9 *  modify it under the terms of the Do What The Fuck You Want To
10 *  Public License, Version 2, as published by Sam Hocevar. See
11 *  http://sam.zoy.org/wtfpl/COPYING for more details.
[35]12 */
[17]13
[769]14/*
[540]15 *  This file contains the libcaca DOS/conio.h input and output driver
[205]16 */
17
[63]18#include "config.h"
[859]19#include "common.h"
[63]20
[539]21#if defined(USE_CONIO)
22
23#include <dos.h>
24#include <conio.h>
25#if defined(SCREENUPDATE_IN_PC_H)
26#   include <pc.h>
27#endif
28
[550]29#include <stdlib.h>
30
[185]31#include "caca.h"
32#include "caca_internals.h"
[524]33#include "cucul.h"
34#include "cucul_internals.h"
[17]35
[550]36struct driver_private
37{
38    struct text_info ti;
39    char *screen;
40};
41
[811]42static int conio_init_graphics(caca_display_t *dp)
[227]43{
[811]44    dp->drv.p = malloc(sizeof(struct driver_private));
[550]45
[539]46    _wscroll = 0;
47    _setcursortype(_NOCURSOR);
48    clrscr();
[348]49
[811]50    gettextinfo(&dp->drv.p->ti);
51    dp->drv.p->screen = malloc(2 * dp->drv.p->ti.screenwidth
52                                 * dp->drv.p->ti.screenheight * sizeof(char));
53    if(dp->drv.p->screen == NULL)
[539]54        return -1;
[227]55#   if defined(SCREENUPDATE_IN_PC_H)
[811]56    ScreenRetrieve(dp->drv.p->screen);
[227]57#   else
[539]58    /* FIXME */
[227]59#   endif
[813]60    _cucul_set_canvas_size(dp->cv, dp->drv.p->ti.screenwidth,
61                                   dp->drv.p->ti.screenheight);
[227]62    return 0;
63}
64
[811]65static int conio_end_graphics(caca_display_t *dp)
[251]66{
[539]67    _wscroll = 1;
68    textcolor((enum COLORS)WHITE);
69    textbackground((enum COLORS)BLACK);
[811]70    gotoxy(dp->cv->width, dp->cv->height);
[539]71    cputs("\r\n");
72    _setcursortype(_NORMALCURSOR);
[300]73
[811]74    free(dp->drv.p->screen);
75    free(dp->drv.p);
[539]76
[251]77    return 0;
78}
79
[819]80static int conio_set_display_title(caca_display_t *dp, char const *title)
[343]81{
[1006]82    return -1;
[343]83}
84
[819]85static unsigned int conio_get_display_width(caca_display_t *dp)
[352]86{
87    /* Fallback to a 6x10 font */
[811]88    return dp->cv->width * 6;
[352]89}
90
[819]91static unsigned int conio_get_display_height(caca_display_t *dp)
[352]92{
93    /* Fallback to a 6x10 font */
[811]94    return dp->cv->height * 10;
[352]95}
96
[811]97static void conio_display(caca_display_t *dp)
[227]98{
[811]99    char *screen = dp->drv.p->screen;
100    uint32_t *attr = dp->cv->attr;
101    uint32_t *chars = dp->cv->chars;
[1218]102    unsigned int n;
[567]103
[811]104    for(n = dp->cv->height * dp->cv->width; n--; )
[265]105    {
[1218]106        char ch = cucul_utf32_to_cp437(*chars++);
107        if(n && *chars == CUCUL_MAGIC_FULLWIDTH)
108        {
109            *screen++ = '[';
110            *screen++ = _cucul_argb32_to_ansi8(*attr++);
111            ch = ']';
112            chars++;
113            n--;
114        }
115        *screen++ = ch;
[728]116        *screen++ = _cucul_argb32_to_ansi8(*attr++);
[265]117    }
[227]118#   if defined(SCREENUPDATE_IN_PC_H)
[811]119    ScreenUpdate(dp->drv.p->screen);
[227]120#   else
[539]121    /* FIXME */
[227]122#   endif
[539]123}
[261]124
[811]125static void conio_handle_resize(caca_display_t *dp)
[539]126{
[553]127    /* We know nothing about our window */
[811]128    dp->resize.w = dp->cv->width;
129    dp->resize.h = dp->cv->height;
[227]130}
131
[811]132static int conio_get_event(caca_display_t *dp, caca_event_t *ev)
[548]133{
[681]134    unsigned char ch;
[777]135    caca_event_t release;
[548]136
137    if(!_conio_kbhit())
[681]138    {
139        ev->type = CACA_EVENT_NONE;
140        return 0;
141    }
[548]142
[681]143    ch = getch();
144
145    ev->type = CACA_EVENT_KEY_PRESS;
[810]146    ev->data.key.ch = ch;
[969]147    ev->data.key.utf32 = (uint32_t)ch;
[681]148    ev->data.key.utf8[0] = ch;
149    ev->data.key.utf8[1] = '\0';
150
151    release = *ev;
152    release.type = CACA_EVENT_KEY_RELEASE;
[811]153    _push_event(dp, &release);
[681]154
155    return 1;
[548]156}
157
[347]158/*
[539]159 * Driver initialisation
[347]160 */
[524]161
[811]162int conio_install(caca_display_t *dp)
[347]163{
[811]164    dp->drv.driver = CACA_DRIVER_CONIO;
[347]165
[811]166    dp->drv.init_graphics = conio_init_graphics;
167    dp->drv.end_graphics = conio_end_graphics;
[819]168    dp->drv.set_display_title = conio_set_display_title;
169    dp->drv.get_display_width = conio_get_display_width;
170    dp->drv.get_display_height = conio_get_display_height;
[811]171    dp->drv.display = conio_display;
172    dp->drv.handle_resize = conio_handle_resize;
173    dp->drv.get_event = conio_get_event;
174    dp->drv.set_mouse = NULL;
[684]175
176    return 0;
[347]177}
178
[539]179#endif /* USE_CONIO */
[281]180
Note: See TracBrowser for help on using the repository browser.