🩹 Remove poison wchar_t macro

This commit is contained in:
Scott Lahteine
2022-07-01 04:49:37 -05:00
parent 814b53750f
commit 80c7abd727
26 changed files with 244 additions and 239 deletions

View File

@ -28,7 +28,7 @@ void lcd_put_int(const int i) { u8g.print(i); }
// return < 0 on error
// return the advanced pixels
int lcd_put_wchar_max(const wchar_t c, const pixel_len_t max_length) {
int lcd_put_lchar_max(const lchar_t &c, const pixel_len_t max_length) {
if (c < 256) {
u8g.print((char)c);
return u8g_GetFontBBXWidth(u8g.getU8g());

View File

@ -371,11 +371,11 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
if (!PAGE_CONTAINS(y1 + 1, y2 + 2)) return;
lcd_put_wchar(LCD_PIXEL_WIDTH - 11 * (MENU_FONT_WIDTH), y2, 'E');
lcd_put_wchar((char)('1' + extruder));
lcd_put_wchar(' ');
lcd_put_lchar(LCD_PIXEL_WIDTH - 11 * (MENU_FONT_WIDTH), y2, 'E');
lcd_put_lchar((char)('1' + extruder));
lcd_put_lchar(' ');
lcd_put_u8str(i16tostr3rj(thermalManager.wholeDegHotend(extruder)));
lcd_put_wchar('/');
lcd_put_lchar('/');
if (get_blink() || !thermalManager.heater_idle[extruder].timed_out)
lcd_put_u8str(i16tostr3rj(thermalManager.degTargetHotend(extruder)));
@ -421,12 +421,12 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
vlen = vstr ? utf8_strlen(vstr) : 0;
if (style & SS_CENTER) {
int pad = (LCD_PIXEL_WIDTH - plen - vlen * MENU_FONT_WIDTH) / MENU_FONT_WIDTH / 2;
while (--pad >= 0) n -= lcd_put_wchar(' ');
while (--pad >= 0) n -= lcd_put_lchar(' ');
}
if (plen) n = lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, n / (MENU_FONT_WIDTH)) * (MENU_FONT_WIDTH);
if (vlen) n -= lcd_put_u8str_max(vstr, n);
while (n > MENU_FONT_WIDTH) n -= lcd_put_wchar(' ');
while (n > MENU_FONT_WIDTH) n -= lcd_put_lchar(' ');
}
}
@ -434,9 +434,9 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
void MenuItemBase::_draw(const bool sel, const uint8_t row, FSTR_P const ftpl, const char, const char post_char) {
if (mark_as_selected(row, sel)) {
pixel_len_t n = lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, LCD_WIDTH - 1) * (MENU_FONT_WIDTH);
while (n > MENU_FONT_WIDTH) n -= lcd_put_wchar(' ');
lcd_put_wchar(LCD_PIXEL_WIDTH - (MENU_FONT_WIDTH), row_y2, post_char);
lcd_put_wchar(' ');
while (n > MENU_FONT_WIDTH) n -= lcd_put_lchar(' ');
lcd_put_lchar(LCD_PIXEL_WIDTH - (MENU_FONT_WIDTH), row_y2, post_char);
lcd_put_lchar(' ');
}
}
@ -449,8 +449,8 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
pixel_len_t n = lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, LCD_WIDTH - 2 - vallen * prop) * (MENU_FONT_WIDTH);
if (vallen) {
lcd_put_wchar(':');
while (n > MENU_FONT_WIDTH) n -= lcd_put_wchar(' ');
lcd_put_lchar(':');
while (n > MENU_FONT_WIDTH) n -= lcd_put_lchar(' ');
lcd_moveto(LCD_PIXEL_WIDTH - _MAX((MENU_FONT_WIDTH) * vallen, pixelwidth + 2), row_y2);
if (pgm) lcd_put_u8str_P(inStr); else lcd_put_u8str(inStr);
}
@ -494,14 +494,14 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
// If a value is included, print a colon, then print the value right-justified
if (value) {
lcd_put_wchar(':');
lcd_put_lchar(':');
if (extra_row) {
// Assume that value is numeric (with no descender)
baseline += EDIT_FONT_ASCENT + 2;
onpage = PAGE_CONTAINS(baseline - (EDIT_FONT_ASCENT - 1), baseline);
}
if (onpage) {
lcd_put_wchar(((lcd_chr_fit - 1) - (vallen * prop + 1)) * one_chr_width, baseline, ' '); // Right-justified, padded, add a leading space
lcd_put_lchar(((lcd_chr_fit - 1) - (vallen * prop + 1)) * one_chr_width, baseline, ' '); // Right-justified, padded, add a leading space
lcd_put_u8str(value);
}
}
@ -533,10 +533,10 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
void MenuItem_sdbase::draw(const bool sel, const uint8_t row, FSTR_P const, CardReader &theCard, const bool isDir) {
if (mark_as_selected(row, sel)) {
const uint8_t maxlen = LCD_WIDTH - isDir;
if (isDir) lcd_put_wchar(LCD_STR_FOLDER[0]);
if (isDir) lcd_put_lchar(LCD_STR_FOLDER[0]);
const pixel_len_t pixw = maxlen * (MENU_FONT_WIDTH);
pixel_len_t n = pixw - lcd_put_u8str_max(ui.scrolled_filename(theCard, maxlen, row, sel), pixw);
while (n > MENU_FONT_WIDTH) n -= lcd_put_wchar(' ');
while (n > MENU_FONT_WIDTH) n -= lcd_put_lchar(' ');
}
}
@ -611,11 +611,11 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
// Print plot position
if (PAGE_CONTAINS(LCD_PIXEL_HEIGHT - (INFO_FONT_HEIGHT - 1), LCD_PIXEL_HEIGHT)) {
lcd_put_wchar(5, LCD_PIXEL_HEIGHT, '(');
lcd_put_lchar(5, LCD_PIXEL_HEIGHT, '(');
u8g.print(x_plot);
lcd_put_wchar(',');
lcd_put_lchar(',');
u8g.print(y_plot);
lcd_put_wchar(')');
lcd_put_lchar(')');
// Show the location value
lcd_put_u8str_P(74, LCD_PIXEL_HEIGHT, Z_LBL);

View File

@ -200,7 +200,7 @@ FORCE_INLINE void _draw_centered_temp(const celsius_t temp, const uint8_t tx, co
const char *str = i16tostr3rj(temp);
const uint8_t len = str[0] != ' ' ? 3 : str[1] != ' ' ? 2 : 1;
lcd_put_u8str(tx - len * (INFO_FONT_WIDTH) / 2 + 1, ty, &str[3-len]);
lcd_put_wchar(LCD_STR_DEGREE[0]);
lcd_put_lchar(LCD_STR_DEGREE[0]);
}
}
@ -432,13 +432,13 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const
const bool is_inch = parser.using_inch_units();
const AxisEnum a = TERN(LCD_SHOW_E_TOTAL, axis == E_AXIS ? X_AXIS : axis, axis);
const uint8_t offs = a * (is_inch ? XYZ_SPACING_IN : XYZ_SPACING);
lcd_put_wchar((is_inch ? X_LABEL_POS_IN : X_LABEL_POS) + offs, XYZ_BASELINE, AXIS_CHAR(axis));
lcd_put_lchar((is_inch ? X_LABEL_POS_IN : X_LABEL_POS) + offs, XYZ_BASELINE, AXIS_CHAR(axis));
lcd_moveto((is_inch ? X_VALUE_POS_IN : X_VALUE_POS) + offs, XYZ_BASELINE);
if (blink)
lcd_put_u8str(value);
else if (axis_should_home(axis))
while (const char c = *value++) lcd_put_wchar(c <= '.' ? c : '?');
while (const char c = *value++) lcd_put_lchar(c <= '.' ? c : '?');
else if (NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !axis_is_trusted(axis))
lcd_put_u8str(axis == Z_AXIS ? F(" ") : F(" "));
else
@ -675,7 +675,7 @@ void MarlinUI::draw_status_screen() {
lcd_put_u8str(STATUS_CUTTER_TEXT_X, STATUS_CUTTER_TEXT_Y, cutter_power2str(cutter.unitPower));
#elif CUTTER_UNIT_IS(RPM)
lcd_put_u8str(STATUS_CUTTER_TEXT_X - 2, STATUS_CUTTER_TEXT_Y, ftostr61rj(float(cutter.unitPower) / 1000));
lcd_put_wchar('K');
lcd_put_lchar('K');
#else
lcd_put_u8str(STATUS_CUTTER_TEXT_X, STATUS_CUTTER_TEXT_Y, cutter_power2str(cutter.unitPower));
#endif
@ -734,7 +734,7 @@ void MarlinUI::draw_status_screen() {
}
#endif
lcd_put_u8str(STATUS_FAN_TEXT_X, STATUS_FAN_TEXT_Y, i16tostr3rj(thermalManager.pwmToPercent(spd)));
lcd_put_wchar(c);
lcd_put_lchar(c);
}
}
#endif
@ -783,7 +783,7 @@ void MarlinUI::draw_status_screen() {
if (progress_state == 0) {
if (progress_string[0]) {
lcd_put_u8str(progress_x_pos, EXTRAS_BASELINE, progress_string);
lcd_put_wchar('%');
lcd_put_lchar('%');
}
}
else if (progress_state == 2 && estimation_string[0]) {
@ -804,7 +804,7 @@ void MarlinUI::draw_status_screen() {
#if ENABLED(SHOW_SD_PERCENT)
if (progress_string[0]) {
lcd_put_u8str(55, EXTRAS_BASELINE, progress_string); // Percent complete
lcd_put_wchar('%');
lcd_put_lchar('%');
}
#endif
@ -814,7 +814,7 @@ void MarlinUI::draw_status_screen() {
#if ENABLED(SHOW_REMAINING_TIME)
if (blink && estimation_string[0]) {
lcd_put_wchar(estimation_x_pos, EXTRAS_BASELINE, 'R');
lcd_put_lchar(estimation_x_pos, EXTRAS_BASELINE, 'R');
lcd_put_u8str(estimation_string);
}
else
@ -912,11 +912,11 @@ void MarlinUI::draw_status_screen() {
if (PAGE_CONTAINS(EXTRAS_2_BASELINE - INFO_FONT_ASCENT, EXTRAS_2_BASELINE - 1)) {
set_font(FONT_MENU);
lcd_put_wchar(3, EXTRAS_2_BASELINE, LCD_STR_FEEDRATE[0]);
lcd_put_lchar(3, EXTRAS_2_BASELINE, LCD_STR_FEEDRATE[0]);
set_font(FONT_STATUSMENU);
lcd_put_u8str(12, EXTRAS_2_BASELINE, i16tostr3rj(feedrate_percentage));
lcd_put_wchar('%');
lcd_put_lchar('%');
//
// Filament sensor display if SD is disabled
@ -924,10 +924,10 @@ void MarlinUI::draw_status_screen() {
#if ENABLED(FILAMENT_LCD_DISPLAY) && DISABLED(SDSUPPORT)
lcd_put_u8str(56, EXTRAS_2_BASELINE, wstring);
lcd_put_u8str(102, EXTRAS_2_BASELINE, mstring);
lcd_put_wchar('%');
lcd_put_lchar('%');
set_font(FONT_MENU);
lcd_put_wchar(47, EXTRAS_2_BASELINE, LCD_STR_FILAM_DIA[0]); // lcd_put_u8str(F(LCD_STR_FILAM_DIA));
lcd_put_wchar(93, EXTRAS_2_BASELINE, LCD_STR_FILAM_MUL[0]);
lcd_put_lchar(47, EXTRAS_2_BASELINE, LCD_STR_FILAM_DIA[0]); // lcd_put_u8str(F(LCD_STR_FILAM_DIA));
lcd_put_lchar(93, EXTRAS_2_BASELINE, LCD_STR_FILAM_MUL[0]);
#endif
}
@ -941,12 +941,12 @@ void MarlinUI::draw_status_screen() {
// Alternate Status message and Filament display
if (ELAPSED(millis(), next_filament_display)) {
lcd_put_u8str(F(LCD_STR_FILAM_DIA));
lcd_put_wchar(':');
lcd_put_lchar(':');
lcd_put_u8str(wstring);
lcd_put_u8str(F(" " LCD_STR_FILAM_MUL));
lcd_put_wchar(':');
lcd_put_lchar(':');
lcd_put_u8str(mstring);
lcd_put_wchar('%');
lcd_put_lchar('%');
return;
}
#endif
@ -979,7 +979,7 @@ void MarlinUI::draw_status_message(const bool blink) {
if (slen <= lcd_width) {
// The string fits within the line. Print with no scrolling
lcd_put_u8str(status_message);
while (slen < lcd_width) { lcd_put_wchar(' '); ++slen; }
while (slen < lcd_width) { lcd_put_lchar(' '); ++slen; }
}
else {
// String is longer than the available space
@ -997,14 +997,14 @@ void MarlinUI::draw_status_message(const bool blink) {
// If the remaining string doesn't completely fill the screen
if (rlen < lcd_width) {
uint8_t chars = lcd_width - rlen; // Amount of space left in characters
lcd_put_wchar(' '); // Always at 1+ spaces left, draw a space
lcd_put_lchar(' '); // Always at 1+ spaces left, draw a space
if (--chars) { // Draw a second space if there's room
lcd_put_wchar(' ');
lcd_put_lchar(' ');
if (--chars) { // Draw a third space if there's room
lcd_put_wchar(' ');
lcd_put_lchar(' ');
if (--chars) { // Print a second copy of the message
lcd_put_u8str_max(status_message, pixel_width - (rlen + 2) * (MENU_FONT_WIDTH));
lcd_put_wchar(' ');
lcd_put_lchar(' ');
}
}
}
@ -1019,7 +1019,7 @@ void MarlinUI::draw_status_message(const bool blink) {
lcd_put_u8str_max(status_message, pixel_width);
// Fill the rest with spaces
for (; slen < lcd_width; ++slen) lcd_put_wchar(' ');
for (; slen < lcd_width; ++slen) lcd_put_lchar(' ');
#endif // !STATUS_MESSAGE_SCROLLING

View File

@ -60,11 +60,11 @@ static int fontgroup_init(font_group_t * root, const uxg_fontinfo_t * fntinfo, i
return 0;
}
static const font_t* fontgroup_find(font_group_t * root, wchar_t val) {
uxg_fontinfo_t vcmp = {(uint16_t)(val / 128), (uint8_t)(val % 128 + 128), (uint8_t)(val % 128 + 128), 0, 0};
size_t idx = 0;
static const font_t* fontgroup_find(font_group_t * root, const lchar_t &val) {
if (val <= 0xFF) return nullptr;
if (val < 256) return nullptr;
uxg_fontinfo_t vcmp = { uint16_t(val >> 7), uint8_t((val & 0x7F) + 0x80), uint8_t((val & 0x7F) + 0x80), 0, 0 };
size_t idx = 0;
if (pf_bsearch_r((void*)root->m_fntifo, root->m_fntinfo_num, pf_bsearch_cb_comp_fntifo_pgm, (void*)&vcmp, &idx) < 0)
return nullptr;
@ -73,7 +73,7 @@ static const font_t* fontgroup_find(font_group_t * root, wchar_t val) {
return vcmp.fntdata;
}
static void fontgroup_drawwchar(font_group_t *group, const font_t *fnt_default, wchar_t val, void * userdata, fontgroup_cb_draw_t cb_draw_ram) {
static void fontgroup_drawwchar(font_group_t *group, const font_t *fnt_default, const lchar_t &val, void * userdata, fontgroup_cb_draw_t cb_draw_ram) {
uint8_t buf[2] = {0, 0};
const font_t * fntpqm = (font_t*)fontgroup_find(group, val);
if (!fntpqm) {
@ -106,10 +106,10 @@ static void fontgroup_drawwchar(font_group_t *group, const font_t *fnt_default,
static void fontgroup_drawstring(font_group_t *group, const font_t *fnt_default, const char *utf8_msg, read_byte_cb_t cb_read_byte, void * userdata, fontgroup_cb_draw_t cb_draw_ram) {
const uint8_t *p = (uint8_t*)utf8_msg;
for (;;) {
wchar_t val = 0;
p = get_utf8_value_cb(p, cb_read_byte, &val);
if (!val) break;
fontgroup_drawwchar(group, fnt_default, val, userdata, cb_draw_ram);
lchar_t wc;
p = get_utf8_value_cb(p, cb_read_byte, wc);
if (!wc) break;
fontgroup_drawwchar(group, fnt_default, wc, userdata, cb_draw_ram);
}
}
@ -149,19 +149,19 @@ static int fontgroup_cb_draw_u8g(void *userdata, const font_t *fnt_current, cons
}
/**
* @brief Draw a wchar_t at the specified position
* @brief Draw a lchar_t at the specified position
*
* @param pu8g : U8G pointer
* @param x : position x axis
* @param y : position y axis
* @param ch : the wchar_t
* @param wc : the lchar_t
* @param max_width : the pixel width of the string allowed
*
* @return number of pixels advanced
*
* Draw a UTF-8 string at the specified position
*/
unsigned int uxg_DrawWchar(u8g_t *pu8g, unsigned int x, unsigned int y, wchar_t ch, pixel_len_t max_width) {
unsigned int uxg_DrawWchar(u8g_t *pu8g, unsigned int x, unsigned int y, const lchar_t &wc, pixel_len_t max_width) {
struct _uxg_drawu8_data_t data;
font_group_t *group = &g_fontgroup_root;
const font_t *fnt_default = uxg_GetFont(pu8g);
@ -176,7 +176,7 @@ unsigned int uxg_DrawWchar(u8g_t *pu8g, unsigned int x, unsigned int y, wchar_t
data.adv = 0;
data.max_width = max_width;
data.fnt_prev = nullptr;
fontgroup_drawwchar(group, fnt_default, ch, (void*)&data, fontgroup_cb_draw_u8g);
fontgroup_drawwchar(group, fnt_default, wc, (void*)&data, fontgroup_cb_draw_u8g);
u8g_SetFont(pu8g, (const u8g_fntpgm_uint8_t*)fnt_default);
return data.adv;

View File

@ -26,7 +26,7 @@ typedef struct _uxg_fontinfo_t {
int uxg_SetUtf8Fonts(const uxg_fontinfo_t * fntinfo, int number); // fntinfo is type of PROGMEM
unsigned int uxg_DrawWchar(u8g_t *pu8g, unsigned int x, unsigned int y, wchar_t ch, const pixel_len_t max_length);
unsigned int uxg_DrawWchar(u8g_t *pu8g, unsigned int x, unsigned int y, const lchar_t &ch, const pixel_len_t max_length);
unsigned int uxg_DrawUtf8Str(u8g_t *pu8g, unsigned int x, unsigned int y, const char *utf8_msg, const pixel_len_t max_length);
unsigned int uxg_DrawUtf8StrP(u8g_t *pu8g, unsigned int x, unsigned int y, PGM_P utf8_msg, const pixel_len_t max_length);