Prusa MINI Firmware overview
guitypes.c File Reference
#include "guitypes.h"

Functions

void interval_intersect_ui16 (uint16_t *p)
 
rect_ui16_t rect_intersect_ui16 (rect_ui16_t rc, rect_ui16_t rc1)
 
rect_ui16_t rect_ui16_add_padding_ui8 (rect_ui16_t rc, padding_ui8_t pad)
 
rect_ui16_t rect_ui16_sub_padding_ui8 (rect_ui16_t rc, padding_ui8_t pad)
 
rect_ui16_t rect_align_ui16 (rect_ui16_t rc, rect_ui16_t rc1, uint8_t align)
 
point_ui16_t font_meas_text (font_t *pf, const char *str)
 
int font_line_chars (font_t *pf, const char *str, uint16_t line_width)
 
point_ui16_t icon_meas (const uint8_t *pi)
 
const uint8_tresource_ptr (uint16_t id)
 
uint16_t resource_size (uint16_t id)
 
FILE * resource_fopen (uint16_t id, const char *opentype)
 
font_tresource_font (uint16_t id)
 

Variables

const resource_entry_t resource_table []
 
const uint16_t resource_table_size
 
const uint16_t resource_count
 

Function Documentation

◆ interval_intersect_ui16()

void interval_intersect_ui16 ( uint16_t *  p)
7  {
8  if (p[0] < p[2]) //p0 is left
9  {
10  if (p[1] > p[2]) //intersection exists
11  {
12  p[4] = p[2]; //result left point is p2
13  if (p[1] > p[3]) //intersection is equal p2-p3
14  p[5] = p[3]; //result right point is p3
15  else //intersection is equal p2-p1
16  p[5] = p[1]; //result right point is p1
17  } else {
18  p[4] = 0;
19  p[5] = 0;
20  }
21  } else //p2 is left
22  {
23  if (p[3] > p[0]) //intersection exists
24  {
25  p[4] = p[0]; //result left point is p0
26  if (p[3] > p[1]) //intersection is equal p0-p1
27  p[5] = p[1]; //result right point is p1
28  else //intersection is equal p0-p3
29  p[5] = p[3]; //result right point is p3
30  } else {
31  p[4] = 0;
32  p[5] = 0;
33  }
34  }
35 }
Here is the caller graph for this function:

◆ rect_intersect_ui16()

rect_ui16_t rect_intersect_ui16 ( rect_ui16_t  rc,
rect_ui16_t  rc1 
)
37  {
38  uint16_t x[6] = { rc.x, rc.x + rc.w, rc1.x, rc1.x + rc1.w, 0, 0 };
39  uint16_t y[6] = { rc.y, rc.y + rc.h, rc1.y, rc1.y + rc1.h, 0, 0 };
42  rect_ui16_t rc2 = { x[4], y[4], x[5] - x[4], y[5] - y[4] };
43  return rc2;
44 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rect_ui16_add_padding_ui8()

rect_ui16_t rect_ui16_add_padding_ui8 ( rect_ui16_t  rc,
padding_ui8_t  pad 
)
46  {
47  rect_ui16_t rect = { 0, 0, rc.w + pad.left + pad.right, rc.h + pad.top + pad.bottom };
48  if (rc.x > pad.left)
49  rect.x = rc.x - pad.left;
50  if (rc.y > pad.top)
51  rect.y = rc.y - pad.top;
52  return rect;
53 }

◆ rect_ui16_sub_padding_ui8()

rect_ui16_t rect_ui16_sub_padding_ui8 ( rect_ui16_t  rc,
padding_ui8_t  pad 
)
55  {
56  rect_ui16_t rect = { rc.x + pad.left, rc.y + pad.top, 0, 0 };
57  if (rc.w > (pad.left + pad.right))
58  rect.w = rc.w - (pad.left + pad.right);
59  if (rc.h > (pad.top + pad.bottom))
60  rect.h = rc.h - (pad.top + pad.bottom);
61  return rect;
62 }
Here is the caller graph for this function:

◆ rect_align_ui16()

rect_ui16_t rect_align_ui16 ( rect_ui16_t  rc,
rect_ui16_t  rc1,
uint8_t  align 
)
64  {
65  rect_ui16_t rect = rc1;
66  switch (align & ALIGN_HMASK) {
67  case ALIGN_LEFT:
68  rect.x = rc.x;
69  break;
70  case ALIGN_RIGHT:
71  rect.x = ((rc.x + rc.w) > rc1.w) ? ((rc.x + rc.w) - rc1.w) : 0;
72  break;
73  case ALIGN_HCENTER:
74  if (rc.w >= rc1.w)
75  rect.x = rc.x + ((rc.w - rc1.w) / 2);
76  else
77  rect.x = (rc.x > ((rc1.w - rc.w) / 2)) ? rc.x - ((rc1.w - rc.w) / 2) : 0;
78  break;
79  }
80  switch (align & ALIGN_VMASK) {
81  case ALIGN_TOP:
82  rect.y = rc.y;
83  break;
84  case ALIGN_BOTTOM:
85  rect.y = ((rc.y + rc.h) > rc1.h) ? ((rc.y + rc.h) - rc1.h) : 0;
86  break;
87  case ALIGN_VCENTER:
88  if (rc.h >= rc1.h)
89  rect.y = rc.y + ((rc.h - rc1.h) / 2);
90  else
91  rect.y = (rc.y > ((rc1.h - rc.h) / 2)) ? rc.y - ((rc1.h - rc.h) / 2) : 0;
92  break;
93  }
94  return rect;
95 }
Here is the caller graph for this function:

◆ font_meas_text()

point_ui16_t font_meas_text ( font_t pf,
const char *  str 
)
97  {
98  int x = 0;
99  int y = 0;
100  int w = 0;
101  int h = 0;
102  int char_w = pf->w;
103  int char_h = pf->h;
104  int len = strlen(str);
105  char c;
106  while (len--) {
107  c = *(str++);
108  if (c == '\n') {
109  if (x + char_w > w)
110  w = x + char_w;
111  y += char_h;
112  x = 0;
113  } else
114  x += char_w;
115  h = y + char_h;
116  }
117  if (x > w)
118  w = x;
119  return point_ui16((uint16_t)w, (uint16_t)h);
120 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ font_line_chars()

int font_line_chars ( font_t pf,
const char *  str,
uint16_t  line_width 
)
122  {
123  int w = 0;
124  int char_w = pf->w;
125  int len = strlen(str);
126  int n = 0;
127  char c;
128  // This is generally about finding the closest '\n' character within the current line to be drawn.
129  // Line is limited by pixel dimension, all characters have the same fixed pixel size
130  // Such character may not be found, so n becomes > len
131  while ((w + char_w) <= line_width) {
132  c = str[n++];
133  if (c == '\n')
134  break;
135  else
136  w += char_w;
137  }
138 
139  // if the line width is >= than characters to be printed, skip further search
140  // and just return len - i.e. the whole string is to be printed at once.
141  if (n >= len)
142  return len; // must return here to prevent touching memory beyond str in the next while cycle
143 
144  while ((n > 0) && ((str[n] != ' ') && (str[n] != '\n'))) {
145  n--;
146  }
147 
148  if (n == 0)
149  n = line_width / char_w;
150  if (n >= len)
151  return len;
152  return n;
153 }
Here is the caller graph for this function:

◆ icon_meas()

point_ui16_t icon_meas ( const uint8_t pi)
155  {
156  point_ui16_t wh = { 0, 0 };
157  if (memcmp(pi, "\x89PNG", 4) == 0) {
158  wh.x = swap_ui16(*((uint16_t *)(pi + 18)));
159  wh.y = swap_ui16(*((uint16_t *)(pi + 22)));
160  }
161  return wh;
162 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ resource_ptr()

const uint8_t* resource_ptr ( uint16_t  id)
168  {
169  if (id < resource_count)
170  return resource_table[id].ptr;
171  return 0;
172 }
Here is the caller graph for this function:

◆ resource_size()

uint16_t resource_size ( uint16_t  id)
174  {
175  if (id < resource_count)
176  return resource_table[id].size;
177  return 0;
178 }

◆ resource_fopen()

FILE* resource_fopen ( uint16_t  id,
const char *  opentype 
)
180  {
181  if (id < resource_count)
182  return fmemopen((uint8_t *)resource_table[id].ptr, resource_table[id].size, opentype);
183  return 0;
184 }
Here is the caller graph for this function:

◆ resource_font()

font_t* resource_font ( uint16_t  id)
186  {
187  if (id < resource_count)
188  return (font_t *)resource_table[id].ptr;
189  return 0;
190 }
Here is the caller graph for this function:

Variable Documentation

◆ resource_table

const resource_entry_t resource_table[]

◆ resource_table_size

const uint16_t resource_table_size

◆ resource_count

const uint16_t resource_count
_rect_ui16_t::y
uint16_t y
Definition: guitypes.h:71
_font_t::h
uint8_t h
Definition: guitypes.h:78
ALIGN_BOTTOM
#define ALIGN_BOTTOM
Definition: guitypes.h:16
_rect_ui16_t::w
uint16_t w
Definition: guitypes.h:72
_font_t
Definition: guitypes.h:76
_padding_ui8_t::bottom
uint8_t bottom
Definition: guitypes.h:90
_padding_ui8_t::top
uint8_t top
Definition: guitypes.h:88
_padding_ui8_t::right
uint8_t right
Definition: guitypes.h:89
_point_ui16_t::x
uint16_t x
Definition: guitypes.h:65
_resource_entry_t::ptr
const uint8_t * ptr
Definition: guitypes.h:102
ALIGN_RIGHT
#define ALIGN_RIGHT
Definition: guitypes.h:12
interval_intersect_ui16
void interval_intersect_ui16(uint16_t *p)
Definition: guitypes.c:7
_point_ui16_t
Definition: guitypes.h:64
_padding_ui8_t::left
uint8_t left
Definition: guitypes.h:87
swap_ui16
static uint16_t swap_ui16(uint16_t val)
Definition: guitypes.h:120
_point_ui16_t::y
uint16_t y
Definition: guitypes.h:66
ALIGN_TOP
#define ALIGN_TOP
Definition: guitypes.h:14
_font_t::w
uint8_t w
Definition: guitypes.h:77
_rect_ui16_t
Definition: guitypes.h:69
ALIGN_LEFT
#define ALIGN_LEFT
Definition: guitypes.h:10
uint8_t
const uint8_t[]
Definition: 404_html.c:3
_rect_ui16_t::h
uint16_t h
Definition: guitypes.h:73
ALIGN_VCENTER
#define ALIGN_VCENTER
Definition: guitypes.h:15
resource_count
const uint16_t resource_count
resource_table
const resource_entry_t resource_table[]
_resource_entry_t::size
const uint16_t size
Definition: guitypes.h:103
_rect_ui16_t::x
uint16_t x
Definition: guitypes.h:70
ALIGN_HCENTER
#define ALIGN_HCENTER
Definition: guitypes.h:11
point_ui16
static point_ui16_t point_ui16(uint16_t x, uint16_t y)
Definition: guitypes.h:154
size
static png_bytep size_t size
Definition: pngwrite.c:2170
ALIGN_HMASK
#define ALIGN_HMASK
Definition: guitypes.h:13
ALIGN_VMASK
#define ALIGN_VMASK
Definition: guitypes.h:17