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 777 2006-04-16 18:28:47Z 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 | |
---|
20 | #if !defined(__KERNEL__) |
---|
21 | # include <stdio.h> |
---|
22 | #endif |
---|
23 | |
---|
24 | #include "caca.h" |
---|
25 | #include "caca_internals.h" |
---|
26 | #include "cucul.h" |
---|
27 | #include "cucul_internals.h" |
---|
28 | |
---|
29 | static int raw_init_graphics(caca_t *kk) |
---|
30 | { |
---|
31 | return 0; |
---|
32 | } |
---|
33 | |
---|
34 | static int raw_end_graphics(caca_t *kk) |
---|
35 | { |
---|
36 | return 0; |
---|
37 | } |
---|
38 | |
---|
39 | static int raw_set_window_title(caca_t *kk, char const *title) |
---|
40 | { |
---|
41 | return 0; |
---|
42 | } |
---|
43 | |
---|
44 | static unsigned int raw_get_window_width(caca_t *kk) |
---|
45 | { |
---|
46 | return 0; |
---|
47 | } |
---|
48 | |
---|
49 | static unsigned int raw_get_window_height(caca_t *kk) |
---|
50 | { |
---|
51 | return 0; |
---|
52 | } |
---|
53 | |
---|
54 | static void raw_display(caca_t *kk) |
---|
55 | { |
---|
56 | uint32_t *attr = kk->qq->attr; |
---|
57 | uint32_t *chars = kk->qq->chars; |
---|
58 | uint32_t w, h; |
---|
59 | unsigned int n; |
---|
60 | |
---|
61 | w = kk->qq->width; |
---|
62 | h = kk->qq->height; |
---|
63 | |
---|
64 | fprintf(stdout, "CACA%c%c%c%c%c%c%c%c", |
---|
65 | (w >> 24), (w >> 16) & 0xff, (w >> 8) & 0xff, w & 0xff, |
---|
66 | (h >> 24), (h >> 16) & 0xff, (h >> 8) & 0xff, h & 0xff); |
---|
67 | |
---|
68 | for(n = kk->qq->height * kk->qq->width; n--; ) |
---|
69 | { |
---|
70 | uint32_t c = *chars++; |
---|
71 | uint32_t a = *attr++; |
---|
72 | |
---|
73 | fprintf(stdout, "%c%c%c%c%c%c%c%c", |
---|
74 | (c >> 24), (c >> 16) & 0xff, (c >> 8) & 0xff, c & 0xff, |
---|
75 | (a >> 24), (a >> 16) & 0xff, (a >> 8) & 0xff, a & 0xff); |
---|
76 | } |
---|
77 | |
---|
78 | fprintf(stdout, "ACAC"); |
---|
79 | fflush(stdout); |
---|
80 | } |
---|
81 | |
---|
82 | static void raw_handle_resize(caca_t *kk) |
---|
83 | { |
---|
84 | ; |
---|
85 | } |
---|
86 | |
---|
87 | static int raw_get_event(caca_t *kk, caca_event_t *ev) |
---|
88 | { |
---|
89 | ev->type = CACA_EVENT_NONE; |
---|
90 | return 0; |
---|
91 | } |
---|
92 | |
---|
93 | /* |
---|
94 | * Driver initialisation |
---|
95 | */ |
---|
96 | |
---|
97 | int raw_install(caca_t *kk) |
---|
98 | { |
---|
99 | kk->drv.driver = CACA_DRIVER_RAW; |
---|
100 | |
---|
101 | kk->drv.init_graphics = raw_init_graphics; |
---|
102 | kk->drv.end_graphics = raw_end_graphics; |
---|
103 | kk->drv.set_window_title = raw_set_window_title; |
---|
104 | kk->drv.get_window_width = raw_get_window_width; |
---|
105 | kk->drv.get_window_height = raw_get_window_height; |
---|
106 | kk->drv.display = raw_display; |
---|
107 | kk->drv.handle_resize = raw_handle_resize; |
---|
108 | kk->drv.get_event = raw_get_event; |
---|
109 | kk->drv.set_mouse = NULL; |
---|
110 | |
---|
111 | return 0; |
---|
112 | } |
---|
113 | |
---|