6 //generic algos used by all 3 backends
8 int console_setcolors(struct Console
* self
, rgb_t bgcolor
, rgb_t fgcolor
) {
10 console_setcolor(self
, 0, bgcolor
) +
11 console_setcolor(self
, 1, fgcolor
);
14 void console_setautomove(Console
* c
, int automove
) {
15 c
->automove
= !!automove
;
18 void console_unblink(Console
* c
) {
20 console_blink_cursor(c
);
23 mouse_event
console_getmouse(Console
* c
) {
27 void console_getcursor(struct Console
* self
, int* x
, int* y
) {
32 void console_scrollup(Console
* c
) {
36 void console_linebreak(Console
* c
) {
40 if(c
->cursor
.y
== c
->dim
.y
) {
46 void console_advance_cursor(Console
* c
, int steps
) {
47 // unblink former position
50 if(c
->cursor
.x
+ steps
>= c
->dim
.x
)
52 else if(c
->cursor
.x
+ steps
< 0) {
54 c
->cursor
.x
= c
->dim
.x
- 1;
61 void console_fill(Console
*c
, rect
* area
, int ch
) {
63 for(y
= area
->topleft
.y
; y
<= area
->bottomright
.y
; y
++) {
64 for(x
= area
->topleft
.x
; x
<= area
->bottomright
.x
; x
++) {
65 console_goto(c
, x
, y
);
66 console_putchar(c
, ch
, 0);
72 static void cursor_move_do(int which
, int* dest
, int max
) {
74 if(*dest
+ which
>= 0 && *dest
+ which
< max
)
79 static void cursor_move(Console
* c
, int x
, int y
) {
80 int which
, *dest
, max
;
82 which
= x
; dest
= &c
->cursor
.x
; max
= c
->dim
.x
;
83 cursor_move_do(which
, dest
, max
);
84 which
= y
; dest
= &c
->cursor
.y
; max
= c
->dim
.y
;
85 cursor_move_do(which
, dest
, max
);
86 console_blink_cursor(c
);
89 void console_cursor_up(Console
* c
) {
90 cursor_move(c
, 0, -1);
93 void console_cursor_down(Console
* c
) {
97 void console_cursor_left(Console
* c
) {
98 cursor_move(c
, -1, 0);
101 void console_cursor_right(Console
* c
) {
102 cursor_move(c
, 1, 0);
105 void console_printf(Console
* c
, const char* fmt
, ...) {
108 console_initoutput(c
);
110 ssize_t x
, result
= vsnprintf(dest
, sizeof(dest
), fmt
, ap
);
112 for(x
= 0; x
< result
; x
++) {
113 console_printchar(c
, dest
[x
], 0);
117 enum ConsoleBackend
console_getbackendtype(Console
*c
) {
118 return c
->backendtype
;