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

Last change on this file since 1233 was 1233, checked in by Sam Hocevar, 14 years ago
  • Allow to create the initial canvas with a zero size. Either the application resizes it later, or the driver changes it to fit the display.
  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1/*
2 *  libcaca       Colour ASCII-Art library
3 *  Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id: driver_raw.c 1233 2006-10-26 08:16:43Z sam $
7 *
8 *  This library is free software; you can redistribute it and/or
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.
12 */
13
14/*
15 *  This file contains the libcaca raw input and output driver
16 */
17
18#include "config.h"
19#include "common.h"
20
21#if !defined(__KERNEL__)
22
23#include <stdio.h>
24#include <stdlib.h>
25
26#include "caca.h"
27#include "caca_internals.h"
28#include "cucul.h"
29#include "cucul_internals.h"
30
31static int raw_init_graphics(caca_display_t *dp)
32{
33    unsigned int width = dp->cv->width, height = dp->cv->height;
34    char const *geometry;
35
36#if defined(HAVE_GETENV)
37    geometry = getenv("CACA_GEOMETRY");
38    if(geometry && *geometry)
39        sscanf(geometry, "%ux%u", &width, &height);
40#endif
41
42    _cucul_set_canvas_size(dp->cv, width ? width : 80, height ? height : 24);
43
44    return 0;
45}
46
47static int raw_end_graphics(caca_display_t *dp)
48{
49    return 0;
50}
51
52static int raw_set_display_title(caca_display_t *dp, char const *title)
53{
54    return -1;
55}
56
57static unsigned int raw_get_display_width(caca_display_t *dp)
58{
59    return 0;
60}
61
62static unsigned int raw_get_display_height(caca_display_t *dp)
63{
64    return 0;
65}
66
67static void raw_display(caca_display_t *dp)
68{
69    cucul_buffer_t *buffer;
70
71    buffer = cucul_export_canvas(dp->cv, "caca");
72    fwrite(cucul_get_buffer_data(buffer),
73           cucul_get_buffer_size(buffer), 1, stdout);
74    fflush(stdout);
75    cucul_free_buffer(buffer);
76}
77
78static void raw_handle_resize(caca_display_t *dp)
79{
80    ;
81}
82
83static int raw_get_event(caca_display_t *dp, caca_event_t *ev)
84{
85    ev->type = CACA_EVENT_NONE;
86    return 0;
87}
88
89/*
90 * Driver initialisation
91 */
92
93int raw_install(caca_display_t *dp)
94{
95    dp->drv.driver = CACA_DRIVER_RAW;
96
97    dp->drv.init_graphics = raw_init_graphics;
98    dp->drv.end_graphics = raw_end_graphics;
99    dp->drv.set_display_title = raw_set_display_title;
100    dp->drv.get_display_width = raw_get_display_width;
101    dp->drv.get_display_height = raw_get_display_height;
102    dp->drv.display = raw_display;
103    dp->drv.handle_resize = raw_handle_resize;
104    dp->drv.get_event = raw_get_event;
105    dp->drv.set_mouse = NULL;
106
107    return 0;
108}
109
110#endif /* !__KERNEL__ */
Note: See TracBrowser for help on using the repository browser.