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