blob: 4b5f4cad18cd9751bb86550636813ed864746ab0 [file] [log] [blame]
Travis Geiselbrecht801509f2010-05-21 23:02:04 -07001/*
2 * Copyright (c) 2008-2010 Travis Geiselbrecht
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24/**
25 * @addtogroup graphics
26 * @{
27 */
28
29/**
30 * @file
31 * @brief Console text display
32 *
33 * This module displays text on the console. The text is retained so that
34 * it can be redisplayed if the display is cleared.
35 *
36 * Output is to the default graphics display
37 */
38
39#include <debug.h>
40#include <list.h>
41#include <stdlib.h>
42#include <string.h>
43#include <dev/display.h>
44#include <lib/gfx.h>
45#include <lib/font.h>
46#include <lib/text.h>
47
48#define TEXT_COLOR 0xffffffff
49
50static struct list_node text_list = LIST_INITIAL_VALUE(text_list);
51
52struct text_line {
53 struct list_node node;
54 const char *str;
55 int x, y;
56};
57
58/**
59 * @brief Add a string to the console text
60 */
61void text_draw(int x, int y, const char *string)
62{
63 struct text_line *line = malloc(sizeof(struct text_line));
64
65 line->str = strdup(string);
66 line->x = x;
67 line->y = y;
68
69 list_add_head(&text_list, &line->node);
70
71 text_update();
72}
73
74/**
75 * @brief Refresh the display
76 */
77void text_update(void)
78{
79 struct display_info info;
80 display_get_info(&info);
81
82 /* get the display's surface */
83 gfx_surface *surface = gfx_create_surface_from_display(&info);
84
85 struct text_line *line;
86 list_for_every_entry(&text_list, line, struct text_line, node) {
87 const char *c;
88 int x = line->x;
89 for (c = line->str; *c; c++) {
90 font_draw_char(surface, *c, x, line->y, TEXT_COLOR);
91 x += FONT_X;
92 }
93 }
94
95 gfx_flush(surface);
96
97 gfx_surface_destroy(surface);
98}
99