blob: da118d1812670f136c17879b112caaa8b0d98b63 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
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 if (display_get_info(&info) < 0)
81 return;
82
83 /* get the display's surface */
84 gfx_surface *surface = gfx_create_surface_from_display(&info);
85
86 struct text_line *line;
87 list_for_every_entry(&text_list, line, struct text_line, node) {
88 const char *c;
89 int x = line->x;
90 for (c = line->str; *c; c++) {
91 font_draw_char(surface, *c, x, line->y, TEXT_COLOR);
92 x += FONT_X;
93 }
94 }
95
96 gfx_flush(surface);
97
98 gfx_surface_destroy(surface);
99}
100