sGUI  V1.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
text.c
Go to the documentation of this file.
1 
72 #ifdef __cplusplus
73 extern "C" {
74 #endif /* __cplusplus */
75 
76 /*----- Header-Files -------------------------------------------------------*/
77 #include <stdlib.h> /* Common types and functions */
78 #include <stdint.h> /* Standard integer formats */
79 #include "lcd.h" /* Main functionality and lld */
80 
81 /*----- Macros -------------------------------------------------------------*/
82 
83 /*----- Data types ---------------------------------------------------------*/
84 
85 /*----- Function prototypes ------------------------------------------------*/
86 
87 /*----- Data ---------------------------------------------------------------*/
91 static LCDCOLOR TextColor = 0xFFFF;
92 
96 static LCDCOLOR BackColor = 0x0000;
97 
101 static FONT_T *CurrentFont = &font_5x8;
102 
103 /*----- Implementation -----------------------------------------------------*/
113 static void LCD_DrawChar(uint16_t Xpos, uint16_t Ypos, LCDCOLOR BackColor,
114  LCDCOLOR TextColor, FONT_T *Font, void *ptr) {
115 
116  uint32_t x = 0, y = 0;
118  uint32_t *PixelCount;
119  uint8_t count = 0;
120 
121  for (y = Font->height; y > 0; y--) {
122 
123  for (x = 0; x < Font->width; x++) {
124 
125  PixelCount = ptr + x * Font->datasize;
126  if ((*PixelCount & (1 << (y - 1))) == 0) {
127  pixels[count] = BackColor;
128  }
129  else {
130  pixels[count] = TextColor;
131  }
132  count++;
133  }
134  }
135 
136  LCD_WriteArea(Xpos, Ypos, Xpos + Font->width - 1, Ypos + Font->height - 1,
137  &pixels[0]);
138 }
139 
145  TextColor = Color;
146 }
147 
153  BackColor = Color;
154 }
155 
160 void LCD_SetFont(FONT_T *Font) {
161  CurrentFont = Font;
162 }
163 
169  return CurrentFont;
170 }
171 
176 uint8_t LCD_GetLineCount(void) {
177  return LCD_VER_RESOLUTION / CurrentFont->height;
178 }
179 
186 void LCD_ClearLine(uint8_t Line) {
187 
188  LCD_DrawRectF(0, Line * CurrentFont->height, LCD_HOR_RESOLUTION - 1,
189  CurrentFont->height - 1, BackColor);
190 }
191 
199 void LCD_DisplayCharXY(uint16_t x, uint16_t y, char Ascii) {
200 
201  Ascii -= 32;
202 
203  LCD_DrawChar(
204  x,
205  y,
206  BackColor,
207  TextColor,
208  CurrentFont,
209  (void *) (CurrentFont->data
210  + Ascii * CurrentFont->width * CurrentFont->datasize));
211 }
212 
223 void LCD_DisplayCharLine(uint8_t Line, uint8_t Column, char Ascii) {
224 
225  LCD_DisplayCharXY(Column * CurrentFont->width, Line * CurrentFont->height,
226  Ascii);
227 }
228 
236 void LCD_DisplayStringXY(uint16_t x, uint16_t y, const char *ptr) {
237 
238  while (*ptr != 0) {
239  LCD_DisplayCharXY(x, y, *ptr++);
240  x += CurrentFont->width;
241  }
242 }
243 
250 void LCD_DisplayStringLine(uint8_t Line, const char *ptr) {
251 
252  uint8_t i = 0;
253 
254  while ((*ptr != 0) && (i < (LCD_HOR_RESOLUTION / CurrentFont->width))) {
255  if (*ptr == '\n') {
256  Line++;
257  }
258  else if (*ptr == '\r') {
259  i = 0;
260  }
261  else if (*ptr == '\t') {
262  LCD_DisplayCharLine(Line, i++, ' ');
263  while (i % 4) {
264  LCD_DisplayCharLine(Line, i++, ' ');
265  }
266  }
267  else if (*ptr == '\b') {
268  LCD_DisplayCharLine(Line, --i, ' ');
269  i--;
270  }
271  else {
272  LCD_DisplayCharLine(Line, i++, *ptr);
273  }
274  ptr++;
275  }
276 
277  while (i < (LCD_HOR_RESOLUTION / CurrentFont->width)) {
278  LCD_DisplayCharLine(Line, i++, ' ');
279  }
280 }
281 
288 void LCD_DisplayStringCenterLine(uint8_t Line, const char *ptr) {
289 
290  uint8_t i;
291  uint16_t length = 0;
292 
293  for (i = 0;
294  (i < LCD_HOR_RESOLUTION / CurrentFont->width) && (ptr[i] != 0);
295  i++) {
296 
297  length += CurrentFont->width;
298  }
299 
301  Line * CurrentFont->height, ptr);
302 }
303 
304 /*----- EOF ----------------------------------------------------------------*/
305 
306 #ifdef __cplusplus
307 }
308 #endif /* __cplusplus */
309 
uint8_t width
Definition: font.h:114
#define FONT_MAX_HEIGHT
Definition: font.h:106
void LCD_SetFont(FONT_T *Font)
Sets the current font.
Definition: text.c:160
static LCDCOLOR BackColor
Color of the background.
Definition: text.c:96
void LCD_SetTextColor(LCDCOLOR Color)
Sets the Text color.
Definition: text.c:144
static void LCD_DrawChar(uint16_t Xpos, uint16_t Ypos, LCDCOLOR BackColor, LCDCOLOR TextColor, FONT_T *Font, void *ptr)
Draws a character on LCD.
Definition: text.c:113
void LCD_ClearLine(uint8_t Line)
Clears the selected line.
Definition: text.c:186
void LCD_DisplayStringLine(uint8_t Line, const char *ptr)
Displays a string on a line on the LCD. Position is set with a line number.
Definition: text.c:250
void LCD_DisplayCharLine(uint8_t Line, uint8_t Column, char Ascii)
Displays one character (16dots width, 24dots height) on the LCD. Position is set with a line and a co...
Definition: text.c:223
void LCD_DrawRectF(uint16_t Xpos, uint16_t Ypos, uint16_t width, uint16_t height, LCDCOLOR Color)
Displays a filled rectangle.
Definition: geometry.c:178
void LCD_DisplayCharXY(uint16_t x, uint16_t y, char Ascii)
Displays one character (16dots width, 24dots height) on the LCD. Position is set with a x- and a y-co...
Definition: text.c:199
uint8_t LCD_GetLineCount(void)
Gets the current count of possible lines.
Definition: text.c:176
uint8_t datasize
Definition: font.h:116
void LCD_DisplayStringXY(uint16_t x, uint16_t y, const char *ptr)
Displays a string on the LCD. Position is set with the x- and y-coordinate.
Definition: text.c:236
static uint8_t count
Number of messages which are stored in LOG_Messages.
Definition: log.c:115
Simple graphic library main functionality.
#define LCD_HOR_RESOLUTION
void * data
Definition: font.h:117
void LCD_DisplayStringCenterLine(uint8_t Line, const char *ptr)
Displays a string on the LCD. Position is set at the y-coordinate on center of the display...
Definition: text.c:288
uint16_t LCDCOLOR
Data type for a color definition.
Definition: color.h:98
FONT_T * LCD_GetFont(void)
Gets the current font.
Definition: text.c:168
static void LCD_WriteArea(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t *pData)
Write an array of data to a specified area on the display.
Definition: lcd_lld.h:118
This struct encapsulates the parameters of a font.
Definition: font.h:113
static LCDCOLOR TextColor
Color of the text.
Definition: text.c:91
static FONT_T * CurrentFont
Current font.
Definition: text.c:101
#define FONT_MAX_WIDTH
Definition: font.h:107
uint8_t height
Definition: font.h:115
void LCD_SetBackColor(LCDCOLOR Color)
Sets the Background color.
Definition: text.c:152