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

Last change on this file since 2138 was 2138, checked in by Sam Hocevar, 12 years ago
  • Implement caca_create_display_with_driver() to specify an output driver without using environment variables..
  • Implement caca_get_display_driver() to return the current display's output driver.
  • Add a simple example program to test caca_create_display_with_driver().
  • Property svn:keywords set to Id
File size: 2.6 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 2138 2007-12-16 01:50:41Z 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#include "common.h"
21
22#if !defined(__KERNEL__)
23
24#include <stdio.h>
25#include <stdlib.h>
26
27#include "cucul.h"
28#include "caca.h"
29#include "caca_internals.h"
30
31static int raw_init_graphics(caca_display_t *dp)
32{
33    unsigned int width = cucul_get_canvas_width(dp->cv);
34    unsigned int height = cucul_get_canvas_height(dp->cv);
35    char const *geometry;
36
37#if defined(HAVE_GETENV)
38    geometry = getenv("CACA_GEOMETRY");
39    if(geometry && *geometry)
40        sscanf(geometry, "%ux%u", &width, &height);
41#endif
42
43    dp->resize.allow = 1;
44    cucul_set_canvas_size(dp->cv, width ? width : 80, height ? height : 24);
45    dp->resize.allow = 0;
46
47    return 0;
48}
49
50static int raw_end_graphics(caca_display_t *dp)
51{
52    return 0;
53}
54
55static int raw_set_display_title(caca_display_t *dp, char const *title)
56{
57    return -1;
58}
59
60static unsigned int raw_get_display_width(caca_display_t const *dp)
61{
62    return 0;
63}
64
65static unsigned int raw_get_display_height(caca_display_t const *dp)
66{
67    return 0;
68}
69
70static void raw_display(caca_display_t *dp)
71{
72    void *buffer;
73    unsigned long int len;
74
75    buffer = cucul_export_memory(dp->cv, "caca", &len);
76    if(!buffer)
77        return;
78    fwrite(buffer, len, 1, stdout);
79    fflush(stdout);
80    free(buffer);
81}
82
83static void raw_handle_resize(caca_display_t *dp)
84{
85    ;
86}
87
88static int raw_get_event(caca_display_t *dp, caca_privevent_t *ev)
89{
90    ev->type = CACA_EVENT_NONE;
91    return 0;
92}
93
94/*
95 * Driver initialisation
96 */
97
98int raw_install(caca_display_t *dp)
99{
100    dp->drv.id = CACA_DRIVER_RAW;
101    dp->drv.driver = "raw";
102
103    dp->drv.init_graphics = raw_init_graphics;
104    dp->drv.end_graphics = raw_end_graphics;
105    dp->drv.set_display_title = raw_set_display_title;
106    dp->drv.get_display_width = raw_get_display_width;
107    dp->drv.get_display_height = raw_get_display_height;
108    dp->drv.display = raw_display;
109    dp->drv.handle_resize = raw_handle_resize;
110    dp->drv.get_event = raw_get_event;
111    dp->drv.set_mouse = NULL;
112    dp->drv.set_cursor = NULL;
113
114    return 0;
115}
116
117#endif /* !__KERNEL__ */
Note: See TracBrowser for help on using the repository browser.