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

Last change on this file since 2821 was 2821, checked in by Sam Hocevar, 11 years ago

Starting refactoring to get rid of libcucul. The initial reason for the
split is rendered moot by the plugin system: when enabled, binaries do
not link directly with libX11 or libGL. I hope this is a step towards
more consisteny and clarity.

  • Property svn:keywords set to Id
File size: 2.5 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 2821 2008-09-27 13:12:46Z sam $
7 *
8 *  This library is free software. It comes without any warranty, to
9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15/*
16 *  This file contains the libcaca raw input and output driver
17 */
18
19#include "config.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
29static int raw_init_graphics(caca_display_t *dp)
30{
31    int width = caca_get_canvas_width(dp->cv);
32    int height = caca_get_canvas_height(dp->cv);
33    char const *geometry;
34
35#if defined(HAVE_GETENV)
36    geometry = getenv("CACA_GEOMETRY");
37    if(geometry && *geometry)
38        sscanf(geometry, "%ux%u", &width, &height);
39#endif
40
41    dp->resize.allow = 1;
42    caca_set_canvas_size(dp->cv, width ? width : 80, height ? height : 24);
43    dp->resize.allow = 0;
44
45    return 0;
46}
47
48static int raw_end_graphics(caca_display_t *dp)
49{
50    return 0;
51}
52
53static int raw_set_display_title(caca_display_t *dp, char const *title)
54{
55    return -1;
56}
57
58static int raw_get_display_width(caca_display_t const *dp)
59{
60    return 0;
61}
62
63static int raw_get_display_height(caca_display_t const *dp)
64{
65    return 0;
66}
67
68static void raw_display(caca_display_t *dp)
69{
70    void *buffer;
71    size_t len;
72
73    buffer = caca_export_memory(dp->cv, "caca", &len);
74    if(!buffer)
75        return;
76    fwrite(buffer, len, 1, stdout);
77    fflush(stdout);
78    free(buffer);
79}
80
81static void raw_handle_resize(caca_display_t *dp)
82{
83    ;
84}
85
86static int raw_get_event(caca_display_t *dp, caca_privevent_t *ev)
87{
88    ev->type = CACA_EVENT_NONE;
89    return 0;
90}
91
92/*
93 * Driver initialisation
94 */
95
96int raw_install(caca_display_t *dp)
97{
98    dp->drv.id = CACA_DRIVER_RAW;
99    dp->drv.driver = "raw";
100
101    dp->drv.init_graphics = raw_init_graphics;
102    dp->drv.end_graphics = raw_end_graphics;
103    dp->drv.set_display_title = raw_set_display_title;
104    dp->drv.get_display_width = raw_get_display_width;
105    dp->drv.get_display_height = raw_get_display_height;
106    dp->drv.display = raw_display;
107    dp->drv.handle_resize = raw_handle_resize;
108    dp->drv.get_event = raw_get_event;
109    dp->drv.set_mouse = NULL;
110    dp->drv.set_cursor = NULL;
111
112    return 0;
113}
114
115#endif /* !__KERNEL__ */
Note: See TracBrowser for help on using the repository browser.