Refactor BeRTOS to be in his own directory.
[bertos.git] / bertos / gfx / text.h
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
6  * Bertos is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * As a special exception, you may use this file as part of a free software
21  * library without restriction.  Specifically, if other files instantiate
22  * templates or use macros or inline functions from this file, or you compile
23  * this file and link it with other files to produce an executable, this
24  * file does not by itself cause the resulting executable to be covered by
25  * the GNU General Public License.  This exception does not however
26  * invalidate any other reasons why the executable file might be covered by
27  * the GNU General Public License.
28  *
29  * Copyright 2003, 2004, 2005 Develer S.r.l. (http://www.develer.com/)
30  * Copyright 1999 Bernardo Innocenti <bernie@develer.com>
31  *
32  * -->
33  *
34  * \brief Text graphic routines (interface)
35  *
36  * \author Bernardo Innocenti <bernie@develer.com>
37  * \author Stefano Fedrigo <aleph@develer.com>
38  * \version $Id$
39  */
40
41 #ifndef GFX_TEXT_H
42 #define GFX_TEXT_H
43
44 #include <cfg/compiler.h>
45 #include <cfg/macros.h> /* BV() */
46 #include <cpu/attr.h> /* CPU_HARVARD */
47 #include <gfx/gfx.h> /* coord_t */
48
49 #include <stdarg.h>
50
51 /**
52  * \name Style flags
53  * \see text_style()
54  * \{
55  */
56 #define STYLEF_BOLD        BV(0)
57 #define STYLEF_ITALIC      BV(1)
58 #define STYLEF_UNDERLINE   BV(2)
59 #define STYLEF_INVERT      BV(3)
60 #define STYLEF_EXPANDED    BV(4)
61 #define STYLEF_CONDENSED   BV(5)
62 #define STYLEF_STRIKEOUT   BV(6)  /*<! Not implemented */
63 #define STYLEF_TALL        BV(7)  /*<! Not implemented */
64
65 #define STYLEF_MASK \
66         (STYLEF_BOLD | STYLEF_ITALIC | STYLEF_UNDERLINE \
67         | STYLEF_INVERT | STYLEF_EXPANDED | STYLEF_CONDENSED \
68         | STYLEF_STRIKEOUT | STYLEF_TALL)
69 /*\}*/
70
71 /**
72  * \name Formatting flags for text rendering
73  * \see text_xprintf()
74  * \{
75  */
76 #define TEXT_NORMAL   0       /**< Normal mode */
77 #define TEXT_FILL     BV(13)  /**< Fill rest of line with spaces */
78 #define TEXT_CENTER   BV(14)  /**< Center string in line */
79 #define TEXT_RIGHT    BV(15)  /**< Right aligned */
80 /*\}*/
81
82 /** Escape sequences codes */
83 #define ANSI_ESC_CLEARSCREEN 'c'
84
85
86 /* Fwd decl */
87 struct Bitmap;
88
89 /* Low-level text functions (mware/text.c) */
90 void text_moveTo(struct Bitmap *bm, int row, int col);
91 void text_setCoord(struct Bitmap *bm, int x, int y);
92 int text_putchar(char c, struct Bitmap *bm);
93 uint8_t text_style(struct Bitmap *bm, uint8_t flags, uint8_t mask);
94 void text_clear(struct Bitmap *bm);
95 void text_clearLine(struct Bitmap *bm, int line);
96
97 /* Text formatting functions (mware/text_format.c) */
98 int text_puts(const char *str, struct Bitmap *bm);
99 int text_vprintf(struct Bitmap *bm, const char *fmt, va_list ap);
100 int text_printf(struct Bitmap *bm, const char *fmt, ...) FORMAT(__printf__, 2, 3);
101 int text_xyvprintf(struct Bitmap *bm, coord_t x, coord_t y, uint16_t mode, const char *fmt, va_list ap);
102 int text_xyprintf(struct Bitmap *bm, coord_t x, coord_t col, uint16_t mode, const char *fmt, ...) FORMAT(__printf__, 5, 6);
103 int text_xprintf(struct Bitmap *bm, uint8_t row, uint8_t col, uint16_t mode, const char *fmt, ...) FORMAT(__printf__, 5, 6);
104 int text_vwidthf(struct Bitmap *bm, const char * fmt, va_list ap);
105 int text_widthf(struct Bitmap *bm, const char * fmt, ...) FORMAT(__printf__, 2, 3);
106
107 /* Text formatting functions for program-memory strings (mware/text_format.c) */
108 #if CPU_HARVARD
109 #include <mware/pgm.h>
110 int text_puts_P(const char * PROGMEM str, struct Bitmap *bm);
111 int text_vprintf_P(struct Bitmap *bm, const char * PROGMEM fmt, va_list ap);
112 int text_printf_P(struct Bitmap *bm, const char * PROGMEM fmt, ...) FORMAT(__printf__, 2, 3);
113 int text_xprintf_P(struct Bitmap *bm, uint8_t row, uint8_t col, uint16_t mode, const char * PROGMEM fmt, ...) FORMAT(__printf__, 5, 6);
114 int text_vwidthf_P(struct Bitmap *bm, const char * PROGMEM fmt, va_list ap);
115 int text_widthf_P(struct Bitmap *bm, const char * PROGMEM fmt, ...);
116 #endif /* CPU_HARVARD */
117
118 #endif /* GFX_TEXT_H */