Landtiger LPC1768 C BigLib 1
A self made, custom C library for the LandTiger board.
 
Loading...
Searching...
No Matches
glcd.h File Reference
#include "allocator.h"
#include "glcd_macros.h"
#include "glcd_types.h"

Go to the source code of this file.

Macros

#define RGB8_TO_RGB565(rgb)    (u16)((((rgb >> 16) & 0xFF) >> 3) << 11 | (((rgb >> 8) & 0xFF) >> 2) << 5 | ((rgb & 0xFF) >> 3))
 Converts RGB (24 bit) into RGB565 (16 bit):
 

Functions

LCD_Error LCD_Init (LCD_Orientation orientation, MEM_Allocator *const alloc, const LCD_Color *const clear_to)
 Initializes TFT LCD Controller.
 
bool LCD_IsInitialized (void)
 Checks if the LCD has been initialized.
 
u16 LCD_GetWidth (void)
 Returns the width of the screen at the current orientation.
 
u16 LCD_GetHeight (void)
 Returns the height of the screen at the current orientation.
 
LCD_Coordinate LCD_GetSize (void)
 Returns the size of the screen at the current orientation.
 
LCD_Coordinate LCD_GetCenter (void)
 Returns the center of the screen at the current orientation.
 
LCD_Color LCD_GetPointColor (LCD_Coordinate point)
 Returns the RGB565 color of the pixel at the specified coordinates.
 
LCD_Error LCD_SetPointColor (LCD_Color color, LCD_Coordinate point)
 Sets the color of the pixel at the specified coordinates.
 
LCD_Error LCD_SetBackgroundColor (LCD_Color color, bool redraw_objects)
 Sets the background color of the screen.
 
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 pointer.
 
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 in the memory arena.
 
LCD_Error LCD_RMClear (void)
 Removes all visible and non-visible objects from the screen.
 
LCD_Error LCD_RMRender (void)
 Manually triggers an update of the screen. Useful when you want to add multiple objects at once, and only update the screen at the end.
 
LCD_Error LCD_RMRenderTemporary (LCD_Obj *const obj)
 Renders the object immediately, without adding neither to the render list nor to the memory arena. This is useful for objects that are not frequently updated, and that you don't want to store in the memory arena.
 
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.
 
bool LCD_RMIsVisible (LCD_ObjID id)
 Returns whether an object is visible on the screen or not.
 
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 itself, and in the memory arena.
 
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.
 
LCD_Error LCD_FMRemoveFont (LCD_FontID id)
 Removes a font from the font manager by its ID.
 
LCD_Error LCD_GetBBox (LCD_ObjID id, LCD_BBox *out_bbox)
 Returns the bounding box of an object in the render list.
 
LCD_Error LCD_CalcBBoxForObject (const LCD_Obj *const obj, LCD_BBox *out_bbox)
 Returns the bounding box of a temporary object.
 
LCD_Error LCD_DEBUG_RenderBBox (LCD_ObjID id)
 Debug function to render the bounding box of a component.
 

Macro Definition Documentation

◆ RGB8_TO_RGB565

#define RGB8_TO_RGB565 (   rgb)     (u16)((((rgb >> 16) & 0xFF) >> 3) << 11 | (((rgb >> 8) & 0xFF) >> 2) << 5 | ((rgb & 0xFF) >> 3))

Converts RGB (24 bit) into RGB565 (16 bit):

  • 5 bits for red (bits 11-15)
  • 6 bits for green (bits 5-10)
  • 5 bits for blue (bits 0-4)

Definition at line 12 of file glcd.h.

Function Documentation

◆ LCD_CalcBBoxForObject()

LCD_Error LCD_CalcBBoxForObject ( const LCD_Obj *const  obj,
LCD_BBox out_bbox 
)

Returns the bounding box of a temporary object.

Parameters
objThe object to get the bounding box of.
out_bboxThe bounding box of the object, if it was found.
Returns
LCD_Error The error code.

Definition at line 621 of file glcd.c.

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}
@ LCD_ERR_INVALID_OBJ
The object is invalid (invalid ID, empty components array, etc.)
Definition glcd_errors.h:14
@ 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_OK
No error occurred.
Definition glcd_errors.h:8
bool __LCD_PROC_DoProcessObject(const LCD_Obj *const obj, LCD_BBox *out_bbox, u8 mode)
@ MD_BBOX
u8 comps_size
Definition glcd_types.h:192
LCD_Component * comps
Definition glcd_types.h:191

◆ LCD_DEBUG_RenderBBox()

LCD_Error LCD_DEBUG_RenderBBox ( LCD_ObjID  id)

Debug function to render the bounding box of a component.

Parameters
idThe ID of the object to render the bounding box of.
Returns
LCD_Error The error code.

Definition at line 635 of file glcd.c.

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}
u32 CL_ListSize(const CL_List *const list)
Gets the number of elements in the list.
Definition cl_list.c:334
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_ERR_OK
No error.
Definition cl_types.h:26
_PRIVATE bool s_initialized
Whether the LCD has been initialized.
Definition glcd.c:16
_PRIVATE CL_List * s_render_list
Render list, containing all the components to be rendered & metadata.
Definition glcd.c:53
@ 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
#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
@ MD_DRAW_BBOX
@ LCD_COL_BLUE
Definition glcd_types.h:26
@ LCD_COL_GREEN
Definition glcd_types.h:30
Represents a generic object, made up of 1 or more basic components, that are rendered on the screen.
Definition glcd_types.h:189
LCD_Obj * obj
Definition glcd.c:36
uint32_t u32
Definition types.h:6

◆ LCD_FMAddFont()

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.

Parameters
fontThe font to add
out_idThe ID of the font, if it was added successfully to the font manager.
Returns
LCD_Error The error code.

Definition at line 577 of file glcd.c.

578{
581
582 *out_id = LCDFontListSize;
583 LCDFontList[*out_id] = font;
585 return LCD_ERR_OK;
586}
_USED_EXTERNALLY u8 LCDFontListSize
Definition glcd.c:29
_USED_EXTERNALLY LCD_Font LCDFontList[GLCD_MAX_FONTS]
The list of fonts that have been loaded into the LCD.
Definition glcd.c:28
#define GLCD_MAX_FONTS
Maximum number of fonts that can be loaded into the LCD.
Definition glcd_config.h:13
@ LCD_ERR_FONT_LIST_FULL
The font list is full. No more fonts can be added.
Definition glcd_errors.h:26

◆ LCD_FMRemoveFont()

LCD_Error LCD_FMRemoveFont ( LCD_FontID  id)

Removes a font from the font manager by its ID.

Parameters
idThe ID of the font to remove from the font manager.
Returns
LCD_Error The error code.

Definition at line 588 of file glcd.c.

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}
@ LCD_ERR_INVALID_FONT_ID
The font ID is invalid.
Definition glcd_errors.h:29

◆ LCD_GetBBox()

LCD_Error LCD_GetBBox ( LCD_ObjID  id,
LCD_BBox out_bbox 
)

Returns the bounding box of an object in the render list.

Parameters
idThe ID of the object to get the bounding box of.
out_bboxThe bounding box of the object, if it was found.
Returns
LCD_Error The error code.

Definition at line 602 of file glcd.c.

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}

◆ LCD_GetCenter()

LCD_Coordinate LCD_GetCenter ( void  )

Returns the center of the screen at the current orientation.

Definition at line 233 of file glcd.c.

233{ return s_initialized ? (LCD_Coordinate){LCDMaxX / 2, LCDMaxY / 2} : (LCD_Coordinate){0}; }
_USED_EXTERNALLY u16 LCDMaxY
Definition glcd.c:22
_USED_EXTERNALLY u16 LCDMaxX
Current LCD maximum X and Y coordinates.
Definition glcd.c:22

◆ LCD_GetHeight()

u16 LCD_GetHeight ( void  )

Returns the height of the screen at the current orientation.

Definition at line 229 of file glcd.c.

229{ return s_initialized ? LCDMaxY : 0; }

◆ LCD_GetPointColor()

LCD_Color LCD_GetPointColor ( LCD_Coordinate  point)

Returns the RGB565 color of the pixel at the specified coordinates.

Parameters
pointThe coordinates of the pixel
Returns
The RGB565 color of the pixel

Definition at line 237 of file glcd.c.

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}
u16 __LCD_LL_GetPointColor(u16 x, u16 y)
@ LCD_COL_NONE
Definition glcd_types.h:33

◆ LCD_GetSize()

LCD_Coordinate LCD_GetSize ( void  )

Returns the size of the screen at the current orientation.

Definition at line 231 of file glcd.c.

◆ LCD_GetWidth()

u16 LCD_GetWidth ( void  )

Returns the width of the screen at the current orientation.

Definition at line 227 of file glcd.c.

227{ return s_initialized ? LCDMaxX : 0; }

◆ LCD_Init()

LCD_Error LCD_Init ( LCD_Orientation  orientation,
MEM_Allocator *const  alloc,
const LCD_Color *const  clear_to 
)

Initializes TFT LCD Controller.

Parameters
orientationThe orientation of the screen, from the LCD_Orientation enum
allocThe memory allocator to use for the LCD objects
clear_to[OPTIONAL] The color to clear the screen with
Returns
LCD_Error The error code.

Definition at line 200 of file glcd.c.

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}
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
const LCD_Font Font_MSGothic
const LCD_Font Font_System
LCD_Error LCD_SetBackgroundColor(LCD_Color color, bool redraw_objects)
Sets the background color of the screen.
Definition glcd.c:264
_PRIVATE MEM_Allocator * s_allocator
The memory allocator used to allocate the objects.
Definition glcd.c:19
@ LCD_ERR_NO_MEMORY
The memory pool does not have enough space to allocate the object.
Definition glcd_errors.h:32
void __LCD_LL_Init(u16 orientation)

◆ LCD_IsInitialized()

bool LCD_IsInitialized ( void  )

Checks if the LCD has been initialized.

Returns
Whether the LCD has been initialized

Definition at line 225 of file glcd.c.

225{ return s_initialized; }

◆ LCD_RMAdd()

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 pointer.

Parameters
objThe object to add
out_idThe ID of the object, or NULL on error.
optionsAdding preferences, from the LCD_RMAddOption enum.
Returns
LCD_Error The error code.
Note
Accepting the obj as a const * to simulate the r-value reference in C++, where it's possible to pass a temporary (LCD_Obj&&) to the function, and then move the object to the memory arena. This is not possible in C. If used with the two macros LCD_OBJECT an LCD_RENDER_IMM, the object is passed as r-value reference!

Definition at line 292 of file glcd.c.

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}
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_ListPushBack(CL_List *const list, const void *const elem)
Adds an element at the end of the list.
Definition cl_list.c:80
#define VISIBLE_MASK
Definition glcd.c:40
_PRIVATE u32 s_render_list_id_ctr
Definition glcd.c:54
_PRIVATE bool alloc_component_object(const LCD_Component *const src, LCD_Component *dest)
Definition glcd.c:68
_PRIVATE void dealloc_component_object(LCD_Component *const comp)
Definition glcd.c:117
#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_ERR_TOO_MANY_COMPS_IN_OBJ
The object has too many components.
Definition glcd_errors.h:20
@ 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
Used to store a drawable component of any type.
Definition glcd_types.h:168
LCD_BBox bbox
Definition glcd_types.h:190
LCD_ObjID id
Definition glcd.c:35
uint8_t u8
Definition types.h:8

◆ LCD_RMClear()

LCD_Error LCD_RMClear ( void  )

Removes all visible and non-visible objects from the screen.

Returns
LCD_Error The error code.

Definition at line 395 of file glcd.c.

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}
void CL_ListClear(CL_List *const list)
Removes all elements from the list.
Definition cl_list.c:316
#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
bool CL_ListIsEmpty(const CL_List *const list)
Checks if the list is empty.
Definition cl_list.c:339
_USED_EXTERNALLY LCD_Color LCDCurrentBGColor
Current background color of the screen.
Definition glcd.c:25
void __LCD_LL_FillScreen(u16 color)

◆ LCD_RMIsVisible()

bool LCD_RMIsVisible ( LCD_ObjID  id)

Returns whether an object is visible on the screen or not.

Parameters
idThe ID of the object to check
Returns
Whether the object is visible or not

Definition at line 495 of file glcd.c.

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}
#define RLITEM_IS_VISIBLE(obj)
Definition glcd.c:49

◆ LCD_RMMove()

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 itself, and in the memory arena.

Parameters
idThe ID of the object to move
new_posThe new position of the object, which will replace the old one
redraw_underneathWhether to redraw the objects that are below the object prior to the move
Returns
LCD_Error The error code.
Note
As of now, this method moves the oject by translating each components' coordinate by an offset calculated from the top-left corner of the bounding box of the object itself, returned by the LCD_GetObjBBox() method. This may be imprecise!

Definition at line 507 of file glcd.c.

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}
_PRIVATE LCD_Error render(struct __RLItem *const item)
Definition glcd.c:147
_PRIVATE LCD_Error unrender(struct __RLItem *const item, bool redraw_underneath)
Definition glcd.c:165
LCD_Error
Error codes returned by the GLCD library.
Definition glcd_errors.h:6
@ 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_Coordinate top_left
Definition glcd_types.h:62
LCD_Coordinate center
Definition glcd_types.h:112
LCD_Circle * circle
Definition glcd_types.h:175
LCD_Coordinate pos
Definition glcd_types.h:170
LCD_Line * line
Definition glcd_types.h:173
LCD_ComponentType type
Definition glcd_types.h:169
union LCD_Component::@0 object
LCD_Coordinate to
Definition glcd_types.h:100
LCD_Coordinate from
Definition glcd_types.h:100
uint16_t u16
Definition types.h:7
int16_t i16
Definition types.h:11

◆ LCD_RMRemove()

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 in the memory arena.

Parameters
idThe ID of the object to remove
redraw_underneathWhether to redraw the objects that are below the removed object
Returns
LCD_Error The error code.

Definition at line 362 of file glcd.c.

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++)
385 dealloc_component_object(&item->obj->comps[i]);
386
387 MEM_Free(s_allocator, item->obj->comps);
388 MEM_Free(s_allocator, item->obj);
390
392 return LCD_ERR_OK;
393}
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

◆ LCD_RMRender()

LCD_Error LCD_RMRender ( void  )

Manually triggers an update of the screen. Useful when you want to add multiple objects at once, and only update the screen at the end.

Returns
LCD_Error The error code.

Definition at line 421 of file glcd.c.

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}
#define RLITEM_IS_RENDERED(obj)
Definition glcd.c:50

◆ LCD_RMRenderTemporary()

LCD_Error LCD_RMRenderTemporary ( LCD_Obj *const  obj)

Renders the object immediately, without adding neither to the render list nor to the memory arena. This is useful for objects that are not frequently updated, and that you don't want to store in the memory arena.

Note
To remove an object rendered you must call LCD_SetBackgroundColor(), effectively clearing the screen and redrawing only the objects stored.
Parameters
objThe object to render immediately
Returns
LCD_Error The error code.
Note
Accepting the obj as a const * to simulate the r-value reference in C++, where it's possible to pass a temporary (LCD_Obj&&) to the function, and then move the object to the memory arena. This is not possible in C. If used with the two macros LCD_OBJECT an LCD_RENDER_IMM, the object is passed as r-value reference!

Definition at line 438 of file glcd.c.

439{
440 if (!s_initialized)
442
443 if (!obj || !obj->comps || obj->comps_size <= 0)
444 return LCD_ERR_INVALID_OBJ;
445
447}

◆ LCD_RMSetVisibility()

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.

Parameters
idThe ID of the object to hide
visibleWhether the object should be visible or not
redraw_underneathWhether to redraw the objects that are below the current one.
Returns
LCD_Error The error code.

Definition at line 449 of file glcd.c.

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}
@ LCD_ERR_DURING_UNRENDER
An error occurred during shape deletion.
Definition glcd_errors.h:40
u8 metadata
Definition glcd.c:37

◆ LCD_SetBackgroundColor()

LCD_Error LCD_SetBackgroundColor ( LCD_Color  color,
bool  redraw_objects 
)

Sets the background color of the screen.

Parameters
colorThe RGB565 color to set
redraw_objectsIf true, the object that were previously visible are re-rendered on top of the new background color.
Returns
LCD_Error The error code.
Note
This function clears the screen, then re-renders all the objects in the render list with the new background color.

Definition at line 264 of file glcd.c.

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}
#define RLITEM_UNSET_RENDERED(obj)
Definition glcd.c:47
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
#define RGB8_TO_RGB565(rgb)
Converts RGB (24 bit) into RGB565 (16 bit):
Definition glcd.h:12

◆ LCD_SetPointColor()

LCD_Error LCD_SetPointColor ( LCD_Color  color,
LCD_Coordinate  point 
)

Sets the color of the pixel at the specified coordinates.

Parameters
colorThe RGB565 color to set
pointThe coordinates of the pixel to color
Returns
LCD_Error The error code.

Definition at line 245 of file glcd.c.

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}
@ LCD_ERR_COORDS_OUT_OF_BOUNDS
The specified (x,y) coordinates are out of the screen boundaries.
Definition glcd_errors.h:23
void __LCD_LL_SetPointColor(u16 rgb565, u16 x, u16 y)