Landtiger LPC1768 C BigLib 1
A self made, custom C library for the LandTiger board.
 
Loading...
Searching...
No Matches
glcd.c
Go to the documentation of this file.
1#include "glcd.h"
2#include "cl_list.h"
3#include "glcd_config.h"
4
5#include "glcd_lowlevel.h"
6#include "glcd_processor.h"
7
8#include <LPC17xx.h>
9#include <stdbool.h>
10#include <stdlib.h>
11#include <string.h>
12
13// VARIABLES
14
17
20
23
26
30
31// RENDER LIST
32
39
40#define VISIBLE_MASK (0x1)
41#define RENDERED_MASK (0x2)
42
43#define RLITEM_SET_VISIBLE(obj) ((obj)->metadata |= VISIBLE_MASK)
44#define RLITEM_SET_RENDERED(obj) ((obj)->metadata |= RENDERED_MASK)
45
46#define RLITEM_UNSET_VISIBLE(obj) ((obj)->metadata &= ~VISIBLE_MASK)
47#define RLITEM_UNSET_RENDERED(obj) ((obj)->metadata &= ~RENDERED_MASK)
48
49#define RLITEM_IS_VISIBLE(obj) ((obj)->metadata & VISIBLE_MASK)
50#define RLITEM_IS_RENDERED(obj) ((obj)->metadata & RENDERED_MASK)
51
55
56// PRIVATE FUNCTIONS
57
58_PRIVATE inline bool bboxes_intersect(const LCD_BBox *const a, const LCD_BBox *const b)
59{
60 // Check for overlap along the x-axis: left edge of a is to the left of the right edge of b
61 // AND the right edge of a is to the right of the left edge of b
62 return (a->top_left.x < b->bottom_right.x) && (a->bottom_right.x > b->top_left.x) &&
63 // Check for overlap along the y-axis: top edge of a is above the bottom edge of b
64 // AND the bottom edge of a is below the top edge of b
65 (a->top_left.y < b->bottom_right.y) && (a->bottom_right.y > b->top_left.y);
66}
67
69{
70 dest->pos = src->pos;
71 dest->type = src->type;
72 dest->cached_bbox = src->cached_bbox;
73
74 switch (src->type)
75 {
76 case LCD_COMP_LINE:
77 if ((dest->object.line = MEM_Alloc(s_allocator, sizeof(LCD_Line))) == NULL)
78 return false;
79
80 memcpy(dest->object.line, src->object.line, sizeof(LCD_Line));
81 return true;
82 case LCD_COMP_RECT:
83 if ((dest->object.rect = MEM_Alloc(s_allocator, sizeof(LCD_Rect))) == NULL)
84 return false;
85
86 memcpy(dest->object.rect, src->object.rect, sizeof(LCD_Rect));
87 return true;
88 case LCD_COMP_CIRCLE:
89 if ((dest->object.circle = MEM_Alloc(s_allocator, sizeof(LCD_Circle))) == NULL)
90 return false;
91
92 memcpy(dest->object.circle, src->object.circle, sizeof(LCD_Circle));
93 return true;
94 case LCD_COMP_IMAGE:
95 if ((dest->object.image = MEM_Alloc(s_allocator, sizeof(LCD_Image))) == NULL)
96 return false;
97
98 memcpy(dest->object.image, src->object.image, sizeof(LCD_Image));
99 return true;
100 case LCD_COMP_TEXT:
101 if ((dest->object.text = MEM_Alloc(s_allocator, sizeof(LCD_Text))) == NULL)
102 return false;
103
104 memcpy(dest->object.text, src->object.text, sizeof(LCD_Text));
105 return true;
106 case LCD_COMP_BUTTON:
107 if ((dest->object.button = MEM_Alloc(s_allocator, sizeof(LCD_Button))) == NULL)
108 return false;
109
110 memcpy(dest->object.button, src->object.button, sizeof(LCD_Button));
111 return true;
112 }
113
114 return false; // Should never reach this
115}
116
118{
119 switch (comp->type)
120 {
121 case LCD_COMP_LINE:
123 break;
124 case LCD_COMP_RECT:
126 break;
127 case LCD_COMP_CIRCLE:
129 break;
130 case LCD_COMP_IMAGE:
132 break;
133 case LCD_COMP_TEXT:
135 break;
136 case LCD_COMP_BUTTON:
138 break;
139 }
140}
141
142// RENDERING FUNCTIONS
143
144// This function needs to control the rendering phase. It will skip object which have
145// the rendered property set to true (already rendered). It WON'T TOUCH the visible property,
146// it will only update rendered (false->true).
147_PRIVATE inline LCD_Error render(struct __RLItem *const item)
148{
149 // If the object is already rendered, skip it.
150 if (RLITEM_IS_RENDERED(item))
151 return LCD_ERR_OK;
152
154 {
156 return LCD_ERR_OK;
157 }
158
160}
161
162// Just like render(), this function controls the un-rendering phase. It will skip
163// items only if they have the rendered property set to false (already un-rendered). It WON'T
164// TOUCH the visible property. It will update rendered (true->false).
165_PRIVATE LCD_Error unrender(struct __RLItem *const item, bool redraw_underneath)
166{
167 // If the object is not rendered, skip it
168 if (!RLITEM_IS_RENDERED(item))
169 return LCD_ERR_OK;
170
171 // If we don't need to redraw the objects underneath, we can apply a rougher method for deleting,
172 // which is faster. It's up to the caller to decide whether to redraw the objects underneath or not.
173 if (__LCD_PROC_DoProcessObject(item->obj, &item->obj->bbox,
174 redraw_underneath ? MD_DELETE : (MD_DELETE | MD_DELETE_FAST)))
176
177 if (!redraw_underneath)
179
180 // If we need to redraw the objects underneath, we need to find out which objects
181 // are underneath the object we just un-rendered, and mark them as un-rendered too.
182 const LCD_BBox *const bbox = &item->obj->bbox;
184 // Skipping the object we just un-rendered, or invisible ones.
185 if (itm->id == item->id || !RLITEM_IS_VISIBLE(itm))
186 continue;
187
188 if (bboxes_intersect(bbox, &itm->obj->bbox))
190 });
191
192 return LCD_RMRender();
193}
194
195// PUBLIC FUNCTIONS
196
197#include "font_msgothic.h"
198#include "font_system.h"
199
200LCD_Error LCD_Init(LCD_Orientation orientation, MEM_Allocator *const alloc, const LCD_Color *const clear_to)
201{
202 __LCD_LL_Init(orientation);
203
204 // Loading the two default fonts: MS Gothic & System
207 LCDFontListSize = 2;
208
209 // Allocating the render list
210 s_render_list = CL_ListAlloc(alloc, sizeof(struct __RLItem));
211 if (!s_render_list)
212 return LCD_ERR_NO_MEMORY;
213
214 s_allocator = alloc;
215 s_initialized = true;
216
217 if (clear_to)
218 LCD_SetBackgroundColor(*clear_to, false);
219
220 return LCD_ERR_OK;
221}
222
223// clang-format off
224
225bool LCD_IsInitialized(void) { return s_initialized; }
226
227u16 LCD_GetWidth(void) { return s_initialized ? LCDMaxX : 0; }
228
229u16 LCD_GetHeight(void) { return s_initialized ? LCDMaxY : 0; }
230
232
234
235// clang-format on
236
238{
239 if (point.x >= LCDMaxX || point.y >= LCDMaxY || !s_initialized)
240 return LCD_COL_NONE;
241
242 return __LCD_LL_GetPointColor(point.x, point.y);
243}
244
246{
247 if (!s_initialized)
249
250 if (color == LCD_COL_NONE)
251 return LCD_ERR_OK;
252
253 // Checking if color is already 565
254 if ((color & ~(0xFFFF)) != 0)
255 color = RGB8_TO_RGB565(color);
256
257 if (point.x >= LCDMaxX || point.y >= LCDMaxY)
259
260 __LCD_LL_SetPointColor(color, point.x, point.y);
261 return LCD_ERR_OK;
262}
263
264LCD_Error LCD_SetBackgroundColor(LCD_Color color, bool redraw_objects)
265{
266 if (!s_initialized)
268
269 if (color == LCD_COL_NONE)
270 return LCD_ERR_OK;
271
272 if ((color & ~(0xFFFF)) != 0)
273 color = RGB8_TO_RGB565(color);
274
275 LCDCurrentBGColor = color;
276 __LCD_LL_FillScreen(color);
277
278 // No object is displayed anymore, so we need to change the rendered
279 // property of each object in the render queue to false, so that after
280 // calling LCD_RMRender(), they will be re-rendered with the new background.
282
283 // If we don't need to redraw the objects, we can return now.
284 if (!redraw_objects)
285 return LCD_ERR_OK;
286
287 return LCD_RMRender();
288}
289
290// RENDERING
291
292LCD_Error LCD_RMAdd(LCD_Obj *const obj, LCD_ObjID *out_id, u8 options)
293{
294 if (!s_initialized)
296
297 if (!obj)
298 return LCD_ERR_NULL_PARAMS;
299
300 if (!obj->comps || obj->comps_size == 0)
301 return LCD_ERR_INVALID_OBJ;
302
305
306 // Allocating an object:
307 LCD_Obj *new_obj = MEM_Alloc(s_allocator, sizeof(LCD_Obj));
308 if (!new_obj)
309 {
310 *out_id = -1;
311 return LCD_ERR_NO_MEMORY;
312 }
313
314 // Allocating the components of the object
315 new_obj->comps = MEM_Alloc(s_allocator, obj->comps_size * sizeof(LCD_Component));
316 if (!new_obj->comps)
317 {
318 *out_id = -1;
319 MEM_Free(s_allocator, new_obj);
320 return LCD_ERR_NO_MEMORY;
321 }
322
323 // Copying the object
324 new_obj->comps_size = obj->comps_size;
325 new_obj->bbox = (LCD_BBox){0}; // BBox will be calculated by the processor
326
327 // Each component has an object, which is a union of all the possible components. Since the
328 // union contains pointers, we need to allocate them separately, based on the type attribute.
329 for (u8 i = 0; i < obj->comps_size; i++)
330 {
331 if (!alloc_component_object(&obj->comps[i], &new_obj->comps[i]))
332 {
333 *out_id = -1;
334 MEM_Free(s_allocator, new_obj->comps);
335 MEM_Free(s_allocator, new_obj);
336 return LCD_ERR_NO_MEMORY;
337 }
338 }
339
340 // Adding the object to the render list
341 const struct __RLItem item = {
343 .obj = new_obj,
344 .metadata = (options & LCD_ADD_OBJ_OPT_DONT_MARK_VISIBLE) ? 0 : VISIBLE_MASK,
345 };
346
348 {
349 *out_id = -1;
350 for (u8 i = 0; i < new_obj->comps_size; i++)
351 dealloc_component_object(&new_obj->comps[i]);
352
353 MEM_Free(s_allocator, new_obj->comps);
354 MEM_Free(s_allocator, new_obj);
355 return LCD_ERR_NO_MEMORY;
356 }
357
358 *out_id = item.id;
359 return LCD_ERR_OK;
360}
361
362LCD_Error LCD_RMRemove(LCD_ObjID id, bool redraw_underneath)
363{
364 if (!s_initialized)
366
367 if (id < 0 || (u32)id >= CL_ListSize(s_render_list))
368 return LCD_ERR_INVALID_OBJ;
369
370 struct __RLItem *item = NULL;
371 if (CL_ListGetPtr(s_render_list, id, (void **)&item) != CL_ERR_OK || !item)
372 return LCD_ERR_INVALID_OBJ;
373
374 // Additional checks
375 if (!item->obj || !item->obj->comps || item->obj->comps_size == 0)
376 return LCD_ERR_INVALID_OBJ;
377
378 // Un-rendering the object
379 LCD_Error err;
380 if ((err = unrender(item, redraw_underneath)) != LCD_ERR_OK)
381 return err;
382
383 // Deallocating the object
384 for (u8 i = 0; i < item->obj->comps_size; i++)
386
387 MEM_Free(s_allocator, item->obj->comps);
388 MEM_Free(s_allocator, item->obj);
390
392 return LCD_ERR_OK;
393}
394
396{
397 if (!s_initialized)
399
401 return LCD_ERR_OK;
402
403 // Clearing the render list
405 for (u8 i = 0; i < item->obj->comps_size; i++)
406 dealloc_component_object(&item->obj->comps[i]);
407
408 MEM_Free(s_allocator, item->obj->comps);
409 MEM_Free(s_allocator, item->obj);
410 });
411
413
414 // Clearing the screen
416
418 return LCD_ERR_OK;
419}
420
422{
423 if (!s_initialized)
425
426 LCD_Error err;
428 if (RLITEM_IS_VISIBLE(itm) && !RLITEM_IS_RENDERED(itm))
429 {
430 if ((err = render(itm)) != LCD_ERR_OK)
431 return err;
432 }
433 });
434
435 return LCD_ERR_OK;
436}
437
448
449LCD_Error LCD_RMSetVisibility(LCD_ObjID id, bool visible, bool redraw_underneath)
450{
451 if (!s_initialized)
453
454 if (id < 0 || (u32)id >= CL_ListSize(s_render_list))
455 return LCD_ERR_INVALID_OBJ;
456
457 struct __RLItem *item = NULL;
458 if (CL_ListGetPtr(s_render_list, id, (void **)&item) != CL_ERR_OK || !item)
459 return LCD_ERR_INVALID_OBJ;
460
461 // Additional checks
462 if (!item->obj || !item->obj->comps || item->obj->comps_size == 0)
463 return LCD_ERR_INVALID_OBJ;
464
465 // If item is already visible, and we want to make it visible, we can skip the operation.
466 if (visible && RLITEM_IS_VISIBLE(item))
467 return LCD_ERR_OK;
468
469 // If item is not visible, and we want to make it invisible, we can skip the operation.
470 if (!visible && !RLITEM_IS_VISIBLE(item))
471 return LCD_ERR_OK;
472
473 // If we want to make the object visible, we need to render it.
474 if (visible)
475 {
476 item->metadata |= VISIBLE_MASK;
477 if (render(item) == LCD_ERR_OK)
478 return LCD_ERR_OK;
479 else
480 {
481 item->metadata &= ~VISIBLE_MASK;
483 }
484 }
485
486 // If we want to make the object invisible, we need to un-render it.
487 item->metadata &= ~VISIBLE_MASK;
488 if (unrender(item, redraw_underneath) == LCD_ERR_OK)
489 return LCD_ERR_OK;
490
491 item->metadata |= VISIBLE_MASK;
493}
494
496{
497 if (!s_initialized || id < 0 || (u32)id >= CL_ListSize(s_render_list))
498 return false;
499
500 struct __RLItem *item = NULL;
501 if (CL_ListGetPtr(s_render_list, id, (void **)&item) != CL_ERR_OK || !item)
502 return false;
503
504 return RLITEM_IS_VISIBLE(item);
505}
506
507LCD_Error LCD_RMMove(LCD_ObjID id, LCD_Coordinate new_pos, bool redraw_underneath)
508{
509 if (!s_initialized)
511
512 if (id < 0 || (u32)id >= CL_ListSize(s_render_list))
513 return LCD_ERR_INVALID_OBJ;
514
515 struct __RLItem *item = NULL;
516 if (CL_ListGetPtr(s_render_list, id, (void **)&item) != CL_ERR_OK || !item)
517 return LCD_ERR_INVALID_OBJ;
518
519 // Additional checks
520 if (!item->obj || !item->obj->comps || item->obj->comps_size == 0)
521 return LCD_ERR_INVALID_OBJ;
522
523 // Starting by de-rendering the previous object
524 LCD_Error err;
525 if ((err = unrender(item, redraw_underneath)) != LCD_ERR_OK)
526 return err;
527
528 // Iterating through each component and update its position
529 i16 dx, dy;
530 LCD_Component *comp;
531 for (u16 i = 0; i < item->obj->comps_size; i++)
532 {
533 comp = &(item->obj->comps[i]);
534 switch (comp->type)
535 {
536 case LCD_COMP_LINE: {
537 // For a line, we need to calculate the BBox, and calculate the offset that
538 // needs to be applied to the from & to coordinates with the top-left corner
539 // of the BBox, and new_pos, which in this case is interpreted as the new
540 // top-left corner of the line.
541 LCD_BBox *bbox = &item->obj->bbox;
542 dx = new_pos.x - bbox->top_left.x;
543 dy = new_pos.y - bbox->top_left.y;
544
545 comp->object.line->from.x += dx;
546 comp->object.line->from.y += dy;
547 comp->object.line->to.x += dx;
548 comp->object.line->to.y += dy;
549 break;
550 }
551 case LCD_COMP_CIRCLE:
552 dx = new_pos.x - comp->object.circle->center.x;
553 dy = new_pos.y - comp->object.circle->center.y;
554
555 // Calculate the offset
556 comp->object.circle->center.x += dx;
557 comp->object.circle->center.y += dy;
558 break;
559 case LCD_COMP_RECT:
560 case LCD_COMP_IMAGE:
561 case LCD_COMP_TEXT:
562 case LCD_COMP_BUTTON:
563 dx = new_pos.x - comp->pos.x;
564 dy = new_pos.y - comp->pos.y;
565
566 comp->pos.x += dx;
567 comp->pos.y += dy;
568 break;
569 }
570 }
571
572 return render(item);
573}
574
575// PUBLIC FONT MANAGER FUNCTIONS
576
578{
581
582 *out_id = LCDFontListSize;
583 LCDFontList[*out_id] = font;
585 return LCD_ERR_OK;
586}
587
589{
590 if (id >= LCDFontListSize || id <= 1) // Cannot remove the default fonts
592
593 for (u32 i = id; i < LCDFontListSize - 1; i++)
594 LCDFontList[i] = LCDFontList[i + 1];
595
597 return LCD_ERR_OK;
598}
599
600// BBOX
601
603{
604 if (!s_initialized)
606
607 if (!out_bbox)
608 return LCD_ERR_NULL_PARAMS;
609
610 if (id < 0 || (u32)id >= CL_ListSize(s_render_list))
611 return LCD_ERR_INVALID_OBJ;
612
613 struct __RLItem *item = NULL;
614 if (CL_ListGetPtr(s_render_list, id, (void **)&item) != CL_ERR_OK || !item || !item->obj)
615 return LCD_ERR_INVALID_OBJ;
616
617 *out_bbox = item->obj->bbox;
618 return LCD_ERR_INVALID_OBJ;
619}
620
622{
623 if (!obj || !out_bbox)
624 return LCD_ERR_NULL_PARAMS;
625
626 if (!obj->comps || obj->comps_size == 0)
627 return LCD_ERR_INVALID_OBJ;
628
629 const bool res = __LCD_PROC_DoProcessObject(obj, out_bbox, MD_BBOX);
631}
632
633// PUBLIC DEBUG FUNCTIONS
634
636{
637 if (!s_initialized)
639
640 if (id < 0 || (u32)id >= CL_ListSize(s_render_list))
641 return LCD_ERR_INVALID_OBJ;
642
643 struct __RLItem *item = NULL;
644 if (CL_ListGetPtr(s_render_list, id, (void **)&item) != CL_ERR_OK || !item)
645 return LCD_ERR_INVALID_OBJ;
646
647 if (!item->obj || !item->obj->comps || item->obj->comps_size == 0)
648 return LCD_ERR_INVALID_OBJ;
649
650 const LCD_Dimension dim = {
651 .width = abs(item->obj->bbox.bottom_right.x - item->obj->bbox.top_left.x),
652 .height = abs(item->obj->bbox.bottom_right.y - item->obj->bbox.top_left.y),
653 };
654
655 // A bbox is always a rectangle, so we can render it as a rectangle directly.
656 // clang-format off
658 LCD_RECT(item->obj->bbox.top_left, {
659 .width = dim.width, .height = dim.height,
660 .edge_color = LCD_COL_RED, .fill_color = LCD_COL_NONE,
661 }),
662 LCD_LINE({
663 .from = item->obj->bbox.top_left,
664 .to = item->obj->bbox.bottom_right,
665 .color = LCD_COL_GREEN,
666 }),
667 LCD_LINE({
668 .from = (LCD_Coordinate){
669 .x = item->obj->bbox.top_left.x + dim.width,
670 .y = item->obj->bbox.top_left.y,
671 },
672 .to = (LCD_Coordinate){
673 .x = item->obj->bbox.top_left.x,
674 .y = item->obj->bbox.top_left.y + dim.height
675 },
676 .color = LCD_COL_BLUE,
677 })
678 );
679
680 const bool res = __LCD_PROC_DoProcessObject(&obj, NULL, MD_DRAW_BBOX);
681 // clang-format on
682
683 return res ? LCD_ERR_OK : LCD_ERR_DURING_RENDER;
684}
void MEM_Free(MEM_Allocator *ma, void *ptr)
Free a previously allocated block.
Definition allocator.c:98
void * MEM_Alloc(MEM_Allocator *ma, u32 size)
Allocate a block of memory from the pool with at least 'size' bytes.
Definition allocator.c:52
CL_Error CL_ListRemoveAt(CL_List *const list, u32 index, void *out_elem)
Removes an element at the specified index.
Definition cl_list.c:260
void CL_ListClear(CL_List *const list)
Removes all elements from the list.
Definition cl_list.c:316
u32 CL_ListSize(const CL_List *const list)
Gets the number of elements in the list.
Definition cl_list.c:334
#define CL_LIST_FOREACH_PTR(__type, __name, __list,...)
Macro to iterate over the elements of the list with a pointer to the current element.
Definition cl_list.h:33
CL_Error CL_ListPushBack(CL_List *const list, const void *const elem)
Adds an element at the end of the list.
Definition cl_list.c:80
bool CL_ListIsEmpty(const CL_List *const list)
Checks if the list is empty.
Definition cl_list.c:339
CL_Error CL_ListGetPtr(const CL_List *const list, u32 index, void **out_elem)
Gets an element at the specified index as a pointer, so the user can modify it.
Definition cl_list.c:186
CL_List * CL_ListAlloc(MEM_Allocator *const alloc, u32 elem_sz)
Initializes a new doubly-linked list with tail, with the allocated memory provided by the user.
Definition cl_list.c:43
@ CL_ERR_OK
No error.
Definition cl_types.h:26
const LCD_Font Font_MSGothic
const LCD_Font Font_System
_PRIVATE LCD_Error render(struct __RLItem *const item)
Definition glcd.c:147
bool LCD_RMIsVisible(LCD_ObjID id)
Returns whether an object is visible on the screen or not.
Definition glcd.c:495
#define RLITEM_UNSET_RENDERED(obj)
Definition glcd.c:47
#define RLITEM_IS_VISIBLE(obj)
Definition glcd.c:49
LCD_Coordinate LCD_GetCenter(void)
Returns the center of the screen at the current orientation.
Definition glcd.c:233
_USED_EXTERNALLY u16 LCDMaxY
Definition glcd.c:22
_PRIVATE bool bboxes_intersect(const LCD_BBox *const a, const LCD_BBox *const b)
Definition glcd.c:58
#define RLITEM_IS_RENDERED(obj)
Definition glcd.c:50
bool LCD_IsInitialized(void)
Checks if the LCD has been initialized.
Definition glcd.c:225
LCD_Coordinate LCD_GetSize(void)
Returns the size of the screen at the current orientation.
Definition glcd.c:231
LCD_Error LCD_FMAddFont(LCD_Font font, LCD_FontID *out_id)
Adds a new font to the font manager, and returns its ID through the out_id pointer.
Definition glcd.c:577
LCD_Error LCD_CalcBBoxForObject(const LCD_Obj *const obj, LCD_BBox *out_bbox)
Returns the bounding box of a temporary object.
Definition glcd.c:621
#define VISIBLE_MASK
Definition glcd.c:40
u16 LCD_GetHeight(void)
Returns the height of the screen at the current orientation.
Definition glcd.c:229
LCD_Error LCD_SetPointColor(LCD_Color color, LCD_Coordinate point)
Sets the color of the pixel at the specified coordinates.
Definition glcd.c:245
_USED_EXTERNALLY u8 LCDFontListSize
Definition glcd.c:29
_PRIVATE bool s_initialized
Whether the LCD has been initialized.
Definition glcd.c:16
_PRIVATE LCD_Error unrender(struct __RLItem *const item, bool redraw_underneath)
Definition glcd.c:165
LCD_Error LCD_RMAdd(LCD_Obj *const obj, LCD_ObjID *out_id, u8 options)
Adds a new object to the render list, and returns its ID (if out_id is not NULL) through the out_id p...
Definition glcd.c:292
u16 LCD_GetWidth(void)
Returns the width of the screen at the current orientation.
Definition glcd.c:227
_USED_EXTERNALLY u16 LCDMaxX
Current LCD maximum X and Y coordinates.
Definition glcd.c:22
LCD_Error LCD_SetBackgroundColor(LCD_Color color, bool redraw_objects)
Sets the background color of the screen.
Definition glcd.c:264
LCD_Error LCD_Init(LCD_Orientation orientation, MEM_Allocator *const alloc, const LCD_Color *const clear_to)
Initializes TFT LCD Controller.
Definition glcd.c:200
_PRIVATE MEM_Allocator * s_allocator
The memory allocator used to allocate the objects.
Definition glcd.c:19
LCD_Error LCD_RMRemove(LCD_ObjID id, bool redraw_underneath)
Removes an object from the render list by its ID. It also deallocates the memory used by that object ...
Definition glcd.c:362
LCD_Error LCD_DEBUG_RenderBBox(LCD_ObjID id)
Debug function to render the bounding box of a component.
Definition glcd.c:635
LCD_Error LCD_RMClear(void)
Removes all visible and non-visible objects from the screen.
Definition glcd.c:395
LCD_Error LCD_RMRenderTemporary(LCD_Obj *const obj)
Renders the object immediately, without adding neither to the render list nor to the memory arena....
Definition glcd.c:438
LCD_Color LCD_GetPointColor(LCD_Coordinate point)
Returns the RGB565 color of the pixel at the specified coordinates.
Definition glcd.c:237
_USED_EXTERNALLY LCD_Font LCDFontList[GLCD_MAX_FONTS]
The list of fonts that have been loaded into the LCD.
Definition glcd.c:28
LCD_Error LCD_RMSetVisibility(LCD_ObjID id, bool visible, bool redraw_underneath)
Shows/hides an object on/from the screen without modifying the render list.
Definition glcd.c:449
_PRIVATE CL_List * s_render_list
Render list, containing all the components to be rendered & metadata.
Definition glcd.c:53
LCD_Error LCD_RMRender(void)
Manually triggers an update of the screen. Useful when you want to add multiple objects at once,...
Definition glcd.c:421
_PRIVATE u32 s_render_list_id_ctr
Definition glcd.c:54
_USED_EXTERNALLY LCD_Color LCDCurrentBGColor
Current background color of the screen.
Definition glcd.c:25
LCD_Error LCD_GetBBox(LCD_ObjID id, LCD_BBox *out_bbox)
Returns the bounding box of an object in the render list.
Definition glcd.c:602
_PRIVATE bool alloc_component_object(const LCD_Component *const src, LCD_Component *dest)
Definition glcd.c:68
LCD_Error LCD_FMRemoveFont(LCD_FontID id)
Removes a font from the font manager by its ID.
Definition glcd.c:588
#define RLITEM_SET_RENDERED(obj)
Definition glcd.c:44
_PRIVATE void dealloc_component_object(LCD_Component *const comp)
Definition glcd.c:117
LCD_Error LCD_RMMove(LCD_ObjID id, LCD_Coordinate new_pos, bool redraw_underneath)
Moves an object in the render list to a new position. It also updates the object's position in the RL...
Definition glcd.c:507
#define RGB8_TO_RGB565(rgb)
Converts RGB (24 bit) into RGB565 (16 bit):
Definition glcd.h:12
#define GLCD_MAX_FONTS
Maximum number of fonts that can be loaded into the LCD.
Definition glcd_config.h:13
#define GLCD_MAX_COMPS_PER_OBJECT
This macro controls the timing between the low level operations with the GLCD controller....
Definition glcd_config.h:10
LCD_Error
Error codes returned by the GLCD library.
Definition glcd_errors.h:6
@ LCD_ERR_UNINITIALIZED
The library is not initialized.
Definition glcd_errors.h:11
@ LCD_ERR_DURING_RENDER
An error occurred during shape drawing.
Definition glcd_errors.h:37
@ LCD_ERR_DURING_UNRENDER
An error occurred during shape deletion.
Definition glcd_errors.h:40
@ LCD_ERR_INVALID_OBJ
The object is invalid (invalid ID, empty components array, etc.)
Definition glcd_errors.h:14
@ LCD_ERR_COORDS_OUT_OF_BOUNDS
The specified (x,y) coordinates are out of the screen boundaries.
Definition glcd_errors.h:23
@ LCD_ERR_INVALID_FONT_ID
The font ID is invalid.
Definition glcd_errors.h:29
@ LCD_ERR_NO_MEMORY
The memory pool does not have enough space to allocate the object.
Definition glcd_errors.h:32
@ LCD_ERR_NULL_PARAMS
One or more params is NULL.
Definition glcd_errors.h:17
@ LCD_ERR_DURING_BBOX_CALC
An error occurred during bounding box calculation.
Definition glcd_errors.h:43
@ LCD_ERR_FONT_LIST_FULL
The font list is full. No more fonts can be added.
Definition glcd_errors.h:26
@ LCD_ERR_TOO_MANY_COMPS_IN_OBJ
The object has too many components.
Definition glcd_errors.h:20
@ LCD_ERR_OK
No error occurred.
Definition glcd_errors.h:8
void __LCD_LL_FillScreen(u16 color)
void __LCD_LL_Init(u16 orientation)
u16 __LCD_LL_GetPointColor(u16 x, u16 y)
void __LCD_LL_SetPointColor(u16 rgb565, u16 x, u16 y)
#define LCD_LINE(...)
Definition glcd_macros.h:91
#define LCD_OBJECT_DEFINE(...)
Defines an object without adding it to the LCD render list.
Definition glcd_macros.h:10
#define LCD_RECT(coords,...)
Definition glcd_macros.h:97
bool __LCD_PROC_DoProcessObject(const LCD_Obj *const obj, LCD_BBox *out_bbox, u8 mode)
@ MD_DELETE
@ MD_DRAW_BBOX
@ MD_DELETE_FAST
@ MD_BBOX
LCD_Orientation
Definition glcd_types.h:12
i8 LCD_FontID
Definition glcd_types.h:91
i32 LCD_ObjID
Definition glcd_types.h:195
u32 LCD_Color
Represents a color in the RGB565 format.
Definition glcd_types.h:40
@ LCD_COL_BLUE
Definition glcd_types.h:26
@ LCD_COL_NONE
Definition glcd_types.h:33
@ LCD_COL_GREEN
Definition glcd_types.h:30
@ LCD_COL_BLACK
Definition glcd_types.h:24
@ LCD_COMP_RECT
Definition glcd_types.h:159
@ LCD_COMP_BUTTON
Definition glcd_types.h:163
@ LCD_COMP_IMAGE
Definition glcd_types.h:161
@ LCD_COMP_CIRCLE
Definition glcd_types.h:160
@ LCD_COMP_TEXT
Definition glcd_types.h:162
@ LCD_COMP_LINE
Definition glcd_types.h:158
@ LCD_ADD_OBJ_OPT_DONT_MARK_VISIBLE
Request GLCD to not mark the newly added object as visible. In that way, it it won't be rendered by a...
Definition glcd_types.h:204
LCD_Coordinate top_left
Definition glcd_types.h:62
LCD_Coordinate bottom_right
Definition glcd_types.h:62
LCD_Coordinate center
Definition glcd_types.h:112
Used to store a drawable component of any type.
Definition glcd_types.h:168
LCD_Circle * circle
Definition glcd_types.h:175
LCD_Coordinate pos
Definition glcd_types.h:170
LCD_Text * text
Definition glcd_types.h:177
LCD_Button * button
Definition glcd_types.h:178
LCD_Line * line
Definition glcd_types.h:173
LCD_ComponentType type
Definition glcd_types.h:169
LCD_Rect * rect
Definition glcd_types.h:174
union LCD_Component::@0 object
LCD_Image * image
Definition glcd_types.h:176
LCD_BBox cached_bbox
Definition glcd_types.h:171
LCD_Coordinate to
Definition glcd_types.h:100
LCD_Coordinate from
Definition glcd_types.h:100
Represents a generic object, made up of 1 or more basic components, that are rendered on the screen.
Definition glcd_types.h:189
LCD_BBox bbox
Definition glcd_types.h:190
u8 comps_size
Definition glcd_types.h:192
LCD_Component * comps
Definition glcd_types.h:191
u8 metadata
Definition glcd.c:37
LCD_ObjID id
Definition glcd.c:35
LCD_Obj * obj
Definition glcd.c:36
uint8_t u8
Definition types.h:8
#define _PRIVATE
Definition types.h:37
uint16_t u16
Definition types.h:7
int16_t i16
Definition types.h:11
#define _USED_EXTERNALLY
Definition types.h:35
uint32_t u32
Definition types.h:6